Utils = {}; Utils.normalizeString = function (str) { function normalize(str) { var rExps = [{ re: /[\xC0-\xC6]/g, ch: 'A' }, { re: /[\xE0-\xE6]/g, ch: 'a' }, { re: /[\xC8-\xCB]/g, ch: 'E' }, { re: /[\xE8-\xEB]/g, ch: 'e' }, { re: /[\xCC-\xCF]/g, ch: 'I' }, { re: /[\xEC-\xEF]/g, ch: 'i' }, { re: /[\xD2-\xD6]/g, ch: 'O' }, { re: /[\xF2-\xF6]/g, ch: 'o' }, { re: /[\xD9-\xDC]/g, ch: 'U' }, { re: /[\xF9-\xFC]/g, ch: 'u' }, { re: /[\xDF]/g, ch: 'ss' }, { re: /[\xD1]/g, ch: 'N' }, { re: /[\xF1]/g, ch: 'n'}]; for (var i = 0, len = rExps.length; i < len; i++) str = str.replace(rExps[i].re, rExps[i].ch); return str; } str = str.toLowerCase(); str = normalize(str); str = str.replace( new RegExp("'","g"), ""); str = str.replace( new RegExp("\"", "g") , ""); str = str.replace( new RegExp ("[^a-zA-Z0-9]","gi") , "_"); str = str.replace( new RegExp ("_+","gi"), "_"); str = str.replace( new RegExp ("_+$","gi"), ""); return str; }; Utils.createLinkToGenrePage = function (genreName) { return BASE_URL+'/genres/'+Utils.normalizeString(genreName); }; Utils.createLinkToGamePage = function (gameId,gameName) { return BASE_URL+'/games/'+gameId+'/'+Utils.normalizeString(gameName); }; Utils.ellipsisText = function () { $('.ellipsis_text:visible').each( function(index){ try { if ( $(this).parent().attr("threedots") == null ) { $(this).html($.trim($(this).html())); numOfLines = parseInt( $(this).parent().attr("class").replace("lines",'') ); $(this).parent().ThreeDots({max_rows:numOfLines}); } } catch(e){ }; }); }; Utils.fixUnloadImages = function () { function checkImages() { $(".image_fallback_enabled").each(function(){ var imageDim = imgRealSize(this); if (imageDim.width == 0 || imageDim.width == 28) { // image failed to load $(this).addClass("missing_img"); $(this).attr("alt",""); $(this).attr("title",""); $(this).attr("src","/system/modules/com.exent.owned.cms.utils/resources/img/empty.png"); } }); } setTimeout(checkImages,5000); }; //added function for getting natural size of the images due to ie8 natural width bug function imgRealSize(img) { var $img = $(img); if ($img.prop('naturalWidth') == undefined) { var $tmpImg = $('').attr('src', $img.attr('src')); $img.prop('naturalWidth', $tmpImg[0].width); $img.prop('naturalHeight', $tmpImg[0].height); } return { 'width': $img.prop('naturalWidth'), 'height': $img.prop('naturalHeight') } } Utils.fixUnloadImagesByName = function (imageName) { function checkImagesByName() { $(".image_fallback_enabled_by_name").each(function(){ var imageDim = imgRealSize(this); if (imageDim.width == 0 || imageDim.width == 28) { // image failed to load $(this).addClass("missing_img"); $(this).attr("alt",""); $(this).attr("title",""); $(this).attr("src","/system/modules/com.exent.owned.cms.utils/resources/img/"+imageName+""); } }); } setTimeout(checkImagesByName,5000); }; Utils.createIFrame = function (target,width,height,source,prop) { prop = prop ? prop : {}; prop.name = prop.name ? prop.name : Math.random().toString(36).substring(7); prop.id = prop.id ? prop.id : prop.name; prop.style = prop.style ? prop.style : ""; prop["class"] = prop["class"] ? prop["class"] : ""; if($(target).length==0) { try{ //console.error("error creating iframe in "+target); }catch(e){}; } var frame = $(''); $(target).append(frame); return frame; }; Utils.createPseudoFrame = function (target,width,height,content) { var iframe = Utils.createIFrame(target,width,height,"about:blank"); if ( iframe != null) { var iframeDoc; if (iframe.contentDocument) { iframeDoc = iframe.contentDocument; } else if (iframe.contentWindow) { iframeDoc = iframe.contentWindow.document; } else if (window.frames[iframe.name]) { iframeDoc = window.frames[iframe.name].document; } if (iframeDoc) { iframeDoc.open(); iframeDoc.write('
'+content+'<\/body><\/html>'); iframeDoc.close(); } } return iframe; }; Utils.addParameter = function (href,key,value) { var param = key+"="+value; var hash = href.split("#")[1]; href = href.split("#")[0]; if (href.charAt(href.length - 1) === '?') //Very unlikely href += param; else if (href.indexOf('?') > 0) href += '&' + param; else href += '?' + param; if (hash != null && hash != "") { href += "#"+hash; } return href; }; Utils.isPageExist = function (requestUrl,prop){ if (prop == null) prop = {}; $.ajax({ type: "HEAD", url: requestUrl, cache: false, error: function(){ if (prop.error) prop.error() }, success:function(){ if (prop.success) prop.success() } }); }; Utils.preventSelection = function() { $("body").unbind("selectstart").bind( "selectstart", function(e){ e.preventDefault(); return false; }); }; Utils.preventRightClick = function() { $("body").unbind("contextmenu").bind( "contextmenu", function(e){ e.preventDefault(); return false; }); }; Utils.preventSpecialKeys = function() { $(document).bind( "keydown", function(e){ switch (e.which) { case 37: // Left arrow case 39: // Right arrow if (e.altKey) { e.preventDefault(); return false; } break; case 79 : // O key case 80 : // P key case 82 : // R key case 83 : // S key if (e.ctrlKey) { e.preventDefault(); return false; } break; case 116 : // F5 case 8 : // Backspace case 9 : // Tab e.preventDefault(); if (window.event) { window.event.keyCode = 0; window.event.returnValue = false; } return false; } }); $("body").bind( "mousewheel", function(e){ if ( (e.shiftKey) || (e.ctrlKey) ) { e.preventDefault(); return false; } }); }; Utils.getUrlVars = function() { try { var paramsMap = new Array(); var qstr = location.search.substring(1); var arr = qstr.split("&"); for (i = 0; i < arr.length; i++) { var breakpoint = arr[i].indexOf("="); myname = arr[i].substring(0, breakpoint); myvalue = arr[i].substring(breakpoint + 1, arr[i].length) paramsMap[myname] = myvalue; } return paramsMap; } catch (e) {} }; Utils.setCookie = function (c_name,value,exdays,subdomain,path){ var exdate=new Date(); if (subdomain == null) subdomian = true; if (path == null) path = "/"; exdate.setDate(exdate.getDate() + exdays); var c_value=c_name+"="+escape(value); if(exdays!=null){ c_value+="; expires="+exdate.toUTCString(); } if(!subdomain){ var host = document.location.host.split("."); if(host.length > 2){ host[0]=""; }else{ host.unshift(""); } c_value+="; domain="+host.join("."); } c_value+="; path="+path; document.cookie=c_value; }; Utils.getCookie = function(c_name){ var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i