Skip to content

Instantly share code, notes, and snippets.

@victorvhpg
Created December 1, 2014 05:48
Show Gist options
  • Save victorvhpg/626c806e00c8f3074018 to your computer and use it in GitHub Desktop.
Save victorvhpg/626c806e00c8f3074018 to your computer and use it in GitHub Desktop.
jQueryAMD
(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