PageSourceSearch

https://www.tv-vratsa.bg/sc/js/anylink2/anylink.js

js tv-vratsa.bg collected 2026-10-02 13:37:22 UTC 11,170 bytes, 286 lines download raw bytes

1//** AnyLink CSS Menu v2.0- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com
2//** Script Download/ instructions page: http://www.dynamicdrive.com/dynamicindex1/anylinkcss.htm
3//** January 19', 2009: Script Creation date
4
5//**May 23rd, 09': v2.1
6	//1) Automatically adds a "selectedanchor" CSS class to the currrently selected anchor link
7	//2) For image anchor links, the custom HTML attributes "data-image" and "data-overimage" can be inserted to set the anchor's default and over images.
8
9//**June 1st, 09': v2.2
10	//1) Script now runs automatically after DOM has loaded. anylinkcssmenu.init) can now be called in the HEAD section
11
12if (typeof dd_domreadycheck=="undefined") //global variable to detect if DOM is ready
13	var dd_domreadycheck=false
14
15var anylinkcssmenu={
16
17menusmap: {},
18preloadimages: [],
19effects: {delayhide: 200, shadow:{enabled:true, opacity:0.3, depth: [5, 5]}, fade:{enabled:true, duration:500}}, //customize menu effects
20
21dimensions: {},
22
23getoffset:function(what, offsettype){
24	return (what.offsetParent)? what[offsettype]+this.getoffset(what.offsetParent, offsettype) : what[offsettype]
25},
26
27getoffsetof:function(el){
28	el._offsets={left:this.getoffset(el, "offsetLeft"), top:this.getoffset(el, "offsetTop"), h: el.offsetHeight}
29},
30
31getdimensions:function(menu){
32	this.dimensions={anchorw:menu.anchorobj.offsetWidth, anchorh:menu.anchorobj.offsetHeight,
33		docwidth:(window.innerWidth ||this.standardbody.clientWidth)-20,
34		docheight:(window.innerHeight ||this.standardbody.clientHeight)-15,
35		docscrollx:window.pageXOffset || this.standardbody.scrollLeft,
36		docscrolly:window.pageYOffset || this.standardbody.scrollTop
37	}
38	if (!this.dimensions.dropmenuw){
39		this.dimensions.dropmenuw=menu.dropmenu.offsetWidth
40		this.dimensions.dropmenuh=menu.dropmenu.offsetHeight
41	}
42},
43
44isContained:function(m, e){
45	var e=window.event || e
46	var c=e.relatedTarget || ((e.type=="mouseover")? e.fromElement : e.toElement)
47	while (c && c!=m)try {c=c.parentNode} catch(e){c=m}
48	if (c==m)
49		return true
50	else
51		return false
52},
53
54setopacity:function(el, value){
55	el.style.opacity=value
56	if (typeof el.style.opacity!="string"){ //if it's not a string (ie: number instead), it means property not supported
57		el.style.MozOpacity=value
58		if (el.filters){
59			el.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity="+ value*100 +")"
60		}
61	}
62},
63
64showmenu:function(menuid){
65	var menu=anylinkcssmenu.menusmap[menuid]
66	clearTimeout(menu.hidetimer)
67	this.getoffsetof(menu.anchorobj)
68	this.getdimensions(menu)
69	var posx=menu.anchorobj._offsets.left + (menu.orientation=="lr"? this.dimensions.anchorw : 0) //base x pos
70	var posy=menu.anchorobj._offsets.top+this.dimensions.anchorh - (menu.orientation=="lr"? this.dimensions.anchorh : 0)//base y pos
71	if (posx+this.dimensions.dropmenuw+this.effects.shadow.depth[0]>this.dimensions.docscrollx+this.dimensions.docwidth){ //drop left instead?
72		posx=posx-this.dimensions.dropmenuw + (menu.orientation=="lr"? -this.dimensions.anchorw : this.dimensions.anchorw)
73	}
74	if (posy+this.dimensions.dropmenuh>this.dimensions.docscrolly+this.dimensions.docheight){  //drop up instead?
75		posy=Math.max(posy-this.dimensions.dropmenuh - (menu.orientation=="lr"? -this.dimensions.anchorh : this.dimensions.anchorh), this.dimensions.docscrolly) //position above anchor or window's top edge
76	}
77	if (this.effects.fade.enabled){
78		this.setopacity(menu.dropmenu, 0) //set opacity to 0 so menu appears hidden initially
79		if (this.effects.shadow.enabled)
80			this.setopacity(menu.shadow, 0) //set opacity to 0 so shadow appears hidden initially
81	}
82	menu.dropmenu.setcss({left:posx+'px', top:posy+'px', visibility:'visible'})
83	if (this.effects.shadow.enabled)
84		menu.shadow.setcss({left:posx+anylinkcssmenu.effects.shadow.depth[0]+'px', top:posy+anylinkcssmenu.effects.shadow.depth[1]+'px', visibility:'visible'})
85	if (this.effects.fade.enabled){
86		clearInterval(menu.animatetimer)
87		menu.curanimatedegree=0
88		menu.starttime=new Date().getTime() //get time just before animation is run
89		menu.animatetimer=setInterval(function(){anylinkcssmenu.revealmenu(menuid)}, 20)
90	}
91},
92
93revealmenu:function(menuid){
94	var menu=anylinkcssmenu.menusmap[menuid]
95	var elapsed=new Date().getTime()-menu.starttime //get time animation has run
96	if (elapsed<this.effects.fade.duration){
97		this.setopacity(menu.dropmenu, menu.curanimatedegree)
98		if (this.effects.shadow.enabled)
99			this.setopacity(menu.shadow, menu.curanimatedegree*this.effects.shadow.opacity)
100	}
101	else{
102		clearInterval(menu.animatetimer)
103		this.setopacity(menu.dropmenu, 1)
104		menu.dropmenu.style.filter=""
105	}
106	menu.curanimatedegree=(1-Math.cos((elapsed/this.effects.fade.duration)*Math.PI)) / 2
107},
108
109setcss:function(param){
110	for (prop in param){
111		this.style[prop]=param[prop]
112	}
113},
114
115setcssclass:function(el, targetclass, action){
116	var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig")
117	if (action=="check")
118		return needle.test(el.className)
119	else if (action=="remove")
120		el.className=el.className.replace(needle, "")
121	else if (action=="add" && !needle.test(el.className))
122		el.className+=" "+targetclass
123},
124
125hidemenu:function(menuid){
126	var menu=anylinkcssmenu.menusmap[menuid]
127	clearInterval(menu.animatetimer)
128	menu.dropmenu.setcss({visibility:'hidden', left:0, top:0})
129	menu.shadow.setcss({visibility:'hidden', left:0, top:0})
130},
131
132getElementsByClass:function(targetclass){
133	if (document.querySelectorAll)
134		return document.querySelectorAll("."+targetclass)
135	else{
136		var classnameRE=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "i") //regular expression to screen for classname
137		var pieces=[]
138		var alltags=document.all? document.all : document.getElementsByTagName("*")
139		for (var i=0; i<alltags.length; i++){
140			if (typeof alltags[i].className=="string" && alltags[i].className.search(classnameRE)!=-1)
141				pieces[pieces.length]=alltags[i]
142		}
143		return pieces
144	}
145},
146
147addEvent:function(targetarr, functionref, tasktype){
148	if (targetarr.length>0){
149		var target=targetarr.shift()
150		if (target.addEventListener)
151			target.addEventListener(tasktype, functionref, false)
152		else if (target.attachEvent)
153			target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)})
154		this.addEvent(targetarr, functionref, tasktype)
155	}
156},
157
158domready:function(functionref){ //based on code from the jQuery library
159	if (dd_domreadycheck){
160		functionref()
161		return
162	}
163	// Mozilla, Opera and webkit nightlies currently support this event
164	if (document.addEventListener) {
165		// Use the handy event callback
166		document.addEventListener("DOMContentLoaded", function(){
167			document.removeEventListener("DOMContentLoaded", arguments.callee, false )
168			functionref();
169			dd_domreadycheck=true
170		}, false )
171	}
172	else if (document.attachEvent){
173		// If IE and not an iframe
174		// continually check to see if the document is ready
175		if ( document.documentElement.doScroll && window == window.top) (function(){
176			if (dd_domreadycheck) return
177			try{
178				// If IE is used, use the trick by Diego Perini
179				// http://javascript.nwbox.com/IEContentLoaded/
180				document.documentElement.doScroll("left")
181			}catch(error){
182				setTimeout( arguments.callee, 0)
183				return;
184			}
185			//and execute any waiting functions
186			functionref();
187			dd_domreadycheck=true
188		})();
189	}
190	if (document.attachEvent && parent.length>0) //account for page being in IFRAME, in which above doesn't fire in IE
191		this.addEvent(window, function(){functionref()}, "load");
192},
193
194addState:function(anchorobj, state){
195	if (anchorobj.getAttribute('data-image')){
196		var imgobj=(anchorobj.tagName=="IMG")? anchorobj : anchorobj.getElementsByTagName('img')[0]
197		if (imgobj){
198			imgobj.src=(state=="add")? anchorobj.getAttribute('data-overimage') : anchorobj.getAttribute('data-image')
199		}
200	}
201	else
202		anylinkcssmenu.setcssclass(anchorobj, "selectedanchor", state)
203},
204
205
206setupmenu:function(targetclass, anchorobj, pos){
207	this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
208	var relattr=anchorobj.getAttribute("rel")
209	var dropmenuid=relattr.replace(/\[(\w+)\]/, '')
210	var menu=this.menusmap[targetclass+pos]={
211		id: targetclass+pos,
212		anchorobj: anchorobj,	
213		dropmenu: document.getElementById(dropmenuid),
214		revealtype: (relattr.length!=dropmenuid.length && RegExp.$1=="click")? "click" : "mouseover",
215		orientation: anchorobj.getAttribute("rev")=="lr"? "lr" : "ud",
216		shadow: document.createElement("div")
217	}
218	menu.anchorobj._internalID=targetclass+pos
219	menu.anchorobj._isanchor=true
220	menu.dropmenu._internalID=targetclass+pos
221	menu.shadow._internalID=targetclass+pos
222	menu.shadow.className="anylinkshadow"
223	document.body.appendChild(menu.dropmenu) //move drop down div to end of page
224	document.body.appendChild(menu.shadow)
225	menu.dropmenu.setcss=this.setcss
226	menu.shadow.setcss=this.setcss
227	menu.shadow.setcss({width: menu.dropmenu.offsetWidth+"px", height:menu.dropmenu.offsetHeight+"px"})
228	this.setopacity(menu.shadow, this.effects.shadow.opacity)
229	this.addEvent([menu.anchorobj, menu.dropmenu, menu.shadow], function(e){ //MOUSEOVER event for anchor, dropmenu, shadow
230		var menu=anylinkcssmenu.menusmap[this._internalID]
231		if (this._isanchor && menu.revealtype=="mouseover" && !anylinkcssmenu.isContained(this, e)){ //event for anchor
232			anylinkcssmenu.showmenu(menu.id)
233			anylinkcssmenu.addState(this, "add")
234		}
235		else if (typeof this._isanchor=="undefined"){ //event for drop down menu and shadow
236			clearTimeout(menu.hidetimer)
237		}
238	}, "mouseover")
239	this.addEvent([menu.anchorobj, menu.dropmenu, menu.shadow], function(e){ //MOUSEOUT event for anchor, dropmenu, shadow
240		if (!anylinkcssmenu.isContained(this, e)){
241			var menu=anylinkcssmenu.menusmap[this._internalID]
242			menu.hidetimer=setTimeout(function(){
243				anylinkcssmenu.addState(menu.anchorobj, "remove")
244				anylinkcssmenu.hidemenu(menu.id)
245			}, anylinkcssmenu.effects.delayhide)
246		}
247	}, "mouseout")
248	this.addEvent([menu.anchorobj, menu.dropmenu], function(e){ //CLICK event for anchor, dropmenu
249		var menu=anylinkcssmenu.menusmap[this._internalID]
250		if ( this._isanchor && menu.revealtype=="click"){
251			if (menu.dropmenu.style.visibility=="visible")
252				anylinkcssmenu.hidemenu(menu.id)
253			else{
254				anylinkcssmenu.addState(this, "add")
255				anylinkcssmenu.showmenu(menu.id)
256			}
257			if (e.preventDefault)
258				e.preventDefault()
259			return false
260		}
261		else
262			menu.hidetimer=setTimeout(function(){anylinkcssmenu.hidemenu(menu.id)}, anylinkcssmenu.effects.delayhide)
263	}, "click")
264},
265
266init:function(targetclass){
267	this.domready(function(){anylinkcssmenu.trueinit(targetclass)})
268},
269
270trueinit:function(targetclass){
271	var anchors=this.getElementsByClass(targetclass)
272	var preloadimages=this.preloadimages
273	for (var i=0; i<anchors.length; i++){
274		if (anchors[i].getAttribute('data-image')){ //preload anchor image?
275			preloadimages[preloadimages.length]=new Image()
276			preloadimages[preloadimages.length-1].src=anchors[i].getAttribute('data-image')
277		}
278		if (anchors[i].getAttribute('data-overimage')){ //preload anchor image?
279			preloadimages[preloadimages.length]=new Image()
280			preloadimages[preloadimages.length-1].src=anchors[i].getAttribute('data-overimage')
281		}
282		this.setupmenu(targetclass, anchors[i], i)
283	}
284}
285
286}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.