Created
April 1, 2012 14:01
-
-
Save ground-creative/2275478 to your computer and use it in GitHub Desktop.
Jquery smartToggle class
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
/** Jquery smartToggle class(object oriented) developed by Carlo Pietrobattista | |
* @version 0.5 | |
*/ | |
function smartToggle() | |
{ | |
/** expand toggle html tags and change the link text(if needed), mandatory vars: hiddenId(the id to show or hide) | |
* @param hiddenId string the el id to show/hide | |
* @param numeric delay the delay for the toggle action | |
* @param type string use type if you need to change the link text if needed, types are: regular(change text before toggle),reverse(change text after toggle) | |
* @param linkId string the link el id if type param is used | |
* @param linkText string the link text if type param is used | |
* @example new smartToggle().toggle('html_tag_id',100); | |
*/ | |
this.toggle=function(hiddenId,delay,type,linkId,linkText) | |
{ | |
if(type=="regular"){document.getElementById(linkId).innerHTML=linkText;} | |
$('#' + hiddenId).toggle(delay,function(){if(type=="reverse"){document.getElementById(linkId).innerHTML=linkText;}}); | |
}; | |
/** expand slideToggle html tags and change the link text(if needed), mandatory vars: hiddenId(the id to show or hide) | |
* @param hiddenId string the el id to show/hide | |
* @param numeric delay the delay for the toggle action | |
* @param type string use type if you need to change the link text if needed, types are: regular(change text before toggle),reverse(change text after toggle) | |
* @param linkId string the link el id if type param is used | |
* @param linkText string the link text if type param is used | |
* @example new smartToggle().slidetoggle('html_tag_id',100,'regular','link_el_id','new link text'); | |
*/ | |
this.slidetoggle=function(hiddenId,delay,type,linkId,linkText) | |
{ | |
if(type=="regular"){document.getElementById(linkId).innerHTML=linkText;} | |
$('#' + hiddenId).slideToggle(delay,function(){if(type=="reverse"){document.getElementById(linkId).innerHTML=linkText;}}); | |
}; | |
/** expand multitoggle to show/hide multiple elements with 1 click | |
* @param hiddenIds string|array the elements ids to show | |
* @param hideElements string|array the elements ids to hide | |
* @param numeric delay the delay for the toggle action | |
* @example new jqueryWidgets().multiToggle(['element_show_id1','element_show_id2'],['element_hide_id1','element_hide_id2'],1200); | |
*/ | |
this.multiToggle=function(hiddenIds,hideElements,delay) | |
{ | |
if(typeof(hiddenIds)=="object") | |
{ | |
for(var i=0;i<hiddenIds.length;i++) | |
{ | |
if(!$('#' + hiddenIds[i]).is(":visible")) | |
{ | |
$('#' + hiddenIds[i]).fadeIn('slow'); | |
} | |
} | |
} | |
else if(!$('#' + hiddenIds).is(":visible")) | |
{ | |
$('#' + hiddenIds).fadeIn('slow'); | |
} | |
if(typeof(hideElements)=="object") // hide visible html elements | |
{ | |
for(var i=0;i<hideElements.length;i++) | |
{ | |
if($('#' + hideElements[i]).is(":visible")){$('#' + hideElements[i]).hide();} | |
} | |
} | |
else if($('#' + hideElements).is(":visible")){$('#' + hideElements).hide();} | |
fadeElement=true; | |
} | |
//return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment