Jump to content

Help! splicing plugin for second function.


ehime

Recommended Posts

I have a iLayer plugin that is calling a remote text file/stripped html file into a local iLayeron my webpage right now, I'm trying to splice it to include a second call for another remotefile under a different function (functions intersect and crash each other now if I use the samefunction name on two different parts of the page). I ran into a block when if v=1 post data,since v is already taken I need something different for it to post a positive integer to forthis.has.data.and.will.post, take a look, tell me what you think. Thanks guys!Origional Plugin:

var srcFrame;$(document).ready(function(){  loadOuter('layers/main.html'); // ...});//External content into a layerfunction loadOuter(doc) { srcFrame = document.getElementById("hiddenContent"); srcFrame.src = doc; // workaround for missing onLoad event in IFRAME for NN6 if (!srcFrame.onload) {  setTimeout("transferHTML()", 200) }}function transferHTML(){ srcContent=''; if (srcFrame.contentDocument){  srcContent=srcFrame.contentDocument.getElementsByTagName("*")[0].innerHTML; } else if (srcFrame.contentWindow){  srcContent=srcFrame.contentWindow.document.body.innerHTML; } document.getElementById("outerDisplay").innerHTML = srcContent}var DocAry=new Array('');function SelectList(v){ if (v>0){  loadOuter(DocAry[v-1]); }}

Code till I hit my road-block:

var srcFrame;$(document).ready(function(){  loadOuter('layers/main.html'); // ...  loadInner('layers/space.html');});	//External content into a layer	function loadOuter(doc) {	 srcFrame = document.getElementById("loadContent");	 srcFrame.src = doc;		 // workaround for missing onLoad event in IFRAME for NN6		 if (!srcFrame.onload) {		  setTimeout("xferOuter()", 200)		 }		}	//External content into a layer	function loadInner(doc) {	 srcFrame = document.getElementById("prodContent");	 srcFrame.src = doc;		 // workaround for missing onLoad event in IFRAME for NN6		 if (!srcFrame.onload) {		  setTimeout("xferInner()", 200)		 }		}				function xferOuter(){			 srcContent='';			 if (srcFrame.contentDocument){			  srcContent=srcFrame.contentDocument.getElementsByTagName("*")[0].innerHTML;			 }				 else if (srcFrame.contentWindow){				  srcContent=srcFrame.contentWindow.document.body.innerHTML;				 }				 document.getElementById("outerDisplay").innerHTML = srcContent				}			function xferInner(){			 srcContent='';			 if (srcFrame.contentDocument){			  srcContent=srcFrame.contentDocument.getElementsByTagName("*")[0].innerHTML;			 }				 else if (srcFrame.contentWindow){				  srcContent=srcFrame.contentWindow.document.body.innerHTML;				 }				 document.getElementById("prodDisplay").innerHTML = srcContent				}var outAry=new Array('');var innAry=new Array('');	function SelectList(v){	 if (v>0){	  loadOuter(outAry[v-1]);	 }		else if ()	}

Link to comment
Share on other sites

Those two sets of functions are using a lot of the same global variables. Both load functions set a variable called srcFrame, and both xfer functions use srcFrame, so they're both trying to do their work on the same object. You need to either chain the functions so that one waits before the other finishes to run, or give each set its own global variables to use. If you really want to get into it you can just make an object or class that will handle all of what you want to do and then make 2 instances of the class to work with your page. I'm not sure how SelectList gets used, but it looks like you either need to duplicate that also or give it a second parameter so it knows which function to call.

Link to comment
Share on other sites

Do you think that srcContent is botching me along with srcFrame? I played around with stuff and I'm not sure why but if I don't includethe select frame function it collapses my entire script and will nolonger function. You mentioned creating a class or an object withthis? How would you go about doing it, out of the sake of curiousity.Thanks for the quick rep man, very informative. Patched the functionsto discriminate them form themselves, here's the code that I'm workingwith right now. Unfortunetly I broke it somewhere along the lines
var outFrame;var inFrame;$(document).ready(function(){  loadOuter('layers/main.html'); // ...  loadInner('layers/space.html');});	//External content into a layer	function loadOuter(doc) {	 outFrame = document.getElementById("loadContent");	 outFrame.src = doc;		 // workaround for missing onLoad event in IFRAME for NN6		 if (!outFrame.onload) {		  setTimeout("xferOuter()", 200)		 }		}	function loadInner(doc) {	 inFrame = document.getElementById("innerContent");	 inFrame.src = doc;		 if (!inFrame.onload) {		  setTimeout("xferInner()", 200)		 }		}					// Load for Display					function xferOuter(){					 outContent='';					 if (outFrame.contentDocument){					  outContent=outFrame.contentDocument.getElementsByTagName("*")[0].innerHTML;					 }						 else if (outFrame.contentWindow){						  outContent=outFrame.contentWindow.document.body.innerHTML;						 }						 document.getElementById("outerDisplay").innerHTML = outContent						}					function xferInner(){					 inContent='';					 if (inFrame.contentDocument){					  inContent=inFrame.contentDocument.getElementsByTagName("*")[0].innerHTML;					 }						 else if (inFrame.contentWindow){						  inContent=inFrame.contentWindow.document.body.innerHTML;						 }						 document.getElementById("innerDisplay").innerHTML = inContent						}var outAry=new Array('');var innAry=new Array('');	function outList(v){	 if (v>0){	  loadOuter(outAry[v-1]);	 }		else if ()	}		function inList(v){	 if (v>0){	  loadInner(outAry[v-1]);	 }		else if ()	}

Link to comment
Share on other sites

Do you think that srcContent is botching me along with srcFrame?
Probably not, it looks like a local variable. You can make sure it's local by using var.
function xferOuter(){  var outContent='';  if (outFrame.contentDocument){	outContent=outFrame.contentDocument.getElementsByTagName("*")[0].innerHTML;  }  else if (outFrame.contentWindow){	outContent=outFrame.contentWindow.document.body.innerHTML;  }  document.getElementById("outerDisplay").innerHTML = outContent}

You mentioned creating a class or an object withthis? How would you go about doing it, out of the sake of curiousity.
In general, look at the information that changes between the functions and make generic functions that take the changing information as parameters. With the load functions, the things that change are the ID to find, the function to run onload, and the global variable that stores the frame reference. The global variable is what you need the class for, because you can make it a local class property instead of a global variable, and then each instance of the class would have its own set of data. So you would convert the global variables to class properties, and generalize the functions so that any information that changes is sent as a parameter. e.g., you might define a load function inside a class like this:
	load = function(doc, id) {	 this.srcFrame = document.getElementById(id + "Content");	 this.srcFrame.src = doc;	 this.id = id;	 // workaround for missing onLoad event in IFRAME for NN6	 if (!srcFrame.onload) {	  setTimeout("this.xfer()", 200)	 }	}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...