Created
May 2, 2017 09:56
-
-
Save bantya/19b838995e047f4a07e268f7eeb3cc0b to your computer and use it in GitHub Desktop.
JS: Basic pure js plugin structure
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
(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