Skip to content

Commit 85c0221

Browse files
author
Tero Piirainen
committed
lazyload support to tabs and scrollable
1 parent d6cc3c5 commit 85c0221

24 files changed

+247
-154
lines changed

release-notes/version-1.2.0.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ Fundamental changes
1212

1313
all tools
1414
- support for lazyloading
15-
15+
16+
tabs
17+
- history as configuration option
18+
- lazyload flag
19+
- deprecated "ajax" effect in favor of lazyloading plugin
20+
- deprecated "horizontal" effect. separate accordion plugin will be released later
21+
22+
1623
mask
1724
- simple, straighforward, lightweight
1825
- fit called when mask loaded

src/form/form.slider.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,11 @@
9393
with JavaScript we don't want the HTML5 range element
9494
NOTE: input.attr("type", "text") throws exception by the browser
9595
*/
96-
var tmp = $('<input/>').attr("type", "text").addClass(input.attr("className"))
97-
.attr("name", input.attr("name"));
96+
var tmp = $('<input/>')
97+
.attr("type", "text")
98+
.addClass(input.attr("className"))
99+
.attr("name", input.attr("name"))
100+
.attr("disabled", input.attr("disabled"));
98101

99102
input.replaceWith(tmp);
100103
input = tmp;
@@ -262,12 +265,12 @@
262265
self[name] = function(fn) {
263266
return self.bind(name, fn);
264267
};
265-
});
266-
268+
});
267269

268270

