Created
May 1, 2013 18:44
-
-
Save haohello/5497340 to your computer and use it in GitHub Desktop.
Extensible UMD Plugins
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 ( name, definition ){ | |
var theModule = definition(), | |
// this is considered "safe": | |
hasDefine = typeof define === 'function' && define.amd, | |
// hasDefine = typeof define === 'function', | |
hasExports = typeof module !== 'undefined' && module.exports; | |
if ( hasDefine ){ // AMD Module | |
define(theModule); | |
} else if ( hasExports ) { // Node.js Module | |
module.exports = theModule; | |
} else { // Assign to common namespaces or simply the global object (window) | |
(this.jQuery || this.ender || this.$ || this)[name] = theModule; | |
} | |
})( 'core', function () { | |
var module = this; | |
module.plugins = []; | |
module.highlightColor = "yellow"; | |
module.errorColor = "red"; | |
// define the core module here and return the public API | |
// this is the highlight method used by the core highlightAll() | |
// method and all of the plugins highlighting elements different | |
// colors | |
module.highlight = function(el,strColor){ | |
// this module uses jQuery, however plain old JavaScript | |
// or say, Dojo could be just as easily used. | |
if(this.jQuery){ | |
jQuery(el).css('background', strColor); | |
} | |
} | |
return { | |
highlightAll:function(){ | |
module.highlight('div', module.highlightColor); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment