/    Sign up×
Community /Pin to ProfileBookmark

What Calls Function zxcMse(event) ?

Somewhere on this forum I found a piece of code, javascript, that was titled something like ‘cursor position conversted to css styling’.

I thought it would be good to help me learn something about javascript and I copied it.

It’s good. I’m learning something. But there’s one thing I don’t understand.

There’s a function called ‘zxcMse(event)’ and it doesn’t get called by anything.

But I have a feeling that it is not wasted – something is calling it. Maybe the system knows it is there and it is called by a mouse event. But how does the system know it is there?

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsApr 19.2010 — zxc is my 'trademark' but looks quite old

post the whole code and it can be explained and updated
Copy linkTweet thisAlerts:
@abrogardauthorApr 19.2010 — Okay, thank you Vic.

Here it is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<title></title>

</head>

<body>

<script language="JavaScript" type="text/javascript">

<!--

var zxcEvt=0;

var zxcObj;

function PopUp(id,txt,sw){

zxcObj=document.getElementById(id);

if (!sw){ zxcObj.style.visibility='hidden'; zxcObj=null; return; }

zxcObj.innerHTML=txt;

zxcObj.style.visibility='visible';

}

function zxcMse(event){

if(!event) var event=window.event;

var zxcx,zxcy;

if (document.all){ zxcx=event.clientX+zxcDocS()[0]; zxcy=event.clientY+zxcDocS()[1]; }

else { zxcx=event.pageX,zxcy=event.pageY; }

if (!zxcObj){ return; }

zxcObj.style.left=(zxcx+5)+'px';

zxcObj.style.top=(zxcy+5)+'px';

}

function zxcDocS(){

var zxcsx,zxcsy;

if (!document.body.scrollTop){ zxcsx=document.documentElement.scrollLeft; zxcsy=document.documentElement.scrollTop; }

else { zxcsx=document.body.scrollLeft; zxcsy=document.body.scrollTop; }

return [zxcsx,zxcsy];

}

function zxcEventAdd(zxco,zxct,zxcf){

if (zxco.addEventListener){ zxco.addEventListener(zxct, function(e){ zxco[zxcf](e);}, false); }

else if (zxco.attachEvent){ zxco.attachEvent('on'+zxct,function(e){ zxco[zxcf](e); }); }

else {

var zxcPrev=zxco['on'+zxct];

if (zxcPrev){ zxco['on'+zxct]=function(e){ zxcPrev(e); zxco[zxcf](e); }; }

else { zxco['on'+zxct]=zxco[zxcf]; }

}

}

function zxcAddEvt(zxcobj,zxcfun,zxcevt){

if (zxcobj[zxcevt+'add']){ return; }

zxcobj['zxcaddEvt'+zxcEvt]=window[zxcfun];

zxcobj[zxcevt+'add']=true;

zxcEventAdd(zxcobj,zxcevt,'zxcaddEvt'+zxcEvt);

zxcEvt++;

}

zxcAddEvt(document,'zxcMse','mousemove');

//-->

</script>

</body>

<div style="position:relative;width:100px;height:100px;background-color:red;"

onmouseover="PopUp('PU','some text',true);"

onmouseout="PopUp('PU');"
></div>


<div id="PU" style="position:absolute;visibility:hidden;width:100px;height:100px;background-color:#FFFFCC;" ></div>

</html>
Copy linkTweet thisAlerts:
@rnd_meApr 20.2010 — i don't know about events, but you can back trace function calls using the caller property:

[CODE]function one(){
two();
}

function two(){
alert(arguments.callee.caller);
}

one();//shows first function...[/CODE]
Copy linkTweet thisAlerts:
@abrogardauthorApr 20.2010 — Well thanks for that. I tried it and got:

<localhost>

function zxcMse(event){

if(!event) var event=window.event;

var zxcx,zxcy;

if (document.all){ zxcx=event.clientX+zxcDocS()[0]; zxcy=event.clientY+zxcDocS()[1]; }

else { zxcx=event.pageX,zxcy=event.pageY; }

if (!zxcObj){ return; }

zxcObj.style.left=(zxcx+5)+'px';

zxcObj.style.top=(zxcy+5)+'px';

caller();

}

which tells me what? That <localhost> called the function?

What I'm wondering is how it gets called if it is not called explicitly by the javascript code. It seems to get called on mouseover of the initial rectangle. I can believe the system calls a function on mouseover. But 'zxc' is a trademark of that programmer. The system's not going to call his function by that name unless he tells it about it. Where does he do that?
Copy linkTweet thisAlerts:
@vwphillipsApr 20.2010 — this calls zxcMse on mousemove

[CODE]function zxcEventAdd(zxco,zxct,zxcf){
if (zxco.addEventListener){ zxco.addEventListener(zxct, function(e){ zxco[zxcf](e);}, false); }
else if (zxco.attachEvent){ zxco.attachEvent('on'+zxct,function(e){ zxco[zxcf](e); }); }
else {
var zxcPrev=zxco['on'+zxct];
if (zxcPrev){ zxco['on'+zxct]=function(e){ zxcPrev(e); zxco[zxcf](e); }; }
else { zxco['on'+zxct]=zxco[zxcf]; }
}
}

function zxcAddEvt(zxcobj,zxcfun,zxcevt){
if (zxcobj[zxcevt+'add']){ return; }
zxcobj['zxcaddEvt'+zxcEvt]=window[zxcfun];
zxcobj[zxcevt+'add']=true;
zxcEventAdd(zxcobj,zxcevt,'zxcaddEvt'+zxcEvt);
zxcEvt++;
}

zxcAddEvt(document,'zxcMse','mousemove');
[/CODE]
Copy linkTweet thisAlerts:
@abrogardauthorApr 22.2010 — ahh.... I wasn't aware of being able to call a function as an argument simply by name. Got a lot to learn, don't I? The whole DOM and event handling stuff. All your nested curly brackets. Your function(e).... the whole bit...

my eyes aren't wide open... blinded by the glare.... squinting into the sun... but thanks to you and your code I've found a place to start...

thanks

ab ?
×

Success!

Help @abrogard spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...