/* * Javascript уровня фреймворка. обслуживает хидер, футер и базовые потребности всех страниц * * */ window.Get_DOM_Node = window.__$ = document.all ? function(n) { return document.all[n] } : (document.getElementById ? (function(n) { return document.getElementById(n) }) : null); var isFlashInstalled = function() { return (typeof navigator.plugins == "undefined" || navigator.plugins.length == 0) ? !!(new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) : navigator.plugins["Shockwave Flash"]; }; var console = console || {}; console.log = console.log || function(){}; console.warn = console.warn || function(){}; console.error = console.error || function(){}; console.info = console.info || function(){}; console.debug = console.debug || console.log; $().ready(function(){ //make left column's height same as right /* var fixheight = 0; if (parseInt($('._page_with_content').css('border-top-width')) > 0) fixheight = parseInt($('._page_with_content').css('border-top-width')) + parseInt($('._page_with_content').css('border-bottom-width')); $('._page_with_content').css('min-height', $('._page_height_content').height() - fixheight); */ // меню (всплывание подменю) $('._menuitem').hover(function() {//mouseover $(this).children('a').addClass('a_drdown_up').end().children('._menuitemdrop').show(); }, function() {//mouseout $(this).children('a').removeClass('a_drdown_up').end().children('._menuitemdrop').hide(); }); // bind HomePage link /*$('body').append('
').find('#bm_makehp_window').jqm({ajax: 'http://'+HOST+'/?_tpl=fw_makehp&ajax=1'+escape(navigator.userAgent.toLowerCase()),overlay: 50, modal: false,trigger:'#bm_makehp',ajaxText:''}); $('body').append('').find('#bm_ctr_enter_window').jqm({ajax: 'http://'+HOST+'/?_tpl=fw_spell',overlay: 50, modal: false,ajaxText:'', onLoad: function(h) { var s = (parent.getSelection) ? parent.getSelection() : ((parent.document.getSelection) ? parent.document.getSelection() : ((document.selection.createRange) ? document.selection.createRange().text : null)); h.w.find('._mess').attr('value', 'Ошибка: "'+s+'" '); if (s.getRangeAt) { var r=s.getRangeAt(0); h.w.find('._mess_context').attr('value', 'Контекст: ' + r.startContainer.data); } } });*/ // bind Login link for little window /*$('body').append('').find('#bm_login_window_big').jqm({ajax: 'http://'+HOST+'/?_tpl=fw_login&mode=big',overlay: 50, modal: true,ajaxText:''}); $('#bm_login_window').jqm({ajaxText: '', ajax: false, overlay: 72, modal: false}); // bind beta window $('body').append('').find('#bm_beta_window').jqm({ajax: 'http://'+HOST+'/?_tpl=fw_beta',overlay: 50, modal: false,ajaxText:'', onShow: function(h) { var sw = $(window).width()/2; if (last_mouse_click_x < sw) last_mouse_click_x = last_mouse_click_x + 15; else last_mouse_click_x = last_mouse_click_x - 340; var sh = $(window).height()/2; if (last_mouse_click_y < sh) last_mouse_click_y = last_mouse_click_y + 15; else last_mouse_click_y = last_mouse_click_y - 180; h.w.css('left', last_mouse_click_x + 'px').css('top', last_mouse_click_y + 'px').show(); } });*/ // local for now - TODO: refactor to global $.fn.submitBeta = function() { var url = this.attr('action') + '&ajax=1'; var $textarea = this.find('[data-el="betamess"]'); var data = $textarea.val(); var $result = this.find('[data-el="result"]'); if (data != '') { $.ajax({ url: url, type: 'POST', dataType: 'json', timeOut: 1000, data: { 'text':data, 'context':'otzyv' }, error: function () { $result.text($result.data('text-error')).addClass('b-feedback__form-result_active b-feedback__form-result_error'); //alert('error!'); }, success: function (xml) { $result.text($result.data('text-success')).removeClass('b-feedback__form-result_error').addClass('b-feedback__form-result_active b-feedback__form-result_success'); setTimeout(function() { $('[data-el="feedback"]').toggleClass('b-feedback_active'); $($result.removeClass('b-feedback__form-result_active b-feedback__form-result_error b-feedback__form-result_success')); $textarea.val(''); }, 1500); //alert('success!'); } }); } }; /*$('._bm_beta').bind('click', function(e) { last_mouse_click_x = e.clientX; last_mouse_click_y = e.clientY; $('#bm_beta_window').jqmShow(); return false; });*/ //hello string in the header (mailchecker) //berlin.mail_checker(); /*$(document).bind('keydown', function(e) { var s = (parent.getSelection) ? parent.getSelection() : ((parent.document.getSelection) ? parent.document.getSelection() : ((document.selection.createRange) ? document.selection.createRange().text : null)); if (s.toString() != '' && (e.keyCode == 10 || (e.keyCode == 13 && e.ctrlKey))) { $('#bm_ctr_enter_window').jqmShow(); } });*/ // make _blank for external links in the main part of the page /*$('.l-bigcol a[href^=http]').not('a[href*=bigmir]').each(function() { $(this).attr('target', '_blank'); });*/ // sliders // TODO: refactor not to use animation blocking (will be more attractive for user) $('.b-tab__control_prev').click(function() { var $stack = ($(this).attr('scrollable')) ? $($(this).attr('scrollable')) : $(this).parents('.b-tab').next().find('._scrollable'); if ($stack.data('animation') == 'on') return; if (parseFloat($stack.css('margin-left')) < 0 || $stack.attr('loop')) { $stack.data('animation', 'on'); var window_width = parseFloat($stack.attr('itemwidth') * $stack.attr('perscreen')); if ($stack.attr('loop')) $stack.prepend($stack.find('li:last').detach()).css('margin-left', parseFloat($stack.css('margin-left')) - window_width + 'px'); $stack.animate({ 'margin-left':parseFloat($stack.css('margin-left')) + window_width + 'px'}, 'slow', function() {$stack.data('animation', 'off');}); var $page = $(this).siblings('.b-tab__paginator').children('._page'); $page.text(parseFloat($page.text()) - 1); } }); $('.b-tab__control_next').click(function() { var $stack = ($(this).attr('scrollable')) ? $($(this).attr('scrollable')) : $(this).parents('.b-tab').next().find('._scrollable'); if ($stack.data('animation') == 'on') return; if (Math.abs(parseFloat($stack.css('margin-left'))) <= $stack.attr('itemwidth')*$stack.attr('items')-$stack.attr('itemwidth')*$stack.attr('perscreen') || $stack.attr('loop')) { $stack.data('animation', 'on'); var window_width = parseFloat($stack.attr('itemwidth') * $stack.attr('perscreen')); $stack.animate({ 'margin-left':parseFloat($stack.css('margin-left')) - window_width + 'px'}, 'slow', function() { if ($stack.attr('loop')) $stack.append($stack.find('li:first').detach()).css('margin-left', parseFloat($stack.css('margin-left')) + window_width + 'px'); $stack.data('animation', 'off'); }); var $page = $(this).siblings('.b-tab__paginator').children('._page'); $page.text(parseFloat($page.text()) + 1); } }); $('#bm_login_overlay').bind('click', function() { login_hide(); }); $('#bm_login_close').on('click', function() { login_hide(); }); }); function login_show(annotation) { var w = 496; var h = 246; $('#bm_login_window').children('[data-el="inner"]').html(''); $('#bm_login_window').addClass('b-modal_visible'); } function login_hide() { $('#bm_login_window').removeClass('b-modal_visible'); setTimeout(function() { $('#bm_login_window').children('[data-el="inner"]').html(''); }, 200); } // custom function - returns the next element or the first if it's the last $.fn.nextorfirst = function(){ if ($(this).next().size() == 1) return $(this).next(); else return $(this).siblings().first(); }; $.fn.prevorlast = function(n){ if ($(this).prev().size() == 1) return $(this).prev(); else return $(this).siblings().last(); }; // reverse objects collection. fex: $('a').reverse().each(... $.fn.reverse = [].reverse; var berlin = {};// main berlin object for all properties and functions berlin.mail_checker = function() { $('#fw_hello').load('http://'+HOST+'/?_tpl=fw_hello&ajax=1&nc='+(new Date()).getTime(), function() { berlin.login_bind(); }); $('#fw_header_info').load('http://' + HOST + '/?_tpl=fw_header_info&ajax=1&nc=' + (new Date()).getTime(), function() { }); setTimeout(berlin.mail_checker, 5*60*1000); } /*berlin.login_bind = function() { $('#bm_login').bind('click', function() { if ($('#bm_login_window').attr('shown') == 1) { $('#bm_login_window').jqmHide(); $('#bm_login_window').attr('shown', 0); } else { $('#bm_login_window').html(''); $('#bm_login_window').jqmShow(); $('#bm_login_window').attr('shown', 1); } return false; }); }*/ berlin.toggleFlash_active = false; berlin.toggleFlash = function() { if (this.toggleFlash_active) { this.toggleFlash_active.show(); this.toggleFlash_active = false; } else { this.toggleFlash_active = $('embed,object').hide(); } } var UtmTracker = { campaign: '', source: '', medium: new Array(), init: function(){ $(document).on('click','a',function(){ UtmTracker.utm(this); }); }, clear: function(){ this.campaign = ''; this.source = ''; this.medium = new Array(); }, utm: function (e){ this.clear(); this.findSource(e); this.findCampaign(e); this.findMedium(e); this.update(e); }, update: function(e){ // the first letter is slash - means the same domain patt1 = /^\//; // the domain is bigmir site patt2 = new RegExp('^(http://|//)'+this.source,'gi'); // url should not have utm parameters patt3 = new RegExp('(utm_campaign=|utm_source=|utm_medium=)','gi'); var href = $(e).attr('href'); if( (href.match(patt1) || href.match(patt2) || href.match(patt3)) && !(href.match(patt3)) ) // WRITE! { if(href.match(/\?/)) delimiter = '&'; else delimiter = '?'; $(e).attr('href', $(e).attr('href')+delimiter+'utm_campaign='+this.campaign+'&utm_source='+this.source+'&utm_medium='+this.formatMedium() ) } }, formatMedium: function(){ return this.medium.join('-'); }, findSource: function(e){ $(e).parents().each(function(){ if($(this).data('utm-source')) UtmTracker.source = $(this).data('utm-source'); }); }, findCampaign: function(e){ $(e).parents().each(function(){ if($(this).data('utm-campaign')){ UtmTracker.campaign = $(this).data('utm-campaign'); return false; } }); }, findMedium: function(e){ if($(e).data('utm-medium')) UtmTracker.medium.unshift($(e).data('utm-medium')); $(e).parents().each(function(){ if($(this).data('utm-medium')){ UtmTracker.medium.unshift($(this).data('utm-medium')); } }); }, }; /* $().ready(function(){ // init floating left social plugin $(function() { var $el = $('[data-el="socialLeft"]'); if (!$el.length) return; var offset = $el.offset(); var topPadding = 15; $(window).scroll(function() { var parentH = $el.parent().height(); if ($(window).scrollTop() > offset.top) { if (parentH > $(window).scrollTop() + offset.top - topPadding) { $el.stop().animate({ marginTop: $(window).scrollTop() + offset.top - topPadding }); } else { $el.stop().animate({ marginTop: parentH + topPadding }); } } else { $el.stop().animate({ marginTop: 0 }); }; }); }); });*/ $().ready(function() { (function getUpwardsArrow() { var upwards = { el: $('[data-b="up"]'), // selector visibility: false, // is arrow visible offset: { current: 0, // current $(window).scrollTop() active: document.documentElement.clientHeight // Mininal offset for making arrow visible }, modifiers: { active: 'b-upwards_active' // Arrow element active state modifier }, step: { speed: 15, // speed of one animation step distance: 60 // distance of one animation step }, speed: 200, // time of animation enabled: true // function trigger, change this to true for work }; if (!upwards.enabled) return; $(window).scroll(function() { upwards.offset.current = $(this).scrollTop(); if (upwards.offset.current >= upwards.offset.active && !upwards.visibility) { upwards.el.addClass(upwards.modifiers.active); upwards.visibility = true; } else if (upwards.offset.current < upwards.offset.active && upwards.visibility) { upwards.el.removeClass(upwards.modifiers.active); upwards.visibility = false; } }); upwards.el.click(function() { $('body, html').animate({ scrollTop: 0 }, upwards.speed); }); })(); /* video placeholders mobile */ var player_placeholders = $('[data-selector="player_placeholder"]'); player_placeholders.each(function () { $(this).on('click', function () { $(this).replaceWith($(this).data('iframe')); }); }); });