Created
November 7, 2012 02:50
-
-
Save wrongkitchen/4029316 to your computer and use it in GitHub Desktop.
Javascript: Common Function
This file contains 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
// CommonFunction.js | |
// Author Kenji Wong | |
// Lastest Modification 16/11/2012 | |
if(!window.console) window.console = { log: function(){ return; } }; | |
var classExtend = function(subClass, superClass) { | |
var F = function() {}; | |
F.prototype = superClass.prototype; | |
subClass.prototype = new F(); | |
subClass.prototype.constructor = subClass; | |
subClass.superclass = superClass.prototype; | |
if(superClass.prototype.constructor == Object.prototype.constructor) { | |
superClass.prototype.constructor = superClass; | |
} | |
}; | |
var preloadImageArray = function(pImageArray, pCallback){ | |
if (document.images){ | |
var imageCount_num = pImageArray.length; | |
var imageObj_array = []; | |
var imageLoaded_num = 0; | |
for(var i=0; i<imageCount_num; i++){ | |
var image_obj = new Image(); | |
image_obj.src = pImageArray[i]; | |
image_obj.onload = function(){ | |
imageObj_array.push(this); | |
imageLoaded_num += 1; | |
if(imageLoaded_num == pImageArray.length) | |
pCallback(imageObj_array); | |
}; | |
} | |
} | |
}; | |
var checkViewPort = function(){ | |
var navigateUA = navigator.userAgent; | |
if ((navigateUA.indexOf('iPhone') == -1) && (navigateUA.indexOf('iPod') == -1) && (navigateUA.indexOf('iPad') == -1)){ | |
var e = window, a = 'inner'; | |
var viewport = document.querySelector("meta[name=viewport]"); | |
if (!('innerWidth' in window)){ | |
a = 'client'; | |
e = document.documentElement || document.body; | |
} | |
var initScale = new Number(e[a+"Width"] / 640); | |
initScale = initScale.toFixed(1); | |
viewport.setAttribute('content', 'width=device-width, minimum-scale=0.5, initial-scale='+initScale); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment