forked from josex2r/jQuery-SlotMachine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.js
41 lines (37 loc) · 920 Bytes
/
jquery.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
41
/* eslint-disable no-undef */
const name = 'slotMachine';
class JQuerySlotMachine extends SlotMachine {
destroy () {
super.destroy();
$.data(this.element[0], 'plugin_' + name, null);
}
}
/*
* Create new plugin instance if needed and return it
*/
function _getInstance (element, options) {
let machine;
if (!$.data(element[0], 'plugin_' + name)) {
machine = new JQuerySlotMachine(element[0], options);
$.data(element[0], 'plugin_' + name, machine);
} else {
machine = $.data(element[0], 'plugin_' + name);
}
return machine;
}
/*
* Chainable instance
*/
$.fn[name] = function initPlugin (options) {
let instances;
if (this.length === 1) {
instances = _getInstance(this, options);
} else {
const $els = this;
instances = $.map($els, (el, index) => {
const $el = $els.eq(index);
return _getInstance($el[0], options);
});
}
return instances;
};