-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery_wrapper.js
40 lines (40 loc) · 1.28 KB
/
jquery_wrapper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
;(function ( $, window, undefined ) {
const pluginName = "Slider";
const defaults = {
ranges: [],
min: 0,
max: 100,
step: 1,
overlappingRanges: false,
minRange: 1,
minGap: 0,
minNoRanges: 0,
maxNoRanges: 100,
mergeRanges: true,
create: () => {},
remove: () => {},
merge: () => {},
slide: () => {}
};
$.fn[pluginName] = function(options = null, args = []){
if (options === null) {
// Return only one (anti pattern, TODO: change later)
return $(this).data("plugin_" + pluginName);
} else if(typeof options === "object"){
// Initialize multiples
const mergedOptions = $.extend({}, defaults, options);
this.each(function(){
mergedOptions.container = $(this);
const obj = new Slider(mergedOptions);
$(this).data("plugin_" + pluginName, obj);
});
}else if(typeof options === "string"){
// function
let returnArr = [];
this.each(function(){
returnArr.push($(this).data("plugin_" + pluginName)[options](...args));
});
return returnArr;
}
}
}(jQuery, window));