Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.08 KB | None | 0 0
  1. var arpExpand = 'ARP' + arpNow(), arpCache = {};
  2.  
  3. if (!window._ua) var _ua = navigator.userAgent.toLowerCase();
  4. if (!window.locDomain) var locDomain = location.host.toString().match(/[a-zA-Z]+\.[a-zA-Z]+\.?$/)[0];
  5.  
  6. window.locHost = location.host;
  7. window.locProtocol = location.protocol;
  8. window.__debugMode = true;
  9.  
  10. var browser = {
  11. version: (_ua.match( /.+(?:me|ox|on|rv|it|era|opr|ie|edge)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
  12. opera: (/opera/i.test(_ua) || /opr/i.test(_ua)),
  13. vivaldi: /vivaldi/i.test(_ua),
  14. msie: (/msie/i.test(_ua) && !/opera/i.test(_ua) || /trident\//i.test(_ua)) || /edge/i.test(_ua),
  15. msie6: (/msie 6/i.test(_ua) && !/opera/i.test(_ua)),
  16. msie7: (/msie 7/i.test(_ua) && !/opera/i.test(_ua)),
  17. msie8: (/msie 8/i.test(_ua) && !/opera/i.test(_ua)),
  18. msie9: (/msie 9/i.test(_ua) && !/opera/i.test(_ua)),
  19. msie_edge: (/edge/i.test(_ua) && !/opera/i.test(_ua)),
  20. mozilla: /firefox/i.test(_ua),
  21. chrome: /chrome/i.test(_ua) && !/edge/i.test(_ua),
  22. safari: (!(/chrome/i.test(_ua)) && /webkit|safari|khtml/i.test(_ua)),
  23. iphone: /iphone/i.test(_ua),
  24. ipod: /ipod/i.test(_ua),
  25. iphone4: /iphone.*OS 4/i.test(_ua),
  26. ipod4: /ipod.*OS 4/i.test(_ua),
  27. ipad: /ipad/i.test(_ua),
  28. android: /android/i.test(_ua),
  29. bada: /bada/i.test(_ua),
  30. mobile: /iphone|ipod|ipad|opera mini|opera mobi|iemobile|android/i.test(_ua),
  31. msie_mobile: /iemobile/i.test(_ua),
  32. safari_mobile: /iphone|ipod|ipad/i.test(_ua),
  33. opera_mobile: /opera mini|opera mobi/i.test(_ua),
  34. opera_mini: /opera mini/i.test(_ua),
  35. mac: /mac/i.test(_ua),
  36. search_bot: /(yandex|google|stackrambler|aport|slurp|msnbot|bingbot|twitterbot|ia_archiver|facebookexternalhit)/i.test(_ua)
  37. };
  38.  
  39. var ajax = {
  40.  
  41. init: function() {
  42. var r = false;
  43. try
  44. {
  45. if (r = new XMLHttpRequest()) {
  46. ajax.req = function() { return new XMLHttpRequest(); }
  47. return;
  48. }
  49. } catch(e) {}
  50. if (!ajax.req) {
  51. location.replace('/badbrowser.php');
  52. }
  53. },
  54.  
  55. getreq: function() {
  56. if(!ajax.req) ajax.init();
  57. return ajax.req();
  58. },
  59.  
  60. plainget: function(url, successHandler) {
  61. var r = ajax.getreq();
  62. r.onreadystatechange = function() {
  63. if(r.readyState == 4)
  64. successHandler && successHandler(JSON.parse(r.responseText));
  65. }
  66. r.open('POST', url, true);
  67. r.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  68. r.send('ajax_req=1');
  69. return r;
  70. },
  71.  
  72. modalget: function(url, successHandler) {
  73. var r = ajax.getreq();
  74. r.onreadystatechange = function() {
  75. if(r.readyState == 4)
  76. successHandler && successHandler(JSON.parse(r.responseText));
  77. }
  78. r.open('POST', url, true);
  79. r.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  80. r.send('ajax_req=1&modality=1');
  81. return r;
  82. },
  83.  
  84. getjson: function(method, params, successHandler) {
  85. var r = ajax.getreq();
  86. var data = null;
  87. r.open('GET', '/methods/' + method + '.php?' + toURL(params), true);
  88. r.onreadystatechange = function() {
  89. if(r.readyState == 4) {
  90. data = JSON.parse(r.responseText);
  91. successHandler && successHandler(data);
  92. }
  93. }
  94. r.send();
  95. }
  96.  
  97. }
  98.  
  99. var stManager = {
  100.  
  101. getPage: function(loc, callback) {
  102. loc = loc.replace(/^\/|\/$/g, '');
  103. if(navMap[loc] && navMap[loc][1] && !navMap[loc][0]) return stManager.add(navMap[loc][1], callback);
  104. for(let key in navMap) if((new RegExp('^'+key+'$')).test(loc) && navMap[key][0] && navMap[key][1])
  105. return stManager.add(navMap[key][1], callback);
  106. return callback && callback();
  107. },
  108.  
  109. find: function(file) {
  110. let found = false, pattern = new RegExp(file.replace(/\?.*/, ''));
  111. if(file.match(/\.css/)) elsFunc(sel('link'), function(el) { if(el.getAttribute('href') && el.getAttribute('href').match(pattern)) found = true; });
  112. else elsFunc(sel('script'), function(el) { if(el.getAttribute('src') && el.getAttribute('src').match(pattern)) found = true; });
  113. return found;
  114. },
  115.  
  116. add: function(files, callback) {
  117. if(!isArray(files)) files = [files];
  118. let link = geByTag('link', document.head);
  119. let script = geByTag('script', document.head);
  120. each(files, function(i, file) {
  121. if(stManager.find(file)) return stManager.done(files, file, callback);
  122. if(file.match(/\.css/)) {
  123. var css = document.createElement('link');
  124. css.rel = 'stylesheet';
  125. css.type = 'text/css';
  126. css.href = '/css/' + file + '?' + conf.version;
  127. css.onload = function() { stManager.done(files, file, callback); };
  128. document.head.insertBefore(css, link[link.length - 1]);
  129. } else {
  130. var js = document.createElement('script');
  131. js.type = 'text/javascript';
  132. js.src = '/js/al/' + file + '?' + conf.version;
  133. js.onload = function() { stManager.done(files, file, callback); };
  134. document.head.insertBefore(js, script[script.length - 1]);
  135. }
  136. });
  137. },
  138.  
  139. addBody: function(files, callback) {
  140. if(!isArray(files)) files = [files];
  141. let link = geByTag('link', document.body);
  142. let script = geByTag('script', document.body);
  143. each(files, function(i, file) {
  144. if(stManager.find(file)) return stManager.done(files, file, callback);
  145. if(file.match(/\.css/)) {
  146. var css = document.createElement('link');
  147. css.rel = 'stylesheet';
  148. css.type = 'text/css';
  149. css.href = '/css/' + file + '?' + conf.version;
  150. document.body.insertBefore(css, link[link.length - 1]);
  151. } else {
  152. var js = document.createElement('script');
  153. js.type = 'text/javascript';
  154. js.src = '/js/al/' + file + '?' + conf.version;
  155. document.body.insertBefore(js, script[script.length - 1]);
  156. }
  157. });
  158. },
  159.  
  160. done: function(files, file, callback) {
  161. stManager.loaded.push(file);
  162. if(files.length == stManager.loaded.length) {
  163. stManager.loaded = [];
  164. callback && callback();
  165. }
  166. },
  167.  
  168. loaded: []
  169.  
  170. }
  171.  
  172. var nav = {
  173.  
  174. go: function(loc, ev, opts) {
  175. if(ev) ev.preventDefault();
  176. if(typeof loc != 'string') loc = loc.getAttribute('href');
  177. opts = opts || {};
  178. nav.last_loc = location.pathname + location.search;
  179. if(!nav.isLoad) {
  180. nav.isLoad = true;
  181. if(nav.last_loc != loc) history.pushState(null, null, loc);
  182. document.body.className = 'progress';
  183. topNotifier.hide();
  184. ajax.plainget(loc, function(data) {
  185. document.title = data.title;
  186. elsRem(sel('#aj'));
  187. data.meta.forEach(function(obj) {
  188. let meta = document.createElement('meta'); meta.id = 'aj';
  189. for(let prop in obj) meta.setAttribute(prop, obj[prop]);
  190. document.head.insertBefore(meta, sel('meta')[0]);
  191. });
  192. stManager.getPage(loc, function() {
  193. document.body.removeAttribute('class');
  194. ge('page_wrapper').innerHTML = data.body;
  195. ge('scroll_fix_wrap').scrollTop = 0;
  196. page.path(loc);
  197. nav.isLoad = false;
  198. });
  199. });
  200. }
  201. },
  202.  
  203. link: function(loc, ev, opts) {
  204. opts = opts || {};
  205. if(ev) ev.preventDefault();
  206. if(typeof loc != 'string') loc = loc.getAttribute('href');
  207. if(!nav.isLoad) {
  208. loc = loc.replace(new RegExp('^(' + locProtocol + '//' + locHost + ')?/?', 'i'), '');
  209. if(opts.curWindow) return window.location.assign(loc);
  210. window.open(loc);
  211. }
  212. },
  213.  
  214. isLoad: false,
  215. last_loc: null
  216.  
  217. }
  218.  
  219. var modality = {
  220.  
  221. show: function(loc, ev, loaded) {
  222. if(ev) ev.preventDefault();
  223. if(typeof loc != 'string') loc = loc.getAttribute('href');
  224. document.body.className = 'progress';
  225. topNotifier.hide();
  226. ajax.modalget(loc, function(data) {
  227. document.body.removeAttribute('class');
  228. document.body.style.overflow = 'hidden';
  229. stManager.getPage(loc, function() {
  230. setStyle(ge('modal_bg'), {visibility: 'visible', opacity: 1}), setStyle(ge('modal_wrap'), {visibility: 'visible', opacity: 1});
  231. ge('modal_wrap').innerHTML = data.body;
  232. eventFunc(document.body, 'click', '.modal-box', modality.hide);
  233. page.path(loc);
  234. modality.active = true;
  235. loaded && loaded();
  236. onBodyResize();
  237. });
  238. });
  239. },
  240.  
  241. hide: function() {
  242. if(modality.active) {
  243. document.body.style.overflow = '';
  244. ge('modal_wrap').innerHTML = '';
  245. ge('modal_bg').removeAttribute('style'),
  246. ge('modal_wrap').removeAttribute('style');
  247. modality.active = false;
  248. } return;
  249. },
  250.  
  251. active: false
  252.  
  253. }
  254.  
  255. var dd = {
  256.  
  257. init: function() {
  258. elsFunc(sel('.dropdown-select'), function(el) {
  259. var selectElement = sel('select[id="' + el.getAttribute('for') + '"]', false, el.parentNode);
  260. if(selectElement) {
  261. if(getComputedStyle(el.parentNode)['position'] == 'static') el.parentNode.style.position = 'relative';
  262. var obj = sel('option[value="' + selectElement.value + '"]', false, selectElement);
  263. el.innerHTML = obj ? obj.innerHTML : selectElement.value;
  264. var ddlist = document.createElement('div');
  265. var identifier = 0;
  266. ddlist.className = 'dropdown-variants';
  267. ddlist.style.width = el.offsetWidth * 0.93;
  268. ddlist.style.left = el.offsetWidth * 0.035;
  269. ddlist.style.top = el.offsetTop + el.offsetHeight;
  270. ddlist.setAttribute('id', el.getAttribute('for'));
  271. elsFunc(sel('option', 1, selectElement), function(val) {
  272. let option = document.createElement('div');
  273. for(let i = 0; i < val.attributes.length; i++) {
  274. if(val.attributes[i].name == 'class' || val.attributes[i].name == 'id') continue;
  275. option.setAttribute(val.attributes[i].name, val.attributes[i].value);
  276. if(val.attributes[i].name.substr(0, 2) != 'on') {
  277. option[val.attributes[i].name] = val[val.attributes[i].name];
  278. }
  279. }
  280. option.setAttribute('id', (identifier + ' ' + (val.getAttribute('id') || '')).replace(/ $/, ''));
  281. option.className = ('dropdown-option ' + val.className).replace(/ $/, '');
  282. option.innerHTML = val.innerHTML;
  283. if(!val.disabled) ddlist.appendChild(option);
  284. identifier++;
  285. }), el.parentNode.insertAdjacentHTML('beforeend', ddlist.outerHTML);
  286. }
  287. el.addEventListener('transitionend', function() {
  288. if(this.offsetHeight == 0) this.style.display = 'none';
  289. });
  290. el.addEventListener('click', function() {
  291. var dropdown = sel('.dropdown-variants[id="' + this.getAttribute('for') + '"]', false, this.parentNode);
  292. dd.toggle(dropdown);
  293. });
  294. });
  295. elsFunc(sel('.dropdown-option'), function(el) { el.addEventListener('click', function() {
  296. var selectObject = sel('select[id="' + this.parentNode.getAttribute('id') + '"]', false, this.parentNode.parentNode);
  297. var optionNum = parseInt(this.getAttribute('id'));
  298. selectObject.value = sel('option', 1, selectObject)[optionNum].value;
  299. selectObject.dispatchEvent(new Event('change'));
  300. var obj = sel('option[value="' + selectObject.value + '"]', false, selectObject);
  301. sel('.dropdown-select[for="' + this.parentNode.getAttribute('id') + '"]', false, this.parentNode.parentNode).innerHTML = obj ? obj.innerHTML : selectObject.value;
  302. dd.hide(this.parentNode);
  303. })});
  304. },
  305.  
  306. toggle: function(dropdown) {
  307. if(dropdown.offsetHeight == 0) {
  308. dd.show(dropdown);
  309. } else {
  310. dd.hide(dropdown);
  311. }
  312. },
  313.  
  314. show: function(dropdown) {
  315. dropdown.style.display = 'block';
  316. var ddMaxHeight = 0;
  317. elsFunc(sel('*', 1, dropdown), function(el) {
  318. ddMaxHeight += el.offsetHeight;
  319. }), dropdown.style.maxHeight = ddMaxHeight;
  320. },
  321.  
  322. hide: function(dropdown) {
  323. dropdown.style.maxHeight = 0;
  324. }
  325.  
  326. }
  327.  
  328. var topNotifier = {
  329.  
  330. show: function(el, ev) {
  331. var nt = geByClass1('top-notify-wrap', ge('page_header_wrap')),
  332. ntCount = geByClass1('top-notify-count', ge('page_header_wrap')),
  333. ntList = geByClass1('top-notify-list', nt),
  334. ntEmpty = geByClass1('top-notify-empty', nt),
  335. ntResult = geByClass1('notify-result', nt),
  336. ntSpinner = geByClass1('spinner-load', nt);
  337. if(!cookie('i')) return;
  338. if(nt.classList.contains('shown')) return nt.classList.remove('shown');
  339. if(!isVisible(ntSpinner)) show(ntSpinner);
  340. nt.classList.add('shown');
  341. ntResult.innerHTML = '', ntList.innerHTML = '';
  342. eventFunc(document.body, 'click', '.user-menu-notify', topNotifier.hide);
  343. ajax.getjson('account.getNotify', { i: cookie('i') }, function(data) {
  344. if(isVisible(ntEmpty)) hide(ntEmpty);
  345. if(isVisible(ntSpinner)) hide(ntSpinner);
  346. if(data.error) return msgBox(ntResult, 'err', data.error.err_msg);
  347. if(data.success == 0) return show(ntEmpty);
  348. data.success.forEach(data => {
  349. 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>');
  350. elsFunc(sel('.__new'), function(el) {
  351. ntCount.innerHTML = parseInt(ntCount.innerHTML) - 1;
  352. if(parseInt(ntCount.innerHTML) < 1) hide(ntCount);
  353. else show(ntCount);
  354. setTimeout(function() { el.classList.remove('__new'); }, 2000);
  355. });
  356. });
  357. });
  358. },
  359.  
  360. hide: function() {
  361. var nt = geByClass1('top-notify-wrap', ge('page_header_wrap'));
  362. if(!nt) return;
  363. if(!nt.classList.contains('shown')) return;
  364. nt.classList.remove('shown');
  365. }
  366.  
  367. }
  368.  
  369. // FX
  370.  
  371. var Fx = {
  372.  
  373. Transitions: {
  374. linear: function(t, b, c, d) { return c*t/d + b; },
  375. sineInOut: function(t, b, c, d) { return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; },
  376. halfSine: function(t, b, c, d) { return c * (Math.sin(Math.PI * (t/d) / 2)) + b; },
  377. easeOutBack: function(t, b, c, d) { var s = 1.70158; return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; },
  378. easeInCirc: function(t, b, c, d) { return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b; },
  379. easeOutCirc: function(t, b, c, d) { return c * Math.sqrt(1 - (t=t/d-1)*t) + b; },
  380. easeInQuint: function(t, b, c, d) { return c*(t/=d)*t*t*t*t + b; },
  381. easeOutQuint: function(t, b, c, d) { return c*((t=t/d-1)*t*t*t*t + 1) + b; },
  382. easeOutCubic: function(t, b, c, d) { return c*((t=t/d-1)*t*t + 1) + b;},
  383. swiftOut: function(t, b, c, d) { return c * cubicBezier(0.4, 0, 0.22, 1, t/d, 4/d) + b; }
  384. },
  385. Attrs: [
  386. [ 'height', 'marginTop', 'marginBottom', 'paddingTop', 'paddingBottom' ],
  387. [ 'width', 'marginLeft', 'marginRight', 'paddingLeft', 'paddingRight' ],
  388. [ 'opacity', 'left', 'top' ]
  389. ],
  390. Timers: [],
  391. TimerId: null
  392.  
  393. }, fx = Fx;
  394.  
  395. Fx.Base = function(el, options, name) {
  396. this.el = ge(el);
  397. this.name = name;
  398. this.options = extend({
  399. onStep: function(){},
  400. onComplete: function() {},
  401. transition: options.transition || Fx.Transitions.sineInOut,
  402. duration: 500
  403. }, options || {});
  404. }
  405.  
  406. Fx.Base.prototype = {
  407. start: function(from, to){
  408. this.from = from;
  409. this.to = to;
  410. this.time = arpNow();
  411. this.isTweening = true;
  412.  
  413. var self = this;
  414. function t(gotoEnd) {
  415. return self.step(gotoEnd);
  416. }
  417. t.el = this.el;
  418. if (t() && Fx.Timers.push(t) && !Fx.TimerId) {
  419. Fx.TimerId = setInterval(function() {
  420. var timers = Fx.Timers, l = timers.length;
  421. for (var i = 0; i < l; i++) {
  422. if (!timers[i]()) {
  423. timers.splice(i--, 1);
  424. l--;
  425. }
  426. }
  427. if (!l) {
  428. clearInterval(Fx.TimerId);
  429. Fx.TimerId = null;
  430. }
  431. }, 13);
  432. }
  433. return this;
  434. },
  435.  
  436. stop: function(gotoEnd) {
  437. var timers = Fx.Timers;
  438. for (var i = timers.length - 1; i >= 0; i--) {
  439. if (timers[i].el == this.el ) {
  440. if (gotoEnd) {
  441. timers[i](true);
  442. }
  443. timers.splice(i, 1);
  444. }
  445. }
  446. this.isTweening = false;
  447. },
  448.  
  449. step: function(gotoEnd) {
  450. var time = arpNow();
  451. if (!gotoEnd && time < this.time + this.options.duration) {
  452. this.cTime = time - this.time;
  453. this.now = {};
  454. for (p in this.to) {
  455. if (isArray(this.to[p])) {
  456. var color = [], j;
  457. for (j = 0; j < 3; j++) {
  458. if (this.from[p] === undefined || this.to[p] === undefined) {
  459. return false;
  460. }
  461. color.push(Math.min(parseInt(this.compute(this.from[p][j], this.to[p][j])), 255));
  462. }
  463. this.now[p] = color;
  464. } else {
  465. this.now[p] = this.compute(this.from[p], this.to[p]);
  466. if (this.options.discrete) this.now[p] = intval(this.now[p]);
  467. }
  468. }
  469. this.update();
  470. return true;
  471. } else {
  472. setTimeout(this.options.onComplete.bind(this, this.el), 10);
  473. this.now = extend(this.to, this.options.orig);
  474. this.update();
  475. if (this.options.hide) hide(this.el);
  476. this.isTweening = false;
  477. return false;
  478. }
  479. },
  480.  
  481. compute: function(from, to){
  482. var change = to - from;
  483. return this.options.transition(this.cTime, from, change, this.options.duration);
  484. },
  485.  
  486. update: function(){
  487. this.options.onStep(this.now);
  488. for (var p in this.now) {
  489. if (isArray(this.now[p])) setStyle(this.el, p, 'rgb(' + this.now[p].join(',') + ')');
  490. else this.el[p] != undefined ? (this.el[p] = this.now[p]) : setStyle(this.el, p, this.now[p]);
  491. }
  492. },
  493.  
  494. cur: function(name, force){
  495. if (this.el[name] != null && (!this.el.style || this.el.style[name] == null))
  496. return this.el[name];
  497. return parseFloat(getStyle(this.el, name, force)) || 0;
  498. }
  499. };
  500.  
  501. function genFx(type, num) {
  502. var obj = {};
  503. each(Fx.Attrs.concat.apply([], Fx.Attrs.slice(0, num)), function() {
  504. obj[this] = type;
  505. });
  506. return obj;
  507. }
  508.  
  509. // DOM
  510. function rand(mi, ma) { return Math.random() * (ma - mi + 1) + mi; }
  511. function irand(mi, ma) { return Math.floor(rand(mi, ma)); }
  512. function isUndefined(obj) { return typeof obj === 'undefined' };
  513. function isFunction(obj) {return obj && Object.prototype.toString.call(obj) === '[object Function]'; }
  514. function isArray(obj) { return Object.prototype.toString.call(obj) === '[object Array]'; }
  515. function isString(obj) { return typeof obj === 'string'; }
  516. function isObject(obj) { return Object.prototype.toString.call(obj) === '[object Object]'; }
  517. 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; }
  518. function arpNow() { return +new Date; }
  519. function arpImage() { return window.Image ? (new Image()) : ce('img'); } // IE8 workaround
  520. function trim(text) { return (text || '').replace(/^\s+|\s+$/g, ''); }
  521. function stripHTML(text) { return text ? text.replace(/<(?:.|\s)*?>/g, '') : ''; }
  522. function escapeRE(s) { return s ? s.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1') : ''; }
  523. function boundingRectEnabled(obj) { return (typeof obj.getBoundingClientRect !== 'undefined'); }
  524. function intval(value) {
  525. if (value === true) return 1;
  526. return parseInt(value) || 0;
  527. }
  528. function floatval(value) {
  529. if (value === true) return 1;
  530. return parseFloat(value) || 0;
  531. }
  532. function positive(value) {
  533. value = intval(value);
  534. return value < 0 ? 0 : value;
  535. }
  536. function isNumeric(value) {
  537. return !isNaN(value);
  538. }
  539. function isVisible(elem) {
  540. elem = ge(elem);
  541. if (!elem || !elem.style) return false;
  542. return getStyle(elem, 'display') != 'none';
  543. }
  544.  
  545. function ge(el) {
  546. return (typeof el == 'string' || typeof el == 'number') ? document.getElementById(el) : el;
  547. }
  548. function geByTag(searchTag, node) {
  549. node = ge(node) || document;
  550. return node.getElementsByTagName(searchTag);
  551. }
  552. function gpeByClass(className, elem, stopElement) {
  553. elem = ge(elem);
  554. if (!elem) return null;
  555. while (stopElement !== elem && (elem = elem.parentNode)) {
  556. if (hasClass(elem, className)) return elem;
  557. }
  558. return null;
  559. }
  560. function geByClass1(searchClass, node, tag) {
  561. node = ge(node) || document;
  562. tag = tag || '*';
  563. return node.querySelector && node.querySelector(tag + '.' + searchClass) || geByClass(searchClass, node, tag)[0];
  564. }
  565. function geByClass(searchClass, node, tag) {
  566.  
  567. node = ge(node) || document;
  568. tag = tag || '*';
  569. var classElements = [];
  570.  
  571. if (node.querySelectorAll && tag != '*') {
  572. return node.querySelectorAll(tag + '.' + searchClass);
  573. }
  574.  
  575. if (node.getElementsByClassName) {
  576. var nodes = node.getElementsByClassName(searchClass);
  577. if (tag != '*') {
  578. tag = tag.toUpperCase();
  579. for (var i = 0, l = nodes.length; i < l; ++i) {
  580. if (nodes[i].tagName.toUpperCase() == tag) {
  581. classElements.push(nodes[i]);
  582. }
  583. }
  584. } else {
  585. classElements = Array.prototype.slice.call(nodes);
  586. }
  587. return classElements;
  588. }
  589.  
  590. var els = geByTag(tag, node);
  591. var pattern = new RegExp('(^|\\s)' + searchClass + '(\\s|$)');
  592. for (var i = 0, l = els.length; i < l; ++i) {
  593. if (pattern.test(els[i].className)) {
  594. classElements.push(els[i]);
  595. }
  596. }
  597.  
  598. return classElements;
  599.  
  600. }
  601. function extend() {
  602. var a = arguments, target = a[0] || {}, i = 1, l = a.length, deep = false, options;
  603. if (typeof target === 'boolean') {
  604. deep = target;
  605. target = a[1] || {};
  606. i = 2;
  607. }
  608.  
  609. if (typeof target !== 'object' && !isFunction(target)) target = {};
  610.  
  611. for (; i < l; ++i) {
  612. if ((options = a[i]) != null) {
  613. for (var name in options) {
  614. var src = target[name], copy = options[name];
  615. if (target === copy) continue;
  616. if (deep && copy && typeof copy === 'object' && !copy.nodeType) {
  617. target[name] = extend(deep, src || (copy.length != null ? [] : {}), copy);
  618. } else if (copy !== undefined) {
  619. target[name] = copy;
  620. }
  621. }
  622. }
  623. }
  624. return target;
  625. }
  626. function getRGB(color) {
  627. var result;
  628. if (color && isArray(color) && color.length == 3)
  629. return color;
  630. if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
  631. return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
  632. if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
  633. return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
  634. if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
  635. return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
  636. if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
  637. return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
  638. }
  639. function getColor(elem, attr) {
  640. var color;
  641. do {
  642. color = getStyle(elem, attr);
  643. if (!color.indexOf('rgba')) color = '';
  644. if (color != '' && color != 'transparent' || elem.nodeName.toLowerCase() == 'body') {
  645. break;
  646. }
  647. attr = 'backgroundColor';
  648. } while (elem = elem.parentNode);
  649. return getRGB(color);
  650. }
  651. function setStyle(elem, name, value){
  652. elem = ge(elem);
  653. if (!elem) return;
  654. if (typeof name == 'object') return each(name, function(k, v) { setStyle(elem,k,v); });
  655. if (name == 'opacity') {
  656. if (browser.msie) {
  657. if ((value + '').length) {
  658. if (value !== 1) {
  659. elem.style.filter = 'alpha(opacity=' + value * 100 + ')';
  660. } else {
  661. elem.style.filter = '';
  662. }
  663. } else {
  664. elem.style.cssText = elem.style.cssText.replace(/filter\s*:[^;]*/gi, '');
  665. }
  666. elem.style.zoom = 1;
  667. };
  668. elem.style.opacity = value;
  669. } else {
  670. try {
  671. var isN = typeof(value) == 'number';
  672. if (isN && (/height|width/i).test(name)) value = Math.abs(value);
  673. elem.style[name] = isN && !(/z-?index|font-?weight|opacity|zoom|line-?height/i).test(name) ? value + 'px' : value;
  674. } catch(e) { debugLog('setStyle error: ', [name, value], e); }
  675. }
  676. }
  677. function getStyle(elem, name, force) {
  678. elem = ge(elem);
  679. if (isArray(name)) { var res = {}; each(name, function(i,v){res[v] = getStyle(elem, v);}); return res; }
  680. if (!elem) return '';
  681. if (force === undefined) {
  682. force = true;
  683. }
  684. if (!force && name == 'opacity' && browser.msie) {
  685. var filter = elem.style['filter'];
  686. return filter ? (filter.indexOf('opacity=') >= 0 ?
  687. (parseFloat(filter.match(/opacity=([^)]*)/)[1] ) / 100) + '' : '1') : '';
  688. }
  689. if (!force && elem.style && (elem.style[name] || name == 'height')) {
  690. return elem.style[name];
  691. }
  692.  
  693. var ret, defaultView = document.defaultView || window;
  694. if (defaultView.getComputedStyle) {
  695. name = name.replace(/([A-Z])/g, '-$1').toLowerCase();
  696. var computedStyle = defaultView.getComputedStyle(elem, null);
  697. if (computedStyle) {
  698. ret = computedStyle.getPropertyValue(name);
  699. }
  700. } else if (elem.currentStyle) {
  701. if (name == 'opacity' && browser.msie) {
  702. var filter = elem.currentStyle['filter'];
  703. return filter && filter.indexOf('opacity=') >= 0 ?
  704. (parseFloat(filter.match(/opacity=([^)]*)/)[1]) / 100) + '' : '1';
  705. }
  706. var camelCase = name.replace(/\-(\w)/g, function(all, letter){
  707. return letter.toUpperCase();
  708. });
  709. ret = elem.currentStyle[name] || elem.currentStyle[camelCase];
  710. if (ret == 'auto') {
  711. ret = 0;
  712. }
  713.  
  714. ret = (ret + '').split(' ');
  715. each(ret, function(i,v) {
  716. if (!/^\d+(px)?$/i.test(v) && /^\d/.test(v)) {
  717. var style = elem.style, left = style.left, rsLeft = elem.runtimeStyle.left;
  718. elem.runtimeStyle.left = elem.currentStyle.left;
  719. style.left = v || 0;
  720. ret[i] = style.pixelLeft + 'px';
  721. style.left = left;
  722. elem.runtimeStyle.left = rsLeft;
  723. }
  724. });
  725. ret = ret.join(' ');
  726. }
  727.  
  728. if (force && (name == 'width' || name == 'height')) {
  729. var ret2 = getSize(elem, true)[({'width': 0, 'height': 1})[name]];
  730. ret = (intval(ret) ? Math.max(floatval(ret), ret2) : ret2) + 'px';
  731. }
  732.  
  733. return ret;
  734. }
  735. function data(elem, name, data) {
  736. if (!elem) return false;
  737. var id = elem[arpExpand], undefined;
  738. if (data !== undefined) {
  739. if (!arpCache[id]) arpCache[id] = {};
  740. arpCache[id][name] = data;
  741. }
  742. return name ? arpCache[id] && arpCache[id][name] : id;
  743. }
  744. function animate(el, params, speed, callback) {
  745. el = ge(el);
  746. if (!el) return;
  747. var _cb = isFunction(callback) ? callback : function() {};
  748. var options = extend({}, typeof speed == 'object' ? speed : {duration: speed, onComplete: _cb});
  749. var fromArr = {}, toArr = {}, visible = isVisible(el), self = this, p;
  750. options.orig = {};
  751. params = clone(params);
  752. if (params.discrete) {
  753. options.discrete = 1;
  754. delete(params.discrete);
  755. }
  756. if (browser.iphone) options.duration = 0;
  757.  
  758. var tween = data(el, 'tween'), i, name, toggleAct = visible ? 'hide' : 'show';
  759. if (tween && tween.isTweening) {
  760. options.orig = extend(options.orig, tween.options.orig);
  761. tween.stop(false);
  762. if (tween.options.show) toggleAct = 'hide';
  763. else if (tween.options.hide) toggleAct = 'show';
  764. }
  765. for (p in params) {
  766. if (!tween && (params[p] == 'show' && visible || params[p] == 'hide' && !visible)) {
  767. return options.onComplete.call(this, el);
  768. }
  769. if ((p == 'height' || p == 'width') && el.style) {
  770. if (!params.overflow) {
  771. if (options.orig.overflow == undefined) {
  772. options.orig.overflow = getStyle(el, 'overflow');
  773. }
  774. el.style.overflow = 'hidden';
  775. }
  776. if (!hasClass(el, 'inl_bl') && el.tagName != 'TD') {
  777. el.style.display = 'block';
  778. }
  779. }
  780. if (/show|hide|toggle/.test(params[p])) {
  781. if (params[p] == 'toggle') {
  782. params[p] = toggleAct;
  783. }
  784. if (params[p] == 'show') {
  785. var from = 0;
  786. options.show = true;
  787. if (options.orig[p] == undefined) {
  788. options.orig[p] = getStyle(el, p, false) || '';
  789. setStyle(el, p, 0);
  790. }
  791.  
  792. var o = options.orig[p];
  793. var old = el.style[p];
  794. el.style[p] = o;
  795. params[p] = parseFloat(getStyle(el, p, true));
  796. el.style[p] = old;
  797.  
  798. if (p == 'height' && browser.msie && !params.overflow) {
  799. el.style.overflow = 'hidden';
  800. }
  801. } else {
  802. if (options.orig[p] == undefined) {
  803. options.orig[p] = getStyle(el, p, false) || '';
  804. }
  805. options.hide = true;
  806. params[p] = 0;
  807. }
  808. }
  809. }
  810. if (options.show && !visible) {
  811. show(el);
  812. }
  813. tween = new Fx.Base(el, options);
  814. each(params, function(name, to) {
  815. if(/backgroundColor|borderBottomColor|borderLeftColor|borderRightColor|borderTopColor|color|borderColor|outlineColor/.test(name)) {
  816. var p = (name == 'borderColor') ? 'borderTopColor' : name;
  817. from = getColor(el, p);
  818. to = getRGB(to);
  819. if (from === undefined) return;
  820. } else {
  821. var parts = to.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
  822. start = tween.cur(name, true) || 0;
  823. if (parts) {
  824. to = parseFloat(parts[2]);
  825. if (parts[1]) {
  826. to = ((parts[1] == '-=' ? -1 : 1) * to) + to;
  827. }
  828. }
  829.  
  830. from = tween.cur(name, true);
  831. if (from == 0 && (name == 'width' || name == 'height'))
  832. from = 1;
  833.  
  834. if (name == 'opacity' && to > 0 && !visible) {
  835. setStyle(el, 'opacity', 0);
  836. from = 0;
  837. show(el);
  838. }
  839. }
  840. if (from != to || (isArray(from) && from.join(',') == to.join(','))) {
  841. fromArr[name] = from;
  842. toArr[name] = to;
  843. }
  844. });
  845.  
  846. tween.start(fromArr, toArr);
  847. data(el, 'tween', tween);
  848. return tween;
  849. }
  850. function getXYRect(obj, notBounding) {
  851. var rect;
  852. if (notBounding && getStyle(obj, 'display') == 'inline') {
  853. var rects = obj.getClientRects();
  854. rect = rects && rects[0] || obj.getBoundingClientRect();
  855. } else {
  856. rect = obj.getBoundingClientRect();
  857. }
  858. return rect;
  859. }
  860. function getXY(obj, forFixed) {
  861. obj = ge(obj);
  862. if (!obj) return [0,0];
  863.  
  864. var docElem, win,
  865. rect = {top: 0, left: 0},
  866. doc = obj.ownerDocument;
  867. if (!doc) {
  868. return [0, 0];
  869. }
  870. docElem = doc.documentElement;
  871.  
  872. if (boundingRectEnabled(obj)) {
  873. rect = getXYRect(obj, true);
  874. }
  875. win = doc == doc.window ? doc : (doc.nodeType === 9 ? doc.defaultView || doc.parentWindow : false);
  876. return [
  877. rect.left + (!forFixed ? win.pageXOffset || docElem.scrollLeft : 0) - (docElem.clientLeft || 0),
  878. rect.top + (!forFixed ? win.pageYOffset || docElem.scrollTop : 0) - (docElem.clientTop || 0)
  879. ];
  880. }
  881. function isWindow(el) {
  882. return el != null && el === el.window;
  883. }
  884. function getSize(elem, withoutBounds, notBounding) {
  885. elem = ge(elem);
  886. var s = [0, 0], de = document.documentElement, rect;
  887. if (withoutBounds && getStyle(elem, 'boxSizing') === 'border-box') {
  888. withoutBounds = false;
  889. }
  890. if (elem == document) {
  891. s = [Math.max(
  892. de.clientWidth,
  893. bodyNode.scrollWidth, de.scrollWidth,
  894. bodyNode.offsetWidth, de.offsetWidth
  895. ), Math.max(
  896. de.clientHeight,
  897. bodyNode.scrollHeight, de.scrollHeight,
  898. bodyNode.offsetHeight, de.offsetHeight
  899. )];
  900. } else if (elem) {
  901. function getWH() {
  902. if (boundingRectEnabled(elem) && (rect = getXYRect(elem, notBounding)) && rect.width !== undefined) {
  903. s = [rect.width, rect.height];
  904. } else {
  905. s = [elem.offsetWidth, elem.offsetHeight];
  906. }
  907. if (!withoutBounds) return;
  908. var padding = 0, border = 0;
  909. each(s, function(i, v) {
  910. var which = i ? ['Top', 'Bottom'] : ['Left', 'Right'];
  911. each(which, function(){
  912. s[i] -= parseFloat(getStyle(elem, 'padding' + this)) || 0;
  913. s[i] -= parseFloat(getStyle(elem, 'border' + this + 'Width')) || 0;
  914. });
  915. });
  916. }
  917. if (!isVisible(elem)) {
  918. var props = {position: 'absolute', visibility: 'hidden', display: 'block'};
  919. var old = {}, old_cssText = false;
  920. if (elem.style.cssText.indexOf('!important') > -1) {
  921. old_cssText = elem.style.cssText;
  922. }
  923. each(props, function(i, v) {
  924. old[i] = elem.style[i];
  925. elem.style[i] = v;
  926. });
  927. getWH();
  928. each(props, function(i, v) {
  929. elem.style[i] = old[i];
  930. });
  931. if (old_cssText) {
  932. elem.style.cssText = old_cssText;
  933. }
  934. } else getWH();
  935. }
  936. return s;
  937. }
  938. function toURL(obj) {
  939. var str = "";
  940. for (var key in obj) {
  941. if (str != "") str += "&";
  942. str += key + "=" + encodeURIComponent(obj[key]);
  943. }
  944. return str;
  945. }
  946. function serialize(form) {
  947. var field, s = [];
  948. if (typeof form == 'object' && form.nodeName == "FORM") {
  949. var len = form.elements.length;
  950. for (i=0; i<len; i++) {
  951. field = form.elements[i];
  952. if (field.name && !field.disabled && field.type != 'file' && field.type != 'reset' && field.type != 'submit' && field.type != 'button') {
  953. if (field.type == 'select-multiple') {
  954. for (j=form.elements[i].options.length-1; j>=0; j--) {
  955. if(field.options[j].selected)
  956. s[s.length] = encodeURIComponent(field.name) + "=" + encodeURIComponent(field.options[j].value);
  957. }
  958. } else if ((field.type != 'checkbox' && field.type != 'radio') || field.checked) {
  959. s[s.length] = encodeURIComponent(field.name) + "=" + encodeURIComponent(field.value);
  960. }
  961. }
  962. }
  963. }
  964. return s.join('&').replace(/%20/g, '+');
  965. }
  966. function ce(tagName, attr, style) {
  967. var el = document.createElement(tagName);
  968. if (attr) extend(el, attr);
  969. if (style) setStyle(el, style);
  970. return el;
  971. }
  972. function each(object, callback) {
  973. if (!isObject(object) && typeof object.length !== 'undefined') {
  974. for (var i = 0, length = object.length; i < length; i++) {
  975. var value = object[i];
  976. if (callback.call(value, i, value) === false) break;
  977. }
  978. } else {
  979. for (var name in object) {
  980. if(!Object.prototype.hasOwnProperty.call(object, name)) continue;
  981. if(callback.call(object[name], name, object[name]) === false) break;
  982. }
  983. }
  984. return object;
  985. }
  986. function clone(obj, req) {
  987. var newObj = !isObject(obj) && typeof obj.length !== 'undefined' ? [] : {};
  988. for (var i in obj) {
  989. if (/webkit/i.test(_ua) && (i == 'layerX' || i == 'layerY' || i == 'webkitMovementX' || i == 'webkitMovementY')) continue;
  990. if (req && typeof(obj[i]) === 'object' && i !== 'prototype' && obj[i] !== null) {
  991. newObj[i] = clone(obj[i]);
  992. } else {
  993. newObj[i] = obj[i];
  994. }
  995. }
  996. return newObj;
  997. }
  998.  
  999. function attr(el, attrName, value) {
  1000. el = ge(el);
  1001. if (typeof value == 'undefined') {
  1002. return el.getAttribute(attrName);
  1003. } else {
  1004. el.setAttribute(attrName, value);
  1005. return value;
  1006. }
  1007. }
  1008. function removeAttr(el) {
  1009. for (var i = 0, l = arguments.length; i < l; ++i) {
  1010. var n = arguments[i];
  1011. if (el[n] === undefined) continue;
  1012. try {
  1013. delete el[n];
  1014. } catch(e) {
  1015. try {
  1016. el.removeAttribute(n);
  1017. } catch(e) {}
  1018. }
  1019. }
  1020. }
  1021. function domEL(el, p) {
  1022. p = p ? 'previousSibling' : 'nextSibling';
  1023. while (el && !el.tagName) el = el[p];
  1024. return el;
  1025. }
  1026. function domNS(el) {
  1027. return domEL((el || {}).nextSibling);
  1028. }
  1029. function domPS(el) {
  1030. return domEL((el || {}).previousSibling, 1);
  1031. }
  1032. function domFC(el) {
  1033. return domEL((el || {}).firstChild);
  1034. }
  1035. function domLC(el) {
  1036. return domEL((el || {}).lastChild, 1);
  1037. }
  1038. function domPN(el) {
  1039. return (el || {}).parentNode;
  1040. }
  1041. function domChildren(el) {
  1042. var chidlren = [];
  1043. var nodes = el.childNodes;
  1044. for (var i = 0; i < nodes.length; i++) {
  1045. if (nodes[i].tagName) {
  1046. chidlren.push(nodes[i]);
  1047. }
  1048. }
  1049. return chidlren;
  1050. }
  1051. function show(elem) {
  1052. var l = arguments.length;
  1053. if (l > 1) {
  1054. for (var i = 0; i < l; i++) {
  1055. show(arguments[i]);
  1056. } return;
  1057. }
  1058.  
  1059. elem = ge(elem);
  1060. if(!elem || !elem.style) return;
  1061.  
  1062. var old = elem.olddisplay;
  1063. var newStyle = 'block';
  1064. var tag = elem.tagName.toLowerCase();
  1065. elem.style.display = old || '';
  1066.  
  1067. if(getStyle(elem, 'display') !== 'none') return;
  1068. if(hasClass(elem, 'inline') || hasClass(elem, '_inline')) {
  1069. newStyle = 'inline';
  1070. } else if(hasClass(elem, '_inline_block')) {
  1071. newStyle = 'inline-block';
  1072. } else if(tag === 'tr' && !browser.msie) {
  1073. newStyle = 'table-row';
  1074. } else if(tag === 'table' && !browser.msie) {
  1075. newStyle = 'table';
  1076. } else {
  1077. newStyle = 'block';
  1078. }
  1079. elem.style.display = elem.olddisplay = newStyle;
  1080. sAnim.scroll();
  1081. }
  1082. function hide(elem) {
  1083. var l = arguments.length;
  1084. if (l > 1) {
  1085. for (var i = 0; i < l; i++) {
  1086. hide(arguments[i]);
  1087. } return;
  1088. }
  1089.  
  1090. elem = ge(elem);
  1091. if(!elem || !elem.style) return;
  1092.  
  1093. var display = getStyle(elem, 'display');
  1094. elem.olddisplay = (display != 'none' ? display : '');
  1095. elem.style.display = 'none';
  1096. }
  1097. function cookie(name, value, expires = 86400 * 3600, path = '/') {
  1098. if(!name || /^(?:expires|max\-age|path|domain|secure)$/i.test(name)) return false;
  1099. if(typeof value == 'undefined') {
  1100. return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(name).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || '';
  1101. } else {
  1102. if (expires) {
  1103. switch (expires.constructor) {
  1104. case Number:
  1105. expires = expires === Infinity ? "expires=Fri, 31 Dec 9999 23:59:59 GMT" : "max-age=" + expires;
  1106. break;
  1107. case String:
  1108. expires = "expires=" + expires;
  1109. break;
  1110. case Date:
  1111. expires = "expires=" + expires.toUTCString();
  1112. break;
  1113. default:
  1114. }
  1115. } else expires = 'expires=Fri, 31 Dec 1970 23:59:59 GMT';
  1116. document.cookie = encodeURIComponent(name)+'= '+encodeURIComponent(value)+'; ' + expires + (path ? '; path=' + path : '');
  1117. return true;
  1118. }
  1119. }
  1120. function pa(str) {
  1121. var args = [].slice.call(arguments, 1), i = 0;
  1122. return str.replace(/%s/g, function() {
  1123. return args[i++];
  1124. });
  1125. }
  1126. function pa1(str) {
  1127. var query = str.substr(1);
  1128. var result = {};
  1129. query.split("&").forEach(function(part) {
  1130. var item = part.split("=");
  1131. result[item[0]] = decodeURIComponent(item[1]);
  1132. });
  1133. return result;
  1134. }
  1135. function sortAsc(element) {
  1136. [].map.call(element.children, Object).sort(function(a, b) {
  1137. return +b.id.match(/\d+/) - +a.id.match(/\d+/);
  1138. }).forEach(function(elem) {
  1139. element.appendChild(elem);
  1140. });
  1141. }
  1142. function sortDesc(element) {
  1143. [].map.call(element.children, Object).sort(function(a, b) {
  1144. return +a.id.match(/\d+/) - +b.id.match(/\d+/);
  1145. }).forEach(function(elem) {
  1146. element.appendChild(elem);
  1147. });
  1148. }
  1149. function elsRem(elements) {
  1150. if(typeof(elements.length) != "undefined") elements.forEach(function(el) { el.remove(); });
  1151. else elements.remove();
  1152. }
  1153. function elsFunc(elements, func) {
  1154. if(typeof(elements.length) != "undefined") elements.forEach(function(el) { func(el); });
  1155. else func(elements);
  1156. }
  1157. function sel(selector, all, context) {
  1158. context = context || document;
  1159. if(typeof(all) == "undefined") all = true;
  1160. return all ? context.querySelectorAll(selector) : context.querySelector(selector);
  1161. }
  1162. function eventFunc(evElement, evType) {
  1163. let args = [].splice.call(arguments, 2);
  1164. evElement.ebind('click', function(ev) {
  1165. if(!ev.path.filter(function(el) { return el.matches && el.matches(args[0]); }).length) {
  1166. args[1] && args[1]();
  1167. this.eoff('click');
  1168. }
  1169. }, true);
  1170. }
  1171.  
  1172. // UTILS
  1173. Function.prototype.pbind = function() {
  1174. var args = Array.prototype.slice.call(arguments);
  1175. args.unshift(window);
  1176. return this.bind.apply(this, args);
  1177. };
  1178. Object.prototype.ebind = function(ev, callback, bool = false) {
  1179. this.eoff(ev);
  1180. if(NodeList.prototype.isPrototypeOf(this) || HTMLCollection.prototype.isPrototypeOf(this)) {
  1181. this.forEach(function(v) {
  1182. if(!v.listeners) v.listeners = [];
  1183. let l = v.addEventListener(ev, callback, bool);
  1184. v.listeners.push({type: ev, listener: callback});
  1185. });
  1186. } else {
  1187. if(!this.listeners) this.listeners = [];
  1188. let l = this.addEventListener(ev, callback, bool);
  1189. this.listeners.push({type: ev, listener: callback});
  1190. } return this;
  1191. }
  1192. Object.prototype.eoff = function(ev) {
  1193. if(NodeList.prototype.isPrototypeOf(this) || HTMLCollection.prototype.isPrototypeOf(this)) {
  1194. this.forEach(function(v) {
  1195. if(v.listeners) {
  1196. let listenersCount = v.listeners.length;
  1197. for(let listenersIterator = 0; listenersIterator < c; listenersIterator++) {
  1198. let l = v.listeners[listenersIterator];
  1199. if(l && l.type == ev) {
  1200. this.removeEventListener(ev, l.listener);
  1201. delete v.listeners[listenersIterator];
  1202. }
  1203. }
  1204. }
  1205. });
  1206. } else if(this.listeners) {
  1207. let listenersCount = this.listeners.length;
  1208. for(let listenersIterator = 0; listenersIterator < c; listenersIterator++) {
  1209. let l = this.listeners[listenersIterator];
  1210. if(l && l.type == ev) {
  1211. this.removeEventListener(ev, l.listener);
  1212. delete this.listeners[listenersIterator];
  1213. }
  1214. }
  1215. } return this;
  1216. }
  1217.  
  1218. // CSS
  1219. function hasClass(obj, name) {
  1220. obj = ge(obj);
  1221. if(obj && obj.nodeType === 1 && (' ' + obj.className + ' ').replace(/[\t\r\n\f]/g, ' ').indexOf(' ' + name + ' ') >= 0) return true;
  1222. return false;
  1223. }
  1224.  
  1225. // EVENTS
  1226. window.onpopstate = function() { return nav.go(location.pathname + location.search, null, null); }
  1227. document.addEventListener('DOMContentLoaded', function() {
  1228. if(window.devicePixelRatio >= 2) stManager.addBody('retina.css');
  1229. stManager.getPage(location.pathname, page.path);
  1230. sAnim.init();
  1231. });
  1232.  
  1233. // FUNC
  1234. function formatDate(date) {
  1235. var day = addDateZero(date.getDate());
  1236. var month = addDateZero(date.getMonth()+1);
  1237. var year = date.getFullYear();
  1238. var hour = addDateZero(date.getHours());
  1239. var minute = addDateZero(date.getMinutes());
  1240. return day+'.'+month+'.'+year+' '+hour+':'+minute;
  1241. }
  1242. function getSpecialDate(timestamp) {
  1243. timestamp = parseInt(timestamp);
  1244. var months = ['Янв','Февр','Март','Апр','Май','Июнь','Июль','Авг','Сент','Окт','Ноя','Дек'];
  1245. var cur = new Date();
  1246. var a = new Date(timestamp * 1000);
  1247. var a_hour = a.getHours(), a_min = a.getMinutes();
  1248. var last_minutes = parseInt(((Math.floor(Date.now() / 1000) / 60) - (timestamp / 60)));
  1249.  
  1250. if (a_hour < 10) var a_hour = '0' + a_hour.toString();
  1251. if (a_min < 10) var a_min = '0' + a_min.toString();
  1252. if(Math.floor(Date.now() / 1000) < (timestamp + 60)) return 'Только что';
  1253. if(Math.floor(Date.now() / 1000) < (timestamp + 60 + 60)) return 'Минуту назад';
  1254. if(Math.floor(Date.now() / 1000) < (timestamp + 60 + 60 + 60)) return 'Две минуты назад';
  1255. if(Math.floor(Date.now() / 1000) < (timestamp + 60 + 60 + 60 + 60)) return 'Три минуты назад';
  1256. if(Math.floor(Date.now() / 1000) < (timestamp + 60 + 60 + 60 + 60 + 60)) return 'Четыре минуты назад';
  1257. if(last_minutes > 0 && last_minutes <= 59) return last_minutes + ' минут назад';
  1258. if(last_minutes > 59 && last_minutes <= 120) return 'Час назад';
  1259. if(last_minutes > 120 && last_minutes <= 180) return 'Два часа назад';
  1260. if(last_minutes > 180 && last_minutes <= 240) return 'Три часа назад';
  1261. if(cur.getDate() == a.getDate() && cur.getFullYear() == a.getFullYear()) return a_hour + ':' + a_min;
  1262. if(cur.getDate() > a.getDate()) return a.getDate()+' '+months[a.getMonth()]+' '+a.getFullYear()+', '+a_hour+':'+a_min;
  1263. }
  1264. function addDateZero(i) {
  1265. if(i < 10) i = '0' + i;
  1266. return i;
  1267. }
  1268. function onBodyResize() {
  1269.  
  1270. if(modality.active) { // modality resize
  1271.  
  1272. if(browser.mobile) return;
  1273. if(geByClass1('modal-box', ge('modal_wrap')).offsetHeight > window.innerHeight) {
  1274. geByClass1('modal-box', ge('modal_wrap')).style.top = geByClass1('modal-box', ge('modal_wrap')).offsetHeight / 2;
  1275. } else geByClass1('modal-box', ge('modal_wrap')).style.top = '';
  1276.  
  1277. if(geByClass1('modal-box', ge('modal_wrap')).offsetWidth > window.innerWidth) {
  1278. geByClass1('modal-box', ge('modal_wrap')).style.left = geByClass1('modal-box', ge('modal_wrap')).offsetWidth / 2;
  1279. } else geByClass1('modal-box', ge('modal_wrap')).style.left = '';
  1280.  
  1281. }
  1282.  
  1283. if((ge('scroll_fix_wrap').scrollHeight - ge('page_footer_wrap').offsetHeight) > window.innerHeight) setStyle(ge('page_footer_wrap'), {display: 'block'});
  1284. else setStyle(ge('page_footer_wrap'), {display: 'none'});
  1285. }
  1286. function topMsg(text, seconds, type) {
  1287. var el = ge('system_msg');
  1288. clearTimeout(window.topMsgTimer);
  1289. if(!type) type = 'default';
  1290. if(!text) return hide('system_msg');
  1291. if(seconds) window.topMsgTimer = setTimeout(topMsg.pbind(false), seconds * 1000);
  1292. el.className = 'fixed';
  1293. el.classList.add(type);
  1294. el.innerHTML = text;
  1295. show(el);
  1296. }
  1297. function msgBox(container, type, message) {
  1298. if(message == undefined) return;
  1299. elsRem(sel('.msg-box'));
  1300. return container.appendChild(ce('div', {className: 'msg-box ' + type, innerHTML: '<div class=\'msg-text\'>'+message+'</div>'}));
  1301. }
  1302. function toAnim(el, offset = 0) {
  1303. if(!el) return;
  1304. animate(ge('scroll_fix_wrap'), { scrollTop: el.offsetTop + offset }, 500);
  1305. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement