Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.35 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. show(ntList);
  349. data.success.forEach(data => {
  350. 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>');
  351. elsFunc(sel('.__new'), function(el) {
  352. ntCount.innerHTML = parseInt(ntCount.innerHTML) - 1;
  353. if(parseInt(ntCount.innerHTML) < 1) hide(ntCount);
  354. else show(ntCount);
  355. setTimeout(function() { el.classList.remove('__new'); }, 2000);
  356. });
  357. });
  358. });
  359. },
  360.  
  361. hide: function() {
  362. var nt = geByClass1('top-notify-wrap', ge('page_header_wrap'));
  363. if(!nt) return;
  364. if(!nt.classList.contains('shown')) return;
  365. nt.classList.remove('shown');
  366. }
  367.  
  368. }
  369.  
  370. // FX
  371.  
  372. var Fx = {
  373.  
  374. Transitions: {
  375. linear: function(t, b, c, d) { return c*t/d + b; },
  376. sineInOut: function(t, b, c, d) { return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; },
  377. halfSine: function(t, b, c, d) { return c * (Math.sin(Math.PI * (t/d) / 2)) + b; },
  378. easeOutBack: function(t, b, c, d) { var s = 1.70158; return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; },
  379. easeInCirc: function(t, b, c, d) { return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b; },
  380. easeOutCirc: function(t, b, c, d) { return c * Math.sqrt(1 - (t=t/d-1)*t) + b; },
  381. easeInQuint: function(t, b, c, d) { return c*(t/=d)*t*t*t*t + b; },
  382. easeOutQuint: function(t, b, c, d) { return c*((t=t/d-1)*t*t*t*t + 1) + b; },
  383. easeOutCubic: function(t, b, c, d) { return c*((t=t/d-1)*t*t + 1) + b;},
  384. swiftOut: function(t, b, c, d) { return c * cubicBezier(0.4, 0, 0.22, 1, t/d, 4/d) + b; }
  385. },
  386. Attrs: [
  387. [ 'height', 'marginTop', 'marginBottom', 'paddingTop', 'paddingBottom' ],
  388. [ 'width', 'marginLeft', 'marginRight', 'paddingLeft', 'paddingRight' ],
  389. [ 'opacity', 'left', 'top' ]
  390. ],
  391. Timers: [],
  392. TimerId: null
  393.  
  394. }, fx = Fx;
  395.  
  396. Fx.Base = function(el, options, name) {
  397. this.el = ge(el);
  398. this.name = name;
  399. this.options = extend({
  400. onStep: function(){},
  401. onComplete: function() {},
  402. transition: options.transition || Fx.Transitions.sineInOut,
  403. duration: 500
  404. }, options || {});
  405. }
  406.  
  407. Fx.Base.prototype = {
  408. start: function(from, to){
  409. this.from = from;
  410. this.to = to;
  411. this.time = arpNow();
  412. this.isTweening = true;
  413.  
  414. var self = this;
  415. function t(gotoEnd) {
  416. return self.step(gotoEnd);
  417. }
  418. t.el = this.el;
  419. if (t() && Fx.Timers.push(t) && !Fx.TimerId) {
  420. Fx.TimerId = setInterval(function() {
  421. var timers = Fx.Timers, l = timers.length;
  422. for (var i = 0; i < l; i++) {
  423. if (!timers[i]()) {
  424. timers.splice(i--, 1);
  425. l--;
  426. }
  427. }
  428. if (!l) {
  429. clearInterval(Fx.TimerId);
  430. Fx.TimerId = null;
  431. }
  432. }, 13);
  433. }
  434. return this;
  435. },
  436.  
  437. stop: function(gotoEnd) {
  438. var timers = Fx.Timers;
  439. for (var i = timers.length - 1; i >= 0; i--) {
  440. if (timers[i].el == this.el ) {
  441. if (gotoEnd) {
  442. timers[i](true);
  443. }
  444. timers.splice(i, 1);
  445. }
  446. }
  447. this.isTweening = false;
  448. },
  449.  
  450. step: function(gotoEnd) {
  451. var time = arpNow();
  452. if (!gotoEnd && time < this.time + this.options.duration) {
  453. this.cTime = time - this.time;
  454. this.now = {};
  455. for (p in this.to) {
  456. if (isArray(this.to[p])) {
  457. var color = [], j;
  458. for (j = 0; j < 3; j++) {
  459. if (this.from[p] === undefined || this.to[p] === undefined) {
  460. return false;
  461. }
  462. color.push(Math.min(parseInt(this.compute(this.from[p][j], this.to[p][j])), 255));
  463. }
  464. this.now[p] = color;
  465. } else {
  466. this.now[p] = this.compute(this.from[p], this.to[p]);
  467. if (this.options.discrete) this.now[p] = intval(this.now[p]);
  468. }
  469. }
  470. this.update();
  471. return true;
  472. } else {
  473. setTimeout(this.options.onComplete.bind(this, this.el), 10);
  474. this.now = extend(this.to, this.options.orig);
  475. this.update();
  476. if (this.options.hide) hide(this.el);
  477. this.isTweening = false;
  478. return false;
  479. }
  480. },
  481.  
  482. compute: function(from, to){
  483. var change = to - from;
  484. return this.options.transition(this.cTime, from, change, this.options.duration);
  485. },
  486.  
  487. update: function(){
  488. this.options.onStep(this.now);
  489. for (var p in this.now) {
  490. if (isArray(this.now[p])) setStyle(this.el, p, 'rgb(' + this.now[p].join(',') + ')');
  491. else this.el[p] != undefined ? (this.el[p] = this.now[p]) : setStyle(this.el, p, this.now[p]);
  492. }
  493. },
  494.  
  495. cur: function(name, force){
  496. if (this.el[name] != null && (!this.el.style || this.el.style[name] == null))
  497. return this.el[name];
  498. return parseFloat(getStyle(this.el, name, force)) || 0;
  499. }
  500. };
  501.  
  502. function genFx(type, num) {
  503. var obj = {};
  504. each(Fx.Attrs.concat.apply([], Fx.Attrs.slice(0, num)), function() {
  505. obj[this] = type;
  506. });
  507. return obj;
  508. }
  509.  
  510. // DOM
  511. function rand(mi, ma) { return Math.random() * (ma - mi + 1) + mi; }
  512. function irand(mi, ma) { return Math.floor(rand(mi, ma)); }
  513. function isUndefined(obj) { return typeof obj === 'undefined' };
  514. function isFunction(obj) {return obj && Object.prototype.toString.call(obj) === '[object Function]'; }
  515. function isArray(obj) { return Object.prototype.toString.call(obj) === '[object Array]'; }
  516. function isString(obj) { return typeof obj === 'string'; }
  517. function isObject(obj) { return Object.prototype.toString.call(obj) === '[object Object]'; }
  518. 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; }
  519. function arpNow() { return +new Date; }
  520. function arpImage() { return window.Image ? (new Image()) : ce('img'); } // IE8 workaround
  521. function trim(text) { return (text || '').replace(/^\s+|\s+$/g, ''); }
  522. function stripHTML(text) { return text ? text.replace(/<(?:.|\s)*?>/g, '') : ''; }
  523. function escapeRE(s) { return s ? s.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1') : ''; }
  524. function boundingRectEnabled(obj) { return (typeof obj.getBoundingClientRect !== 'undefined'); }
  525. function intval(value) {
  526. if (value === true) return 1;
  527. return parseInt(value) || 0;
  528. }
  529. function floatval(value) {
  530. if (value === true) return 1;
  531. return parseFloat(value) || 0;
  532. }
  533. function positive(value) {
  534. value = intval(value);
  535. return value < 0 ? 0 : value;
  536. }
  537. function isNumeric(value) {
  538. return !isNaN(value);
  539. }
  540. function isVisible(elem) {
  541. elem = ge(elem);
  542. if (!elem || !elem.style) return false;
  543. return getStyle(elem, 'display') != 'none';
  544. }
  545.  
  546. function ge(el) {
  547. return (typeof el == 'string' || typeof el == 'number') ? document.getElementById(el) : el;
  548. }
  549. function geByTag(searchTag, node) {
  550. node = ge(node) || document;
  551. return node.getElementsByTagName(searchTag);
  552. }
  553. function gpeByClass(className, elem, stopElement) {
  554. elem = ge(elem);
  555. if (!elem) return null;
  556. while (stopElement !== elem && (elem = elem.parentNode)) {
  557. if (hasClass(elem, className)) return elem;
  558. }
  559. return null;
  560. }
  561. function geByClass1(searchClass, node, tag) {
  562. node = ge(node) || document;
  563. tag = tag || '*';
  564. return node.querySelector && node.querySelector(tag + '.' + searchClass) || geByClass(searchClass, node, tag)[0];
  565. }
  566. function geByClass(searchClass, node, tag) {
  567.  
  568. node = ge(node) || document;
  569. tag = tag || '*';
  570. var classElements = [];
  571.  
  572. if (node.querySelectorAll && tag != '*') {
  573. return node.querySelectorAll(tag + '.' + searchClass);
  574. }
  575.  
  576. if (node.getElementsByClassName) {
  577. var nodes = node.getElementsByClassName(searchClass);
  578. if (tag != '*') {
  579. tag = tag.toUpperCase();
  580. for (var i = 0, l = nodes.length; i < l; ++i) {
  581. if (nodes[i].tagName.toUpperCase() == tag) {
  582. classElements.push(nodes[i]);
  583. }
  584. }
  585. } else {
  586. classElements = Array.prototype.slice.call(nodes);
  587. }
  588. return classElements;
  589. }
  590.  
  591. var els = geByTag(tag, node);
  592. var pattern = new RegExp('(^|\\s)' + searchClass + '(\\s|$)');
  593. for (var i = 0, l = els.length; i < l; ++i) {
  594. if (pattern.test(els[i].className)) {
  595. classElements.push(els[i]);
  596. }
  597. }
  598.  
  599. return classElements;
  600.  
  601. }
  602. function extend() {
  603. var a = arguments, target = a[0] || {}, i = 1, l = a.length, deep = false, options;
  604. if (typeof target === 'boolean') {
  605. deep = target;
  606. target = a[1] || {};
  607. i = 2;
  608. }
  609.  
  610. if (typeof target !== 'object' && !isFunction(target)) target = {};
  611.  
  612. for (; i < l; ++i) {
  613. if ((options = a[i]) != null) {
  614. for (var name in options) {
  615. var src = target[name], copy = options[name];
  616. if (target === copy) continue;
  617. if (deep && copy && typeof copy === 'object' && !copy.nodeType) {
  618. target[name] = extend(deep, src || (copy.length != null ? [] : {}), copy);
  619. } else if (copy !== undefined) {
  620. target[name] = copy;
  621. }
  622. }
  623. }
  624. }
  625. return target;
  626. }
  627. function getRGB(color) {
  628. var result;
  629. if (color && isArray(color) && color.length == 3)
  630. return color;
  631. if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
  632. return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
  633. if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
  634. return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
  635. if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
  636. return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
  637. if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
  638. return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
  639. }
  640. function getColor(elem, attr) {
  641. var color;
  642. do {
  643. color = getStyle(elem, attr);
  644. if (!color.indexOf('rgba')) color = '';
  645. if (color != '' && color != 'transparent' || elem.nodeName.toLowerCase() == 'body') {
  646. break;
  647. }
  648. attr = 'backgroundColor';
  649. } while (elem = elem.parentNode);
  650. return getRGB(color);
  651. }
  652. function setStyle(elem, name, value){
  653. elem = ge(elem);
  654. if (!elem) return;
  655. if (typeof name == 'object') return each(name, function(k, v) { setStyle(elem,k,v); });
  656. if (name == 'opacity') {
  657. if (browser.msie) {
  658. if ((value + '').length) {
  659. if (value !== 1) {
  660. elem.style.filter = 'alpha(opacity=' + value * 100 + ')';
  661. } else {
  662. elem.style.filter = '';
  663. }
  664. } else {
  665. elem.style.cssText = elem.style.cssText.replace(/filter\s*:[^;]*/gi, '');
  666. }
  667. elem.style.zoom = 1;
  668. };
  669. elem.style.opacity = value;
  670. } else {
  671. try {
  672. var isN = typeof(value) == 'number';
  673. if (isN && (/height|width/i).test(name)) value = Math.abs(value);
  674. elem.style[name] = isN && !(/z-?index|font-?weight|opacity|zoom|line-?height/i).test(name) ? value + 'px' : value;
  675. } catch(e) { debugLog('setStyle error: ', [name, value], e); }
  676. }
  677. }
  678. function getStyle(elem, name, force) {
  679. elem = ge(elem);
  680. if (isArray(name)) { var res = {}; each(name, function(i,v){res[v] = getStyle(elem, v);}); return res; }
  681. if (!elem) return '';
  682. if (force === undefined) {
  683. force = true;
  684. }
  685. if (!force && name == 'opacity' && browser.msie) {
  686. var filter = elem.style['filter'];
  687. return filter ? (filter.indexOf('opacity=') >= 0 ?
  688. (parseFloat(filter.match(/opacity=([^)]*)/)[1] ) / 100) + '' : '1') : '';
  689. }
  690. if (!force && elem.style && (elem.style[name] || name == 'height')) {
  691. return elem.style[name];
  692. }
  693.  
  694. var ret, defaultView = document.defaultView || window;
  695. if (defaultView.getComputedStyle) {
  696. name = name.replace(/([A-Z])/g, '-$1').toLowerCase();
  697. var computedStyle = defaultView.getComputedStyle(elem, null);
  698. if (computedStyle) {
  699. ret = computedStyle.getPropertyValue(name);
  700. }
  701. } else if (elem.currentStyle) {
  702. if (name == 'opacity' && browser.msie) {
  703. var filter = elem.currentStyle['filter'];
  704. return filter && filter.indexOf('opacity=') >= 0 ?
  705. (parseFloat(filter.match(/opacity=([^)]*)/)[1]) / 100) + '' : '1';
  706. }
  707. var camelCase = name.replace(/\-(\w)/g, function(all, letter){
  708. return letter.toUpperCase();
  709. });
  710. ret = elem.currentStyle[name] || elem.currentStyle[camelCase];
  711. if (ret == 'auto') {
  712. ret = 0;
  713. }
  714.  
  715. ret = (ret + '').split(' ');
  716. each(ret, function(i,v) {
  717. if (!/^\d+(px)?$/i.test(v) && /^\d/.test(v)) {
  718. var style = elem.style, left = style.left, rsLeft = elem.runtimeStyle.left;
  719. elem.runtimeStyle.left = elem.currentStyle.left;
  720. style.left = v || 0;
  721. ret[i] = style.pixelLeft + 'px';
  722. style.left = left;
  723. elem.runtimeStyle.left = rsLeft;
  724. }
  725. });
  726. ret = ret.join(' ');
  727. }
  728.  
  729. if (force && (name == 'width' || name == 'height')) {
  730. var ret2 = getSize(elem, true)[({'width': 0, 'height': 1})[name]];
  731. ret = (intval(ret) ? Math.max(floatval(ret), ret2) : ret2) + 'px';
  732. }
  733.  
  734. return ret;
  735. }
  736. function data(elem, name, data) {
  737. if (!elem) return false;
  738. var id = elem[arpExpand], undefined;
  739. if (data !== undefined) {
  740. if (!arpCache[id]) arpCache[id] = {};
  741. arpCache[id][name] = data;
  742. }
  743. return name ? arpCache[id] && arpCache[id][name] : id;
  744. }
  745. function animate(el, params, speed, callback) {
  746. el = ge(el);
  747. if (!el) return;
  748. var _cb = isFunction(callback) ? callback : function() {};
  749. var options = extend({}, typeof speed == 'object' ? speed : {duration: speed, onComplete: _cb});
  750. var fromArr = {}, toArr = {}, visible = isVisible(el), self = this, p;
  751. options.orig = {};
  752. params = clone(params);
  753. if (params.discrete) {
  754. options.discrete = 1;
  755. delete(params.discrete);
  756. }
  757. if (browser.iphone) options.duration = 0;
  758.  
  759. var tween = data(el, 'tween'), i, name, toggleAct = visible ? 'hide' : 'show';
  760. if (tween && tween.isTweening) {
  761. options.orig = extend(options.orig, tween.options.orig);
  762. tween.stop(false);
  763. if (tween.options.show) toggleAct = 'hide';
  764. else if (tween.options.hide) toggleAct = 'show';
  765. }
  766. for (p in params) {
  767. if (!tween && (params[p] == 'show' && visible || params[p] == 'hide' && !visible)) {
  768. return options.onComplete.call(this, el);
  769. }
  770. if ((p == 'height' || p == 'width') && el.style) {
  771. if (!params.overflow) {
  772. if (options.orig.overflow == undefined) {
  773. options.orig.overflow = getStyle(el, 'overflow');
  774. }
  775. el.style.overflow = 'hidden';
  776. }
  777. if (!hasClass(el, 'inl_bl') && el.tagName != 'TD') {
  778. el.style.display = 'block';
  779. }
  780. }
  781. if (/show|hide|toggle/.test(params[p])) {
  782. if (params[p] == 'toggle') {
  783. params[p] = toggleAct;
  784. }
  785. if (params[p] == 'show') {
  786. var from = 0;
  787. options.show = true;
  788. if (options.orig[p] == undefined) {
  789. options.orig[p] = getStyle(el, p, false) || '';
  790. setStyle(el, p, 0);
  791. }
  792.  
  793. var o = options.orig[p];
  794. var old = el.style[p];
  795. el.style[p] = o;
  796. params[p] = parseFloat(getStyle(el, p, true));
  797. el.style[p] = old;
  798.  
  799. if (p == 'height' && browser.msie && !params.overflow) {
  800. el.style.overflow = 'hidden';
  801. }
  802. } else {
  803. if (options.orig[p] == undefined) {
  804. options.orig[p] = getStyle(el, p, false) || '';
  805. }
  806. options.hide = true;
  807. params[p] = 0;
  808. }
  809. }
  810. }
  811. if (options.show && !visible) {
  812. show(el);
  813. }
  814. tween = new Fx.Base(el, options);
  815. each(params, function(name, to) {
  816. if(/backgroundColor|borderBottomColor|borderLeftColor|borderRightColor|borderTopColor|color|borderColor|outlineColor/.test(name)) {
  817. var p = (name == 'borderColor') ? 'borderTopColor' : name;
  818. from = getColor(el, p);
  819. to = getRGB(to);
  820. if (from === undefined) return;
  821. } else {
  822. var parts = to.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
  823. start = tween.cur(name, true) || 0;
  824. if (parts) {
  825. to = parseFloat(parts[2]);
  826. if (parts[1]) {
  827. to = ((parts[1] == '-=' ? -1 : 1) * to) + to;
  828. }
  829. }
  830.  
  831. from = tween.cur(name, true);
  832. if (from == 0 && (name == 'width' || name == 'height'))
  833. from = 1;
  834.  
  835. if (name == 'opacity' && to > 0 && !visible) {
  836. setStyle(el, 'opacity', 0);
  837. from = 0;
  838. show(el);
  839. }
  840. }
  841. if (from != to || (isArray(from) && from.join(',') == to.join(','))) {
  842. fromArr[name] = from;
  843. toArr[name] = to;
  844. }
  845. });
  846.  
  847. tween.start(fromArr, toArr);
  848. data(el, 'tween', tween);
  849. return tween;
  850. }
  851. function getXYRect(obj, notBounding) {
  852. var rect;
  853. if (notBounding && getStyle(obj, 'display') == 'inline') {
  854. var rects = obj.getClientRects();
  855. rect = rects && rects[0] || obj.getBoundingClientRect();
  856. } else {
  857. rect = obj.getBoundingClientRect();
  858. }
  859. return rect;
  860. }
  861. function getXY(obj, forFixed) {
  862. obj = ge(obj);
  863. if (!obj) return [0,0];
  864.  
  865. var docElem, win,
  866. rect = {top: 0, left: 0},
  867. doc = obj.ownerDocument;
  868. if (!doc) {
  869. return [0, 0];
  870. }
  871. docElem = doc.documentElement;
  872.  
  873. if (boundingRectEnabled(obj)) {
  874. rect = getXYRect(obj, true);
  875. }
  876. win = doc == doc.window ? doc : (doc.nodeType === 9 ? doc.defaultView || doc.parentWindow : false);
  877. return [
  878. rect.left + (!forFixed ? win.pageXOffset || docElem.scrollLeft : 0) - (docElem.clientLeft || 0),
  879. rect.top + (!forFixed ? win.pageYOffset || docElem.scrollTop : 0) - (docElem.clientTop || 0)
  880. ];
  881. }
  882. function isWindow(el) {
  883. return el != null && el === el.window;
  884. }
  885. function getSize(elem, withoutBounds, notBounding) {
  886. elem = ge(elem);
  887. var s = [0, 0], de = document.documentElement, rect;
  888. if (withoutBounds && getStyle(elem, 'boxSizing') === 'border-box') {
  889. withoutBounds = false;
  890. }
  891. if (elem == document) {
  892. s = [Math.max(
  893. de.clientWidth,
  894. bodyNode.scrollWidth, de.scrollWidth,
  895. bodyNode.offsetWidth, de.offsetWidth
  896. ), Math.max(
  897. de.clientHeight,
  898. bodyNode.scrollHeight, de.scrollHeight,
  899. bodyNode.offsetHeight, de.offsetHeight
  900. )];
  901. } else if (elem) {
  902. function getWH() {
  903. if (boundingRectEnabled(elem) && (rect = getXYRect(elem, notBounding)) && rect.width !== undefined) {
  904. s = [rect.width, rect.height];
  905. } else {
  906. s = [elem.offsetWidth, elem.offsetHeight];
  907. }
  908. if (!withoutBounds) return;
  909. var padding = 0, border = 0;
  910. each(s, function(i, v) {
  911. var which = i ? ['Top', 'Bottom'] : ['Left', 'Right'];
  912. each(which, function(){
  913. s[i] -= parseFloat(getStyle(elem, 'padding' + this)) || 0;
  914. s[i] -= parseFloat(getStyle(elem, 'border' + this + 'Width')) || 0;
  915. });
  916. });
  917. }
  918. if (!isVisible(elem)) {
  919. var props = {position: 'absolute', visibility: 'hidden', display: 'block'};
  920. var old = {}, old_cssText = false;
  921. if (elem.style.cssText.indexOf('!important') > -1) {
  922. old_cssText = elem.style.cssText;
  923. }
  924. each(props, function(i, v) {
  925. old[i] = elem.style[i];
  926. elem.style[i] = v;
  927. });
  928. getWH();
  929. each(props, function(i, v) {
  930. elem.style[i] = old[i];
  931. });
  932. if (old_cssText) {
  933. elem.style.cssText = old_cssText;
  934. }
  935. } else getWH();
  936. }
  937. return s;
  938. }
  939. function toURL(obj) {
  940. var str = "";
  941. for (var key in obj) {
  942. if (str != "") str += "&";
  943. str += key + "=" + encodeURIComponent(obj[key]);
  944. }
  945. return str;
  946. }
  947. function serialize(form) {
  948. var field, s = [];
  949. if (typeof form == 'object' && form.nodeName == "FORM") {
  950. var len = form.elements.length;
  951. for (i=0; i<len; i++) {
  952. field = form.elements[i];
  953. if (field.name && !field.disabled && field.type != 'file' && field.type != 'reset' && field.type != 'submit' && field.type != 'button') {
  954. if (field.type == 'select-multiple') {
  955. for (j=form.elements[i].options.length-1; j>=0; j--) {
  956. if(field.options[j].selected)
  957. s[s.length] = encodeURIComponent(field.name) + "=" + encodeURIComponent(field.options[j].value);
  958. }
  959. } else if ((field.type != 'checkbox' && field.type != 'radio') || field.checked) {
  960. s[s.length] = encodeURIComponent(field.name) + "=" + encodeURIComponent(field.value);
  961. }
  962. }
  963. }
  964. }
  965. return s.join('&').replace(/%20/g, '+');
  966. }
  967. function ce(tagName, attr, style) {
  968. var el = document.createElement(tagName);
  969. if (attr) extend(el, attr);
  970. if (style) setStyle(el, style);
  971. return el;
  972. }
  973. function each(object, callback) {
  974. if (!isObject(object) && typeof object.length !== 'undefined') {
  975. for (var i = 0, length = object.length; i < length; i++) {
  976. var value = object[i];
  977. if (callback.call(value, i, value) === false) break;
  978. }
  979. } else {
  980. for (var name in object) {
  981. if(!Object.prototype.hasOwnProperty.call(object, name)) continue;
  982. if(callback.call(object[name], name, object[name]) === false) break;
  983. }
  984. }
  985. return object;
  986. }
  987. function clone(obj, req) {
  988. var newObj = !isObject(obj) && typeof obj.length !== 'undefined' ? [] : {};
  989. for (var i in obj) {
  990. if (/webkit/i.test(_ua) && (i == 'layerX' || i == 'layerY' || i == 'webkitMovementX' || i == 'webkitMovementY')) continue;
  991. if (req && typeof(obj[i]) === 'object' && i !== 'prototype' && obj[i] !== null) {
  992. newObj[i] = clone(obj[i]);
  993. } else {
  994. newObj[i] = obj[i];
  995. }
  996. }
  997. return newObj;
  998. }
  999.  
  1000. function attr(el, attrName, value) {
  1001. el = ge(el);
  1002. if (typeof value == 'undefined') {
  1003. return el.getAttribute(attrName);
  1004. } else {
  1005. el.setAttribute(attrName, value);
  1006. return value;
  1007. }
  1008. }
  1009. function removeAttr(el) {
  1010. for (var i = 0, l = arguments.length; i < l; ++i) {
  1011. var n = arguments[i];
  1012. if (el[n] === undefined) continue;
  1013. try {
  1014. delete el[n];
  1015. } catch(e) {
  1016. try {
  1017. el.removeAttribute(n);
  1018. } catch(e) {}
  1019. }
  1020. }
  1021. }
  1022. function domEL(el, p) {
  1023. p = p ? 'previousSibling' : 'nextSibling';
  1024. while (el && !el.tagName) el = el[p];
  1025. return el;
  1026. }
  1027. function domNS(el) {
  1028. return domEL((el || {}).nextSibling);
  1029. }
  1030. function domPS(el) {
  1031. return domEL((el || {}).previousSibling, 1);
  1032. }
  1033. function domFC(el) {
  1034. return domEL((el || {}).firstChild);
  1035. }
  1036. function domLC(el) {
  1037. return domEL((el || {}).lastChild, 1);
  1038. }
  1039. function domPN(el) {
  1040. return (el || {}).parentNode;
  1041. }
  1042. function domChildren(el) {
  1043. var chidlren = [];
  1044. var nodes = el.childNodes;
  1045. for (var i = 0; i < nodes.length; i++) {
  1046. if (nodes[i].tagName) {
  1047. chidlren.push(nodes[i]);
  1048. }
  1049. }
  1050. return chidlren;
  1051. }
  1052. function show(elem) {
  1053. var l = arguments.length;
  1054. if (l > 1) {
  1055. for (var i = 0; i < l; i++) {
  1056. show(arguments[i]);
  1057. } return;
  1058. }
  1059.  
  1060. elem = ge(elem);
  1061. if(!elem || !elem.style) return;
  1062.  
  1063. var old = elem.olddisplay;
  1064. var newStyle = 'block';
  1065. var tag = elem.tagName.toLowerCase();
  1066. elem.style.display = old || '';
  1067.  
  1068. if(getStyle(elem, 'display') !== 'none') return;
  1069. if(hasClass(elem, 'inline') || hasClass(elem, '_inline')) {
  1070. newStyle = 'inline';
  1071. } else if(hasClass(elem, '_inline_block')) {
  1072. newStyle = 'inline-block';
  1073. } else if(tag === 'tr' && !browser.msie) {
  1074. newStyle = 'table-row';
  1075. } else if(tag === 'table' && !browser.msie) {
  1076. newStyle = 'table';
  1077. } else {
  1078. newStyle = 'block';
  1079. }
  1080. elem.style.display = elem.olddisplay = newStyle;
  1081. sAnim.scroll();
  1082. }
  1083. function hide(elem) {
  1084. var l = arguments.length;
  1085. if (l > 1) {
  1086. for (var i = 0; i < l; i++) {
  1087. hide(arguments[i]);
  1088. } return;
  1089. }
  1090.  
  1091. elem = ge(elem);
  1092. if(!elem || !elem.style) return;
  1093.  
  1094. var display = getStyle(elem, 'display');
  1095. elem.olddisplay = (display != 'none' ? display : '');
  1096. elem.style.display = 'none';
  1097. }
  1098. function cookie(name, value, expires = 86400 * 3600, path = '/') {
  1099. if(!name || /^(?:expires|max\-age|path|domain|secure)$/i.test(name)) return false;
  1100. if(typeof value == 'undefined') {
  1101. return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(name).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || '';
  1102. } else {
  1103. if (expires) {
  1104. switch (expires.constructor) {
  1105. case Number:
  1106. expires = expires === Infinity ? "expires=Fri, 31 Dec 9999 23:59:59 GMT" : "max-age=" + expires;
  1107. break;
  1108. case String:
  1109. expires = "expires=" + expires;
  1110. break;
  1111. case Date:
  1112. expires = "expires=" + expires.toUTCString();
  1113. break;
  1114. default:
  1115. }
  1116. } else expires = 'expires=Fri, 31 Dec 1970 23:59:59 GMT';
  1117. document.cookie = encodeURIComponent(name)+'= '+encodeURIComponent(value)+'; ' + expires + (path ? '; path=' + path : '');
  1118. return true;
  1119. }
  1120. }
  1121. function pa(str) {
  1122. var args = [].slice.call(arguments, 1), i = 0;
  1123. return str.replace(/%s/g, function() {
  1124. return args[i++];
  1125. });
  1126. }
  1127. function pa1(str) {
  1128. var query = str.substr(1);
  1129. var result = {};
  1130. query.split("&").forEach(function(part) {
  1131. var item = part.split("=");
  1132. result[item[0]] = decodeURIComponent(item[1]);
  1133. });
  1134. return result;
  1135. }
  1136. function sortAsc(element) {
  1137. [].map.call(element.children, Object).sort(function(a, b) {
  1138. return +b.id.match(/\d+/) - +a.id.match(/\d+/);
  1139. }).forEach(function(elem) {
  1140. element.appendChild(elem);
  1141. });
  1142. }
  1143. function sortDesc(element) {
  1144. [].map.call(element.children, Object).sort(function(a, b) {
  1145. return +a.id.match(/\d+/) - +b.id.match(/\d+/);
  1146. }).forEach(function(elem) {
  1147. element.appendChild(elem);
  1148. });
  1149. }
  1150. function elsRem(elements) {
  1151. if(typeof(elements.length) != "undefined") elements.forEach(function(el) { el.remove(); });
  1152. else elements.remove();
  1153. }
  1154. function elsFunc(elements, func) {
  1155. if(typeof(elements.length) != "undefined") elements.forEach(function(el) { func(el); });
  1156. else func(elements);
  1157. }
  1158. function sel(selector, all, context) {
  1159. context = context || document;
  1160. if(typeof(all) == "undefined") all = true;
  1161. return all ? context.querySelectorAll(selector) : context.querySelector(selector);
  1162. }
  1163. function eventFunc(evElement, evType) {
  1164. let args = [].splice.call(arguments, 2);
  1165. evElement.ebind('click', function(ev) {
  1166. if(!ev.path.filter(function(el) { return el.matches && el.matches(args[0]); }).length) {
  1167. args[1] && args[1]();
  1168. this.eoff('click');
  1169. }
  1170. }, true);
  1171. }
  1172.  
  1173. // UTILS
  1174. Function.prototype.pbind = function() {
  1175. var args = Array.prototype.slice.call(arguments);
  1176. args.unshift(window);
  1177. return this.bind.apply(this, args);
  1178. };
  1179.  
  1180. function createElementFunc(functionName, func, allowMany = true) {
  1181. Element.prototype[functionName] = func;
  1182. if(allowMany) NodeList.prototype[functionName] = HTMLCollection.prototype[functionName] = func;
  1183. return true;
  1184. }
  1185.  
  1186. createElementFunc('ebind', function(ev, callback, bool = false) {
  1187. this.eoff(ev);
  1188. if(NodeList.prototype.isPrototypeOf(this) || HTMLCollection.prototype.isPrototypeOf(this)) {
  1189. this.forEach(function(v) {
  1190. if(!v.listeners) v.listeners = [];
  1191. let l = v.addEventListener(ev, callback, bool);
  1192. v.listeners.push({type: ev, listener: callback});
  1193. });
  1194. } else {
  1195. if(!this.listeners) this.listeners = [];
  1196. let l = this.addEventListener(ev, callback, bool);
  1197. this.listeners.push({type: ev, listener: callback});
  1198. } return this;
  1199. });
  1200.  
  1201. createElementFunc('eoff', function(ev) {
  1202. if(NodeList.prototype.isPrototypeOf(this) || HTMLCollection.prototype.isPrototypeOf(this)) {
  1203. this.forEach(function(v) {
  1204. if(v.listeners) {
  1205. let listenersCount = v.listeners.length;
  1206. for(let listenersIterator = 0; listenersIterator < c; listenersIterator++) {
  1207. let l = v.listeners[listenersIterator];
  1208. if(l && l.type == ev) {
  1209. this.removeEventListener(ev, l.listener);
  1210. delete v.listeners[listenersIterator];
  1211. }
  1212. }
  1213. }
  1214. });
  1215. } else if(this.listeners) {
  1216. let listenersCount = this.listeners.length;
  1217. for(let listenersIterator = 0; listenersIterator < c; listenersIterator++) {
  1218. let l = this.listeners[listenersIterator];
  1219. if(l && l.type == ev) {
  1220. this.removeEventListener(ev, l.listener);
  1221. delete this.listeners[listenersIterator];
  1222. }
  1223. }
  1224. } return this;
  1225. });
  1226.  
  1227. // CSS
  1228. function hasClass(obj, name) {
  1229. obj = ge(obj);
  1230. if(obj && obj.nodeType === 1 && (' ' + obj.className + ' ').replace(/[\t\r\n\f]/g, ' ').indexOf(' ' + name + ' ') >= 0) return true;
  1231. return false;
  1232. }
  1233.  
  1234. // EVENTS
  1235. window.onpopstate = function() { return nav.go(location.pathname + location.search, null, null); }
  1236. document.addEventListener('DOMContentLoaded', function() {
  1237. if(window.devicePixelRatio >= 2) stManager.addBody('retina.css');
  1238. stManager.getPage(location.pathname, page.path);
  1239. sAnim.init();
  1240. });
  1241.  
  1242. // FUNC
  1243. function formatDate(date) {
  1244. var day = addDateZero(date.getDate());
  1245. var month = addDateZero(date.getMonth()+1);
  1246. var year = date.getFullYear();
  1247. var hour = addDateZero(date.getHours());
  1248. var minute = addDateZero(date.getMinutes());
  1249. return day+'.'+month+'.'+year+' '+hour+':'+minute;
  1250. }
  1251. function getSpecialDate(timestamp) {
  1252. timestamp = parseInt(timestamp);
  1253. var months = ['Янв','Февр','Март','Апр','Май','Июнь','Июль','Авг','Сент','Окт','Ноя','Дек'];
  1254. var cur = new Date();
  1255. var a = new Date(timestamp * 1000);
  1256. var a_hour = a.getHours(), a_min = a.getMinutes();
  1257. var last_minutes = parseInt(((Math.floor(Date.now() / 1000) / 60) - (timestamp / 60)));
  1258.  
  1259. if (a_hour < 10) var a_hour = '0' + a_hour.toString();
  1260. if (a_min < 10) var a_min = '0' + a_min.toString();
  1261. if(Math.floor(Date.now() / 1000) < (timestamp + 60)) return 'Только что';
  1262. if(Math.floor(Date.now() / 1000) < (timestamp + 60 + 60)) return 'Минуту назад';
  1263. if(Math.floor(Date.now() / 1000) < (timestamp + 60 + 60 + 60)) return 'Две минуты назад';
  1264. if(Math.floor(Date.now() / 1000) < (timestamp + 60 + 60 + 60 + 60)) return 'Три минуты назад';
  1265. if(Math.floor(Date.now() / 1000) < (timestamp + 60 + 60 + 60 + 60 + 60)) return 'Четыре минуты назад';
  1266. if(last_minutes > 0 && last_minutes <= 59) return last_minutes + ' минут назад';
  1267. if(last_minutes > 59 && last_minutes <= 120) return 'Час назад';
  1268. if(last_minutes > 120 && last_minutes <= 180) return 'Два часа назад';
  1269. if(last_minutes > 180 && last_minutes <= 240) return 'Три часа назад';
  1270. if(cur.getDate() == a.getDate() && cur.getFullYear() == a.getFullYear()) return a_hour + ':' + a_min;
  1271. if(cur.getDate() > a.getDate()) return a.getDate()+' '+months[a.getMonth()]+' '+a.getFullYear()+', '+a_hour+':'+a_min;
  1272. }
  1273. function addDateZero(i) {
  1274. if(i < 10) i = '0' + i;
  1275. return i;
  1276. }
  1277. function onBodyResize() {
  1278.  
  1279. if(modality.active) { // modality resize
  1280.  
  1281. if(browser.mobile) return;
  1282. if(geByClass1('modal-box', ge('modal_wrap')).offsetHeight > window.innerHeight) {
  1283. geByClass1('modal-box', ge('modal_wrap')).style.top = geByClass1('modal-box', ge('modal_wrap')).offsetHeight / 2;
  1284. } else geByClass1('modal-box', ge('modal_wrap')).style.top = '';
  1285.  
  1286. if(geByClass1('modal-box', ge('modal_wrap')).offsetWidth > window.innerWidth) {
  1287. geByClass1('modal-box', ge('modal_wrap')).style.left = geByClass1('modal-box', ge('modal_wrap')).offsetWidth / 2;
  1288. } else geByClass1('modal-box', ge('modal_wrap')).style.left = '';
  1289.  
  1290. }
  1291.  
  1292. if((ge('scroll_fix_wrap').scrollHeight - ge('page_footer_wrap').offsetHeight) > window.innerHeight) setStyle(ge('page_footer_wrap'), {display: 'block'});
  1293. else setStyle(ge('page_footer_wrap'), {display: 'none'});
  1294. }
  1295. function topMsg(text, seconds, type) {
  1296. var el = ge('system_msg');
  1297. clearTimeout(window.topMsgTimer);
  1298. if(!type) type = 'default';
  1299. if(!text) return hide('system_msg');
  1300. if(seconds) window.topMsgTimer = setTimeout(topMsg.pbind(false), seconds * 1000);
  1301. el.className = 'fixed';
  1302. el.classList.add(type);
  1303. el.innerHTML = text;
  1304. show(el);
  1305. }
  1306. function msgBox(container, type, message) {
  1307. if(message == undefined) return;
  1308. elsRem(sel('.msg-box'));
  1309. return container.appendChild(ce('div', {className: 'msg-box ' + type, innerHTML: '<div class=\'msg-text\'>'+message+'</div>'}));
  1310. }
  1311. function toAnim(el, offset = 0) {
  1312. if(!el) return;
  1313. animate(ge('scroll_fix_wrap'), { scrollTop: el.offsetTop + offset }, 500);
  1314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement