PageSourceSearch

https://imeureka.com/global/js/Plugin.js

js imeureka.com collected 2026-10-08 21:07:18 UTC 4,643 bytes, 173 lines download raw bytes

1(function (global, factory) {
2  if (typeof define === "function" && define.amd) {
3    define('/Plugin', ['exports', 'jquery'], factory);
4  } else if (typeof exports !== "undefined") {
5    factory(exports, require('jquery'));
6  } else {
7    var mod = {
8      exports: {}
9    };
10    factory(mod.exports, global.jQuery);
11    global.Plugin = mod.exports;
12  }
13})(this, function (exports, _jquery) {
14  'use strict';
15
16  Object.defineProperty(exports, "__esModule", {
17    value: true
18  });
19  exports.pluginFactory = exports.getDefaults = exports.getPlugin = exports.getPluginAPI = exports.Plugin = undefined;
20
21  var _jquery2 = babelHelpers.interopRequireDefault(_jquery);
22
23  var plugins = {};
24  var apis = {};
25
26  var Plugin = function () {
27    function Plugin($el) {
28      var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
29      babelHelpers.classCallCheck(this, Plugin);
30
31      this.name = this.getName();
32      this.$el = $el;
33      this.options = options;
34      this.isRendered = false;
35    }
36
37    babelHelpers.createClass(Plugin, [{
38      key: 'getName',
39      value: function getName() {
40        return 'plugin';
41      }
42    }, {
43      key: 'render',
44      value: function render() {
45        if (_jquery2.default.fn[this.name]) {
46          this.$el[this.name](this.options);
47        } else {
48          return false;
49        }
50      }
51    }, {
52      key: 'initialize',
53      value: function initialize() {
54        if (this.isRendered) {
55          return false;
56        }
57        this.render();
58        this.isRendered = true;
59      }
60    }], [{
61      key: 'getDefaults',
62      value: function getDefaults() {
63        return {};
64      }
65    }, {
66      key: 'register',
67      value: function register(name, obj) {
68        if (typeof obj === 'undefined') {
69          return;
70        }
71
72        plugins[name] = obj;
73
74        if (typeof obj.api !== 'undefined') {
75          Plugin.registerApi(name, obj);
76        }
77      }
78    }, {
79      key: 'registerApi',
80      value: function registerApi(name, obj) {
81        var api = obj.api();
82
83        if (typeof api === 'string') {
84          var _api = obj.api().split('|');
85          var event = _api[0] + ('.plugin.' + name);
86          var func = _api[1] || 'render';
87
88          var callback = function callback(e) {
89            var $el = (0, _jquery2.default)(this);
90            var plugin = $el.data('pluginInstance');
91
92            if (!plugin) {
93              plugin = new obj($el, _jquery2.default.extend(true, {}, getDefaults(name), $el.data()));
94              plugin.initialize();
95              $el.data('pluginInstance', plugin);
96            }
97
98            plugin[func](e);
99          };
100
101          apis[name] = function (selector, context) {
102            if (context) {
103              (0, _jquery2.default)(context).off(event);
104              (0, _jquery2.default)(context).on(event, selector, callback);
105            } else {
106              (0, _jquery2.default)(selector).on(event, callback);
107            }
108          };
109        } else if (typeof api === 'function') {
110          apis[name] = api;
111        }
112      }
113    }]);
114    return Plugin;
115  }();
116
117  function getPluginAPI(name) {
118    if (typeof name === 'undefined') {
119      return apis;
120    } else {
121      return apis[name];
122    }
123  }
124
125  function getPlugin(name) {
126    if (typeof plugins[name] !== 'undefined') {
127      return plugins[name];
128    } else {
129      console.warn('Plugin:' + name + ' has no warpped class.');
130      return false;
131    }
132  }
133
134  function getDefaults(name) {
135    var PluginClass = getPlugin(name);
136
137    if (PluginClass) {
138      return PluginClass.getDefaults();
139    } else {
140      return {};
141    }
142  }
143
144  function pluginFactory(name, $el) {
145    var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
146
147    var PluginClass = getPlugin(name);
148
149    if (PluginClass && typeof PluginClass.api === 'undefined') {
150      return new PluginClass($el, _jquery2.default.extend(true, {}, getDefaults(name), options));
151    } else if (_jquery2.default.fn[name]) {
152      var plugin = new Plugin($el, options);
153      plugin.getName = function () {
154        return name;
155      };
156      plugin.name = name;
157      return plugin;
158    } else if (typeof PluginClass.api !== 'undefined') {
159      // console.log('Plugin:' + name + ' use api render.');
160      return false;
161    } else {
162      console.warn('Plugin:' + name + ' script is not loaded.');
163      return false;
164    }
165  }
166
167  exports.Plugin = Plugin;
168  exports.getPluginAPI = getPluginAPI;
169  exports.getPlugin = getPlugin;
170  exports.getDefaults = getDefaults;
171  exports.pluginFactory = pluginFactory;
172  exports.default = Plugin;
173});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.