Skip to content

Commit 0162818

Browse files
hansonrhansonr
authored andcommitted
fixes persistence issues with jQuery menu
1 parent cf8b7f9 commit 0162818

File tree

8 files changed

+68
-23
lines changed

8 files changed

+68
-23
lines changed
138 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20181220025341
1+
20181220041423
138 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20181220025341
1+
20181220041423
284 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/src/swingjs/jquery/JQueryUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @author Bob Hanson
1111
*
1212
*/
13-
public class JQueryUI {
13+
public class JQueryUI {
1414

1515
public JQueryUI() {
1616

sources/net.sf.j2s.java.core/src/swingjs/jquery/j2sMenu.js

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,25 @@ try{
4444
this._on({
4545
"mousedown .ui-menu-item > a":function(e){e.preventDefault()},
4646
"click .ui-state-disabled > a":function(e){e.preventDefault()},
47-
"click .ui-menu-item:has(a)":function(t){var r=e(t.target).closest(".ui-menu-item");!n&&r.not(".ui-state-disabled").length&&(n=!0,this.select(t),r.has(".ui-menu").length?this.expand(t):this.element.is(":focus")||(this.element.trigger("focus",[!0]),this.active&&this.active.parents(".ui-menu").length===1&&clearTimeout(this.timer)))},
47+
"click .ui-menu-item:has(a)":function(t){
48+
49+
50+
// BH 12/20/2018 adds persistence for JMenu clicks
51+
52+
if (this.active && this.active[0].attributes.name && this.active[0].attributes.name.value == "javax.swing.JMenu") {
53+
clearTimeout(this.timer);
54+
return
55+
}
56+
57+
var r=e(t.target).closest(".ui-menu-item");
58+
59+
!n&&r.not(".ui-state-disabled").length&&(n=!0,this.select(t),r.has(".ui-menu").length?this.expand(t):this.element.is(":focus")||(this.element.trigger("focus",[!0]),this.active&&this.active.parents(".ui-menu").length===1&&clearTimeout(this.timer)))
60+
61+
; $(".ui-menu").hide();
62+
63+
64+
65+
},
4866
"mouseenter .ui-menu-item":function(t){var n=e(t.currentTarget);n.siblings().children(".ui-state-active").removeClass("ui-state-active"),this.focus(t,n)},
4967
mouseleave:"collapseAll",
5068
"mouseleave .ui-menu": "collapseAll",
@@ -72,7 +90,8 @@ try{
7290
.data("ui-menu-submenu-carat",!0);
7391
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);/[^\-+GG+GG\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()},
7492
_itemRole:function(){return{menu:"menuitem",listbox:"option"}[this.options.role]},
75-
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&&/^mouse/.test(e.type)&&this._startOpening(n),this.activeMenu=t.parent(),this._trigger("focus",e,{item:t})},
93+
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():
94+
this.timer=this._delay(function(){this._close()},this.delay),n=t.children(".ui-menu"),n.length&&/^mouse/.test(e.type)&&this._startOpening(n),this.activeMenu=t.parent(),this._trigger("focus",e,{item:t})},
7695
_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))},
7796
blur:function(e,t){
7897

@@ -94,7 +113,20 @@ try{
94113
this.activeMenu=r
95114
}, this.delay)
96115
},
97-
_close:function(e){e||(e=this.active?this.active.parent():this.element),e.find(".ui-menu").hide().attr("aria-hidden","true").attr("aria-expanded","false").end().find("a.ui-state-active").removeClass("ui-state-active")},
116+
_close:function(e){
117+
118+
var e0= e;
119+
e||(e=this.active?this.active.parent():this.element),
120+
e.find(".ui-menu")
121+
.hide()
122+
.attr("aria-hidden","true")
123+
.attr("aria-expanded","false")
124+
.end()
125+
.find("a.ui-state-active")
126+
.removeClass("ui-state-active")
127+
128+
129+
},
98130
collapse:function(e){var t=this.active&&this.active.parent().closest(".ui-menu-item",this.element);t&&t.length&&(this._close(),this.focus(e,t))},
99131
expand:function(e){var t=this.active&&this.active.children(".ui-menu ").children(".ui-menu-item").first();t&&t.length&&(this._open(t.parent()),this._delay(function(){this.focus(e,t)}))},
100132
next:function(e){this._move("next","first",e)},
@@ -158,11 +190,19 @@ var bindMenuActionCommands = function(eventType, menu, isBind) {
158190
var children = (menu.uiClassID ? menu.ui.getChildren() : menu.getComponents());
159191
for(var i = children.length; --i >= 0;)
160192
bindMenuActionCommands(eventType, children[i], isBind);
193+
194+
195+
196+
161197
if (!menu.uiClassID || !menu["data-ui"])
162198
return;
163199
J2S.$documentOff(eventType, menu.id);
164200
if (isBind)
165201
J2S.$documentOn(eventType, menu.id, function(event) {
202+
203+
204+
205+
166206
if (menu.uiClassID) {
167207
System.out.println(["menu " + menu.ui.id , " clicked " , event.target.id , event.target.tagName, event.target["data-component"]]);
168208
Swing.hideMenus(menu._applet);

sources/net.sf.j2s.java.core/srcjs/swingjs2.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10659,6 +10659,7 @@ return jQuery;
1065910659
})(jQuery,document,"click mousemove mouseup touchmove touchend", "outjsmol");
1066010660
// j2sCore.js (based on JmolCore.js
1066110661

10662+
// BH 12/20/2018 fixes mouse event extended modifiers for drag operation
1066210663
// BH 11/7/2018 adds J2S.addDirectDatabaseCall(domain)
1066310664
// BH 9/18/2018 fixes data.getBytes() not qualified
1066410665
// BH 8/12/2018 adding J2S.onClazzLoaded(i,msg) hook for customization
@@ -12463,24 +12464,28 @@ console.log("J2S._getRawDataFromServer " + J2S._serverUrl + " for " + query);
1246312464

1246412465
var getMouseModifiers = function(ev, id) {
1246512466
// id needed to properly not assign the InputEvent.ButtonX_DOWN_MASK for an UP operation
12467+
// and also recognize a drag (503 + buttons pressed
1246612468
var modifiers = 0;
12467-
if (id != 503)
12468-
switch (ev.button) {
12469-
default:
12470-
ev.button = 0;
12471-
// fall through
12472-
case 0:
12473-
modifiers = (1 << 4) | (id ? 0 : (1 << 10));// InputEvent.BUTTON1 +
12474-
// InputEvent.BUTTON1_DOWN_MASK;
12475-
break;
12476-
case 1:
12477-
modifiers = (1 << 3) | (id ? 0 : (1 << 11));// InputEvent.BUTTON2 +
12478-
// InputEvent.BUTTON2_DOWN_MASK;
12479-
break;
12480-
case 2:
12481-
modifiers = (1 << 2) | (id ? 0 : (1 << 12));// InputEvent.BUTTON3 +
12482-
// InputEvent.BUTTON3_DOWN_MASK;
12483-
break;
12469+
if (id == 503) {
12470+
modifiers = ev.buttons << 10;
12471+
} else {
12472+
switch (ev.button) {
12473+
default:
12474+
ev.button = 0;
12475+
// fall through
12476+
case 0:
12477+
modifiers = (1 << 4) | (id ? 0 : (1 << 10));// InputEvent.BUTTON1 +
12478+
// InputEvent.BUTTON1_DOWN_MASK;
12479+
break;
12480+
case 1:
12481+
modifiers = (1 << 3) | (id ? 0 : (1 << 11));// InputEvent.BUTTON2 +
12482+
// InputEvent.BUTTON2_DOWN_MASK;
12483+
break;
12484+
case 2:
12485+
modifiers = (1 << 2) | (id ? 0 : (1 << 12));// InputEvent.BUTTON3 +
12486+
// InputEvent.BUTTON3_DOWN_MASK;
12487+
break;
12488+
}
1248412489
}
1248512490
return modifiers | J2S.getKeyModifiers(ev);
1248612491
}

0 commit comments

Comments
 (0)