// Opera trick if(history.navigationMode) history.navigationMode = 'compatible'; var showMainMenuTimeout = 0; var hideMainMenuTimeout = 0; var spinnerTimeout = false; var deviceIsTablet = function() { return !!navigator.userAgent.match(/(iPad|SCH-I800|xoom|kindle)/i); } var deviceIsPhone = function() { return !deviceIsTablet() && !!navigator.userAgent.match(/(iPhone|iPod|blackberry|android 0.5|htc|lg|midp|mmp|mobile|nokia|opera mini|palm|pocket|psp|sgh|smartphone|symbian|treo mini|Playstation Portable|SonyEricsson|Samsung|MobileExplorer|PalmSource|Benq|Windows Phone|Windows Mobile|IEMobile|Windows CE|Nintendo Wii)/i); } var deviceIsMobile = function() { return deviceIsTablet() || deviceIsPhone(); } var flushSpinnerMessage = function(msg, do_not_hide) { if(spinnerTimeout) clearInterval(spinnerTimeout); $('#spinner .message').html(msg); $('#spinner').show(); if(typeof do_not_hide == "undefined") { spinnerTimeout = setTimeout(function(){ $('#spinner').hide() }, 4000); } else if (typeof do_not_hide == "number") { spinnerTimeout = setTimeout(function(){ $('#spinner').hide() }, do_not_hide); } }; $(function() { if(deviceIsMobile()) { if(!getCookie('mobileDeviceNotification')) { alert("Текущая версия сайта имеет ограниченную функциональность при использовании с мобильных устройств. Приносим извинения за временные неудобства.\n\nThe current version of the website has limited functionality when used with mobile devices. We apologize for any inconvenience."); } setCookie('mobileDeviceNotification', true, {expires: 21600}); } $('#dialog-loginForm').dialog({ autoOpen: false, width: 270, position: ['center', 'center'], height: 'auto', modal: true, resizable: false, draggable: false }); $('#dialog-logoutForm').dialog({ autoOpen: false, width: 320, position: ['center', 'center'], height: 'auto', modal: true, resizable: false, draggable: false, open: function(){ $(document).keydown(function(e){ if (e.keyCode == 13) { $('#dialog-logoutForm .ok').click(); return false; } }); } }); $('#dialog-registrationResponce').dialog({ autoOpen: false, width: 'auto', position: ['center', 'center'], height: 'auto', modal: true, resizable: false, draggable: false }); $('#dialog-passwordRemind').dialog({ autoOpen: false, width: 'auto', position: ['center', 'center'], height: 'auto', modal: true, resizable: false, draggable: false, open: function() { $('#dialog-passwordRemind p.original').show(); $('#dialog-passwordRemind p.responce').hide(); } }); $('#dialog-socialLogin').dialog({ autoOpen: false, width: 'auto', position: ['center', 'center'], height: 'auto', modal: true, resizable: false, draggable: false }); $(window).resize(function() { $('#dialog-loginForm').dialog('option', {position: ['center', 'center']}); $('#dialog-logoutForm').dialog('option', {position: ['center', 'center']}); $('#dialog-passwordRemind').dialog('option', {position: ['center', 'center']}); }); $('input[placeholder], textarea[placeholder]').placeholder(); $('#main_menu_top .right a').tooltip({showURL: false, positionLeft: true, left: -5}); $('#loginCaller, .loginCaller').click(function(){ $('#dialog-loginForm').dialog('open'); return false; }); $('#logoutCaller').click(function(){ $popup = $('#dialog-logoutForm').dialog('open'); $popup.dialog('option', 'width', $($popup).parent().width()); return false; }); $('#lang-select').change(function(){ setCookie('userInterfaceLanguage', $(this).val(), {domain: document.location.hostname.replace(/^([a-z]{3}\.)?((test\.)?travvi(\.\w+)*)$/, ".$2"), path: '/', expires: 157680157 }); location.reload(); return false; }); $('#auth-form').submit(function(event){ var result = false; Spinner.show(); $.post($(this).attr('action'), $(this).serialize(), function(data) { eval(data); if (!result) { Spinner.hide(); flushSpinnerMessage(Travvi.s('js.login_error'), 10000); } else { document.location.reload(); } }); return false; }); $('#dialog-logoutForm .cancel').button().click(function(){ $('#dialog-logoutForm').dialog('close'); return false; }); $('#dialog-logoutForm .ok').button().click(function(){ $('#dialog-logoutForm').dialog('close'); //FB.logout(); $.ajax({ url: '/logout', type: 'post', success: function() { document.location.href ="/"; } }); return false; }); $( ".submit", "#dialog-loginForm" ).button(); $('#mainMenuWrapper input:checkbox, #dialog-loginForm input:checkbox').checkbox({ empty: '/skin/images/empty.png'}); // Report error Dialog $('#dialog-reportProblemForm').dialog({ autoOpen: false, width: 'auto', position: ['center', 'center'], height: 'auto', modal: true, resizable: false, draggable: false }); $('#reportProblemFormCaller').click(function(){ $('#dialog-reportProblemForm').dialog('open'); return false; }); $('#dialog-reportProblemForm a.submit.ok').button({disabled: true}).click(function(){ // Browser (and OS) detection var browser = { detect: function(){ return { browser: this.search(this.data.browser), version: this.search(navigator.userAgent) || this.search(navigator.appVersion), os: this.search(this.data.os) } }, search: function(data) { if (typeof data === "object"){ // search for string match for(var i = 0; i < data.length; i++) { var dataString = data[i].string, dataProp = data[i].prop; this.version_string = data[i].versionSearch || data[i].identity; if (dataString){ if (dataString.indexOf(data[i].subString) != -1){ return data[i].identity; } } else if (dataProp){ return data[i].identity; } } } else { // search for version number var index = data.indexOf(this.version_string); if (index == -1) return; return parseFloat(data.substr(index + this.version_string.length + 1)); } }, data: { browser: [ { string: navigator.userAgent, subString: "Chrome", identity: "Chrome" }, { string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb" }, { string: navigator.vendor, subString: "Apple", identity: "Safari", versionSearch: "Version" }, { prop: window.opera, identity: "Opera", versionSearch: "Version" }, { string: navigator.vendor, subString: "iCab",identity: "iCab" }, { string: navigator.vendor, subString: "KDE", identity: "Konqueror" }, { string: navigator.userAgent, subString: "Firefox", identity: "Firefox" }, { string: navigator.vendor, subString: "Camino", identity: "Camino" }, { string: navigator.userAgent, subString: "Netscape", identity: "Netscape" }, { string: navigator.userAgent, subString: "MSIE", identity: "Explorer", versionSearch: "MSIE" }, { string: navigator.userAgent, subString: "Gecko", identity: "Mozilla", versionSearch: "rv" }, { string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla" } ], os: [ { string: navigator.platform, subString: "Win", identity: "Windows" }, { string: navigator.platform, subString: "Mac", identity: "Mac" }, { string: navigator.userAgent, subString: "iPhone", identity: "iPhone/iPod" }, { string: navigator.userAgent, subString: "iPad", identitiy: "iPad" }, { string: navigator.platform, subString: "Linux", identity: "Linux" }, { string: navigator.userAgent, subString: "Android", identity: "Android" } ]} }; var data = $('#dialog-reportProblemForm form').serializeArray(); var detected = browser.detect(); data.push( {name: "message[url]", value: window.location.href}, {name: "message[screen]", value: screen.width + 'x' + screen.height}, {name: "message[browser]", value: detected.browser}, {name: "message[version]", value: detected.version}, {name: "message[os]", value: detected.os} ); $.ajax({ url: '/report_error', data: data, type: 'post', dataType: 'script' }); $('#dialog-reportProblemForm').dialog('close'); flushSpinnerMessage(Travvi.s('js.error_report_thanks'), 'do not hide ;)'); setTimeout(function(){ $('#spinner').hide() }, 5000); return false; }); $('#dialog-reportProblemForm a.submit.cancel').button().click(function(){ $('#dialog-reportProblemForm').dialog('close'); return false; }); $('#message_section').selectik({width: 604}); // placeholder text display trick $('#message_section').val(''); $('#message_section li.selected').remove(); $('#message_section').parent().find('span.custom-text').html('' + Travvi.s('js.select_value') + ''); $('#dialog-reportProblemForm').on('keyup', 'input, textarea', function(){ var valid = true; $('#dialog-reportProblemForm input, #dialog-reportProblemForm select, #dialog-reportProblemForm textarea').each(function() { if($.trim($(this).val()) === "") { valid = false; } }); if(valid) { $('#dialog-reportProblemForm a.submit.ok').button({disabled: false}); } else { $('#dialog-reportProblemForm a.submit.ok').button({disabled: true}); } return false; }); $('#dialog-reportProblemForm').on('change', 'select', function(){ $('#dialog-reportProblemForm textarea').keyup(); return false; }); $('#spinner .close').click(function(){ $('#spinner').hide(); return false; }); // Remind password dialog $('#tm-password a').click(function(){ $('#dialog-passwordRemind').dialog('open'); return false; }); $('#dialog-passwordRemind a.submit.cancel').button().click(function(){ $('#dialog-passwordRemind').dialog('close'); return false; }); $('#dialog-passwordRemind a.submit.ok').button().click(function(){ $('#dialog-passwordRemind form').submit(); return false; }); $('#dialog-passwordRemind form').submit(function(){ var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; if(!re.test($('#pwd_remind_email').val())) { $('#pwd_remind_email').focus().css({backgroundColor: "#F00"}).animate({backgroundColor: "#FFF"}, 1500); return false; } $('#dialog-passwordRemind').dialog('close'); Spinner.show(); $.post($(this).attr('action'), $(this).serialize(), function(data, textStatus, xhr) { $('#dialog-registrationResponce').html(data); Spinner.hide(); }); return false; }); $('#social-login a').click(function(){ $('#dialog-socialLogin').dialog('open'); return false; }); $('#dialog-socialLogin a.submit.cancel').button().click(function(){ $('#dialog-socialLogin').dialog('close'); return false; }); });