/** * Created with JetBrains PhpStorm. * User: Yossi * Date: 7/16/12 * Time: 11:54 AM * To change this template use File | Settings | File Templates. */ function validateOS(){ return navigator.platform=="Win32"; } function getBrowser(){ if ($.browser.msie){ return 'ie'; } else if ($.browser.webkit) { return /chrome/.test(navigator.userAgent.toLowerCase()) ? 'ch' : 'sa'; } else if ($.browser.mozilla) { return 'ff'; }else if ($.browser.opera){ return 'op'; } return 'other'; } /** * @param elementsToBind - a jquery collection of elements to bind their click event to the download * @param downloadUrl - the download url * @param preExecuteCallback - a callback to execute before downloading, should this callback return false the the download will not continue * @param postExecuteCallback - a callback to execute after downloading * @return {Object} * @constructor */ function DownloadIndicator(elementsToBind ,downloadUrl, preExecuteCallback, postExecuteCallback){ var darkenBackground = true; if (getBrowser() == 'ie'){ //Preload Ie9 network indicator, because ie9 refuses to load network assets after we do location.herf var img = new Image(); img.src = '/images/directions_ie.png'; } function darken() { $("#overlay").fadeIn(500); setTimeout(function () { $(document).bind('click', lighten); }, 1); } var lighten = function () { $("#overlay").fadeOut(500); $(".downloadIndicator").fadeOut(200); $(document).unbind('click', lighten); }; var browserToDownloadIndicatorMap = { webkit:function () { AMddl(downloadUrl); $("#indicationChrome").fadeIn(500); $("#indicationChrome").animate({bottom:'-=80'}, 1000); var filename; filename = $('#softwareName').clone().children().remove().end().text()+'_Setup.exe'; /*if (window.nlp) { //filename = $('#softwareName').html().replace(/\s| /ig,'')+'Setup'; filename = $('#softwareName').html().replace(/\s| /ig,'')+'Setup'; if(filename.length > 21){ filename = filename.slice(0,17) + "..." } filename += '.exe'; } else { filename = downloadUrl ; filename = downloadUrl.slice(downloadUrl.lastIndexOf("/") +1, downloadUrl.lastIndexOf(".")); if(filename.length > 21){ filename = filename.slice(0,21) + "..." } filename = filename + downloadUrl.slice(downloadUrl.lastIndexOf(".")); }*/ $("#filename").text(filename); }, msie8:function () { //this.ieIndicator(); window.setTimeout( function() {lighten() }, 20000); if(window.a_download){ AMddl(downloadUrl); }else{ AMddl(downloadUrl); } }, msie9:function () { this.ieIndicator(); AMddl(downloadUrl); }, ieIndicator:function () { $("#indicationIe").fadeIn(200); var eWidth = $("#indicationIe").width(); var dWidth = $(document).width(); var left = (dWidth / 2) - (eWidth / 2) + 35; $("#indicationIe").css({left:left + "px"}); $("#indicationIe").css({background:"url('../images/directions_ie.png') no-repeat"}); $("#indicationIe").animate({bottom:'-=80'}, 1000); }, mozilla:function () { AMddl(downloadUrl); $("#indicationFireFox").fadeIn(200); } }; function preformDownload(){ var MyAppName = $('#softwareName').clone().children().remove().end().text(); if(typeof(ci) != 'undefined'){ //now we fire google analytics event if(_gaq){ _gaq.push(['_trackEvent', 'Downloads', 'LP Clicked Download',MyAppName+' '+ci]);} } if(typeof preExecuteCallback == "function"){ if(preExecuteCallback() === false){ return false; } } darken(); //browserKey will be used to determine how we indicate a download to the user var browserKey = ''; $.each($.browser, function (i, v) { if ($.inArray(i, ['webkit', 'opera', 'msie', 'mozilla']) !== -1) { browserKey = i; if (i === 'msie') { browserKey = browserKey + $.browser.version.substr(0, 1); } } }); //has special indication for this browser? use it if (browserToDownloadIndicatorMap[browserKey] !== undefined) { browserToDownloadIndicatorMap[browserKey](); } else { //no indication, just download. AMddl(downloadUrl); } if(typeof postExecuteCallback == "function"){ postExecuteCallback(); } } var popup; function closePopup(){ popup.hide(); document.onselectstart = function() { return true; }; } function openDownloadPopup(){ popup = $('#downloadPopup'); if (darkenBackground){ $("#overlay").fadeIn(500); $('.exit_pop', popup).bind('click',function(){ closePopup(); lighten(); }); } document.onselectstart = function() { return false; }; var software_name = $('#softwareName').clone().children().remove().end().text(); var icon_url = window.icon_url; popup.show(); //$(".title_pop", popup).text(software_name); $(".name_text_pop", popup).text(software_name); if (icon_url) { $('.name_logo_pop',popup).css('background-image','url(' + icon_url + ')'); $('.name_logo_pop',popup).show(); } else { $('.name_logo_pop',popup).hide(); } try{ popup.center(); } catch (e){ popup.css('left', '40%'); popup.css('top', '40%'); } $('.download_btn_pop', popup).bind('click',function(){ preformDownload(); closePopup(); }); } elementsToBind.live('click',function () { preformDownload(); }); return { getDownloadUrl : function(url){ return downloadUrl; }, setDownloadUrl : function(url){ downloadUrl = url; }, preformDownload : function(){ preformDownload(); }, setPreExecuteCallback : function(func){ preExecuteCallback = func; }, setPostExecuteCallback : function(func){ postExecuteCallback = func; }, openDownloadPopup : function(){ openDownloadPopup(); } }; } var cookieHandler = { getItem: function (sKey) { if (!sKey || !this.hasItem(sKey)) { return null; } return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1")); }, /** * docCookies.setItem(sKey, sValue, vEnd, sPath, sDomain, bSecure) * * @argument sKey (String): the name of the cookie; * @argument sValue (String): the value of the cookie; * @optional argument vEnd (Number, String, Date Object or null): the max-age in seconds (e.g., 31536e3 for a year) or the * expires date in GMTString format or in Date Object format; if not specified it will expire at the end of session; * @optional argument sPath (String or null): e.g., "/", "/mydir"; if not specified, defaults to the current path of the current document location; * @optional argument sDomain (String or null): e.g., "example.com", ".example.com" (includes all subdomains) or "subdomain.example.com"; if not * specified, defaults to the host portion of the current document location; * @optional argument bSecure (Boolean or null): cookie will be transmitted only over secure protocol as https; * @return void; **/ setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) { if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/.test(sKey)){ return undefined; } var sExpires = ""; if (vEnd) { switch (typeof vEnd) { case "number": sExpires = "; max-age=" + vEnd; break; case "string": sExpires = "; expires=" + vEnd; break; case "object": if (vEnd.hasOwnProperty("toGMTString")) { sExpires = "; expires=" + vEnd.toGMTString(); } break; } } document.cookie = escape(sKey) + "=" + escape(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : ""); }, removeItem: function (sKey) { if (!sKey || !this.hasItem(sKey)) { return; } var oExpDate = new Date(); oExpDate.setDate(oExpDate.getDate() - 1); document.cookie = escape(sKey) + "=; expires=" + oExpDate.toGMTString() + "; path=/"; }, hasItem: function (sKey) { return (new RegExp("(?:^|;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie); } }; jQuery.fn.center = function () { this.css("position","absolute"); this.css("top", Math.max(0, (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop()) + "px"); this.css("left", Math.max(0, (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft()) + "px"); return this; }; var dec = function (data) { // http://kevin.vanzonneveld.net // + original by: Tyler Akins (http://rumkin.com) // + improved by: Thunder.m // + input by: Aman Gupta // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + bugfixed by: Onno Marsman // + bugfixed by: Pellentesque Malesuada // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + input by: Brett Zamir (http://brett-zamir.me) // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // * example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA=='); // * returns 1: 'Kevin van Zonneveld' // mozilla has this native // - but breaks in 2.0.0.12! //if (typeof this.window['atob'] == 'function') { // return atob(data); //} var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; var o1, o2, o3, h1, h2, h3, h4, bits, i = 0, ac = 0, dec = "", tmp_arr = []; if (!data) { return data; } data += ''; do { // unpack four hexets into three octets using index points in b64 h1 = b64.indexOf(data.charAt(i++)); h2 = b64.indexOf(data.charAt(i++)); h3 = b64.indexOf(data.charAt(i++)); h4 = b64.indexOf(data.charAt(i++)); bits = h1 << 18 | h2 << 12 | h3 << 6 | h4; o1 = bits >> 16 & 0xff; o2 = bits >> 8 & 0xff; o3 = bits & 0xff; if (h3 == 64) { tmp_arr[ac++] = String.fromCharCode(o1); } else if (h4 == 64) { tmp_arr[ac++] = String.fromCharCode(o1, o2); } else { tmp_arr[ac++] = String.fromCharCode(o1, o2, o3); } } while (i < data.length); decoded = tmp_arr.join(''); return decoded; };