Skip to content

Commit 286e764

Browse files
committed
primefaces#3263 aligned all components to only start the widgetVar, not the widget-instance itself
1 parent b029a50 commit 286e764

File tree

3 files changed

+206
-207
lines changed

3 files changed

+206
-207
lines changed

src/main/resources/META-INF/resources/primefaces/lightbox/lightbox.js

Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* PrimeFaces LightBox Widget
33
*/
44
PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
5-
5+
66
init: function(cfg) {
77
this._super(cfg);
8-
8+
99
this.links = this.jq.children(':not(.ui-lightbox-inline)');
1010

1111
this.createPanel();
@@ -24,20 +24,19 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
2424
this.links.eq(0).click();
2525
}
2626

27-
this.panel.data('widget', this);
2827
this.links.data('primefaces-lightbox-trigger', true).find('*').data('primefaces-lightbox-trigger', true);
2928
},
30-
29+
3130
refresh: function(cfg) {
3231
$(PrimeFaces.escapeClientId(cfg.id) + '_panel').remove();
33-
32+
3433
this.init(cfg);
3534
},
36-
35+
3736
destroy: function() {
3837
this.panel.remove();
3938
},
40-
39+
4140
createPanel: function() {
4241
var dom = '<div id="' + this.id + '_panel" class="ui-lightbox ui-widget ui-helper-hidden ui-corner-all ui-shadow">';
4342
dom += '<div class="ui-lightbox-content-wrapper">';
@@ -48,41 +47,41 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
4847
dom += '<div class="ui-lightbox-caption ui-widget-header"><span class="ui-lightbox-caption-text"></span>';
4948
dom += '<a class="ui-lightbox-close ui-corner-all" href="#"><span class="ui-icon ui-icon-closethick"></span></a><div style="clear:both" /></div>';
5049
dom += '</div>';
51-
50+
5251
$(document.body).append(dom);
53-
52+
5453
this.panel = $(this.jqId + '_panel');
5554
this.contentWrapper = this.panel.children('.ui-lightbox-content-wrapper');
5655
this.content = this.contentWrapper.children('.ui-lightbox-content');
5756
this.caption = this.panel.children('.ui-lightbox-caption');
58-
this.captionText = this.caption.children('.ui-lightbox-caption-text');
57+
this.captionText = this.caption.children('.ui-lightbox-caption-text');
5958
this.closeIcon = this.caption.children('.ui-lightbox-close');
6059
this.closeIcon.data('primefaces-lightbox-trigger', true).find('*').data('primefaces-lightbox-trigger', true);
6160
},
62-
61+
6362
setupImaging: function() {
6463
var _self = this;
6564

6665
this.content.append('<img class="ui-helper-hidden"></img>');
6766
this.imageDisplay = this.content.children('img');
6867
this.navigators = this.contentWrapper.children('a');
69-
68+
7069
this.imageDisplay.on('load', function() {
7170
var image = $(this);
72-
71+
7372
_self.scaleImage(image);
7473

7574
//coordinates to center overlay
7675
var leftOffset = (_self.panel.width() - image.width()) / 2,
7776
topOffset = (_self.panel.height() - image.height()) / 2;
78-
77+
7978
//resize content for new image
8079
_self.content.removeClass('ui-lightbox-loading').animate({
8180
width: image.width()
8281
,height: image.height()
8382
},
8483
500,
85-
function() {
84+
function() {
8685
//show image
8786
image.fadeIn();
8887
_self.showNavigators();
@@ -96,10 +95,10 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
9695
});
9796

9897
this.navigators.mouseover(function() {
99-
$(this).addClass('ui-state-hover');
98+
$(this).addClass('ui-state-hover');
10099
})
101100
.mouseout(function() {
102-
$(this).removeClass('ui-state-hover');
101+
$(this).removeClass('ui-state-hover');
103102
})
104103
.click(function(e) {
105104
var nav = $(this);
@@ -110,19 +109,19 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
110109
var index = _self.current == 0 ? _self.links.length - 1 : _self.current - 1;
111110

112111
_self.links.eq(index).trigger('click');
113-
}
112+
}
114113
else {
115114
var index = _self.current == _self.links.length - 1 ? 0 : _self.current + 1;
116115

117116
_self.links.eq(index).trigger('click');
118117
}
119118

120-
e.preventDefault();
119+
e.preventDefault();
121120
});
122121

123122
this.links.click(function(e) {
124123
var link = $(this);
125-
124+
126125
if(_self.isHidden()) {
127126
_self.content.addClass('ui-lightbox-loading').width(32).height(32);
128127
_self.show();
@@ -144,7 +143,7 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
144143
setTimeout(function() {
145144
_self.imageDisplay.attr('src', link.attr('href'));
146145
_self.current = link.index();
147-
146+
148147
var title = link.attr('title');
149148
if(title) {
150149
_self.captionText.html(title);
@@ -155,19 +154,19 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
155154
e.preventDefault();
156155
});
157156
},
158-
157+
159158
scaleImage: function(image) {
160159
var win = $(window),
161160
winWidth = win.width(),
162161
winHeight = win.height(),
163162
imageWidth = image.width(),
164163
imageHeight = image.height(),
165164
ratio = imageHeight / imageWidth;
166-
165+
167166
if(imageWidth >= winWidth && ratio <= 1){
168167
imageWidth = winWidth * 0.75;
169168
imageHeight = imageWidth * ratio;
170-
}
169+
}
171170
else if(imageHeight >= winHeight){
172171
imageHeight = winHeight * 0.75;
173172
imageWidth = imageHeight / ratio;
@@ -178,7 +177,7 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
178177
,'height':imageHeight + 'px'
179178
})
180179
},
181-
180+
182181
setupInline: function() {
183182
this.inline = this.jq.children('.ui-lightbox-inline');
184183
this.inline.appendTo(this.content).show();
@@ -196,16 +195,16 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
196195
e.preventDefault();
197196
});
198197
},
199-
198+
200199
setupIframe: function() {
201200
var $this = this;
202201
this.iframeLoaded = false;
203202
this.cfg.width = this.cfg.width||'640px';
204203
this.cfg.height = this.cfg.height||'480px';
205-
206-
this.iframe = $('<iframe frameborder="0" style="width:' + this.cfg.width + ';height:'
204+
205+
this.iframe = $('<iframe frameborder="0" style="width:' + this.cfg.width + ';height:'
207206
+ this.cfg.height + ';border:0 none; display: block;"></iframe>').appendTo(this.content);
208-
207+
209208
if(this.cfg.iframeTitle) {
210209
this.iframe.attr('title', this.cfg.iframeTitle);
211210
}
@@ -217,7 +216,7 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
217216
,height: $this.cfg.height
218217
});
219218
$this.show();
220-
219+
221220
$this.iframe.on('load', function() {
222221
$this.iframeLoaded = true;
223222
$this.content.removeClass('ui-lightbox-loading');
@@ -227,22 +226,22 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
227226
else {
228227
$this.show();
229228
}
230-
229+
231230
var title = $this.links.eq(0).attr('title');
232231
if(title) {
233232
$this.captionText.text(title);
234233
$this.caption.slideDown();
235234
}
236-
235+
237236
e.preventDefault();
238237
});
239238
},
240-
239+
241240
bindCommonEvents: function() {
242241
var $this = this,
243242
hideNS = PrimeFaces.env.ios ? 'touchstart.' + this.id: 'click.' + this.id,
244243
resizeNS = 'resize.' + this.id;
245-
244+
246245
this.closeIcon.mouseover(function() {
247246
$(this).addClass('ui-state-hover');
248247
})
@@ -256,11 +255,11 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
256255
});
257256

