@ -84,8 +84,6 @@ function GoogieSpell(img_dir, server_url, has_dict)
// Extensions
// Extensions
this . custom _ajax _error = null ;
this . custom _ajax _error = null ;
this . custom _no _spelling _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 . extra _menu _items = [ ] ;
this . custom _spellcheck _starter = null ;
this . custom _spellcheck _starter = null ;
this . main _controller = true ;
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
// Set document's onclick to hide the language and error menu
$ ( document ) . click ( function ( e ) {
$ ( document ) . click ( function ( e ) {
var target = $ ( e . target ) ;
var target = $ ( e . target ) ;
if ( target . attr ( 'googie_action_btn' ) != '1' && ref . isLangWindowShown ( ) )
ref . hideLangWindow ( ) ;
if ( target . attr ( 'googie_action_btn' ) != '1' && ref . isErrorWindowShown ( ) )
if ( target . attr ( 'googie_action_btn' ) != '1' && ref . isErrorWindowShown ( ) )
ref . hideErrorWindow ( ) ;
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 . 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 ( )
this . setFocus = function ( )
{
{
try {
try {
@ -316,7 +307,6 @@ this.prepare = function(ignore, no_indicator)
this . error _links = [ ] ;
this . error _links = [ ] ;
this . ta _scroll _top = this . text _area . scrollTop ;
this . ta _scroll _top = this . text _area . scrollTop ;
this . ignore = ignore ;
this . ignore = ignore ;
this . hideLangWindow ( ) ;
var area = $ ( this . text _area ) ;
var area = $ ( this . text _area ) ;
@ -432,14 +422,9 @@ this.saveOldValue = function(elm, old_value) {
this . createListSeparator = function ( )
this . createListSeparator = function ( )
{
{
var td = document . createElement ( 'td' ) ,
return $ ( '<li>' ) . html ( ' ' ) . attr ( 'googie_action_btn' , '1' )
tr = document . createElement ( 'tr' ) ;
. css ( { 'cursor' : 'default' , 'font-size' : '3px' , 'border-top' : '1px solid #ccc' , 'padding-top' : '3px' } )
. get ( 0 ) ;
$ ( 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 ;
} ;
} ;
this . correctError = function ( id , elm , l _elm , rm _pre _space )
this . correctError = function ( id , elm , l _elm , rm _pre _space )
@ -482,180 +467,145 @@ this.showErrorWindow = function(elm, id)
var ref = this ,
var ref = this ,
pos = $ ( elm ) . offset ( ) ,
pos = $ ( elm ) . offset ( ) ,
table = document . createElement ( 'table' ) ,
list = document . createElement ( 'ul' ) ;
list = document . createElement ( 'tbody' ) ;
$ ( this . error _window ) . html ( '' ) ;
$ ( this . error _window ) . html ( '' ) ;
$ ( table ) . addClass ( 'googie_list' ) . attr ( 'googie_action_btn' , '1' ) ;
$ ( list ) . addClass ( 'googie_list' ) . attr ( 'googie_action_btn' , '1' ) ;
// Check if we should use custom menu builder, if not we use the default
// Build up the result list
var changed = false ;
var suggestions = this . results [ id ] [ 'suggestions' ] ,
for ( var k = 0 ; k < this . custom _menu _builder . length ; k ++ ) {
offset = this . results [ id ] [ 'attrs' ] [ 'o' ] ,
var eb = this . custom _menu _builder [ k ] ;
len = this . results [ id ] [ 'attrs' ] [ 'l' ] ,
if ( eb [ 0 ] ( this . results [ id ] ) ) {
row , item , dummy ;
changed = eb [ 1 ] ( this , list , elm ) ;
break ;
// [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 ) {
for ( var i = 0 , len = suggestions . length ; i < len ; i ++ ) {
// Build up the result list
row = document . createElement ( 'li' ) ,
var suggestions = this . results [ id ] [ 'suggestions' ] ,
dummy = document . createElement ( 'span' ) ;
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' ) ;
$ ( dummy ) . text ( this . lang _no _suggestions ) ;
$ ( dummy ) . html ( suggestions [ i ] ) ;
$ ( item ) . attr ( 'googie_action_btn' , '1' ) . css ( 'cursor' , 'default' ) ;
item . appendChild ( dummy ) ;
$ ( row ) . mouseover ( this . item _onmouseover ) . mouseout ( this . item _onmouseout )
row . appendChild ( item ) ;
. click ( function ( e ) { ref . correctError ( id , elm , e . target . firstChild ) ; } ) ;
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' ) ;
$ ( dummy ) . html ( suggestions [ i ] ) ;
row . appendChild ( dummy ) ;
list . appendChild ( row ) ;
}
$ ( item ) . mouseover ( this . item _onmouseover ) . mouseout ( this . item _onmouseout )
// The element is changed, append the revert
. click ( function ( e ) { ref . correctError ( id , elm , e . target . firstChild ) } ) ;
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 ) ;
$ ( rev _span ) . addClass ( 'googie_list_revert' ) . html ( this . lang _revert + ' ' + old _value ) ;
row . appendChild ( item ) ;
list . appendChild ( row ) ;
}
// The element is changed, append the revert
$ ( revert _row ) . mouseover ( this . item _onmouseover ) . mouseout ( this . item _onmouseout )
if ( elm . is _changed && elm . innerHTML != elm . old _value ) {
. click ( function ( e ) {
var old _value = elm . old _value ,
ref . updateOrginalText ( offset , elm . innerHTML , old _value , id ) ;
revert _row = document . createElement ( 'tr' ) ,
$ ( elm ) . removeAttr ( 'is_corrected' ) . css ( 'color' , '#b91414' ) . html ( old _value ) ;
revert = document . createElement ( 'td' ) ,
ref . hideErrorWindow ( ) ;
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 ) ;
}
// Append the edit box
revert _row . appendChild ( rev _span ) ;
var edit _row = document . createElement ( 'tr' ) ,
list . appendChild ( revert _row ) ;
edit = document . createElement ( 'td' ) ,
}
edit _input = document . createElement ( 'input' ) ,
ok _pic = document . createElement ( 'button' ) , // roundcube mod.
edit _form = document . createElement ( 'form' ) ;
var onsub = function ( ) {
// Append the edit box
if ( edit _input . value != '' ) {
var edit _row = document . createElement ( 'li' ) ,
if ( ! ref . isDefined ( elm . old _value ) )
edit _input = document . createElement ( 'input' ) ,
ref . saveOldValue ( elm , elm . innerHTML ) ;
ok _pic = document . createElement ( 'button' ) ,
edit _form = document . createElement ( 'form' ) ;
ref . updateOrginalText ( offset , elm . innerHTML , edit _input . value , id ) ;
var onsub = function ( ) {
$ ( elm ) . attr ( 'is_corrected' , true ) . css ( 'color' , 'green' ) . text ( edit _input . value ) ;
if ( edit _input . value != '' ) {
ref . hideErrorWindow ( ) ;
if ( ! ref . isDefined ( elm . old _value ) )
}
ref . saveOldValue ( elm , elm . innerHTML ) ;
return false ;
} ;
$ ( edit _input ) . width ( 120 )
ref . updateOrginalText ( offset , elm . innerHTML , edit _input . value , id ) ;
. css ( { 'margin' : 0 , 'padding' : 0 } )
$ ( elm ) . attr ( 'is_corrected' , true ) . css ( 'color' , 'green' ) . text ( edit _input . value ) ;
. val ( $ ( elm ) . text ( ) ) . attr ( 'googie_action_btn' , '1' ) ;
ref . hideErrorWindow ( ) ;
$ ( 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' ) ;
}
}
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' )
$ ( edit _form ) . attr ( 'googie_action_btn' , '1' )
. css ( { 'margin' : 0 , 'padding' : 0 , 'cursor' : 'default' , 'white-space' : 'nowrap' } )
. css ( { 'margin' : 0 , 'padding' : 0 , 'cursor' : 'default' , 'white-space' : 'nowrap' } )
. submit ( onsub ) ;
. submit ( onsub ) ;
edit _form . appendChild ( edit _input ) ;
edit _form . appendChild ( edit _input ) ;
edit _form . appendChild ( ok _pic ) ;
edit _form . appendChild ( ok _pic ) ;
edit . appendChild ( edit _form ) ;
edit _row . appendChild ( edit _form ) ;
edit _row . appendChild ( edit ) ;
list . appendChild ( edit _row ) ;
list . appendChild ( edit _row ) ;
// Append extra menu items
// Append extra menu items
if ( this . extra _menu _items . length > 0 )
if ( this . extra _menu _items . length > 0 )
list . appendChild ( this . createListSeparator ( ) ) ;
list . appendChild ( this . createListSeparator ( ) ) ;
var loop = function ( i ) {
var loop = function ( i ) {
if ( i < ref . extra _menu _items . length ) {
if ( i < ref . extra _menu _items . length ) {
var e _elm = ref . extra _menu _items [ i ] ;
var e _elm = ref . extra _menu _items [ i ] ;
if ( ! e _elm [ 2 ] || e _elm [ 2 ] ( elm , ref ) ) {
if ( ! e _elm [ 2 ] || e _elm [ 2 ] ( elm , ref ) ) {
var e _row = document . createElement ( 'tr' ) ,
var e _row = document . createElement ( 'tr' ) ,
e _col = document . createElement ( 'td' ) ;
e _col = document . createElement ( 'td' ) ;
$ ( e _col ) . html ( e _elm [ 0 ] )
$ ( e _col ) . html ( e _elm [ 0 ] )
. mouseover ( ref . item _onmouseover )
. mouseover ( ref . item _onmouseover )
. mouseout ( ref . item _onmouseout )
. mouseout ( ref . item _onmouseout )
. click ( function ( ) { return e _elm [ 1 ] ( elm , ref ) } ) ;
. click ( function ( ) { return e _elm [ 1 ] ( elm , ref ) } ) ;
e _row . appendChild ( e _col ) ;
e _row . appendChild ( e _col ) ;
list . appendChild ( e _row ) ;
list . appendChild ( e _row ) ;
}
loop ( i + 1 ) ;
}
}
} ;
loop ( i + 1 ) ;
}
} ;
loop ( 0 ) ;
loop ( 0 ) ;
loop = null ;
loop = null ;
//Close button
//Close button
if ( this . use _close _btn ) {
if ( this . use _close _btn ) {
list . appendChild ( this . createCloseButton ( this . hideErrorWindow ) ) ;
list . appendChild ( this . createCloseButton ( this . hideErrorWindow ) ) ;
}
}
}
table . appendChild ( list ) ;
this . error _window . appendChild ( list ) ;
this . error _window . appendChild ( table ) ;
// roundcube plugin api hook
// roundcube plugin api hook
rcmail . triggerEvent ( 'googiespell_create' , { obj : this . error _window } ) ;
rcmail . triggerEvent ( 'googiespell_create' , { obj : this . error _window } ) ;
@ -835,103 +785,6 @@ this.showErrorsInIframe = function()
// this.edit_layer.scrollTop = this.ta_scroll_top;
// 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 . deHighlightCurSel = function ( )
{
{
$ ( this . lang _cur _elm ) . removeClass ( ) . addClass ( 'googie_list_onout' ) ;
$ ( 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 ( )
this . createSpellDiv = function ( )
{
{
var span = document . createElement ( 'span' ) ;
var span = document . createElement ( 'span' ) ;
@ -1043,10 +872,7 @@ this.checkSpellingState = function(fire)
if ( fire )
if ( fire )
this . setStateChanged ( 'ready' ) ;
this . setStateChanged ( 'ready' ) ;
if ( this . show _change _lang _pic )
this . switch _lan _pic = document . createElement ( 'span' ) ;
this . switch _lan _pic = this . createChangeLangPic ( ) ;
else
this . switch _lan _pic = document . createElement ( 'span' ) ;
var span _chck = this . createSpellDiv ( ) ,
var span _chck = this . createSpellDiv ( ) ,
ref = this ;
ref = this ;