Current Path : /var/www/html/clients/e-nkama.ru/e-nkama_bitrix/bitrix/templates/mobile/js/ |
Current File : /var/www/html/clients/e-nkama.ru/e-nkama_bitrix/bitrix/templates/mobile/js/script.js |
var DBMGOSapp = { flgOnPopState: false, imgloader: '', objSidebar: null, objBtnNav: null, slideForPx: 250, ajaxTimeout: 15700, content: null, objModalNav: null, options: { isSetDocHref: false, isSetTableClass: true, InitUrl: '' }, route: function(event) { var self = this, thisRel = $(event.currentTarget).attr("rel"), thisUrl = $(event.currentTarget).attr("href"), thisTitle = $(event.currentTarget).attr("title"); if(thisRel == 'external'){ return true; }else if(thisRel == 'menu'){ event.preventDefault(); event.stopPropagation(); window.scrollTo(0, 1); var showID = $(event.currentTarget).attr("data-link"), curID = $(event.currentTarget).attr("data-cur"), nextH = $('#'+showID).height(); var blNav = $('#navigation'); blNav.css('position','relative').animate({left : '-300px' },250, function(){ $('#'+curID).removeClass('db_open').css('margin-left', '-600px'); $('#navigation .dinamic_menu').css('height', nextH+'px'); $('#'+showID).addClass('db_open').css('margin-left', '0px'); blNav.animate({left : '0px' },250).css('position','initial'); }); /* var timeout_id = setTimeout(function() { $('#'+curID).removeClass('db_open').css('margin-left', '-600px'); $('#navigation .dinamic_menu').css('height', nextH+'px'); $('#'+showID).addClass('db_open').css('margin-left', '0px'); clearTimeout(timeout_id); }, 750); try{ $('#'+curID).removeClass('db_open').animate({marginLeft: '-600px'},200, function(){ $('#navigation .dinamic_menu').animate({height:nextH+'px'},150, function(){ $('#'+showID).addClass('db_open').animate({marginLeft: '0px'},250, function(){ clearTimeout(timeout_id); }); }); }); } catch (e) { } //*/ return false; }else{ if(thisRel == 'nav-menu'){ $('.nav-block-fx li').removeClass('active'); $(event.currentTarget).parent().addClass('active'); } event.preventDefault(); event.stopPropagation(); self.loadPage(thisUrl, thisTitle); } }, sendForm: function(idForm){ var self = this, objForm = $('#'+idForm), backurl = $('#backurl' ,objForm).val(); linkhtmlurl = objForm.attr('action'); if(objForm.length > 0){ self.__closeNav(); setTimeout(function() { $.ajax({ type: 'POST', url: linkhtmlurl, data: objForm.serialize(), dataType: 'html', timeout: self.ajaxTimeout, context: window, success: function(data, textStatus, jqXHR){ try{ eval(data); } catch(e) { if(backurl){ window.location = backurl; }else{ window.location = '/'; } return false; } self.slidePage(new DBMGOSView(context).renderContent()); window.document.title = context.title; window.scrollTo(0, 1); self.flgOnPopState = true; }, error: function(xhr, type){ self.slidePage(new DBMGOSView().renderError(type)); } }); }, 100); return false; } return true; }, loadPage: function(thisUrl, thisTitle){ var self = this; window.scrollTo(0, 1); self.__closeNav(); self._load(thisUrl, function(data) { data.title = data.title.replace(/"/g,'"'); self.slidePage(new DBMGOSView(data).renderContent()); window.document.title = data.title; self.flgOnPopState = true; window.history.pushState(null, null, thisUrl); }); if(thisTitle){ window.document.title = thisTitle; } }, slidePage: function(page) { var self = this html = page.el; if(self.options.isSetDocHref){ html = DBMGOSParsHTML.SetDocHref(html); }else{ html = DBMGOSParsHTML.SetDoc(html); } if(self.options.isSetTableClass){ html = DBMGOSParsHTML.SetTableClass(html); } html = DBMGOSParsHTML.SetCustom(html); /***************************************************/ self.content.html(html); DBMGOSParsHTML.globSetCarusel(); self.__initHeaderBar(); }, __initHeaderBar: function(){ var self = this, barHeight = self.objSidebar.height(); //+10 $('body').css('padding-top', barHeight+'px'); //$(self.content).removeClass('db_open').addClass('db_close'); }, __openNav: function(event){ var self = this, top = document.body.scrollTop; //self.objBtnNav.click(); if(top > 10){ window.scrollTo(0, 1); } self.objBtnNav.removeClass('collapsed'); /*$(self.objBtnNav.attr('data-target')).addClass('in');*/ $(navigation).removeClass('db_nav_hide'); $(self.content).removeClass('db_close').addClass('db_open').animate({right:'-211px'},150); }, __closeNav: function(event){ var self = this, top = document.body.scrollTop; if(top > 10){ window.scrollTo(0, 1); } self.objBtnNav.addClass('collapsed'); /*$(self.objBtnNav.attr('data-target')).removeClass('in');*/ $(navigation).addClass('db_nav_hide'); $(self.content).removeClass('db_open').addClass('db_close').animate({right:'0'},150); }, _load: function(linkhtmlurl, callback){ //alert(linkhtmlurl); var self = this; window.scrollTo(0, 1); linkhtmlurl = (linkhtmlurl === '/' ? '/?' : linkhtmlurl); self.content.html(self.imgloader); setTimeout(function() { $.ajax({ type: 'GET', url: linkhtmlurl, data: { isAjax: 'Y' }, //, type: 'pda' dataType: 'html', timeout: self.ajaxTimeout, context: window, success: function(data, textStatus, jqXHR){ try{ eval(data); } catch(e) { window.location.reload(); } callback(context); }, error: function(xhr, type){ self.slidePage(new DBMGOSView().renderError(type)); } }); }, 100); }, registerEvents: function() { var self = this; if (document.documentElement.hasOwnProperty('ontouchstart')) { self.objBtnNav.on('touchstart', function(){ if(self.objBtnNav.hasClass('collapsed')){ self.__openNav(); }else{ self.__closeNav(); } }); } else { self.objBtnNav.on('mouseup', function(){ if(self.objBtnNav.hasClass('collapsed')){ self.__openNav(); }else{ self.__closeNav(); } }); } $(document).on('click', 'a', $.proxy(this.route, this)); window.onpopstate = function(event){ if(self.flgOnPopState){ self.loadPage(location.pathname, 'reload'); } } if ('orientation' in window){ $(window).on('orientationchange', function(){ self.__initHeaderBar(); window.scrollTo(0, 1); }); } if ('onresize' in window){ window.onresize = function(){ self.__initHeaderBar(); } } }, initialize: function(params) { //pInitUrl, pIsSetDocHref, pIsSetTableClass var self = this; $('body').html(new DBMGOSView().renderBase().el); $('.nav-block-fx.db_open').css('margin-left','0px'); if (params) { for ( i in params ) { self.options[i] = params[i]; } } self.content = $('#content'); self.objSidebar = $('.bar-header'); self.objBtnNav = $('#bntNav'); self.objModalNav = $('#menuModal'); self.imgloader = '<div id="loading"><span>'+objMess.load_title+'</span></div>'; if(self.options.InitUrl.length > 0){ self.loadPage(self.options.InitUrl, 'Load'); } self.registerEvents(); } }; var DBMGOSView = function(jsonData) { this.renderBase = function() { this.el.html(DBMGOSView.BaseTemplate()); return this; }; this.renderContent = function() { this.el.html(DBMGOSView.PageContentTemplate(jsonData)); this.el.addClass('scroll'); return this; }; this.renderError = function(type) { this.el.html(DBMGOSView.ErrorTemplate({title: objMess.error_title, desc: type, btnTitle: objMess.error_btnTitle})); return this; }; this.initialize = function() { this.el = $('<div/>'); }; this.initialize(); } Handlebars.registerHelper('listmenu', function(items, options) { var out = ""; $.each(items, function (index, item){ out = out + options.fn(item); }); return out; }); DBMGOSView.BaseTemplate = Handlebars.compile($("#home-tpl").html()); DBMGOSView.PageContentTemplate = Handlebars.compile($("#page-content-tpl").html()); DBMGOSView.ErrorTemplate = Handlebars.compile($("#error-tpl").html()); var DBMGOSParsHTML = { SetDocHref: function(html) { var a,b,c; $('a[href$="odt"], a[href$="doc"], a[href$="docx"], a[href$="pdf"], a[href$="txt"], a[href$="rft"], a[href$="ppt"], a[href$="pptx"], a[href$="xls"], a[href$="xlsx"], a[href$="zip"], a[href$="rar"]', html).each(function(index, item){ b = $(item); c = b.html(); b.attr('rel', 'external').not(':has(i)').addClass('doc btn').html('<i class="icon-download"></i><span>'+c+'</span>'); }); return html; }, SetDoc: function(html) { var a,b,c; $('a[href$="odt"], a[href$="doc"], a[href$="docx"], a[href$="pdf"], a[href$="txt"], a[href$="rft"], a[href$="ppt"], a[href$="pptx"], a[href$="xls"], a[href$="xlsx"], a[href$="zip"], a[href$="rar"]', html).each(function(index, item){ b = $(item); c = b.html(); b.attr('rel', 'external'); }); return html; }, SetTableClass: function(html) { var a,b,c; $('table', html).addClass('table'); return html; }, SetCustom: function(html) { var a,b,c; $('ul.carusel, #item-menu ul', html).addClass('nav nav-tabs nav-stacked'); $('#undertabs div', html).addClass('btn'); a = $('<ul class="nav nav-tabs"></ul>'); $('table.bx-sm-holder-show a', html).each(function(index, item){ item = $(item); if(item.parent().parent().parent().parent().parent().parent().hasClass('bx-sm-feature-select')){ b = 'active'; }else{ b = ''; } a.append($('<li class="'+b+'"><a href="'+item.attr('href')+'">'+item.text()+'</a></li>')); }); c = $('#right-column', html), $($('table', c)[0]).remove(), c.prepend(a); return html; }, globSetCarusel: function() { var a; a = $('.carousel'); if(a.length > 0){ a.carousel({ interval: 9000 }); } } }