PluginProbe
Booking Calendar / 11.8.2
Booking Calendar v11.8.2
11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 10.11.3 All 202 releases
booking / vendors / sortablejs / src / PluginManager.js

PluginManager.js in Booking Calendar 11.8.2, at vendors/sortablejs/src/PluginManager.js

95 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 let plugins = [];
2
3 const defaults = {
4 initializeByDefault: true
5 };
6
7 export default {
8 mount(plugin) {
9 // Set default static properties
10 for (let option in defaults) {
11 if (defaults.hasOwnProperty(option) && !(option in plugin)) {
12 plugin[option] = defaults[option];
13 }
14 }
15
16 plugins.forEach(p => {
17 if (p.pluginName === plugin.pluginName) {
18 throw (`Sortable: Cannot mount plugin ${ plugin.pluginName } more than once`);
19 }
20 });
21
22 plugins.push(plugin);
23 },
24 pluginEvent(eventName, sortable, evt) {
25 this.eventCanceled = false;
26 evt.cancel = () => {
27 this.eventCanceled = true;
28 };
29 const eventNameGlobal = eventName + 'Global';
30 plugins.forEach(plugin => {
31 if (!sortable[plugin.pluginName]) return;
32 // Fire global events if it exists in this sortable
33 if (
34 sortable[plugin.pluginName][eventNameGlobal]
35 ) {
36 sortable[plugin.pluginName][eventNameGlobal]({ sortable, ...evt });
37 }
38
39 // Only fire plugin event if plugin is enabled in this sortable,
40 // and plugin has event defined
41 if (
42 sortable.options[plugin.pluginName] &&
43 sortable[plugin.pluginName][eventName]
44 ) {
45 sortable[plugin.pluginName][eventName]({ sortable, ...evt });
46 }
47 });
48 },
49 initializePlugins(sortable, el, defaults, options) {
50 plugins.forEach(plugin => {
51 const pluginName = plugin.pluginName;
52 if (!sortable.options[pluginName] && !plugin.initializeByDefault) return;
53
54 let initialized = new plugin(sortable, el, sortable.options);
55 initialized.sortable = sortable;
56 initialized.options = sortable.options;
57 sortable[pluginName] = initialized;
58
59 // Add default options from plugin
60 Object.assign(defaults, initialized.defaults);
61 });
62
63 for (let option in sortable.options) {
64 if (!sortable.options.hasOwnProperty(option)) continue;
65 let modified = this.modifyOption(sortable, option, sortable.options[option]);
66 if (typeof(modified) !== 'undefined') {
67 sortable.options[option] = modified;
68 }
69 }
70 },
71 getEventProperties(name, sortable) {
72 let eventProperties = {};
73 plugins.forEach(plugin => {
74 if (typeof(plugin.eventProperties) !== 'function') return;
75 Object.assign(eventProperties, plugin.eventProperties.call(sortable[plugin.pluginName], name));
76 });
77
78 return eventProperties;
79 },
80 modifyOption(sortable, name, value) {
81 let modifiedValue;
82 plugins.forEach(plugin => {
83 // Plugin must exist on the Sortable
84 if (!sortable[plugin.pluginName]) return;
85
86 // If static option listener exists for this option, call in the context of the Sortable's instance of this plugin
87 if (plugin.optionListeners && typeof(plugin.optionListeners[name]) === 'function') {
88 modifiedValue = plugin.optionListeners[name].call(sortable[plugin.pluginName], value);
89 }
90 });
91
92 return modifiedValue;
93 }
94 };
95