Results 1 to 3 of 3

Thread: Modifying switchcontent.js to tell which is filterTag is expanded

  1. #1
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default Modifying switchcontent.js to tell which is filterTag is expanded

    Hi,

    I'm using switchtoggle.js, found at http://www.dynamicdrive.com/dynamici...tchcontent.htm (the older version, but it won't make any difference here).

    Works beautifully, BTW, and am using it in several places, usually generating the sections in a loop from content taken from a database or flat files with php, so the sections have an base id of 'band' and numbered 1, 2, 3..... with the resultant id's being band1, band2, etc.

    I need to know which section is expanded so I can have javascript do appropriate tasks depending on which section is expanded. So, to do this I need to augment the script. Where and how are somewhat evasive, but it probably should be in this section:
    Code:
    switchcontent.prototype.expandcontent=function(header){
    	var innercontent=document.getElementById(header.id.replace("-title", ""))
    	innercontent.style.display="block"
    	this.togglestatus(header, this.statusOpen)
    	this.togglecolor(header, this.colorOpen)
    }
    Has anyone already done this? I was thinking about adding:

    Code:
            var sec=document.getElementByID(header);
            section=sec.substring(str.lastIndexOf("d")+1,str.lastIndexOf("-"));
    and defining section in the first, main javascript in my program. The "d" is the last character in the base section identifier that I happen to be using in this page, but it is not a generic solution. And also, this is not the right way because variables should be self contained in this file and not referenced directly elsewhere. What is the proper way to do this so I have generic code to use elsewhere?

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    to add a callback function

    Code:
    //PRIVATE: Contracts a content based on its corresponding header entered
    
    switchcontent.prototype.contractcontent=function(header){
    	var innercontent=document.getElementById(header.id.replace("-title", "")) //Reference content container for this header
    	innercontent.style.display="none"
    	this.togglestatus(header, this.statusClosed)
    	this.togglecolor(header, this.colorClosed)
        if (typeof(this.oncontract)=='function'){
         this.oncontract(innercontent);
        }
    }
    
    
    //PRIVATE: Expands a content based on its corresponding header entered
    
    switchcontent.prototype.expandcontent=function(header){
    	var innercontent=document.getElementById(header.id.replace("-title", ""))
    	if (header.ajaxstatus=="waiting"){//if this is an Ajax header AND remote content hasn't already been fetched
    		switchcontent.connect(header.ajaxfile, header)
    	}
    	innercontent.style.display="block"
    	this.togglestatus(header, this.statusOpen)
    	this.togglecolor(header, this.colorOpen)
        if (typeof(this.onexpand)=='function'){
         this.onexpand(innercontent);
        }
    }

    definition

    Code:
    var bobexample=new switchcontent("switchgroup1", "div") //Limit scanning of switch contents to just "div" elements
    bobexample.setStatus('<img src="http://img242.imageshack.us/img242/5553/opencq8.png" /> ', '<img src="http://img167.imageshack.us/img167/7718/closedy2.png" /> ')
    bobexample.setColor('darkred', 'black')
    bobexample.setPersist(true)
    bobexample.collapsePrevious(true) //Only one content open at any given time
    bobexample.onexpand=function(obj){
     alert(obj.id);
    }
    bobexample.oncontract=function(obj){
     alert(obj.id);
    }
    
    bobexample.init()
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. The Following User Says Thank You to vwphillips For This Useful Post:

    Strangeplant (10-17-2014)

  4. #3
    Join Date
    Feb 2006
    Posts
    236
    Thanks
    8
    Thanked 3 Times in 3 Posts

    Default

    I modified the switchcontent.js as vwphillips documented, above. I thank you for the code work, specially because I would not have thought of using 'typeof'. It returns the div id correctly.

    Then, in the switchcontent definition, I add the following javascript code, just before the .init(), like this, to retrieve the numerical part of the div id, and assign it to the variable 'section':
    Code:
    <script type="text/javascript">
    var section=0
    var band=new switchcontent("switchband", "div")
    band.setStatus("[close] ", "[expand] ")
    band.setColor("darkred", "purple")
    band.setPersist(true)
    band.collapsePrevious(true)
    band.onexpand=function(obj){
    	var r = /\d+/
    	section = obj.id.match(r)
    }
    band.init()
    </script>
    or in the php code that I use to generate the page, like this:
    Code:
    	echo('<script type="text/javascript">'."\n");
    	echo('var section=0'."\n");
    //     the rest of the definition goes here
    	echo('band.onexpand=function(obj){'."\n");
    	echo('	var r = /\d+/'."\n");
    	echo('	section = obj.id.match(r)'."\n");
    //	echo('	alert(obj.id + " section: " + section)'."\n");								// testing returned section value
    	echo('}'."\n");
    	echo('band.init()'."\n");
    	echo('</script>'."\n");
    This way, I can use the section value to activate the proper and variable link when using modal dialog, jquery.simplemodal.1.4.4.min.js. And the dialog link is on the page like this:
    Code:
    <td nowrap align="right"><a href="#" onclick="modalDialog(section); return false;"><b>File Structure &amp; Processing Notes &raquo;&nbsp;</b></a></td>
    Just to finish showing what I was up to, here is the php code to give the javascript modal dialog function:
    Code:
    	<script type="text/javascript">
    		function modalDialog(x){
    			links = ["lib/Default.html","lib/lidar_rawdata_format.htm","lib/lidar_netcdf_file_format.htm","lib/lidar_rawdata_format.htm"];
    			var src = links[x];
    			$.modal('<iframe src="' + src + '" height="520" width="1020" style="border:0">', {
    				close: true,
    				containerCss:{
    					backgroundColor:"#fff", 
    					height:550, 
    					padding:20,
    					width:1060
    				},
    				overlayClose:true,
    				onOpen: function (dialog) {
    					dialog.overlay.fadeIn(function () {
    						dialog.data.hide();
    						dialog.container.fadeIn(function () {
    							dialog.data.fadeIn();
    						});
    					});
    				},
    				onClose: function (dialog) {
    					dialog.data.fadeOut(function () {
    						dialog.container.fadeOut(function () {
    							dialog.overlay.fadeOut(function () {
    								$.modal.close();
    							});
    						});
    					});
    				}
    			});
    		}
    
    		$('select').change(function() {
    			$(this).parents('form').submit();
    		});
    	</script>
    Last edited by Strangeplant; 10-17-2014 at 03:25 PM.

Similar Threads

  1. SwitchContent issues
    By lydas2000 in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 02-26-2009, 08:25 PM
  2. SwitchContent - Strange Timing(?) Bug
    By ExTexan in forum Bug reports
    Replies: 3
    Last Post: 12-04-2008, 07:35 AM
  3. Need help with switchcontent script
    By ETT in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 06-02-2008, 06:35 PM
  4. switchcontent using flash button
    By ata_gp in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 06-18-2007, 03:10 PM
  5. New Person question about SwitchContent
    By danakalinin in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 01-12-2005, 09:55 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •