Advertisement
Guest User

Untitled

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