Forked from EmmanuelBeziat/javascript-plugin-boilerplate.js
Created
February 9, 2018 12:12
-
-
Save malkafly/4c22083308add71d1c10621fe69e127c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* | |
* Version : | |
* Emmanuel B. (www.emmanuelbeziat.com) | |
* https://github.com/EmmanuelBeziat/ | |
**/ | |
(function (root, factory) { | |
if (typeof define === 'function' && define.amd) { | |
// AMD. Register as an anonymous module. | |
define([], factory); | |
} else if (typeof module === 'object' && module.exports) { | |
// Node. Does not work with strict CommonJS, but | |
// only CommonJS-like environments that support module.exports, | |
// like Node. | |
module.exports = factory(); | |
} else { | |
// Browser globals (root is window) | |
root.MyPlugin = factory(); | |
} | |
}(this, function () { | |
var MyPlugin = function (el, options){ | |
'use strict'; | |
var self = Object.create(MyPlugin.prototype); | |
/** | |
* Default settings | |
*/ | |
self.options = { | |
myOption: '', | |
callbackFunction: null | |
}; | |
/** | |
* User defined options | |
*/ | |
if (options) { | |
Object.keys(options).forEach(function (key){ | |
self.options[key] = options[key]; | |
}); | |
} | |
/** | |
* By default, search for an item with '' class | |
*/ | |
if (!el) { | |
self.form = document.querySelector('.class'); | |
} | |
if (el && 'string' === typeof el) { | |
self.form = document.querySelector(el); | |
} | |
else if (el && 'object' === typeof el) { | |
self.form = el; | |
} | |
else { | |
throw new Error('[MyPlugin] Unable to get a valid object'); | |
} | |
var init = function () { | |
build.call(this); | |
}; | |
/** | |
* | |
* Allow callback | |
*/ | |
function sampleFunction() { | |
// callback | |
if ('function' === typeof self.options.callbackFunction) { | |
self.options.callbackFunction(); | |
} | |
} | |
/** | |
* Main build function | |
* 1. | |
* 2. | |
*/ | |
function build() { | |
} | |
init(); | |
return self; | |
}; | |
return MyPlugin; | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment