properties inherence (sort of)?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
CaptainN
Forum Newbie
Posts: 9
Joined: Tue Jun 18, 2002 1:41 pm

properties inherence (sort of)?

Post by CaptainN »

In javascript, I'm trying to create an object that will out put the necessary code for semi-transparent gif files and still have regular properties as if it where an image.

Here is the code so far (it's kinda sloppy at the moment, and I intend to remove the dependancy on the clear gif by making it a <span> instead of an <img>, but I have to make sure the behavior isn't too different (tilte, alt and other stuff might not work in a <span> without extensive workarounds)).

Code: Select all

function AlphaImage(src) &#123;
	// set the location of the clear gif here.
	clearGif = 'dot_clr.gif';
	// these are the attributes' names, I'd like to find a better way to do this,
	// like take them from the arguments, but I don't know how at the moment.
	attributes = new Array('null','width','height','alt','title','border','class');
	
	// begin outputting the image
	document.write('<img src="' + src);
	
	// output the attributes
	for (i=1; i < AlphaImage.arguments.length; i++) &#123;
		if (AlphaImage.arguments&#1111;i]) &#123;
			document.write('" ' + attributes&#1111;i] + '="' + AlphaImage.arguments&#1111;i]);
		&#125;
	&#125;
	
	// if document.body.filters is an object, assume that the AlphaImageLoader filter is present
	// (I'd like to test for the specific filter, but it doesn't seem to work. I'll make a work-around 
	// for IE 4 and 5 later) If it is output the necessary style sheet rule and change the src of the 
	// image to clearGif.
	if (typeof document.body.filters == "object") &#123;
		document.write('" style="FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader( src=' + src + ', sizingmethod=scale )">');
		
		// here I define the imagePath (the path that will lead to the src propertie) and the 
		// other properties of the image. I'd like to get the poperties all on the same branch
		// but I can't set the properties individually for some reason (it takes the value and
		// not the path).
		this.properties = document.images&#1111;document.images.length-1];
		this.image = this.properties.filters.item("DXImageTransform.Microsoft.AlphaImageLoader");
		
		// set the src of the image to clearGif to make it see through so the style can show through
		document.images&#1111;document.images.length-1].src = clearGif;
	&#125; else &#123;
		// make dom implementation match IE.
		document.write('">');
		this.properties = document.images&#1111;document.images.length-1];
		this.image = this.properties;	
	&#125;
&#125;

// AlphaImage swap Image Method
AlphaImage.prototype.swapSrc = function(newSrc) &#123;
	this.image.src = newSrc;
&#125;

I'd like to be able to set "this.src" to "this.properties.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src" but when I do that it takes the value of the filter.src and assignes that to "this.src".

Is there anyway to get "this.src" to point to "this.properties.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src" instead of taking its value?
Post Reply