/** * Cookie plugin * * Copyright (c) 2006 Klaus Hartl (stilbuero.de) * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * */ /** * Create a cookie with the given name and value and other optional parameters. * * @example $.cookie('the_cookie', 'the_value'); * @desc Set the value of a cookie. * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true }); * @desc Create a cookie with all available options. * @example $.cookie('the_cookie', 'the_value'); * @desc Create a session cookie. * @example $.cookie('the_cookie', null); * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain * used when the cookie was set. * * @param String name The name of the cookie. * @param String value The value of the cookie. * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. * If set to null or omitted, the cookie will be a session cookie and will not be retained * when the the browser exits. * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will * require a secure protocol (like HTTPS). * @type undefined * * @name $.cookie * @cat Plugins/Cookie * @author Klaus Hartl/klaus.hartl@stilbuero.de */ /** * Get the value of a cookie with the given name. * * @example $.cookie('the_cookie'); * @desc Get the value of a cookie. * * @param String name The name of the cookie. * @return The value of the cookie. * @type String * * @name $.cookie * @cat Plugins/Cookie * @author Klaus Hartl/klaus.hartl@stilbuero.de */ jQuery.cookie = function(name, value, options) { if (typeof value != 'undefined') { // name and value given, set cookie options = options || {}; if (value === null) { value = ''; options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; } expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE } // CAUTION: Needed to parenthesize options.path and options.domain // in the following expressions, otherwise they evaluate to undefined // in the packed version for some reason... var path = options.path ? '; path=' + (options.path) : ''; var domain = options.domain ? '; domain=' + (options.domain) : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { // only name given, get cookie var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = jQuery.trim(cookies[i]); // Does this cookie string begin with the name we want? if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } }; /* Detect whether a string starts with a specified substring */ function kb_startsWith(haystack, needle) { return (haystack.indexOf(needle) == 0); } /* Detect whether a string ends with a specified substring */ function kb_endsWith(str, suffix) { return str.indexOf(suffix, str.length - suffix.length) !== -1; } /* Detect whether the URL specifies language with the passed country code. */ function kb_languageInURL(country) { // We detect header translation depending on the URL string. // URL: www.yandex.ru/dendric/mendric // then the pathname is /dendric/mendric // - var pathname = window.location.pathname.toLowerCase(); var countryCode = country.toLowerCase(); // http://www.yandex.ru/en -- OK // http://www.yandex.ru/en/ -- OK // http://www.yandex.ru/enlargedVersion - NOT OK // http://www.yandex.ru/en/index.html - OK // var returnString = kb_startsWith(pathname, "/" + countryCode + "/") || kb_startsWith(pathname, "/" + countryCode) && kb_endsWith(pathname, countryCode); if (!returnString) { if ( countryCode == getParameterByName('languageCode').toLowerCase() ) { returnString = true; } } if (!returnString) { if(countryCode == $.cookie('languageCode').toLowerCase()) { returnString = true; } } return returnString; } function getParameterByName(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); } var kb_translation_dictionary = { RU: { "main-slog": "

ЛУЧШИЕ ЦЕНЫ НА ОТЕЛИ ПО ВСЕМУ МИРУ

Сравните цены от 1000 сайтов и экономьте до 80%

", "search-description": "Поиск лучших предложений от мировых систем бронирования", "bestprice": "Гарантия лучшей цены", "bestprice-description": "На нашем сайте вы сможете легко и быстро находить лучшие цены на отели от всех крупнейших систем бронирования.", "bestdeals": "Выгодные предложения", "bestdeals-description": "Уникальная технология позволяет сканировать все основные сайты бронирования отелей, находя самые лучшие предложения по любому из заданных направлений.", "guest": "Оценка гостей", "guest-description": "Фотографии отеля не всегда дают полное представление о том, что будет ожидать вас при заселении. Мы сканируем собираем реальные отзывы гостей, чтобы вы могли получить объективную информацию.", }, EN: { "main-slog": "

THE BEST HOTELS PRICES GUARANTEED

Compare thousands of travel sites and save up to 80%

", "search-description": "Find the best deals from all the major hotel & booking sites", "bestprice": "Best Price Guaranteed", "bestprice-description": "Is it really the cheapest? out Best Price Guaranteed gives you peace of mind that you'll get the cheapest price online for the hotel rooms", "bestdeals": "Best deals", "bestdeals-description": "We search all corners of the internet - from the major booking sites to individual hotel websites -so you can easily compare the best deals on hotels worldwide.", "guest": "Guest ratings", "guest-description": "Hotel photos and the star ratings don't tell you everything. We search across the major booking and the hotel sites and collect guest reviews posted online so that you can get the full story.", } }; var realCountryCode = ''; var pathname = window.location.pathname.toUpperCase(); var expression = new RegExp("/(.{2})(/.*|$)", "ig"); var match = expression.exec(pathname); if (match != null) { realCountryCode = match[1]; if (realCountryCode == "BY" || realCountryCode == "UA") { realCountryCode = "RU"; } } if (!realCountryCode) { realCountryCode = getParameterByName('languageCode').toUpperCase(); } if (!realCountryCode) { realCountryCode = $.cookie('languageCode'); } if (!realCountryCode || !kb_translation_dictionary.hasOwnProperty(realCountryCode)) { realCountryCode = "EN"; } // The URL may specify the language // if (realCountryCode == 'RU') { countryCode = "RU"; } else { countryCode = "EN"; } $(function(){ var languageCode = countryCode; console.log(languageCode); if (languageCode == 'RU') { for (i in kb_translation_dictionary.RU) { var el = jQuery('#'+i); if (el.length) { el.html(kb_translation_dictionary.RU[i]); } } } });