269271
// dragging
270-
handle.bind("dragstart", function(e) {
272+
handle.bind("dragstart", function(e) {
273+
271274
if (input.is(":disabled")) { return false; }
272275

273276
e.type = "onBeforeSlide";
@@ -276,8 +279,7 @@
276279
init();
277280

278281
}).bind("drag", function(e) {
279-
if (input.is(":disabled")) { return false; }
280-
282+
if (input.is(":disabled")) { return false; }
281283

282284
seek(conf.vertical ? origo - e.offsetY : e.offsetX - origo, e);
283285

src/form/form.styleable.js

100644100755
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@
102102
a.addClass(conf.disabledClass);
103103
}
104104

105+
input.bind("style", function() {
106+
a.toggleClass(cls, this.checked);
107+
a.toggleClass(conf.disabledClass, this.disabled);
108+
});
109+
105110
}
106111

107112
$.fn.styleable = function(conf) {

src/overlay/overlay.apple.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
// set close button and content over the image
102102
overlay.css("zIndex", opts.zIndex + 1).fadeIn(opts.fadeInSpeed, function() {
103103

104-
if (self.isOpened() && !$(this).index(overlay)) {
104+
if (self.isOpened() && !$(this).index(overlay)) {
105105
onLoad.call();
106106
} else {
107107
overlay.hide();

src/overlay/overlay.js

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,19 @@
7070
var self = this,
7171
$self = $(this),
7272
w = $(window),
73-
closers,
73+
closers,
7474
overlay,
7575
opened,
76-
mask = conf.mask && $.tools.mask.version;
77-
78-
// @deprecated
79-
if (conf.expose && $.tools.mask.version) {
80-
mask = conf.expose;
81-
}
76+
maskConf = $.tools.mask && (conf.mask || conf.expose),
77+
uid = Math.random().toString().substring(10);
8278

79+
8380
// mask configuration
84-
if (mask) {
85-
if (typeof mask == 'string') { mask = {color: mask}; }
86-
mask.closeOnClick = mask.closeOnEsc = false;
87-
}
88-
81+
if (maskConf) {
82+
if (typeof maskConf == 'string') { maskConf = {color: maskConf}; }
83+
maskConf.closeOnClick = maskConf.closeOnEsc = false;
84+
}
85+
8986
// get overlay and triggerr
9087
var jq = conf.target || trigger.attr("rel");
9188
overlay = jq ? $(jq) : null || trigger;
@@ -130,7 +127,7 @@
130127
opened = true;
131128

132129
// possible mask effect
133-
if (mask) { $.mask.load(overlay, mask); }
130+
if (maskConf) { $.mask.load(overlay, maskConf); }
134131

135132
// calculate end position
136133
var top = conf.top;
@@ -166,40 +163,33 @@
166163
$self.trigger(e);
167164
}
168165
});
169-
166+
167+
// mask.click closes overlay
168+
if (maskConf) {
169+
$.mask.getMask().one("click", self.close);
170+
}
171+
170172
// when window is clicked outside overlay, we close
171173
if (conf.closeOnClick) {
172-
$(document).bind("click.overlay", function(e) {
173-
174-
if (!self.isOpened()) { $(this).unbind("click.overlay"); }
175-
176-
// mask.click closes overlay
177-
if (mask) { return $.mask.getMask().one("click", self.close); }
178-
179-
// otherwize we must click outside the overlay
180-
var et = $(e.target);
181-
if (et.parents(overlay).length > 1) { return; }
182-
183-
// close all instances
184-
$.each(instances, function() {
185-
this.close(e);
186-
});
174+
$(document).bind("click." + uid, function(e) {
175+
if (!$(e.target).parents(overlay).length) {
176+
self.close(e);
177+
}
187178
});
188179
}
189-
180+
190181
// keyboard::escape
191-
if (conf.closeOnEsc) {
192-
182+
if (conf.closeOnEsc) {
183+
193184
// one callback is enough if multiple instances are loaded simultaneously
194-
$(document).bind("keydown.overlay", function(e) {
195-
if (e.keyCode == 27) {
196-
$.each(instances, function() {
197-
this.close(e);
198-
});
185+
$(document).bind("keydown." + uid, function(e) {
186+
if (e.keyCode == 27) {
187+
self.close(e);
199188
}
200189
});
201190
}
202191

192+
203193
return self;
204194
},
205195

@@ -220,17 +210,13 @@
220210
$self.trigger(e);
221211
});
222212

223-
// if all instances are closed then we unbind the keyboard / clicking actions
224-
var allClosed = true;
225-
$.each(instances, function() {
226-
if (this.isOpened()) { allClosed = false; }
227-
});
213+
// unbind the keyboard / clicking actions
214+
$(document).unbind("click." + uid).unbind("keydown." + uid);
228215

229-
if (allClosed) {
230-
$(document).unbind("click.overlay").unbind("keydown.overlay");
231-
$.mask.close();
232-
}
233-
216+
if (maskConf) {
217+
$.mask.close();
218+
}
219+
234220
return self;
235221
},
236222

src/scrollable/scrollable.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
$.tools = $.tools || {};
1818

1919
$.tools.scrollable = {
20-
version: '@VERSION',
2120

2221
conf: {
2322

@@ -50,8 +49,8 @@
5049

5150
// 1.2
5251
mousewheel: false,
53-
wheelSpeed: 0
54-
52+
wheelSpeed: 0,
53+
lazyload: false
5554

5655
// CALLBACKS: onBeforeSeek, onSeek, onReload
5756
}
@@ -67,9 +66,8 @@
6766
horizontal = !conf.vertical,
6867
wrap = root.children(),
6968
index = 0,
70-
forward;
71-
72-
69+
forward;
70+
7371
if (!current) { current = self; }
7472

7573
// bind all callbacks from configuration
@@ -262,6 +260,10 @@
262260
return self;
263261
},
264262

263+
getLoader: function() {
264+
return loader;
265+
},
266+
265267
click: function(i) {
266268

267269
var item = self.getItems().eq(i),
@@ -421,10 +423,32 @@
421423
});
422424
}
423425

424-
});
425-
426-
self.reload();
426+
});
427+
428+
// lazyload support. all logic is here.
429+
var lconf = $.tools.lazyload && conf.lazyload, loader, lazies;
430+
431+
if (lconf) {
432+
lazies = lconf === true ? self.getItems() : root.find(lconf.select || lconf);
433+
434+
if (typeof lconf != 'object') { lconf = {}; }
435+
436+
$.extend(lconf, { growParent: root, api: true}, lconf);
437+
loader = lazies.lazyload(lconf);
438+
439+
function load(ev, i) {
440+
var els = self.getItems().slice(i, i + conf.size);
441+
442+
els.each(function() {
443+
els = els.add($(this).find(":unloaded"));
444+
});
445+
loader.load(els);
446+
}
447+
self.onBeforeSeek(load);
448+
load(null, 0);
449+
}
427450

451+
self.reload();
428452
}
429453

430454

0 commit comments

Comments
 (0)