UNPKG

jquery-my-plugin

Version:

Made with create-jquery-plugin

95 lines (89 loc) 4.25 kB
"use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } /*! * jquery-my-plugin 1.0.0 * Made with create-jquery-plugin * * Created by ashraf <ashraf.alqadi@atlascrisis.ae> * * @license MIT */ (function (factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. define(['jquery'], factory); } else if ((typeof module === "undefined" ? "undefined" : _typeof(module)) === 'object' && module.exports) { // Node/CommonJS module.exports = function (root, jQuery) { if (jQuery === undefined) { // require('jQuery') returns a factory that requires window to // build a jQuery instance, we normalize how we use modules // that require this pattern but the window provided is a noop // if it's defined (how jquery works) if (typeof window !== 'undefined') { jQuery = require('jquery'); } else { jQuery = require('jquery')(root); } } factory(jQuery); return jQuery; }; } else { // Browser globals factory(jQuery); } })(function ($) { "use strict"; // Default Options var defaults = { // TODO: ADD YOUR DEFAULT OPTIONS HERE myStyle: 'my-style1' }; var MyPlugin = /*#__PURE__*/function () { function MyPlugin(element, options) { _classCallCheck(this, MyPlugin); // Merge user settings with default this.options = $.extend(true, {}, defaults, options); // Main container element this.main = $(element); // Initial load this._init(); } // Initial Method _createClass(MyPlugin, [{ key: "_init", value: function _init() { // Plugin init and logic this.main.addClass(this.options.myStyle).html(this.options.myStyle); } // TODO: YOU CAN ADD MORE FUNCTIONS FOR YOUR PLUGIN HERE }]); return MyPlugin; }(); // Wrapper for the plugin $.fn.myPlugin = function (options) { var pluginName = "myPlugin"; if (options === undefined || _typeof(options) === 'object') { return this.each(function () { if (!$.data(this, pluginName)) { $.data(this, pluginName, new MyPlugin(this, options)); } }); } else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') { var instance = $.data(this[0], pluginName); if (options === 'destroy') { $.data(this, pluginName, null); } if (instance instanceof MyPlugin && typeof instance[options] === 'function') { return instance[options].apply(instance, Array.prototype.slice.call(arguments, 1)); } else { return this; } } }; });