Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var arpExpand = 'ARP' + arpNow(), arpCache = {};
- if (!window._ua) var _ua = navigator.userAgent.toLowerCase();
- if (!window.locDomain) var locDomain = location.host.toString().match(/[a-zA-Z]+\.[a-zA-Z]+\.?$/)[0];
- window.locHost = location.host;
- window.locProtocol = location.protocol;
- window.__debugMode = true;
- var browser = {
- version: (_ua.match( /.+(?:me|ox|on|rv|it|era|opr|ie|edge)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
- opera: (/opera/i.test(_ua) || /opr/i.test(_ua)),
- vivaldi: /vivaldi/i.test(_ua),
- msie: (/msie/i.test(_ua) && !/opera/i.test(_ua) || /trident\//i.test(_ua)) || /edge/i.test(_ua),
- msie6: (/msie 6/i.test(_ua) && !/opera/i.test(_ua)),
- msie7: (/msie 7/i.test(_ua) && !/opera/i.test(_ua)),
- msie8: (/msie 8/i.test(_ua) && !/opera/i.test(_ua)),
- msie9: (/msie 9/i.test(_ua) && !/opera/i.test(_ua)),
- msie_edge: (/edge/i.test(_ua) && !/opera/i.test(_ua)),
- mozilla: /firefox/i.test(_ua),
- chrome: /chrome/i.test(_ua) && !/edge/i.test(_ua),
- safari: (!(/chrome/i.test(_ua)) && /webkit|safari|khtml/i.test(_ua)),
- iphone: /iphone/i.test(_ua),
- ipod: /ipod/i.test(_ua),
- iphone4: /iphone.*OS 4/i.test(_ua),
- ipod4: /ipod.*OS 4/i.test(_ua),
- ipad: /ipad/i.test(_ua),
- android: /android/i.test(_ua),
- bada: /bada/i.test(_ua),
- mobile: /iphone|ipod|ipad|opera mini|opera mobi|iemobile|android/i.test(_ua),
- msie_mobile: /iemobile/i.test(_ua),
- safari_mobile: /iphone|ipod|ipad/i.test(_ua),
- opera_mobile: /opera mini|opera mobi/i.test(_ua),
- opera_mini: /opera mini/i.test(_ua),
- mac: /mac/i.test(_ua),
- search_bot: /(yandex|google|stackrambler|aport|slurp|msnbot|bingbot|twitterbot|ia_archiver|facebookexternalhit)/i.test(_ua)
- };
- var ajax = {
- init: function() {
- var r = false;
- try
- {
- if (r = new XMLHttpRequest()) {
- ajax.req = function() { return new XMLHttpRequest(); }
- return;
- }
- } catch(e) {}
- if (!ajax.req) {
- location.replace('/badbrowser.php');
- }
- },
- getreq: function() {
- if(!ajax.req) ajax.init();
- return ajax.req();
- },
- plainget: function(url, successHandler) {
- var r = ajax.getreq();
- r.onreadystatechange = function() {
- if(r.readyState == 4)
- successHandler && successHandler(JSON.parse(r.responseText));
- }
- r.open('POST', url, true);
- r.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- r.send('ajax_req=1');
- return r;
- },
- modalget: function(url, successHandler) {
- var r = ajax.getreq();
- r.onreadystatechange = function() {
- if(r.readyState == 4)
- successHandler && successHandler(JSON.parse(r.responseText));
- }
- r.open('POST', url, true);
- r.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- r.send('ajax_req=1&modality=1');
- return r;
- },
- getjson: function(method, params, successHandler) {
- var r = ajax.getreq();
- var data = null;
- r.open('GET', '/methods/' + method + '.php?' + toURL(params), true);
- r.onreadystatechange = function() {
- if(r.readyState == 4) {
- data = JSON.parse(r.responseText);
- successHandler && successHandler(data);
- }
- }
- r.send();
- }
- }
- var stManager = {
- getPage: function(loc, callback) {
- loc = loc.replace(/^\/|\/$/g, '');
- if(navMap[loc] && navMap[loc][1] && !navMap[loc][0]) return stManager.add(navMap[loc][1], callback);
- for(let key in navMap) if((new RegExp('^'+key+'$')).test(loc) && navMap[key][0] && navMap[key][1])
- return stManager.add(navMap[key][1], callback);
- return callback && callback();
- },
- find: function(file) {
- let found = false, pattern = new RegExp(file.replace(/\?.*/, ''));
- if(file.match(/\.css/)) elsFunc(sel('link'), function(el) { if(el.getAttribute('href') && el.getAttribute('href').match(pattern)) found = true; });
- else elsFunc(sel('script'), function(el) { if(el.getAttribute('src') && el.getAttribute('src').match(pattern)) found = true; });
- return found;
- },
- add: function(files, callback) {
- if(!isArray(files)) files = [files];
- let link = geByTag('link', document.head);
- let script = geByTag('script', document.head);
- each(files, function(i, file) {
- if(stManager.find(file)) return stManager.done(files, file, callback);
- if(file.match(/\.css/)) {
- var css = document.createElement('link');
- css.rel = 'stylesheet';
- css.type = 'text/css';
- css.href = '/css/' + file + '?' + conf.version;
- css.onload = function() { stManager.done(files, file, callback); };
- document.head.insertBefore(css, link[link.length - 1]);
- } else {
- var js = document.createElement('script');
- js.type = 'text/javascript';
- js.src = '/js/al/' + file + '?' + conf.version;
- js.onload = function() { stManager.done(files, file, callback); };
- document.head.insertBefore(js, script[script.length - 1]);
- }
- });
- },
- addBody: function(files, callback) {
- if(!isArray(files)) files = [files];
- let link = geByTag('link', document.body);
- let script = geByTag('script', document.body);
- each(files, function(i, file) {
- if(stManager.find(file)) return stManager.done(files, file, callback);
- if(file.match(/\.css/)) {
- var css = document.createElement('link');
- css.rel = 'stylesheet';
- css.type = 'text/css';
- css.href = '/css/' + file + '?' + conf.version;
- document.body.insertBefore(css, link[link.length - 1]);
- } else {
- var js = document.createElement('script');
- js.type = 'text/javascript';
- js.src = '/js/al/' + file + '?' + conf.version;
- document.body.insertBefore(js, script[script.length - 1]);
- }
- });
- },
- done: function(files, file, callback) {
- stManager.loaded.push(file);
- if(files.length == stManager.loaded.length) {
- stManager.loaded = [];
- callback && callback();
- }
- },
- loaded: []
- }
- var nav = {
- go: function(loc, ev, opts) {
- if(ev) ev.preventDefault();
- if(typeof loc != 'string') loc = loc.getAttribute('href');
- opts = opts || {};
- nav.last_loc = location.pathname + location.search;
- if(!nav.isLoad) {
- nav.isLoad = true;
- if(nav.last_loc != loc) history.pushState(null, null, loc);
- document.body.className = 'progress';
- topNotifier.hide();
- ajax.plainget(loc, function(data) {
- document.title = data.title;
- elsRem(sel('#aj'));
- data.meta.forEach(function(obj) {
- let meta = document.createElement('meta'); meta.id = 'aj';
- for(let prop in obj) meta.setAttribute(prop, obj[prop]);
- document.head.insertBefore(meta, sel('meta')[0]);
- });
- stManager.getPage(loc, function() {
- document.body.removeAttribute('class');
- ge('page_wrapper').innerHTML = data.body;
- ge('scroll_fix_wrap').scrollTop = 0;
- page.path(loc);
- nav.isLoad = false;
- });
- });
- }
- },
- link: function(loc, ev, opts) {
- opts = opts || {};
- if(ev) ev.preventDefault();
- if(typeof loc != 'string') loc = loc.getAttribute('href');
- if(!nav.isLoad) {
- loc = loc.replace(new RegExp('^(' + locProtocol + '//' + locHost + ')?/?', 'i'), '');
- if(opts.curWindow) return window.location.assign(loc);
- window.open(loc);
- }
- },
- isLoad: false,
- last_loc: null
- }
- var modality = {
- show: function(loc, ev, loaded) {
- if(ev) ev.preventDefault();
- if(typeof loc != 'string') loc = loc.getAttribute('href');
- document.body.className = 'progress';
- topNotifier.hide();
- ajax.modalget(loc, function(data) {
- document.body.removeAttribute('class');
- document.body.style.overflow = 'hidden';
- stManager.getPage(loc, function() {
- setStyle(ge('modal_bg'), {visibility: 'visible', opacity: 1}), setStyle(ge('modal_wrap'), {visibility: 'visible', opacity: 1});
- ge('modal_wrap').innerHTML = data.body;
- eventFunc(document.body, 'click', '.modal-box', modality.hide);
- page.path(loc);
- modality.active = true;
- loaded && loaded();
- onBodyResize();
- });
- });
- },
- hide: function() {
- if(modality.active) {
- document.body.style.overflow = '';
- ge('modal_wrap').innerHTML = '';
- ge('modal_bg').removeAttribute('style'),
- ge('modal_wrap').removeAttribute('style');
- modality.active = false;
- } return;
- },
- active: false
- }
- var dd = {
- init: function() {
- elsFunc(sel('.dropdown-select'), function(el) {
- var selectElement = sel('select[id="' + el.getAttribute('for') + '"]', false, el.parentNode);
- if(selectElement) {
- if(getComputedStyle(el.parentNode)['position'] == 'static') el.parentNode.style.position = 'relative';
- var obj = sel('option[value="' + selectElement.value + '"]', false, selectElement);
- el.innerHTML = obj ? obj.innerHTML : selectElement.value;
- var ddlist = document.createElement('div');
- var identifier = 0;
- ddlist.className = 'dropdown-variants';
- ddlist.style.width = el.offsetWidth * 0.93;
- ddlist.style.left = el.offsetWidth * 0.035;
- ddlist.style.top = el.offsetTop + el.offsetHeight;
- ddlist.setAttribute('id', el.getAttribute('for'));
- elsFunc(sel('option', 1, selectElement), function(val) {
- let option = document.createElement('div');
- for(let i = 0; i < val.attributes.length; i++) {
- if(val.attributes[i].name == 'class' || val.attributes[i].name == 'id') continue;
- option.setAttribute(val.attributes[i].name, val.attributes[i].value);
- if(val.attributes[i].name.substr(0, 2) != 'on') {
- option[val.attributes[i].name] = val[val.attributes[i].name];
- }
- }
- option.setAttribute('id', (identifier + ' ' + (val.getAttribute('id') || '')).replace(/ $/, ''));
- option.className = ('dropdown-option ' + val.className).replace(/ $/, '');
- option.innerHTML = val.innerHTML;
- if(!val.disabled) ddlist.appendChild(option);
- identifier++;
- }), el.parentNode.insertAdjacentHTML('beforeend', ddlist.outerHTML);
- }
- el.addEventListener('transitionend', function() {
- if(this.offsetHeight == 0) this.style.display = 'none';
- });
- el.addEventListener('click', function() {
- var dropdown = sel('.dropdown-variants[id="' + this.getAttribute('for') + '"]', false, this.parentNode);
- dd.toggle(dropdown);
- });
- });
- elsFunc(sel('.dropdown-option'), function(el) { el.addEventListener('click', function() {
- var selectObject = sel('select[id="' + this.parentNode.getAttribute('id') + '"]', false, this.parentNode.parentNode);
- var optionNum = parseInt(this.getAttribute('id'));
- selectObject.value = sel('option', 1, selectObject)[optionNum].value;
- selectObject.dispatchEvent(new Event('change'));
- var obj = sel('option[value="' + selectObject.value + '"]', false, selectObject);
- sel('.dropdown-select[for="' + this.parentNode.getAttribute('id') + '"]', false, this.parentNode.parentNode).innerHTML = obj ? obj.innerHTML : selectObject.value;
- dd.hide(this.parentNode);
- })});
- },
- toggle: function(dropdown) {
- if(dropdown.offsetHeight == 0) {
- dd.show(dropdown);
- } else {
- dd.hide(dropdown);
- }
- },
- show: function(dropdown) {
- dropdown.style.display = 'block';
- var ddMaxHeight = 0;
- elsFunc(sel('*', 1, dropdown), function(el) {
- ddMaxHeight += el.offsetHeight;
- }), dropdown.style.maxHeight = ddMaxHeight;
- },
- hide: function(dropdown) {
- dropdown.style.maxHeight = 0;
- }
- }
- var topNotifier = {
- show: function(el, ev) {
- var nt = geByClass1('top-notify-wrap', ge('page_header_wrap')),
- ntCount = geByClass1('top-notify-count', ge('page_header_wrap')),
- ntList = geByClass1('top-notify-list', nt),
- ntEmpty = geByClass1('top-notify-empty', nt),
- ntResult = geByClass1('notify-result', nt),
- ntSpinner = geByClass1('spinner-load', nt);
- if(!cookie('i')) return;
- if(nt.classList.contains('shown')) return nt.classList.remove('shown');
- if(!isVisible(ntSpinner)) show(ntSpinner);
- nt.classList.add('shown');
- ntResult.innerHTML = '', ntList.innerHTML = '';
- eventFunc(document.body, 'click', '.user-menu-notify', topNotifier.hide);
- ajax.getjson('account.getNotify', { i: cookie('i') }, function(data) {
- if(isVisible(ntEmpty)) hide(ntEmpty);
- if(isVisible(ntSpinner)) hide(ntSpinner);
- if(data.error) return msgBox(ntResult, 'err', data.error.err_msg);
- if(data.success == 0) return show(ntEmpty);
- show(ntList);
- data.success.forEach(data => {
- if(data.sender && data.comment) ntList.insertAdjacentHTML('afterbegin', '<div class="top-notify-item'+(parseInt(data.seen) ? '':' __new')+'"><div class="top-item-avatar" style="background: url(\'/images/avatars/'+data.sender.avatar+'.jpg\');"></div><div class="top-item-content"><div class="top-item-text">'+pa(data.text, '<a href="/'+data.sender.server+'/'+data.sender.name+'" onClick="return nav.go(this, event);">'+data.sender.name+'</a>', '<a href="'+data.comment.page+'" onClick="return nav.go(this, event);">'+data.comment.text+'</a>')+'</div></div></div>');
- elsFunc(sel('.__new'), function(el) {
- ntCount.innerHTML = parseInt(ntCount.innerHTML) - 1;
- if(parseInt(ntCount.innerHTML) < 1) hide(ntCount);
- else show(ntCount);
- setTimeout(function() { el.classList.remove('__new'); }, 2000);
- });
- });
- });
- },
- hide: function() {
- var nt = geByClass1('top-notify-wrap', ge('page_header_wrap'));
- if(!nt) return;
- if(!nt.classList.contains('shown')) return;
- nt.classList.remove('shown');
- }
- }
- // FX
- var Fx = {
- Transitions: {
- linear: function(t, b, c, d) { return c*t/d + b; },
- sineInOut: function(t, b, c, d) { return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; },
- halfSine: function(t, b, c, d) { return c * (Math.sin(Math.PI * (t/d) / 2)) + b; },
- easeOutBack: function(t, b, c, d) { var s = 1.70158; return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; },
- easeInCirc: function(t, b, c, d) { return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b; },
- easeOutCirc: function(t, b, c, d) { return c * Math.sqrt(1 - (t=t/d-1)*t) + b; },
- easeInQuint: function(t, b, c, d) { return c*(t/=d)*t*t*t*t + b; },
- easeOutQuint: function(t, b, c, d) { return c*((t=t/d-1)*t*t*t*t + 1) + b; },
- easeOutCubic: function(t, b, c, d) { return c*((t=t/d-1)*t*t + 1) + b;},
- swiftOut: function(t, b, c, d) { return c * cubicBezier(0.4, 0, 0.22, 1, t/d, 4/d) + b; }
- },
- Attrs: [
- [ 'height', 'marginTop', 'marginBottom', 'paddingTop', 'paddingBottom' ],
- [ 'width', 'marginLeft', 'marginRight', 'paddingLeft', 'paddingRight' ],
- [ 'opacity', 'left', 'top' ]
- ],
- Timers: [],
- TimerId: null
- }, fx = Fx;
- Fx.Base = function(el, options, name) {
- this.el = ge(el);
- this.name = name;
- this.options = extend({
- onStep: function(){},
- onComplete: function() {},
- transition: options.transition || Fx.Transitions.sineInOut,
- duration: 500
- }, options || {});
- }
- Fx.Base.prototype = {
- start: function(from, to){
- this.from = from;
- this.to = to;
- this.time = arpNow();
- this.isTweening = true;
- var self = this;
- function t(gotoEnd) {
- return self.step(gotoEnd);
- }
- t.el = this.el;
- if (t() && Fx.Timers.push(t) && !Fx.TimerId) {
- Fx.TimerId = setInterval(function() {
- var timers = Fx.Timers, l = timers.length;
- for (var i = 0; i < l; i++) {
- if (!timers[i]()) {
- timers.splice(i--, 1);
- l--;
- }
- }
- if (!l) {
- clearInterval(Fx.TimerId);
- Fx.TimerId = null;
- }
- }, 13);
- }
- return this;
- },
- stop: function(gotoEnd) {
- var timers = Fx.Timers;
- for (var i = timers.length - 1; i >= 0; i--) {
- if (timers[i].el == this.el ) {
- if (gotoEnd) {
- timers[i](true);
- }
- timers.splice(i, 1);
- }
- }
- this.isTweening = false;
- },
- step: function(gotoEnd) {
- var time = arpNow();
- if (!gotoEnd && time < this.time + this.options.duration) {
- this.cTime = time - this.time;
- this.now = {};
- for (p in this.to) {
- if (isArray(this.to[p])) {
- var color = [], j;
- for (j = 0; j < 3; j++) {
- if (this.from[p] === undefined || this.to[p] === undefined) {
- return false;
- }
- color.push(Math.min(parseInt(this.compute(this.from[p][j], this.to[p][j])), 255));
- }
- this.now[p] = color;
- } else {
- this.now[p] = this.compute(this.from[p], this.to[p]);
- if (this.options.discrete) this.now[p] = intval(this.now[p]);
- }
- }
- this.update();
- return true;
- } else {
- setTimeout(this.options.onComplete.bind(this, this.el), 10);
- this.now = extend(this.to, this.options.orig);
- this.update();
- if (this.options.hide) hide(this.el);
- this.isTweening = false;
- return false;
- }
- },
- compute: function(from, to){
- var change = to - from;
- return this.options.transition(this.cTime, from, change, this.options.duration);
- },
- update: function(){
- this.options.onStep(this.now);
- for (var p in this.now) {
- if (isArray(this.now[p])) setStyle(this.el, p, 'rgb(' + this.now[p].join(',') + ')');
- else this.el[p] != undefined ? (this.el[p] = this.now[p]) : setStyle(this.el, p, this.now[p]);
- }
- },
- cur: function(name, force){
- if (this.el[name] != null && (!this.el.style || this.el.style[name] == null))
- return this.el[name];
- return parseFloat(getStyle(this.el, name, force)) || 0;
- }
- };
- function genFx(type, num) {
- var obj = {};
- each(Fx.Attrs.concat.apply([], Fx.Attrs.slice(0, num)), function() {
- obj[this] = type;
- });
- return obj;
- }
- // DOM
- function rand(mi, ma) { return Math.random() * (ma - mi + 1) + mi; }
- function irand(mi, ma) { return Math.floor(rand(mi, ma)); }
- function isUndefined(obj) { return typeof obj === 'undefined' };
- function isFunction(obj) {return obj && Object.prototype.toString.call(obj) === '[object Function]'; }
- function isArray(obj) { return Object.prototype.toString.call(obj) === '[object Array]'; }
- function isString(obj) { return typeof obj === 'string'; }
- function isObject(obj) { return Object.prototype.toString.call(obj) === '[object Object]'; }
- function isEmpty(o) { if(Object.prototype.toString.call(o) !== '[object Object]') {return false;} for(var i in o){ if(o.hasOwnProperty(i)){return false;} } return true; }
- function arpNow() { return +new Date; }
- function arpImage() { return window.Image ? (new Image()) : ce('img'); } // IE8 workaround
- function trim(text) { return (text || '').replace(/^\s+|\s+$/g, ''); }
- function stripHTML(text) { return text ? text.replace(/<(?:.|\s)*?>/g, '') : ''; }
- function escapeRE(s) { return s ? s.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1') : ''; }
- function boundingRectEnabled(obj) { return (typeof obj.getBoundingClientRect !== 'undefined'); }
- function intval(value) {
- if (value === true) return 1;
- return parseInt(value) || 0;
- }
- function floatval(value) {
- if (value === true) return 1;
- return parseFloat(value) || 0;
- }
- function positive(value) {
- value = intval(value);
- return value < 0 ? 0 : value;
- }
- function isNumeric(value) {
- return !isNaN(value);
- }
- function isVisible(elem) {
- elem = ge(elem);
- if (!elem || !elem.style) return false;
- return getStyle(elem, 'display') != 'none';
- }
- function ge(el) {
- return (typeof el == 'string' || typeof el == 'number') ? document.getElementById(el) : el;
- }
- function geByTag(searchTag, node) {
- node = ge(node) || document;
- return node.getElementsByTagName(searchTag);
- }
- function gpeByClass(className, elem, stopElement) {
- elem = ge(elem);
- if (!elem) return null;
- while (stopElement !== elem && (elem = elem.parentNode)) {
- if (hasClass(elem, className)) return elem;
- }
- return null;
- }
- function geByClass1(searchClass, node, tag) {
- node = ge(node) || document;
- tag = tag || '*';
- return node.querySelector && node.querySelector(tag + '.' + searchClass) || geByClass(searchClass, node, tag)[0];
- }
- function geByClass(searchClass, node, tag) {
- node = ge(node) || document;
- tag = tag || '*';
- var classElements = [];
- if (node.querySelectorAll && tag != '*') {
- return node.querySelectorAll(tag + '.' + searchClass);
- }
- if (node.getElementsByClassName) {
- var nodes = node.getElementsByClassName(searchClass);
- if (tag != '*') {
- tag = tag.toUpperCase();
- for (var i = 0, l = nodes.length; i < l; ++i) {
- if (nodes[i].tagName.toUpperCase() == tag) {
- classElements.push(nodes[i]);
- }
- }
- } else {
- classElements = Array.prototype.slice.call(nodes);
- }
- return classElements;
- }
- var els = geByTag(tag, node);
- var pattern = new RegExp('(^|\\s)' + searchClass + '(\\s|$)');
- for (var i = 0, l = els.length; i < l; ++i) {
- if (pattern.test(els[i].className)) {
- classElements.push(els[i]);
- }
- }
- return classElements;
- }
- function extend() {
- var a = arguments, target = a[0] || {}, i = 1, l = a.length, deep = false, options;
- if (typeof target === 'boolean') {
- deep = target;
- target = a[1] || {};
- i = 2;
- }
- if (typeof target !== 'object' && !isFunction(target)) target = {};
- for (; i < l; ++i) {
- if ((options = a[i]) != null) {
- for (var name in options) {
- var src = target[name], copy = options[name];
- if (target === copy) continue;
- if (deep && copy && typeof copy === 'object' && !copy.nodeType) {
- target[name] = extend(deep, src || (copy.length != null ? [] : {}), copy);
- } else if (copy !== undefined) {
- target[name] = copy;
- }
- }
- }
- }
- return target;
- }
- function getRGB(color) {
- var result;
- if (color && isArray(color) && color.length == 3)
- return color;
- if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
- return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
- if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
- return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
- if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
- return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
- if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
- return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
- }
- function getColor(elem, attr) {
- var color;
- do {
- color = getStyle(elem, attr);
- if (!color.indexOf('rgba')) color = '';
- if (color != '' && color != 'transparent' || elem.nodeName.toLowerCase() == 'body') {
- break;
- }
- attr = 'backgroundColor';
- } while (elem = elem.parentNode);
- return getRGB(color);
- }
- function setStyle(elem, name, value){
- elem = ge(elem);
- if (!elem) return;
- if (typeof name == 'object') return each(name, function(k, v) { setStyle(elem,k,v); });
- if (name == 'opacity') {
- if (browser.msie) {
- if ((value + '').length) {
- if (value !== 1) {
- elem.style.filter = 'alpha(opacity=' + value * 100 + ')';
- } else {
- elem.style.filter = '';
- }
- } else {
- elem.style.cssText = elem.style.cssText.replace(/filter\s*:[^;]*/gi, '');
- }
- elem.style.zoom = 1;
- };
- elem.style.opacity = value;
- } else {
- try {
- var isN = typeof(value) == 'number';
- if (isN && (/height|width/i).test(name)) value = Math.abs(value);
- elem.style[name] = isN && !(/z-?index|font-?weight|opacity|zoom|line-?height/i).test(name) ? value + 'px' : value;
- } catch(e) { debugLog('setStyle error: ', [name, value], e); }
- }
- }
- function getStyle(elem, name, force) {
- elem = ge(elem);
- if (isArray(name)) { var res = {}; each(name, function(i,v){res[v] = getStyle(elem, v);}); return res; }
- if (!elem) return '';
- if (force === undefined) {
- force = true;
- }
- if (!force && name == 'opacity' && browser.msie) {
- var filter = elem.style['filter'];
- return filter ? (filter.indexOf('opacity=') >= 0 ?
- (parseFloat(filter.match(/opacity=([^)]*)/)[1] ) / 100) + '' : '1') : '';
- }
- if (!force && elem.style && (elem.style[name] || name == 'height')) {
- return elem.style[name];
- }
- var ret, defaultView = document.defaultView || window;
- if (defaultView.getComputedStyle) {
- name = name.replace(/([A-Z])/g, '-$1').toLowerCase();
- var computedStyle = defaultView.getComputedStyle(elem, null);
- if (computedStyle) {
- ret = computedStyle.getPropertyValue(name);
- }
- } else if (elem.currentStyle) {
- if (name == 'opacity' && browser.msie) {
- var filter = elem.currentStyle['filter'];
- return filter && filter.indexOf('opacity=') >= 0 ?
- (parseFloat(filter.match(/opacity=([^)]*)/)[1]) / 100) + '' : '1';
- }
- var camelCase = name.replace(/\-(\w)/g, function(all, letter){
- return letter.toUpperCase();
- });
- ret = elem.currentStyle[name] || elem.currentStyle[camelCase];
- if (ret == 'auto') {
- ret = 0;
- }
- ret = (ret + '').split(' ');
- each(ret, function(i,v) {
- if (!/^\d+(px)?$/i.test(v) && /^\d/.test(v)) {
- var style = elem.style, left = style.left, rsLeft = elem.runtimeStyle.left;
- elem.runtimeStyle.left = elem.currentStyle.left;
- style.left = v || 0;
- ret[i] = style.pixelLeft + 'px';
- style.left = left;
- elem.runtimeStyle.left = rsLeft;
- }
- });
- ret = ret.join(' ');
- }
- if (force && (name == 'width' || name == 'height')) {
- var ret2 = getSize(elem, true)[({'width': 0, 'height': 1})[name]];
- ret = (intval(ret) ? Math.max(floatval(ret), ret2) : ret2) + 'px';
- }
- return ret;
- }
- function data(elem, name, data) {
- if (!elem) return false;
- var id = elem[arpExpand], undefined;
- if (data !== undefined) {
- if (!arpCache[id]) arpCache[id] = {};
- arpCache[id][name] = data;
- }
- return name ? arpCache[id] && arpCache[id][name] : id;
- }
- function animate(el, params, speed, callback) {
- el = ge(el);
- if (!el) return;
- var _cb = isFunction(callback) ? callback : function() {};
- var options = extend({}, typeof speed == 'object' ? speed : {duration: speed, onComplete: _cb});
- var fromArr = {}, toArr = {}, visible = isVisible(el), self = this, p;
- options.orig = {};
- params = clone(params);
- if (params.discrete) {
- options.discrete = 1;
- delete(params.discrete);
- }
- if (browser.iphone) options.duration = 0;
- var tween = data(el, 'tween'), i, name, toggleAct = visible ? 'hide' : 'show';
- if (tween && tween.isTweening) {
- options.orig = extend(options.orig, tween.options.orig);
- tween.stop(false);
- if (tween.options.show) toggleAct = 'hide';
- else if (tween.options.hide) toggleAct = 'show';
- }
- for (p in params) {
- if (!tween && (params[p] == 'show' && visible || params[p] == 'hide' && !visible)) {
- return options.onComplete.call(this, el);
- }
- if ((p == 'height' || p == 'width') && el.style) {
- if (!params.overflow) {
- if (options.orig.overflow == undefined) {
- options.orig.overflow = getStyle(el, 'overflow');
- }
- el.style.overflow = 'hidden';
- }
- if (!hasClass(el, 'inl_bl') && el.tagName != 'TD') {
- el.style.display = 'block';
- }
- }
- if (/show|hide|toggle/.test(params[p])) {
- if (params[p] == 'toggle') {
- params[p] = toggleAct;
- }
- if (params[p] == 'show') {
- var from = 0;
- options.show = true;
- if (options.orig[p] == undefined) {
- options.orig[p] = getStyle(el, p, false) || '';
- setStyle(el, p, 0);
- }
- var o = options.orig[p];
- var old = el.style[p];
- el.style[p] = o;
- params[p] = parseFloat(getStyle(el, p, true));
- el.style[p] = old;
- if (p == 'height' && browser.msie && !params.overflow) {
- el.style.overflow = 'hidden';
- }
- } else {
- if (options.orig[p] == undefined) {
- options.orig[p] = getStyle(el, p, false) || '';
- }
- options.hide = true;
- params[p] = 0;
- }
- }
- }
- if (options.show && !visible) {
- show(el);
- }
- tween = new Fx.Base(el, options);
- each(params, function(name, to) {
- if(/backgroundColor|borderBottomColor|borderLeftColor|borderRightColor|borderTopColor|color|borderColor|outlineColor/.test(name)) {
- var p = (name == 'borderColor') ? 'borderTopColor' : name;
- from = getColor(el, p);
- to = getRGB(to);
- if (from === undefined) return;
- } else {
- var parts = to.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
- start = tween.cur(name, true) || 0;
- if (parts) {
- to = parseFloat(parts[2]);
- if (parts[1]) {
- to = ((parts[1] == '-=' ? -1 : 1) * to) + to;
- }
- }
- from = tween.cur(name, true);
- if (from == 0 && (name == 'width' || name == 'height'))
- from = 1;
- if (name == 'opacity' && to > 0 && !visible) {
- setStyle(el, 'opacity', 0);
- from = 0;
- show(el);
- }
- }
- if (from != to || (isArray(from) && from.join(',') == to.join(','))) {
- fromArr[name] = from;
- toArr[name] = to;
- }
- });
- tween.start(fromArr, toArr);
- data(el, 'tween', tween);
- return tween;
- }
- function getXYRect(obj, notBounding) {
- var rect;
- if (notBounding && getStyle(obj, 'display') == 'inline') {
- var rects = obj.getClientRects();
- rect = rects && rects[0] || obj.getBoundingClientRect();
- } else {
- rect = obj.getBoundingClientRect();
- }
- return rect;
- }
- function getXY(obj, forFixed) {
- obj = ge(obj);
- if (!obj) return [0,0];
- var docElem, win,
- rect = {top: 0, left: 0},
- doc = obj.ownerDocument;
- if (!doc) {
- return [0, 0];
- }
- docElem = doc.documentElement;
- if (boundingRectEnabled(obj)) {
- rect = getXYRect(obj, true);
- }
- win = doc == doc.window ? doc : (doc.nodeType === 9 ? doc.defaultView || doc.parentWindow : false);
- return [
- rect.left + (!forFixed ? win.pageXOffset || docElem.scrollLeft : 0) - (docElem.clientLeft || 0),
- rect.top + (!forFixed ? win.pageYOffset || docElem.scrollTop : 0) - (docElem.clientTop || 0)
- ];
- }
- function isWindow(el) {
- return el != null && el === el.window;
- }
- function getSize(elem, withoutBounds, notBounding) {
- elem = ge(elem);
- var s = [0, 0], de = document.documentElement, rect;
- if (withoutBounds && getStyle(elem, 'boxSizing') === 'border-box') {
- withoutBounds = false;
- }
- if (elem == document) {
- s = [Math.max(
- de.clientWidth,
- bodyNode.scrollWidth, de.scrollWidth,
- bodyNode.offsetWidth, de.offsetWidth
- ), Math.max(
- de.clientHeight,
- bodyNode.scrollHeight, de.scrollHeight,
- bodyNode.offsetHeight, de.offsetHeight
- )];
- } else if (elem) {
- function getWH() {
- if (boundingRectEnabled(elem) && (rect = getXYRect(elem, notBounding)) && rect.width !== undefined) {
- s = [rect.width, rect.height];
- } else {
- s = [elem.offsetWidth, elem.offsetHeight];
- }
- if (!withoutBounds) return;
- var padding = 0, border = 0;
- each(s, function(i, v) {
- var which = i ? ['Top', 'Bottom'] : ['Left', 'Right'];
- each(which, function(){
- s[i] -= parseFloat(getStyle(elem, 'padding' + this)) || 0;
- s[i] -= parseFloat(getStyle(elem, 'border' + this + 'Width')) || 0;
- });
- });
- }
- if (!isVisible(elem)) {
- var props = {position: 'absolute', visibility: 'hidden', display: 'block'};
- var old = {}, old_cssText = false;
- if (elem.style.cssText.indexOf('!important') > -1) {
- old_cssText = elem.style.cssText;
- }
- each(props, function(i, v) {
- old[i] = elem.style[i];
- elem.style[i] = v;
- });
- getWH();
- each(props, function(i, v) {
- elem.style[i] = old[i];
- });
- if (old_cssText) {
- elem.style.cssText = old_cssText;
- }
- } else getWH();
- }
- return s;
- }
- function toURL(obj) {
- var str = "";
- for (var key in obj) {
- if (str != "") str += "&";
- str += key + "=" + encodeURIComponent(obj[key]);
- }
- return str;
- }
- function serialize(form) {
- var field, s = [];
- if (typeof form == 'object' && form.nodeName == "FORM") {
- var len = form.elements.length;
- for (i=0; i<len; i++) {
- field = form.elements[i];
- if (field.name && !field.disabled && field.type != 'file' && field.type != 'reset' && field.type != 'submit' && field.type != 'button') {
- if (field.type == 'select-multiple') {
- for (j=form.elements[i].options.length-1; j>=0; j--) {
- if(field.options[j].selected)
- s[s.length] = encodeURIComponent(field.name) + "=" + encodeURIComponent(field.options[j].value);
- }
- } else if ((field.type != 'checkbox' && field.type != 'radio') || field.checked) {
- s[s.length] = encodeURIComponent(field.name) + "=" + encodeURIComponent(field.value);
- }
- }
- }
- }
- return s.join('&').replace(/%20/g, '+');
- }
- function ce(tagName, attr, style) {
- var el = document.createElement(tagName);
- if (attr) extend(el, attr);
- if (style) setStyle(el, style);
- return el;
- }
- function each(object, callback) {
- if (!isObject(object) && typeof object.length !== 'undefined') {
- for (var i = 0, length = object.length; i < length; i++) {
- var value = object[i];
- if (callback.call(value, i, value) === false) break;
- }
- } else {
- for (var name in object) {
- if(!Object.prototype.hasOwnProperty.call(object, name)) continue;
- if(callback.call(object[name], name, object[name]) === false) break;
- }
- }
- return object;
- }
- function clone(obj, req) {
- var newObj = !isObject(obj) && typeof obj.length !== 'undefined' ? [] : {};
- for (var i in obj) {
- if (/webkit/i.test(_ua) && (i == 'layerX' || i == 'layerY' || i == 'webkitMovementX' || i == 'webkitMovementY')) continue;
- if (req && typeof(obj[i]) === 'object' && i !== 'prototype' && obj[i] !== null) {
- newObj[i] = clone(obj[i]);
- } else {
- newObj[i] = obj[i];
- }
- }
- return newObj;
- }
- function attr(el, attrName, value) {
- el = ge(el);
- if (typeof value == 'undefined') {
- return el.getAttribute(attrName);
- } else {
- el.setAttribute(attrName, value);
- return value;
- }
- }
- function removeAttr(el) {
- for (var i = 0, l = arguments.length; i < l; ++i) {
- var n = arguments[i];
- if (el[n] === undefined) continue;
- try {
- delete el[n];
- } catch(e) {
- try {
- el.removeAttribute(n);
- } catch(e) {}
- }
- }
- }
- function domEL(el, p) {
- p = p ? 'previousSibling' : 'nextSibling';
- while (el && !el.tagName) el = el[p];
- return el;
- }
- function domNS(el) {
- return domEL((el || {}).nextSibling);
- }
- function domPS(el) {
- return domEL((el || {}).previousSibling, 1);
- }
- function domFC(el) {
- return domEL((el || {}).firstChild);
- }
- function domLC(el) {
- return domEL((el || {}).lastChild, 1);
- }
- function domPN(el) {
- return (el || {}).parentNode;
- }
- function domChildren(el) {
- var chidlren = [];
- var nodes = el.childNodes;
- for (var i = 0; i < nodes.length; i++) {
- if (nodes[i].tagName) {
- chidlren.push(nodes[i]);
- }
- }
- return chidlren;
- }
- function show(elem) {
- var l = arguments.length;
- if (l > 1) {
- for (var i = 0; i < l; i++) {
- show(arguments[i]);
- } return;
- }
- elem = ge(elem);
- if(!elem || !elem.style) return;
- var old = elem.olddisplay;
- var newStyle = 'block';
- var tag = elem.tagName.toLowerCase();
- elem.style.display = old || '';
- if(getStyle(elem, 'display') !== 'none') return;
- if(hasClass(elem, 'inline') || hasClass(elem, '_inline')) {
- newStyle = 'inline';
- } else if(hasClass(elem, '_inline_block')) {
- newStyle = 'inline-block';
- } else if(tag === 'tr' && !browser.msie) {
- newStyle = 'table-row';
- } else if(tag === 'table' && !browser.msie) {
- newStyle = 'table';
- } else {
- newStyle = 'block';
- }
- elem.style.display = elem.olddisplay = newStyle;
- sAnim.scroll();
- }
- function hide(elem) {
- var l = arguments.length;
- if (l > 1) {
- for (var i = 0; i < l; i++) {
- hide(arguments[i]);
- } return;
- }
- elem = ge(elem);
- if(!elem || !elem.style) return;
- var display = getStyle(elem, 'display');
- elem.olddisplay = (display != 'none' ? display : '');
- elem.style.display = 'none';
- }
- function cookie(name, value, expires = 86400 * 3600, path = '/') {
- if(!name || /^(?:expires|max\-age|path|domain|secure)$/i.test(name)) return false;
- if(typeof value == 'undefined') {
- return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(name).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || '';
- } else {
- if (expires) {
- switch (expires.constructor) {
- case Number:
- expires = expires === Infinity ? "expires=Fri, 31 Dec 9999 23:59:59 GMT" : "max-age=" + expires;
- break;
- case String:
- expires = "expires=" + expires;
- break;
- case Date:
- expires = "expires=" + expires.toUTCString();
- break;
- default:
- }
- } else expires = 'expires=Fri, 31 Dec 1970 23:59:59 GMT';
- document.cookie = encodeURIComponent(name)+'= '+encodeURIComponent(value)+'; ' + expires + (path ? '; path=' + path : '');
- return true;
- }
- }
- function pa(str) {
- var args = [].slice.call(arguments, 1), i = 0;
- return str.replace(/%s/g, function() {
- return args[i++];
- });
- }
- function pa1(str) {
- var query = str.substr(1);
- var result = {};
- query.split("&").forEach(function(part) {
- var item = part.split("=");
- result[item[0]] = decodeURIComponent(item[1]);
- });
- return result;
- }
- function sortAsc(element) {
- [].map.call(element.children, Object).sort(function(a, b) {
- return +b.id.match(/\d+/) - +a.id.match(/\d+/);
- }).forEach(function(elem) {
- element.appendChild(elem);
- });
- }
- function sortDesc(element) {
- [].map.call(element.children, Object).sort(function(a, b) {
- return +a.id.match(/\d+/) - +b.id.match(/\d+/);
- }).forEach(function(elem) {
- element.appendChild(elem);
- });
- }
- function elsRem(elements) {
- if(typeof(elements.length) != "undefined") elements.forEach(function(el) { el.remove(); });
- else elements.remove();
- }
- function elsFunc(elements, func) {
- if(typeof(elements.length) != "undefined") elements.forEach(function(el) { func(el); });
- else func(elements);
- }
- function sel(selector, all, context) {
- context = context || document;
- if(typeof(all) == "undefined") all = true;
- return all ? context.querySelectorAll(selector) : context.querySelector(selector);
- }
- function eventFunc(evElement, evType) {
- let args = [].splice.call(arguments, 2);
- evElement.ebind('click', function(ev) {
- if(!ev.path.filter(function(el) { return el.matches && el.matches(args[0]); }).length) {
- args[1] && args[1]();
- this.eoff('click');
- }
- }, true);
- }
- // UTILS
- Function.prototype.pbind = function() {
- var args = Array.prototype.slice.call(arguments);
- args.unshift(window);
- return this.bind.apply(this, args);
- };
- function createElementFunc(functionName, func, allowMany = true) {
- Element.prototype[functionName] = func;
- if(allowMany) NodeList.prototype[functionName] = HTMLCollection.prototype[functionName] = func;
- return true;
- }
- createElementFunc('ebind', function(ev, callback, bool = false) {
- this.eoff(ev);
- if(NodeList.prototype.isPrototypeOf(this) || HTMLCollection.prototype.isPrototypeOf(this)) {
- this.forEach(function(v) {
- if(!v.listeners) v.listeners = [];
- let l = v.addEventListener(ev, callback, bool);
- v.listeners.push({type: ev, listener: callback});
- });
- } else {
- if(!this.listeners) this.listeners = [];
- let l = this.addEventListener(ev, callback, bool);
- this.listeners.push({type: ev, listener: callback});
- } return this;
- });
- createElementFunc('eoff', function(ev) {
- if(NodeList.prototype.isPrototypeOf(this) || HTMLCollection.prototype.isPrototypeOf(this)) {
- this.forEach(function(v) {
- if(v.listeners) {
- let listenersCount = v.listeners.length;
- for(let listenersIterator = 0; listenersIterator < c; listenersIterator++) {
- let l = v.listeners[listenersIterator];
- if(l && l.type == ev) {
- this.removeEventListener(ev, l.listener);
- delete v.listeners[listenersIterator];
- }
- }
- }
- });
- } else if(this.listeners) {
- let listenersCount = this.listeners.length;
- for(let listenersIterator = 0; listenersIterator < c; listenersIterator++) {
- let l = this.listeners[listenersIterator];
- if(l && l.type == ev) {
- this.removeEventListener(ev, l.listener);
- delete this.listeners[listenersIterator];
- }
- }
- } return this;
- });
- // CSS
- function hasClass(obj, name) {
- obj = ge(obj);
- if(obj && obj.nodeType === 1 && (' ' + obj.className + ' ').replace(/[\t\r\n\f]/g, ' ').indexOf(' ' + name + ' ') >= 0) return true;
- return false;
- }
- // EVENTS
- window.onpopstate = function() { return nav.go(location.pathname + location.search, null, null); }
- document.addEventListener('DOMContentLoaded', function() {
- if(window.devicePixelRatio >= 2) stManager.addBody('retina.css');
- stManager.getPage(location.pathname, page.path);
- sAnim.init();
- });
- // FUNC
- function formatDate(date) {
- var day = addDateZero(date.getDate());
- var month = addDateZero(date.getMonth()+1);
- var year = date.getFullYear();
- var hour = addDateZero(date.getHours());
- var minute = addDateZero(date.getMinutes());
- return day+'.'+month+'.'+year+' '+hour+':'+minute;
- }
- function getSpecialDate(timestamp) {
- timestamp = parseInt(timestamp);
- var months = ['Янв','Февр','Март','Апр','Май','Июнь','Июль','Авг','Сент','Окт','Ноя','Дек'];
- var cur = new Date();
- var a = new Date(timestamp * 1000);
- var a_hour = a.getHours(), a_min = a.getMinutes();
- var last_minutes = parseInt(((Math.floor(Date.now() / 1000) / 60) - (timestamp / 60)));
- if (a_hour < 10) var a_hour = '0' + a_hour.toString();
- if (a_min < 10) var a_min = '0' + a_min.toString();
- if(Math.floor(Date.now() / 1000) < (timestamp + 60)) return 'Только что';
- if(Math.floor(Date.now() / 1000) < (timestamp + 60 + 60)) return 'Минуту назад';
- if(Math.floor(Date.now() / 1000) < (timestamp + 60 + 60 + 60)) return 'Две минуты назад';
- if(Math.floor(Date.now() / 1000) < (timestamp + 60 + 60 + 60 + 60)) return 'Три минуты назад';
- if(Math.floor(Date.now() / 1000) < (timestamp + 60 + 60 + 60 + 60 + 60)) return 'Четыре минуты назад';
- if(last_minutes > 0 && last_minutes <= 59) return last_minutes + ' минут назад';
- if(last_minutes > 59 && last_minutes <= 120) return 'Час назад';
- if(last_minutes > 120 && last_minutes <= 180) return 'Два часа назад';
- if(last_minutes > 180 && last_minutes <= 240) return 'Три часа назад';
- if(cur.getDate() == a.getDate() && cur.getFullYear() == a.getFullYear()) return a_hour + ':' + a_min;
- if(cur.getDate() > a.getDate()) return a.getDate()+' '+months[a.getMonth()]+' '+a.getFullYear()+', '+a_hour+':'+a_min;
- }
- function addDateZero(i) {
- if(i < 10) i = '0' + i;
- return i;
- }
- function onBodyResize() {
- if(modality.active) { // modality resize
- if(browser.mobile) return;
- if(geByClass1('modal-box', ge('modal_wrap')).offsetHeight > window.innerHeight) {
- geByClass1('modal-box', ge('modal_wrap')).style.top = geByClass1('modal-box', ge('modal_wrap')).offsetHeight / 2;
- } else geByClass1('modal-box', ge('modal_wrap')).style.top = '';
- if(geByClass1('modal-box', ge('modal_wrap')).offsetWidth > window.innerWidth) {
- geByClass1('modal-box', ge('modal_wrap')).style.left = geByClass1('modal-box', ge('modal_wrap')).offsetWidth / 2;
- } else geByClass1('modal-box', ge('modal_wrap')).style.left = '';
- }
- if((ge('scroll_fix_wrap').scrollHeight - ge('page_footer_wrap').offsetHeight) > window.innerHeight) setStyle(ge('page_footer_wrap'), {display: 'block'});
- else setStyle(ge('page_footer_wrap'), {display: 'none'});
- }
- function topMsg(text, seconds, type) {
- var el = ge('system_msg');
- clearTimeout(window.topMsgTimer);
- if(!type) type = 'default';
- if(!text) return hide('system_msg');
- if(seconds) window.topMsgTimer = setTimeout(topMsg.pbind(false), seconds * 1000);
- el.className = 'fixed';
- el.classList.add(type);
- el.innerHTML = text;
- show(el);
- }
- function msgBox(container, type, message) {
- if(message == undefined) return;
- elsRem(sel('.msg-box'));
- return container.appendChild(ce('div', {className: 'msg-box ' + type, innerHTML: '<div class=\'msg-text\'>'+message+'</div>'}));
- }
- function toAnim(el, offset = 0) {
- if(!el) return;
- animate(ge('scroll_fix_wrap'), { scrollTop: el.offsetTop + offset }, 500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement