3 jQuery'fied spell checker based on GoogieSpell 4.0
4 (which was published under GPL "version 2 or any later version")
6 Copyright (C) 2006 Amir Salihefendic
7 Copyright (C) 2009 Aleksander Machniak
8 Copyright (C) 2011 Kolab Systems AG
12 4mir Salihefendic (http://amix.dk) - amix@amix.dk
13 Aleksander Machniak - alec [at] alec.pl
17 GOOGIE_DEFAULT_LANG = 'en';
19 function GoogieSpell(img_dir, server_url, has_dict)
22 cookie_value = getCookie('language');
24 GOOGIE_CUR_LANG = cookie_value != null ? cookie_value : GOOGIE_DEFAULT_LANG;
26 this.array_keys = function(arr) {
28 for (var key in arr) { res.push([key]); }
32 this.img_dir = img_dir;
33 this.server_url = server_url;
35 this.org_lang_to_word = {
36 "da": "Dansk", "de": "Deutsch", "en": "English",
37 "es": "Español", "fr": "Français", "it": "Italiano",
38 "nl": "Nederlands", "pl": "Polski", "pt": "Português",
39 "fi": "Suomi", "sv": "Svenska"
41 this.lang_to_word = this.org_lang_to_word;
42 this.langlist_codes = this.array_keys(this.lang_to_word);
43 this.show_change_lang_pic = true;
44 this.change_lang_pic_placement = 'right';
45 this.report_state_change = true;
47 this.ta_scroll_top = 0;
48 this.el_scroll_top = 0;
50 this.lang_chck_spell = "Check spelling";
51 this.lang_revert = "Revert to";
52 this.lang_close = "Close";
53 this.lang_rsm_edt = "Resume editing";
54 this.lang_no_error_found = "No spelling errors found";
55 this.lang_no_suggestions = "No suggestions";
56 this.lang_learn_word = "Add to dictionary";
58 this.show_spell_img = false; // roundcube mod.
59 this.decoration = true;
60 this.use_close_btn = false;
61 this.edit_layer_dbl_click = true;
62 this.report_ta_not_found = true;
65 this.custom_ajax_error = null;
66 this.custom_no_spelling_error = null;
67 this.custom_menu_builder = []; // Should take an eval function and a build menu function
68 this.custom_item_evaulator = null; // Should take an eval function and a build menu function
69 this.extra_menu_items = [];
70 this.custom_spellcheck_starter = null;
71 this.main_controller = true;
72 this.has_dictionary = has_dict;
75 this.lang_state_observer = null;
76 this.spelling_state_observer = null;
77 this.show_menu_observer = null;
78 this.all_errors_fixed_observer = null;
80 // Focus links - used to give the text box focus
81 this.use_focus = false;
82 this.focus_link_t = null;
83 this.focus_link_b = null;
87 this.cnt_errors_fixed = 0;
89 // Set document's onclick to hide the language and error menu
90 $(document).bind('click', function(e) {
91 var target = $(e.target);
92 if(target.attr('googie_action_btn') != '1' && ref.isLangWindowShown())
94 if(target.attr('googie_action_btn') != '1' && ref.isErrorWindowShown())
95 ref.hideErrorWindow();
99 this.decorateTextarea = function(id)
101 this.text_area = typeof id === 'string' ? document.getElementById(id) : id;
103 if (this.text_area) {
104 if (!this.spell_container && this.decoration) {
105 var table = document.createElement('table'),
106 tbody = document.createElement('tbody'),
107 tr = document.createElement('tr'),
108 spell_container = document.createElement('td'),
109 r_width = this.isDefined(this.force_width) ? this.force_width : this.text_area.offsetWidth,
110 r_height = this.isDefined(this.force_height) ? this.force_height : 16;
112 tr.appendChild(spell_container);
113 tbody.appendChild(tr);
114 $(table).append(tbody).insertBefore(this.text_area).width('100%').height(r_height);
115 $(spell_container).height(r_height).width(r_width).css('text-align', 'right');
117 this.spell_container = spell_container;
120 this.checkSpellingState();
122 else if (this.report_ta_not_found)
123 alert('Text area not found');
127 // API Functions (the ones that you can call)
129 this.setSpellContainer = function(id)
131 this.spell_container = typeof id === 'string' ? document.getElementById(id) : id;
134 this.setLanguages = function(lang_dict)
136 this.lang_to_word = lang_dict;
137 this.langlist_codes = this.array_keys(lang_dict);
140 this.setCurrentLanguage = function(lan_code)
142 GOOGIE_CUR_LANG = lan_code;
145 var now = new Date();
146 now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
147 setCookie('language', lan_code, now);
150 this.setForceWidthHeight = function(width, height)
152 // Set to null if you want to use one of them
153 this.force_width = width;
154 this.force_height = height;
157 this.setDecoration = function(bool)
159 this.decoration = bool;
162 this.dontUseCloseButtons = function()
164 this.use_close_btn = false;
167 this.appendNewMenuItem = function(name, call_back_fn, checker)
169 this.extra_menu_items.push([name, call_back_fn, checker]);
172 this.appendCustomMenuBuilder = function(eval_fn, builder)
174 this.custom_menu_builder.push([eval_fn, builder]);
177 this.setFocus = function()
180 this.focus_link_b.focus();
181 this.focus_link_t.focus();
191 // Set functions (internal)
193 this.setStateChanged = function(current_state)
195 this.state = current_state;
196 if (this.spelling_state_observer != null && this.report_state_change)
197 this.spelling_state_observer(current_state, this);
200 this.setReportStateChange = function(bool)
202 this.report_state_change = bool;
209 this.getUrl = function()
211 return this.server_url + GOOGIE_CUR_LANG;
214 this.escapeSpecial = function(val)
216 return val ? val.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">") : '';
219 this.createXMLReq = function (text)
221 return '<?xml version="1.0" encoding="utf-8" ?>'
222 + '<spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1">'
223 + '<text>' + text + '</text></spellrequest>';
226 this.spellCheck = function(ignore)
228 this.prepare(ignore);
230 var req_text = this.escapeSpecial(this.orginal_text),
233 $.ajax({ type: 'POST', url: this.getUrl(), data: this.createXMLReq(req_text), dataType: 'text',
235 if (ref.custom_ajax_error)
236 ref.custom_ajax_error(ref);
238 alert('An error was encountered on the server. Please try again later.');
239 if (ref.main_controller) {
240 $(ref.spell_span).remove();
241 ref.removeIndicator();
243 ref.checkSpellingState();
245 success: function(data) {
246 ref.processData(data);
247 if (!ref.results.length) {
248 if (!ref.custom_no_spelling_error)
249 ref.flashNoSpellingErrorState();
251 ref.custom_no_spelling_error(ref);
253 ref.removeIndicator();
258 this.learnWord = function(word, id)
260 word = this.escapeSpecial(word.innerHTML);
263 req_text = '<?xml version="1.0" encoding="utf-8" ?><learnword><text>' + word + '</text></learnword>';
265 $.ajax({ type: 'POST', url: this.getUrl(), data: req_text, dataType: 'text',
267 if (ref.custom_ajax_error)
268 ref.custom_ajax_error(ref);
270 alert('An error was encountered on the server. Please try again later.');
272 success: function(data) {
279 // Spell checking functions
281 this.prepare = function(ignore, no_indicator)
283 this.cnt_errors_fixed = 0;
285 this.setStateChanged('checking_spell');
287 if (!no_indicator && this.main_controller)
288 this.appendIndicator(this.spell_span);
290 this.error_links = [];
291 this.ta_scroll_top = this.text_area.scrollTop;
292 this.ignore = ignore;
293 this.hideLangWindow();
295 if ($(this.text_area).val() == '' || ignore) {
296 if (!this.custom_no_spelling_error)
297 this.flashNoSpellingErrorState();
299 this.custom_no_spelling_error(this);
300 this.removeIndicator();
304 this.createEditLayer(this.text_area.offsetWidth, this.text_area.offsetHeight);
305 this.createErrorWindow();
306 $('body').append(this.error_window);
308 try { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); }
311 if (this.main_controller)
312 $(this.spell_span).unbind('click');
314 this.orginal_text = $(this.text_area).val();
317 this.parseResult = function(r_text)
319 // Returns an array: result[item] -> ['attrs'], ['suggestions']
320 var re_split_attr_c = /\w+="(\d+|true)"/g,
321 re_split_text = /\t/g,
322 matched_c = r_text.match(/<c[^>]*>[^<]*<\/c>/g),
325 if (matched_c == null)
328 for (var i=0, len=matched_c.length; i < len; i++) {
335 split_c = matched_c[i].match(re_split_attr_c);
336 for (var j=0; j < split_c.length; j++) {
337 c_attr = split_c[j].split(/=/);
338 val = c_attr[1].replace(/"/g, '');
339 item['attrs'][c_attr[0]] = val != 'true' ? parseInt(val) : val;
343 item['suggestions'] = [];
344 var only_text = matched_c[i].replace(/<[^>]*>/g, ''),
345 split_t = only_text.split(re_split_text);
346 for (var k=0; k < split_t.length; k++) {
348 item['suggestions'].push(split_t[k]);
356 this.processData = function(data)
358 this.results = this.parseResult(data);
359 if (this.results.length) {
360 this.showErrorsInIframe();
361 this.resumeEditingState();
366 // Error menu functions
368 this.createErrorWindow = function()
370 this.error_window = document.createElement('div');
371 $(this.error_window).addClass('googie_window popupmenu').attr('googie_action_btn', '1');
374 this.isErrorWindowShown = function()
376 return $(this.error_window).is(':visible');
379 this.hideErrorWindow = function()
381 $(this.error_window).hide();
382 $(this.error_window_iframe).hide();
385 this.updateOrginalText = function(offset, old_value, new_value, id)
387 var part_1 = this.orginal_text.substring(0, offset),
388 part_2 = this.orginal_text.substring(offset+old_value.length),
389 add_2_offset = new_value.length - old_value.length;
391 this.orginal_text = part_1 + new_value + part_2;
392 $(this.text_area).val(this.orginal_text);
393 for (var j=0, len=this.results.length; j<len; j++) {
394 // Don't edit the offset of the current item
395 if (j != id && j > id)
396 this.results[j]['attrs']['o'] += add_2_offset;
400 this.saveOldValue = function(elm, old_value) {
401 elm.is_changed = true;
402 elm.old_value = old_value;
405 this.createListSeparator = function()
407 var td = document.createElement('td'),
408 tr = document.createElement('tr');
410 $(td).html(' ').attr('googie_action_btn', '1')
411 .css({'cursor': 'default', 'font-size': '3px', 'border-top': '1px solid #ccc', 'padding-top': '3px'});
417 this.correctError = function(id, elm, l_elm, rm_pre_space)
419 var old_value = elm.innerHTML,
420 new_value = l_elm.nodeType == 3 ? l_elm.nodeValue : l_elm.innerHTML,
421 offset = this.results[id]['attrs']['o'];
424 var pre_length = elm.previousSibling.innerHTML;
425 elm.previousSibling.innerHTML = pre_length.slice(0, pre_length.length-1);
426 old_value = " " + old_value;
430 this.hideErrorWindow();
431 this.updateOrginalText(offset, old_value, new_value, id);
433 $(elm).html(new_value).css('color', 'green').attr('is_corrected', true);
435 this.results[id]['attrs']['l'] = new_value.length;
437 if (!this.isDefined(elm.old_value))
438 this.saveOldValue(elm, old_value);
443 this.ignoreError = function(elm, id)
445 // @TODO: ignore all same words
446 $(elm).removeAttr('class').css('color', '').unbind();
447 this.hideErrorWindow();
450 this.showErrorWindow = function(elm, id)
452 if (this.show_menu_observer)
453 this.show_menu_observer(this);
456 pos = $(elm).offset(),
457 table = document.createElement('table'),
458 list = document.createElement('tbody');
460 $(this.error_window).html('');
461 $(table).addClass('googie_list').attr('googie_action_btn', '1');
463 // Check if we should use custom menu builder, if not we use the default
465 for (var k=0; k<this.custom_menu_builder.length; k++) {
466 var eb = this.custom_menu_builder[k];
467 if (eb[0](this.results[id])) {
468 changed = eb[1](this, list, elm);
474 // Build up the result list
475 var suggestions = this.results[id]['suggestions'],
476 offset = this.results[id]['attrs']['o'],
477 len = this.results[id]['attrs']['l'],
480 // [Add to dictionary] button
481 if (this.has_dictionary && !$(elm).attr('is_corrected')) {
482 row = document.createElement('tr'),
483 item = document.createElement('td'),
484 dummy = document.createElement('span');
486 $(dummy).text(this.lang_learn_word);
487 $(item).attr('googie_action_btn', '1').css('cursor', 'default')
488 .mouseover(ref.item_onmouseover)
489 .mouseout(ref.item_onmouseout)
491 ref.learnWord(elm, id);
492 ref.ignoreError(elm, id);
495 item.appendChild(dummy);
496 row.appendChild(item);
497 list.appendChild(row);
500 if (suggestions.length == 0) {
501 row = document.createElement('tr'),
502 item = document.createElement('td'),
503 dummy = document.createElement('span');
505 $(dummy).text(this.lang_no_suggestions);
506 $(item).attr('googie_action_btn', '1').css('cursor', 'default');
508 item.appendChild(dummy);
509 row.appendChild(item);
510 list.appendChild(row);
513 for (var i=0, len=suggestions.length; i < len; i++) {
514 row = document.createElement('tr'),
515 item = document.createElement('td'),
516 dummy = document.createElement('span');
518 $(dummy).html(suggestions[i]);
520 $(item).mouseover(this.item_onmouseover).mouseout(this.item_onmouseout)
521 .click(function(e) { ref.correctError(id, elm, e.target.firstChild) });
523 item.appendChild(dummy);
524 row.appendChild(item);
525 list.appendChild(row);
528 // The element is changed, append the revert
529 if (elm.is_changed && elm.innerHTML != elm.old_value) {
530 var old_value = elm.old_value,
531 revert_row = document.createElement('tr'),
532 revert = document.createElement('td'),
533 rev_span = document.createElement('span');
535 $(rev_span).addClass('googie_list_revert').html(this.lang_revert + ' ' + old_value);
537 $(revert).mouseover(this.item_onmouseover).mouseout(this.item_onmouseout)
539 ref.updateOrginalText(offset, elm.innerHTML, old_value, id);
540 $(elm).removeAttr('is_corrected').css('color', '#b91414').html(old_value);
541 ref.hideErrorWindow();
544 revert.appendChild(rev_span);
545 revert_row.appendChild(revert);
546 list.appendChild(revert_row);
549 // Append the edit box
550 var edit_row = document.createElement('tr'),
551 edit = document.createElement('td'),
552 edit_input = document.createElement('input'),
553 ok_pic = document.createElement('img'),
554 edit_form = document.createElement('form');
556 var onsub = function () {
557 if (edit_input.value != '') {
558 if (!ref.isDefined(elm.old_value))
559 ref.saveOldValue(elm, elm.innerHTML);
561 ref.updateOrginalText(offset, elm.innerHTML, edit_input.value, id);
562 $(elm).attr('is_corrected', true).css('color', 'green').html(edit_input.value);
563 ref.hideErrorWindow();
568 $(edit_input).width(120).css({'margin': 0, 'padding': 0});
569 $(edit_input).val(elm.innerHTML).attr('googie_action_btn', '1');
570 $(edit).css('cursor', 'default').attr('googie_action_btn', '1');
572 $(ok_pic).attr('src', this.img_dir + 'ok.gif')
573 .width(32).height(16)
574 .css({'cursor': 'pointer', 'margin-left': '2px', 'margin-right': '2px'})
577 $(edit_form).attr('googie_action_btn', '1')
578 .css({'margin': 0, 'padding': 0, 'cursor': 'default', 'white-space': 'nowrap'})
581 edit_form.appendChild(edit_input);
582 edit_form.appendChild(ok_pic);
583 edit.appendChild(edit_form);
584 edit_row.appendChild(edit);
585 list.appendChild(edit_row);
587 // Append extra menu items
588 if (this.extra_menu_items.length > 0)
589 list.appendChild(this.createListSeparator());
591 var loop = function(i) {
592 if (i < ref.extra_menu_items.length) {
593 var e_elm = ref.extra_menu_items[i];
595 if (!e_elm[2] || e_elm[2](elm, ref)) {
596 var e_row = document.createElement('tr'),
597 e_col = document.createElement('td');
599 $(e_col).html(e_elm[0])
600 .mouseover(ref.item_onmouseover)
601 .mouseout(ref.item_onmouseout)
602 .click(function() { return e_elm[1](elm, ref) });
604 e_row.appendChild(e_col);
605 list.appendChild(e_row);
615 if (this.use_close_btn) {
616 list.appendChild(this.createCloseButton(this.hideErrorWindow));
620 table.appendChild(list);
621 this.error_window.appendChild(table);
623 // calculate and set position
624 var height = $(this.error_window).height(),
625 width = $(this.error_window).width(),
626 pageheight = $(document).height(),
627 pagewidth = $(document).width(),
628 top = pos.top + height + 20 < pageheight ? pos.top + 20 : pos.top - height,
629 left = pos.left + width < pagewidth ? pos.left : pos.left - width;
631 $(this.error_window).css({'top': top+'px', 'left': left+'px'}).show();
633 // Dummy for IE - dropdown bug fix
634 if ($.browser.msie) {
635 if (!this.error_window_iframe) {
636 var iframe = $('<iframe>').css({'position': 'absolute', 'z-index': -1});
637 $('body').append(iframe);
638 this.error_window_iframe = iframe;
641 $(this.error_window_iframe)
642 .css({'top': this.error_window.offsetTop, 'left': this.error_window.offsetLeft,
643 'width': this.error_window.offsetWidth, 'height': this.error_window.offsetHeight})
650 // Edit layer (the layer where the suggestions are stored)
652 this.createEditLayer = function(width, height)
654 this.edit_layer = document.createElement('div');
655 $(this.edit_layer).addClass('googie_edit_layer').attr('id', 'googie_edit_layer')
656 .width('auto').height(height);
658 if (this.text_area.nodeName.toLowerCase() != 'input' || $(this.text_area).val() == '') {
659 $(this.edit_layer).css('overflow', 'auto').height(height-4);
661 $(this.edit_layer).css('overflow', 'hidden');
666 if (this.edit_layer_dbl_click) {
667 $(this.edit_layer).dblclick(function(e) {
668 if (e.target.className != 'googie_link' && !ref.isErrorWindowShown()) {
670 var fn1 = function() {
671 $(ref.text_area).focus();
674 window.setTimeout(fn1, 10);
681 this.resumeEditing = function()
683 this.setStateChanged('ready');
686 this.el_scroll_top = this.edit_layer.scrollTop;
688 this.hideErrorWindow();
690 if (this.main_controller)
691 $(this.spell_span).removeClass().addClass('googie_no_style');
694 if (this.use_focus) {
695 $(this.focus_link_t).remove();
696 $(this.focus_link_b).remove();
699 $(this.edit_layer).remove();
700 $(this.text_area).show();
702 if (this.el_scroll_top != undefined)
703 this.text_area.scrollTop = this.el_scroll_top;
705 this.checkSpellingState(false);
708 this.createErrorLink = function(text, id)
710 var elm = document.createElement('span'),
713 ref.showErrorWindow(elm, id);
718 $(elm).html(text).addClass('googie_link').click(d).removeAttr('is_corrected')
719 .attr({'googie_action_btn' : '1', 'g_id' : id});
724 this.createPart = function(txt_part)
727 return document.createTextNode(" ");
729 txt_part = this.escapeSpecial(txt_part);
730 txt_part = txt_part.replace(/\n/g, "<br>");
731 txt_part = txt_part.replace(/ /g, " ");
732 txt_part = txt_part.replace(/^ /g, " ");
733 txt_part = txt_part.replace(/ $/g, " ");
735 var span = document.createElement('span');
736 $(span).html(txt_part);
740 this.showErrorsInIframe = function()
742 var output = document.createElement('div'),
744 results = this.results;
746 if (results.length > 0) {
747 for (var i=0, length=results.length; i < length; i++) {
748 var offset = results[i]['attrs']['o'],
749 len = results[i]['attrs']['l'],
750 part_1_text = this.orginal_text.substring(pointer, offset),
751 part_1 = this.createPart(part_1_text);
753 output.appendChild(part_1);
754 pointer += offset - pointer;
756 // If the last child was an error, then insert some space
757 var err_link = this.createErrorLink(this.orginal_text.substr(offset, len), i);
758 this.error_links.push(err_link);
759 output.appendChild(err_link);
763 // Insert the rest of the orginal text
764 var part_2_text = this.orginal_text.substr(pointer, this.orginal_text.length),
765 part_2 = this.createPart(part_2_text);
767 output.appendChild(part_2);
770 output.innerHTML = this.orginal_text;
772 $(output).css('text-align', 'left');
775 if (this.custom_item_evaulator)
776 $.map(this.error_links, function(elm){me.custom_item_evaulator(me, elm)});
778 $(this.edit_layer).append(output);
780 // Hide text area and show edit layer
781 $(this.text_area).hide();
782 $(this.edit_layer).insertBefore(this.text_area);
784 if (this.use_focus) {
785 this.focus_link_t = this.createFocusLink('focus_t');
786 this.focus_link_b = this.createFocusLink('focus_b');
788 $(this.focus_link_t).insertBefore(this.edit_layer);
789 $(this.focus_link_b).insertAfter(this.edit_layer);
792 // this.edit_layer.scrollTop = this.ta_scroll_top;
797 // Choose language menu
799 this.createLangWindow = function()
801 this.language_window = document.createElement('div');
802 $(this.language_window).addClass('googie_window popupmenu')
803 .width(100).attr('googie_action_btn', '1');
805 // Build up the result list
806 var table = document.createElement('table'),
807 list = document.createElement('tbody'),
811 $(table).addClass('googie_list').width('100%');
814 for (i=0; i < this.langlist_codes.length; i++) {
815 row = document.createElement('tr');
816 item = document.createElement('td');
817 span = document.createElement('span');
819 $(span).text(this.lang_to_word[this.langlist_codes[i]]);
820 this.lang_elms.push(item);
822 $(item).attr('googieId', this.langlist_codes[i])
823 .bind('click', function(e) {
824 ref.deHighlightCurSel();
825 ref.setCurrentLanguage($(this).attr('googieId'));
827 if (ref.lang_state_observer != null) {
828 ref.lang_state_observer();
831 ref.highlightCurSel();
832 ref.hideLangWindow();
834 .bind('mouseover', function(e) {
835 if (this.className != "googie_list_selected")
836 this.className = "googie_list_onhover";
838 .bind('mouseout', function(e) {
839 if (this.className != "googie_list_selected")
840 this.className = "googie_list_onout";
843 item.appendChild(span);
844 row.appendChild(item);
845 list.appendChild(row);
849 if (this.use_close_btn) {
850 list.appendChild(this.createCloseButton(function () { ref.hideLangWindow.apply(ref) }));
853 this.highlightCurSel();
855 table.appendChild(list);
856 this.language_window.appendChild(table);
859 this.isLangWindowShown = function()
861 return $(this.language_window).is(':visible');
864 this.hideLangWindow = function()
866 $(this.language_window).hide();
867 $(this.switch_lan_pic).removeClass().addClass('googie_lang_3d_on');
870 this.showLangWindow = function(elm)
872 if (this.show_menu_observer)
873 this.show_menu_observer(this);
875 this.createLangWindow();
876 $('body').append(this.language_window);
878 var pos = $(elm).offset(),
879 height = $(elm).height(),
880 width = $(elm).width(),
881 h = $(this.language_window).height(),
882 pageheight = $(document).height(),
883 left = this.change_lang_pic_placement == 'right' ?
884 pos.left - 100 + width : pos.left + width,
885 top = pos.top + h < pageheight ? pos.top + height : pos.top - h - 4;
887 $(this.language_window).css({'top' : top+'px','left' : left+'px'}).show();
889 this.highlightCurSel();
892 this.deHighlightCurSel = function()
894 $(this.lang_cur_elm).removeClass().addClass('googie_list_onout');
897 this.highlightCurSel = function()
899 if (GOOGIE_CUR_LANG == null)
900 GOOGIE_CUR_LANG = GOOGIE_DEFAULT_LANG;
901 for (var i=0; i < this.lang_elms.length; i++) {
902 if ($(this.lang_elms[i]).attr('googieId') == GOOGIE_CUR_LANG) {
903 this.lang_elms[i].className = 'googie_list_selected';
904 this.lang_cur_elm = this.lang_elms[i];
907 this.lang_elms[i].className = 'googie_list_onout';
912 this.createChangeLangPic = function()
915 .attr({src: this.img_dir + 'change_lang.gif', 'alt': 'Change language', 'googie_action_btn': '1'}),
916 switch_lan = document.createElement('span');
919 $(switch_lan).addClass('googie_lang_3d_on')
921 .bind('click', function(e) {
922 var elm = this.tagName.toLowerCase() == 'img' ? this.parentNode : this;
923 if($(elm).hasClass('googie_lang_3d_click')) {
924 elm.className = 'googie_lang_3d_on';
925 ref.hideLangWindow();
928 elm.className = 'googie_lang_3d_click';
929 ref.showLangWindow(elm);
936 this.createSpellDiv = function()
938 var span = document.createElement('span');
940 $(span).addClass('googie_check_spelling_link').text(this.lang_chck_spell);
942 if (this.show_spell_img) {
943 $(span).append(' ').append($('<img>').attr('src', this.img_dir + 'spellc.gif'));
952 this.flashNoSpellingErrorState = function(on_finish)
954 this.setStateChanged('no_error_found');
957 if (this.main_controller) {
960 var fn = function() {
962 ref.checkSpellingState();
964 no_spell_errors = fn;
967 no_spell_errors = function () { ref.checkSpellingState() };
969 var rsm = $('<span>').text(this.lang_no_error_found);
971 $(this.switch_lan_pic).hide();
972 $(this.spell_span).empty().append(rsm)
973 .removeClass().addClass('googie_check_spelling_ok');
975 window.setTimeout(no_spell_errors, 1000);
979 this.resumeEditingState = function()
981 this.setStateChanged('resume_editing');
983 //Change link text to resume
984 if (this.main_controller) {
985 var rsm = $('<span>').text(this.lang_rsm_edt);
988 $(this.switch_lan_pic).hide();
989 $(this.spell_span).empty().unbind().append(rsm)
990 .bind('click', function() { ref.resumeEditing() })
991 .removeClass().addClass('googie_resume_editing');
994 try { this.edit_layer.scrollTop = this.ta_scroll_top; }
998 this.checkSpellingState = function(fire)
1001 this.setStateChanged('ready');
1003 if (this.show_change_lang_pic)
1004 this.switch_lan_pic = this.createChangeLangPic();
1006 this.switch_lan_pic = document.createElement('span');
1008 var span_chck = this.createSpellDiv(),
1011 if (this.custom_spellcheck_starter)
1012 $(span_chck).bind('click', function(e) { ref.custom_spellcheck_starter() });
1014 $(span_chck).bind('click', function(e) { ref.spellCheck() });
1017 if (this.main_controller) {
1018 if (this.change_lang_pic_placement == 'left') {
1019 $(this.spell_container).empty().append(this.switch_lan_pic).append(' ').append(span_chck);
1021 $(this.spell_container).empty().append(span_chck).append(' ').append(this.switch_lan_pic);
1025 this.spell_span = span_chck;
1032 this.isDefined = function(o)
1034 return (o !== undefined && o !== null)
1037 this.errorFixed = function()
1039 this.cnt_errors_fixed++;
1040 if (this.all_errors_fixed_observer)
1041 if (this.cnt_errors_fixed == this.cnt_errors) {
1042 this.hideErrorWindow();
1043 this.all_errors_fixed_observer();
1047 this.errorFound = function()
1052 this.createCloseButton = function(c_fn)
1054 return this.createButton(this.lang_close, 'googie_list_close', c_fn);
1057 this.createButton = function(name, css_class, c_fn)
1059 var btn_row = document.createElement('tr'),
1060 btn = document.createElement('td'),
1064 spn_btn = document.createElement('span');
1065 $(spn_btn).addClass(css_class).html(name);
1067 spn_btn = document.createTextNode(name);
1070 $(btn).bind('click', c_fn)
1071 .bind('mouseover', this.item_onmouseover)
1072 .bind('mouseout', this.item_onmouseout);
1074 btn.appendChild(spn_btn);
1075 btn_row.appendChild(btn);
1080 this.removeIndicator = function(elm)
1082 //$(this.indicator).remove();
1085 rcmail.set_busy(false, null, this.rc_msg_id);
1088 this.appendIndicator = function(elm)
1090 // modified by roundcube
1092 this.rc_msg_id = rcmail.set_busy(true, 'checking');
1094 this.indicator = document.createElement('img');
1095 $(this.indicator).attr('src', this.img_dir + 'indicator.gif')
1096 .css({'margin-right': '5px', 'text-decoration': 'none'}).width(16).height(16);
1099 $(this.indicator).insertBefore(elm);
1101 $('body').append(this.indicator);
1105 this.createFocusLink = function(name)
1107 var link = document.createElement('a');
1108 $(link).attr({'href': 'javascript:;', 'name': name});
1112 this.item_onmouseover = function(e)
1114 if (this.className != 'googie_list_revert' && this.className != 'googie_list_close')
1115 this.className = 'googie_list_onhover';
1117 this.parentNode.className = 'googie_list_onhover';
1120 this.item_onmouseout = function(e)
1122 if (this.className != 'googie_list_revert' && this.className != 'googie_list_close')
1123 this.className = 'googie_list_onout';
1125 this.parentNode.className = 'googie_list_onout';