2013-08-28 06:02:55 +00:00
|
|
|
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
|
|
|
|
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
|
|
|
|
|
|
|
|
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
|
|
|
|
|
|
|
|
// MIT license
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A polyfill for requestAnimationFrame
|
|
|
|
*
|
|
|
|
* @method requestAnimationFrame
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* A polyfill for cancelAnimationFrame
|
|
|
|
*
|
|
|
|
* @method cancelAnimationFrame
|
|
|
|
*/
|
|
|
|
var lastTime = 0;
|
|
|
|
var vendors = ['ms', 'moz', 'webkit', 'o'];
|
|
|
|
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
|
2013-12-23 04:19:52 +00:00
|
|
|
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
|
|
|
|
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] ||
|
|
|
|
window[vendors[x] + 'CancelRequestAnimationFrame'];
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
2013-12-23 04:19:52 +00:00
|
|
|
if (!window.requestAnimationFrame) {
|
|
|
|
window.requestAnimationFrame = function(callback) {
|
2013-08-28 06:02:55 +00:00
|
|
|
var currTime = new Date().getTime();
|
|
|
|
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
|
2013-11-06 04:51:23 +00:00
|
|
|
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
|
2013-08-28 06:02:55 +00:00
|
|
|
timeToCall);
|
|
|
|
lastTime = currTime + timeToCall;
|
|
|
|
return id;
|
|
|
|
};
|
2013-12-23 04:19:52 +00:00
|
|
|
}
|
2013-08-28 06:02:55 +00:00
|
|
|
|
2013-12-23 04:19:52 +00:00
|
|
|
if (!window.cancelAnimationFrame) {
|
2013-08-28 06:02:55 +00:00
|
|
|
window.cancelAnimationFrame = function(id) {
|
|
|
|
clearTimeout(id);
|
|
|
|
};
|
2013-12-23 04:19:52 +00:00
|
|
|
}
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
window.requestAnimFrame = window.requestAnimationFrame;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a hex color number to an [R, G, B] array
|
|
|
|
*
|
2013-12-23 04:19:52 +00:00
|
|
|
* @method hex2rgb
|
2013-11-06 04:51:23 +00:00
|
|
|
* @param hex {Number}
|
2013-08-28 06:02:55 +00:00
|
|
|
*/
|
2013-12-23 04:19:52 +00:00
|
|
|
PIXI.hex2rgb = function hex2rgb(hex) {
|
|
|
|
return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255];
|
|
|
|
};
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A polyfill for Function.prototype.bind
|
|
|
|
*
|
|
|
|
* @method bind
|
|
|
|
*/
|
2013-12-23 04:19:52 +00:00
|
|
|
if (typeof Function.prototype.bind !== 'function') {
|
|
|
|
Function.prototype.bind = (function () {
|
|
|
|
var slice = Array.prototype.slice;
|
|
|
|
return function (thisArg) {
|
|
|
|
var target = this, boundArgs = slice.call(arguments, 1);
|
|
|
|
|
|
|
|
if (typeof target !== 'function') throw new TypeError();
|
|
|
|
|
|
|
|
function bound() {
|
|
|
|
var args = boundArgs.concat(slice.call(arguments));
|
|
|
|
target.apply(this instanceof bound ? this : thisArg, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
bound.prototype = (function F(proto) {
|
|
|
|
if (proto) F.prototype = proto;
|
|
|
|
if (!(this instanceof F)) return new F();
|
|
|
|
})(target.prototype);
|
|
|
|
|
|
|
|
return bound;
|
|
|
|
};
|
|
|
|
})();
|
2013-08-28 06:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A wrapper for ajax requests to be handled cross browser
|
|
|
|
*
|
|
|
|
* @class AjaxRequest
|
|
|
|
* @constructor
|
|
|
|
*/
|
2013-12-23 04:19:52 +00:00
|
|
|
PIXI.AjaxRequest = function AjaxRequest()
|
2013-08-28 06:02:55 +00:00
|
|
|
{
|
2013-12-23 04:19:52 +00:00
|
|
|
var activexmodes = ['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.3.0', 'Microsoft.XMLHTTP']; //activeX versions to check for in IE
|
|
|
|
|
|
|
|
if (window.ActiveXObject)
|
|
|
|
{ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
|
|
|
|
for (var i=0; i<activexmodes.length; i++)
|
|
|
|
{
|
|
|
|
try{
|
|
|
|
return new window.ActiveXObject(activexmodes[i]);
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
//suppress error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (window.XMLHttpRequest) // if Mozilla, Safari etc
|
|
|
|
{
|
|
|
|
return new window.XMLHttpRequest();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* DEBUGGING ONLY
|
|
|
|
*/
|
|
|
|
PIXI.runList = function(item)
|
|
|
|
{
|
2013-12-23 04:19:52 +00:00
|
|
|
window.console.log('>>>>>>>>>');
|
|
|
|
window.console.log('_');
|
|
|
|
var safe = 0;
|
|
|
|
var tmp = item.first;
|
|
|
|
window.console.log(tmp);
|
|
|
|
|
|
|
|
while(tmp._iNext)
|
|
|
|
{
|
|
|
|
safe++;
|
|
|
|
tmp = tmp._iNext;
|
|
|
|
window.console.log(tmp);
|
|
|
|
// console.log(tmp);
|
|
|
|
|
|
|
|
if(safe > 100)
|
|
|
|
{
|
|
|
|
window.console.log('BREAK');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2013-08-28 06:02:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|