@ -84,8 +84,6 @@ function GoogieSpell(img_dir, server_url, has_dict)
// Extensions
this . custom _ajax _error = null ;
this . custom _no _spelling _error = null ;
this . custom _menu _builder = [ ] ; // Should take an eval function and a build menu function
this . custom _item _evaulator = null ; // Should take an eval function and a build menu function
this . extra _menu _items = [ ] ;
this . custom _spellcheck _starter = null ;
this . main _controller = true ;
@ -109,8 +107,6 @@ function GoogieSpell(img_dir, server_url, has_dict)
// Set document's onclick to hide the language and error menu
$ ( document ) . click ( function ( e ) {
var target = $ ( e . target ) ;
if ( target . attr ( 'googie_action_btn' ) != '1' && ref . isLangWindowShown ( ) )
ref . hideLangWindow ( ) ;
if ( target . attr ( 'googie_action_btn' ) != '1' && ref . isErrorWindowShown ( ) )
ref . hideErrorWindow ( ) ;
} ) ;
@ -190,11 +186,6 @@ this.appendNewMenuItem = function(name, call_back_fn, checker)
this . extra _menu _items . push ( [ name , call _back _fn , checker ] ) ;
} ;
this . appendCustomMenuBuilder = function ( eval _fn , builder )
{
this . custom _menu _builder . push ( [ eval _fn , builder ] ) ;
} ;
this . setFocus = function ( )
{
try {
@ -316,7 +307,6 @@ this.prepare = function(ignore, no_indicator)
this . error _links = [ ] ;
this . ta _scroll _top = this . text _area . scrollTop ;
this . ignore = ignore ;
this . hideLangWindow ( ) ;
var area = $ ( this . text _area ) ;
@ -432,14 +422,9 @@ this.saveOldValue = function(elm, old_value) {
this . createListSeparator = function ( )
{
var td = document . createElement ( 'td' ) ,
tr = document . createElement ( 'tr' ) ;
$ ( td ) . html ( ' ' ) . attr ( 'googie_action_btn' , '1' )
. css ( { 'cursor' : 'default' , 'font-size' : '3px' , 'border-top' : '1px solid #ccc' , 'padding-top' : '3px' } ) ;
tr . appendChild ( td ) ;
return tr ;
return $ ( '<li>' ) . html ( ' ' ) . attr ( 'googie_action_btn' , '1' )
. css ( { 'cursor' : 'default' , 'font-size' : '3px' , 'border-top' : '1px solid #ccc' , 'padding-top' : '3px' } )
. get ( 0 ) ;
} ;
this . correctError = function ( id , elm , l _elm , rm _pre _space )
@ -482,180 +467,145 @@ this.showErrorWindow = function(elm, id)
var ref = this ,
pos = $ ( elm ) . offset ( ) ,
table = document . createElement ( 'table' ) ,
list = document . createElement ( 'tbody' ) ;
list = document . createElement ( 'ul' ) ;
$ ( this . error _window ) . html ( '' ) ;
$ ( table ) . addClass ( 'googie_list' ) . attr ( 'googie_action_btn' , '1' ) ;
// Check if we should use custom menu builder, if not we use the default
var changed = false ;
for ( var k = 0 ; k < this . custom _menu _builder . length ; k ++ ) {
var eb = this . custom _menu _builder [ k ] ;
if ( eb [ 0 ] ( this . results [ id ] ) ) {
changed = eb [ 1 ] ( this , list , elm ) ;
break ;
}
$ ( list ) . addClass ( 'googie_list' ) . attr ( 'googie_action_btn' , '1' ) ;
// Build up the result list
var suggestions = this . results [ id ] [ 'suggestions' ] ,
offset = this . results [ id ] [ 'attrs' ] [ 'o' ] ,
len = this . results [ id ] [ 'attrs' ] [ 'l' ] ,
row , item , dummy ;
// [Add to dictionary] button
if ( this . has _dictionary && ! $ ( elm ) . attr ( 'is_corrected' ) ) {
row = document . createElement ( 'li' ) ,
dummy = document . createElement ( 'span' ) ;
$ ( dummy ) . text ( this . lang _learn _word ) . addClass ( 'googie_add_to_dict' ) ;
$ ( row ) . attr ( 'googie_action_btn' , '1' ) . css ( 'cursor' , 'default' )
. mouseover ( ref . item _onmouseover )
. mouseout ( ref . item _onmouseout )
. click ( function ( e ) {
ref . learnWord ( elm , id ) ;
ref . ignoreError ( elm , id ) ;
} ) ;
row . appendChild ( dummy ) ;
list . appendChild ( row ) ;
}
if ( ! changed ) {
// Build up the result list
var suggestions = this . results [ id ] [ 'suggestions' ] ,
offset = this . results [ id ] [ 'attrs' ] [ 'o' ] ,
len = this . results [ id ] [ 'attrs' ] [ 'l' ] ,
row , item , dummy ;
// [Add to dictionary] button
if ( this . has _dictionary && ! $ ( elm ) . attr ( 'is_corrected' ) ) {
row = document . createElement ( 'tr' ) ,
item = document . createElement ( 'td' ) ,
dummy = document . createElement ( 'span' ) ;
$ ( dummy ) . text ( this . lang _learn _word ) . addClass ( 'googie_add_to_dict' ) ;
$ ( item ) . attr ( 'googie_action_btn' , '1' ) . css ( 'cursor' , 'default' )
. mouseover ( ref . item _onmouseover )
. mouseout ( ref . item _onmouseout )
. click ( function ( e ) {
ref . learnWord ( elm , id ) ;
ref . ignoreError ( elm , id ) ;
} ) ;
item . appendChild ( dummy ) ;
row . appendChild ( item ) ;
list . appendChild ( row ) ;
}
/ *
if ( suggestions . length == 0 ) {
row = document . createElement ( 'tr' ) ,
item = document . createElement ( 'td' ) ,
dummy = document . createElement ( 'span' ) ;
for ( var i = 0 , len = suggestions . length ; i < len ; i ++ ) {
row = document . createElement ( 'li' ) ,
dummy = document . createElement ( 'span' ) ;
$ ( dummy ) . text ( this . lang _no _suggestions ) ;
$ ( item ) . attr ( 'googie_action_btn' , '1' ) . css ( 'cursor' , 'default' ) ;
$ ( dummy ) . html ( suggestions [ i ] ) ;
item . appendChild ( dummy ) ;
row . appendChild ( item ) ;
list . appendChild ( row ) ;
}
* /
for ( var i = 0 , len = suggestions . length ; i < len ; i ++ ) {
row = document . createElement ( 'tr' ) ,
item = document . createElement ( 'td' ) ,
dummy = document . createElement ( 'span' ) ;
$ ( row ) . mouseover ( this . item _onmouseover ) . mouseout ( this . item _onmouseout )
. click ( function ( e ) { ref . correctError ( id , elm , e . target . firstChild ) ; } ) ;
$ ( dummy ) . html ( suggestions [ i ] ) ;
row . appendChild ( dummy ) ;
list . appendChild ( row ) ;
}
$ ( item ) . mouseover ( this . item _onmouseover ) . mouseout ( this . item _onmouseout )
. click ( function ( e ) { ref . correctError ( id , elm , e . target . firstChild ) } ) ;
// The element is changed, append the revert
if ( elm . is _changed && elm . innerHTML != elm . old _value ) {
var old _value = elm . old _value ,
revert _row = document . createElement ( 'li' ) ,
rev _span = document . createElement ( 'span' ) ;
item . appendChild ( dummy ) ;
row . appendChild ( item ) ;
list . appendChild ( row ) ;
}
$ ( rev _span ) . addClass ( 'googie_list_revert' ) . html ( this . lang _revert + ' ' + old _value ) ;
// The element is changed, append the revert
if ( elm . is _changed && elm . innerHTML != elm . old _value ) {
var old _value = elm . old _value ,
revert _row = document . createElement ( 'tr' ) ,
revert = document . createElement ( 'td' ) ,
rev _span = document . createElement ( 'span' ) ;
$ ( rev _span ) . addClass ( 'googie_list_revert' ) . html ( this . lang _revert + ' ' + old _value ) ;
$ ( revert ) . mouseover ( this . item _onmouseover ) . mouseout ( this . item _onmouseout )
. click ( function ( e ) {
ref . updateOrginalText ( offset , elm . innerHTML , old _value , id ) ;
$ ( elm ) . removeAttr ( 'is_corrected' ) . css ( 'color' , '#b91414' ) . html ( old _value ) ;
ref . hideErrorWindow ( ) ;
} ) ;
revert . appendChild ( rev _span ) ;
revert _row . appendChild ( revert ) ;
list . appendChild ( revert _row ) ;
}
$ ( revert _row ) . mouseover ( this . item _onmouseover ) . mouseout ( this . item _onmouseout )
. click ( function ( e ) {
ref . updateOrginalText ( offset , elm . innerHTML , old _value , id ) ;
$ ( elm ) . removeAttr ( 'is_corrected' ) . css ( 'color' , '#b91414' ) . html ( old _value ) ;
ref . hideErrorWindow ( ) ;
} ) ;
// Append the edit box
var edit _row = document . createElement ( 'tr' ) ,
edit = document . createElement ( 'td' ) ,
edit _input = document . createElement ( 'input' ) ,
ok _pic = document . createElement ( 'button' ) , // roundcube mod.
edit _form = document . createElement ( 'form' ) ;
revert _row . appendChild ( rev _span ) ;
list . appendChild ( revert _row ) ;
}
var onsub = function ( ) {
if ( edit _input . value != '' ) {
if ( ! ref . isDefined ( elm . old _value ) )
ref . saveOldValue ( elm , elm . innerHTML ) ;
// Append the edit box
var edit _row = document . createElement ( 'li' ) ,
edit _input = document . createElement ( 'input' ) ,
ok _pic = document . createElement ( 'button' ) ,
edit _form = document . createElement ( 'form' ) ;
ref . updateOrginalText ( offset , elm . innerHTML , edit _input . value , id ) ;
$ ( elm ) . attr ( 'is_corrected' , true ) . css ( 'color' , 'green' ) . text ( edit _input . value ) ;
ref . hideErrorWindow ( ) ;
}
return false ;
} ;
var onsub = function ( ) {
if ( edit _input . value != '' ) {
if ( ! ref . isDefined ( elm . old _value ) )
ref . saveOldValue ( elm , elm . innerHTML ) ;
$ ( edit _input ) . width ( 120 )
. css ( { 'margin' : 0 , 'padding' : 0 } )
. val ( $ ( elm ) . text ( ) ) . attr ( 'googie_action_btn' , '1' ) ;
$ ( edit ) . css ( 'cursor' , 'default' ) . attr ( 'googie_action_btn' , '1' ) ;
// roundcube modified image use
if ( this . use _ok _pic ) {
$ ( '<img>' ) . attr ( 'src' , this . img _dir + 'ok.gif' )
. width ( 32 ) . height ( 16 )
. css ( { cursor : 'pointer' , 'margin-left' : '2px' , 'margin-right' : '2px' } )
. appendTo ( ok _pic ) ;
}
else {
$ ( ok _pic ) . text ( 'OK' ) ;
ref . updateOrginalText ( offset , elm . innerHTML , edit _input . value , id ) ;
$ ( elm ) . attr ( 'is_corrected' , true ) . css ( 'color' , 'green' ) . text ( edit _input . value ) ;
ref . hideErrorWindow ( ) ;
}
return false ;
} ;
$ ( ok _pic ) . addClass ( 'mainaction save googie_ok_button' ) . click ( onsub ) ;
$ ( edit _input ) . width ( 120 )
. css ( { 'margin' : 0 , 'padding' : 0 } )
. val ( $ ( elm ) . text ( ) ) . attr ( 'googie_action_btn' , '1' ) ;
$ ( edit _row ) . css ( 'cursor' , 'default' ) . attr ( 'googie_action_btn' , '1' ) ;
// roundcube modified image use
if ( this . use _ok _pic ) {
$ ( '<img>' ) . attr ( 'src' , this . img _dir + 'ok.gif' )
. width ( 32 ) . height ( 16 )
. css ( { cursor : 'pointer' , 'margin-left' : '2px' , 'margin-right' : '2px' } )
. appendTo ( ok _pic ) ;
}
else {
$ ( ok _pic ) . text ( 'OK' ) ;
}
$ ( ok _pic ) . addClass ( 'mainaction save googie_ok_button' ) . click ( onsub ) ;
$ ( edit _form ) . attr ( 'googie_action_btn' , '1' )
. css ( { 'margin' : 0 , 'padding' : 0 , 'cursor' : 'default' , 'white-space' : 'nowrap' } )
. submit ( onsub ) ;
$ ( edit _form ) . attr ( 'googie_action_btn' , '1' )
. css ( { 'margin' : 0 , 'padding' : 0 , 'cursor' : 'default' , 'white-space' : 'nowrap' } )
. submit ( onsub ) ;
edit _form . appendChild ( edit _input ) ;
edit _form . appendChild ( ok _pic ) ;
edit . appendChild ( edit _form ) ;
edit _row . appendChild ( edit ) ;
list . appendChild ( edit _row ) ;
edit _form . appendChild ( edit _input ) ;
edit _form . appendChild ( ok _pic ) ;
edit _row . appendChild ( edit _form ) ;
list . appendChild ( edit _row ) ;
// Append extra menu items
if ( this . extra _menu _items . length > 0 )
list . appendChild ( this . createListSeparator ( ) ) ;
// Append extra menu items
if ( this . extra _menu _items . length > 0 )
list . appendChild ( this . createListSeparator ( ) ) ;
var loop = function ( i ) {
if ( i < ref . extra _menu _items . length ) {
var e _elm = ref . extra _menu _items [ i ] ;
var loop = function ( i ) {
if ( i < ref . extra _menu _items . length ) {
var e _elm = ref . extra _menu _items [ i ] ;
if ( ! e _elm [ 2 ] || e _elm [ 2 ] ( elm , ref ) ) {
var e _row = document . createElement ( 'tr' ) ,
e _col = document . createElement ( 'td' ) ;
if ( ! e _elm [ 2 ] || e _elm [ 2 ] ( elm , ref ) ) {
var e _row = document . createElement ( 'tr' ) ,
e _col = document . createElement ( 'td' ) ;
$ ( e _col ) . html ( e _elm [ 0 ] )
. mouseover ( ref . item _onmouseover )
. mouseout ( ref . item _onmouseout )
. click ( function ( ) { return e _elm [ 1 ] ( elm , ref ) } ) ;
$ ( e _col ) . html ( e _elm [ 0 ] )
. mouseover ( ref . item _onmouseover )
. mouseout ( ref . item _onmouseout )
. click ( function ( ) { return e _elm [ 1 ] ( elm , ref ) } ) ;
e _row . appendChild ( e _col ) ;
list . appendChild ( e _row ) ;
}
loop ( i + 1 ) ;
e _row . appendChild ( e _col ) ;
list . appendChild ( e _row ) ;
}
} ;
loop ( i + 1 ) ;
}
} ;
loop ( 0 ) ;
loop = null ;
loop ( 0 ) ;
loop = null ;
//Close button
if ( this . use _close _btn ) {
list . appendChild ( this . createCloseButton ( this . hideErrorWindow ) ) ;
}
//Close button
if ( this . use _close _btn ) {
list . appendChild ( this . createCloseButton ( this . hideErrorWindow ) ) ;
}
table . appendChild ( list ) ;
this . error _window . appendChild ( table ) ;
this . error _window . appendChild ( list ) ;
// roundcube plugin api hook
rcmail . triggerEvent ( 'googiespell_create' , { obj : this . error _window } ) ;
@ -835,103 +785,6 @@ this.showErrorsInIframe = function()
// this.edit_layer.scrollTop = this.ta_scroll_top;
} ;
//////
// Choose language menu
//////
this . createLangWindow = function ( )
{
this . language _window = document . createElement ( 'div' ) ;
$ ( this . language _window ) . addClass ( 'googie_window popupmenu' )
. width ( 100 ) . attr ( 'googie_action_btn' , '1' ) ;
// Build up the result list
var table = document . createElement ( 'table' ) ,
list = document . createElement ( 'tbody' ) ,
ref = this ,
row , item , span ;
$ ( table ) . addClass ( 'googie_list' ) . width ( '100%' ) ;
this . lang _elms = [ ] ;
for ( i = 0 ; i < this . langlist _codes . length ; i ++ ) {
row = document . createElement ( 'tr' ) ;
item = document . createElement ( 'td' ) ;
span = document . createElement ( 'span' ) ;
$ ( span ) . text ( this . lang _to _word [ this . langlist _codes [ i ] ] ) ;
this . lang _elms . push ( item ) ;
$ ( item ) . attr ( 'googieId' , this . langlist _codes [ i ] )
. click ( function ( e ) {
ref . deHighlightCurSel ( ) ;
ref . setCurrentLanguage ( $ ( this ) . attr ( 'googieId' ) ) ;
if ( ref . lang _state _observer != null ) {
ref . lang _state _observer ( ) ;
}
ref . highlightCurSel ( ) ;
ref . hideLangWindow ( ) ;
} )
. mouseover ( function ( e ) {
if ( this . className != "googie_list_selected" )
this . className = "googie_list_onhover" ;
} )
. mouseout ( function ( e ) {
if ( this . className != "googie_list_selected" )
this . className = "googie_list_onout" ;
} ) ;
item . appendChild ( span ) ;
row . appendChild ( item ) ;
list . appendChild ( row ) ;
}
// Close button
if ( this . use _close _btn ) {
list . appendChild ( this . createCloseButton ( function ( ) { ref . hideLangWindow . apply ( ref ) } ) ) ;
}
this . highlightCurSel ( ) ;
table . appendChild ( list ) ;
this . language _window . appendChild ( table ) ;
} ;
this . isLangWindowShown = function ( )
{
return $ ( this . language _window ) . is ( ':visible' ) ;
} ;
this . hideLangWindow = function ( )
{
$ ( this . language _window ) . hide ( ) ;
$ ( this . switch _lan _pic ) . removeClass ( ) . addClass ( 'googie_lang_3d_on' ) ;
} ;
this . showLangWindow = function ( elm )
{
if ( this . show _menu _observer )
this . show _menu _observer ( this ) ;
this . createLangWindow ( ) ;
$ ( 'body' ) . append ( this . language _window ) ;
var pos = $ ( elm ) . offset ( ) ,
height = $ ( elm ) . height ( ) ,
width = $ ( elm ) . width ( ) ,
h = $ ( this . language _window ) . height ( ) ,
pageheight = $ ( document ) . height ( ) ,
left = this . change _lang _pic _placement == 'right' ?
pos . left - 100 + width : pos . left + width ,
top = pos . top + h < pageheight ? pos . top + height : pos . top - h - 4 ;
$ ( this . language _window ) . css ( { 'top' : top + 'px' , 'left' : left + 'px' } ) . show ( ) ;
this . highlightCurSel ( ) ;
} ;
this . deHighlightCurSel = function ( )
{
$ ( this . lang _cur _elm ) . removeClass ( ) . addClass ( 'googie_list_onout' ) ;
@ -952,30 +805,6 @@ this.highlightCurSel = function()
}
} ;
this . createChangeLangPic = function ( )
{
var img = $ ( '<img>' )
. attr ( { src : this . img _dir + 'change_lang.gif' , 'alt' : 'Change language' , 'googie_action_btn' : '1' } ) ,
switch _lan = document . createElement ( 'span' ) ;
ref = this ;
$ ( switch _lan ) . addClass ( 'googie_lang_3d_on' )
. append ( img )
. click ( function ( e ) {
var elm = this . tagName . toLowerCase ( ) == 'img' ? this . parentNode : this ;
if ( $ ( elm ) . hasClass ( 'googie_lang_3d_click' ) ) {
elm . className = 'googie_lang_3d_on' ;
ref . hideLangWindow ( ) ;
}
else {
elm . className = 'googie_lang_3d_click' ;
ref . showLangWindow ( elm ) ;
}
} ) ;
return switch _lan ;
} ;
this . createSpellDiv = function ( )
{
var span = document . createElement ( 'span' ) ;
@ -1043,10 +872,7 @@ this.checkSpellingState = function(fire)
if ( fire )
this . setStateChanged ( 'ready' ) ;
if ( this . show _change _lang _pic )
this . switch _lan _pic = this . createChangeLangPic ( ) ;
else
this . switch _lan _pic = document . createElement ( 'span' ) ;
this . switch _lan _pic = document . createElement ( 'span' ) ;
var span _chck = this . createSpellDiv ( ) ,
ref = this ;