Skip to content

Commit 4f3f3f1

Browse files
Duc Tri Ledefault_git_name
authored andcommitted
Change bind/unbind to on/off and wrapping some selectors around quotes
1 parent 786d7fb commit 4f3f3f1

File tree

13 files changed

+76
-80
lines changed

13 files changed

+76
-80
lines changed

src/dateinput/dateinput.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@
332332
ev.type = "onShow";
333333
fire.trigger(ev);
334334

335-
$(document).bind("keydown.d", function(e) {
335+
$(document).on("keydown.d", function(e) {
336336

337337
if (e.ctrlKey) { return true; }
338338
var key = e.keyCode;
@@ -399,7 +399,7 @@
399399

400400

401401
// click outside dateinput
402-
$(document).bind("click.d", function(e) {
402+
$(document).on("click.d", function(e) {
403403
var el = e.target;
404404

405405
if (!$(el).parents("#" + css.root).length && el != input[0] && (!trigger || el != trigger[0])) {
@@ -435,24 +435,24 @@
435435
opened = true;
436436

437437
// month selector
438-
monthSelector.unbind("change").change(function() {
438+
monthSelector.off("change").change(function() {
439439
self.setValue(integer(yearSelector.val()), integer($(this).val()));
440440
});
441441

442442
// year selector
443-
yearSelector.unbind("change").change(function() {
443+
yearSelector.off("change").change(function() {
444444
self.setValue(integer($(this).val()), integer(monthSelector.val()));
445445
});
446446

447447
// prev / next month
448-
pm = root.find("#" + css.prev).unbind("click").click(function(e) {
448+
pm = root.find("#" + css.prev).off("click").click(function(e) {
449449
if (!pm.hasClass(css.disabled)) {
450450
self.addMonth(-1);
451451
}
452452
return false;
453453
});
454454

455-
nm = root.find("#" + css.next).unbind("click").click(function(e) {
455+
nm = root.find("#" + css.next).off("click").click(function(e) {
456456
if (!nm.hasClass(css.disabled)) {
457457
self.addMonth();
458458
}
@@ -669,7 +669,7 @@
669669
},
670670

671671
destroy: function() {
672-
input.add(document).unbind("click.d").unbind("keydown.d");
672+
input.add(document).off("click.d keydown.d");
673673
root.add(trigger).remove();
674674
input.removeData("dateinput").removeClass(css.input);
675675
if (original) { input.replaceWith(original); }
@@ -687,7 +687,7 @@
687687
// cancelled ?
688688
if (e.isDefaultPrevented()) { return; }
689689

690-
$(document).unbind("click.d").unbind("keydown.d");
690+
$(document).off("click.d keydown.d");
691691

692692
// do the hide
693693
root.hide();
@@ -728,20 +728,20 @@
728728

729729
// configuration
730730
if ($.isFunction(conf[name])) {
731-
$(self).bind(name, conf[name]);
731+
$(self).on(name, conf[name]);
732732
}
733733

734734
// API methods
735735
self[name] = function(fn) {
736-
if (fn) { $(self).bind(name, fn); }
736+
if (fn) { $(self).on(name, fn); }
737737
return self;
738738
};
739739
});
740740

741741
if (!conf.editable) {
742742

743743
// show dateinput & assign keyboard shortcuts
744-
input.bind("focus.d click.d", self.show).keydown(function(e) {
744+
input.on("focus.d click.d", self.show).keydown(function(e) {
745745

746746
var key = e.keyCode;
747747

src/overlay/overlay.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163

164164
// when window is clicked outside overlay, we close
165165
if (conf.closeOnClick) {
166-
$(document).bind("click." + uid, function(e) {
166+
$(document).on("click." + uid, function(e) {
167167
if (!$(e.target).parents(overlay).length) {
168168
self.close(e);
169169
}
@@ -174,7 +174,7 @@
174174
if (conf.closeOnEsc) {
175175

176176
// one callback is enough if multiple instances are loaded simultaneously
177-
$(document).bind("keydown." + uid, function(e) {
177+
$(document).on("keydown." + uid, function(e) {
178178
if (e.keyCode == 27) {
179179
self.close(e);
180180
}
@@ -203,7 +203,7 @@
203203
});
204204

205205
// unbind the keyboard / clicking actions
206-
$(document).unbind("click." + uid).unbind("keydown." + uid);
206+
$(document).off("click." + uid + " keydown." + uid);
207207

208208
if (maskConf) {
209209
$.mask.close();
@@ -240,12 +240,12 @@
240240

241241
// configuration
242242
if ($.isFunction(conf[name])) {
243-
$(self).bind(name, conf[name]);
243+
$(self).on(name, conf[name]);
244244
}
245245

246246
// API
247247
self[name] = function(fn) {
248-
if (fn) { $(self).bind(name, fn); }
248+
if (fn) { $(self).on(name, fn); }
249249
return self;
250250
};
251251
});

src/rangeinput/rangeinput.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
FULL featured drag and drop. 0.7 kb minified, 0.3 gzipped. done.
4747
Who told d'n'd is rocket science? Usage:
4848
49-
$(".myelement").drag({y: false}).bind("drag", function(event, x, y) {
49+
$(".myelement").drag({y: false}).on("drag", function(event, x, y) {
5050
// do your custom thing
5151
});
5252
@@ -66,7 +66,7 @@
6666

6767
conf = $.extend({x: true, y: true, drag: true}, conf);
6868

69-
doc = doc || $(document).bind("mousedown mouseup", function(e) {
69+
doc = doc || $(document).on("mousedown mouseup", function(e) {
7070

7171
var el = $(e.target);
7272

@@ -78,7 +78,7 @@
7878
y0 = e.pageY - offset.top,
7979
start = true;
8080

81-
doc.bind("mousemove.drag", function(e) {
81+
doc.on("mousemove.drag", function(e) {
8282
var x = e.pageX -x0,
8383
y = e.pageY -y0,
8484
props = {};
@@ -104,7 +104,7 @@
104104
draggable.trigger("dragEnd");
105105
}
106106
} finally {
107-
doc.unbind("mousemove.drag");
107+
doc.off("mousemove.drag");
108108
draggable = null;
109109
}
110110
}
@@ -167,11 +167,8 @@
167167
precision = conf.precision;
168168

169169
if (precision === undefined) {
170-
try {
171-
precision = step.toString().split(".")[1].length;
172-
} catch (err) {
173-
precision = 0;
174-
}
170+
precision = step.toString().split(".");
171+
precision = precision.length === 2 ? precision[1].length : 0;
175172
}
176173

177174
// Replace built-in range input (type attribute cannot be changed)
@@ -330,19 +327,19 @@
330327

331328
// from configuration
332329
if ($.isFunction(conf[name])) {
333-
$(self).bind(name, conf[name]);
330+
$(self).on(name, conf[name]);
334331
}
335332

336333
// API methods
337334
self[name] = function(fn) {
338-
if (fn) { $(self).bind(name, fn); }
335+
if (fn) { $(self).on(name, fn); }
339336
return self;
340337
};
341338
});
342339

343340

344341
// dragging
345-
handle.drag({drag: false}).bind("dragStart", function() {
342+
handle.drag({drag: false}).on("dragStart", function() {
346343

347344
/* do some pre- calculations for seek() function. improves performance */
348345
init();
@@ -351,12 +348,12 @@
351348
fireOnSlide = hasEvent($(self)) || hasEvent(input);
352349

353350

354-
}).bind("drag", function(e, y, x) {
351+
}).on("drag", function(e, y, x) {
355352

356353
if (input.is(":disabled")) { return false; }
357354
slide(e, vertical ? y : x);
358355

359-
}).bind("dragEnd", function(e) {
356+
}).on("dragEnd", function(e) {
360357
if (!e.isDefaultPrevented()) {
361358
e.type = "change";
362359
fire.trigger(e, [value]);

src/scrollable/scrollable.autoscroll.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,13 @@
5959
if (timer) { return; }
6060

6161
stopped = false;
62-
63-
root.bind('onSeek', scroll);
64-
scroll();
62+
root.on('onSeek', scroll);
63+
scroll();
6564
};
6665

6766
api.pause = function() {
6867
timer = clearTimeout(timer); // clear any queued items immediately
69-
root.unbind('onSeek', scroll);
68+
root.off('onSeek', scroll);
7069
};
7170

7271
// resume playing if not stopped

src/scrollable/scrollable.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@
190190

191191
// configuration
192192
if ($.isFunction(conf[name])) {
193-
$(self).bind(name, conf[name]);
193+
$(self).on(name, conf[name]);
194194
}
195195

196196
self[name] = function(fn) {
197-
if (fn) { $(self).bind(name, fn); }
197+
if (fn) { $(self).on(name, fn); }
198198
return self;
199199
};
200200
});
@@ -314,7 +314,7 @@
314314

315315
if (conf.keyboard) {
316316

317-
$(document).bind("keydown.scrollable", function(evt) {
317+
$(document).on("keydown.scrollable", function(evt) {
318318

319319
// skip certain conditions
320320
if (!conf.keyboard || evt.altKey || evt.ctrlKey || evt.metaKey || $(evt.target).is(":input")) {

src/scrollable/scrollable.navigator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
if (hashed) {
6363
history.pushState({i: 0}, '');
6464

65-
$(window).bind("popstate", function(evt) {
65+
$(window).on("popstate", function(evt) {
6666
var s = evt.originalEvent.state;
6767
if (s) { api.seekTo(s.i); }
6868
});

src/tabs/tabs.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
firstRender = !root.data('tabs');
164164

165165
if (typeof i == 'string' && i.replace("#", "")) {
166-
tab = tabs.filter("[href*=" + i.replace("#", "") + "]");
166+
tab = tabs.filter("[href*=\"" + i.replace("#", "") + "\"]");
167167
i = Math.max(tabs.index(tab), 0);
168168
}
169169

@@ -239,8 +239,8 @@
239239
},
240240

241241
destroy: function() {
242-
tabs.unbind(conf.event).removeClass(conf.current);
243-
panes.find("a[href^=#]").unbind("click.T");
242+
tabs.off(conf.event).removeClass(conf.current);
243+
panes.find("a[href^=\"#\"]").off("click.T");
244244
return self;
245245
}
246246

@@ -251,12 +251,12 @@
251251

252252
// configuration
253253
if ($.isFunction(conf[name])) {
254-
$(self).bind(name, conf[name]);
254+
$(self).on(name, conf[name]);
255255
}
256256

257257
// API
258258
self[name] = function(fn) {
259-
if (fn) { $(self).bind(name, fn); }
259+
if (fn) { $(self).on(name, fn); }
260260
return self;
261261
};
262262
});
@@ -269,19 +269,19 @@
269269

270270
// setup click actions for each tab
271271
tabs.each(function(i) {
272-
$(this).bind(conf.event, function(e) {
272+
$(this).on(conf.event, function(e) {
273273
self.click(i, e);
274274
return e.preventDefault();
275275
});
276276
});
277277

278278
// cross tab anchor link
279-
panes.find("a[href^=#]").bind("click.T", function(e) {
279+
panes.find("a[href^=\"#\"]").on("click.T", function(e) {
280280
self.click($(this).attr("href"), e);
281281
});
282282

283283
// open initial tab
284-
if (location.hash && conf.tabs == "a" && root.find("[href=" +location.hash+ "]").length) {
284+
if (location.hash && conf.tabs == "a" && root.find("[href=\"" +location.hash+ "\"]").length) {
285285
self.click(location.hash);
286286

287287
} else {

src/tabs/tabs.slideshow.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
// onPlay
8787
fire.trigger("onPlay");
8888

89-
fire.bind('onClick', next);
89+
fire.on('onClick', next);
9090
next();
9191

9292
return self;
@@ -106,7 +106,7 @@
106106
// onPause
107107
fire.trigger("onPause");
108108

109-
fire.unbind('onClick', next);
109+
fire.off('onClick', next);
110110

111111
return self;
112112
},
@@ -129,12 +129,12 @@
129129

130130
// configuration
131131
if ($.isFunction(conf[name])) {
132-
$(self).bind(name, conf[name]);
132+
$(self).on(name, conf[name]);
133133
}
134134

135135
// API methods
136136
self[name] = function(fn) {
137-
return $(self).bind(name, fn);
137+
return $(self).on(name, fn);
138138
};
139139
});
140140

src/toolbox/toolbox.expose.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116

117117
// esc button
118118
if (conf.closeOnEsc) {
119-
$(document).bind("keydown.mask", function(e) {
119+
$(document).on("keydown.mask", function(e) {
120120
if (e.keyCode == 27) {
121121
$.mask.close(e);
122122
}
@@ -125,13 +125,13 @@
125125

126126
// mask click closes
127127
if (conf.closeOnClick) {
128-
mask.bind("click.mask", function(e) {
128+
mask.on("click.mask", function(e) {
129129
$.mask.close(e);
130130
});
131131
}
132132

133133
// resize mask when window is resized
134-
$(window).bind("resize.mask", function() {
134+
$(window).on("resize.mask", function() {
135135
$.mask.fit();
136136
});
137137

@@ -178,9 +178,9 @@
178178
});
179179

180180
// unbind various event listeners
181-
$(document).unbind("keydown.mask");
182-
mask.unbind("click.mask");
183-
$(window).unbind("resize.mask");
181+
$(document).off("keydown.mask");
182+
mask.off("click.mask");
183+
$(window).off("resize.mask");
184184
}
185185

186186
return this;

0 commit comments

Comments
 (0)