258257
//hide when outside is clicked
259-
$(document.body).off(hideNS).on(hideNS, function (e) {
258+
$(document.body).off(hideNS).on(hideNS, function (e) {
260259
if($this.isHidden()) {
261260
return;
262261
}
263-
262+
264263
//do nothing if target is the link
265264
var target = $(e.target);
266265
if(target.data('primefaces-lightbox-trigger')) {
@@ -270,15 +269,15 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
270269
//hide if mouse is outside of lightbox
271270
var offset = $this.panel.offset(),
272271
pageX, pageY;
273-
272+
274273
if(e.originalEvent && e.originalEvent.touches) {
275274
pageX = e.originalEvent.touches[0].pageX;
276275
pageY = e.originalEvent.touches[0].pageY;
277276
} else {
278277
pageX = e.pageX;
279278
pageY = e.pageY;
280279
}
281-
280+
282281
if(pageX < offset.left ||
283282
pageX > offset.left + $this.panel.width() ||
284283
pageY < offset.top ||
@@ -288,7 +287,7 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
288287
$this.hide();
289288
}
290289
});
291-
290+
292291
//sync window resize
293292
$(window).off(resizeNS).on(resizeNS, function() {
294293
if(!$this.isHidden()) {
@@ -299,12 +298,12 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
299298
}
300299
});
301300
},
302-
301+
303302
show: function() {
304303
this.center();
305-
304+
306305
this.panel.css('z-index', ++PrimeFaces.zindex).show();
307-
306+
308307
if(!this.isModalActive()) {
309308
this.enableModality();
310309
}
@@ -313,7 +312,7 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
313312
this.cfg.onShow.call(this);
314313
}
315314
},
316-
315+
317316
hide: function() {
318317
this.panel.fadeOut();
319318
this.disableModality();
@@ -328,8 +327,8 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
328327
this.cfg.onHide.call(this);
329328
}
330329
},
331-
332-
center: function() {
330+
331+
center: function() {
333332
var win = $(window),
334333
left = (win.width() / 2 ) - (this.panel.width() / 2),
335334
top = (win.height() / 2 ) - (this.panel.height() / 2);
@@ -339,7 +338,7 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
339338
'top': top
340339
});
341340
},
342-
341+
343342
enableModality: function() {
344343
$(document.body).append('<div id="' + this.id + '_modal" class="ui-widget-overlay"></div>').
345344
children(this.jqId + '_modal').css({
@@ -348,43 +347,43 @@ PrimeFaces.widget.LightBox = PrimeFaces.widget.BaseWidget.extend({
348347
,'z-index': this.panel.css('z-index') - 1
349348
});
350349
},
351-
350+
352351
disableModality: function() {
353352
$(document.body).children(this.jqId + '_modal').remove();
354353
},
355-
354+
356355
isModalActive: function() {
357356
return $(document.body).children(this.jqId + '_modal').length === 1;
358357
},
359-
358+
360359
showNavigators: function() {
361360
this.navigators.zIndex(this.imageDisplay.zIndex() + 1).show();
362361
},
363-
362+
364363
hideNavigators: function() {
365364
this.navigators.hide();
366365
},
367-
366+
368367
addOnshowHandler: function(fn) {
369368
this.onshowHandlers.push(fn);
370369
},
371-
370+
372371
isHidden: function() {
373372
return this.panel.is(':hidden');
374373
},
375-
374+
376375
showURL: function(opt) {
377376
if(opt.width)
378377
this.iframe.attr('width', opt.width);
379378
if(opt.height)
380379
this.iframe.attr('height', opt.height);
381-
382-
this.iframe.attr('src', opt.src);
383-
380+
381+
this.iframe.attr('src', opt.src);
382+
384383
this.captionText.text(opt.title||'');
385384
this.caption.slideDown();
386-
385+
387386
this.show();
388387
}
389-
388+
390389
});

0 commit comments

Comments
 (0)