1 /************************************************************************/
\r
3 /************************************************************************/
\r
4 /* Copyright (c) 2010 by Laurel Williams */
\r
5 /* Inclusive Design Institute */
\r
6 /* http://atutor.ca */
\r
8 /* This program is free software. You can redistribute it and/or */
\r
9 /* modify it under the terms of the GNU General Public License */
\r
10 /* as published by the Free Software Foundation. */
\r
11 /************************************************************************/
\r
19 ATutor = ATutor || {};
\r
20 ATutor.mods = ATutor.mods || {};
\r
21 ATutor.mods.editor = ATutor.mods.editor || {};
\r
24 var hiddenClass = "hidden";
\r
25 var enabledClass = "clickable";
\r
27 var hideIt = function (theElement, hiddenElement) {
\r
28 theElement.addClass(hiddenClass);
\r
29 hiddenElement.val("0");
\r
32 var showIt = function (theElement, hiddenElement) {
\r
33 theElement.removeClass(hiddenClass);
\r
34 hiddenElement.val("1");
\r
37 //hides or shows tool (toggle) and sets hidden input value appropriately.
\r
38 var doToggle = function (theElement, hiddenElement) {
\r
39 if (theElement.hasClass(hiddenClass)) {
\r
40 showIt(theElement, hiddenElement);
\r
42 hideIt(theElement, hiddenElement);
\r
46 //click function to launch accessibility validation window
\r
47 var launchAChecker = function () {
\r
48 var theCode = '<html><body onLoad="document.accessform.submit();"> \n';
\r
49 theCode += '<h1>'+ATutor.mods.editor.processing_text+' .....</h1>\n';
\r
50 theCode += '<form action="'+ATutor.base_href+'mods/_core/editor/accessibility.php?popup=1" name="accessform" method="post"> \n';
\r
51 theCode += '<input type="hidden" name="cid" value="'+jQuery("input[name=cid]").val()+'" /> \n';
\r
52 theCode += '<textarea name="body_text" style="display:none">' + tinyMCE.activeEditor.getContent() + '</textarea>\n';
\r
53 theCode += '<input type="submit" style="display:none" /></form> \n';
\r
54 theCode += '</body></html> \n';
\r
55 accessWin = window.open('', 'accessibilityWin', 'menubar=0,scrollbars=1,resizable=1,width=600,height=600');
\r
56 accessWin.document.writeln(theCode);
\r
57 accessWin.document.close();
\r
61 //AChecker variables
\r
62 var accessibilityTool = {
\r
63 toolId: "#accessibilitytool",
\r
64 enabledClass: enabledClass,
\r
65 enabledImage: "images/achecker.png",
\r
66 clickFunction: function () {
\r
69 disabledImage: "images/achecker_disabled.png"
\r
72 //customized head variables
\r
73 var headId = "#head";
\r
74 var displayheadId = "#displayhead";
\r
76 toolId: "#headtool",
\r
77 enabledClass: enabledClass,
\r
78 enabledImage: "images/custom_head.png",
\r
79 clickFunction: function () {
\r
80 doToggle(jQuery(headId), jQuery(displayheadId));
\r
82 disabledImage: "images/custom_head_disabled.png"
\r
85 //paste from file variables
\r
86 var pasteId = "#paste";
\r
87 var displaypasteId = "#displaypaste";
\r
89 toolId: "#pastetool",
\r
90 enabledClass: enabledClass,
\r
91 enabledImage: "images/paste.png",
\r
92 clickFunction: function () {
\r
93 doToggle(jQuery(pasteId), jQuery(displaypasteId));
\r
95 disabledImage: "images/paste_disabled.png"
\r
98 //click function to launch file manager window
\r
99 var launchFileManager = function () {
\r
100 window.open(ATutor.base_href + 'mods/_core/file_manager/index.php?framed=1&popup=1&cp=' + ATutor.mods.editor.content_path, 'newWin1', 'menubar=0,scrollbars=1,resizable=1,width=640,height=490');
\r
104 //file manager variables
\r
105 var filemanTool = {
\r
106 toolId: "#filemantool",
\r
107 enabledClass: enabledClass,
\r
108 enabledImage: "images/file-manager.png",
\r
109 clickFunction: function () {
\r
110 launchFileManager();
\r
112 disabledImage: "images/file-manager_disabled.png"
\r
115 //checks hidden variable and shows/hides element accordingly
\r
116 var setDisplay = function (theElement, hiddenElement) {
\r
117 if (hiddenElement.val() === '0') {
\r
118 theElement.addClass(hiddenClass);
\r
120 theElement.removeClass(hiddenClass);
\r
124 var disableTool = function (theTool) {
\r
125 var theToolElement = jQuery(theTool.toolId);
\r
126 theToolElement.removeClass(theTool.enabledClass);
\r
127 theToolElement.attr("src", ATutor.base_href + theTool.disabledImage);
\r
128 theToolElement.attr("title", theTool.disabledTitle);
\r
129 theToolElement.attr("alt", theTool.disabledTitle);
\r
130 theToolElement.unbind("click");
\r
133 var enableTool = function (theTool) {
\r
134 var theToolElement = jQuery(theTool.toolId);
\r
135 theToolElement.addClass(theTool.enabledClass);
\r
136 theToolElement.attr("src", ATutor.base_href + theTool.enabledImage);
\r
137 theToolElement.attr("title", theTool.enabledTitle);
\r
138 theToolElement.attr("alt", theTool.enabledTitle);
\r
139 theToolElement.click(theTool.clickFunction);
\r
142 //initialises values to show or hide them
\r
143 var setupPage = function () {
\r
144 var head = jQuery(headId);
\r
145 var displayhead = jQuery(displayheadId);
\r
146 var paste = jQuery(pasteId);
\r
147 var displaypaste = jQuery(displaypasteId);
\r
148 var textArea = jQuery("#textSpan");
\r
149 var weblink = jQuery("#weblinkSpan");
\r
150 var textAreaId = "body_text";
\r
151 if (jQuery("#weblink").attr("checked")) {
\r
152 disableTool(accessibilityTool);
\r
153 disableTool(headTool);
\r
154 disableTool(pasteTool);
\r
155 disableTool(filemanTool);
\r
157 hideIt(head, displayhead);
\r
158 hideIt(paste, displaypaste);
\r
159 if (tinyMCE.get(textAreaId)) {
\r
160 tinyMCE.execCommand('mceRemoveControl', false, textAreaId);
\r
164 } else if (jQuery("#html").attr("checked")) {
\r
165 enableTool(accessibilityTool);
\r
166 enableTool(headTool);
\r
167 enableTool(pasteTool);
\r
168 enableTool(filemanTool);
\r
170 setDisplay(head, displayhead);
\r
171 setDisplay(paste, displaypaste);
\r
172 if (ATutor.mods.editor.editor_pref !== '1' && !tinyMCE.get(textAreaId)) {
\r
173 tinyMCE.execCommand('mceAddControl', false, textAreaId);
\r
178 disableTool(accessibilityTool);
\r
179 disableTool(headTool);
\r
180 enableTool(pasteTool);
\r
181 enableTool(filemanTool);
\r
183 hideIt(head, displayhead);
\r
184 setDisplay(paste, displaypaste);
\r
186 if (tinyMCE.get(textAreaId)) {
\r
187 tinyMCE.execCommand('mceRemoveControl', false, textAreaId);
\r
193 //click function to launch preview window
\r
194 var previewTool = function () {
\r
195 var theCode = '<html><body onLoad="document.accessform.submit();"> \n';
\r
196 theCode += '<h1>'+ATutor.mods.editor.processing_text+' .....</h1>\n';
\r
197 theCode += '<form action="'+ATutor.base_href+'mods/_core/editor/preview.php?popup=1" name="accessform" method="post"> \n';
\r
198 theCode += '<input type="hidden" name="title" value="'+jQuery("input[name=title]").val()+'" /> \n';
\r
199 theCode += '<input type="hidden" name="cid" value="'+jQuery("input[name=cid]").val()+'" /> \n';
\r
200 theCode += '<input type="hidden" name="formatting" value="'+jQuery("#formatting_radios input:radio:checked").val()+'" /> \n';
\r
201 jQuery("input[name*='glossary_defs[']").each(function() {
\r
202 theCode += '<input type="hidden" name="'+this.name+'" value="'+jQuery(this).val()+'" /> \n';
\r
204 if (jQuery("#weblink").attr("checked")) {
\r
205 theCode += '<input type="hidden" name="weblink_text" value="'+jQuery("#weblink_text").val()+'" /> \n';
\r
206 } else if (jQuery("#html").attr("checked")) {
\r
207 theCode += '<textarea name="body_text" style="display:none">' + tinyMCE.activeEditor.getContent() + '</textarea>\n';
\r
209 theCode += '<textarea name="body_text" style="display:none">' + jQuery("#body_text").val() + '</textarea>\n';
\r
211 theCode += '<input type="submit" style="display:none" /></form> \n';
\r
212 theCode += '</body></html> \n';
\r
213 accessWin = window.open('', 'previewWin', 'menubar=0,scrollbars=1,resizable=1,width=600,height=600');
\r
214 accessWin.document.writeln(theCode);
\r
215 accessWin.document.close();
\r
219 //click function to launch tool window
\r
220 var launchTool = function () {
\r
221 window.open(ATutor.base_href + 'mods/_core/tool_manager/index.php?framed=1&popup=1&tool_file=' + ATutor.mods.editor.tool_file + '&cid=' + ATutor.mods.editor.content_id, 'newWin2', 'menubar=0,scrollbars=1,resizable=1,width=600,height=400');
\r
225 //set up click handlers and show/hide appropriate tools via setupPage
\r
226 var initialize = function () {
\r
227 jQuery("#previewtool").click(previewTool);
\r
228 jQuery(".tool").click(launchTool);
\r
229 jQuery("#formatting_radios > input").click(setupPage);
\r
230 headTool.enabledTitle = ATutor.mods.editor.head_enabled_title;
\r
231 headTool.disabledTitle = ATutor.mods.editor.head_disabled_title;
\r
232 pasteTool.enabledTitle = ATutor.mods.editor.paste_enabled_title;
\r
233 pasteTool.disabledTitle = ATutor.mods.editor.paste_disabled_title;
\r
234 filemanTool.enabledTitle = ATutor.mods.editor.fileman_enabled_title;
\r
235 filemanTool.disabledTitle = ATutor.mods.editor.fileman_disabled_title;
\r
236 accessibilityTool.enabledTitle = ATutor.mods.editor.accessibility_enabled_title;
\r
237 accessibilityTool.disabledTitle = ATutor.mods.editor.accessibility_disabled_title;
\r
241 jQuery(document).ready(initialize);
\r