From b18accbfe7e2ec7b569e6265b178c86db12e23be Mon Sep 17 00:00:00 2001 From: root Date: Fri, 4 Sep 2009 07:51:27 +0200 Subject: [PATCH] fix globalAlpha check so it doesn't barf in IE --- pixastic.core.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/pixastic.core.js b/pixastic.core.js index 5f1d15e..d51beaf 100755 --- a/pixastic.core.js +++ b/pixastic.core.js @@ -332,8 +332,9 @@ var Pixastic = (function() { return img; } - } else if (Pixastic.Client.isIE() && typeof img.__pixastic_org_style != "undefined") { - img.style.cssText = img.__pixastic_org_style; + } else if (Pixastic.Client.isIE()) { + if (typeof img.__pixastic_org_style != "undefined") + img.style.cssText = img.__pixastic_org_style; } }, @@ -364,24 +365,26 @@ var Pixastic = (function() { })(), hasGlobalAlpha : (function() { + var hasAlpha = false; var red = document.createElement("canvas"); - red.width = red.height = 1; - var redctx = red.getContext("2d"); - redctx.fillStyle = "rgb(255,0,0)"; - redctx.fillRect(0,0,1,1); + if (red.getContext) { + red.width = red.height = 1; + var redctx = red.getContext("2d"); + redctx.fillStyle = "rgb(255,0,0)"; + redctx.fillRect(0,0,1,1); - var blue = document.createElement("canvas"); - blue.width = blue.height = 1; - var bluectx = red.getContext("2d"); - bluectx.fillStyle = "rgb(0,0,255)"; - bluectx.fillRect(0,0,1,1); + var blue = document.createElement("canvas"); + blue.width = blue.height = 1; + var bluectx = red.getContext("2d"); + bluectx.fillStyle = "rgb(0,0,255)"; + bluectx.fillRect(0,0,1,1); - redctx.globalAlpha = 0.5; - redctx.drawImage(blue, 0, 0); - var reddata = redctx.getImageData(0,0,1,1).data; - - var hasAlpha = (reddata[2] != 255); + redctx.globalAlpha = 0.5; + redctx.drawImage(blue, 0, 0); + var reddata = redctx.getImageData(0,0,1,1).data; + hasAlpha = (reddata[2] != 255); + } return function() { return hasAlpha; }