Created
November 22, 2011 16:02
-
-
Save davetayls/1386003 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /* | |
| Lighweight Concertina Plugin | |
| <ul class="concertina"> | |
| <li> | |
| <h2>header</h2> | |
| <div>content</div> | |
| </li> | |
| <li> | |
| <h2>header</h2> | |
| <div>content</div> | |
| </li> | |
| <li> | |
| <h2>header</h2> | |
| <div>content</div> | |
| </li> | |
| </ul> | |
| $('.concertina').concertina(); | |
| ------------------------------------------------------------*/ | |
| /*jslint browser: true, vars: true, white: true, forin: true, nomen: true */ | |
| /*global define,require */ | |
| (function($) { | |
| 'use strict'; | |
| var DEFAULT_SETTINGS = { | |
| itemClass: 'concertina-item', | |
| headerClass: 'concertina-header', | |
| headerSelector: '>li>h2', | |
| contentClass: 'concertina-content', | |
| selectedClass: 'concertina-on', | |
| speed: 200 | |
| }, | |
| DATA_KEY = 'concertina.settings' | |
| ; | |
| $.fn.concertina = function(options) { | |
| var settings; | |
| if (typeof (options) === "string") { | |
| settings = this.data(DATA_KEY); | |
| if (options === "expandAll") { | |
| this.find(">." + settings.itemClass) | |
| .removeClass(settings.selectedClass) | |
| .addClass(settings.selectedClass) | |
| .find(">." + settings.contentClass).show(); | |
| } | |
| if (options === "closeAll") { | |
| this.find(">." + settings.itemClass) | |
| .removeClass(settings.selectedClass) | |
| .find(">." + settings.contentClass).hide(); | |
| } | |
| } else { | |
| settings = $.extend({}, DEFAULT_SETTINGS, options); | |
| this.data(DATA_KEY, settings) | |
| .find(settings.headerSelector) | |
| .each(function() { | |
| var parent = $(this).parent().addClass(settings.itemClass); | |
| var header = $(this).addClass(settings.headerClass); | |
| var content = $(this).next().addClass(settings.contentClass); | |
| if (!parent.hasClass(settings.selectedClass)) { | |
| content.hide(); | |
| } | |
| header.click(function(e) { | |
| if (e.target.tagName.toLowerCase() !== "input") { | |
| if (parent.hasClass(settings.selectedClass)) { | |
| content.slideUp(settings.speed); | |
| parent.removeClass(settings.selectedClass); | |
| } else { | |
| content.slideDown(settings.speed); | |
| parent.addClass(settings.selectedClass); | |
| } | |
| return false; | |
| } | |
| }); | |
| }); | |
| } | |
| }; | |
| }(window.jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment