var A; A = { init: function() { A.w = $(window); A.P.init(); A.W.init(); A.FORM.init(); A.w.scroll(A.scroll); return A.scroll(); }, scroll: function() { return A.P.scroll(); }, notify: function(x, html = '') { return x.queue(function() { x.html(html).show(300); return x.dequeue(); }); }, // Работа с формами в этом проекте mail: /^([A-Za-z0-9_-]+\.)*[A-Za-z0-9_-]+@[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*\.[A-Za-z]{2,6}$/, FORM: { globalPrepareValidate: function(i, r) { $(".error_text", i.$wrap).remove(); return i.$wrap.removeClass('error good'); }, globalGood: function(i, r) { return i.$wrap.addClass('good'); }, globalBad: function(i, r) { i.$wrap.addClass('error'); return i.$wrap.append($('
' + r.errors.join("
") + '
')); }, init: function() { $.fn.FORM('setGlobalGood', A.FORM.globalGood); $.fn.FORM('setGlobalBad', A.FORM.globalBad); return $.fn.FORM('setPrepareValidate', A.FORM.globalPrepareValidate); } }, setCookie: function(k, v, date) { var cook, domain; domain = ' domain=' + window.location.host + ';'; cook = k + "=" + v + '; expires=' + new Date(date ? date : new Date().getTime() + 5184000000).toGMTString() + '; path=/;'; document.cookie = cook + domain; console.log(cook + domain); return cook; }, getCookie: function(name) { var pattern, regexp; pattern = "(?:; )?" + name + "=([^;]*);?"; regexp = new RegExp(pattern); if (regexp.test(document.cookie)) { return decodeURIComponent(RegExp["$1"]); } return false; }, reachYandex: function(x) {}, //yaCounter43782099?.reachGoal(x) reachGoogle: function(x, y, z) { return typeof ga === "function" ? ga('send', 'event', x, y, z) : void 0; } }; $(document).ready(A.init); // u - url // d - data // c - callback // cd - callback data var API, API_THEME; API = function(u, d = {}, c = null, cd = {}) { var url; d['nocache'] = (new Date()).getTime(); url = "/api/" + u + "/"; console.log(url, d); return $.ajax({ url: url, type: "POST", dataType: d.dataType !== void 0 ? d.dataType : "html", data: d, success: function(data) { if (c !== null) { return typeof c === "function" ? c(data, cd) : void 0; } }, error: function() { return typeof c === "function" ? c({ error: 1 }, cd) : void 0; } }); }; API_THEME = 'themes.opr/'; var H; H = { menu: {}, selected: {}, top_selected: null, inited: false, dir: '', // up | down | left | right title: null, data: null, scroll: [], isLoading: false, data: null, ready: function() { if (!H.inited) { $(window).on('popstate', H.switchByWindow); H.inited = true; H.body = $("#content"); H.title = $("title"); H.keywords = $("meta[name=keywords]"); H.description = $("meta[name=description]"); H.title = $("title"); //H.switch() H.$html = $("html,body"); $(window).on('scroll', H.onScroll); return H.data = init_data; } }, onScroll: function() { if (!H.isLoading) { return H.scroll[window.location.href] = H.$html.scrollTop(); } }, reload: function() { return H.switch({ animate: false }); }, formGo: function(form) { var $f, action, path, s; s = ($f = $(form)).serialize(); action = $f.attr('action'); if (action === void 0) { action = window.location.pathname; } //console.log action H.go(path = action + '?' + s); return false; }, go: function(x, data = null, title = '', reload = true) { var y; if (x.substr(0, 1) === '/') { x = x.substr(1); } y = '/' + x; H.data = data; history.pushState(data, title, y); if (reload) { return H.switch(); } }, setTitle: function(x) { return H.title.text(x); }, switchByWindow: function(x) { var $c, scrollTo; if (H.now !== window.location.href) { return H.switch(x.state); } else { if (window.location.hash !== '') { if (($c = $(window.location.hash)).length > 0) { scrollTo = $c.offset().top - 65; return H.$html.scrollTop(scrollTo); } } } }, getData: function(x) { var res; res = null; if (H.data !== null) { res = H.data[x]; } return res; }, switch: function(o = { animate: true }) { var path, url; path = H.parse(); url = path.join("/"); if (url === "/" || url === "") { url = "/?justContent=1"; } else { url = `/${url}/?justContent=1`; } if (window.location.search.length > 0) { url += '&' + window.location.search.substr(1); } //console.log url H.isLoading = true; return $.ajax({ url: url, //url:"/#{url}/?mini=1" dataType: "JSON", success: function(data) { var $c, $data, $html, i, j, ref, ref1, s, scrollTo; //console.log data console.log('time_compile', data.time_compile, 'bd_time', data.time_bd); if (typeof data.location === "string" && data.location !== "") { return H.go(data.location); } else { H.data = data.data; H.title.text(data.title); $data = $(data.content); $html = $($data[0]); H.setTitle(data.data.title); H.keywords.attr('content', data.keywords); H.description.attr('content', data.description); //$hide = $(".b_content:not(.hide)").addClass('hide') //$(".b_content").remove() //$.fn.TABLE('allDestroy') H.body.html($html); scrollTo = 0; if (H.scroll[window.location.href] !== void 0) { scrollTo = H.scroll[window.location.href]; } if (window.location.hash !== '') { if (($c = $(window.location.hash)).length > 0) { scrollTo = $c.offset().top - 80; } } A.P.initMini($html, data.data); //A.P.scrollToTop() if ($data.length > 1) { for (i = j = 1, ref = $data.length - 1; (1 <= ref ? j <= ref : j >= ref); i = 1 <= ref ? ++j : --j) { s = document.createElement('script'); if ((ref1 = $data[i].tagName) === 'SCRIPT' || ref1 === 'script') { s.innerHTML = $($data[i]).html(); H.body[0].appendChild(s); } } } //console.log('scrollTo',scrollTo) H.$html.scrollTop(scrollTo); return H.isLoading = false; } }, error: function() { return console.log('history error '); } }); }, SEARCH: { set: function(s, reload = false) { var x; x = window.location.pathname + '?' + s; return H.go(x, null, '', reload); }, parse: function() { var i, pos, res, v, x; res = {}; if (window.location.search.length > 0) { x = window.location.search.substr(1).split('&'); for (i in x) { v = x[i]; pos = v.indexOf('='); if (pos >= 0) { res[v.substr(0, pos)] = v.substr(pos + 1); } else { res[v] = null; } } } return res; }, setValue: function(key, value, reload = false) { var s, x; x = H.SEARCH.parse(); x[key] = value; s = H.SEARCH.toString(x); return H.SEARCH.set(s); }, toString: function(a) { var i, res, v; res = []; for (i in a) { v = a[i]; res.push(i + '=' + (v != null ? v : '')); } return res.join('&'); }, get: function(x) { var e; try { return decodeURI(H.SEARCH.parse()[x]); } catch (error) { e = error; return H.SEARCH.parse()[x]; } } }, //H.SEARCH.parse()[x] parse: function(x = null) { var a, i, j, len, o, url; url = x != null ? x : window.location.pathname; a = url.split("/"); o = []; for (j = 0, len = a.length; j < len; j++) { i = a[j]; if (i !== "") { o.push(i); } } return o; } }; $(window).ready(H.ready); //------------------------------------------------- // A.I = РАБОТА С ПОЛЯМИ ВВОДА //------------------------------------------------- A.I = { waitInput: function(x) { return $(x).each(function() { var button, click, val; button = $(this); click = button.attr('onclick'); val = $.trim(button.val()); return button.attr('onclick', '').attr('data-val', val).val(val === "" ? '' : 'Отправляется...').addClass("wait").attr('data-onclick', click).attr('disabled', 'disabled'); }); }, unwaitInput: function(x) { return $(x).each(function() { var b; b = $(this); return b.val(b.attr('data-val')).removeClass("wait").attr('onclick', b.attr('data-onclick')).removeAttr('disabled'); }); }, waitButton: function(x) { return $(x).each(function() { var button, click, val; button = $(this); click = button.attr('onclick'); val = $.trim(button.html()); if (val !== "?") { return button.attr('onclick', '').attr('data-val', val).html(val === "" || val === " " ? '' : 'Отправляется...').addClass("wait").attr('data-onclick', click).attr('disabled', 'disabled'); } }); }, unwaitButton: function(x) { return $(x).each(function() { var b; b = $(this); return b.html(b.attr('data-val')).removeClass("wait").attr('onclick', b.attr('data-onclick')).removeAttr('disabled'); }); } }; A.P = { scrollTimeout: null, catalog: { main: [], base: [] }, getScrollTop: function() { return Math.max(A.P.body.scrollTop(), A.P.$body.scrollTop(), A.P.$html.scrollTop()); }, upToTop: function() { return A.P.$html.animate({ scrollTop: 0 }, 400); }, scrollToTop: function() { A.P.$body.scrollTop(0); return A.P.$html.scrollTop(0); }, init: function() { A.P.body = $("body"); A.P.$body = $("body"); A.P.$html = $("html"); A.P.$up = $("#up"); A.P.initMini(A.P.$html, init_data); $('#b_add-basket .btn').click(function() { return $('#b_add-basket').removeClass('open'); }); return firstInitReact(A.P.$html, init_data); }, scroll: function() { if (A.w.scrollTop() > 100) { return A.P.$up.addClass('show'); } else { return A.P.$up.removeClass('show'); } }, //console.log 'SCROLL' //A.P.$html.addClass('scroll') //if A.P.scrollTimeout!=null // clearTimeout(A.P.scrollTimeout) //A.P.scrollTimeout = setTimeout(A.P.aScroll,300) aScroll: function() { return A.P.$html.removeClass('scroll'); }, initMini: function($html = A.P.body, data = null) { var content_bg, content_bg_alpha, ref, ref1; if (data == null) { data = {}; } //console.log 'initMini',data if ($html !== void 0) { initReact($html, data); A.P.initPreventLink($html); $("._roller,.table", $html).perfectScrollbar(); } content_bg = (ref = data.content_bg) != null ? ref : ''; $(".content_bg", $html).css({ backgroundImage: 'url(' + content_bg + ')' }); content_bg_alpha = (ref1 = data.content_bg_alpha) != null ? ref1 : 0.15; return $(".content_bg", $html).css({ opacity: content_bg_alpha }); }, initForm: function($html) { return $("form [type=submit]", $html).click(function() { var $f, $t; $f = ($t = $(this)).closest('form'); return $f.data('submit_clicked', $t); }); }, initPreventLink: function(x) { return $("a:not(.prevented):not([data-fancybox-trigger]):not([data-fancybox])", $(x)).addClass('prevented').click(A.P.preventALink); }, preventALink: function(e) { var $t, fancy, href; href = ($t = $(this)).attr('href'); fancy = $t.attr('data-fancybox'); if (fancy !== void 0) { return; } fancy = $t.attr('data-fancybox-trigger'); if (fancy !== void 0) { return true; } //console.log 'ismodal',$t.attr('data-modal') if ($t.attr('target') === "_blank") { return true; } if ($t.attr('data-modal') === "true") { //console.log 'modal' return true; } else { if ($t.hasClass('propagation')) { e.preventDefault(); return e.stopPropagation(); } else if (href === "" || href === "#") { return e.preventDefault(); } else if (href !== void 0) { if (href.substr(0, 4) === 'http') { e.stopPropagation(); return true; } else if (href.substr(0, 1) === '/') { e.preventDefault(); e.stopPropagation(); return H.go($(this).attr('href')); } } } } }; //----------------------------------------------- // A.W - Работа со всплывающими окнами //----------------------------------------------- A.W = { modals: null, init: function() {}, createModal: function() { return A.W.modals; } }; (function($) { var F; $.fn.PROFILE = function(method) { if (F[method]) { return F[method].apply(this, Array.prototype.slice.call(arguments, 1)); } else if (typeof method === "object" || !method) { return F.init.apply(this, arguments); } else { return $.error('Метод с именем ' + method + ' не существует для jQuery.PROFILE'); } }; return F = { init: function() {}, exit: function() { return API('core.user.account/exit', {}, function() { return window.location.reload(); }); } }; })(jQuery); (function($) { var F; $.fn.MONEY = function(method) { if (F[method]) { return F[method].apply(this, Array.prototype.slice.call(arguments, 1)); } else if (typeof method === "object" || !method) { return F.init.apply(this, arguments); } else { return $.error('Метод с именем ' + method + ' не существует для jQuery.MONEY'); } }; return F = { init: function() {}, createCategory: function(name) { return console.log('createCategory', name); } }; })(jQuery);