Created
December 1, 2014 05:48
-
-
Save victorvhpg/626c806e00c8f3074018 to your computer and use it in GitHub Desktop.
jQueryAMD
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(window) { | |
"use strict"; | |
//criamos uma funcao auto executavel que recebe uma function "fnCriaPlugin" | |
//que eh a implementacao do nosso plugin | |
(function(fnCriaPlugin) { | |
//agora eh so verificar se possui AMD ou nao | |
if (typeof define === "function" && define.amd) { | |
// COM suporte AMD | |
//entao registra o plugin com a depedencia jquery | |
define(["jquery"], fnCriaPlugin); | |
} else { | |
// SEM suporte AMD | |
fnCriaPlugin(window.jQuery); | |
} | |
})(function($) { | |
//implementacao do plugin... | |
var exemploPlugin = { | |
//... | |
init: function() { | |
//... | |
console.log("oi"); | |
} | |
}; | |
$.fn.exemploPlugin = function() { | |
//...... | |
}; | |
return $.fn.exemploPlugin; | |
}); | |
})(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment