1 /************************************************************************/
\r
3 /************************************************************************/
\r
4 /* Copyright (c) 2009 */
\r
5 /* Adaptive Technology Resource Centre / University of Toronto */
\r
7 /* This program is free software. You can redistribute it and/or */
\r
8 /* modify it under the terms of the GNU General Public License */
\r
9 /* as published by the Free Software Foundation. */
\r
10 /************************************************************************/
\r
17 trans = trans || {};
\r
18 trans.editor = trans.editor || {};
\r
21 var hiddenClass = "hidden";
\r
22 var enabledClass = "clickable";
\r
24 var hideIt = function (theElement, hiddenElement) {
\r
25 theElement.addClass(hiddenClass);
\r
26 hiddenElement.val("0");
\r
29 var showIt = function (theElement, hiddenElement) {
\r
30 theElement.removeClass(hiddenClass);
\r
31 hiddenElement.val("1");
\r
34 //hides or shows tool (toggle) and sets hidden input value appropriately.
\r
35 var doToggle = function (theElement, hiddenElement) {
\r
36 if (theElement.hasClass(hiddenClass)) {
\r
37 showIt(theElement, hiddenElement);
\r
39 hideIt(theElement, hiddenElement);
\r
43 //click function to launch accessibility validation window
\r
44 var launchAChecker = function () {
\r
45 var theCode = '<html><body onLoad="document.accessform.submit();"> \n';
\r
46 theCode += '<h1>'+trans.editor.processing_text+' .....</h1>\n';
\r
47 theCode += '<form action="'+trans.base_href+'home/editor/accessibility.php?popup=1" name="accessform" method="post"> \n';
\r
48 theCode += '<input type="hidden" name="_cid" value="'+jQuery("input[name=\_cid]").val()+'" /> \n';
\r
49 theCode += '<textarea name="body_text" style="display:none">' + tinyMCE.activeEditor.getContent() + '</textarea>\n';
\r
50 theCode += '<input type="submit" style="display:none" /></form> \n';
\r
51 theCode += '</body></html> \n';
\r
52 accessWin = window.open('', 'accessibilityWin', 'menubar=0,scrollbars=1,resizable=1,width=600,height=600');
\r
53 accessWin.document.writeln(theCode);
\r
54 accessWin.document.close();
\r
58 //AChecker variables
\r
59 var accessibilityTool = {
\r
60 toolId: "#accessibilitytool",
\r
61 enabledClass: enabledClass,
\r
62 enabledImage: "images/achecker.png",
\r
63 clickFunction: function () {
\r
66 disabledImage: "images/achecker_disabled.png"
\r
69 //customized head variables
\r
70 var headId = "#head";
\r
71 var displayheadId = "#displayhead";
\r
73 toolId: "#headtool",
\r
74 enabledClass: enabledClass,
\r
75 enabledImage: "images/custom_head.png",
\r
76 clickFunction: function () {
\r
77 doToggle(jQuery(headId), jQuery(displayheadId));
\r
79 disabledImage: "images/custom_head_disabled.png"
\r
82 //paste from file variables
\r
83 var pasteId = "#paste";
\r
84 var displaypasteId = "#displaypaste";
\r
86 toolId: "#pastetool",
\r
87 enabledClass: enabledClass,
\r
88 enabledImage: "images/paste.png",
\r
89 clickFunction: function () {
\r
90 doToggle(jQuery(pasteId), jQuery(displaypasteId));
\r
92 disabledImage: "images/paste_disabled.png"
\r
95 //click function to launch file manager window
\r
96 var launchFileManager = function () {
\r
97 window.open(trans.base_href + 'file_manager/index.php?framed=1&popup=1&cp=' + trans.editor.content_path + '&_course_id=' + trans.editor.course_id, 'newWin1', 'menubar=0,scrollbars=1,resizable=1,width=640,height=490');
\r
101 //file manager variables
\r
102 var filemanTool = {
\r
103 toolId: "#filemantool",
\r
104 enabledClass: enabledClass,
\r
105 enabledImage: "images/file-manager.png",
\r
106 clickFunction: function () {
\r
107 launchFileManager();
\r
109 disabledImage: "images/file-manager_disabled.png"
\r
112 //checks hidden variable and shows/hides element accordingly
\r
113 var setDisplay = function (theElement, hiddenElement) {
\r
114 if (hiddenElement.val() === '0') {
\r
115 theElement.addClass(hiddenClass);
\r
117 theElement.removeClass(hiddenClass);
\r
121 var disableTool = function (theTool) {
\r
122 var theToolElement = jQuery(theTool.toolId);
\r
123 theToolElement.removeClass(theTool.enabledClass);
\r
124 theToolElement.attr("src", trans.base_href + theTool.disabledImage);
\r
125 theToolElement.attr("title", theTool.disabledTitle);
\r
126 theToolElement.attr("alt", theTool.disabledTitle);
\r
127 theToolElement.unbind("click");
\r
130 var enableTool = function (theTool) {
\r
131 var theToolElement = jQuery(theTool.toolId);
\r
132 theToolElement.addClass(theTool.enabledClass);
\r
133 theToolElement.attr("src", trans.base_href + theTool.enabledImage);
\r
134 theToolElement.attr("title", theTool.enabledTitle);
\r
135 theToolElement.attr("alt", theTool.enabledTitle);
\r
136 theToolElement.click(theTool.clickFunction);
\r
139 //initialises values to show or hide them
\r
140 var setupPage = function () {
\r
141 var head = jQuery(headId);
\r
142 var displayhead = jQuery(displayheadId);
\r
143 var paste = jQuery(pasteId);
\r
144 var displaypaste = jQuery(displaypasteId);
\r
145 var textArea = jQuery("#textSpan");
\r
146 var weblink = jQuery("#weblinkSpan");
\r
147 var textAreaId = "body_text";
\r
148 if (jQuery("#weblink").attr("checked")) {
\r
149 disableTool(accessibilityTool);
\r
150 disableTool(headTool);
\r
151 disableTool(pasteTool);
\r
152 disableTool(filemanTool);
\r
154 hideIt(head, displayhead);
\r
155 hideIt(paste, displaypaste);
\r
156 if (tinyMCE.get(textAreaId)) {
\r
157 tinyMCE.execCommand('mceRemoveControl', false, textAreaId);
\r
161 } else if (jQuery("#html").attr("checked")) {
\r
162 enableTool(accessibilityTool);
\r
163 enableTool(headTool);
\r
164 enableTool(pasteTool);
\r
165 enableTool(filemanTool);
\r
167 setDisplay(head, displayhead);
\r
168 setDisplay(paste, displaypaste);
\r
169 if (trans.editor.editor_pref !== '1' && !tinyMCE.get(textAreaId)) {
\r
170 tinyMCE.execCommand('mceAddControl', false, textAreaId);
\r
175 disableTool(accessibilityTool);
\r
176 disableTool(headTool);
\r
177 enableTool(pasteTool);
\r
178 enableTool(filemanTool);
\r
180 hideIt(head, displayhead);
\r
181 setDisplay(paste, displaypaste);
\r
183 if (tinyMCE.get(textAreaId)) {
\r
184 tinyMCE.execCommand('mceRemoveControl', false, textAreaId);
\r
190 //click function to launch preview window
\r
191 var previewTool = function () {
\r
192 var theCode = '<html><body onLoad="document.accessform.submit();"> \n';
\r
193 theCode += '<h1>'+trans.editor.processing_text+' .....</h1>\n';
\r
194 theCode += '<form action="'+trans.base_href+'home/editor/preview.php?popup=1" name="accessform" method="post"> \n';
\r
195 theCode += '<input type="hidden" name="title" value="'+jQuery("input[name=title]").val()+'" /> \n';
\r
196 theCode += '<input type="hidden" name="_cid" value="'+jQuery("input[name=\_cid]").val()+'" /> \n';
\r
197 theCode += '<input type="hidden" name="formatting" value="'+jQuery("#formatting_radios input:radio:checked").val()+'" /> \n';
\r
198 if (jQuery("#weblink").attr("checked")) {
\r
199 theCode += '<input type="hidden" name="weblink_text" value="'+jQuery("#weblink_text").val()+'" /> \n';
\r
200 } else if (jQuery("#html").attr("checked")) {
\r
201 theCode += '<textarea name="body_text" style="display:none">' + tinyMCE.activeEditor.getContent() + '</textarea>\n';
\r
203 theCode += '<textarea name="body_text" style="display:none">' + jQuery("#body_text").val() + '</textarea>\n';
\r
205 theCode += '<input type="submit" style="display:none" /></form> \n';
\r
206 theCode += '</body></html> \n';
\r
207 accessWin = window.open('', 'previewWin', 'menubar=0,scrollbars=1,resizable=1,width=600,height=600');
\r
208 accessWin.document.writeln(theCode);
\r
209 accessWin.document.close();
\r
213 //click function to launch tool window
\r
214 var launchTool = function () {
\r
215 window.open(trans.base_href + 'home/tool_manager/index.php?framed=1&popup=1&tool_file=' + trans.editor.tool_file + '&_cid=' + trans.editor.content_id, 'newWin2', 'menubar=0,scrollbars=1,resizable=1,width=600,height=400');
\r
219 //set up click handlers and show/hide appropriate tools via setupPage
\r
220 var initialize = function () {
\r
221 jQuery("#previewtool").click(previewTool);
\r
222 jQuery(".tool").click(launchTool);
\r
223 jQuery("#formatting_radios > input").click(setupPage);
\r
224 headTool.enabledTitle = trans.editor.head_enabled_title;
\r
225 headTool.disabledTitle = trans.editor.head_disabled_title;
\r
226 pasteTool.enabledTitle = trans.editor.paste_enabled_title;
\r
227 pasteTool.disabledTitle = trans.editor.paste_disabled_title;
\r
228 filemanTool.enabledTitle = trans.editor.fileman_enabled_title;
\r
229 filemanTool.disabledTitle = trans.editor.fileman_disabled_title;
\r
230 accessibilityTool.enabledTitle = trans.editor.accessibility_enabled_title;
\r
231 accessibilityTool.disabledTitle = trans.editor.accessibility_disabled_title;
\r
235 jQuery(document).ready(initialize);
\r