Results 1 to 4 of 4

Thread: Switch Content Script II, write out page contracted

  1. #1
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Switch Content Script II, write out page contracted

    Switch Content Script II
    http://www.dynamicdrive.com/dynamici...chcontent2.htm

    First: Excellent script, thanks.

    I'm using it to display my email, so I run thru the database and write the subjects out to a page. When done the script iterates thru the divs on the page collapsing the content.

    Everything works well, when I expand the subject the script retrieves the messages from the database and contracts the previously expanded message.

    My problem is when I show about 200 or more subjects the asp page writes out fast but then the script has to iterate thru all the divs collapsing and that can add a couple of seconds. I would like to write out the page with the content contracted and I'm not sure how to go about it or even if it's possible.

    Can anyone help.

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Hmm I'm not sure how realistic it is to modify the script to write all the DIVs- including all of its settings such as the status icons- dynamically when the page loads, instead of having the script do that dynamically. It's possible I suppose, though quite a lot of changes to the script has to occur here, including integrating with your server side script in the backend.

    You can increase the initialization time slightly by replacing the original "collectElementbyClass()" function inside switchcontent.js with the below version instead:

    Code:
    switchcontent.prototype.collectElementbyClass=function(classname){ //Returns an array containing DIVs with specified classname
    	var classnameRE=new RegExp("(^|\\s+)"+classname+"($|\\s+)", "i") //regular expression to screen for classname within element
    	this.headers=[], this.innercontents=[]
    	if (document.querySelectorAll)
    		var targetelements=document.querySelectorAll(this.filter_content_tag+'.'+classname)
    	else if (this.filter_content_tag!="") //If user defined limit type of element to scan for to a certain element (ie: "div" only)
    		var allelements=document.getElementsByTagName(this.filter_content_tag)
    	else //else, scan all elements on the page!
    		var allelements=document.all? document.all : document.getElementsByTagName("*")
    	var contentlength=targetelements? targetelements.length : allelements.length
    	for (var i=0; i<contentlength; i++){
    		if (targetelements || (typeof allelements[i].className=="string" && allelements[i].className.search(classnameRE)!=-1)){
    			var targetelement=targetelements? targetelements[i] : allelements[i]
    			if (document.getElementById(targetelement.id+"-title")!=null){ //if header exists for this inner content
    				this.headers[this.headers.length]=document.getElementById(targetelement.id+"-title") //store reference to header intended for this inner content
    				this.innercontents[this.innercontents.length]=targetelement //store reference to this inner content
    			}
    		}
    	}
    }
    DD Admin

  3. #3
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thank you DDADMIN,

    Wow, that small change shaved off roughly 2-3 seconds on a 9-10 second page load.

    Cheers

  4. #4
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Glad to hear.
    DD Admin

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
  •