From 7366704243bda288986902769576368b8da415aa Mon Sep 17 00:00:00 2001 From: Anthony Williams Date: Wed, 1 May 2013 12:15:12 +0100 Subject: [PATCH] ClassToggle: Add ability to explicitly add/remove classes ClassToggle can now explicitly add or remove classnames from target elements. To do this, simply prepend -- or ++ to explicitly remove or add class names to the target element(s). For example, to toggle one class whilst explicitly removing another, use: data-classtoggle-class="toggle-this,--remove-this" To remove one class whilst adding another, use: data-classtoggle-cass="++add-this,--remove-this" --- ClassToggle/abitgone-classtoggle-min.js | 25 +++++++------ ClassToggle/abitgone-classtoggle.js | 48 +++++++++++++++---------- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/ClassToggle/abitgone-classtoggle-min.js b/ClassToggle/abitgone-classtoggle-min.js index d5b1448..ea2d56a 100644 --- a/ClassToggle/abitgone-classtoggle-min.js +++ b/ClassToggle/abitgone-classtoggle-min.js @@ -9,25 +9,24 @@ - **href** (for anchors) or **data-classtoggle-target** This specifies the target element - + - **data-classtoggle-class** The class, or comma-separated classes, to be toggled, on and off, by the trigger - + Additionally, you may specify the following additional class names: - **data-classtoggle-altclass** The class you'd like to alternate with the main class. For example, data-classtoggle-class="Red" and data-classtoggle-altclass="Green" will alternate the .Red and .Green classes each time the trigger element - is activated. Unlike multiple classes, this will check for the existence of data-classtoggle-class and - data-classtoggle-altclass before toggling the main class or alternate class. - + is activated. + - **data-classtoggle-trigger-activeclass** Specifies a class to be added to the trigger when it activates the ClassToggle. - + - **data-classtoggle-trigger-selector** Specifies a jQuery selector which data-classtoggle-trigger-activeclass will be toggled on when the trigger elements are activated. Useful if you have more than one trigger which could trigger the target element. - + For more information on how to use this plugin and for live examples, visit http://abitgone.github.com/jQuery-Plugins/ClassToggle @@ -35,21 +34,21 @@ ------- Author: Anthony Williams Web: http://abitgone.github.com/jQuery-Plugins/ClassToggle - + Copyright (c) 2012 Anthony Williams - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -*/!function(){var e=function(e,t){this.$element=$(e);this.options=$.extend({},$.fn.classToggle.defaults,t);this.options.parent&&(this.$parent=$(this.options.parent));this.options.classToggle&&this.classToggle()};e.prototype={constructor:e,classToggle:function(){var e,t,n,r,i,s=$(this.options.trigger),o=$(this.options.triggerTarget),u=this.options.classtoggleClass,a=this.options.classtoggleAltclass,f=this.options.classtoggleTriggerActiveclass,l=this.options.classtoggleTriggerSelector,c=this.options.classtoggleTarget;if(c==undefined){c=s.attr("href")==undefined?s.attr("href"):this.options.trigger.href;c=c.replace(/.*(?=#[^\s]+$)/,"")}if(c==undefined)return;e=$(c);if(u==undefined||e==undefined)return;u=u.split(",");t=!1;for(n=0;n