1 line
8.1 KiB
JavaScript
1 line
8.1 KiB
JavaScript
var A,API,API_THEME,H;A={init:function(){return A.w=$(window),A.P.init(),A.W.init(),A.FORM.init(),A.w.scroll(A.scroll),A.scroll()},scroll:function(){return A.P.scroll()},notify:function(t,n=""){return t.queue(function(){return t.html(n).show(300),t.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(t,n){return $(".error_text",t.$wrap).remove(),t.$wrap.removeClass("error good")},globalGood:function(t,n){return t.$wrap.addClass("good")},globalBad:function(t,n){return t.$wrap.addClass("error"),t.$wrap.append($('<div class="error_text">'+n.errors.join("<br/>")+"</div>"))},init:function(){return $.fn.FORM("setGlobalGood",A.FORM.globalGood),$.fn.FORM("setGlobalBad",A.FORM.globalBad),$.fn.FORM("setPrepareValidate",A.FORM.globalPrepareValidate)}},setCookie:function(t,n,o){var r,e;return e=" domain="+window.location.host+";",r=t+"="+n+"; expires="+new Date(o||(new Date).getTime()+5184e6).toGMTString()+"; path=/;",document.cookie=r+e,console.log(r+e),r},getCookie:function(t){return!!new RegExp("(?:; )?"+t+"=([^;]*);?").test(document.cookie)&&decodeURIComponent(RegExp.$1)},reachYandex:function(t){},reachGoogle:function(t,n,o){return"function"==typeof ga?ga("send","event",t,n,o):void 0}},$(document).ready(A.init),API=function(t,n={},o=null,r={}){var e;return n.nocache=(new Date).getTime(),e="/api/"+t+"/",console.log(e,n),$.ajax({url:e,type:"POST",dataType:void 0!==n.dataType?n.dataType:"html",data:n,success:function(t){if(null!==o)return"function"==typeof o?o(t,r):void 0},error:function(){return"function"==typeof o?o({error:1},r):void 0}})},API_THEME="themes.opr/",H={menu:{},selected:{},top_selected:null,inited:!1,dir:"",title:null,data:null,scroll:[],isLoading:!1,data:null,ready:function(){if(!H.inited)return $(window).on("popstate",H.switchByWindow),H.inited=!0,H.body=$("#content"),H.title=$("title"),H.keywords=$("meta[name=keywords]"),H.description=$("meta[name=description]"),H.title=$("title"),H.$html=$("html,body"),$(window).on("scroll",H.onScroll),H.data=init_data},onScroll:function(){if(!H.isLoading)return H.scroll[window.location.href]=H.$html.scrollTop()},reload:function(){return H.switch({animate:!1})},formGo:function(t){var n,o,r;return r=(n=$(t)).serialize(),void 0===(o=n.attr("action"))&&(o=window.location.pathname),H.go(o+"?"+r),!1},go:function(t,n=null,o="",r=!0){var e;if("/"===t.substr(0,1)&&(t=t.substr(1)),e="/"+t,H.data=n,history.pushState(n,o,e),r)return H.switch()},setTitle:function(t){return H.title.text(t)},switchByWindow:function(t){var n,o;return H.now!==window.location.href?H.switch(t.state):""!==window.location.hash&&(n=$(window.location.hash)).length>0?(o=n.offset().top-65,H.$html.scrollTop(o)):void 0},getData:function(t){var n;return n=null,null!==H.data&&(n=H.data[t]),n},switch:function(t={animate:!0}){var n;return n="/"===(n=H.parse().join("/"))||""===n?"/?justContent=1":`/${n}/?justContent=1`,window.location.search.length>0&&(n+="&"+window.location.search.substr(1)),H.isLoading=!0,$.ajax({url:n,dataType:"JSON",success:function(t){var n,o,r,e,a,i,l,c,u;if(console.log("time_compile",t.time_compile,"bd_time",t.time_bd),"string"==typeof t.location&&""!==t.location)return H.go(t.location);if(H.data=t.data,H.title.text(t.title),o=$(t.content),r=$(o[0]),H.setTitle(t.data.title),H.keywords.attr("content",t.keywords),H.description.attr("content",t.description),H.body.html(r),u=0,void 0!==H.scroll[window.location.href]&&(u=H.scroll[window.location.href]),""!==window.location.hash&&(n=$(window.location.hash)).length>0&&(u=n.offset().top-80),A.P.initMini(r,t.data),o.length>1)for(e=a=1,i=o.length-1;1<=i?a<=i:a>=i;e=1<=i?++a:--a)c=document.createElement("script"),"SCRIPT"!==(l=o[e].tagName)&&"script"!==l||(c.innerHTML=$(o[e]).html(),H.body[0].appendChild(c));return H.$html.scrollTop(u),H.isLoading=!1},error:function(){return console.log("history error ")}})},SEARCH:{set:function(t,n=!1){var o;return o=window.location.pathname+"?"+t,H.go(o,null,"",n)},parse:function(){var t,n,o,r,e;if(o={},window.location.search.length>0)for(t in e=window.location.search.substr(1).split("&"))(n=(r=e[t]).indexOf("="))>=0?o[r.substr(0,n)]=r.substr(n+1):o[r]=null;return o},setValue:function(t,n,o=!1){var r,e;return(e=H.SEARCH.parse())[t]=n,r=H.SEARCH.toString(e),H.SEARCH.set(r)},toString:function(t){var n,o,r;for(n in o=[],t)r=t[n],o.push(n+"="+(null!=r?r:""));return o.join("&")},get:function(t){try{return decodeURI(H.SEARCH.parse()[t])}catch(n){return n,H.SEARCH.parse()[t]}}},parse:function(t=null){var n,o,r,e,a;for(a=[],r=0,e=(n=(null!=t?t:window.location.pathname).split("/")).length;r<e;r++)""!==(o=n[r])&&a.push(o);return a}},$(window).ready(H.ready),A.I={waitInput:function(t){return $(t).each(function(){var t,n,o;return n=(t=$(this)).attr("onclick"),o=$.trim(t.val()),t.attr("onclick","").attr("data-val",o).val(""===o?"":"Отправляется...").addClass("wait").attr("data-onclick",n).attr("disabled","disabled")})},unwaitInput:function(t){return $(t).each(function(){var t;return(t=$(this)).val(t.attr("data-val")).removeClass("wait").attr("onclick",t.attr("data-onclick")).removeAttr("disabled")})},waitButton:function(t){return $(t).each(function(){var t,n,o;if(n=(t=$(this)).attr("onclick"),"?"!==(o=$.trim(t.html())))return t.attr("onclick","").attr("data-val",o).html(""===o||" "===o?"":"Отправляется...").addClass("wait").attr("data-onclick",n).attr("disabled","disabled")})},unwaitButton:function(t){return $(t).each(function(){var t;return(t=$(this)).html(t.attr("data-val")).removeClass("wait").attr("onclick",t.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(){return A.P.$body.scrollTop(0),A.P.$html.scrollTop(0)},init:function(){return 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")}),firstInitReact(A.P.$html,init_data)},scroll:function(){return A.w.scrollTop()>100?A.P.$up.addClass("show"):A.P.$up.removeClass("show")},aScroll:function(){return A.P.$html.removeClass("scroll")},initMini:function(t=A.P.body,n=null){var o,r,e,a;return null==n&&(n={}),void 0!==t&&(initReact(t,n),A.P.initPreventLink(t),$("._roller,.table",t).perfectScrollbar()),o=null!=(e=n.content_bg)?e:"",$(".content_bg",t).css({backgroundImage:"url("+o+")"}),r=null!=(a=n.content_bg_alpha)?a:.15,$(".content_bg",t).css({opacity:r})},initForm:function(t){return $("form [type=submit]",t).click(function(){var t;return(t=$(this)).closest("form").data("submit_clicked",t)})},initPreventLink:function(t){return $("a:not(.prevented):not([data-fancybox-trigger]):not([data-fancybox])",$(t)).addClass("prevented").click(A.P.preventALink)},preventALink:function(t){var n,o;if(o=(n=$(this)).attr("href"),void 0===n.attr("data-fancybox")){if(void 0!==n.attr("data-fancybox-trigger"))return!0;if("_blank"===n.attr("target"))return!0;if("true"===n.attr("data-modal"))return!0;if(n.hasClass("propagation"))return t.preventDefault(),t.stopPropagation();if(""===o||"#"===o)return t.preventDefault();if(void 0!==o){if("http"===o.substr(0,4))return t.stopPropagation(),!0;if("/"===o.substr(0,1))return t.preventDefault(),t.stopPropagation(),H.go($(this).attr("href"))}}}},A.W={modals:null,init:function(){},createModal:function(){return A.W.modals}},function(t){var n;t.fn.PROFILE=function(o){return n[o]?n[o].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof o&&o?t.error("Метод с именем "+o+" не существует для jQuery.PROFILE"):n.init.apply(this,arguments)},n={init:function(){},exit:function(){return API("core.user.account/exit",{},function(){return window.location.reload()})}}}(jQuery),function(t){var n;t.fn.MONEY=function(o){return n[o]?n[o].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof o&&o?t.error("Метод с именем "+o+" не существует для jQuery.MONEY"):n.init.apply(this,arguments)},n={init:function(){},createCategory:function(t){return console.log("createCategory",t)}}}(jQuery); |