Last active
August 29, 2015 14:07
-
-
Save ethyde/072d2aa5ec7695e3514f to your computer and use it in GitHub Desktop.
jQuery namespace plugin, with callbacks
Inspiration : 1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript 2. http://stefangabos.ro/jquery/jquery-plugin-boilerplate-revisited/ 3. https://github.com/jquery-boilerplate/jquery-patterns/blob/master/patterns/jquery.namespace.plugin-boilerplate.js 4. ht…
This file contains 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( window, document, $, undefined ) { | |
'use strict'; | |
var DEMO = DEMO || {}; | |
DEMO.defaultOptions = { | |
newFontSize : '20px', | |
onSetup : null, | |
onAfterAnimation: null | |
}; | |
DEMO.init = function(element, options){ | |
var base = this; | |
base.$element = $( element ); | |
base.element = element; | |
base.options = $.extend({}, DEMO.defaultOptions, options ); | |
DEMO.animation(base); | |
if ( $.isFunction( base.options.onSetup ) ) { | |
base.options.onSetup.call( base ); | |
} | |
}; | |
DEMO.animation = function( base ){ | |
base.$element.animate({ | |
fontSize :base.options.newFontSize | |
}, { | |
complete: base.options.onAfterAnimation | |
} | |
); | |
}; | |
$.fn.patternPlugin = function( options ) { | |
// use each if more than one element in pages | |
// return this.each(function () { | |
// new DEMO.init( this, options ); | |
// }); | |
return new DEMO.init( this, options ); | |
}; | |
})( window, document, jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment