Skip to content

Commit

Permalink
Safari works now - Uint8ClampedArray constructor
Browse files Browse the repository at this point in the history
Uint8ClampedArray.constructor.name is Uint8Array or Array when the shiv
is in effect. Almost there, IE!
  • Loading branch information
Diogenesthecynic committed Oct 25, 2013
1 parent 48bfdab commit c293d63
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion data.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Data.js */
// A few functions to store and display ~persistent data
"use strict";
// "use strict";

// window.data stores the references to data and elements
function resetData() {
Expand Down
7 changes: 5 additions & 2 deletions mario.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ function FullScreenMario() {
|| window.msCancelRequestAnimationFrame
|| clearTimeout;

// THANKS INTERNET EXPLORER
if(!window.Uint8ClampedArray) window.Uint8ClampedArray = Array;
window.Uint8ClampedArray = window.Uint8ClampedArray
|| window.Uint8Array
|| Array;
// Because the shiv will mess this up for sprites.js detection
window.Uint8ArrayName = Uint8ClampedArray.name || "Uint8Array"; // ie

// Resetting everything may take a while
resetMeasurements();
Expand Down
8 changes: 4 additions & 4 deletions sprites.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function getSpriteFromLibrary(thing) {
return;
}
// If it's more complicated, search for it
if(sprite.constructor != Uint8ClampedArray) {
if(sprite.constructor.name != Uint8ArrayName) {
sprite = findSpriteInLibrary(thing, sprite, classes);
}

Expand Down Expand Up @@ -246,7 +246,7 @@ function expandObtainedSpriteMultiple(sprites, thing, width, height) {
// Expand each array from the multiple sprites to parsed
for(part in sprites) {
// If it's an actual sprite array, parse it
if((sprite = sprites[part]) instanceof Uint8ClampedArray) {
if((sprite = sprites[part]).constructor.name == Uint8ArrayName) {
++thing.num_sprites;
parsed[part] = expandObtainedSprite(sprite, thing, width, height, true);
}
Expand Down Expand Up @@ -295,7 +295,7 @@ function findSpriteInLibrary(thing, current, classes) {
nogood = false;
switch(check.constructor.name) {
// If it's a sprite array, you've found it.
case "Uint8ClampedArray": case "SpriteMultiple":
case Uint8ArrayName: case "SpriteMultiple":
return check;
// If it's an object, recurse normally
case "Object":
Expand All @@ -312,7 +312,7 @@ function findSpriteInLibrary(thing, current, classes) {
if(!nogood && current) {
switch(current.constructor.name) {
// You did it!
case "Uint8ClampedArray": case "SpriteMultiple": return current;
case Uint8ArrayName: case "SpriteMultiple": return current;
// Keep going
case "Object":
continue;
Expand Down

0 comments on commit c293d63

Please sign in to comment.