Skip to content

Instantly share code, notes, and snippets.

@bantya
Created May 2, 2017 09:56
Show Gist options
  • Save bantya/19b838995e047f4a07e268f7eeb3cc0b to your computer and use it in GitHub Desktop.
Save bantya/19b838995e047f4a07e268f7eeb3cc0b to your computer and use it in GitHub Desktop.
JS: Basic pure js plugin structure
(function () {
// Define the constructor
this.Modal = function () {
// Create global element references
this.closeButton = null;
this.modal = null;
this.overlay = null;
// Define options defaults
var defaults = {
className: 'fade-and-drop',
closeButton: true,
content: '',
maxWidth: 600,
minWidth: 280,
overlay: true
};
// Create options by extending defaults with the passed in arguments
if (arguments[0] && typeof arguments[0] === "object") {
this.options = extendDefaults(defaults, arguments[0]);
}
// Public methods
Modal.prototype.open = function() {
// Open code
};
// Private methods
// Utility method to extend defaults with user options
function extendDefaults (defaults, options) {
var option;
for (option in options) {
if (options.hasOwnProperty(option)) {
defaults[option] = options[option];
}
}
return defaults;
}
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment