Skip to content

Commit c4c6327

Browse files
author
Tero Piirainen
committed
updated event model (again). more suitable for "normal" jQuery users. will be documented later.
1 parent 18f1a82 commit c4c6327

31 files changed

+407
-478
lines changed

release-notes/version-1.2.0.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ Fundamental changes
1212

1313
all tools
1414
- support for lazyloading
15-
15+
- new event model
16+
- tabs(number) support is removed
17+
- api: property is deprecated. use data("tabs") instead --> was a bit forced to do this
18+
- tabs() is deprecated. use data("tabs") instead
19+
- jQuery bind, unbind and one methods can be used (with namespacing + multiple instances at once)
20+
- new versioning scheme
21+
- new global configuration structure
22+
23+
1624
tabs
1725
- history as configuration option
1826
- lazyload flag
@@ -37,7 +45,9 @@ mask
3745
overlay
3846
- removed deprecated getContent method
3947
- removed the gallery plugin
48+
- onStart event is now deprecated. use onBeforeLoad instead
4049

41-
50+
scrollable
51+
- onStart is deprecated
4252

4353

src/1.3.0/form/form.upload.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
*/
1313
(function() {
1414

15-
$.tools = $.tools || {};
15+
$.tools = $.tools || {version: '@VERSION'};
1616

1717
var tool = $.tools.upload = {
1818

19-
version: '@VERSION',
20-
2119
conf: {
2220
pagepath: '/setup/upload/',
2321
buttonText: 'Select file',

src/form/form.datepicker.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@
1818
*/
1919
(function($) {
2020

21-
$.tools = $.tools || {};
22-
$.tools.form = $.tools.form || {};
21+
$.tools = $.tools || {version: '@VERSION'};
2322

24-
var instances = [], tool = $.tools.form.datepicker = {
25-
26-
version: '@VERSION',
23+
var instances = [], tool = $.tools.datepicker = {
2724

2825
conf: {
2926
format: 'mm/dd/yy',
@@ -143,8 +140,7 @@
143140
function Datepicker(input, conf) {
144141

145142
// variables
146-
var self = this,
147-
$self = $(this).add(input),
143+
var self = this,
148144
css = conf.css,
149145
labels = LABELS[conf.lang],
150146
root = $("#" + css.root),
@@ -165,6 +161,8 @@
165161
input.replaceWith(tmp);
166162
input = tmp;
167163

164+
var fire = input.add(this);
165+
168166
// default value
169167
if (value) {
170168
input.data("date", value);
@@ -224,15 +222,15 @@
224222

225223
// onBeforePick
226224
e.type = "onBeforePick";
227-
$self.trigger(e, [date]);
225+
fire.trigger(e, [date]);
228226
if (e.isDefaultPrevented()) { return; }
229227

230228
// formatting
231229
input.val(format(date, conf.format, conf.lang));
232230

233231
// onPick
234232
e.type = "onPick";
235-
$self.trigger(e, [date]);
233+
fire.trigger(e, [date]);
236234

237235
// store date
238236
input.data("date", date);
@@ -499,12 +497,12 @@
499497
},
500498

501499
bind: function(name, fn) {
502-
$self.bind(name, fn);
500+
$(self).bind(name, fn);
503501
return self;
504502
},
505503

506504
unbind: function(name) {
507-
$self.unbind(name);
505+
$(self).unbind(name);
508506
return self;
509507
},
510508

@@ -534,28 +532,26 @@
534532
return self.bind(name, fn);
535533
};
536534
});
537-
}
538-
539-
535+
}
540536

541537

542538
$.fn.datepicker = function(conf) {
543539

544540
// return existing instance
545-
var el = this.eq(typeof conf == 'number' ? conf : 0).data("datepicker");
541+
var el = this.data("datepicker"), els;
546542
if (el) { return el; }
547543

548544
// configuration
549-
var globals = $.extend({}, tool.conf);
550-
conf = $.extend(globals, conf);
545+
conf = $.extend({}, tool.conf, conf);
551546

552547
this.each(function() {
553548
el = new Datepicker($(this), conf);
554549
instances.push(el);
555-
$(this).add(el.getInput()).data("datepicker", el);
550+
var input = el.getInput().data("datepicker", el);
551+
els = els ? els.add(input) : input;
556552
});
557-
558-
return conf.api ? el: this;
553+
554+
return conf.api ? el : els;
559555
};
560556

561557

src/form/form.slider.js

Lines changed: 54 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121

2222
(function($) {
2323

24-
$.tools = $.tools || {};
24+
$.tools = $.tools || {version: '@VERSION'};
2525

2626
var current, tool = $.tools.slider = {
27-
version: '@VERSION',
2827

2928
conf: {
3029
min: 0,
@@ -59,63 +58,47 @@
5958
}
6059

6160

62-
function Slider(el, conf) {
63-
64-
var root, input;
65-
66-
// construct slider from the range input
67-
if (el.is("input")) {
68-
69-
input = el;
70-
root = $("<div><div/><a/></div>");
71-
72-
root.addClass(conf.sliderClass).find("a").addClass(conf.handleClass);
73-
74-
// progress is not required
75-
if (conf.progressClass) {
76-
root.find("div").addClass(conf.progressClass);
77-
}
78-
79-
// get (HTML5) attributes
80-
$.each("min,max,size,step,value".split(","), function(i, key) {
81-
var val = input.attr(key);
82-
conf[key] = parseFloat(val, 10);
83-
});
84-
85-
input.before(root);
86-
87-
if (conf.hideInput) {
88-
input.hide();
89-
90-
} else {
91-
92-
/*
93-
with JavaScript we don't want the HTML5 range element
94-
NOTE: input.attr("type", "text") throws exception by the browser
95-
*/
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"));
101-
102-
input.replaceWith(tmp);
103-
input = tmp;
104-
}
105-
}
61+
function Slider(input, conf) {
10662

10763
// private variables
108-
var self = this,
109-
$self = $(this),
110-
progress = root.find("." + conf.progressClass),
111-
handle = root.find("." + conf.handleClass),
64+
var self = this,
65+
root = $("<div><div/><a/></div>"),
11266
range = conf.max - conf.min,
11367
value,
11468
callbacks,
11569
origo,
11670
len,
117-
pos;
71+
pos,
72+
progress,
73+
handle;
74+
11875

76+
input.before(root);
77+
handle = root.addClass(conf.sliderClass).find("a").addClass(conf.handleClass);
78+
progress = root.find("div").addClass(conf.progressClass);
79+
80+
// get (HTML5) attributes
81+
$.each("min,max,size,step,value".split(","), function(i, key) {
82+
var val = input.attr(key);
83+
conf[key] = parseFloat(val, 10);
84+
});
85+
86+
/*
87+
with JavaScript we don't want the HTML5 range element
88+
NOTE: input.attr("type", "text") throws exception by the browser
89+
*/
90+
var tmp = $('<input/>')
91+
.attr("type", "text")
92+
.addClass(input.attr("className"))
93+
.attr("name", input.attr("name"))
94+
.attr("disabled", input.attr("disabled"));
95+
96+
input.replaceWith(tmp);
97+
input = tmp;
98+
99+
if (conf.hideInput) { input.hide(); }
100+
101+
var fire = input.add(this);
119102

120103
function init() {
121104
var o = handle.offset();
@@ -159,7 +142,7 @@
159142
value = v;
160143
e = e || $.Event();
161144
e.type = "onSlide";
162-
$(self).trigger(e, [v]);
145+
fire.trigger(e, [v]);
163146
}
164147

165148
// move handle & resize progress
@@ -242,12 +225,12 @@
242225

243226
// callback functions
244227
bind: function(name, fn) {
245-
$self.bind(name, fn);
228+
$(self).bind(name, fn);
246229
return self;
247230
},
248231

249232
unbind: function(name) {
250-
$self.unbind(name);
233+
$(self).unbind(name);
251234
return self;
252235
}
253236

@@ -271,10 +254,10 @@
271254
// dragging
272255
handle.bind("dragstart", function(e) {
273256

274-
if (input.is(":disabled")) { return false; }
275-
257+
if (input.is(":disabled")) { return false; }
276258
e.type = "onBeforeSlide";
277-
$self.trigger(e);
259+
260+
fire.trigger(e);
278261
if (e.isDefaultPrevented()) { return false; }
279262
init();
280263

@@ -285,7 +268,7 @@
285268

286269
}).bind("dragend", function(e) {
287270
e.type = "onSlideEnd";
288-
$self.trigger(e);
271+
fire.trigger(e);
289272

290273
}).click(function(e) {
291274
return e.preventDefault();
@@ -297,7 +280,7 @@
297280
if (input.is(":disabled")) { return false; }
298281

299282
e.type = "onBeforeSlide";
300-
$self.trigger(e);
283+
fire.trigger(e);
301284
if (e.isDefaultPrevented()) { return false; }
302285
init();
303286

@@ -306,20 +289,14 @@
306289
seek(conf.vertical ? origo - e.pageY + fix : e.pageX - origo - fix, e);
307290

308291
e.type = "onSlideEnd";
309-
$self.trigger(e);
292+
fire.trigger(e);
310293
});
294+
295+
self.onSlide(function(e, val) {
296+
input.val(val);
297+
});
311298

312-
313-
if (input) {
314-
self.onSlide(function(e, val) {
315-
input.val(val);
316-
});
317-
}
318-
319-
if (conf.value) {
320-
self.setValue(conf.value || conf.min);
321-
}
322-
299+
self.setValue(conf.value || conf.min);
323300
}
324301

325302
if (tool.conf.keyboard) {
@@ -366,24 +343,23 @@
366343
$.fn.slider = function(conf) {
367344

368345
// return existing instance
369-
var el = this.eq(typeof conf == 'number' ? conf : 0).data("slider");
346+
var el = this.data("slider"), els;
370347
if (el) { return el; }
371348

372349
if (typeof conf == 'number') {
373350
conf = {max: conf};
374351
}
375352

376353
// extend configuration with globals
377-
var globals = $.extend({}, tool.conf);
378-
conf = $.extend(globals, conf);
354+
conf = $.extend({}, tool.conf, conf);
379355

380356
this.each(function() {
381-
var root = $(this);
382-
el = new Slider(root, $.extend({}, conf));
383-
root.add(el.getInput()).data("slider", el);
357+
el = new Slider($(this), $.extend({}, conf));
358+
var input = el.getInput().data("slider", el);
359+
els = els ? els.add(input) : input;
384360
});
385361

386-
return conf.api ? el: this;
362+
return conf.api ? el : els;
387363
};
388364

389365

0 commit comments

Comments
 (0)