Skip to content

Commit dc5d7b7

Browse files
hansonrhansonr
authored andcommitted
jquery widget upgrades
1 parent cd2e120 commit dc5d7b7

File tree

3 files changed

+70
-20
lines changed

3 files changed

+70
-20
lines changed

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44
* A relatively simple ComboBox that supports actual objects, not just strings
55
*
66
*/
7+
8+
// NOTE: If you change this file, then you need to touch and save JQueryUI.java, as only then
9+
// will the transpiler copy this file to site/swingjs/j2s/swingjs/jquery/
10+
711
$( function() {
812
$('head').append('<style>.j2scb-sel {background-color:#B8CFE5;}'
913
+'\n.j2scb-unsel {background-color:white;}'
1014
+'\n.j2scb-hov {background-color:lightblue;}'
1115
+'\n.j2scbcont {position:absolute; left:0px;top:0px;border:black solid 1px;}'
1216
+'\n.j2scbhead {position:absolute; left:0px;top:0px;padding:.1em .2em 0em .2em;text-align:left;overflow:hidden;}'
13-
+'\n.j2scbbtn {position:absolute; left:100px;top:0px; width:20px;text-align:center;cursor:pointer;background-color:lightblue;padding:0px}'
17+
+'\n.j2scbbtn {position:absolute; leftbackground-color:white;:100px;top:0px; width:20px;text-align:center;cursor:pointer;background-color:lightblue;padding:0px}'
1418
+'\n.j2scbpopup {position:absolute; list-style:none}'
15-
+'\n.j2scblist {position:absolute; left:0px;top:0px;margin:0;border:black solid 1px;cursor:pointer;text-align:left;padding:0em;scrollbar-width:thin;cursor:pointer;}</style>'
19+
+'\n.j2scblist {background-color:white;position:absolute; left:0px;top:0px;margin:0;border:black solid 1px;cursor:pointer;text-align:left;padding:0em;scrollbar-width:thin;cursor:pointer;}</style>'
1620
);
1721

18-
var t;
1922
var CLOSE_DELAY = 50;
20-
var stopT = function() {clearTimeout(t); t = 0;}
2123

2224
// the widget definition, where 'custom' is the namespace,
2325
// 'j2sCB' the widget name
@@ -87,7 +89,7 @@ $( function() {
8789
$('body').after(this.popup);
8890
this.updateCSS();
8991
this.on( [this.head, this.btn, this.cont], { click: '_open' });
90-
this.on( [this.popup, this.list], {mouseover: stopT });
92+
this.on( [this.popup, this.list], {mouseover: '_stopT' });
9193
this.on( [this.cont, this.head, this.btn, this.popup, this.list], {
9294
mouseleave: '_close'//,
9395
//keydown: '_keyEvent'
@@ -137,8 +139,8 @@ $( function() {
137139
+ (all = this.list.find('.j2scbopt').length) + ' selected option' + (all > 1 ? 's' :''));
138140
if (andTrigger)
139141
this._trigger( 'change' , null, [this, "selected", sel[0].j2scbIndex]);
140-
else
141-
stopT();
142+
// else
143+
// this._stopT("update");
142144
},
143145
updateList: function(items) {
144146
this.list.children().detach();
@@ -213,7 +215,7 @@ $( function() {
213215
this.cont.focus();
214216
if (this.options.disabled)
215217
return;
216-
stopT();
218+
this._stopT("_open");
217219
var loc = this.element.offset();
218220
if (e)
219221
this._trigger('change', null, [this, 'opening']);
@@ -229,11 +231,13 @@ $( function() {
229231
this.element.focus();
230232
},
231233
hidePopup: function() {
232-
this.options.popupVisible = false;
233-
this.popup.hide();
234+
if (this.options.popupVisible) {
235+
this.options.popupVisible = false;
236+
this.popup.hide();
237+
}
234238
},
235239
_overOpt: function(e) {
236-
stopT();
240+
this._stopT("_overOpt");
237241
this.list.find('.j2scbopt').removeClass('j2scb-hov j2scb-sel');
238242
var opt = $(e && e.target || e).closest('.j2scbopt');
239243
opt.addClass('j2scb-hov');
@@ -263,14 +267,19 @@ $( function() {
263267
this.update(andTrigger);
264268
return opt;
265269
},
270+
_stopT: function(why) {
271+
clearTimeout(this.t);
272+
this.t = 0;
273+
},
266274
_close: function() {
267-
if (t)return;
275+
if (this.t)return;
268276
var me = this;
269-
t = setTimeout(function() {
277+
this.t = setTimeout(function() {
270278
me.hidePopup();
271-
stopT();
279+
me.t = 0;
272280
},CLOSE_DELAY);
273281
}
282+
274283
});
275284

276285
} );

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

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
// author: Bob Hanson, hansonr@stolaf.edu
44
// last edited 1/23/2019 -- fixes for mouse-down effector (mac) operation
55

6+
// NOTE: If you change this file, then you need to touch and save JQueryUI.java, as only then
7+
// will the transpiler copy this file to site/swingjs/j2s/swingjs/jquery/
8+
69
/*! jQuery UI - v1.9.2 - 2012-12-17
710
* http://jqueryui.com
811
* Includes: jquery.ui.core.js, jquery.ui.widget.js, jquery.ui.mouse.js, jquery.ui.position.js, jquery.ui.menu.js
@@ -44,11 +47,19 @@ try{
4447
}
4548
}
4649

50+
var closeOnLeave = function(e, me, t) {
51+
debugger
52+
53+
e.contains(me.element[0],me.document[0].activeElement)
54+
||me.collapseAll(t)
55+
}
56+
4757
var cleanText = function(n) {
4858
return n && n.innerText.replace(/\n/g,"|");
4959
}
5060

5161
var CLICK_OUT_DELAY = 200;// ms; 100 was too fast
62+
var CLOSE_DELAY = 700;
5263

5364
var outActive;
5465

@@ -131,7 +142,7 @@ try{
131142
n||me.focus(t,me.active||me.element.children(".ui-j2smenu-item").eq(0));
132143
return;
133144
case "onblur":
134-
me.timer = delayMe(me, function(){e.contains(me.element[0],me.document[0].activeElement)||me.collapseAll(t)});
145+
me.timer = delayMe(me, function(){closeOnLeave(e, me, t)});
135146
break;
136147
case "_activate":
137148
me.active.is(".ui-state-disabled")||(me.active.children(".a[aria-haspopup='true']").length?me.expand(t):me.select(t));
@@ -140,6 +151,7 @@ try{
140151
if(t.attr("aria-hidden")!=="true") {
141152
return;
142153
}
154+
me._stopT("opening");
143155
me.timer=delayMe(me, function(){me._closeSubmenus(),me._openSubmenu(t);},me.delay);
144156
return;
145157
case "_hideAllMenus":
@@ -155,6 +167,7 @@ try{
155167
n = e.extend({of:n},me.options.position);
156168
var ui = me.activeMenu && me.activeMenu[0] && me.activeMenu[0]["data-ui"];
157169
ui && ui.processJ2SMenuCmd$OA([trigger,me,e,t.parent(),n,why]);
170+
me._stopT("opening");
158171
clearMe(me.timer, trigger);
159172
me.refresh("_openSubmenu",n);
160173
var v = me.element.find(".ui-j2smenu").not(t.parents(".ui-j2smenu"));
@@ -224,6 +237,8 @@ try{
224237
}
225238
break;
226239
case "collapseAll":
240+
// e jQuery
241+
// t event
227242
var u;
228243
if ( me.closed || !n && (!someMenuOpen(e) ||
229244
((u=e(t&&t.target)).hasClass("ui-j2smenu-node") || u.hasClass("ui-j2smenu"))
@@ -246,7 +261,6 @@ try{
246261
}, me.delay);
247262
break;
248263
case "focus":
249-
//System.out.println("j2smenu " + document.activeElement.id);
250264
me.blur(t,t&&t.type==="focus");
251265
me._scrollIntoView(n);
252266
me.active=n.first();
@@ -261,10 +275,8 @@ try{
261275
me.activeMenu=n.parent();
262276
me._trigger("focus",t,{item:n});
263277
t = n;
264-
//System.out.println("j2smenu " + document.activeElement.id);
265278
break;
266279
case "blur":
267-
//System.out.println("j2smenu " + document.activeElement.id);
268280
if (me.active && t && typeof n == "undefined" && t.relatedTarget && t.relatedTarget.getAttribute("role") != "presentation") {
269281
doCmd("_hide", me, t, me.element);
270282
}
@@ -276,7 +288,6 @@ try{
276288
me.active=null;
277289
me._trigger("blur",t,{item:a});
278290
t = a;
279-
//System.out.println("j2smenu " + document.activeElement.id);
280291
break;
281292
case "select":
282293
me.active=me.active||e(t.target).closest(".ui-j2smenu-item");
@@ -353,6 +364,10 @@ try{
353364

354365
_create:function(){
355366

367+
368+
xxm = this;
369+
370+
xxe = e;
356371
this.closed = false;
357372

358373
if (typeof this.options.delay == "number")
@@ -378,6 +393,10 @@ try{
378393
blur: function(t){doCmd("onblur",this,e,t)},
379394
keydown:"_keydown"
380395
}),
396+
this.on($(".ui-j2smenu-node"), {
397+
"mouseout":function() {this._closeMe()},
398+
"mouseover":function() {this._stopT("over")}
399+
}),
381400
this.refresh("create");
382401
},
383402
_destroy:function(){this.element.removeAttr("aria-activedescendant").find(".ui-j2smenu").andSelf()
@@ -459,6 +478,24 @@ try{
459478
break;
460479
}
461480
},
481+
482+
on: function(a, x) {for(var i = a.length; --i >= 0;)this._on(a[i],x)},
483+
on2: function(obj, evts, handle) {var a = {};for(var i = evts.length; --i >= 0;)a[evts[i]]=handle;this._on(obj, a)},
484+
_stopT: function(why) {
485+
clearTimeout(this.t);
486+
this.t = 0;
487+
},
488+
_closeMe: function() {
489+
if (this.t)return;
490+
var me = this;
491+
this.t = setTimeout(function() {
492+
me.collapseAll();
493+
me.t = 0;
494+
},CLOSE_DELAY);
495+
},
496+
497+
498+
462499
_activate:function(t){ doCmd("_activate", this, e, t); },
463500
_startOpening: function(t){ doCmd("_startOpening", this, e, t); },
464501
focus:function(t,n){ doCmd("focus", this, e, t, n) },
@@ -499,7 +536,7 @@ Swing.__getMenuStyle = function(applet) { return '\
499536
.swingjsPopupMenu,.swingjsPopupMenu .ui-j2smenu{list-style:none;padding:2px;margin:0;display:block;outline:none;box-shadow:1px 1px 5px rgba(50,50,50,0.75)}\
500537
.swingjsPopupMenu .ui-j2smenu{margin-top:-3px;position:absolute}\
501538
.swingjsPopupMenu .ui-j2smenu-item{cursor:pointer;margin:0 0 0 0;padding:0;width:100%}\
502-
.swingjsPopupMenu .a:focus{cursor:pointer;margin:0 0 0 0;padding:0;width:100%}\
539+
.swingjsPopupMenu .a:focus{outline:none;cursor:pointer;margin:0 0 0 0;padding:0;width:100%}\
503540
.swingjsPopupMenu .ui-j2smenu-divider{margin:3px 1px;height:0;transform:translateY(-4px);position:absolute;font-size:0;line-height:0px;border-width:2px 0 0 0;width:93%;}\
504541
.swingjsPopupMenu .ui-j2smenu-item .a{display:block;padding:0.05em 0.4em;white-space:nowrap;border:1px solid transparent}\
505542
.swingjsPopupMenu .ui-j2smenu-icons{position:relative}\

sources/net.sf.j2s.java.core/src/swingjs/jquery/jquery-ui-j2sslider.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
// added j2sslider("getState")
1414
;
1515

16+
//NOTE: If you change this file, then you need to touch and save JQueryUI.java, as only then
17+
//will the transpiler copy this file to site/swingjs/j2s/swingjs/jquery/
18+
19+
1620
(function() {
1721

1822
if (J2S.isResourceLoaded("swingjs/jquery/jquery-ui-j2sslider.js", true))

0 commit comments

Comments
 (0)