3030 role :"menu" ,
3131 blur :null ,
3232 focus :null ,
33- select :null } ,
34- _create :function ( ) { this . activeMenu = this . element , this . element . uniqueId ( ) . addClass ( "ui-menu ui-widget ui-widget-content ui-corner-all" ) . toggleClass ( "ui-menu-icons" , ! ! this . element . find ( ".ui-icon" ) . length )
33+ select :null
34+ } ,
35+
36+
37+ _create :function ( ) {
38+
39+ if ( typeof this . options . delay == "number" )
40+ this . delay = this . options . delay ;
41+
42+ this . activeMenu = this . element , this . element . uniqueId ( ) . addClass ( "ui-menu ui-widget ui-widget-content ui-corner-all" ) . toggleClass ( "ui-menu-icons" , ! ! this . element . find ( ".ui-icon" ) . length )
3543 . attr ( { role :this . options . role , tabIndex :0 } ) . bind ( "click" + this . eventNamespace , e . proxy ( function ( e ) { this . options . disabled && e . preventDefault ( ) } , this ) ) , this . options . disabled && this . element . addClass ( "ui-state-disabled" ) . attr ( "aria-disabled" , "true" ) ,
3644 this . _on ( { "mousedown .ui-menu-item > a" :function ( e ) { e . preventDefault ( ) } ,
3745 "click .ui-state-disabled > a" :function ( e ) { e . preventDefault ( ) } ,
4452 this . _on ( this . document , {
4553 click :function ( t ) { e ( t . target ) . closest ( ".ui-menu" ) . length || this . collapseAll ( t ) , n = ! 1 } } ) } ,
4654
47-
48-
4955 _destroy :function ( ) { this . element . removeAttr ( "aria-activedescendant" ) . find ( ".ui-menu" ) . andSelf ( ) . removeClass ( "ui-menu ui-widget ui-widget-content ui-corner-all ui-menu-icons" ) . removeAttr ( "role" ) . removeAttr ( "tabIndex" ) . removeAttr ( "aria-labelledby" ) . removeAttr ( "aria-expanded" ) . removeAttr ( "aria-hidden" ) . removeAttr ( "aria-disabled" ) . removeUniqueId ( ) . show ( ) , this . element . find ( ".ui-menu-item" ) . removeClass ( "ui-menu-item" ) . removeAttr ( "role" ) . removeAttr ( "aria-disabled" ) . children ( "a" ) . removeUniqueId ( ) . removeClass ( "ui-corner-all ui-state-hover" ) . removeAttr ( "tabIndex" ) . removeAttr ( "role" ) . removeAttr ( "aria-haspopup" ) . children ( ) . each ( function ( ) { var t = e ( this ) ; t . data ( "ui-menu-submenu-carat" ) && t . remove ( ) } ) , this . element . find ( ".ui-menu-divider" ) . removeClass ( "ui-menu-divider ui-widget-content" ) } ,
5056 _keydown :function ( t ) { function a ( e ) { return e . replace ( / [ \- \[ \] { } ( ) * + ? . , \\ \^ $ | # \s ] / g, "\\$&" ) } var n , r , i , s , o , u = ! 0 ; switch ( t . keyCode ) { case e . ui . keyCode . PAGE_UP :this . previousPage ( t ) ; break ; case e . ui . keyCode . PAGE_DOWN :this . nextPage ( t ) ; break ; case e . ui . keyCode . HOME :this . _move ( "first" , "first" , t ) ; break ; case e . ui . keyCode . END :this . _move ( "last" , "last" , t ) ; break ; case e . ui . keyCode . UP :this . previous ( t ) ; break ; case e . ui . keyCode . DOWN :this . next ( t ) ; break ; case e . ui . keyCode . LEFT :this . collapse ( t ) ; break ; case e . ui . keyCode . RIGHT :this . active && ! this . active . is ( ".ui-state-disabled" ) && this . expand ( t ) ; break ; case e . ui . keyCode . ENTER :case e . ui . keyCode . SPACE :this . _activate ( t ) ; break ; case e . ui . keyCode . ESCAPE :this . collapse ( t ) ; break ; default :u = ! 1 , r = this . previousFilter || "" , i = String . fromCharCode ( t . keyCode ) , s = ! 1 , clearTimeout ( this . filterTimer ) , i === r ?s = ! 0 :i = r + i , o = new RegExp ( "^" + a ( i ) , "i" ) , n = this . activeMenu . children ( ".ui-menu-item" ) . filter ( function ( ) { return o . test ( e ( this ) . children ( "a" ) . text ( ) ) } ) , n = s && n . index ( this . active . next ( ) ) !== - 1 ?this . active . nextAll ( ".ui-menu-item" ) :n , n . length || ( i = String . fromCharCode ( t . keyCode ) , o = new RegExp ( "^" + a ( i ) , "i" ) , n = this . activeMenu . children ( ".ui-menu-item" ) . filter ( function ( ) { return o . test ( e ( this ) . children ( "a" ) . text ( ) ) } ) ) , n . length ?( this . focus ( t , n ) , n . length > 1 ?( this . previousFilter = i , this . filterTimer = this . _delay ( function ( ) { delete this . previousFilter } , 1e3 ) ) :delete this . previousFilter ) :delete this . previousFilter } u && t . preventDefault ( ) } ,
5157 _activate :function ( e ) { this . active . is ( ".ui-state-disabled" ) || ( this . active . children ( "a[aria-haspopup='true']" ) . length ?this . expand ( e ) :this . select ( e ) ) } ,
5258 refresh :function ( ) { var t , n = this . options . icons . submenu , r = this . element . find ( this . options . menus ) ; r . filter ( ":not(.ui-menu)" ) . addClass ( "ui-menu ui-widget ui-widget-content ui-corner-all" ) . hide ( ) . attr ( { role :this . options . role , "aria-hidden" :"true" , "aria-expanded" :"false" } ) . each ( function ( ) { var t = e ( this ) , r = t . prev ( "a" ) , i = e ( "<span>" ) . addClass ( "ui-menu-icon ui-icon " + n ) . data ( "ui-menu-submenu-carat" , ! 0 ) ; r . attr ( "aria-haspopup" , "true" ) . prepend ( i ) , t . attr ( "aria-labelledby" , r . attr ( "id" ) ) } ) , t = r . add ( this . element ) , t . children ( ":not(.ui-menu-item):has(a)" ) . addClass ( "ui-menu-item" ) . attr ( "role" , "presentation" ) . children ( "a" ) . uniqueId ( ) . addClass ( "ui-corner-all" ) . attr ( { tabIndex :- 1 , role :this . _itemRole ( ) } ) , t . children ( ":not(.ui-menu-item)" ) . each ( function ( ) { var t = e ( this ) ; / [ ^ \- + � G � � G � � + � G � � G � � \s ] / . test ( t . text ( ) ) || t . addClass ( "ui-widget-content ui-menu-divider" ) } ) , t . children ( ".ui-state-disabled" ) . attr ( "aria-disabled" , "true" ) , this . active && ! e . contains ( this . element [ 0 ] , this . active [ 0 ] ) && this . blur ( ) } ,
5359 _itemRole :function ( ) { return { menu :"menuitem" , listbox :"option" } [ this . options . role ] } ,
5460 focus :function ( e , t ) { var n , r ; this . blur ( e , e && e . type === "focus" ) , this . _scrollIntoView ( t ) , this . active = t . first ( ) , r = this . active . children ( "a" ) . addClass ( "ui-state-focus" ) , this . options . role && this . element . attr ( "aria-activedescendant" , r . attr ( "id" ) ) , this . active . parent ( ) . closest ( ".ui-menu-item" ) . children ( "a:first" ) . addClass ( "ui-state-active" ) , e && e . type === "keydown" ?this . _close ( ) :this . timer = this . _delay ( function ( ) { this . _close ( ) } , this . delay ) , n = t . children ( ".ui-menu" ) , n . length && / ^ m o u s e / . test ( e . type ) && this . _startOpening ( n ) , this . activeMenu = t . parent ( ) , this . _trigger ( "focus" , e , { item :t } ) } ,
5561 _scrollIntoView :function ( t ) { var n , r , i , s , o , u ; this . _hasScroll ( ) && ( n = parseFloat ( e . css ( this . activeMenu [ 0 ] , "borderTopWidth" ) ) || 0 , r = parseFloat ( e . css ( this . activeMenu [ 0 ] , "paddingTop" ) ) || 0 , i = t . offset ( ) . top - this . activeMenu . offset ( ) . top - n - r , s = this . activeMenu . scrollTop ( ) , o = this . activeMenu . height ( ) , u = t . height ( ) , i < 0 ?this . activeMenu . scrollTop ( s + i ) :i + u > o && this . activeMenu . scrollTop ( s + i - o + u ) ) } ,
56- blur :function ( e , t ) { t || clearTimeout ( this . timer ) ; if ( ! this . active ) return ; this . active . children ( "a" ) . removeClass ( "ui-state-focus" ) , this . active = null , this . _trigger ( "blur" , e , { item :this . active } ) } ,
62+ blur :function ( e , t ) {
63+
64+ if ( this . active && typeof t == "undefined" && e . relatedTarget && e . relatedTarget . getAttribute ( "role" ) != "presentation" ) {
65+ this . element . hide ( ) ;
66+ }
67+
68+
69+ t || clearTimeout ( this . timer ) ; if ( ! this . active ) return ; this . active . children ( "a" ) . removeClass ( "ui-state-focus" ) , this . active = null , this . _trigger ( "blur" , e , { item :this . active } ) } ,
5770 _startOpening :function ( e ) { clearTimeout ( this . timer ) ; if ( e . attr ( "aria-hidden" ) !== "true" ) return ; this . timer = this . _delay ( function ( ) { this . _close ( ) , this . _open ( e ) } , this . delay ) } ,
5871 _open :function ( t ) { var n = e . extend ( { of :this . active } , this . options . position ) ; clearTimeout ( this . timer ) , this . element . find ( ".ui-menu" ) . not ( t . parents ( ".ui-menu" ) ) . hide ( ) . attr ( "aria-hidden" , "true" ) , t . show ( ) . removeAttr ( "aria-hidden" ) . attr ( "aria-expanded" , "true" ) . position ( n ) } ,
5972 collapseAll :function ( t , n ) { clearTimeout ( this . timer ) , this . timer = this . _delay ( function ( ) { var r = n ?this . element :e ( t && t . target ) . closest ( this . element . find ( ".ui-menu" ) ) ; r . length || ( r = this . element ) , this . _close ( r ) , this . blur ( t ) , this . activeMenu = r } , this . delay ) } ,
@@ -181,6 +194,38 @@ Swing.initMenuItem = function(item) {
181194 item . icon && ( item . icon = '<img src="' + item . _applet . _j2sPath + '/' + item . icon + '" style="max-height: 20px;" />' )
182195}
183196
197+ Swing . updateMenu = function ( menu ) {
198+ if ( menu . uiClassID ) {
199+ // for SwingJS the top node is domNode itself, which is already <ul>
200+ var node = menu . ui . domNode ;
201+ if ( node != menu . $ulTop [ 0 ] ) {
202+ if ( menu . $ulTop ) {
203+ //bindMenuActionCommands(menu._actionEvent, menu, false);
204+ menu . $ulTop . remove ( ) ;
205+ }
206+ menu . setContainer ( J2S . $ ( node ) ) ;
207+ J2S . $ ( node ) . addClass ( "swingjsPopupMenu" ) ;
208+ }
209+ J2S . $after ( "body" , node ) ;
210+ node . style . display = "block" ;
211+ } else {
212+ menu . $ulTop . html ( menu . toHTML ( ) ) ;
213+ bindMenuActionCommands ( menu . _actionEvent , menu , true ) ;
214+ }
215+ menu . $ulTop . menu ( { delay :300 } ) . menu ( 'refresh' ) ;
216+ if ( menu . uiClassID )
217+ menu . $ulTop . find ( "[role=menuitem]" ) . each ( function ( ) { Swing . updateMenuItem ( menu , this ) ; } ) ;
218+ menu . _tainted = false ;
219+ }
220+
221+ Swing . updateMenuItem = function ( menu , node ) {
222+ J2S . unsetMouse ( node ) ;
223+ node . applet = menu . _applet ;
224+ node . _frameViewer = menu . invoker . getFrameViewer$ ( ) ;
225+ node . _menu = menu ;
226+ J2S . setMouse ( node , true ) ;
227+ }
228+
184229Swing . showMenu = function ( menu , x , y ) {
185230 // called by javajs.swing.JPopupMenu and swingjs.plaf.JSPopupMenuUI (menu.uiClassID)
186231 // allow for a user callback for customization of menu
@@ -189,49 +234,22 @@ Swing.showMenu = function(menu, x, y) {
189234 for ( var i in menu . _applet . _menus )
190235 Swing . hideMenu ( menu . _applet . _menus [ i ] , true ) ;
191236 if ( J2S . _showMenuCallback )
192- J2S . _showMenuCallback ( menu , x , y ) ;
237+ J2S . _showMenuCallback ( menu , x , y ) ;
193238 var wasTainted = menu . _tainted ;
194- if ( menu . _tainted ) {
195- if ( menu . uiClassID ) {
196- // for SwingJS the top node is domNode itself, which is already <ul>
197- var node = menu . ui . domNode ;
198- if ( node != menu . $ulTop [ 0 ] ) {
199- if ( menu . $ulTop ) {
200- //bindMenuActionCommands(menu._actionEvent, menu, false);
201- menu . $ulTop . remove ( ) ;
202- }
203- menu . setContainer ( J2S . $ ( node ) ) ;
204- J2S . $ ( node ) . addClass ( "swingjsPopupMenu" ) ;
205- }
206- J2S . $after ( "body" , node ) ;
207- node . style . display = "block" ;
208- } else {
209- menu . $ulTop . html ( menu . toHTML ( ) ) ;
210- bindMenuActionCommands ( menu . _actionEvent , menu , true ) ;
211- }
212- menu . _tainted = false ;
213- }
239+ if ( menu . _tainted )
240+ Swing . updateMenu ( menu ) ;
214241 menu . setPosition ( x , y ) ;
215- menu . $ulTop . hide ( ) . menu ( ) . menu ( 'refresh' ) . show ( ) ;
216- if ( menu . uiClassID && wasTainted ) {
217- menu . $ulTop . find ( "[role=menuitem]" ) . each ( function ( ) {
218- var node = this ;
219- node . applet = menu . _applet ;
220- node . _frameViewer = menu . invoker . getFrameViewer$ ( ) ;
221- node . _menu = menu ;
222- J2S . setMouse ( node , true ) ;
223- } ) ;
224- }
225- menu . _visible = true ;
226- menu . timestamp = System . currentTimeMillis$ ( ) ;
227- menu . dragBind ( true ) ;
228- menu . $ulTop . unbind ( 'clickoutjsmol mousemoveoutjsmol' ) ;
229- if ( ! J2S . _persistentMenu )
230- menu . $ulTop . bind ( 'clickoutjsmol mousemoveoutjsmol' , function ( evspecial , target , ev ) {
231- if ( System . currentTimeMillis$ ( ) - menu . timestamp > 1000 )
232- Swing . hideMenu ( menu ) ;
233- } ) ;
234- menu . $ulTop . bind ( "contextmenu" , function ( ) { return false ; } ) ;
242+ menu . $ulTop . hide ( ) . menu ( ) . show ( ) ;
243+ menu . _visible = true ;
244+ menu . timestamp = System . currentTimeMillis$ ( ) ;
245+ menu . dragBind ( true ) ;
246+ // menu.$ulTop.unbind('clickoutjsmol mousemoveoutjsmol');
247+ // if (!J2S._persistentMenu)
248+ // menu.$ulTop.bind('clickoutjsmol mousemoveoutjsmol', function(evspecial, target, ev) {
249+ // if (System.currentTimeMillis$() - menu.timestamp > 500)
250+ // Swing.hideMenu(menu);
251+ // });
252+ menu . $ulTop . bind ( "contextmenu" , function ( ) { return false ; } ) ;
235253}
236254
237255Swing . hideMenu = function ( menu , force ) {
@@ -252,7 +270,7 @@ Swing.disposeMenu = function(menu) {
252270 if ( menu . uiClassID ) {
253271 menu . $ulTop . find ( "[role=menuitem]" ) . each ( function ( ) {
254272 this . applet = menu . ui . applet ;
255- J2S . setMouse ( this , false ) ;
273+ J2S . unsetMouse ( this ) ;
256274 } ) ;
257275 } else {
258276 Swing . bindMenuActionCommands ( menu , false ) ;
0 commit comments