Merge lp:~openerp-dev/openerp-web/trunk-mail-ie-chm into lp:openerp-web
- trunk-mail-ie-chm
- Merge into trunk
Proposed by
Christophe Matthieu (OpenERP)
Status: | Work in progress |
---|---|
Proposed branch: | lp:~openerp-dev/openerp-web/trunk-mail-ie-chm |
Merge into: | lp:openerp-web |
Diff against target: |
1326 lines (+378/-341) 2 files modified
addons/web/static/lib/cleditor/jquery.cleditor.js (+374/-336) addons/web/static/src/js/view_form.js (+4/-5) |
To merge this branch: | bzr merge lp:~openerp-dev/openerp-web/trunk-mail-ie-chm |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
OpenERP R&D Web Team | Pending | ||
Review via email: mp+139924@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
- 3613. By Christophe Matthieu (OpenERP)
-
[FIX] web cleditor: bind and trigger event change inside cleditor
- 3614. By Christophe Matthieu (OpenERP)
-
[IMP] cleditor: rewrite braces, spaces, ponctuation
- 3615. By Christophe Matthieu (OpenERP)
-
[IMP] web form: fieldtexthtml
- 3616. By Christophe Matthieu (OpenERP)
-
[IMP] cleditor: remove spaces
- 3617. By Christophe Matthieu (OpenERP)
-
[MERGE] from trunk
Unmerged revisions
- 3617. By Christophe Matthieu (OpenERP)
-
[MERGE] from trunk
- 3616. By Christophe Matthieu (OpenERP)
-
[IMP] cleditor: remove spaces
- 3615. By Christophe Matthieu (OpenERP)
-
[IMP] web form: fieldtexthtml
- 3614. By Christophe Matthieu (OpenERP)
-
[IMP] cleditor: rewrite braces, spaces, ponctuation
- 3613. By Christophe Matthieu (OpenERP)
-
[FIX] web cleditor: bind and trigger event change inside cleditor
- 3612. By Christophe Matthieu (OpenERP)
-
[IMP] web form: change for cleditor field html
- 3611. By Christophe Matthieu (OpenERP)
-
[IMP] view_form: add console in cleditor for ie debugging
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'addons/web/static/lib/cleditor/jquery.cleditor.js' | |||
2 | --- addons/web/static/lib/cleditor/jquery.cleditor.js 2012-10-29 14:35:27 +0000 | |||
3 | +++ addons/web/static/lib/cleditor/jquery.cleditor.js 2012-12-21 17:26:22 +0000 | |||
4 | @@ -12,7 +12,8 @@ | |||
5 | 12 | // @output_file_name jquery.cleditor.min.js | 12 | // @output_file_name jquery.cleditor.min.js |
6 | 13 | // ==/ClosureCompiler== | 13 | // ==/ClosureCompiler== |
7 | 14 | 14 | ||
9 | 15 | (function($) { | 15 | (function ($) { |
10 | 16 | 'use strict'; | ||
11 | 16 | 17 | ||
12 | 17 | //============== | 18 | //============== |
13 | 18 | // jQuery Plugin | 19 | // jQuery Plugin |
14 | @@ -25,93 +26,91 @@ | |||
15 | 25 | width: 500, // width not including margins, borders or padding | 26 | width: 500, // width not including margins, borders or padding |
16 | 26 | height: 250, // height not including margins, borders or padding | 27 | height: 250, // height not including margins, borders or padding |
17 | 27 | controls: // controls to add to the toolbar | 28 | controls: // controls to add to the toolbar |
22 | 28 | "bold italic underline strikethrough subscript superscript | font size " + | 29 | 'bold italic underline strikethrough subscript superscript | font size ' + |
23 | 29 | "style | color highlight removeformat | bullets numbering | outdent " + | 30 | 'style | color highlight removeformat | bullets numbering | outdent ' + |
24 | 30 | "indent | alignleft center alignright justify | undo redo | " + | 31 | 'indent | alignleft center alignright justify | undo redo | ' + |
25 | 31 | "rule image link unlink | cut copy paste pastetext | print source", | 32 | 'rule image link unlink | cut copy paste pastetext | print source', |
26 | 32 | colors: // colors in the color popup | 33 | colors: // colors in the color popup |
34 | 33 | "FFF FCC FC9 FF9 FFC 9F9 9FF CFF CCF FCF " + | 34 | 'FFF FCC FC9 FF9 FFC 9F9 9FF CFF CCF FCF ' + |
35 | 34 | "CCC F66 F96 FF6 FF3 6F9 3FF 6FF 99F F9F " + | 35 | 'CCC F66 F96 FF6 FF3 6F9 3FF 6FF 99F F9F ' + |
36 | 35 | "BBB F00 F90 FC6 FF0 3F3 6CC 3CF 66C C6C " + | 36 | 'BBB F00 F90 FC6 FF0 3F3 6CC 3CF 66C C6C ' + |
37 | 36 | "999 C00 F60 FC3 FC0 3C0 0CC 36F 63F C3C " + | 37 | '999 C00 F60 FC3 FC0 3C0 0CC 36F 63F C3C ' + |
38 | 37 | "666 900 C60 C93 990 090 399 33F 60C 939 " + | 38 | '666 900 C60 C93 990 090 399 33F 60C 939 ' + |
39 | 38 | "333 600 930 963 660 060 366 009 339 636 " + | 39 | '333 600 930 963 660 060 366 009 339 636 ' + |
40 | 39 | "000 300 630 633 330 030 033 006 309 303", | 40 | '000 300 630 633 330 030 033 006 309 303', |
41 | 40 | fonts: // font names in the font popup | 41 | fonts: // font names in the font popup |
44 | 41 | "Arial,Arial Black,Comic Sans MS,Courier New,Narrow,Garamond," + | 42 | 'Arial, Arial Black, Comic Sans MS, Courier New, Narrow, Garamond, ' + |
45 | 42 | "Georgia,Impact,Sans Serif,Serif,Tahoma,Trebuchet MS,Verdana", | 43 | 'Georgia, Impact, Sans Serif, Serif, Tahoma, Trebuchet MS, Verdana', |
46 | 43 | sizes: // sizes in the font size popup | 44 | sizes: // sizes in the font size popup |
48 | 44 | "1,2,3,4,5,6,7", | 45 | '1, 2, 3, 4, 5, 6, 7', |
49 | 45 | styles: // styles in the style popup | 46 | styles: // styles in the style popup |
53 | 46 | [["Paragraph", "<p>"], ["Header 1", "<h1>"], ["Header 2", "<h2>"], | 47 | [['Paragraph', '<p>'], ['Header 1', '<h1>'], ['Header 2', '<h2>'], |
54 | 47 | ["Header 3", "<h3>"], ["Header 4","<h4>"], ["Header 5","<h5>"], | 48 | ['Header 3', '<h3>'], ['Header 4', '<h4>'], ['Header 5', '<h5>'], |
55 | 48 | ["Header 6","<h6>"]], | 49 | ['Header 6', '<h6>']], |
56 | 49 | useCSS: false, // use CSS to style HTML when possible (not supported in ie) | 50 | useCSS: false, // use CSS to style HTML when possible (not supported in ie) |
57 | 50 | docType: // Document type contained within the editor | 51 | docType: // Document type contained within the editor |
59 | 51 | '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">', | 52 | '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">', |
60 | 52 | docCSSFile: // CSS file used to style the document contained within the editor | 53 | docCSSFile: // CSS file used to style the document contained within the editor |
62 | 53 | "", | 54 | '', |
63 | 54 | bodyStyle: // style to assign to document body contained within the editor | 55 | bodyStyle: // style to assign to document body contained within the editor |
67 | 55 | "margin:4px; font:10pt Arial,Verdana; cursor:text" | 56 | 'margin:4px; font:10pt Arial, Verdana; cursor:text' |
68 | 56 | }, | 57 | }, |
66 | 57 | |||
69 | 58 | // Define all usable toolbar buttons - the init string property is | 58 | // Define all usable toolbar buttons - the init string property is |
70 | 59 | // expanded during initialization back into the buttons object and | 59 | // expanded during initialization back into the buttons object and |
71 | 60 | // seperate object properties are created for each button. | 60 | // seperate object properties are created for each button. |
73 | 61 | // e.g. buttons.size.title = "Font Size" | 61 | // e.g. buttons.size.title = 'Font Size' |
74 | 62 | buttons: { | 62 | buttons: { |
76 | 63 | // name,title,command,popupName (""=use name) | 63 | // name, title, command, popupName (''=use name) |
77 | 64 | init: | 64 | init: |
112 | 65 | "bold,,|" + | 65 | 'bold,,|' + |
113 | 66 | "italic,,|" + | 66 | 'italic,,|' + |
114 | 67 | "underline,,|" + | 67 | 'underline,,|' + |
115 | 68 | "strikethrough,,|" + | 68 | 'strikethrough,,|' + |
116 | 69 | "subscript,,|" + | 69 | 'subscript,,|' + |
117 | 70 | "superscript,,|" + | 70 | 'superscript,,|' + |
118 | 71 | "font,,fontname,|" + | 71 | 'font,,fontname,|' + |
119 | 72 | "size,Font Size,fontsize,|" + | 72 | 'size,Font Size,fontsize,|' + |
120 | 73 | "style,,formatblock,|" + | 73 | 'style,,formatblock,|' + |
121 | 74 | "color,Font Color,forecolor,|" + | 74 | 'color,Font Color,forecolor,|' + |
122 | 75 | "highlight,Text Highlight Color,hilitecolor,color|" + | 75 | 'highlight,Text Highlight Color,hilitecolor,color|' + |
123 | 76 | "removeformat,Remove Formatting,|" + | 76 | 'removeformat,Remove Formatting,|' + |
124 | 77 | "bullets,,insertunorderedlist|" + | 77 | 'bullets,,insertunorderedlist|' + |
125 | 78 | "numbering,,insertorderedlist|" + | 78 | 'numbering,,insertorderedlist|' + |
126 | 79 | "outdent,,|" + | 79 | 'outdent,,|' + |
127 | 80 | "indent,,|" + | 80 | 'indent,,|' + |
128 | 81 | "alignleft,Align Text Left,justifyleft|" + | 81 | 'alignleft,Align Text Left,justifyleft|' + |
129 | 82 | "center,,justifycenter|" + | 82 | 'center,,justifycenter|' + |
130 | 83 | "alignright,Align Text Right,justifyright|" + | 83 | 'alignright,Align Text Right,justifyright|' + |
131 | 84 | "justify,,justifyfull|" + | 84 | 'justify,,justifyfull|' + |
132 | 85 | "undo,,|" + | 85 | 'undo,,|' + |
133 | 86 | "redo,,|" + | 86 | 'redo,,|' + |
134 | 87 | "rule,Insert Horizontal Rule,inserthorizontalrule|" + | 87 | 'rule,Insert Horizontal Rule,inserthorizontalrule|' + |
135 | 88 | "image,Insert Image,insertimage,url|" + | 88 | 'image,Insert Image,insertimage,url|' + |
136 | 89 | "link,Insert Hyperlink,createlink,url|" + | 89 | 'link,Insert Hyperlink,createlink,url|' + |
137 | 90 | "unlink,Remove Hyperlink,|" + | 90 | 'unlink,Remove Hyperlink,|' + |
138 | 91 | "cut,,|" + | 91 | 'cut,,|' + |
139 | 92 | "copy,,|" + | 92 | 'copy,,|' + |
140 | 93 | "paste,,|" + | 93 | 'paste,,|' + |
141 | 94 | "pastetext,Paste as Text,inserthtml,|" + | 94 | 'pastetext,Paste as Text,inserthtml,|' + |
142 | 95 | "print,,|" + | 95 | 'print,,|' + |
143 | 96 | "source,Show Source" | 96 | 'source,Show Source' |
144 | 97 | }, | 97 | }, |
111 | 98 | |||
145 | 99 | // imagesPath - returns the path to the images folder | 98 | // imagesPath - returns the path to the images folder |
147 | 100 | imagesPath: function() { return imagesPath(); } | 99 | imagesPath: function () { return imagesPath(); } |
148 | 101 | 100 | ||
149 | 102 | }; | 101 | }; |
150 | 103 | 102 | ||
151 | 104 | // cleditor - creates a new editor for each of the matched textareas | 103 | // cleditor - creates a new editor for each of the matched textareas |
153 | 105 | $.fn.cleditor = function(options) { | 104 | $.fn.cleditor = function (options) { |
154 | 106 | 105 | ||
155 | 107 | // Create a new jQuery object to hold the results | 106 | // Create a new jQuery object to hold the results |
156 | 108 | var $result = $([]); | 107 | var $result = $([]); |
157 | 109 | 108 | ||
158 | 110 | // Loop through all matching textareas and create the editors | 109 | // Loop through all matching textareas and create the editors |
161 | 111 | this.each(function(idx, elem) { | 110 | this.each(function (idx, elem) { |
162 | 112 | if (elem.tagName == "TEXTAREA") { | 111 | if (elem.tagName === 'TEXTAREA') { |
163 | 113 | var data = $.data(elem, CLEDITOR); | 112 | var data = $.data(elem, CLEDITOR); |
165 | 114 | if (!data) data = new cleditor(elem, options); | 113 | if (!data) {data = new cleditor(elem, options);} |
166 | 115 | $result = $result.add(data); | 114 | $result = $result.add(data); |
167 | 116 | } | 115 | } |
168 | 117 | }); | 116 | }); |
169 | @@ -128,45 +127,40 @@ | |||
170 | 128 | var | 127 | var |
171 | 129 | 128 | ||
172 | 130 | // Misc constants | 129 | // Misc constants |
212 | 131 | BACKGROUND_COLOR = "backgroundColor", | 130 | BACKGROUND_COLOR = 'backgroundColor', |
213 | 132 | BUTTON = "button", | 131 | BUTTON = 'button', |
214 | 133 | BUTTON_NAME = "buttonName", | 132 | BUTTON_NAME = 'buttonName', |
215 | 134 | CHANGE = "change", | 133 | CHANGE = 'change', |
216 | 135 | CLEDITOR = "cleditor", | 134 | CLEDITOR = 'cleditor', |
217 | 136 | CLICK = "click", | 135 | CLICK = 'click', |
218 | 137 | DISABLED = "disabled", | 136 | DISABLED = 'disabled', |
219 | 138 | DIV_TAG = "<div>", | 137 | DIV_TAG = '<div>', |
220 | 139 | TRANSPARENT = "transparent", | 138 | TRANSPARENT = 'transparent', |
221 | 140 | UNSELECTABLE = "unselectable", | 139 | UNSELECTABLE = 'unselectable', |
222 | 141 | 140 | // Class name constants | |
223 | 142 | // Class name constants | 141 | MAIN_CLASS = 'cleditorMain', // main containing div |
224 | 143 | MAIN_CLASS = "cleditorMain", // main containing div | 142 | TOOLBAR_CLASS = 'cleditorToolbar', // toolbar div inside main div |
225 | 144 | TOOLBAR_CLASS = "cleditorToolbar", // toolbar div inside main div | 143 | GROUP_CLASS = 'cleditorGroup', // group divs inside the toolbar div |
226 | 145 | GROUP_CLASS = "cleditorGroup", // group divs inside the toolbar div | 144 | BUTTON_CLASS = 'cleditorButton', // button divs inside group div |
227 | 146 | BUTTON_CLASS = "cleditorButton", // button divs inside group div | 145 | DISABLED_CLASS = 'cleditorDisabled', // disabled button divs |
228 | 147 | DISABLED_CLASS = "cleditorDisabled",// disabled button divs | 146 | DIVIDER_CLASS = 'cleditorDivider', // divider divs inside group div |
229 | 148 | DIVIDER_CLASS = "cleditorDivider", // divider divs inside group div | 147 | POPUP_CLASS = 'cleditorPopup', // popup divs inside body |
230 | 149 | POPUP_CLASS = "cleditorPopup", // popup divs inside body | 148 | LIST_CLASS = 'cleditorList', // list popup divs inside body |
231 | 150 | LIST_CLASS = "cleditorList", // list popup divs inside body | 149 | COLOR_CLASS = 'cleditorColor', // color popup div inside body |
232 | 151 | COLOR_CLASS = "cleditorColor", // color popup div inside body | 150 | PROMPT_CLASS = 'cleditorPrompt', // prompt popup divs inside body |
233 | 152 | PROMPT_CLASS = "cleditorPrompt", // prompt popup divs inside body | 151 | MSG_CLASS = 'cleditorMsg', // message popup div inside body |
234 | 153 | MSG_CLASS = "cleditorMsg", // message popup div inside body | 152 | |
235 | 154 | 153 | // Test for ie | |
236 | 155 | // Test for ie | 154 | ie = $.browser.msie, |
237 | 156 | ie = $.browser.msie, | 155 | ie6 = /msie\s6/i.test(navigator.userAgent), |
238 | 157 | ie6 = /msie\s6/i.test(navigator.userAgent), | 156 | // Test for iPhone/iTouch/iPad |
239 | 158 | 157 | iOS = /iphone|ipad|ipod/i.test(navigator.userAgent), | |
240 | 159 | // Test for iPhone/iTouch/iPad | 158 | // Popups are created once as needed and shared by all editor instances |
241 | 160 | iOS = /iphone|ipad|ipod/i.test(navigator.userAgent), | 159 | popups = {}, |
242 | 161 | 160 | // Used to prevent the document click event from being bound more than once | |
243 | 162 | // Popups are created once as needed and shared by all editor instances | 161 | documentClickAssigned, |
244 | 163 | popups = {}, | 162 | // Local copy of the buttons object |
245 | 164 | 163 | buttons = $.cleditor.buttons; | |
207 | 165 | // Used to prevent the document click event from being bound more than once | ||
208 | 166 | documentClickAssigned, | ||
209 | 167 | |||
210 | 168 | // Local copy of the buttons object | ||
211 | 169 | buttons = $.cleditor.buttons; | ||
246 | 170 | 164 | ||
247 | 171 | //=============== | 165 | //=============== |
248 | 172 | // Initialization | 166 | // Initialization |
249 | @@ -174,15 +168,15 @@ | |||
250 | 174 | 168 | ||
251 | 175 | // Expand the buttons.init string back into the buttons object | 169 | // Expand the buttons.init string back into the buttons object |
252 | 176 | // and create seperate object properties for each button. | 170 | // and create seperate object properties for each button. |
256 | 177 | // e.g. buttons.size.title = "Font Size" | 171 | // e.g. buttons.size.title = 'Font Size' |
257 | 178 | $.each(buttons.init.split("|"), function(idx, button) { | 172 | $.each(buttons.init.split('|'), function (idx, button) { |
258 | 179 | var items = button.split(","), name = items[0]; | 173 | var items = button.split(','), name = items[0]; |
259 | 180 | buttons[name] = { | 174 | buttons[name] = { |
265 | 181 | stripIndex: idx, | 175 | stripIndex: idx, |
266 | 182 | name: name, | 176 | name: name, |
267 | 183 | title: items[1] === "" ? name.charAt(0).toUpperCase() + name.substr(1) : items[1], | 177 | title: items[1] === '' ? name.charAt(0).toUpperCase() + name.substr(1) : items[1], |
268 | 184 | command: items[2] === "" ? name : items[2], | 178 | command: items[2] === '' ? name : items[2], |
269 | 185 | popupName: items[3] === "" ? name : items[3] | 179 | popupName: items[3] === '' ? name : items[3] |
270 | 186 | }; | 180 | }; |
271 | 187 | }); | 181 | }); |
272 | 188 | delete buttons.init; | 182 | delete buttons.init; |
273 | @@ -192,7 +186,7 @@ | |||
274 | 192 | //============ | 186 | //============ |
275 | 193 | 187 | ||
276 | 194 | // cleditor - creates a new editor for the passed in textarea element | 188 | // cleditor - creates a new editor for the passed in textarea element |
278 | 195 | cleditor = function(area, options) { | 189 | var cleditor = function (area, options) { |
279 | 196 | 190 | ||
280 | 197 | var editor = this; | 191 | var editor = this; |
281 | 198 | 192 | ||
282 | @@ -203,7 +197,7 @@ | |||
283 | 203 | var $area = editor.$area = $(area) | 197 | var $area = editor.$area = $(area) |
284 | 204 | .hide() | 198 | .hide() |
285 | 205 | .data(CLEDITOR, editor) | 199 | .data(CLEDITOR, editor) |
287 | 206 | .blur(function() { | 200 | .blur(function () { |
288 | 207 | // Update the iframe when the textarea loses focus | 201 | // Update the iframe when the textarea loses focus |
289 | 208 | updateFrame(editor, true); | 202 | updateFrame(editor, true); |
290 | 209 | }); | 203 | }); |
291 | @@ -225,11 +219,11 @@ | |||
292 | 225 | .appendTo($toolbar); | 219 | .appendTo($toolbar); |
293 | 226 | 220 | ||
294 | 227 | // Add the buttons to the toolbar | 221 | // Add the buttons to the toolbar |
297 | 228 | $.each(options.controls.split(" "), function(idx, buttonName) { | 222 | $.each(options.controls.split(' '), function (idx, buttonName) { |
298 | 229 | if (buttonName === "") return true; | 223 | if (buttonName === '') {return true;} |
299 | 230 | 224 | ||
300 | 231 | // Divider | 225 | // Divider |
302 | 232 | if (buttonName == "|") { | 226 | if (buttonName === '|') { |
303 | 233 | 227 | ||
304 | 234 | // Add a new divider to the group | 228 | // Add a new divider to the group |
305 | 235 | var $div = $(DIV_TAG) | 229 | var $div = $(DIV_TAG) |
306 | @@ -253,27 +247,28 @@ | |||
307 | 253 | var $buttonDiv = $(DIV_TAG) | 247 | var $buttonDiv = $(DIV_TAG) |
308 | 254 | .data(BUTTON_NAME, button.name) | 248 | .data(BUTTON_NAME, button.name) |
309 | 255 | .addClass(BUTTON_CLASS) | 249 | .addClass(BUTTON_CLASS) |
311 | 256 | .attr("title", button.title) | 250 | .attr('title', button.title) |
312 | 257 | .bind(CLICK, $.proxy(buttonClick, editor)) | 251 | .bind(CLICK, $.proxy(buttonClick, editor)) |
313 | 258 | .appendTo($group) | 252 | .appendTo($group) |
314 | 259 | .hover(hoverEnter, hoverLeave); | 253 | .hover(hoverEnter, hoverLeave); |
315 | 260 | 254 | ||
316 | 261 | // Prepare the button image | 255 | // Prepare the button image |
317 | 262 | var map = {}; | 256 | var map = {}; |
321 | 263 | if (button.css) map = button.css; | 257 | if (button.css) {map = button.css;} |
322 | 264 | else if (button.image) map.backgroundImage = imageUrl(button.image); | 258 | else if (button.image) {map.backgroundImage = imageUrl(button.image);} |
323 | 265 | if (button.stripIndex) map.backgroundPosition = button.stripIndex * -24; | 259 | if (button.stripIndex) {map.backgroundPosition = button.stripIndex * -24;} |
324 | 266 | $buttonDiv.css(map); | 260 | $buttonDiv.css(map); |
325 | 267 | 261 | ||
326 | 268 | // Add the unselectable attribute for ie | 262 | // Add the unselectable attribute for ie |
329 | 269 | if (ie) | 263 | if (ie) { |
330 | 270 | $buttonDiv.attr(UNSELECTABLE, "on"); | 264 | $buttonDiv.attr(UNSELECTABLE, 'on'); |
331 | 265 | } | ||
332 | 271 | 266 | ||
333 | 272 | // Create the popup | 267 | // Create the popup |
336 | 273 | if (button.popupName) | 268 | if (button.popupName) { |
337 | 274 | createPopup(button.popupName, options, button.popupClass, | 269 | createPopup(button.popupName, options, button.popupClass, |
338 | 275 | button.popupContent, button.popupHover); | 270 | button.popupContent, button.popupHover); |
340 | 276 | 271 | } | |
341 | 277 | } | 272 | } |
342 | 278 | 273 | ||
343 | 279 | }); | 274 | }); |
344 | @@ -284,23 +279,25 @@ | |||
345 | 284 | 279 | ||
346 | 285 | // Bind the document click event handler | 280 | // Bind the document click event handler |
347 | 286 | if (!documentClickAssigned) { | 281 | if (!documentClickAssigned) { |
349 | 287 | $(document).click(function(e) { | 282 | $(document).click(function (e) { |
350 | 288 | // Dismiss all non-prompt popups | 283 | // Dismiss all non-prompt popups |
351 | 289 | var $target = $(e.target); | 284 | var $target = $(e.target); |
353 | 290 | if (!$target.add($target.parents()).is("." + PROMPT_CLASS)) | 285 | if (!$target.add($target.parents()).is('.' + PROMPT_CLASS)) { |
354 | 291 | hidePopups(); | 286 | hidePopups(); |
355 | 287 | } | ||
356 | 292 | }); | 288 | }); |
357 | 293 | documentClickAssigned = true; | 289 | documentClickAssigned = true; |
358 | 294 | } | 290 | } |
359 | 295 | 291 | ||
360 | 296 | // Bind the window resize event when the width or height is auto or % | 292 | // Bind the window resize event when the width or height is auto or % |
363 | 297 | if (/auto|%/.test("" + options.width + options.height)) | 293 | if (/auto|%/.test('' + options.width + options.height)) { |
364 | 298 | $(window).resize(function() { | 294 | $(window).resize(function () { |
365 | 299 | // CHM Note MonkeyPatch: if the DOM is not remove, refresh the cleditor | 295 | // CHM Note MonkeyPatch: if the DOM is not remove, refresh the cleditor |
366 | 300 | if(editor.$main.parent().parent().size()) { | 296 | if(editor.$main.parent().parent().size()) { |
367 | 301 | refresh(editor); | 297 | refresh(editor); |
368 | 302 | } | 298 | } |
369 | 303 | }); | 299 | }); |
370 | 300 | } | ||
371 | 304 | 301 | ||
372 | 305 | // Create the iframe and resize the controls | 302 | // Create the iframe and resize the controls |
373 | 306 | refresh(editor); | 303 | refresh(editor); |
374 | @@ -311,40 +308,39 @@ | |||
375 | 311 | // Public Methods | 308 | // Public Methods |
376 | 312 | //=============== | 309 | //=============== |
377 | 313 | 310 | ||
380 | 314 | var fn = cleditor.prototype, | 311 | var fn = cleditor.prototype, |
379 | 315 | |||
381 | 316 | // Expose the following private functions as methods on the cleditor object. | 312 | // Expose the following private functions as methods on the cleditor object. |
382 | 317 | // The closure compiler will rename the private functions. However, the | 313 | // The closure compiler will rename the private functions. However, the |
383 | 318 | // exposed method names on the cleditor object will remain fixed. | 314 | // exposed method names on the cleditor object will remain fixed. |
384 | 319 | methods = [ | 315 | methods = [ |
398 | 320 | ["clear", clear], | 316 | ['clear', clear], |
399 | 321 | ["disable", disable], | 317 | ['disable', disable], |
400 | 322 | ["execCommand", execCommand], | 318 | ['execCommand', execCommand], |
401 | 323 | ["focus", focus], | 319 | ['focus', focus], |
402 | 324 | ["hidePopups", hidePopups], | 320 | ['hidePopups', hidePopups], |
403 | 325 | ["sourceMode", sourceMode, true], | 321 | ['sourceMode', sourceMode, true], |
404 | 326 | ["refresh", refresh], | 322 | ['refresh', refresh], |
405 | 327 | ["select", select], | 323 | ['select', select], |
406 | 328 | ["selectedHTML", selectedHTML, true], | 324 | ['selectedHTML', selectedHTML, true], |
407 | 329 | ["selectedText", selectedText, true], | 325 | ['selectedText', selectedText, true], |
408 | 330 | ["showMessage", showMessage], | 326 | ['showMessage', showMessage], |
409 | 331 | ["updateFrame", updateFrame], | 327 | ['updateFrame', updateFrame], |
410 | 332 | ["updateTextArea", updateTextArea] | 328 | ['updateTextArea', updateTextArea] |
411 | 333 | ]; | 329 | ]; |
412 | 334 | 330 | ||
415 | 335 | $.each(methods, function(idx, method) { | 331 | $.each(methods, function (idx, method) { |
416 | 336 | fn[method[0]] = function() { | 332 | fn[method[0]] = function () { |
417 | 337 | var editor = this, args = [editor]; | 333 | var editor = this, args = [editor]; |
418 | 338 | // using each here would cast booleans into objects! | 334 | // using each here would cast booleans into objects! |
419 | 339 | for(var x = 0; x < arguments.length; x++) {args.push(arguments[x]);} | 335 | for(var x = 0; x < arguments.length; x++) {args.push(arguments[x]);} |
420 | 340 | var result = method[1].apply(editor, args); | 336 | var result = method[1].apply(editor, args); |
422 | 341 | if (method[2]) return result; | 337 | if (method[2]) {return result;} |
423 | 342 | return editor; | 338 | return editor; |
424 | 343 | }; | 339 | }; |
425 | 344 | }); | 340 | }); |
426 | 345 | 341 | ||
429 | 346 | // change - shortcut for .bind("change", handler) or .trigger("change") | 342 | // change - shortcut for .bind('change', handler) or .trigger('change') |
430 | 347 | fn.change = function(handler) { | 343 | fn.change = function (handler) { |
431 | 348 | var $this = $(this); | 344 | var $this = $(this); |
432 | 349 | return handler ? $this.bind(CHANGE, handler) : $this.trigger(CHANGE); | 345 | return handler ? $this.bind(CHANGE, handler) : $this.trigger(CHANGE); |
433 | 350 | }; | 346 | }; |
434 | @@ -356,33 +352,35 @@ | |||
435 | 356 | // buttonClick - click event handler for toolbar buttons | 352 | // buttonClick - click event handler for toolbar buttons |
436 | 357 | function buttonClick(e) { | 353 | function buttonClick(e) { |
437 | 358 | 354 | ||
443 | 359 | var editor = this, | 355 | var editor = this, |
444 | 360 | buttonDiv = e.target, | 356 | buttonDiv = e.target, |
445 | 361 | buttonName = $.data(buttonDiv, BUTTON_NAME), | 357 | buttonName = $.data(buttonDiv, BUTTON_NAME), |
446 | 362 | button = buttons[buttonName], | 358 | button = buttons[buttonName], |
447 | 363 | popupName = button.popupName, | 359 | popupName = button.popupName, |
448 | 364 | popup = popups[popupName]; | 360 | popup = popups[popupName]; |
449 | 365 | 361 | ||
450 | 366 | // Check if disabled | 362 | // Check if disabled |
452 | 367 | if (editor.disabled || $(buttonDiv).attr(DISABLED) == DISABLED) | 363 | if (editor.disabled || $(buttonDiv).attr(DISABLED) === DISABLED) { |
453 | 368 | return; | 364 | return; |
454 | 365 | } | ||
455 | 369 | 366 | ||
456 | 370 | // Fire the buttonClick event | 367 | // Fire the buttonClick event |
457 | 371 | var data = { | 368 | var data = { |
464 | 372 | editor: editor, | 369 | editor: editor, |
465 | 373 | button: buttonDiv, | 370 | button: buttonDiv, |
466 | 374 | buttonName: buttonName, | 371 | buttonName: buttonName, |
467 | 375 | popup: popup, | 372 | popup: popup, |
468 | 376 | popupName: popupName, | 373 | popupName: popupName, |
469 | 377 | command: button.command, | 374 | command: button.command, |
470 | 378 | useCSS: editor.options.useCSS | 375 | useCSS: editor.options.useCSS |
471 | 379 | }; | 376 | }; |
472 | 380 | 377 | ||
474 | 381 | if (button.buttonClick && button.buttonClick(e, data) === false) | 378 | if (button.buttonClick && button.buttonClick(e, data) === false) { |
475 | 382 | return false; | 379 | return false; |
476 | 380 | } | ||
477 | 383 | 381 | ||
478 | 384 | // Toggle source | 382 | // Toggle source |
480 | 385 | if (buttonName == "source") { | 383 | if (buttonName === 'source') { |
481 | 386 | 384 | ||
482 | 387 | // Show the iframe | 385 | // Show the iframe |
483 | 388 | if (sourceMode(editor)) { | 386 | if (sourceMode(editor)) { |
484 | @@ -396,12 +394,12 @@ | |||
485 | 396 | else { | 394 | else { |
486 | 397 | editor.$frame.hide(); | 395 | editor.$frame.hide(); |
487 | 398 | editor.$area.show(); | 396 | editor.$area.show(); |
489 | 399 | buttonDiv.title = "Show Rich Text"; | 397 | buttonDiv.title = 'Show Rich Text'; |
490 | 400 | } | 398 | } |
491 | 401 | 399 | ||
492 | 402 | // Enable or disable the toolbar buttons | 400 | // Enable or disable the toolbar buttons |
493 | 403 | // IE requires the timeout | 401 | // IE requires the timeout |
495 | 404 | setTimeout(function() {refreshButtons(editor);}, 100); | 402 | setTimeout(function () {refreshButtons(editor);}, 100); |
496 | 405 | 403 | ||
497 | 406 | } | 404 | } |
498 | 407 | 405 | ||
499 | @@ -413,27 +411,28 @@ | |||
500 | 413 | var $popup = $(popup); | 411 | var $popup = $(popup); |
501 | 414 | 412 | ||
502 | 415 | // URL | 413 | // URL |
504 | 416 | if (popupName == "url") { | 414 | if (popupName === 'url') { |
505 | 417 | 415 | ||
506 | 418 | // Check for selection before showing the link url popup | 416 | // Check for selection before showing the link url popup |
509 | 419 | if (buttonName == "link" && selectedText(editor) === "") { | 417 | if (buttonName === 'link' && selectedText(editor) === '') { |
510 | 420 | showMessage(editor, "A selection is required when inserting a link.", buttonDiv); | 418 | showMessage(editor, 'A selection is required when inserting a link.', buttonDiv); |
511 | 421 | return false; | 419 | return false; |
512 | 422 | } | 420 | } |
513 | 423 | 421 | ||
514 | 424 | // Wire up the submit button click event handler | 422 | // Wire up the submit button click event handler |
516 | 425 | $popup.children(":button") | 423 | $popup.children(':button') |
517 | 426 | .unbind(CLICK) | 424 | .unbind(CLICK) |
519 | 427 | .bind(CLICK, function() { | 425 | .bind(CLICK, function () { |
520 | 428 | 426 | ||
521 | 429 | // Insert the image or link if a url was entered | 427 | // Insert the image or link if a url was entered |
523 | 430 | var $text = $popup.find(":text"), | 428 | var $text = $popup.find(':text'), |
524 | 431 | url = $.trim($text.val()); | 429 | url = $.trim($text.val()); |
526 | 432 | if (url !== "") | 430 | if (url !== '') { |
527 | 433 | execCommand(editor, data.command, url, null, data.button); | 431 | execCommand(editor, data.command, url, null, data.button); |
528 | 432 | } | ||
529 | 434 | 433 | ||
530 | 435 | // Reset the text, hide the popup and set focus | 434 | // Reset the text, hide the popup and set focus |
532 | 436 | $text.val("http://"); | 435 | $text.val('http://'); |
533 | 437 | hidePopups(); | 436 | hidePopups(); |
534 | 438 | focus(editor); | 437 | focus(editor); |
535 | 439 | 438 | ||
536 | @@ -442,21 +441,22 @@ | |||
537 | 442 | } | 441 | } |
538 | 443 | 442 | ||
539 | 444 | // Paste as Text | 443 | // Paste as Text |
541 | 445 | else if (popupName == "pastetext") { | 444 | else if (popupName === 'pastetext') { |
542 | 446 | 445 | ||
543 | 447 | // Wire up the submit button click event handler | 446 | // Wire up the submit button click event handler |
545 | 448 | $popup.children(":button") | 447 | $popup.children(':button') |
546 | 449 | .unbind(CLICK) | 448 | .unbind(CLICK) |
548 | 450 | .bind(CLICK, function() { | 449 | .bind(CLICK, function () { |
549 | 451 | 450 | ||
550 | 452 | // Insert the unformatted text replacing new lines with break tags | 451 | // Insert the unformatted text replacing new lines with break tags |
554 | 453 | var $textarea = $popup.find("textarea"), | 452 | var $textarea = $popup.find('textarea'), |
555 | 454 | text = $textarea.val().replace(/\n/g, "<br />"); | 453 | text = $textarea.val().replace(/\n/g, '<br />'); |
556 | 455 | if (text !== "") | 454 | if (text !== '') { |
557 | 456 | execCommand(editor, data.command, text, null, data.button); | 455 | execCommand(editor, data.command, text, null, data.button); |
558 | 456 | } | ||
559 | 457 | 457 | ||
560 | 458 | // Reset the text, hide the popup and set focus | 458 | // Reset the text, hide the popup and set focus |
562 | 459 | $textarea.val(""); | 459 | $textarea.val(''); |
563 | 460 | hidePopups(); | 460 | hidePopups(); |
564 | 461 | focus(editor); | 461 | focus(editor); |
565 | 462 | 462 | ||
566 | @@ -476,12 +476,14 @@ | |||
567 | 476 | } | 476 | } |
568 | 477 | 477 | ||
569 | 478 | 478 | ||
571 | 479 | else if (buttonName == "print") | 479 | else if (buttonName === 'print') { |
572 | 480 | editor.$frame[0].contentWindow.print(); | 480 | editor.$frame[0].contentWindow.print(); |
573 | 481 | } | ||
574 | 481 | 482 | ||
575 | 482 | // All other buttons | 483 | // All other buttons |
577 | 483 | else if (!execCommand(editor, data.command, data.value, data.useCSS, buttonDiv)) | 484 | else if (!execCommand(editor, data.command, data.value, data.useCSS, buttonDiv)) { |
578 | 484 | return false; | 485 | return false; |
579 | 486 | } | ||
580 | 485 | 487 | ||
581 | 486 | } | 488 | } |
582 | 487 | 489 | ||
583 | @@ -492,71 +494,78 @@ | |||
584 | 492 | 494 | ||
585 | 493 | // hoverEnter - mouseenter event handler for buttons and popup items | 495 | // hoverEnter - mouseenter event handler for buttons and popup items |
586 | 494 | function hoverEnter(e) { | 496 | function hoverEnter(e) { |
589 | 495 | var $div = $(e.target).closest("div"); | 497 | var $div = $(e.target).closest('div'); |
590 | 496 | $div.css(BACKGROUND_COLOR, $div.data(BUTTON_NAME) ? "#FFF" : "#FFC"); | 498 | $div.css(BACKGROUND_COLOR, $div.data(BUTTON_NAME) ? '#FFF' : '#FFC'); |
591 | 497 | } | 499 | } |
592 | 498 | 500 | ||
593 | 499 | // hoverLeave - mouseleave event handler for buttons and popup items | 501 | // hoverLeave - mouseleave event handler for buttons and popup items |
594 | 500 | function hoverLeave(e) { | 502 | function hoverLeave(e) { |
596 | 501 | $(e.target).closest("div").css(BACKGROUND_COLOR, "transparent"); | 503 | $(e.target).closest('div').css(BACKGROUND_COLOR, 'transparent'); |
597 | 502 | } | 504 | } |
598 | 503 | 505 | ||
599 | 504 | // popupClick - click event handler for popup items | 506 | // popupClick - click event handler for popup items |
600 | 505 | function popupClick(e) { | 507 | function popupClick(e) { |
601 | 506 | 508 | ||
604 | 507 | var editor = this, | 509 | var editor = this, |
605 | 508 | popup = e.data.popup, | 510 | popup = e.data.popup, |
606 | 509 | target = e.target; | 511 | target = e.target; |
607 | 510 | 512 | ||
608 | 511 | // Check for message and prompt popups | 513 | // Check for message and prompt popups |
610 | 512 | if (popup === popups.msg || $(popup).hasClass(PROMPT_CLASS)) | 514 | if (popup === popups.msg || $(popup).hasClass(PROMPT_CLASS)) { |
611 | 513 | return; | 515 | return; |
612 | 516 | } | ||
613 | 514 | 517 | ||
614 | 515 | // Get the button info | 518 | // Get the button info |
620 | 516 | var buttonDiv = $.data(popup, BUTTON), | 519 | var buttonDiv = $.data(popup, BUTTON), |
621 | 517 | buttonName = $.data(buttonDiv, BUTTON_NAME), | 520 | buttonName = $.data(buttonDiv, BUTTON_NAME), |
622 | 518 | button = buttons[buttonName], | 521 | button = buttons[buttonName], |
623 | 519 | command = button.command, | 522 | command = button.command, |
624 | 520 | value, | 523 | value, |
625 | 521 | useCSS = editor.options.useCSS; | 524 | useCSS = editor.options.useCSS; |
626 | 522 | 525 | ||
627 | 523 | // Get the command value | 526 | // Get the command value |
629 | 524 | if (buttonName == "font") | 527 | if (buttonName === 'font') { |
630 | 525 | // Opera returns the fontfamily wrapped in quotes | 528 | // Opera returns the fontfamily wrapped in quotes |
634 | 526 | value = target.style.fontFamily.replace(/"/g, ""); | 529 | value = target.style.fontFamily.replace(/'/g, ''); |
635 | 527 | else if (buttonName == "size") { | 530 | } |
636 | 528 | if (target.tagName == "DIV") | 531 | else if (buttonName === 'size') { |
637 | 532 | if (target.tagName === 'DIV') { | ||
638 | 529 | target = target.children[0]; | 533 | target = target.children[0]; |
639 | 534 | } | ||
640 | 530 | value = target.innerHTML; | 535 | value = target.innerHTML; |
641 | 531 | } | 536 | } |
650 | 532 | else if (buttonName == "style") | 537 | else if (buttonName === 'style') { |
651 | 533 | value = "<" + target.tagName + ">"; | 538 | value = '<' + target.tagName + '>'; |
652 | 534 | else if (buttonName == "color") | 539 | } |
653 | 535 | value = hex(target.style.backgroundColor); | 540 | else if (buttonName === 'color') { |
654 | 536 | else if (buttonName == "highlight") { | 541 | value = hex(target.style.backgroundColor); |
655 | 537 | value = hex(target.style.backgroundColor); | 542 | } |
656 | 538 | if (ie) command = 'backcolor'; | 543 | else if (buttonName === 'highlight') { |
657 | 539 | else useCSS = true; | 544 | value = hex(target.style.backgroundColor); |
658 | 545 | if (ie) {command = 'backcolor';} | ||
659 | 546 | else {useCSS = true;} | ||
660 | 540 | } | 547 | } |
661 | 541 | 548 | ||
662 | 542 | // Fire the popupClick event | 549 | // Fire the popupClick event |
663 | 543 | var data = { | 550 | var data = { |
671 | 544 | editor: editor, | 551 | editor: editor, |
672 | 545 | button: buttonDiv, | 552 | button: buttonDiv, |
673 | 546 | buttonName: buttonName, | 553 | buttonName: buttonName, |
674 | 547 | popup: popup, | 554 | popup: popup, |
675 | 548 | popupName: button.popupName, | 555 | popupName: button.popupName, |
676 | 549 | command: command, | 556 | command: command, |
677 | 550 | value: value, | 557 | value: value, |
678 | 551 | useCSS: useCSS | 558 | useCSS: useCSS |
679 | 552 | }; | 559 | }; |
680 | 553 | 560 | ||
682 | 554 | if (button.popupClick && button.popupClick(e, data) === false) | 561 | if (button.popupClick && button.popupClick(e, data) === false) { |
683 | 555 | return; | 562 | return; |
684 | 563 | } | ||
685 | 556 | 564 | ||
686 | 557 | // Execute the command | 565 | // Execute the command |
688 | 558 | if (data.command && !execCommand(editor, data.command, data.value, data.useCSS, buttonDiv)) | 566 | if (data.command && !execCommand(editor, data.command, data.value, data.useCSS, buttonDiv)) { |
689 | 559 | return false; | 567 | return false; |
690 | 568 | } | ||
691 | 560 | 569 | ||
692 | 561 | // Hide the popup and focus the editor | 570 | // Hide the popup and focus the editor |
693 | 562 | hidePopups(); | 571 | hidePopups(); |
694 | @@ -581,7 +590,7 @@ | |||
695 | 581 | 590 | ||
696 | 582 | // clear - clears the contents of the editor | 591 | // clear - clears the contents of the editor |
697 | 583 | function clear(editor) { | 592 | function clear(editor) { |
699 | 584 | editor.$area.val(""); | 593 | editor.$area.val(''); |
700 | 585 | updateFrame(editor); | 594 | updateFrame(editor); |
701 | 586 | } | 595 | } |
702 | 587 | 596 | ||
703 | @@ -589,82 +598,90 @@ | |||
704 | 589 | function createPopup(popupName, options, popupTypeClass, popupContent, popupHover) { | 598 | function createPopup(popupName, options, popupTypeClass, popupContent, popupHover) { |
705 | 590 | 599 | ||
706 | 591 | // Check if popup already exists | 600 | // Check if popup already exists |
708 | 592 | if (popups[popupName]) | 601 | if (popups[popupName]) { |
709 | 593 | return popups[popupName]; | 602 | return popups[popupName]; |
710 | 603 | } | ||
711 | 594 | 604 | ||
712 | 595 | // Create the popup | 605 | // Create the popup |
713 | 596 | var $popup = $(DIV_TAG) | 606 | var $popup = $(DIV_TAG) |
714 | 597 | .hide() | 607 | .hide() |
715 | 598 | .addClass(POPUP_CLASS) | 608 | .addClass(POPUP_CLASS) |
717 | 599 | .appendTo("body"); | 609 | .appendTo('body'); |
718 | 600 | 610 | ||
719 | 601 | // Add the content | 611 | // Add the content |
720 | 602 | 612 | ||
721 | 603 | // Custom popup | 613 | // Custom popup |
723 | 604 | if (popupContent) | 614 | if (popupContent) { |
724 | 605 | $popup.html(popupContent); | 615 | $popup.html(popupContent); |
725 | 616 | } | ||
726 | 606 | 617 | ||
727 | 607 | // Color | 618 | // Color |
733 | 608 | else if (popupName == "color") { | 619 | else if (popupName === 'color') { |
734 | 609 | var colors = options.colors.split(" "); | 620 | var colors = options.colors.split(' '); |
735 | 610 | if (colors.length < 10) | 621 | if (colors.length < 10) { |
736 | 611 | $popup.width("auto"); | 622 | $popup.width('auto'); |
737 | 612 | $.each(colors, function(idx, color) { | 623 | } |
738 | 624 | $.each(colors, function (idx, color) { | ||
739 | 613 | $(DIV_TAG).appendTo($popup) | 625 | $(DIV_TAG).appendTo($popup) |
741 | 614 | .css(BACKGROUND_COLOR, "#" + color); | 626 | .css(BACKGROUND_COLOR, '#' + color); |
742 | 615 | }); | 627 | }); |
743 | 616 | popupTypeClass = COLOR_CLASS; | 628 | popupTypeClass = COLOR_CLASS; |
744 | 617 | } | 629 | } |
745 | 618 | 630 | ||
746 | 619 | // Font | 631 | // Font |
749 | 620 | else if (popupName == "font") | 632 | else if (popupName === 'font') { |
750 | 621 | $.each(options.fonts.split(","), function(idx, font) { | 633 | $.each(options.fonts.split(','), function (idx, font) { |
751 | 622 | $(DIV_TAG).appendTo($popup) | 634 | $(DIV_TAG).appendTo($popup) |
753 | 623 | .css("fontFamily", font) | 635 | .css('fontFamily', font) |
754 | 624 | .html(font); | 636 | .html(font); |
755 | 625 | }); | 637 | }); |
756 | 638 | } | ||
757 | 626 | 639 | ||
758 | 627 | // Size | 640 | // Size |
761 | 628 | else if (popupName == "size") | 641 | else if (popupName === 'size') { |
762 | 629 | $.each(options.sizes.split(","), function(idx, size) { | 642 | $.each(options.sizes.split(','), function (idx, size) { |
763 | 630 | $(DIV_TAG).appendTo($popup) | 643 | $(DIV_TAG).appendTo($popup) |
765 | 631 | .html("<font size=" + size + ">" + size + "</font>"); | 644 | .html('<font size=' + size + '>' + size + '</font>'); |
766 | 632 | }); | 645 | }); |
767 | 646 | } | ||
768 | 633 | 647 | ||
769 | 634 | // Style | 648 | // Style |
772 | 635 | else if (popupName == "style") | 649 | else if (popupName === 'style') { |
773 | 636 | $.each(options.styles, function(idx, style) { | 650 | $.each(options.styles, function (idx, style) { |
774 | 637 | $(DIV_TAG).appendTo($popup) | 651 | $(DIV_TAG).appendTo($popup) |
776 | 638 | .html(style[1] + style[0] + style[1].replace("<", "</")); | 652 | .html(style[1] + style[0] + style[1].replace('<', '</')); |
777 | 639 | }); | 653 | }); |
778 | 654 | } | ||
779 | 640 | 655 | ||
780 | 641 | // URL | 656 | // URL |
782 | 642 | else if (popupName == "url") { | 657 | else if (popupName === 'url') { |
783 | 643 | $popup.html('Enter URL:<br><input type=text value="http://" size=35><br><input type=button value="Submit">'); | 658 | $popup.html('Enter URL:<br><input type=text value="http://" size=35><br><input type=button value="Submit">'); |
784 | 644 | popupTypeClass = PROMPT_CLASS; | 659 | popupTypeClass = PROMPT_CLASS; |
785 | 645 | } | 660 | } |
786 | 646 | 661 | ||
787 | 647 | // Paste as Text | 662 | // Paste as Text |
789 | 648 | else if (popupName == "pastetext") { | 663 | else if (popupName === 'pastetext') { |
790 | 649 | $popup.html('Paste your content here and click submit.<br /><textarea cols=40 rows=3></textarea><br /><input type=button value=Submit>'); | 664 | $popup.html('Paste your content here and click submit.<br /><textarea cols=40 rows=3></textarea><br /><input type=button value=Submit>'); |
791 | 650 | popupTypeClass = PROMPT_CLASS; | 665 | popupTypeClass = PROMPT_CLASS; |
792 | 651 | } | 666 | } |
793 | 652 | 667 | ||
794 | 653 | // Add the popup type class name | 668 | // Add the popup type class name |
796 | 654 | if (!popupTypeClass && !popupContent) | 669 | if (!popupTypeClass && !popupContent) { |
797 | 655 | popupTypeClass = LIST_CLASS; | 670 | popupTypeClass = LIST_CLASS; |
798 | 671 | } | ||
799 | 656 | $popup.addClass(popupTypeClass); | 672 | $popup.addClass(popupTypeClass); |
800 | 657 | 673 | ||
801 | 658 | // Add the unselectable attribute to all items | 674 | // Add the unselectable attribute to all items |
802 | 659 | if (ie) { | 675 | if (ie) { |
806 | 660 | $popup.attr(UNSELECTABLE, "on") | 676 | $popup.attr(UNSELECTABLE, 'on') |
807 | 661 | .find("div,font,p,h1,h2,h3,h4,h5,h6") | 677 | .find('div, font, p, h1, h2, h3, h4, h5, h6') |
808 | 662 | .attr(UNSELECTABLE, "on"); | 678 | .attr(UNSELECTABLE, 'on'); |
809 | 663 | } | 679 | } |
810 | 664 | 680 | ||
811 | 665 | // Add the hover effect to all items | 681 | // Add the hover effect to all items |
813 | 666 | if ($popup.hasClass(LIST_CLASS) || popupHover === true) | 682 | if ($popup.hasClass(LIST_CLASS) || popupHover === true) { |
814 | 667 | $popup.children().hover(hoverEnter, hoverLeave); | 683 | $popup.children().hover(hoverEnter, hoverLeave); |
815 | 684 | } | ||
816 | 668 | 685 | ||
817 | 669 | // Add the popup to the array and return it | 686 | // Add the popup to the array and return it |
818 | 670 | popups[popupName] = $popup[0]; | 687 | popups[popupName] = $popup[0]; |
819 | @@ -687,10 +704,10 @@ | |||
820 | 687 | 704 | ||
821 | 688 | // Switch the iframe into design mode. | 705 | // Switch the iframe into design mode. |
822 | 689 | // ie6 does not support designMode. | 706 | // ie6 does not support designMode. |
824 | 690 | // ie7 & ie8 do not properly support designMode="off". | 707 | // ie7 & ie8 do not properly support designMode='off'. |
825 | 691 | try { | 708 | try { |
828 | 692 | if (ie) editor.doc.body.contentEditable = !disabled; | 709 | if (ie) {editor.doc.body.contentEditable = !disabled;} |
829 | 693 | else editor.doc.designMode = !disabled ? "on" : "off"; | 710 | else {editor.doc.designMode = !disabled ? 'on' : 'off';} |
830 | 694 | } | 711 | } |
831 | 695 | // Firefox 1.5 throws an exception that can be ignored | 712 | // Firefox 1.5 throws an exception that can be ignored |
832 | 696 | // when toggling designMode from off to on. | 713 | // when toggling designMode from off to on. |
833 | @@ -709,27 +726,31 @@ | |||
834 | 709 | 726 | ||
835 | 710 | // Set the styling method | 727 | // Set the styling method |
836 | 711 | if (!ie) { | 728 | if (!ie) { |
838 | 712 | if (useCSS === undefined || useCSS === null) | 729 | if (useCSS === undefined || useCSS === null) { |
839 | 713 | useCSS = editor.options.useCSS; | 730 | useCSS = editor.options.useCSS; |
841 | 714 | editor.doc.execCommand("styleWithCSS", 0, useCSS.toString()); | 731 | } |
842 | 732 | editor.doc.execCommand('styleWithCSS', 0, useCSS.toString()); | ||
843 | 715 | } | 733 | } |
844 | 716 | 734 | ||
845 | 717 | // Execute the command and check for error | 735 | // Execute the command and check for error |
846 | 718 | var success = true, description; | 736 | var success = true, description; |
848 | 719 | if (ie && command.toLowerCase() == "inserthtml") | 737 | if (ie && command.toLowerCase() === 'inserthtml') { |
849 | 720 | getRange(editor).pasteHTML(value); | 738 | getRange(editor).pasteHTML(value); |
850 | 739 | } | ||
851 | 721 | else { | 740 | else { |
852 | 722 | try { success = editor.doc.execCommand(command, 0, value || null); } | 741 | try { success = editor.doc.execCommand(command, 0, value || null); } |
853 | 723 | catch (err) { description = err.description; success = false; } | 742 | catch (err) { description = err.description; success = false; } |
854 | 724 | if (!success) { | 743 | if (!success) { |
863 | 725 | if ("cutcopypaste".indexOf(command) > -1) | 744 | if ('cutcopypaste'.indexOf(command) > -1) { |
864 | 726 | showMessage(editor, "For security reasons, your browser does not support the " + | 745 | showMessage(editor, 'For security reasons, your browser does not support the ' + |
865 | 727 | command + " command. Try using the keyboard shortcut or context menu instead.", | 746 | command + ' command. Try using the keyboard shortcut or context menu instead.', |
866 | 728 | button); | 747 | button); |
867 | 729 | else | 748 | } |
868 | 730 | showMessage(editor, | 749 | else { |
869 | 731 | (description ? description : "Error executing the " + command + " command."), | 750 | showMessage(editor, |
870 | 732 | button); | 751 | (description ? description : 'Error executing the ' + command + ' command.'), |
871 | 752 | button); | ||
872 | 753 | } | ||
873 | 733 | } | 754 | } |
874 | 734 | } | 755 | } |
875 | 735 | 756 | ||
876 | @@ -741,43 +762,44 @@ | |||
877 | 741 | 762 | ||
878 | 742 | // focus - sets focus to either the textarea or iframe | 763 | // focus - sets focus to either the textarea or iframe |
879 | 743 | function focus(editor) { | 764 | function focus(editor) { |
883 | 744 | setTimeout(function() { | 765 | setTimeout(function () { |
884 | 745 | if (sourceMode(editor)) editor.$area.focus(); | 766 | if (sourceMode(editor)) {editor.$area.focus();} |
885 | 746 | else editor.$frame[0].contentWindow.focus(); | 767 | else {editor.$frame[0].contentWindow.focus();} |
886 | 747 | refreshButtons(editor); | 768 | refreshButtons(editor); |
887 | 748 | }, 0); | 769 | }, 0); |
888 | 749 | } | 770 | } |
889 | 750 | 771 | ||
890 | 751 | // getRange - gets the current text range object | 772 | // getRange - gets the current text range object |
891 | 752 | function getRange(editor) { | 773 | function getRange(editor) { |
893 | 753 | if (ie) return getSelection(editor).createRange(); | 774 | if (ie) {return getSelection(editor).createRange();} |
894 | 754 | return getSelection(editor).getRangeAt(0); | 775 | return getSelection(editor).getRangeAt(0); |
895 | 755 | } | 776 | } |
896 | 756 | 777 | ||
897 | 757 | // getSelection - gets the current text range object | 778 | // getSelection - gets the current text range object |
898 | 758 | function getSelection(editor) { | 779 | function getSelection(editor) { |
900 | 759 | if (ie) return editor.doc.selection; | 780 | if (ie) {return editor.doc.selection;} |
901 | 760 | return editor.$frame[0].contentWindow.getSelection(); | 781 | return editor.$frame[0].contentWindow.getSelection(); |
902 | 761 | } | 782 | } |
903 | 762 | 783 | ||
904 | 763 | // Returns the hex value for the passed in string. | 784 | // Returns the hex value for the passed in string. |
908 | 764 | // hex("rgb(255, 0, 0)"); // #FF0000 | 785 | // hex('rgb(255, 0, 0)'); // #FF0000 |
909 | 765 | // hex("#FF0000"); // #FF0000 | 786 | // hex('#FF0000'); // #FF0000 |
910 | 766 | // hex("#F00"); // #FF0000 | 787 | // hex('#F00'); // #FF0000 |
911 | 767 | function hex(s) { | 788 | function hex(s) { |
914 | 768 | var m = /rgba?\((\d+), (\d+), (\d+)/.exec(s), | 789 | var m = /rgba?\((\d+), (\d+), (\d+)/.exec(s), |
915 | 769 | c = s.split(""); | 790 | c = s.split(''); |
916 | 770 | if (m) { | 791 | if (m) { |
917 | 771 | s = ( m[1] << 16 | m[2] << 8 | m[3] ).toString(16); | 792 | s = ( m[1] << 16 | m[2] << 8 | m[3] ).toString(16); |
920 | 772 | while (s.length < 6) | 793 | while (s.length < 6) { |
921 | 773 | s = "0" + s; | 794 | s = '0' + s; |
922 | 795 | } | ||
923 | 774 | } | 796 | } |
925 | 775 | return "#" + (s.length == 6 ? s : c[1] + c[1] + c[2] + c[2] + c[3] + c[3]); | 797 | return '#' + (s.length === 6 ? s : c[1] + c[1] + c[2] + c[2] + c[3] + c[3]); |
926 | 776 | } | 798 | } |
927 | 777 | 799 | ||
928 | 778 | // hidePopups - hides all popups | 800 | // hidePopups - hides all popups |
929 | 779 | function hidePopups() { | 801 | function hidePopups() { |
931 | 780 | $.each(popups, function(idx, popup) { | 802 | $.each(popups, function (idx, popup) { |
932 | 781 | $(popup) | 803 | $(popup) |
933 | 782 | .hide() | 804 | .hide() |
934 | 783 | .unbind(CLICK) | 805 | .unbind(CLICK) |
935 | @@ -787,25 +809,26 @@ | |||
936 | 787 | 809 | ||
937 | 788 | // imagesPath - returns the path to the images folder | 810 | // imagesPath - returns the path to the images folder |
938 | 789 | function imagesPath() { | 811 | function imagesPath() { |
942 | 790 | var cssFile = "jquery.cleditor.css", | 812 | var cssFile = 'jquery.cleditor.css', |
943 | 791 | href = $("link[href$='" + cssFile +"']").attr("href"); | 813 | href = $('link[href$="' + cssFile +'"]').attr('href'); |
944 | 792 | return href.substr(0, href.length - cssFile.length) + "images/"; | 814 | return href.substr(0, href.length - cssFile.length) + 'images/'; |
945 | 793 | } | 815 | } |
946 | 794 | 816 | ||
947 | 795 | // imageUrl - Returns the css url string for a filemane | 817 | // imageUrl - Returns the css url string for a filemane |
948 | 796 | function imageUrl(filename) { | 818 | function imageUrl(filename) { |
950 | 797 | return "url(" + imagesPath() + filename + ")"; | 819 | return 'url(' + imagesPath() + filename + ')'; |
951 | 798 | } | 820 | } |
952 | 799 | 821 | ||
953 | 800 | // refresh - creates the iframe and resizes the controls | 822 | // refresh - creates the iframe and resizes the controls |
954 | 801 | function refresh(editor) { | 823 | function refresh(editor) { |
955 | 802 | 824 | ||
957 | 803 | var $main = editor.$main, | 825 | var $main = editor.$main, |
958 | 804 | options = editor.options; | 826 | options = editor.options; |
959 | 805 | 827 | ||
960 | 806 | // Remove the old iframe | 828 | // Remove the old iframe |
962 | 807 | if (editor.$frame) | 829 | if (editor.$frame) { |
963 | 808 | editor.$frame.remove(); | 830 | editor.$frame.remove(); |
964 | 831 | } | ||
965 | 809 | 832 | ||
966 | 810 | // Create a new iframe | 833 | // Create a new iframe |
967 | 811 | var $frame = editor.$frame = $('<iframe frameborder="0" src="javascript:true;">') | 834 | var $frame = editor.$frame = $('<iframe frameborder="0" src="javascript:true;">') |
968 | @@ -813,8 +836,8 @@ | |||
969 | 813 | .appendTo($main); | 836 | .appendTo($main); |
970 | 814 | 837 | ||
971 | 815 | // Load the iframe document content | 838 | // Load the iframe document content |
974 | 816 | var contentWindow = $frame[0].contentWindow, | 839 | var contentWindow = $frame[0].contentWindow, |
975 | 817 | doc = editor.doc = contentWindow.document, | 840 | doc = editor.doc = contentWindow.document, |
976 | 818 | $doc = $(doc); | 841 | $doc = $(doc); |
977 | 819 | 842 | ||
978 | 820 | doc.open(); | 843 | doc.open(); |
979 | @@ -828,8 +851,9 @@ | |||
980 | 828 | 851 | ||
981 | 829 | // Work around for bug in IE which causes the editor to lose | 852 | // Work around for bug in IE which causes the editor to lose |
982 | 830 | // focus when clicking below the end of the document. | 853 | // focus when clicking below the end of the document. |
985 | 831 | if (ie) | 854 | if (ie) { |
986 | 832 | $doc.click(function() {focus(editor);}); | 855 | $doc.click(function () {focus(editor);}); |
987 | 856 | } | ||
988 | 833 | 857 | ||
989 | 834 | // Load the content | 858 | // Load the content |
990 | 835 | updateFrame(editor); | 859 | updateFrame(editor); |
991 | @@ -840,60 +864,64 @@ | |||
992 | 840 | // Save the current user selection. This code is needed since IE will | 864 | // Save the current user selection. This code is needed since IE will |
993 | 841 | // reset the selection just after the beforedeactivate event and just | 865 | // reset the selection just after the beforedeactivate event and just |
994 | 842 | // before the beforeactivate event. | 866 | // before the beforeactivate event. |
996 | 843 | $doc.bind("beforedeactivate beforeactivate selectionchange keypress", function(e) { | 867 | $doc.bind('beforedeactivate beforeactivate selectionchange keypress', function (e) { |
997 | 844 | 868 | ||
998 | 845 | // Flag the editor as inactive | 869 | // Flag the editor as inactive |
1000 | 846 | if (e.type == "beforedeactivate") | 870 | if (e.type === 'beforedeactivate') { |
1001 | 847 | editor.inactive = true; | 871 | editor.inactive = true; |
1002 | 872 | } | ||
1003 | 848 | 873 | ||
1004 | 849 | // Get rid of the bogus selection and flag the editor as active | 874 | // Get rid of the bogus selection and flag the editor as active |
1007 | 850 | else if (e.type == "beforeactivate") { | 875 | else if (e.type === 'beforeactivate') { |
1008 | 851 | if (!editor.inactive && editor.range && editor.range.length > 1) | 876 | if (!editor.inactive && editor.range && editor.range.length > 1) { |
1009 | 852 | editor.range.shift(); | 877 | editor.range.shift(); |
1010 | 878 | } | ||
1011 | 853 | delete editor.inactive; | 879 | delete editor.inactive; |
1012 | 854 | } | 880 | } |
1013 | 855 | 881 | ||
1014 | 856 | // Save the selection when the editor is active | 882 | // Save the selection when the editor is active |
1015 | 857 | else if (!editor.inactive) { | 883 | else if (!editor.inactive) { |
1017 | 858 | if (!editor.range) | 884 | if (!editor.range) { |
1018 | 859 | editor.range = []; | 885 | editor.range = []; |
1019 | 886 | } | ||
1020 | 860 | editor.range.unshift(getRange(editor)); | 887 | editor.range.unshift(getRange(editor)); |
1021 | 861 | 888 | ||
1022 | 862 | // We only need the last 2 selections | 889 | // We only need the last 2 selections |
1024 | 863 | while (editor.range.length > 2) | 890 | while (editor.range.length > 2) { |
1025 | 864 | editor.range.pop(); | 891 | editor.range.pop(); |
1026 | 892 | } | ||
1027 | 865 | } | 893 | } |
1028 | 866 | 894 | ||
1029 | 867 | }); | 895 | }); |
1030 | 868 | 896 | ||
1031 | 869 | // Restore the text range when the iframe gains focus | 897 | // Restore the text range when the iframe gains focus |
1033 | 870 | $frame.focus(function() { | 898 | $frame.focus(function () { |
1034 | 871 | restoreRange(editor); | 899 | restoreRange(editor); |
1035 | 872 | }); | 900 | }); |
1036 | 873 | 901 | ||
1037 | 874 | } | 902 | } |
1038 | 875 | 903 | ||
1039 | 876 | // Update the textarea when the iframe loses focus | 904 | // Update the textarea when the iframe loses focus |
1041 | 877 | ($.browser.mozilla ? $doc : $(contentWindow)).blur(function() { | 905 | ($.browser.mozilla ? $doc : $(contentWindow)).blur(function () { |
1042 | 878 | updateTextArea(editor, true); | 906 | updateTextArea(editor, true); |
1043 | 879 | }); | 907 | }); |
1044 | 880 | 908 | ||
1045 | 881 | // Enable the toolbar buttons as the user types or clicks | 909 | // Enable the toolbar buttons as the user types or clicks |
1046 | 882 | $doc.click(hidePopups) | 910 | $doc.click(hidePopups) |
1048 | 883 | .bind("keyup mouseup", function() { | 911 | .bind('keyup mouseup', function () { |
1049 | 884 | refreshButtons(editor); | 912 | refreshButtons(editor); |
1050 | 885 | }); | 913 | }); |
1051 | 886 | 914 | ||
1052 | 887 | // Show the textarea for iPhone/iTouch/iPad or | 915 | // Show the textarea for iPhone/iTouch/iPad or |
1053 | 888 | // the iframe when design mode is supported. | 916 | // the iframe when design mode is supported. |
1056 | 889 | if (iOS) editor.$area.show(); | 917 | if (iOS) {editor.$area.show();} |
1057 | 890 | else $frame.show(); | 918 | else {$frame.show();} |
1058 | 891 | 919 | ||
1059 | 892 | // Wait for the layout to finish - shortcut for $(document).ready() | 920 | // Wait for the layout to finish - shortcut for $(document).ready() |
1061 | 893 | $(function() { | 921 | $(function () { |
1062 | 894 | 922 | ||
1065 | 895 | var $toolbar = editor.$toolbar, | 923 | var $toolbar = editor.$toolbar, |
1066 | 896 | $group = $toolbar.children("div:last"), | 924 | $group = $toolbar.children('div:last'), |
1067 | 897 | wid = $main.width(); | 925 | wid = $main.width(); |
1068 | 898 | 926 | ||
1069 | 899 | // Resize the toolbar | 927 | // Resize the toolbar |
1070 | @@ -901,7 +929,7 @@ | |||
1071 | 901 | $toolbar.height(hgt); | 929 | $toolbar.height(hgt); |
1072 | 902 | 930 | ||
1073 | 903 | // Resize the iframe | 931 | // Resize the iframe |
1075 | 904 | hgt = (/%/.test("" + options.height) ? $main.height() : parseInt(options.height)) - hgt; | 932 | hgt = (/%/.test('' + options.height) ? $main.height() : parseInt(options.height)) - hgt; |
1076 | 905 | $frame.width(wid).height(hgt); | 933 | $frame.width(wid).height(hgt); |
1077 | 906 | 934 | ||
1078 | 907 | // Resize the textarea. IE6 textareas have a 1px top | 935 | // Resize the textarea. IE6 textareas have a 1px top |
1079 | @@ -930,42 +958,46 @@ | |||
1080 | 930 | 958 | ||
1081 | 931 | // Get the object used for checking queryCommandEnabled | 959 | // Get the object used for checking queryCommandEnabled |
1082 | 932 | var queryObj = editor.doc; | 960 | var queryObj = editor.doc; |
1084 | 933 | if (ie) queryObj = getRange(editor); | 961 | if (ie) {queryObj = getRange(editor);} |
1085 | 934 | 962 | ||
1086 | 935 | // Loop through each button | 963 | // Loop through each button |
1087 | 936 | var inSourceMode = sourceMode(editor); | 964 | var inSourceMode = sourceMode(editor); |
1089 | 937 | $.each(editor.$toolbar.find("." + BUTTON_CLASS), function(idx, elem) { | 965 | $.each(editor.$toolbar.find('.' + BUTTON_CLASS), function (idx, elem) { |
1090 | 938 | 966 | ||
1094 | 939 | var $elem = $(elem), | 967 | var $elem = $(elem), |
1095 | 940 | button = $.cleditor.buttons[$.data(elem, BUTTON_NAME)], | 968 | button = $.cleditor.buttons[$.data(elem, BUTTON_NAME)], |
1096 | 941 | command = button.command, | 969 | command = button.command, |
1097 | 942 | enabled = true; | 970 | enabled = true; |
1098 | 943 | 971 | ||
1099 | 944 | // Determine the state | 972 | // Determine the state |
1101 | 945 | if (editor.disabled) | 973 | if (editor.disabled) { |
1102 | 946 | enabled = false; | 974 | enabled = false; |
1103 | 975 | } | ||
1104 | 947 | else if (button.getEnabled) { | 976 | else if (button.getEnabled) { |
1105 | 948 | var data = { | 977 | var data = { |
1112 | 949 | editor: editor, | 978 | editor: editor, |
1113 | 950 | button: elem, | 979 | button: elem, |
1114 | 951 | buttonName: button.name, | 980 | buttonName: button.name, |
1115 | 952 | popup: popups[button.popupName], | 981 | popup: popups[button.popupName], |
1116 | 953 | popupName: button.popupName, | 982 | popupName: button.popupName, |
1117 | 954 | command: button.command, | 983 | command: button.command, |
1118 | 955 | useCSS: editor.options.useCSS | 984 | useCSS: editor.options.useCSS |
1119 | 956 | }; | 985 | }; |
1120 | 957 | enabled = button.getEnabled(data); | 986 | enabled = button.getEnabled(data); |
1122 | 958 | if (enabled === undefined) | 987 | if (enabled === undefined) { |
1123 | 959 | enabled = true; | 988 | enabled = true; |
1124 | 989 | } | ||
1125 | 960 | } | 990 | } |
1128 | 961 | else if (((inSourceMode || iOS) && button.name != "source") || | 991 | else if (((inSourceMode || iOS) && button.name !== 'source') || |
1129 | 962 | (ie && (command == "undo" || command == "redo"))) | 992 | (ie && (command === 'undo' || command === 'redo'))) { |
1130 | 963 | enabled = false; | 993 | enabled = false; |
1134 | 964 | else if (command && command != "print") { | 994 | } |
1135 | 965 | if (ie && command == "hilitecolor") | 995 | else if (command && command !== 'print') { |
1136 | 966 | command = "backcolor"; | 996 | if (ie && command === 'hilitecolor') { |
1137 | 997 | command = 'backcolor'; | ||
1138 | 998 | } | ||
1139 | 967 | // IE does not support inserthtml, so it's always enabled | 999 | // IE does not support inserthtml, so it's always enabled |
1141 | 968 | if (!ie || command != "inserthtml") { | 1000 | if (!ie || command !== 'inserthtml') { |
1142 | 969 | try {enabled = queryObj.queryCommandEnabled(command);} | 1001 | try {enabled = queryObj.queryCommandEnabled(command);} |
1143 | 970 | catch (err) {enabled = false;} | 1002 | catch (err) {enabled = false;} |
1144 | 971 | } | 1003 | } |
1145 | @@ -986,15 +1018,16 @@ | |||
1146 | 986 | 1018 | ||
1147 | 987 | // restoreRange - restores the current ie selection | 1019 | // restoreRange - restores the current ie selection |
1148 | 988 | function restoreRange(editor) { | 1020 | function restoreRange(editor) { |
1150 | 989 | if (ie && editor.range) | 1021 | if (ie && editor.range) { |
1151 | 990 | editor.range[0].select(); | 1022 | editor.range[0].select(); |
1152 | 1023 | } | ||
1153 | 991 | } | 1024 | } |
1154 | 992 | 1025 | ||
1155 | 993 | // select - selects all the text in either the textarea or iframe | 1026 | // select - selects all the text in either the textarea or iframe |
1156 | 994 | function select(editor) { | 1027 | function select(editor) { |
1160 | 995 | setTimeout(function() { | 1028 | setTimeout(function () { |
1161 | 996 | if (sourceMode(editor)) editor.$area.select(); | 1029 | if (sourceMode(editor)) {editor.$area.select();} |
1162 | 997 | else execCommand(editor, "selectall"); | 1030 | else {execCommand(editor, 'selectall');} |
1163 | 998 | }, 0); | 1031 | }, 0); |
1164 | 999 | } | 1032 | } |
1165 | 1000 | 1033 | ||
1166 | @@ -1002,9 +1035,10 @@ | |||
1167 | 1002 | function selectedHTML(editor) { | 1035 | function selectedHTML(editor) { |
1168 | 1003 | restoreRange(editor); | 1036 | restoreRange(editor); |
1169 | 1004 | var range = getRange(editor); | 1037 | var range = getRange(editor); |
1171 | 1005 | if (ie) | 1038 | if (ie) { |
1172 | 1006 | return range.htmlText; | 1039 | return range.htmlText; |
1174 | 1007 | var layer = $("<layer>")[0]; | 1040 | } |
1175 | 1041 | var layer = $('<layer>')[0]; | ||
1176 | 1008 | layer.appendChild(range.cloneContents()); | 1042 | layer.appendChild(range.cloneContents()); |
1177 | 1009 | var html = layer.innerHTML; | 1043 | var html = layer.innerHTML; |
1178 | 1010 | layer = null; | 1044 | layer = null; |
1179 | @@ -1014,13 +1048,13 @@ | |||
1180 | 1014 | // selectedText - returns the current text selection or and empty string | 1048 | // selectedText - returns the current text selection or and empty string |
1181 | 1015 | function selectedText(editor) { | 1049 | function selectedText(editor) { |
1182 | 1016 | restoreRange(editor); | 1050 | restoreRange(editor); |
1184 | 1017 | if (ie) return getRange(editor).text; | 1051 | if (ie) {return getRange(editor).text;} |
1185 | 1018 | return getSelection(editor).toString(); | 1052 | return getSelection(editor).toString(); |
1186 | 1019 | } | 1053 | } |
1187 | 1020 | 1054 | ||
1188 | 1021 | // showMessage - alert replacement | 1055 | // showMessage - alert replacement |
1189 | 1022 | function showMessage(editor, message, button) { | 1056 | function showMessage(editor, message, button) { |
1191 | 1023 | var popup = createPopup("msg", editor.options, MSG_CLASS); | 1057 | var popup = createPopup('msg', editor.options, MSG_CLASS); |
1192 | 1024 | popup.innerHTML = message; | 1058 | popup.innerHTML = message; |
1193 | 1025 | showPopup(editor, popup, button); | 1059 | showPopup(editor, popup, button); |
1194 | 1026 | } | 1060 | } |
1195 | @@ -1056,31 +1090,32 @@ | |||
1196 | 1056 | } | 1090 | } |
1197 | 1057 | 1091 | ||
1198 | 1058 | // Focus the first input element if any | 1092 | // Focus the first input element if any |
1201 | 1059 | setTimeout(function() { | 1093 | setTimeout(function () { |
1202 | 1060 | $popup.find(":text,textarea").eq(0).focus().select(); | 1094 | $popup.find(':text, textarea').eq(0).focus().select(); |
1203 | 1061 | }, 100); | 1095 | }, 100); |
1204 | 1062 | 1096 | ||
1205 | 1063 | } | 1097 | } |
1206 | 1064 | 1098 | ||
1207 | 1065 | // sourceMode - returns true if the textarea is showing | 1099 | // sourceMode - returns true if the textarea is showing |
1208 | 1066 | function sourceMode(editor) { | 1100 | function sourceMode(editor) { |
1210 | 1067 | return editor.$area.is(":visible"); | 1101 | return editor.$area.is(':visible'); |
1211 | 1068 | } | 1102 | } |
1212 | 1069 | 1103 | ||
1213 | 1070 | // updateFrame - updates the iframe with the textarea contents | 1104 | // updateFrame - updates the iframe with the textarea contents |
1214 | 1071 | function updateFrame(editor, checkForChange) { | 1105 | function updateFrame(editor, checkForChange) { |
1215 | 1072 | 1106 | ||
1219 | 1073 | var code = editor.$area.val(), | 1107 | var code = editor.$area.val(), |
1220 | 1074 | options = editor.options, | 1108 | options = editor.options, |
1221 | 1075 | updateFrameCallback = options.updateFrame, | 1109 | updateFrameCallback = options.updateFrame, |
1222 | 1076 | $body = $(editor.doc.body); | 1110 | $body = $(editor.doc.body); |
1223 | 1077 | 1111 | ||
1224 | 1078 | // Check for textarea change to avoid unnecessary firing | 1112 | // Check for textarea change to avoid unnecessary firing |
1225 | 1079 | // of potentially heavy updateFrame callbacks. | 1113 | // of potentially heavy updateFrame callbacks. |
1226 | 1080 | if (updateFrameCallback) { | 1114 | if (updateFrameCallback) { |
1227 | 1081 | var sum = checksum(code); | 1115 | var sum = checksum(code); |
1229 | 1082 | if (checkForChange && editor.areaChecksum == sum) | 1116 | if (checkForChange && editor.areaChecksum === sum) { |
1230 | 1083 | return; | 1117 | return; |
1231 | 1118 | } | ||
1232 | 1084 | editor.areaChecksum = sum; | 1119 | editor.areaChecksum = sum; |
1233 | 1085 | } | 1120 | } |
1234 | 1086 | 1121 | ||
1235 | @@ -1088,14 +1123,15 @@ | |||
1236 | 1088 | var html = updateFrameCallback ? updateFrameCallback(code) : code; | 1123 | var html = updateFrameCallback ? updateFrameCallback(code) : code; |
1237 | 1089 | 1124 | ||
1238 | 1090 | // Prevent script injection attacks by html encoding script tags | 1125 | // Prevent script injection attacks by html encoding script tags |
1240 | 1091 | html = html.replace(/<(?=\/?script)/ig, "<"); | 1126 | html = html.replace(/<(?=\/?script)/ig, '<'); |
1241 | 1092 | 1127 | ||
1242 | 1093 | // Update the iframe checksum | 1128 | // Update the iframe checksum |
1244 | 1094 | if (options.updateTextArea) | 1129 | if (options.updateTextArea) { |
1245 | 1095 | editor.frameChecksum = checksum(html); | 1130 | editor.frameChecksum = checksum(html); |
1246 | 1131 | } | ||
1247 | 1096 | 1132 | ||
1248 | 1097 | // Update the iframe and trigger the change event | 1133 | // Update the iframe and trigger the change event |
1250 | 1098 | if (html != $body.html()) { | 1134 | if (html !== $body.html()) { |
1251 | 1099 | $body.html(html); | 1135 | $body.html(html); |
1252 | 1100 | $(editor).triggerHandler(CHANGE); | 1136 | $(editor).triggerHandler(CHANGE); |
1253 | 1101 | } | 1137 | } |
1254 | @@ -1105,17 +1141,18 @@ | |||
1255 | 1105 | // updateTextArea - updates the textarea with the iframe contents | 1141 | // updateTextArea - updates the textarea with the iframe contents |
1256 | 1106 | function updateTextArea(editor, checkForChange) { | 1142 | function updateTextArea(editor, checkForChange) { |
1257 | 1107 | 1143 | ||
1261 | 1108 | var html = $(editor.doc.body).html(), | 1144 | var html = $(editor.doc.body).html(), |
1262 | 1109 | options = editor.options, | 1145 | options = editor.options, |
1263 | 1110 | updateTextAreaCallback = options.updateTextArea, | 1146 | updateTextAreaCallback = options.updateTextArea, |
1264 | 1111 | $area = editor.$area; | 1147 | $area = editor.$area; |
1265 | 1112 | 1148 | ||
1266 | 1113 | // Check for iframe change to avoid unnecessary firing | 1149 | // Check for iframe change to avoid unnecessary firing |
1267 | 1114 | // of potentially heavy updateTextArea callbacks. | 1150 | // of potentially heavy updateTextArea callbacks. |
1268 | 1115 | if (updateTextAreaCallback) { | 1151 | if (updateTextAreaCallback) { |
1269 | 1116 | var sum = checksum(html); | 1152 | var sum = checksum(html); |
1271 | 1117 | if (checkForChange && editor.frameChecksum == sum) | 1153 | if (checkForChange && editor.frameChecksum === sum) { |
1272 | 1118 | return; | 1154 | return; |
1273 | 1155 | } | ||
1274 | 1119 | editor.frameChecksum = sum; | 1156 | editor.frameChecksum = sum; |
1275 | 1120 | } | 1157 | } |
1276 | 1121 | 1158 | ||
1277 | @@ -1123,11 +1160,12 @@ | |||
1278 | 1123 | var code = updateTextAreaCallback ? updateTextAreaCallback(html) : html; | 1160 | var code = updateTextAreaCallback ? updateTextAreaCallback(html) : html; |
1279 | 1124 | 1161 | ||
1280 | 1125 | // Update the textarea checksum | 1162 | // Update the textarea checksum |
1282 | 1126 | if (options.updateFrame) | 1163 | if (options.updateFrame) { |
1283 | 1127 | editor.areaChecksum = checksum(code); | 1164 | editor.areaChecksum = checksum(code); |
1284 | 1165 | } | ||
1285 | 1128 | 1166 | ||
1286 | 1129 | // Update the textarea and trigger the change event | 1167 | // Update the textarea and trigger the change event |
1288 | 1130 | if (code != $area.val()) { | 1168 | if (code !== $area.val()) { |
1289 | 1131 | $area.val(code); | 1169 | $area.val(code); |
1290 | 1132 | $(editor).triggerHandler(CHANGE); | 1170 | $(editor).triggerHandler(CHANGE); |
1291 | 1133 | } | 1171 | } |
1292 | 1134 | 1172 | ||
1293 | === modified file 'addons/web/static/src/js/view_form.js' | |||
1294 | --- addons/web/static/src/js/view_form.js 2012-12-21 14:02:36 +0000 | |||
1295 | +++ addons/web/static/src/js/view_form.js 2012-12-21 17:26:22 +0000 | |||
1296 | @@ -2624,7 +2624,7 @@ | |||
1297 | 2624 | this.$textarea = this.$el.find('textarea'); | 2624 | this.$textarea = this.$el.find('textarea'); |
1298 | 2625 | var width = ((this.node.attrs || {}).editor_width || '100%'); | 2625 | var width = ((this.node.attrs || {}).editor_width || '100%'); |
1299 | 2626 | var height = ((this.node.attrs || {}).editor_height || 250); | 2626 | var height = ((this.node.attrs || {}).editor_height || 250); |
1301 | 2627 | this.$textarea.cleditor({ | 2627 | this.$cleditor = this.$textarea.cleditor({ |
1302 | 2628 | width: width, // width not including margins, borders or padding | 2628 | width: width, // width not including margins, borders or padding |
1303 | 2629 | height: height, // height not including margins, borders or padding | 2629 | height: height, // height not including margins, borders or padding |
1304 | 2630 | controls: // controls to add to the toolbar | 2630 | controls: // controls to add to the toolbar |
1305 | @@ -2634,10 +2634,9 @@ | |||
1306 | 2634 | bodyStyle: // style to assign to document body contained within the editor | 2634 | bodyStyle: // style to assign to document body contained within the editor |
1307 | 2635 | "margin:4px; font:12px monospace; cursor:text; color:#1F1F1F" | 2635 | "margin:4px; font:12px monospace; cursor:text; color:#1F1F1F" |
1308 | 2636 | }); | 2636 | }); |
1311 | 2637 | this.$cleditor = this.$textarea.cleditor()[0]; | 2637 | this.$cleditor.on('change', function() { |
1310 | 2638 | this.$cleditor.change(function() { | ||
1312 | 2639 | if (! self._updating_editor) { | 2638 | if (! self._updating_editor) { |
1314 | 2640 | self.$cleditor.updateTextArea(); | 2639 | self.$cleditor[0].updateTextArea(); |
1315 | 2641 | self.internal_set_value(self.$textarea.val()); | 2640 | self.internal_set_value(self.$textarea.val()); |
1316 | 2642 | } | 2641 | } |
1317 | 2643 | }); | 2642 | }); |
1318 | @@ -2647,7 +2646,7 @@ | |||
1319 | 2647 | if (! this.get("effective_readonly")) { | 2646 | if (! this.get("effective_readonly")) { |
1320 | 2648 | this.$textarea.val(this.get('value') || ''); | 2647 | this.$textarea.val(this.get('value') || ''); |
1321 | 2649 | this._updating_editor = true; | 2648 | this._updating_editor = true; |
1323 | 2650 | this.$cleditor.updateFrame(); | 2649 | this.$cleditor[0].updateFrame(); |
1324 | 2651 | this._updating_editor = false; | 2650 | this._updating_editor = false; |
1325 | 2652 | } else { | 2651 | } else { |
1326 | 2653 | this.$el.html(this.get('value')); | 2652 | this.$el.html(this.get('value')); |