PageSourceSearch

https://www.megaten.ru/modules/mod_s5_box/js/s5box.js

js megaten.ru collected 2026-09-26 04:41:49 UTC 16,153 bytes, 428 lines download raw bytes

1var S5Box = new Class({
2	Implements: [Events],
3	options: {
4		transition: s5_boxeffect,
5		speed: 350,
6		width: false,
7		height: false,
8		initialWidth: 100,
9		initialHeight: 100,
10		maxWidth: false,
11		maxHeight: false,
12		resize: true,
13		inline: false,
14		title: false,
15		rel: false,
16		opacity: 0.7,
17		preloading: true,
18		close: 'close',
19		open: false,
20		overlayClose: true
21	},
22	
23	events: {
24		windowResize: null,
25		windowResizeIE6: null,
26		windowScrollIE6: null
27	},
28	
29	initialize: function(selector, options){
30		$extend(this.options, options);
31		var elements = $$(selector);
32		if(elements.length){			
33			var that = this, isInitialized = false;				
34			this.cbox = $('colorbox');
35			if(this.cbox){
36				isInitialized = true;				
37			}
38			else{
39				this.cbox = new Element('div', { 'id': 'colorbox'});
40			}						
41			this.overlay = $('cboxOverlay') || this.createDiv('Overlay').setStyle('display', 'none');;
42			this.wrap = $('cboxWrapper') ||  this.createDiv('Wrapper');
43			this.loaded = $('cboxLoadedContent') || this.createDiv('LoadedContent').setStyles({'width': 0, 'height': 0});
44			this.loadingOverlay = $('cboxLoadingOverlay') || this.createDiv('LoadingOverlay');
45			this.loadingGraphic = $('cboxLoadingGraphic') || this.createDiv('LoadingGraphic');
46			this.current = $('cboxCurrent') || this.createDiv('Current');
47			this.title = $('cboxTitle') || this.createDiv('Title');
48			this.close = $('cboxClose') || this.createDiv('Close');
49			this.content = $('cboxContent') || this.createDiv('Content').adopt(
50				this.loaded,
51				this.loadingOverlay,
52				this.loadingGraphic,
53				this.close
54			);			
55			this.topBorder = $('cboxTopCenter') || this.createDiv('TopCenter');
56			this.leftBorder = $('cboxMiddleLeft') || this.createDiv('MiddleLeft');
57			this.rightBorder = $('cboxMiddleRight') || this.createDiv('MiddleRight');
58			this.bottomBorder = $('cboxBottomCenter') || this.createDiv('BottomCenter');			
59			if(!isInitialized){
60				this.wrap.adopt(
61					new Element('div').adopt(
62						$('cboxTopLeft') || this.createDiv('TopLeft'),
63						this.topBorder,
64						$('cboxTopRight') || this.createDiv('TopRight')
65					),
66					new Element('div').adopt(
67						this.leftBorder,
68						this.content,
69						this.rightBorder
70					),
71					new Element('div').adopt(
72						$('cboxBottomLeft') || this.createDiv('BottomLeft'),
73						this.bottomBorder,
74						$('cboxBottomRight') || this.createDiv('BottomRight')
75					)
76				).getChildren().getChildren().each(function(child){
77					child.setStyle('float', 'left');
78				});				
79				this.cbox.adopt(this.wrap).inject(document.body, 'top');
80				this.overlay.inject(document.body, 'top');				
81				var isIE = this.ieVersion();
82				if (isIE > 0 && isIE < 7) {
83					this.overlay.setStyle('position', 'absolute');
84				}
85			}
86			this.content.getChildren().each(function(child){
87				child.addClass('hover')
88					.addEvents({
89						'mouseover': function () { this.addClass('hover'); },
90						'mouseout': function () { this.removeClass('hover'); }
91					})
92					.setStyle('display', 'none');
93			});			
94			this.cbox.setStyle('display', 'block');
95			this.interfaceHeight = this.topBorder.offsetHeight + this.bottomBorder.offsetHeight + this.content.getStyle('margin-top').toInt() + this.content.getStyle('margin-bottom').toInt();//Subtraction needed for IE6
96			this.interfaceWidth = this.leftBorder.offsetWidth + this.rightBorder.offsetWidth + this.content.getStyle('margin-left').toInt() + this.content.getStyle('margin-right').toInt();
97			this.loadedHeight = this.loaded.offsetHeight + this.loaded.getStyle('margin-top').toInt() + this.loaded.getStyle('margin-bottom').toInt();
98			this.loadedWidth = this.loaded.offsetWidth + this.loaded.getStyle('margin-left').toInt() + this.loaded.getStyle('margin-right').toInt();
99			this.cbox.setStyles({'padding-bottom': this.interfaceHeight, 'padding-right': this.interfaceWidth, 'display': 'none'});
100			if(!isInitialized){
101				this.cbox.fx = new Fx.Tween(this.cbox, {property: 'opacity', onComplete: function(){ if(that.ieVersion() > 0){ that.content.setStyle('filter', '');}}});
102				this.overlay.fx = new Fx.Tween(this.overlay, {property: 'opacity', duration: 300});
103				this.close.addEvent('click', this.closefn.bind(this));
104				this.content.getChildren().removeClass('hover');
105				this.cbox.open = false;
106				if (this.options.overlayClose === true) {
107					this.overlay.setStyle('cursor', 'pointer').addEvent('click', this.closefn.bind(this));
108				}
109			}
110			var isIE = that.ieVersion();
111			if(isIE > 0 && isIE < 7){
112				this.events.windowResizeIE6 = this.events.windowScrollIE6 = function(){
113					that.overlay.setStyle({
114						'width': window.getWidth(),
115						'height': window.getHeight(),
116						'top': window.scrollTop(),
117						'left': window.scrollLeft()
118					});
119				};
120			}
121			elements.each(function(element){
122				element.colorbox = $extend({}, that.options);
123			});
124			elements.each(function(element, idx){
125				element.removeEvents('click').addEvent('click', function(e){
126					if(e){
127						e.stop();
128					}
129					that.setting = element.colorbox;
130					that.element = element;
131					if(!that.cbox.open){
132						that.cbox.open = true;
133						that.fireEvent('cbox_open');
134						that.close.innerHTML = that.setting.close;
135						that.overlay.setStyles({'opacity': that.setting.opacity, 'display': 'block'});
136						that.position(that.setSize(that.setting.initialWidth, 'x'), that.setSize(that.setting.initialHeight, 'y'), 0);
137						var isIE = that.ieVersion();
138						if(isIE > 0 && isIE < 7){
139							window.addEvent('resize', that.events.windowResizeIE6);
140							window.addEvent('scroll', that.events.windowScrollIE6);
141							that.events.windowScrollIE6();
142						}
143					}
144					element.blur();
145					that.load();
146				});
147			});
148		}		
149	},
150	setSize: function(size, dimension){
151		dimension = dimension === 'x' ? document.documentElement.clientWidth : document.documentElement.clientHeight;
152		return (typeof size === 'string') ? (size.match(/%/) ? (dimension / 100) * parseInt(size, 10) : parseInt(size, 10)) : size;
153	},
154	isImage: function(url){
155		return this.setting.photo ? true : url.match(/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i);
156	},
157	createDiv: function(id){
158		return new Element('div', { 'id': 'cbox' + id });
159	},
160	ieVersion: function(){
161		var rv = -1;
162		if (navigator.appName == 'Microsoft Internet Explorer'){
163			if (new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})").exec(navigator.userAgent) != null)
164			rv = parseFloat( RegExp.$1 );
165		}
166		return rv;
167	},
168	position: function (mWidth, mHeight, speed, loadedCallback) {	
169		var winHeight = document.documentElement.clientHeight,
170			posTop = winHeight / 2 - mHeight / 2,
171			posLeft = document.documentElement.clientWidth / 2 - mWidth / 2,
172			duration = 0,
173			that = this;
174		if (mHeight > winHeight) { posTop -=(mHeight - winHeight); }
175		if (posTop < 0) { posTop = 0; } 
176		if (posLeft < 0) { posLeft = 0; }
177		posTop += window.getScrollTop();
178		posLeft += window.getScrollLeft();
179		this.wrap.mWidth = mWidth - this.interfaceWidth;
180		this.wrap.mHeight = mHeight - this.interfaceHeight;
181		this.cbox.setStyle('display', 'block');
182		duration = (this.cbox.offsetWidth === mWidth && this.cbox.offsetHeight === mHeight) ? 0 : speed;
183		this.wrap.style.width = this.wrap.style.height = '9999px';
184		if(!this.cbox.fxs){
185			var fx = new Fx.Morph(this.cbox, {
186				duration: duration,
187				link: 'cancel'
188			});
189			fx.set  = function(now){				
190				if (typeof now == 'string') now = this.search(now);
191				for (var p in now) this.render(this.element, p, now[p], this.options.unit);
192				that.topBorder.style.width = that.bottomBorder.style.width = that.content.style.width = that.cbox.style.width;
193				that.loadingGraphic.style.height = that.loadingOverlay.style.height = that.content.style.height = that.leftBorder.style.height = that.rightBorder.style.height = that.cbox.style.height;
194			};
195			this.cbox.fxs = fx;
196		}
197		if(duration == 0){
198			this.cbox.setStyles({
199				height: this.wrap.mHeight,
200				width: this.wrap.mWidth,
201				top:posTop,
202				left:posLeft,
203				opacity: 1
204			});	
205			that.topBorder.style.width = that.bottomBorder.style.width = that.content.style.width = that.cbox.style.width;
206			that.loadingGraphic.style.height = that.loadingOverlay.style.height = that.content.style.height = that.leftBorder.style.height = that.rightBorder.style.height = that.cbox.style.height;			
207		//	this.wrap.style.width = (this.wrap.mWidth + this.interfaceWidth) + 'px';
208		//	this.wrap.style.height = (this.wrap.mHeight + this.interfaceHeight) + 'px';			
209			if(loadedCallback){
210				loadedCallback();
211			}
212		}else{
213			this.cbox.fxs.setOptions({duration: duration}).start({
214				height: this.wrap.mHeight,
215				width: this.wrap.mWidth,
216				top:posTop,
217				left:posLeft
218			}).chain(function(){
219				if(loadedCallback){
220					loadedCallback();
221				}
222			});
223		}
224	},
225	dimensions: function (object) {
226		if(!this.cbox.open){ return; }
227		window.removeEvent('resize', this.events.windowResize);
228		var width, height, topMargin, photo, speed = this.setting.transition === 'none' ? 0 : this.setting.speed, that = this;
229		try{
230			var cboxLoadedContent = $('cboxLoadedContent');
231			if(cboxLoadedContent){
232				cboxLoadedContent.dispose();
233			}
234		}catch(e){}
235		this.loaded = $(object).setStyle('display', 'block');
236		function exameWidth(){
237			if(that.setting.width){
238				width = that.maxWidth;
239			} else {
240				width = that.maxWidth && that.maxWidth < that.loaded.offsetWidth ? that.maxWidth : that.loaded.offsetWidth;
241			}
242			return width;
243		}
244		function exameHeight(){
245			if(that.setting.height){
246				height = that.maxHeight;
247			} else {
248				height = that.maxHeight && that.maxHeight < that.loaded.offsetHeight ? that.maxHeight : that.loaded.offsetHeight;
249			}
250			return height;
251		}
252		this.loaded.inject(document.body)
253			.setProperty('id', 'cboxLoadedContent')
254			.setStyle('width', exameWidth())
255			.setStyle('height', exameHeight())
256			.inject(this.content, 'top');
257		this.loaded.setStyle('display', 'none');
258		var isIE = this.ieVersion();
259		if (isIE > 0 && isIE < 7) {
260			var allselects = $$('select');
261			var cboxselects = $$('#colorbox select');
262			allselects.filter(function(select){
263				return cboxselects.indexOf(select) == -1;
264			}).setStyle('visibility', 'hidden');
265		}
266		photo = $('#cboxPhoto');
267		if (photo && this.setting.height) {
268			topMargin = (height - parseInt(photo.style.height, 10)) /2;
269			photo.style.marginTop = (topMargin > 0 ? topMargin : 0) + 'px';
270		}
271		function setPosition(s){
272			var mWidth = width + that.loadedWidth + that.interfaceWidth, mHeight = height + that.loadedHeight + that.interfaceHeight;
273			that.position(mWidth, mHeight, s, function(){
274				if (!that.cbox.open) {
275					return;
276				}
277				if (that.ieVersion() > 0){
278					if(photo){
279						new Fx.Tween(that.loaded, {property: 'opacity', duration: 100, wait: false}).start(1);
280					}
281					that.cbox.setStyle('filter', '');
282				}
283				that.content.getChildren().setStyle('display', 'block');
284				var cboxIframeTemp = $('cboxIframeTemp');
285					if(cboxIframeTemp){
286					new Element('iframe', {
287						'id': 'cboxIframe',
288						'name': 'iframe_' + new Date().getTime(),
289						'frameborder': 0,
290						'src': (that.setting.href || this.element.href)
291					}).insertAfter(cboxIframeTemp);
292					cboxIframeTemp.dispose();
293					cboxIframeTemp = null;
294				}
295				that.loadingOverlay.setStyle('display', 'none');
296				that.loadingGraphic.setStyle('display', 'none');
297				that.current.setStyle('display', 'none');
298				that.title.innerHTML = (that.setting.title || that.element.title);
299				that.fireEvent('cbox_complete');
300				if (that.setting.transition === 'fade'){
301					that.cbox.fx.setOptions({duration: speed}).start(1);
302				}
303				that.events.windowResize = function(){
304					that.position(mWidth, mHeight, 0);
305				};
306				window.addEvent('resize', that.events.windowResize);
307			});
308		}
309		if (that.setting.transition === 'fade') {
310			that.cbox.fx.setOptions({duration: speed}).start(0).chain(function(){setPosition(0);});
311		} else {
312			setPosition(speed);
313		}
314	},
315	
316	load: function(){
317		var height, width, href, loadingElement;
318		var cboxInlineTemp = $('cboxInlineTemp');
319		if(cboxInlineTemp && this.loaded){
320			this.loaded.getChildren().inject(cboxInlineTemp, 'before');
321			cboxInlineTemp.dispose();
322			cboxInlineTemp = null;
323		}
324		this.fireEvent('cbox_load');
325		height = this.setting.height ? this.setSize(this.setting.height, 'y') - this.loadedHeight - this.interfaceHeight : false;
326		width = this.setting.width ? this.setSize(this.setting.width, 'x') - this.loadedWidth - this.interfaceWidth : false;
327		this.href = this.setting.href || this.element.href;
328		var hrefElm = $(this.href.substring(1));
329		this.loadingOverlay.setStyle('display', 'block');
330		this.loadingGraphic.setStyle('display', 'block');
331		this.close.setStyle('display', 'block');
332		if(this.setting.maxHeight){
333			this.maxHeight = this.setting.maxHeight ? this.setSize(this.setting.maxHeight, 'y') - this.loadedHeight - this.interfaceHeight : false;
334			height = height && height < this.maxHeight ? height : this.maxHeight;
335		}
336		if(this.setting.maxWidth){
337			this.maxWidth = this.setting.maxWidth ? this.setSize(this.setting.maxWidth, 'x') - this.loadedWidth - this.interfaceWidth : false;
338			width = width && width < this.maxWidth ? width : this.maxWidth;
339		}
340		this.maxHeight = height;
341		this.maxWidth = width;
342		if(this.setting.inline){
343			this.createDiv('InlineTemp').setStyle('display', 'none').inject(hrefElm, 'before');
344			this.dimensions(new Element('div').adopt(hrefElm));
345		} else if (this.setting.iframe) {
346			this.dimensions(new Element('div').adopt(this.createDiv('IframeTemp')));
347		} else if (this.setting.html) {
348			dimensions(new Element('div', {innerHTML: this.setting.html}));
349		} else if (isImage(this.href)){
350			var loadingElement = new Image(), that = this;
351			loadingElement.onload = function(){
352				loadingElement.onload = null;
353				if((that.maxHeight || that.maxWidth) && that.setting.resize){
354					var width = loadingElement.width,
355						height = loadingElement.height,
356						percent = 0;
357					if( that.maxWidth && width > that.maxWidth ){
358						percent = (that.maxWidth - width) / width;
359						height += height * percent;
360						width += width * percent;
361						loadingElement.height = height;
362						loadingElement.width = width;
363					}
364					if( that.maxHeight && height > that.maxHeight ){
365						percent = (that.maxHeight - height) / height;
366						height += height * percent;
367						width += width * percent;
368						loadingElement.height = height;
369						loadingElement.width = width;
370					}
371				}
372				dimensions(new Element('div', {
373					styles: {
374						width: loadingElement.width,
375						height: loadingElement.height
376					}
377				}).adopt(loadingElement.height.setStyles({
378					width: loadingElement.width,
379					height:loadingElement.height,
380					display:"block",
381					margin:"auto",
382					border:0
383				}).setProperty('id', 'cboxPhoto')));
384				
385				if(that.ieVersion() == 7){
386					loadingElement.style.msInterpolationMode='bicubic';
387				}
388			};
389			loadingElement.src = this.href;
390		} 
391	},
392	closefn: function(){
393		document.getElementById("colorbox").style.display = "none";
394		var that = this;
395		this.fireEvent('cbox_close');
396		var cboxInlineTemp = $('cboxInlineTemp');
397		if(cboxInlineTemp && this.loaded){
398			this.loaded.getChildren().inject(cboxInlineTemp, 'before');
399		}
400		var isIE = this.ieVersion();
401		if (isIE > 0 && isIE < 7) {
402			var allselects = $$('select');
403			var cboxselects = $$('#colorbox select');
404			allselects.filter(function(select){
405				return cboxselects.indexOf(select) == -1;
406			}).setStyle('visibility', 'hidden');
407		}
408		this.cbox.open = false;
409		window.removeEvents('resize', this.events.windowResize);
410		var isIE = that.ieVersion();
411		if(isIE > 0 && isIE < 7){
412			window.removeEvents('resize', this.events.windowResizeIE6);
413			window.removeEvents('scroll', this.events.windowScrollIE6);		
414		}
415		this.overlay.setStyle('cursor', 'auto').fx.start(0).chain(function(){
416			that.overlay.setStyle('display','none');
417		});;
418		this.content.getChildren().setStyle('display', 'none');	
419		this.cbox.setProperty('className', '')
420			.fx.start(0).chain(function(){
421				var cboxLoadedContent = $('cboxLoadedContent');
422				if(cboxLoadedContent){
423					cboxLoadedContent.dispose();
424				}
425				that.loaded = null;
426			});
427	}
428});

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.