Created
December 3, 2010 06:53
-
-
Save yyr446/726663 to your computer and use it in GitHub Desktop.
HoverMarker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (){ | |
function HoverMarker(query,mark1,mark2,interval){ | |
this.linkmark = document.createElement("span"); | |
this.linkmark.appendChild(document.createTextNode(mark1)); | |
this.linkmark.className = "linkmark"; | |
this.jumpmark = document.createElement("span"); | |
this.jumpmark.appendChild(document.createTextNode(mark2)); | |
this.jumpmark.className = "jumpmark"; | |
this.targets = document./*@cc_on @if (@_jscript_version > 5.7) | |
querySelectorAll( @elif (@_jscript_version <= 5.7) | |
getElementsByTagName( @else@*/ querySelectorAll( /*@end@*/ | |
query); | |
this.interval = interval?interval:5000; | |
this.targets_flg = []; | |
} | |
HoverMarker.prototype.handleEvent = function(e){ | |
switch (e.type){ | |
case 'mouseover': | |
if(e.target.className == "linkmark"){this.linkmarkhover(e);return;} | |
if(e.target.className == "jumpmark"){this.jumpmarkhover(e);return;} | |
} | |
} | |
HoverMarker.prototype.linkmarkhover = function(e){ | |
var target = e.target || e.srcElement; | |
var check; | |
for(var i=0;i<this.targets.length;i++){ | |
if(this.targets[i] == target.parentNode) | |
check = i; | |
} | |
if(!this.targets_flg[check]){ | |
var jumpelm = document.createElement("a"); | |
jumpelm.href = target.parentNode.href; | |
jumpelm.target = target.parentNode.target; | |
jumpelm.appendChild(this.jumpmark); | |
target.appendChild(jumpelm.cloneNode(true)); | |
jumpelm./*@cc_on @if (@_jscript_version > 5.8) | |
addEventListener("mouseover",this,false); @elif (@_jscript_version <= 5.8) | |
attachEvent("onmouseover",(function(that){ | |
return function(){that.jumpmarkhover(event);}})(this)); | |
@else@*/ addEventListener("mouseover",this,false);/*@end@*/ | |
window.setTimeout((function(that,check){return function(){ | |
that.del(check);};})(this,check),this.interval); | |
this.targets_flg[check] = true; | |
}else{ | |
} | |
} | |
HoverMarker.prototype.jumpmarkhover = function(e){ | |
if('undefined' !== typeof e.stopPropagation) | |
e.stopPropagation(); | |
else e.cancelBubble = true; | |
var target = e.target || e.srcElement; | |
window.open(target.parentNode.href,target.parentNode.target); | |
} | |
HoverMarker.prototype.del = function(check){ | |
var target; | |
var elm = this.targets[check].getElementsByTagName("SPAN"); | |
for(var i=0;i<elm.length;i++) | |
if(elm[i].className == "linkmark") | |
target = elm[i].getElementsByTagName("A")[0]; | |
target./*@if (@_jscript_version > 5.8) | |
removeEventListener("mouseover",this,false); @elif (@_jscript_version <= 5.8) | |
detachEvent("onmouseover",(function(that){ | |
return function(){that.linkmarkhover(event);}})(this)); | |
@else@*/ removeEventListener("mouseover",this,false);/*@end@*/ | |
target.parentNode.removeChild(target); | |
this.targets_flg[check] = false; | |
} | |
function setup(){ | |
for(var i=0;i<this.targets.length;i++){ | |
this.targets_flg[i] = false; | |
this.targets[i].insertBefore( | |
this.linkmark.cloneNode(true),this.targets[i].firstChild); | |
this.targets[i].firstChild./*@cc_on @if (@_jscript_version > 5.8) | |
addEventListener("mouseover",this,false); @elif (@_jscript_version <= 5.8) | |
attachEvent("onmouseover",(function(that){ | |
return function(){that.linkmarkhover(event);}})(this)); | |
@else@*/ addEventListener("mouseover",this,false);/*@end@*/ | |
} | |
} | |
HoverMarker.init = function(query,mark1,mark2,interval){ | |
var obj = new HoverMarker(query,mark1,mark2,interval); | |
setup.call(obj); | |
return obj; | |
} | |
this.HoverMarker = HoverMarker; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo
http://yoneyone.my-sv.net/MouseLink.htm