From 2c8540f3b4713c3abc825ddbad8b7a3fe102536b Mon Sep 17 00:00:00 2001 From: kangax Date: Wed, 28 Jul 2010 16:35:01 -0400 Subject: [PATCH] Forgot to pass `callbacks` to `fxCenterObjectH` and `fxCenterObjectV`. --- dist/all.js | 4 ++-- dist/all.min.js | 30 +++++++++++++++--------------- src/element.class.js | 4 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/dist/all.js b/dist/all.js index bcc1b281..d1b0a2ca 100644 --- a/dist/all.js +++ b/dist/all.js @@ -3320,7 +3320,7 @@ fabric.util.animate = animate; * @return {fabric.Element} thisArg * @chainable */ - fxCenterObjectH: function (object) { + fxCenterObjectH: function (object, callbacks) { callbacks = callbacks || { }; var empty = function() { }, @@ -3366,7 +3366,7 @@ fabric.util.animate = animate; * @return {fabric.Element} thisArg * @chainable */ - fxCenterObjectV: function (object) { + fxCenterObjectV: function (object, callbacks) { callbacks = callbacks || { }; var empty = function() { }, diff --git a/dist/all.min.js b/dist/all.min.js index df9191c2..e8ee68b9 100644 --- a/dist/all.min.js +++ b/dist/all.min.js @@ -72,21 +72,21 @@ this._oContextContainer;this.clearContext(this._oContextTop);o!==this._oContextT return this},renderTop:function(){this.clearContext(this._oContextTop);this.overlayImage&&this._oContextTop.drawImage(this.overlayImage,0,0);this._groupSelector&&this._drawSelection();var b=this.getActiveGroup();b&&b.render(this._oContextTop);this.afterRender&&this.afterRender();return this},containsPoint:function(b,d){var m=this.getPointer(b),o=this._normalizePointer(d,m);m=o.x;o=o.y;var u=d._getImageLines(d.oCoords);if((m=d._findCrossPoints(m,o,u))&&m%2===1||d._findTargetCorner(b,this._offset))return true; return false},_normalizePointer:function(b,d){var m=this.getActiveGroup(),o=d.x,u=d.y;if(m&&b.type!=="group"&&m.contains(b)){o-=m.left;u-=m.top}return{x:o,y:u}},findTarget:function(b,d){var m;this.getPointer(b);var o=this.getActiveGroup();if(o&&!d&&this.containsPoint(b,o))return m=o;for(o=this._aObjects.length;o--;)if(this.containsPoint(b,this._aObjects[o])){this.relatedTarget=m=this._aObjects[o];break}return m},toDataURL:function(b){var d;b||(b="png");if(b==="jpeg"||b==="png"){this.renderAll(true); d=this.getElement().toDataURL("image/"+b)}return d},toDataURLWithMultiplier:function(b,d){var m=this.getWidth(),o=this.getHeight(),u=m*d,v=o*d,w=this.getActiveObject();this.setWidth(u).setHeight(v);this._oContextTop.scale(d,d);w&&this.deactivateAll().renderAll();u=this.toDataURL(b);this._oContextTop.scale(1/d,1/d);this.setWidth(m).setHeight(o);w&&this.setActiveObject(w);this.renderAll();return u},getPointer:function(b){b=c(b);return{x:b.x-this._offset.left,y:b.y-this._offset.top}},getCenter:function(){return{top:this.getHeight()/ -2,left:this.getWidth()/2}},centerObjectH:function(b){b.set("left",this.getCenter().left);this.renderAll();return this},fxCenterObjectH:function(b){callbacks=callbacks||{};var d=function(){},m=callbacks.onComplete||d,o=callbacks.onChange||d,u=this;fabric.util.animate({startValue:b.get("left"),endValue:this.getCenter().left,duration:this.FX_DURATION,onChange:function(v){b.set("left",v);u.renderAll();o()},onComplete:function(){b.setCoords();m()}});return this},centerObjectV:function(b){b.set("top",this.getCenter().top); -this.renderAll();return this},fxCenterObjectV:function(b){callbacks=callbacks||{};var d=function(){},m=callbacks.onComplete||d,o=callbacks.onChange||d,u=this;fabric.util.animate({startValue:b.get("top"),endValue:this.getCenter().top,duration:this.FX_DURATION,onChange:function(v){b.set("top",v);u.renderAll();o()},onComplete:function(){b.setCoords();m()}});return this},straightenObject:function(b){b.straighten();this.renderAll();return this},fxStraightenObject:function(b){b.fxStraighten({onChange:this.renderAll.bind(this)}); -return this},toJSON:function(){return JSON.stringify(this.toObject())},toDatalessJSON:function(){return JSON.stringify(this.toDatalessObject())},toObject:function(){return this._toObjectMethod("toObject")},toDatalessObject:function(){return this._toObjectMethod("toDatalessObject")},_toObjectMethod:function(b){return{objects:this._aObjects.map(function(d){if(!this.includeDefaultValues){var m=d.includeDefaultValues;d.includeDefaultValues=false}var o=d[b]();if(!this.includeDefaultValues)d.includeDefaultValues= -m;return o},this),background:this.backgroundColor}},isEmpty:function(){return this._aObjects.length===0},loadFromJSON:function(b,d){if(b){var m=JSON.parse(b);if(!(!m||m&&!m.objects)){this.clear();var o=this;this._enlivenObjects(m.objects,function(){o.backgroundColor=m.background;d&&d()});return this}}},_enlivenObjects:function(b,d){var m=0,o=b.filter(function(v){return v.type==="image"}).length,u=this;b.forEach(function(v){if(v.type)switch(v.type){case "image":case "font":fabric[n(v.type)].fromObject(v, -function(x){u.add(x);++m===o&&d&&d()});break;default:var w=fabric[l(n(v.type))];w&&w.fromObject&&u.add(w.fromObject(v));break}});o===0&&d&&d()},loadFromDatalessJSON:function(b,d){if(b){var m=typeof b==="string"?JSON.parse(b):b;if(!(!m||m&&!m.objects)){this.clear();this._enlivenDatalessObjects(m.objects,d)}}},_enlivenDatalessObjects:function(b,d){function m(x,z){o.insertAt(x,z);x.setCoords();++u===v&&d&&d()}var o=this,u=0,v=b.length;try{b.forEach(function(x,z){var B=x.paths?"paths":"path",A=x[B];delete x[B]; -if(typeof A!=="string")switch(x.type){case "image":case "text":fabric[n(x.type)].fromObject(x,function(y){m(y,z)});break;default:(B=fabric[l(n(x.type))])&&B.fromObject&&m(B.fromObject(x),z);break}else if(x.type==="image")o.loadImageFromURL(A,function(y){y.setSourcePath(A);f(y,x);y.setAngle(x.angle);m(y,z)});else if(x.type==="text"){x.path=A;var C=fabric.Text.fromObject(x);fabric.util.getScript(A,function(){Object.prototype.toString.call(h.opera)==="[object Opera]"?setTimeout(function(){m(C,z)},500): -m(C,z)})}else o.loadSVGFromURL(A,function(y){y=y.length>1?new fabric.PathGroup(y,x):y[0];y.setSourcePath(A);if(!(y instanceof fabric.PathGroup)){f(y,x);typeof x.angle!=="undefined"&&y.setAngle(x.angle)}m(y,z)})},this)}catch(w){console.log(w.message)}},loadImageFromURL:function(){var b={};return function(d,m){function o(){var w=q.getElementById(b[d]);w.width&&w.height?m(new fabric.Image(w)):setTimeout(o,50)}var u=this;if(b[d])o();else{var v=new Image;v.onload=function(){v.onload=null;u._resizeImageToFit(v); -var w=new fabric.Image(v);m(w)};v.className="canvas-img-clone";v.src=d;if(this.shouldCacheImages)b[d]=Element.identify(v);q.body.appendChild(v)}}}(),loadSVGFromURL:function(b,d){function m(v){if(v=v.responseXML)(v=v.documentElement)&&fabric.parseSVGDocument(v,function(w,x){u.cache.set(b,{objects:w.invoke("toObject"),options:x});d(w,x)})}function o(){console.log("ERROR!")}var u=this;b=b.replace(/^\n\s*/,"").replace(/\?.*$/,"").trim();this.cache.has(b,function(v){if(v)u.cache.get(b,function(w){w=u._enlivenCachedObject(w); -d(w.objects,w.options)});else new Ajax.Request(b,{method:"get",onComplete:m,onFailure:o})})},_enlivenCachedObject:function(b){var d=b.objects;b=b.options;d=d.map(function(m){return fabric[n(m.type)].fromObject(m)});return{objects:d,options:b}},remove:function(b){e(this._aObjects,b);this.renderAll();return b},fxRemove:function(b,d){var m=this;b.fxRemove({onChange:this.renderAll.bind(this),onComplete:function(){m.remove(b);typeof d==="function"&&d()}});return this},sendToBack:function(b){e(this._aObjects, -b);this._aObjects.unshift(b);return this.renderAll()},bringToFront:function(b){e(this._aObjects,b);this._aObjects.push(b);return this.renderAll()},sendBackwards:function(b){var d=this._aObjects.indexOf(b),m=d;if(d!==0){for(d=d-1;d>=0;--d)if(b.intersectsWithObject(this._aObjects[d])){m=d;break}e(this._aObjects,b);this._aObjects.splice(m,0,b)}return this.renderAll()},bringForward:function(b){var d=this.getObjects(),m=d.indexOf(b),o=m;if(m!==d.length-1){m=m+1;for(var u=this._aObjects.length;m"};f(fabric.Element,{EMPTY_JSON:'{"objects": [], "background": "white"}',toGrayscale:function(b){var d=b.getContext("2d");b=d.getImageData(0,0,b.width,b.height);var m=b.data,o=b.width,u=b.height,v,w;for(i=0;i1?new fabric.PathGroup(y,x):y[0];y.setSourcePath(A); +if(!(y instanceof fabric.PathGroup)){f(y,x);typeof x.angle!=="undefined"&&y.setAngle(x.angle)}m(y,z)})},this)}catch(w){console.log(w.message)}},loadImageFromURL:function(){var b={};return function(d,m){function o(){var w=q.getElementById(b[d]);w.width&&w.height?m(new fabric.Image(w)):setTimeout(o,50)}var u=this;if(b[d])o();else{var v=new Image;v.onload=function(){v.onload=null;u._resizeImageToFit(v);var w=new fabric.Image(v);m(w)};v.className="canvas-img-clone";v.src=d;if(this.shouldCacheImages)b[d]= +Element.identify(v);q.body.appendChild(v)}}}(),loadSVGFromURL:function(b,d){function m(v){if(v=v.responseXML)(v=v.documentElement)&&fabric.parseSVGDocument(v,function(w,x){u.cache.set(b,{objects:w.invoke("toObject"),options:x});d(w,x)})}function o(){console.log("ERROR!")}var u=this;b=b.replace(/^\n\s*/,"").replace(/\?.*$/,"").trim();this.cache.has(b,function(v){if(v)u.cache.get(b,function(w){w=u._enlivenCachedObject(w);d(w.objects,w.options)});else new Ajax.Request(b,{method:"get",onComplete:m,onFailure:o})})}, +_enlivenCachedObject:function(b){var d=b.objects;b=b.options;d=d.map(function(m){return fabric[n(m.type)].fromObject(m)});return{objects:d,options:b}},remove:function(b){e(this._aObjects,b);this.renderAll();return b},fxRemove:function(b,d){var m=this;b.fxRemove({onChange:this.renderAll.bind(this),onComplete:function(){m.remove(b);typeof d==="function"&&d()}});return this},sendToBack:function(b){e(this._aObjects,b);this._aObjects.unshift(b);return this.renderAll()},bringToFront:function(b){e(this._aObjects, +b);this._aObjects.push(b);return this.renderAll()},sendBackwards:function(b){var d=this._aObjects.indexOf(b),m=d;if(d!==0){for(d=d-1;d>=0;--d)if(b.intersectsWithObject(this._aObjects[d])){m=d;break}e(this._aObjects,b);this._aObjects.splice(m,0,b)}return this.renderAll()},bringForward:function(b){var d=this.getObjects(),m=d.indexOf(b),o=m;if(m!==d.length-1){m=m+1;for(var u=this._aObjects.length;m"};f(fabric.Element,{EMPTY_JSON:'{"objects": [], "background": "white"}',toGrayscale:function(b){var d=b.getContext("2d");b=d.getImageData(0,0,b.width,b.height);var m=b.data,o=b.width,u=b.height,v,w;for(i=0;i1?e.apply(this,c.call(arguments,1)):e.call(this)}, initialize:function(a){this.setOptions(a);this._importProperties();this.originalState={};this.setCoords();this.saveState()},setOptions:function(a){this.options=q(this._getOptions(),a)},_getOptions:function(){return q(f(this._getSuperOptions()),this.options)},_getSuperOptions:function(){var a=this.constructor;if(a)if(a=a.superclass)if((a=a.prototype)&&typeof a._getOptions=="function")return a._getOptions();return{}},_importProperties:function(){this.stateProperties.forEach(function(a){a==="angle"? diff --git a/src/element.class.js b/src/element.class.js index 5aaf8ebe..25b155c7 100644 --- a/src/element.class.js +++ b/src/element.class.js @@ -1308,7 +1308,7 @@ * @return {fabric.Element} thisArg * @chainable */ - fxCenterObjectH: function (object) { + fxCenterObjectH: function (object, callbacks) { callbacks = callbacks || { }; var empty = function() { }, @@ -1354,7 +1354,7 @@ * @return {fabric.Element} thisArg * @chainable */ - fxCenterObjectV: function (object) { + fxCenterObjectV: function (object, callbacks) { callbacks = callbacks || { }; var empty = function() { },