Skip to content

Instantly share code, notes, and snippets.

@7iomka
Forked from jinkrish/index.html
Created January 21, 2017 22:04
Show Gist options
  • Save 7iomka/f89485f80b0621a6afd02889c07b8cee to your computer and use it in GitHub Desktop.
Save 7iomka/f89485f80b0621a6afd02889c07b8cee to your computer and use it in GitHub Desktop.
jQuery plugin
<html>
<head>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
</head>
<body>
<div id="mydiv" ></div>
<script src="jquery.myplugin.js" ></script>
<script>
$("#mydiv").myplugin({
debug: true,
var1: 'myval'
});
</script>
</body>
</html>
(function($){
$.fn.myplugin = function(options){
myp = $.fn.myplugin;
myp.default.selector = $(this);
if(typeof options !== 'undefined'){
myp.default = $.default(myp.default,options);
}
myp.func1();
myp.func2();
};
var myp = $.fn.myplugin;
myp.func1 = function(){
myp.debug('func1');
};
myp.func2 = function(){
myp.debug('func2');
};
myp.debug = function(str){
if(typeof str != 'undefined' && myp.default.debug === true){
console.log(str);
}
};
myp.default = {
debug: false,
selector: null,
var1: ''
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment