Created
September 5, 2011 11:09
-
-
Save bennyschudel/1194708 to your computer and use it in GitHub Desktop.
jQuery Plugin Skeleton
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
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8" /> | |
<title></title> | |
<link rel="stylesheet" type="text/css" media="screen" href="main.css" /> | |
</head> | |
<body> | |
<div id="main"> | |
<div id="element"></div> | |
</div> | |
<!-- scripts --> | |
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"></script> | |
<script type="text/javascript" src="jquery.plugin.js"></script> | |
<!--[if IE]> | |
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> | |
<![endif]--> | |
<script type="text/javascript"> | |
var plugin; | |
jQuery(document).ready(function() { | |
plugin = new $.pluginName($('#element')); | |
plugin.publicMethod(); | |
}); | |
</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($) { | |
$.pluginName = function(el, options) { | |
var self, | |
init, privateMethod; | |
self = this; | |
self.defaults = { | |
property: 'value', | |
events: { | |
event: function() {} | |
} | |
}; | |
self.settings = {}; | |
// init | |
init = function() { | |
self.settings = $.extend(true, {}, self.defaults, options); | |
self.el = el; | |
}; | |
// public methods | |
self.publicMethod = function() { | |
privateMethod(); | |
el.css({'margin': 10}); | |
}; | |
// private methods | |
privateMethod = function() { | |
console.log('privateMethod called'); | |
}; | |
init(); | |
}; | |
})(jQuery); |
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
#main { | |
position: absolute; | |
top: 0; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
background-color: lightgrey; | |
} | |
#element { | |
width: 200px; | |
height: 50px; | |
background-color: grey; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment