PageSourceSearch

https://rusteaco.ru/bitrix/js/main/core/core_fx.js

js rusteaco.ru collected 2026-10-03 22:49:06 UTC 16,538 bytes, 680 lines download raw bytes

1;(function(window){
2
3var defaultOptions = {
4	time: 1.0,
5	step: 0.05,
6	type: 'linear',
7
8	allowFloat: false
9}
10
11/*
12options: {
13	start: start value or {param: value, param: value}
14	finish: finish value or {param: value, param: value}
15	time: time to transform in seconds
16	type: linear|accelerated|decelerated|custom func name
17	callback,
18	callback_start,
19	callback_complete,
20
21	step: time between steps in seconds
22	allowFloat: false|true
23}
24*/
25BX.fx = function(options)
26{
27	this.options = options;
28
29	if (null != this.options.time)
30		this.options.originalTime = this.options.time;
31	if (null != this.options.step)
32		this.options.originalStep = this.options.step;
33
34	if (!this.__checkOptions())
35		return false;
36
37	this.__go = BX.delegate(this.go, this);
38
39	this.PARAMS = {};
40}
41
42BX.fx.prototype.__checkOptions = function()
43{
44	if (typeof this.options.start != typeof this.options.finish)
45		return false;
46
47	if (null == this.options.time) this.options.time = defaultOptions.time;
48	if (null == this.options.step) this.options.step = defaultOptions.step;
49	if (null == this.options.type) this.options.type = defaultOptions.type;
50	if (null == this.options.allowFloat) this.options.allowFloat = defaultOptions.allowFloat;
51
52	this.options.time *= 1000;
53	this.options.step *= 1000;
54
55	if (typeof this.options.start != 'object')
56	{
57		this.options.start = {_param: this.options.start};
58		this.options.finish = {_param: this.options.finish};
59	}
60
61	var i;
62	for (i in this.options.start)
63	{
64		if (null == this.options.finish[i])
65		{
66			this.options.start[i] = null;
67			delete this.options.start[i];
68		}
69	}
70
71	if (!BX.type.isFunction(this.options.type))
72	{
73		if (BX.type.isFunction(window[this.options.type]))
74			this.options.type = window[this.options.type];
75		else if (BX.type.isFunction(BX.fx.RULES[this.options.type]))
76			this.options.type = BX.fx.RULES[this.options.type];
77		else
78			this.options.type = BX.fx.RULES[defaultOptions.type];
79	}
80
81	return true;
82}
83
84BX.fx.prototype.go = function()
85{
86	var timeCurrent = new Date().valueOf();
87	if (timeCurrent < this.PARAMS.timeFinish)
88	{
89		for (var i in this.PARAMS.current)
90		{
91			this.PARAMS.current[i][0] = this.options.type.apply(this, [{
92				start_value: this.PARAMS.start[i][0],
93				finish_value: this.PARAMS.finish[i][0],
94				current_value: this.PARAMS.current[i][0],
95				current_time: timeCurrent - this.PARAMS.timeStart,
96				total_time: this.options.time
97			}]);
98		}
99
100		this._callback(this.options.callback);
101
102		if (!this.paused)
103			this.PARAMS.timer = setTimeout(this.__go, this.options.step);
104	}
105	else
106	{
107		this.stop();
108	}
109}
110
111BX.fx.prototype._callback = function(cb)
112{
113	var tmp = {};
114
115	cb = cb || this.options.callback;
116
117	for (var i in this.PARAMS.current)
118	{
119		tmp[i] = (this.options.allowFloat ? this.PARAMS.current[i][0] : Math.round(this.PARAMS.current[i][0])) + this.PARAMS.current[i][1];
120	}
121
122	return cb.apply(this, [null != tmp['_param'] ? tmp._param : tmp]);
123}
124
125BX.fx.prototype.start = function()
126{
127	var i,value, unit;
128
129	this.PARAMS.start = {};
130	this.PARAMS.current = {};
131	this.PARAMS.finish = {};
132
133	for (i in this.options.start)
134	{
135		value = +this.options.start[i];
136		unit = (this.options.start[i]+'').substring((value+'').length);
137		this.PARAMS.start[i] = [value, unit];
138		this.PARAMS.current[i] = [value, unit];
139		this.PARAMS.finish[i] = [+this.options.finish[i], unit];
140	}
141
142	this._callback(this.options.callback_start);
143	this._callback(this.options.callback);
144
145	this.PARAMS.timeStart = new Date().valueOf();
146	this.PARAMS.timeFinish = this.PARAMS.timeStart + this.options.time;
147	this.PARAMS.timer = setTimeout(BX.delegate(this.go, this), this.options.step);
148
149	return this;
150}
151
152BX.fx.prototype.pause = function()
153{
154	if (this.paused)
155	{
156		this.PARAMS.timer = setTimeout(this.__go, this.options.step);
157		this.paused = false;
158	}
159	else
160	{
161		clearTimeout(this.PARAMS.timer);
162		this.paused = true;
163	}
164}
165
166BX.fx.prototype.stop = function(silent)
167{
168	silent = !!silent;
169	if (this.PARAMS.timer)
170		clearTimeout(this.PARAMS.timer);
171
172	if (null != this.options.originalTime)
173		this.options.time = this.options.originalTime;
174	if (null != this.options.originalStep)
175		this.options.step = this.options.originalStep;
176
177	this.PARAMS.current = this.PARAMS.finish;
178	if (!silent) {
179		this._callback(this.options.callback);
180		this._callback(this.options.callback_complete);
181	}
182}
183
184/*
185type rules of animation
186 - linear - simple linear animation
187 - accelerated
188 - decelerated
189*/
190
191/*
192	params: {
193		start_value, finish_value, current_time, total_time
194	}
195*/
196BX.fx.RULES =
197{
198	linear: function(params)
199	{
200		return params.start_value + (params.current_time/params.total_time) * (params.finish_value - params.start_value);
201	},
202
203	decelerated: function(params)
204	{
205		return params.start_value + Math.sqrt(params.current_time/params.total_time) * (params.finish_value - params.start_value);
206	},
207
208	accelerated: function(params)
209	{
210		var q = params.current_time/params.total_time;
211		return params.start_value + q * q * (params.finish_value - params.start_value);
212	}
213}
214
215/****************** effects realizaion ************************/
216
217/*
218	type = 'fade' || 'scroll' || 'scale' || 'fold'
219*/
220
221BX.fx.hide = function(el, type, opts)
222{
223	el = BX(el);
224
225	if (typeof type == 'object' && null == opts)
226	{
227		opts = type;
228		type = opts.type
229	}
230
231	if (!BX.type.isNotEmptyString(type))
232	{
233		el.style.display = 'none';
234		return;
235	}
236
237	var fxOptions = BX.fx.EFFECTS[type](el, opts, 0);
238	fxOptions.callback_complete = function () {
239		if (opts.hide !== false)
240			el.style.display = 'none';
241
242		if (opts.callback_complete)
243			opts.callback_complete.apply(this, arguments);
244	}
245
246	return (new BX.fx(fxOptions)).start();
247}
248
249BX.fx.show = function(el, type, opts)
250{
251	el = BX(el);
252
253	if (typeof type == 'object' && null == opts)
254	{
255		opts = type;
256		type = opts.type
257	}
258
259	if (!opts) opts = {};
260
261	if (!BX.type.isNotEmptyString(type))
262	{
263		el.style.display = 'block';
264		return;
265	}
266
267	var fxOptions = BX.fx.EFFECTS[type](el, opts, 1);
268
269	fxOptions.callback_complete = function () {
270		if (opts.show !== false)
271			el.style.display = 'block';
272
273		if (opts.callback_complete)
274			opts.callback_complete.apply(this, arguments);
275	}
276
277	return (new BX.fx(fxOptions)).start();
278}
279
280BX.fx.EFFECTS = {
281	scroll: function(el, opts, action)
282	{
283		if (!opts.direction) opts.direction = 'vertical';
284
285		var param = opts.direction == 'horizontal' ? 'width' : 'height';
286
287		var val = parseInt(BX.style(el, param));
288		if (isNaN(val))
289		{
290			val = BX.pos(el)[param];
291		}
292
293		if (action == 0)
294			var start = val, finish = opts.min_height ? parseInt(opts.min_height) : 0;
295		else
296			var finish = val, start = opts.min_height ? parseInt(opts.min_height) : 0;
297
298		return {
299			'start': start,
300			'finish': finish,
301			'time': opts.time || defaultOptions.time,
302			'type': 'linear',
303			callback_start: function () {
304				if (BX.style(el, 'position') == 'static')
305					el.style.position = 'relative';
306
307				el.style.overflow = 'hidden';
308				el.style[param] = start + 'px';
309				el.style.display = 'block';
310			},
311			callback: function (val) {el.style[param] = val + 'px';}
312		}
313	},
314
315	fade: function(el, opts, action)
316	{
317		var fadeOpts = {
318			'time': opts.time || defaultOptions.time,
319			'type': action == 0 ? 'decelerated' : 'linear',
320			'start': action == 0 ? 1 : 0,
321			'finish': action == 0 ? 0 : 1,
322			'allowFloat': true
323		};
324
325		if (BX.browser.IsIE() && !BX.browser.IsIE9())
326		{
327			fadeOpts.start *= 100; fadeOpts.finish *= 100; fadeOpts.allowFloat = false;
328
329			fadeOpts.callback_start = function() {
330				el.style.display = 'block';
331				el.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity=" + fadeOpts.start + ")";
332			};
333
334			fadeOpts.callback = function (val) {
335				(el.filters['DXImageTransform.Microsoft.alpha']||el.filters.alpha).opacity = val;
336			}
337		}
338		else
339		{
340			fadeOpts.callback_start = function () {
341				el.style.display = 'block';
342			}
343
344			fadeOpts.callback = function (val) {
345				el.style.opacity = el.style.KhtmlOpacity = el.style.MozOpacity = val;
346			};
347		}
348
349		return fadeOpts;
350	},
351
352	fold: function (el, opts, action) // 'fold' is a combination of two consequential 'scroll' hidings.
353	{
354		if (action != 0) return;
355
356		var pos = BX.pos(el);
357		var coef = pos.height / (pos.width + pos.height);
358		var old_opts = {time: opts.time || defaultOptions.time, callback_complete: opts.callback_complete, hide: opts.hide};
359
360		opts.type = 'scroll';
361		opts.direction = 'vertical';
362		opts.min_height = opts.min_height || 10;
363		opts.hide = false;
364		opts.time = coef * old_opts.time;
365		opts.callback_complete = function()
366		{
367			el.style.whiteSpace = 'nowrap';
368
369			opts.direction = 'horizontal';
370			opts.min_height = null;
371
372			opts.time = old_opts.time - opts.time;
373			opts.hide = old_opts.hide;
374			opts.callback_complete = old_opts.callback_complete;
375
376			BX.fx.hide(el, opts);
377		}
378
379		return BX.fx.EFFECTS.scroll(el, opts, action);
380	},
381
382	scale: function (el, opts, action)
383	{
384		var val = {width: parseInt(BX.style(el, 'width')), height: parseInt(BX.style(el, 'height'))};
385		if (isNaN(val.width) || isNaN(val.height))
386		{
387			var pos = BX.pos(el)
388			val = {width: pos.width, height: pos.height};
389		}
390
391		if (action == 0)
392			var start = val, finish = {width: 0, height: 0};
393		else
394			var finish = val, start = {width: 0, height: 0};
395
396		return {
397			'start': start,
398			'finish': finish,
399			'time': opts.time || defaultOptions.time,
400			'type': 'linear',
401			callback_start: function () {
402				el.style.position = 'relative';
403				el.style.overflow = 'hidden';
404				el.style.display = 'block';
405				el.style.height = start.height + 'px';
406				el.style.width = start.width + 'px';
407			},
408			callback: function (val) {
409				el.style.height = val.height + 'px';
410				el.style.width = val.width + 'px';
411			}
412		}
413	}
414}
415
416// Color animation
417//
418// Set animation rule
419// BX.fx.colorAnimate.addRule('animationRule1',"#FFF","#faeeb4", "background-color", 100, 1, true);
420// BX.fx.colorAnimate.addRule('animationRule2',"#fc8282","#ff0000", "color", 100, 1, true);
421// Params: 1 - animation name, 2 - start color, 3 - end color, 4 - count step, 5 - delay each step, 6 - return color on end animation
422//
423// Animate color for element
424// BX.fx.colorAnimate(BX('element'), 'animationRule1,animationRule2');
425
426var defaultOptionsColorAnimation = {
427	arStack: {},
428	arRules: {},
429	globalAnimationId: 0
430}
431
432BX.fx.colorAnimate = function(element, rule, back)
433{
434	if (element == null)
435		return;
436
437	animationId = element.getAttribute('data-animation-id');
438	if (animationId == null)
439	{
440		animationId = defaultOptionsColorAnimation.globalAnimationId;
441		element.setAttribute('data-animation-id', defaultOptionsColorAnimation.globalAnimationId++);
442	}
443	var aRuleList = rule.split(/\s*,\s*/);
444
445	for (var j	= 0; j < aRuleList.length; j++)
446	{
447		rule = aRuleList[j];
448
449		if (!defaultOptionsColorAnimation.arRules[rule]) continue;
450
451		var i=0;
452
453		if (!defaultOptionsColorAnimation.arStack[animationId])
454		{
455			defaultOptionsColorAnimation.arStack[animationId] = {};
456		}
457		else if (defaultOptionsColorAnimation.arStack[animationId][rule])
458		{
459			i = defaultOptionsColorAnimation.arStack[animationId][rule].i;
460			clearInterval(defaultOptionsColorAnimation.arStack[animationId][rule].tId);
461		}
462
463		if ((i==0 && back) || (i==defaultOptionsColorAnimation.arRules[rule][3] && !back)) continue;
464
465		defaultOptionsColorAnimation.arStack[animationId][rule] = {'i':i, 'element': element, 'tId':setInterval('BX.fx.colorAnimate.run("'+animationId+'","'+rule+'")', defaultOptionsColorAnimation.arRules[rule][4]),'back':Boolean(back)};
466	}
467}
468
469BX.fx.colorAnimate.addRule = function (rule, startColor, finishColor, cssProp, step, delay, back)
470{
471	defaultOptionsColorAnimation.arRules[rule] = [
472		BX.util.hex2rgb(startColor),
473		BX.util.hex2rgb(finishColor),
474		cssProp.replace(/\-(.)/g,function(){return arguments[1].toUpperCase();}),
475		step,
476		delay || 1,
477		back || false
478	];
479};
480
481BX.fx.colorAnimate.run = function(animationId, rule)
482{
483	element = defaultOptionsColorAnimation.arStack[animationId][rule].element;
484
485    defaultOptionsColorAnimation.arStack[animationId][rule].i += defaultOptionsColorAnimation.arStack[animationId][rule].back?-1:1;
486 	var finishPercent = defaultOptionsColorAnimation.arStack[animationId][rule].i/defaultOptionsColorAnimation.arRules[rule][3];
487	var startPercent = 1 - finishPercent;
488
489	var aRGBStart = defaultOptionsColorAnimation.arRules[rule][0];
490	var aRGBFinish = defaultOptionsColorAnimation.arRules[rule][1];
491
492	element.style[defaultOptionsColorAnimation.arRules[rule][2]] = 'rgb('+
493	Math.floor( aRGBStart['r'] * startPercent + aRGBFinish['r'] * finishPercent ) + ','+
494	Math.floor( aRGBStart['g'] * startPercent + aRGBFinish['g'] * finishPercent ) + ','+
495	Math.floor( aRGBStart['b'] * startPercent + aRGBFinish['b'] * finishPercent ) +')';
496
497	if ( defaultOptionsColorAnimation.arStack[animationId][rule].i == defaultOptionsColorAnimation.arRules[rule][3] || defaultOptionsColorAnimation.arStack[animationId][rule].i ==0)
498	{
499		clearInterval(defaultOptionsColorAnimation.arStack[animationId][rule].tId);
500		if (defaultOptionsColorAnimation.arRules[rule][5])
501			BX.fx.colorAnimate(defaultOptionsColorAnimation.arStack[animationId][rule].element, rule, true);
502	}
503}
504
505
506/*
507options = {
508	delay: 100,
509	duration : 3000,
510	start : { scroll : document.body.scrollTop, left : 0, opacity :  100 },
511	finish : { scroll : document.body.scrollHeight, left : 500, opacity : 10 },
512	transition : BitrixAnimation.makeEaseOut(BitrixAnimation.transitions.quart),
513
514	step : function(state)
515	{
516		document.body.scrollTop = state.scroll;
517		button.style.left =  state.left + "px";
518		button.style.opacity =  state.opacity / 100;
519	},
520	complete : function()
521	{
522		button.style.background = "green";
523	}
524}
525
526options =
527{
528	delay : 20,
529	duration : 4000,
530	transition : BXAnimation.makeEaseOut(BXAnimation.transitions.quart),
531	progress : function(progress)
532	{
533		document.body.scrollTop = Math.round(topMax * progress);
534		button.style.left =  Math.round(leftMax * progress) + "px";
535		button.style.opacity =  (100 + Math.round((opacityMin - 100) * progress)) / 100;
536
537	},
538	complete : function()
539	{
540		button.style.background = "green";
541	}
542}
543*/
544
545BX.easing = function(options)
546{
547	this.options = options;
548	this.timer = null;
549};
550
551BX.easing.prototype.animate = function()
552{
553	if (!this.options || !this.options.start || !this.options.finish ||
554		typeof(this.options.start) != "object" || typeof(this.options.finish) != "object"
555		)
556		return null;
557
558	for (var propName in this.options.start)
559	{
560		if (typeof(this.options.finish[propName]) == "undefined")
561		{
562			delete this.options.start[propName];
563		}
564	}
565
566	this.options.progress = function(progress) {
567		var state = {};
568		for (var propName in this.start)
569			state[propName] = Math.round(this.start[propName] + (this.finish[propName] - this.start[propName]) * progress);
570
571		if (this.step)
572			this.step(state);
573	};
574
575	this.animateProgress();
576};
577
578BX.easing.prototype.stop = function(completed)
579{
580	if (this.timer)
581	{
582		clearInterval(this.timer);
583		this.timer = null;
584
585		if (completed)
586			this.options.complete && this.options.complete();
587	}
588};
589
590BX.easing.prototype.animateProgress = function()
591{
592	var start = new Date();
593	var delta = this.options.transition || BX.easing.transitions.linear;
594	var duration = this.options.duration || 1000;
595
596	this.timer = setInterval(BX.proxy(function() {
597
598		var progress = (new Date() - start) / duration;
599		if (progress > 1)
600			progress = 1;
601
602		this.options.progress(delta(progress));
603
604		if (progress == 1)
605			this.stop(true);
606
607	}, this), this.options.delay || 13);
608
609};
610
611BX.easing.makeEaseInOut = function(delta)
612{
613	return function(progress) {
614		if (progress < 0.5)
615			return delta( 2 * progress ) / 2;
616		else
617			return (2 - delta( 2 * (1-progress) ) ) / 2;
618	}
619};
620
621BX.easing.makeEaseOut = function(delta)
622{
623	return function(progress) {
624		return 1 - delta(1 - progress);
625	};
626};
627
628BX.easing.transitions = {
629
630	linear : function(progress)
631	{
632		return progress;
633	},
634
635	quad : function(progress)
636	{
637		return Math.pow(progress, 2);
638	},
639
640	cubic : function(progress) {
641		return Math.pow(progress, 3);
642	},
643
644	quart : function(progress)
645	{
646		return Math.pow(progress, 4);
647	},
648
649	quint : function(progress)
650	{
651		return Math.pow(progress, 5);
652	},
653
654	circ : function(progress)
655	{
656		return 1 - Math.sin(Math.acos(progress));
657	},
658
659	back : function(progress)
660	{
661		return Math.pow(progress, 2) * ((1.5 + 1) * progress - 1.5);
662	},
663
664	elastic: function(progress)
665	{
666		return Math.pow(2, 10 * (progress-1)) * Math.cos(20 * Math.PI * 1.5/3 * progress);
667	},
668
669	bounce : function(progress)
670	{
671		for(var a = 0, b = 1; 1; a += b, b /= 2) {
672			if (progress >= (7 - 4 * a) / 11) {
673				return -Math.pow((11 - 6 * a - 11 * progress) / 4, 2) + Math.pow(b, 2);
674			}
675		}
676	}};
677
678
679})(window);
680

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.