Properties
Posted: Mon May 28, 2007 7:21 am
Let's say I'm making a slider, and I want it to be able to recognize whether or not the mouse is down, regardless off where the "mouseup" event occurs. Therefore, I'm using it's ownerDocument (or just "document" for browsers that don't support it) and giving it event listeners for both mousedown and mouseup events. I created a custom property with the ownerDocument so that it could be updated through mouse events on the ownerDocument, and accessed through a reference to my slider's ownerDocument.
It works beautifully in Firefox. Not so much In IE. I'm not blaming IE for anything, I'm just certain that I'm probably doing something that just shouldn't be done... maybe.
AddEvent is a function I wrote for cross-browser compatibility. (addEventListener, attachEvent)
Is it not legal to create document.__mousestate?
It works beautifully in Firefox. Not so much In IE. I'm not blaming IE for anything, I'm just certain that I'm probably doing something that just shouldn't be done... maybe.
Code: Select all
function Slider()
{
this.document = this.ownerDocument ? this.ownerDocument : document;
this.document.__mousestate = 'up';
AddEvent(this.document, 'mousedown', function(){this.__mousestate = 'down';}, true);
AddEvent(this.document, 'mouseup', function(){this.__mousestate = 'up';}, true);
}
Slider.prototype.Slide = function()
{
if(this.document.__mousestate == 'up')
return;
// Otherwise, slide the bar
}Is it not legal to create document.__mousestate?