added data url support for Kinetic.Image, and added unit tests

This commit is contained in:
Eric Rowell
2012-07-14 18:32:00 -07:00
parent 4692c51c74
commit 864938ed33
4 changed files with 76 additions and 10 deletions

18
dist/kinetic-core.js vendored
View File

@@ -80,15 +80,18 @@ Kinetic.Type = {
_isFunction: function(obj) {
return !!(obj && obj.constructor && obj.call && obj.apply);
},
_isArray: function(obj) {
return Object.prototype.toString.call(obj) == '[object Array]';
},
_isObject: function(obj) {
return (!!obj && obj.constructor == Object);
},
_isArray: function(obj) {
return Object.prototype.toString.call(obj) == '[object Array]';
},
_isNumber: function(obj) {
return Object.prototype.toString.call(obj) == '[object Number]';
},
_isString: function(obj) {
return Object.prototype.toString.call(obj) == '[object String]';
},
/*
* other utils
*/
@@ -280,7 +283,14 @@ Kinetic.Type = {
return arg;
}
//if arg is image data, then convert it
// if arg is a string, then it's a data url
if(this._isString(arg)) {
var imageObj = new Image();
imageObj.src = arg;
return imageObj;
}
//if arg is an object that contains the data property, it's an image object
if(arg.data) {
var canvas = document.createElement('canvas');
canvas.width = arg.width;

File diff suppressed because one or more lines are too long