Last active
January 21, 2017 22:04
-
-
Save jinkrish/a004707d6d1def4edcf76b6a053bf4e1 to your computer and use it in GitHub Desktop.
jQuery plugin
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
<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> |
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($){ | |
$.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