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
26 var textAreaId = "body_text";
\r
28 var hideIt = function (theElement, hiddenElement) {
\r
29 theElement.addClass(hiddenClass);
\r
30 hiddenElement.val("0");
\r
33 var showIt = function (theElement, hiddenElement) {
\r
34 theElement.removeClass(hiddenClass);
\r
35 hiddenElement.val("1");
\r
38 //hides or shows tool (toggle) and sets hidden input value appropriately.
\r
39 var doToggle = function (theElement, hiddenElement) {
\r
40 if (theElement.hasClass(hiddenClass)) {
\r
41 showIt(theElement, hiddenElement);
\r
43 hideIt(theElement, hiddenElement);
\r
47 //click function to launch accessibility validation window
\r
48 var launchAChecker = function () {
\r
51 if (jQuery("#html_visual_editor").attr("checked")) {
\r
52 body_content = tinyMCE.activeEditor.getContent();
\r
54 body_content = jQuery("#"+textAreaId).val();
\r
57 var theCode = '<html><body onLoad="document.accessform.submit();"> \n';
\r
58 theCode += '<h1>'+ATutor.mods.editor.processing_text+' .....</h1>\n';
\r
59 theCode += '<form action="'+ATutor.base_href+'mods/_core/editor/accessibility.php?popup=1" name="accessform" method="post"> \n';
\r
60 theCode += '<input type="hidden" name="cid" value="'+jQuery("input[name=cid]").val()+'" /> \n';
\r
61 theCode += '<textarea name="body_text" style="display:none">' + body_content + '</textarea>\n';
\r
62 theCode += '<input type="submit" style="display:none" /></form> \n';
\r
63 theCode += '</body></html> \n';
\r
64 accessWin = window.open('', 'accessibilityWin', 'menubar=0,scrollbars=1,resizable=1,width=600,height=600');
\r
65 accessWin.document.writeln(theCode);
\r
66 accessWin.document.close();
\r
70 //AChecker variables
\r
71 var accessibilityTool = {
\r
72 toolId: "#accessibilitytool",
\r
73 enabledClass: enabledClass,
\r
74 enabledImage: "images/achecker.png",
\r
75 clickFunction: function () {
\r
78 disabledImage: "images/achecker_disabled.png"
\r
81 //customized head variables
\r
82 var headId = "#head";
\r
83 var displayheadId = "#displayhead";
\r
85 toolId: "#headtool",
\r
86 enabledClass: enabledClass,
\r
87 enabledImage: "images/custom_head.png",
\r
88 clickFunction: function () {
\r
89 doToggle(jQuery(headId), jQuery(displayheadId));
\r
91 disabledImage: "images/custom_head_disabled.png"
\r
94 //paste from file variables
\r
95 var pasteId = "#paste";
\r
96 var displaypasteId = "#displaypaste";
\r
98 toolId: "#pastetool",
\r
99 enabledClass: enabledClass,
\r
100 enabledImage: "images/paste.png",
\r
101 clickFunction: function () {
\r
102 doToggle(jQuery(pasteId), jQuery(displaypasteId));
\r
104 disabledImage: "images/paste_disabled.png"
\r
107 //click function to launch file manager window
\r
108 var launchFileManager = function () {
\r
109 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
113 //file manager variables
\r
114 var filemanTool = {
\r
115 toolId: "#filemantool",
\r
116 enabledClass: enabledClass,
\r
117 enabledImage: "images/file-manager.png",
\r
118 clickFunction: function () {
\r
119 launchFileManager();
\r
121 disabledImage: "images/file-manager_disabled.png"
\r
124 //checks hidden variable and shows/hides element accordingly
\r
125 var setDisplay = function (theElement, hiddenElement) {
\r
126 if (hiddenElement.val() === '0') {
\r
127 theElement.addClass(hiddenClass);
\r
129 theElement.removeClass(hiddenClass);
\r
133 var disableTool = function (theTool) {
\r
134 var theToolElement = jQuery(theTool.toolId);
\r
135 theToolElement.removeClass(theTool.enabledClass);
\r
136 theToolElement.attr("src", ATutor.base_href + theTool.disabledImage);
\r
137 theToolElement.attr("title", theTool.disabledTitle);
\r
138 theToolElement.attr("alt", theTool.disabledTitle);
\r
139 theToolElement.unbind("click");
\r
142 var enableTool = function (theTool) {
\r
143 var theToolElement = jQuery(theTool.toolId);
\r
144 theToolElement.addClass(theTool.enabledClass);
\r
145 theToolElement.attr("src", ATutor.base_href + theTool.enabledImage);
\r
146 theToolElement.attr("title", theTool.enabledTitle);
\r
147 theToolElement.attr("alt", theTool.enabledTitle);
\r
148 theToolElement.click(theTool.clickFunction);
\r
151 //initialises values to show or hide them
\r
152 var setupPage = function () {
\r
153 var head = jQuery(headId);
\r
154 var displayhead = jQuery(displayheadId);
\r
155 var paste = jQuery(pasteId);
\r
156 var displaypaste = jQuery(displaypasteId);
\r
157 var textArea = jQuery("#textSpan");
\r
158 var weblink = jQuery("#weblinkSpan");
\r
160 // turn on/off visual editor based on the selected formatting tool
\r
161 if (jQuery("#html_visual_editor").attr("checked") && !tinyMCE.get(textAreaId)) {
\r
162 tinyMCE.execCommand('mceAddControl', false, textAreaId);
\r
163 } else if (tinyMCE.get(textAreaId)) {
\r
164 tinyMCE.execCommand('mceRemoveControl', false, textAreaId);
\r
167 if (jQuery("#weblink").attr("checked")) {
\r
168 disableTool(accessibilityTool);
\r
169 disableTool(headTool);
\r
170 disableTool(pasteTool);
\r
171 disableTool(filemanTool);
\r
173 hideIt(head, displayhead);
\r
174 hideIt(paste, displaypaste);
\r
177 } else if (jQuery("#html").attr("checked") || jQuery("#html_visual_editor").attr("checked")) {
\r
178 enableTool(accessibilityTool);
\r
179 enableTool(headTool);
\r
180 enableTool(pasteTool);
\r
181 enableTool(filemanTool);
\r
183 setDisplay(head, displayhead);
\r
184 setDisplay(paste, displaypaste);
\r
188 disableTool(accessibilityTool);
\r
189 disableTool(headTool);
\r
190 enableTool(pasteTool);
\r
191 enableTool(filemanTool);
\r
193 hideIt(head, displayhead);
\r
194 setDisplay(paste, displaypaste);
\r
200 //click function to launch preview window
\r
201 var previewTool = function () {
\r
202 var theCode = '<html><body onLoad="document.accessform.submit();"> \n';
\r
203 theCode += '<h1>'+ATutor.mods.editor.processing_text+' .....</h1>\n';
\r
204 theCode += '<form action="'+ATutor.base_href+'mods/_core/editor/preview.php?popup=1" name="accessform" method="post"> \n';
\r
205 theCode += '<input type="hidden" name="title" value="'+jQuery("input[name=title]").val()+'" /> \n';
\r
206 theCode += '<input type="hidden" name="cid" value="'+jQuery("input[name=cid]").val()+'" /> \n';
\r
207 theCode += '<input type="hidden" name="formatting" value="'+jQuery("#formatting_radios input:radio:checked").val()+'" /> \n';
\r
208 jQuery("input[name*='glossary_defs[']").each(function() {
\r
209 theCode += '<input type="hidden" name="'+this.name+'" value="'+jQuery(this).val()+'" /> \n';
\r
211 if (jQuery("#weblink").attr("checked")) {
\r
212 theCode += '<input type="hidden" name="weblink_text" value="'+jQuery("#weblink_text").val()+'" /> \n';
\r
213 } else if (jQuery("#html_visual_editor").attr("checked")) {
\r
214 theCode += '<textarea name="body_text" style="display:none">' + tinyMCE.activeEditor.getContent() + '</textarea>\n';
\r
216 theCode += '<textarea name="body_text" style="display:none">' + jQuery("#"+textAreaId).val() + '</textarea>\n';
\r
218 theCode += '<input type="submit" style="display:none" /></form> \n';
\r
219 theCode += '</body></html> \n';
\r
220 accessWin = window.open('', 'previewWin', 'menubar=0,scrollbars=1,resizable=1,width=600,height=600');
\r
221 accessWin.document.writeln(theCode);
\r
222 accessWin.document.close();
\r
226 //click function to launch tool window
\r
227 var launchTool = function () {
\r
228 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
232 //set up click handlers and show/hide appropriate tools via setupPage
\r
233 var initialize = function () {
\r
234 jQuery("#previewtool").click(previewTool);
\r
235 jQuery(".tool").click(launchTool);
\r
236 jQuery("#formatting_radios > input").click(setupPage);
\r
237 headTool.enabledTitle = ATutor.mods.editor.head_enabled_title;
\r
238 headTool.disabledTitle = ATutor.mods.editor.head_disabled_title;
\r
239 pasteTool.enabledTitle = ATutor.mods.editor.paste_enabled_title;
\r
240 pasteTool.disabledTitle = ATutor.mods.editor.paste_disabled_title;
\r
241 filemanTool.enabledTitle = ATutor.mods.editor.fileman_enabled_title;
\r
242 filemanTool.disabledTitle = ATutor.mods.editor.fileman_disabled_title;
\r
243 accessibilityTool.enabledTitle = ATutor.mods.editor.accessibility_enabled_title;
\r
244 accessibilityTool.disabledTitle = ATutor.mods.editor.accessibility_disabled_title;
\r
248 jQuery(document).ready(initialize);
\r