Add jQuery plugin structure

This commit is contained in:
conzett 2011-11-22 15:51:31 -05:00
parent 2129d1fc67
commit 0c2a04726d
2 changed files with 37 additions and 28 deletions

View File

@ -8,35 +8,33 @@
*/ */
$(document).ready(function() { ;(function ( $, window, document, undefined ) {
var pluginName = 'skeletonTabs',
defaults = {
propertyName: "value"
};
/* Tabs Activiation function Plugin( element, options ) {
================================================== */ this.element = element;
this.options = $.extend( {}, defaults, options) ;
this._defaults = defaults;
this._name = pluginName;
this.init();
}
var tabs = $('ul.tabs'); Plugin.prototype.init = function () {
tabs.each(function(i) { };
//Get all tabs $.fn[pluginName] = function ( options ) {
var tab = $(this).find('> li > a'); return this.each(function () {
tab.click(function(e) { if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName, new Plugin( this, options ));
}
});
}
//Get Location of tab's content })(jQuery, window, document);
var contentLocation = $(this).attr('href');
//Let go if not a hashed one
if(contentLocation.charAt(0)=="#") {
e.preventDefault();
//Make Tab Active
tab.removeClass('active');
$(this).addClass('active');
//Show Tab Content & add active class
$(contentLocation).show().addClass('active').siblings().hide().removeClass('active');
}
});
});
});

View File

@ -9,7 +9,18 @@
<div id="qunit-testrunner-toolbar"></div> <div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2> <h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol> <ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div> <div id="qunit-fixture">
<div role="tabpanel">
<ul>
<li>Simple</li>
<li>Lightweight</li>
<li>Mobile</li>
</ul>
<div>The tabs are clean and simple divs and basic CSS.</div>
<div>The tabs are cross-browser, but don't need a ton of hacky CSS or markup.</div>
<div>The tabs work like a charm even on mobile devices.</div>
</div>
</div>
</body> </body>
<script src="http://code.jquery.com/jquery-latest.js"></script> <script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script> <script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>