Permalink
Browse files

Update CamanJS and fix IE

  • Loading branch information...
1 parent 37587ae commit 8b7e60ec1b336d0f84967147b455b3abd1ae7b7e @meltingice committed Apr 9, 2013
Showing with 48 additions and 24 deletions.
  1. +2 −0 _assets/javascripts/examples.js.coffee
  2. +38 −15 _assets/javascripts/ext/caman.full.js
  3. +8 −9 _layouts/main.html
@@ -47,6 +47,8 @@ renderPreset = (preset) ->
presetBusy = false
$(document).ready ->
+ return unless $("#example").length > 0
+
caman = Caman '#example'
presetCaman = Caman '#preset-example'
@@ -1,4 +1,3 @@
-//@ sourceMappingURL=caman.full.map
// Generated by CoffeeScript 1.6.1
(function() {
var $, Analyze, Blender, Calculate, Caman, CamanParser, Canvas, Convert, Event, Fiber, Filter, IO, Image, Layer, Log, Logger, PixelInfo, Plugin, Renderer, Root, Store, Util, fs, slice, vignetteFilters,
@@ -240,6 +239,9 @@
} else {
this.initObj = $(obj);
}
+ if (this.initObj == null) {
+ throw "Could not find image or canvas for initialization.";
+ }
return this.initType = this.initObj.nodeName.toLowerCase();
};
@@ -259,8 +261,8 @@
Log.debug("Initializing for NodeJS");
this.image = new Image();
this.image.onload = function() {
- Log.debug("Image loaded. Width = " + _this.image.width + ", Height = " + _this.image.height);
- _this.canvas = new Canvas(_this.image.width, _this.image.height);
+ Log.debug("Image loaded. Width = " + (_this.imageWidth()) + ", Height = " + (_this.imageHeight()));
+ _this.canvas = new Canvas(_this.imageWidth(), _this.imageHeight());
return _this.finishInit();
};
this.image.onerror = function(err) {
@@ -307,21 +309,39 @@
};
Caman.prototype.waitForImageLoaded = function() {
- if (this.image.complete) {
+ if (this.isImageLoaded()) {
return this.imageLoaded();
} else {
return this.image.onload = this.imageLoaded;
}
};
+ Caman.prototype.isImageLoaded = function() {
+ if (!this.image.complete) {
+ return false;
+ }
+ if ((this.image.naturalWidth != null) && this.image.naturalWidth === 0) {
+ return false;
+ }
+ return true;
+ };
+
+ Caman.prototype.imageWidth = function() {
+ return this.image.width || this.image.naturalWidth;
+ };
+
+ Caman.prototype.imageHeight = function() {
+ return this.image.height || this.image.naturalHeight;
+ };
+
Caman.prototype.imageLoaded = function() {
- Log.debug("Image loaded. Width = " + this.image.width + ", Height = " + this.image.height);
+ Log.debug("Image loaded. Width = " + (this.imageWidth()) + ", Height = " + (this.imageHeight()));
if (this.swapped) {
- this.canvas.width = this.image.width / this.hiDPIRatio();
- this.canvas.height = this.image.height / this.hiDPIRatio();
+ this.canvas.width = this.imageWidth() / this.hiDPIRatio();
+ this.canvas.height = this.imageHeight() / this.hiDPIRatio();
} else {
- this.canvas.width = this.image.width;
- this.canvas.height = this.image.height;
+ this.canvas.width = this.imageWidth();
+ this.canvas.height = this.imageHeight();
}
return this.finishInit();
};
@@ -338,10 +358,9 @@
this.assignId();
}
if (this.image != null) {
- this.context.drawImage(this.image, 0, 0, this.image.width, this.image.height, 0, 0, this.preScaledWidth, this.preScaledHeight);
+ this.context.drawImage(this.image, 0, 0, this.imageWidth(), this.imageHeight(), 0, 0, this.preScaledWidth, this.preScaledHeight);
}
- this.imageData = this.context.getImageData(0, 0, this.canvas.width, this.canvas.height);
- this.pixelData = this.imageData.data;
+ this.reloadCanvasData();
if (Caman.allowRevert) {
this.initializedPixelData = new Uint8Array(this.pixelData.length);
this.originalPixelData = new Uint8Array(this.pixelData.length);
@@ -361,6 +380,11 @@
return this.callback = function() {};
};
+ Caman.prototype.reloadCanvasData = function() {
+ this.imageData = this.context.getImageData(0, 0, this.canvas.width, this.canvas.height);
+ return this.pixelData = this.imageData.data;
+ };
+
Caman.prototype.resetOriginalPixelData = function() {
var pixel, _i, _len, _ref, _results;
if (!Caman.allowRevert) {
@@ -420,7 +444,7 @@
};
Caman.prototype.hiDPICapable = function() {
- return window.devicePixelRatio !== 1;
+ return (window.devicePixelRatio != null) && window.devicePixelRatio !== 1;
};
Caman.prototype.needsHiDPISwap = function() {
@@ -445,8 +469,7 @@
oldCanvas.parentNode.replaceChild(this.canvas, oldCanvas);
this.width = this.canvas.width;
this.height = this.canvas.height;
- this.imageData = this.context.getImageData(0, 0, this.canvas.width, this.canvas.height);
- this.pixelData = this.imageData.data;
+ this.reloadCanvasData();
return this.dimensions = {
width: this.canvas.width,
height: this.canvas.height
View
@@ -10,16 +10,9 @@
{% endcss_asset_tag %}
<link href='http://fonts.googleapis.com/css?family=Source+Code+Pro|Raleway:400,200,700' rel='stylesheet' type='text/css'>
-
- {% if site.dev or site.server %}
- <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js"></script>
- <script type="text/javascript">
- Caman.DEBUG = true
- </script>
- {% else %}
- <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
- {% endif %}
+ <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
+
{% javascript_asset_tag site %}
- /_assets/javascripts/copy-command.js
- /_assets/javascripts/ext/html5slider.js
@@ -28,6 +21,12 @@
- /_assets/javascripts/examples.js.coffee
- /_assets/javascripts/guides.js.coffee
{% endjavascript_asset_tag %}
+
+ {% if site.dev or site.server %}
+ <script type="text/javascript">
+ Caman.DEBUG = true
+ </script>
+ {% endif %}
</head>
<body>
{{ content }}

0 comments on commit 8b7e60e

Please sign in to comment.