/* ---------------------------------------------------------------- */ /* generic.js /* ---------------------------------------------------------------- */ (function() { $(document).ready(function() { Laureus.GiftOfSport.init(); }); /* ---------------------------------- */ if (typeof Laureus == "undefined") { Laureus = {}; } Laureus.GiftOfSport = { externalLinkTitle: ", opens in new window", // Localised when called through generic.ashx. Do not change. enableCufon: false, init: function() { this.ie = this.detectIE(); window.onunload = function() { }; this.externalLinks(); this.collapsibleContent(); //this.widows('p'); this.infographicBorders(); $("header .lang-wrap").empty().show(); $("#lang ul").appendTo("header .lang-wrap").droppie(); $("#lang").empty(); $("#lang").show(); if (this.ie <= 6) { //this.pngFix("img, div, a, span"); } }, collapsibleContent: function() { $(".collapsible .collapsible-title").each(function() { $link = $(this); $link.data({ state: "active", activeTitle: $link.text(), inactiveTitle: $link.attr("rel") }); $link.attr("rel", ""); $link.click(function() { var state = $link.data("state"); if (state == "active") { $link.siblings(".collapsible-content").fadeIn(); $link.data("state", "inactive"); $link.text($link.data("inactiveTitle")); } else { $link.siblings(".collapsible-content").fadeOut(); $link.data("state", "active"); $link.text($link.data("activeTitle")); } return false; }); }); }, scrollTo: function(element) { var speed = 400; if ($(element).length > 0) { var target = $(element).offset().top; $('html:not(:animated), body:not(:animated)').animate( { scrollTop: target }, speed, function() { //window.location.hash = target; } ); } }, infographicBorders: function() { $('article.infographic:not(:has(p)) ul.infographic').css('margin-bottom', '0'); }, evenHeights: function(target) { var $base = this; var highest = 0; $(target).each(function() { if ($(this).height() > highest) { highest = $(this).height(); } }); $(target).each(function() { if ($base.ie == 6) { $(this).height(highest); } else { $(this).css("min-height", highest + "px"); } }); //console.log($(target)); }, externalLinks: function() { var message = this.externalLinkTitle; var title = null; $("a[href^='http']:not([href^='" + location.hostname + "'])").each(function() { title = $(this).attr("title") || $(this).text(); $(this).attr("title", title + message); $(this).click(function(e) { window.open($(this).attr("href")); e.preventDefault(); }); }); }, widows: function(selector) { $(selector).each(function() { var tok = $(this).html().replace(/\s/g, " "); if (tok.substr(tok.length - 2, tok.length) == "/>") { // Some sort of end tag, lets not mess with this, could be an image! return; } else { $(this).html(tok.replace(/^(.*) (.*)$/, "$1 $2")); } }); }, doCufon: function(target, params) { if (this.enableCufon) { if (target) { params = params || {}; Cufon.replace(target, params); } } }, detectIE: function() { if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { return Number(RegExp.$1); } else { if (window.devicePixelRatio) { return "safari"; } else { return 0; } } }, pngFix: function(target) { if (target) { try { DD_belatedPNG.Fix(target); } catch (error) { //Catching the error } } } }; })();