Changeset ae8a2a55 in github


Ignore:
Timestamp:
Jun 2, 2010 8:06:10 AM (3 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
05a631a
Parents:
1126fc6
Message:
  • fixed identation + some code improvements
File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/js/googiespell.js

    r677e1f2 rae8a2a55  
    88     AUTHORS 
    99         4mir Salihefendic (http://amix.dk) - amix@amix.dk 
    10          Aleksander Machniak - alec [at] alec.pl 
     10            Aleksander Machniak - alec [at] alec.pl 
    1111*/ 
    1212 
     
    1515 
    1616function GoogieSpell(img_dir, server_url) { 
    17     var ref = this; 
     17    var ref = this, 
     18        cookie_value = getCookie('language'); 
     19 
     20    GOOGIE_CUR_LANG = cookie_value != null ? cookie_value : GOOGIE_DEFAULT_LANG; 
    1821 
    1922    this.array_keys = function(arr) { 
    20         var res = []; 
    21         for (var key in arr) { res.push([key]); } 
    22         return res; 
    23     } 
    24      
    25     var cookie_value = getCookie('language'); 
    26     GOOGIE_CUR_LANG = cookie_value != null ? cookie_value : GOOGIE_DEFAULT_LANG; 
     23            var res = []; 
     24            for (var key in arr) { res.push([key]); } 
     25            return res; 
     26    } 
    2727 
    2828    this.img_dir = img_dir; 
     
    3030 
    3131    this.org_lang_to_word = { 
    32         "da": "Dansk", "de": "Deutsch", "en": "English", 
     32            "da": "Dansk", "de": "Deutsch", "en": "English", 
    3333        "es": "Espa&#241;ol", "fr": "Fran&#231;ais", "it": "Italiano",  
    3434        "nl": "Nederlands", "pl": "Polski", "pt": "Portugu&#234;s", 
     
    5050    this.lang_no_error_found = "No spelling errors found"; 
    5151    this.lang_no_suggestions = "No suggestions"; 
    52      
     52 
    5353    this.show_spell_img = false; // roundcube mod. 
    5454    this.decoration = true; 
     
    5757    this.report_ta_not_found = true; 
    5858 
    59     //Extensions 
     59    // Extensions 
    6060    this.custom_ajax_error = null; 
    6161    this.custom_no_spelling_error = null; 
    62     this.custom_menu_builder = []; //Should take an eval function and a build menu function 
    63     this.custom_item_evaulator = null; //Should take an eval function and a build menu function 
     62    this.custom_menu_builder = []; // Should take an eval function and a build menu function 
     63    this.custom_item_evaulator = null; // Should take an eval function and a build menu function 
    6464    this.extra_menu_items = []; 
    6565    this.custom_spellcheck_starter = null; 
    6666    this.main_controller = true; 
    6767 
    68     //Observers 
     68    // Observers 
    6969    this.lang_state_observer = null; 
    7070    this.spelling_state_observer = null; 
     
    7272    this.all_errors_fixed_observer = null; 
    7373 
    74     //Focus links - used to give the text box focus 
     74    // Focus links - used to give the text box focus 
    7575    this.use_focus = false; 
    7676    this.focus_link_t = null; 
    7777    this.focus_link_b = null; 
    7878 
    79     //Counters 
     79    // Counters 
    8080    this.cnt_errors = 0; 
    8181    this.cnt_errors_fixed = 0; 
    82      
    83     //Set document's onclick to hide the language and error menu 
     82 
     83    // Set document's onclick to hide the language and error menu 
    8484    $(document).bind('click', function(e) { 
    8585        if($(e.target).attr('googie_action_btn') != '1' && ref.isLangWindowShown()) 
    86             ref.hideLangWindow(); 
    87         if($(e.target).attr('googie_action_btn') != '1' && ref.isErrorWindowShown()) 
     86                ref.hideLangWindow(); 
     87            if($(e.target).attr('googie_action_btn') != '1' && ref.isErrorWindowShown()) 
    8888            ref.hideErrorWindow(); 
    8989    }); 
     
    9595    if (this.text_area) { 
    9696        if (!this.spell_container && this.decoration) { 
    97             var table = document.createElement('table'); 
    98             var tbody = document.createElement('tbody'); 
    99             var tr = document.createElement('tr'); 
    100             var spell_container = document.createElement('td'); 
    101  
    102             var r_width = this.isDefined(this.force_width) ? this.force_width : this.text_area.offsetWidth; 
    103             var r_height = this.isDefined(this.force_height) ? this.force_height : 16; 
     97            var table = document.createElement('table'), 
     98                tbody = document.createElement('tbody'), 
     99                tr = document.createElement('tr'), 
     100                spell_container = document.createElement('td'), 
     101                r_width = this.isDefined(this.force_width) ? this.force_width : this.text_area.offsetWidth, 
     102                r_height = this.isDefined(this.force_height) ? this.force_height : 16; 
    104103 
    105104            tr.appendChild(spell_container); 
     
    116115        if (this.report_ta_not_found) 
    117116            alert('Text area not found'); 
    118 } 
     117}; 
    119118 
    120119////// 
     
    123122this.setSpellContainer = function(id) { 
    124123    this.spell_container = typeof(id) == 'string' ? document.getElementById(id) : id; 
    125 } 
     124}; 
    126125 
    127126this.setLanguages = function(lang_dict) { 
    128127    this.lang_to_word = lang_dict; 
    129128    this.langlist_codes = this.array_keys(lang_dict); 
    130 } 
     129}; 
    131130 
    132131this.setCurrentLanguage = function(lan_code) { 
     
    137136    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); 
    138137    setCookie('language', lan_code, now); 
    139 } 
     138}; 
    140139 
    141140this.setForceWidthHeight = function(width, height) { 
     
    143142    this.force_width = width; 
    144143    this.force_height = height; 
    145 } 
     144}; 
    146145 
    147146this.setDecoration = function(bool) { 
    148147    this.decoration = bool; 
    149 } 
     148}; 
    150149 
    151150this.dontUseCloseButtons = function() { 
    152151    this.use_close_btn = false; 
    153 } 
     152}; 
    154153 
    155154this.appendNewMenuItem = function(name, call_back_fn, checker) { 
    156155    this.extra_menu_items.push([name, call_back_fn, checker]); 
    157 } 
     156}; 
    158157 
    159158this.appendCustomMenuBuilder = function(eval, builder) { 
    160159    this.custom_menu_builder.push([eval, builder]); 
    161 } 
     160}; 
    162161 
    163162this.setFocus = function() { 
     
    170169        return false; 
    171170    } 
    172 } 
     171}; 
    173172 
    174173 
     
    180179    if (this.spelling_state_observer != null && this.report_state_change) 
    181180        this.spelling_state_observer(current_state, this); 
    182 } 
     181}; 
    183182 
    184183this.setReportStateChange = function(bool) { 
    185184    this.report_state_change = bool; 
    186 } 
     185}; 
    187186 
    188187 
     
    192191this.getUrl = function() { 
    193192    return this.server_url + GOOGIE_CUR_LANG; 
    194 } 
     193}; 
    195194 
    196195this.escapeSpecial = function(val) { 
    197196    return val.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"); 
    198 } 
     197}; 
    199198 
    200199this.createXMLReq = function (text) { 
     
    202201        + '<spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1">' 
    203202        + '<text>' + text + '</text></spellrequest>'; 
    204 } 
     203}; 
    205204 
    206205this.spellCheck = function(ignore) { 
     
    230229    $('body').append(this.error_window); 
    231230 
    232     try { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); }  
     231    try { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); } 
    233232    catch (e) { } 
    234233 
     
    242241    $.ajax({ type: 'POST', url: this.getUrl(), 
    243242        data: this.createXMLReq(req_text), dataType: 'text', 
    244         error: function(o) { 
    245             if (ref.custom_ajax_error) 
    246                 ref.custom_ajax_error(ref); 
    247             else 
    248                 alert('An error was encountered on the server. Please try again later.'); 
    249             if (ref.main_controller) { 
    250                 $(ref.spell_span).remove(); 
    251                 ref.removeIndicator(); 
    252             } 
    253             ref.checkSpellingState(); 
    254         }, 
     243            error: function(o) { 
     244            if (ref.custom_ajax_error) 
     245                    ref.custom_ajax_error(ref); 
     246            else 
     247                    alert('An error was encountered on the server. Please try again later.'); 
     248            if (ref.main_controller) { 
     249                    $(ref.spell_span).remove(); 
     250                    ref.removeIndicator(); 
     251            } 
     252            ref.checkSpellingState(); 
     253            }, 
    255254        success: function(data) { 
    256             var r_text = data; 
     255                var r_text = data; 
    257256            ref.results = ref.parseResult(r_text); 
    258257            if (r_text.match(/<c.*>/) != null) { 
    259                 //Before parsing be sure that errors were found 
    260                 ref.showErrorsInIframe(); 
    261                 ref.resumeEditingState(); 
     258                    // Before parsing be sure that errors were found 
     259                    ref.showErrorsInIframe(); 
     260                    ref.resumeEditingState(); 
    262261            } else { 
    263                 if (!ref.custom_no_spelling_error) 
    264                     ref.flashNoSpellingErrorState(); 
     262                    if (!ref.custom_no_spelling_error) 
     263                        ref.flashNoSpellingErrorState(); 
    265264                else 
    266                     ref.custom_no_spelling_error(ref); 
     265                ref.custom_no_spelling_error(ref); 
    267266            } 
    268267            ref.removeIndicator(); 
    269         } 
     268            } 
    270269    }); 
    271 } 
     270}; 
    272271 
    273272 
     
    277276this.parseResult = function(r_text) { 
    278277    // Returns an array: result[item] -> ['attrs'], ['suggestions'] 
    279     var re_split_attr_c = /\w+="(\d+|true)"/g; 
    280     var re_split_text = /\t/g; 
    281  
    282     var matched_c = r_text.match(/<c[^>]*>[^<]*<\/c>/g); 
    283     var results = new Array(); 
     278    var re_split_attr_c = /\w+="(\d+|true)"/g, 
     279        re_split_text = /\t/g, 
     280        matched_c = r_text.match(/<c[^>]*>[^<]*<\/c>/g), 
     281        results = []; 
    284282 
    285283    if (matched_c == null) 
    286284        return results; 
    287      
    288     for (var i=0; i < matched_c.length; i++) { 
    289         var item = new Array(); 
     285 
     286    for (var i=0, len=matched_c.length; i < len; i++) { 
     287        var item = []; 
    290288        this.errorFound(); 
    291289 
    292         //Get attributes 
    293         item['attrs'] = new Array(); 
    294         var split_c = matched_c[i].match(re_split_attr_c); 
     290        // Get attributes 
     291        item['attrs'] = []; 
     292        var c_attr, val, 
     293            split_c = matched_c[i].match(re_split_attr_c); 
    295294        for (var j=0; j < split_c.length; j++) { 
    296             var c_attr = split_c[j].split(/=/); 
    297             var val = c_attr[1].replace(/"/g, ''); 
     295            c_attr = split_c[j].split(/=/); 
     296            val = c_attr[1].replace(/"/g, ''); 
    298297            item['attrs'][c_attr[0]] = val != 'true' ? parseInt(val) : val; 
    299298        } 
    300299 
    301         //Get suggestions 
    302         item['suggestions'] = new Array(); 
    303         var only_text = matched_c[i].replace(/<[^>]*>/g, ''); 
    304         var split_t = only_text.split(re_split_text); 
     300        // Get suggestions 
     301        item['suggestions'] = []; 
     302        var only_text = matched_c[i].replace(/<[^>]*>/g, ''), 
     303            split_t = only_text.split(re_split_text); 
    305304        for (var k=0; k < split_t.length; k++) { 
    306305            if(split_t[k] != '') 
     
    311310 
    312311    return results; 
    313 } 
     312}; 
    314313 
    315314 
     
    320319    this.error_window = document.createElement('div'); 
    321320    $(this.error_window).addClass('googie_window').attr('googie_action_btn', '1'); 
    322 } 
     321}; 
    323322 
    324323this.isErrorWindowShown = function() { 
    325324    return $(this.error_window).is(':visible'); 
    326 } 
     325}; 
    327326 
    328327this.hideErrorWindow = function() { 
    329328    $(this.error_window).css('visibility', 'hidden'); 
    330329    $(this.error_window_iframe).css('visibility', 'hidden'); 
    331 } 
     330}; 
    332331 
    333332this.updateOrginalText = function(offset, old_value, new_value, id) { 
    334     var part_1 = this.orginal_text.substring(0, offset); 
    335     var part_2 = this.orginal_text.substring(offset+old_value.length); 
     333    var part_1 = this.orginal_text.substring(0, offset), 
     334        part_2 = this.orginal_text.substring(offset+old_value.length), 
     335        add_2_offset = new_value.length - old_value.length; 
     336 
    336337    this.orginal_text = part_1 + new_value + part_2; 
    337338    $(this.text_area).val(this.orginal_text); 
    338     var add_2_offset = new_value.length - old_value.length; 
    339     for (var j=0; j < this.results.length; j++) { 
    340         //Don't edit the offset of the current item 
     339    for (var j=0, len=this.results.length; j<len; j++) { 
     340        // Don't edit the offset of the current item 
    341341        if (j != id && j > id) 
    342342            this.results[j]['attrs']['o'] += add_2_offset; 
    343343    } 
    344 } 
     344}; 
    345345 
    346346this.saveOldValue = function(elm, old_value) { 
    347347    elm.is_changed = true; 
    348348    elm.old_value = old_value; 
    349 } 
     349}; 
    350350 
    351351this.createListSeparator = function() { 
    352     var td = document.createElement('td'); 
    353     var tr = document.createElement('tr'); 
     352    var td = document.createElement('td'), 
     353        tr = document.createElement('tr'); 
    354354 
    355355    $(td).html(' ').attr('googie_action_btn', '1') 
     
    358358 
    359359    return tr; 
    360 } 
     360}; 
    361361 
    362362this.correctError = function(id, elm, l_elm, rm_pre_space) { 
    363     var old_value = elm.innerHTML; 
    364     var new_value = l_elm.nodeType == 3 ? l_elm.nodeValue : l_elm.innerHTML; 
    365     var offset = this.results[id]['attrs']['o']; 
     363    var old_value = elm.innerHTML, 
     364        new_value = l_elm.nodeType == 3 ? l_elm.nodeValue : l_elm.innerHTML, 
     365        offset = this.results[id]['attrs']['o']; 
    366366 
    367367    if (rm_pre_space) { 
     
    381381    if (!this.isDefined(elm.old_value)) 
    382382        this.saveOldValue(elm, old_value); 
    383      
     383 
    384384    this.errorFixed(); 
    385 } 
     385}; 
    386386 
    387387this.showErrorWindow = function(elm, id) { 
     
    389389        this.show_menu_observer(this); 
    390390 
    391     var ref = this; 
    392     var pos = $(elm).offset(); 
     391    var ref = this, 
     392        pos = $(elm).offset(), 
     393        table = document.createElement('table'), 
     394        list = document.createElement('tbody'); 
     395 
    393396    pos.top -= this.edit_layer.scrollTop; 
    394397 
     
    396399        'top': (pos.top+20)+'px', 'left': (pos.left)+'px'}).html(''); 
    397400 
    398     var table = document.createElement('table'); 
    399     var list = document.createElement('tbody'); 
    400  
    401401    $(table).addClass('googie_list').attr('googie_action_btn', '1'); 
    402402 
    403     //Check if we should use custom menu builder, if not we use the default 
     403    // Check if we should use custom menu builder, if not we use the default 
    404404    var changed = false; 
    405405    for (var k=0; k<this.custom_menu_builder.length; k++) { 
     
    411411    } 
    412412    if (!changed) { 
    413         //Build up the result list 
    414         var suggestions = this.results[id]['suggestions']; 
    415         var offset = this.results[id]['attrs']['o']; 
    416         var len = this.results[id]['attrs']['l']; 
     413        // Build up the result list 
     414        var suggestions = this.results[id]['suggestions'], 
     415            offset = this.results[id]['attrs']['o'], 
     416            len = this.results[id]['attrs']['l'], 
     417            row, item, dummy; 
    417418 
    418419        if (suggestions.length == 0) { 
    419             var row = document.createElement('tr'); 
    420             var item = document.createElement('td'); 
    421             var dummy = document.createElement('span'); 
     420            row = document.createElement('tr'), 
     421            item = document.createElement('td'), 
     422            dummy = document.createElement('span'); 
    422423 
    423424            $(dummy).text(this.lang_no_suggestions); 
     
    429430        } 
    430431 
    431         for (i=0; i < suggestions.length; i++) { 
    432             var row = document.createElement('tr'); 
    433             var item = document.createElement('td'); 
    434             var dummy = document.createElement('span'); 
     432        for (var i=0, len=suggestions.length; i < len; i++) { 
     433            row = document.createElement('tr'), 
     434            item = document.createElement('td'), 
     435            dummy = document.createElement('span'); 
    435436 
    436437            $(dummy).html(suggestions[i]); 
    437              
     438 
    438439            $(item).bind('mouseover', this.item_onmouseover) 
    439                 .bind('mouseout', this.item_onmouseout) 
    440                 .bind('click', function(e) { ref.correctError(id, elm, e.target.firstChild) }); 
     440                    .bind('mouseout', this.item_onmouseout) 
     441                    .bind('click', function(e) { ref.correctError(id, elm, e.target.firstChild) }); 
    441442 
    442443            item.appendChild(dummy); 
     
    447448        //The element is changed, append the revert 
    448449        if (elm.is_changed && elm.innerHTML != elm.old_value) { 
    449             var old_value = elm.old_value; 
    450             var revert_row = document.createElement('tr'); 
    451             var revert = document.createElement('td'); 
    452             var rev_span = document.createElement('span'); 
    453              
    454             $(rev_span).addClass('googie_list_revert').html(this.lang_revert + ' ' + old_value); 
     450            var old_value = elm.old_value, 
     451                revert_row = document.createElement('tr'), 
     452                revert = document.createElement('td'), 
     453                rev_span = document.createElement('span'); 
     454 
     455                $(rev_span).addClass('googie_list_revert').html(this.lang_revert + ' ' + old_value); 
    455456 
    456457            $(revert).bind('mouseover', this.item_onmouseover) 
    457                 .bind('mouseout', this.item_onmouseout) 
    458                 .bind('click', function(e) { 
     458                    .bind('mouseout', this.item_onmouseout) 
     459                    .bind('click', function(e) { 
    459460                    ref.updateOrginalText(offset, elm.innerHTML, old_value, id); 
    460461                    $(elm).attr('is_corrected', true).css('color', '#b91414').html(old_value); 
    461462                    ref.hideErrorWindow(); 
    462                 }); 
     463                    }); 
    463464 
    464465            revert.appendChild(rev_span); 
     
    467468        } 
    468469 
    469         //Append the edit box 
    470         var edit_row = document.createElement('tr'); 
    471         var edit = document.createElement('td'); 
    472         var edit_input = document.createElement('input'); 
    473         var ok_pic = document.createElement('img'); 
    474         var edit_form = document.createElement('form'); 
     470        // Append the edit box 
     471        var edit_row = document.createElement('tr'), 
     472            edit = document.createElement('td'), 
     473            edit_input = document.createElement('input'), 
     474            ok_pic = document.createElement('img'), 
     475                edit_form = document.createElement('form'); 
    475476 
    476477        var onsub = function () { 
     
    480481 
    481482                ref.updateOrginalText(offset, elm.innerHTML, edit_input.value, id); 
    482                 $(elm).attr('is_corrected', true).css('color', 'green').html(edit_input.value); 
     483                        $(elm).attr('is_corrected', true).css('color', 'green').html(edit_input.value); 
    483484                ref.hideErrorWindow(); 
    484485            } 
     
    486487        }; 
    487488 
    488         $(edit_input).width(120).css({'margin': 0, 'padding': 0}); 
    489         $(edit_input).val(elm.innerHTML).attr('googie_action_btn', '1'); 
    490         $(edit).css('cursor', 'default').attr('googie_action_btn', '1'); 
    491  
    492         $(ok_pic).attr('src', this.img_dir + 'ok.gif') 
    493             .width(32).height(16) 
    494             .css({'cursor': 'pointer', 'margin-left': '2px', 'margin-right': '2px'}) 
    495             .bind('click', onsub); 
     489            $(edit_input).width(120).css({'margin': 0, 'padding': 0}); 
     490            $(edit_input).val(elm.innerHTML).attr('googie_action_btn', '1'); 
     491            $(edit).css('cursor', 'default').attr('googie_action_btn', '1'); 
     492 
     493            $(ok_pic).attr('src', this.img_dir + 'ok.gif') 
     494                .width(32).height(16) 
     495            .css({'cursor': 'pointer', 'margin-left': '2px', 'margin-right': '2px'}) 
     496                .bind('click', onsub); 
    496497 
    497498        $(edit_form).attr('googie_action_btn', '1') 
    498             .css({'margin': 0, 'padding': 0, 'cursor': 'default', 'white-space': 'nowrap'}) 
    499             .bind('submit', onsub); 
    500          
    501         edit_form.appendChild(edit_input); 
    502         edit_form.appendChild(ok_pic); 
     499                .css({'margin': 0, 'padding': 0, 'cursor': 'default', 'white-space': 'nowrap'}) 
     500                .bind('submit', onsub); 
     501 
     502            edit_form.appendChild(edit_input); 
     503            edit_form.appendChild(ok_pic); 
    503504        edit.appendChild(edit_form); 
    504505        edit_row.appendChild(edit); 
    505506        list.appendChild(edit_row); 
    506507 
    507         //Append extra menu items 
     508        // Append extra menu items 
    508509        if (this.extra_menu_items.length > 0) 
    509             list.appendChild(this.createListSeparator()); 
    510          
     510                list.appendChild(this.createListSeparator()); 
     511 
    511512        var loop = function(i) { 
    512                 if (i < ref.extra_menu_items.length) { 
    513                     var e_elm = ref.extra_menu_items[i]; 
    514  
    515                     if (!e_elm[2] || e_elm[2](elm, ref)) { 
    516                         var e_row = document.createElement('tr'); 
    517                         var e_col = document.createElement('td'); 
    518  
    519                         $(e_col).html(e_elm[0]) 
    520                             .bind('mouseover', ref.item_onmouseover) 
    521                             .bind('mouseout', ref.item_onmouseout) 
    522                             .bind('click', function() { return e_elm[1](elm, ref) }); 
    523                          
    524                         e_row.appendChild(e_col); 
    525                         list.appendChild(e_row); 
    526                     } 
    527                     loop(i+1); 
     513            if (i < ref.extra_menu_items.length) { 
     514                var e_elm = ref.extra_menu_items[i]; 
     515 
     516                if (!e_elm[2] || e_elm[2](elm, ref)) { 
     517                    var e_row = document.createElement('tr'), 
     518                      e_col = document.createElement('td'); 
     519 
     520                                $(e_col).html(e_elm[0]) 
     521                        .bind('mouseover', ref.item_onmouseover) 
     522                        .bind('mouseout', ref.item_onmouseout) 
     523                                    .bind('click', function() { return e_elm[1](elm, ref) }); 
     524 
     525                                e_row.appendChild(e_col); 
     526                    list.appendChild(e_row); 
    528527                } 
    529         } 
    530          
     528                loop(i+1); 
     529            } 
     530        }; 
     531 
    531532        loop(0); 
    532533        loop = null; 
     
    541542    this.error_window.appendChild(table); 
    542543 
    543     //Dummy for IE - dropdown bug fix 
     544    // Dummy for IE - dropdown bug fix 
    544545    if ($.browser.msie) { 
    545         if (!this.error_window_iframe) { 
     546            if (!this.error_window_iframe) { 
    546547            var iframe = $('<iframe>').css({'position': 'absolute', 'z-index': -1}); 
    547             $('body').append(iframe); 
     548                $('body').append(iframe); 
    548549            this.error_window_iframe = iframe; 
    549550        } 
    550551 
    551         $(this.error_window_iframe).css({'visibility': 'visible', 
    552             'top': this.error_window.offsetTop, 'left': this.error_window.offsetLeft, 
     552            $(this.error_window_iframe).css({'visibility': 'visible', 
     553                'top': this.error_window.offsetTop, 'left': this.error_window.offsetLeft, 
    553554            'width': this.error_window.offsetWidth, 'height': this.error_window.offsetHeight}); 
    554555    } 
    555 } 
     556}; 
    556557 
    557558 
     
    583584        }); 
    584585    } 
    585 } 
     586}; 
    586587 
    587588this.resumeEditing = function() { 
     
    609610    } 
    610611    this.checkSpellingState(false); 
    611 } 
     612}; 
    612613 
    613614this.createErrorLink = function(text, id) { 
    614     var elm = document.createElement('span'); 
    615     var ref = this; 
    616     var d = function (e) { 
     615    var elm = document.createElement('span'), 
     616        ref = this, 
     617        d = function (e) { 
    617618            ref.showErrorWindow(elm, id); 
    618619            d = null; 
    619620            return false; 
    620     }; 
    621      
     621        }; 
     622 
    622623    $(elm).html(text).addClass('googie_link').bind('click', d) 
    623624        .attr({'googie_action_btn' : '1', 'g_id' : id, 'is_corrected' : false}); 
    624625 
    625626    return elm; 
    626 } 
     627}; 
    627628 
    628629this.createPart = function(txt_part) { 
     
    635636    txt_part = txt_part.replace(/^ /g, "&nbsp;"); 
    636637    txt_part = txt_part.replace(/ $/g, "&nbsp;"); 
    637      
     638 
    638639    var span = document.createElement('span'); 
    639640    $(span).html(txt_part); 
    640641    return span; 
    641 } 
     642}; 
    642643 
    643644this.showErrorsInIframe = function() { 
    644     var output = document.createElement('div') 
    645     var pointer = 0; 
    646     var results = this.results; 
     645    var output = document.createElement('div'), 
     646        pointer = 0, 
     647        results = this.results; 
    647648 
    648649    if (results.length > 0) { 
    649         for (var i=0; i < results.length; i++) { 
    650             var offset = results[i]['attrs']['o']; 
    651             var len = results[i]['attrs']['l']; 
    652             var part_1_text = this.orginal_text.substring(pointer, offset); 
    653             var part_1 = this.createPart(part_1_text); 
    654      
     650        for (var i=0, length=results.length; i < length; i++) { 
     651            var offset = results[i]['attrs']['o'], 
     652                len = results[i]['attrs']['l'], 
     653                part_1_text = this.orginal_text.substring(pointer, offset), 
     654                part_1 = this.createPart(part_1_text); 
     655 
    655656            output.appendChild(part_1); 
    656657            pointer += offset - pointer; 
    657              
    658             //If the last child was an error, then insert some space 
     658 
     659            // If the last child was an error, then insert some space 
    659660            var err_link = this.createErrorLink(this.orginal_text.substr(offset, len), i); 
    660661            this.error_links.push(err_link); 
     
    662663            pointer += len; 
    663664        } 
    664         //Insert the rest of the orginal text 
    665         var part_2_text = this.orginal_text.substr(pointer, this.orginal_text.length); 
    666         var part_2 = this.createPart(part_2_text); 
     665 
     666        // Insert the rest of the orginal text 
     667        var part_2_text = this.orginal_text.substr(pointer, this.orginal_text.length), 
     668            part_2 = this.createPart(part_2_text); 
    667669 
    668670        output.appendChild(part_2); 
     
    676678    if (this.custom_item_evaulator) 
    677679        $.map(this.error_links, function(elm){me.custom_item_evaulator(me, elm)}); 
    678      
     680 
    679681    $(this.edit_layer).append(output); 
    680682 
    681     //Hide text area and show edit layer 
     683    // Hide text area and show edit layer 
    682684    $(this.text_area).hide(); 
    683685    $(this.edit_layer).insertBefore(this.text_area); 
     
    692694 
    693695//    this.edit_layer.scrollTop = this.ta_scroll_top; 
    694 } 
     696}; 
    695697 
    696698 
     
    703705        .width(100).attr('googie_action_btn', '1'); 
    704706 
    705     //Build up the result list 
    706     var table = document.createElement('table'); 
    707     var list = document.createElement('tbody'); 
    708     var ref = this; 
     707    // Build up the result list 
     708    var table = document.createElement('table'), 
     709        list = document.createElement('tbody'), 
     710        ref = this, 
     711        row, item, span; 
    709712 
    710713    $(table).addClass('googie_list').width('100%'); 
    711     this.lang_elms = new Array(); 
     714    this.lang_elms = []; 
    712715 
    713716    for (i=0; i < this.langlist_codes.length; i++) { 
    714         var row = document.createElement('tr'); 
    715         var item = document.createElement('td'); 
    716         var span = document.createElement('span'); 
    717          
    718         $(span).text(this.lang_to_word[this.langlist_codes[i]]); 
     717        row = document.createElement('tr'); 
     718        item = document.createElement('td'); 
     719        span = document.createElement('span'); 
     720 
     721            $(span).text(this.lang_to_word[this.langlist_codes[i]]); 
    719722        this.lang_elms.push(item); 
    720723 
    721724        $(item).attr('googieId', this.langlist_codes[i]) 
    722725            .bind('click', function(e) { 
    723                 ref.deHighlightCurSel(); 
    724                 ref.setCurrentLanguage($(this).attr('googieId')); 
    725  
    726                 if (ref.lang_state_observer != null) { 
     726                    ref.deHighlightCurSel(); 
     727                    ref.setCurrentLanguage($(this).attr('googieId')); 
     728 
     729                    if (ref.lang_state_observer != null) { 
    727730                    ref.lang_state_observer(); 
    728                 } 
    729  
    730                 ref.highlightCurSel(); 
    731                 ref.hideLangWindow(); 
     731                    } 
     732 
     733                    ref.highlightCurSel(); 
     734                    ref.hideLangWindow(); 
    732735            }) 
    733             .bind('mouseover', function(e) {  
    734                 if (this.className != "googie_list_selected") 
     736            .bind('mouseover', function(e) { 
     737                    if (this.className != "googie_list_selected") 
    735738                    this.className = "googie_list_onhover"; 
    736739            }) 
    737             .bind('mouseout', function(e) {  
    738                 if (this.className != "googie_list_selected") 
    739                     this.className = "googie_list_onout";  
     740            .bind('mouseout', function(e) { 
     741                    if (this.className != "googie_list_selected") 
     742                    this.className = "googie_list_onout"; 
    740743            }); 
    741744 
    742         item.appendChild(span); 
     745            item.appendChild(span); 
    743746        row.appendChild(item); 
    744747        list.appendChild(row); 
    745748    } 
    746749 
    747     //Close button 
     750    // Close button 
    748751    if (this.use_close_btn) { 
    749752        list.appendChild(this.createCloseButton(function () { ref.hideLangWindow.apply(ref) })); 
     
    754757    table.appendChild(list); 
    755758    this.language_window.appendChild(table); 
    756 } 
     759}; 
    757760 
    758761this.isLangWindowShown = function() { 
    759762    return $(this.language_window).is(':hidden'); 
    760 } 
     763}; 
    761764 
    762765this.hideLangWindow = function() { 
    763766    $(this.language_window).css('visibility', 'hidden'); 
    764767    $(this.switch_lan_pic).removeClass().addClass('googie_lang_3d_on'); 
    765 } 
     768}; 
    766769 
    767770this.deHighlightCurSel = function() { 
    768771    $(this.lang_cur_elm).removeClass().addClass('googie_list_onout'); 
    769 } 
     772}; 
    770773 
    771774this.highlightCurSel = function() { 
     
    781784        } 
    782785    } 
    783 } 
     786}; 
    784787 
    785788this.showLangWindow = function(elm) { 
     
    790793    $('body').append(this.language_window); 
    791794 
    792     var pos = $(elm).offset(); 
    793     var top = pos.top + $(elm).height(); 
    794     var left = this.change_lang_pic_placement == 'right' ?  
    795         pos.left - 100 + $(elm).width() : pos.left + $(elm).width(); 
     795    var pos = $(elm).offset(), 
     796        top = pos.top + $(elm).height(), 
     797        left = this.change_lang_pic_placement == 'right' ? 
     798                pos.left - 100 + $(elm).width() : pos.left + $(elm).width(); 
    796799 
    797800    $(this.language_window).css({'visibility': 'visible', 'top' : top+'px','left' : left+'px'}); 
    798801 
    799802    this.highlightCurSel(); 
    800 } 
     803}; 
    801804 
    802805this.createChangeLangPic = function() { 
    803806    var img = $('<img>') 
    804         .attr({src: this.img_dir + 'change_lang.gif', 'alt': 'Change language', 'googie_action_btn': '1'}); 
    805  
    806     var switch_lan = document.createElement('span'); 
    807     var ref = this; 
     807            .attr({src: this.img_dir + 'change_lang.gif', 'alt': 'Change language', 'googie_action_btn': '1'}), 
     808        switch_lan = document.createElement('span'); 
     809        ref = this; 
    808810 
    809811    $(switch_lan).addClass('googie_lang_3d_on') 
    810         .append(img) 
    811         .bind('click', function(e) { 
     812            .append(img) 
     813            .bind('click', function(e) { 
    812814            var elm = this.tagName.toLowerCase() == 'img' ? this.parentNode : this; 
    813815            if($(elm).hasClass('googie_lang_3d_click')) { 
    814                 elm.className = 'googie_lang_3d_on'; 
    815                 ref.hideLangWindow(); 
     816                elm.className = 'googie_lang_3d_on'; 
     817                    ref.hideLangWindow(); 
    816818            } 
    817819            else { 
    818                 elm.className = 'googie_lang_3d_click'; 
    819                 ref.showLangWindow(elm); 
     820                    elm.className = 'googie_lang_3d_click'; 
     821                    ref.showLangWindow(elm); 
    820822            } 
    821         }); 
     823            }); 
    822824 
    823825    return switch_lan; 
    824 } 
     826}; 
    825827 
    826828this.createSpellDiv = function() { 
     
    830832 
    831833    if (this.show_spell_img) { 
    832         $(span).append(' ').append($('<img>').attr('src', this.img_dir + 'spellc.gif')); 
     834            $(span).append(' ').append($('<img>').attr('src', this.img_dir + 'spellc.gif')); 
    833835    } 
    834836    return span; 
    835 } 
     837}; 
    836838 
    837839 
     
    844846    var ref = this; 
    845847    if (this.main_controller) { 
    846         var no_spell_errors; 
    847         if (on_finish) { 
     848            var no_spell_errors; 
     849            if (on_finish) { 
    848850            var fn = function() { 
    849                 on_finish(); 
    850                 ref.checkSpellingState(); 
     851                on_finish(); 
     852                    ref.checkSpellingState(); 
    851853            }; 
    852854            no_spell_errors = fn; 
    853         } 
    854         else 
     855            } 
     856            else 
    855857            no_spell_errors = function () { ref.checkSpellingState() }; 
    856858 
     
    863865        window.setTimeout(no_spell_errors, 1000); 
    864866    } 
    865 } 
     867}; 
    866868 
    867869this.resumeEditingState = function() { 
     
    881883    try { this.edit_layer.scrollTop = this.ta_scroll_top; } 
    882884    catch (e) {}; 
    883 } 
     885}; 
    884886 
    885887this.checkSpellingState = function(fire) { 
     
    892894        this.switch_lan_pic = document.createElement('span'); 
    893895 
    894     var span_chck = this.createSpellDiv(); 
    895     var ref = this; 
     896    var span_chck = this.createSpellDiv(), 
     897        ref = this; 
    896898 
    897899    if (this.custom_spellcheck_starter) 
     
    903905    if (this.main_controller) { 
    904906        if (this.change_lang_pic_placement == 'left') { 
    905             $(this.spell_container).empty().append(this.switch_lan_pic).append(' ').append(span_chck); 
     907                $(this.spell_container).empty().append(this.switch_lan_pic).append(' ').append(span_chck); 
    906908        } else { 
    907             $(this.spell_container).empty().append(span_chck).append(' ').append(this.switch_lan_pic); 
    908         } 
     909                $(this.spell_container).empty().append(span_chck).append(' ').append(this.switch_lan_pic); 
     910            } 
    909911    } 
    910912 
    911913    this.spell_span = span_chck; 
    912 } 
     914}; 
    913915 
    914916 
     
    918920this.isDefined = function(o) { 
    919921    return (o != 'undefined' && o != null) 
    920 } 
     922}; 
    921923 
    922924this.errorFixed = function() {  
     
    927929            this.all_errors_fixed_observer(); 
    928930        } 
    929 } 
     931}; 
    930932 
    931933this.errorFound = function() { 
    932934    this.cnt_errors++; 
    933 } 
     935}; 
    934936 
    935937this.createCloseButton = function(c_fn) { 
    936938    return this.createButton(this.lang_close, 'googie_list_close', c_fn); 
    937 } 
     939}; 
    938940 
    939941this.createButton = function(name, css_class, c_fn) { 
    940     var btn_row = document.createElement('tr'); 
    941     var btn = document.createElement('td'); 
    942     var spn_btn; 
     942    var btn_row = document.createElement('tr'), 
     943        btn = document.createElement('td'), 
     944        spn_btn; 
    943945 
    944946    if (css_class) { 
    945947        spn_btn = document.createElement('span'); 
    946         $(spn_btn).addClass(css_class).html(name); 
     948            $(spn_btn).addClass(css_class).html(name); 
    947949    } else { 
    948950        spn_btn = document.createTextNode(name); 
     
    950952 
    951953    $(btn).bind('click', c_fn) 
    952         .bind('mouseover', this.item_onmouseover) 
    953         .bind('mouseout', this.item_onmouseout); 
     954            .bind('mouseover', this.item_onmouseover) 
     955            .bind('mouseout', this.item_onmouseout); 
    954956 
    955957    btn.appendChild(spn_btn); 
     
    957959 
    958960    return btn_row; 
    959 } 
     961}; 
    960962 
    961963this.removeIndicator = function(elm) { 
     
    964966    if (window.rcmail) 
    965967        rcmail.set_busy(false); 
    966 } 
     968}; 
    967969 
    968970this.appendIndicator = function(elm) { 
    969971    // modified by roundcube 
    970972    if (window.rcmail) 
    971         rcmail.set_busy(true, 'checking'); 
    972 /*     
     973            rcmail.set_busy(true, 'checking'); 
     974/* 
    973975    this.indicator = document.createElement('img'); 
    974976    $(this.indicator).attr('src', this.img_dir + 'indicator.gif') 
    975         .css({'margin-right': '5px', 'text-decoration': 'none'}).width(16).height(16); 
    976      
     977            .css({'margin-right': '5px', 'text-decoration': 'none'}).width(16).height(16); 
     978 
    977979    if (elm) 
    978         $(this.indicator).insertBefore(elm); 
     980            $(this.indicator).insertBefore(elm); 
    979981    else 
    980         $('body').append(this.indicator); 
    981 */                                   
     982        $('body').append(this.indicator); 
     983*/ 
    982984} 
    983985 
     
    986988    $(link).attr({'href': 'javascript:;', 'name': name}); 
    987989    return link; 
    988 } 
     990}; 
    989991 
    990992this.item_onmouseover = function(e) { 
    991     if (this.className != "googie_list_revert" && this.className != "googie_list_close") 
    992         this.className = "googie_list_onhover"; 
     993    if (this.className != 'googie_list_revert' && this.className != 'googie_list_close') 
     994        this.className = 'googie_list_onhover'; 
    993995    else 
    994         this.parentNode.className = "googie_list_onhover"; 
    995 } 
     996        this.parentNode.className = 'googie_list_onhover'; 
     997}; 
    996998this.item_onmouseout = function(e) { 
    997     if (this.className != "googie_list_revert" && this.className != "googie_list_close") 
    998         this.className = "googie_list_onout"; 
     999    if (this.className != 'googie_list_revert' && this.className != 'googie_list_close') 
     1000        this.className = 'googie_list_onout'; 
    9991001    else 
    1000         this.parentNode.className = "googie_list_onout"; 
    1001 } 
    1002  
    1003  
    1004 }; 
     1002        this.parentNode.className = 'googie_list_onout'; 
     1003}; 
     1004 
     1005 
     1006}; 
Note: See TracChangeset for help on using the changeset viewer.