Created
February 10, 2014 20:24
-
-
Save miketaylr/8923497 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getParameterByName(b) { | |
b = b.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); | |
var a = "[\\?&]" + b + "=([^&#]*)"; | |
var d = new RegExp(a); | |
var c = d.exec(window.location.href); | |
if (c == null) { | |
return ""; | |
} else { | |
return decodeURIComponent(c[1].replace(/\+/g, " ")); | |
} | |
} | |
var createScript = function(c, b, d) { | |
var a = document.createElement("script"); | |
a.type = "text/javascript"; | |
a.language = "javascript1.1"; | |
a.src = c; | |
b.appendChild(a); | |
a.onload = d; | |
}; | |
var Compatibility = { | |
mobileRegexp: /android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/gi, | |
supportedMobileRegexp: /iPhone|Android|android/, | |
blackberyVersion: /Version\/([\d.]+)/, | |
symbianVersion: /Symbian\/([\d.]+)/, | |
check: function() { | |
if (this.isMobile()) { | |
if (this.isUnSupportedMobile()) { | |
this.redirectToOld(); | |
} | |
} else { | |
this.redirectToDesktop(); | |
} | |
}, | |
isMobile: function() { | |
return this.checkUserAgent(this.mobileRegexp); | |
}, | |
isUnSupportedMobile: function() { | |
if (/BlackBerry/.test(navigator.userAgent)) { | |
var a = navigator.userAgent.match(this.blackberyVersion); | |
if (a && parseFloat(a[1]) >= 6) { | |
return false; | |
} | |
return true; | |
} | |
if (/Symbian/.test(navigator.userAgent)) { | |
var a = navigator.userAgent.match(this.symbianVersion); | |
if (a && parseFloat(a[1]) >= 3) { | |
return !document.querySelectorAll; | |
} | |
return true; | |
} | |
return !this.checkUserAgent(this.supportedMobileRegexp); | |
}, | |
checkUserAgent: function(a) { | |
return a.test(navigator.userAgent); | |
}, | |
redirectToDesktop: function() { | |
var a = "http://www.24sata.hr/" + window.location.hash.replace("#", ""); | |
window.location = a + (a.indexOf("?") === -1 ? "?" : "&") + "full_site=true"; | |
}, | |
redirectToOld: function() { | |
var b = window.location.hash.replace("#", "").split("/"), a = "http://m2.24sata.hr/"; | |
switch (b.length) { | |
case 1: | |
switch (b[0]) { | |
case "home": | |
a += "1"; | |
break; | |
case "news": | |
a += "2"; | |
break; | |
case "show": | |
a += "3"; | |
break; | |
case "sport": | |
a += "4"; | |
break; | |
} | |
break; | |
case 2: | |
case 3: | |
a += "1/" + b[1].slice(b[1].lastIndexOf("-") + 1, b[1].length); | |
break; | |
} | |
window.location = a; | |
} | |
}; | |
if (getParameterByName("mobile_site").toLowerCase() != "true" && getParameterByName("mobile").toLowerCase() != "true") { | |
Compatibility.check(); | |
} | |
var screenRotator = { | |
previousOrientation: 0, | |
checkOrientation: function() { | |
if (window.orientation != this.previousOrientation) { | |
previousOrientation = window.orientation; | |
updateOrientation(); | |
} | |
} | |
}; | |
var fallbackScreenRotator = { | |
width: 0, | |
height: 0, | |
checkOrientation: function() { | |
var a = 0; | |
if (screen.width != this.width && screen.height != this.height) { | |
this.width = screen.width; | |
this.height = screen.height; | |
if (this.width > this.height) { | |
a = 90; | |
} | |
updateOrientation(a); | |
} | |
} | |
}; | |
function setScreenRotationListeners() { | |
if (window.hasOwnProperty("orientation")) { | |
window.addEventListener("orientationchange", screenRotator.checkOrientation, false); | |
window.addEventListener("resize", screenRotator.checkOrientation, false); | |
setInterval(fallbackScreenRotator.checkOrientation, 2e3); | |
updateOrientation(); | |
} else { | |
setInterval(fallbackScreenRotator.checkOrientation, 2e3); | |
} | |
} | |
function updateOrientation(b) { | |
var a = window.orientation || b; | |
switch (a) { | |
case 90: | |
case -90: | |
a = "landscape"; | |
$("body").removeClass("portrait"); | |
break; | |
default: | |
$("body").removeClass("landscape"); | |
a = "portrait"; | |
} | |
window.appOrientation = a; | |
if (window.App) { | |
window.App.orientationChange(); | |
} | |
$("body").addClass(a); | |
window.scrollTo(0, 1); | |
setScreenSize(); | |
} | |
function setVariables() { | |
var a = false; | |
window.isWebKitAnimationCapable = !_.isUndefined(document.body.style["-webkit-transform"] || document.body.style["-webkit-animation"] || document.body.style["-webkit-animationName"]); | |
if (!Modernizr.backgroundsize) { | |
$("body").addClass("no-background-size"); | |
} | |
if ($.os.iphone || $.os.android && $.os.version && parseFloat($.os.version) >= 2.1) { | |
a = true; | |
} | |
if ($.os.android && $.os.version && parseFloat($.os.version) >= 4.1 && !navigator.userAgent.match("Chrome")) { | |
a = false; | |
} | |
if (a) { | |
$("body").addClass("fixed-position"); | |
} | |
} | |
function setScreenSize() { | |
$("#wrapper").css({ | |
width: window.innerWidth, | |
height: window.innerHeight | |
}); | |
$("#content").css("width", window.innerWidth); | |
} | |
function initApp() { | |
if ($.os.iphone) { | |
var a = document.createElement("link"); | |
a.rel = "apple-touch-icon-precomposed"; | |
a.href = "/images/icon.png"; | |
document.getElementsByTagName("head")[0].appendChild(a); | |
a = document.createElement("link"); | |
a.rel = "apple-touch-icon-precomposed"; | |
a.sizes = "114x114"; | |
a.href = "/images/icon_retina.png"; | |
document.getElementsByTagName("head")[0].appendChild(a); | |
} | |
setVariables(); | |
setScreenRotationListeners(); | |
window.appOrientation = window.appOrientation || "portrait"; | |
window.App = new AppRouter(); | |
Backbone.history.start(); | |
setScreenSize(); | |
window.addEventListener("resize", function() { | |
setScreenSize(); | |
}, this); | |
$("#splash").remove(); | |
$("#wrapper").show(); | |
$("#preloaded-images").remove(); | |
} | |
function loadJsLib(b) { | |
if (b.length == 0) { | |
initApp(); | |
return; | |
} | |
var a = document.createElement("script"); | |
a.type = "text/javascript"; | |
a.src = b.shift() + ".js?" + v; | |
a.onload = function() { | |
loadJsLib(b); | |
}; | |
document.getElementsByTagName("head")[0].appendChild(a); | |
} | |
function loadStylesheet(b) { | |
var a = document.createElement("link"); | |
a.type = "text/css"; | |
a.rel = "stylesheet"; | |
a.media = "screen"; | |
a.href = b + ".css?" + v; | |
document.getElementsByTagName("head")[0].appendChild(a); | |
} | |
window.addEventListener("load", function() { | |
loadStylesheet("resources/css/dvacetiri7"); | |
loadJsLib(jsFiles); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment