mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-12 07:43:11 +00:00
Forgot to pass callbacks to fxCenterObjectH and fxCenterObjectV.
This commit is contained in:
parent
536d532d41
commit
2c8540f3b4
3 changed files with 19 additions and 19 deletions
4
dist/all.js
vendored
4
dist/all.js
vendored
|
|
@ -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() { },
|
||||
|
|
|
|||
30
dist/all.min.js
vendored
30
dist/all.min.js
vendored
|
|
@ -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<u;++m)if(b.intersectsWithObject(d[m])){o=
|
||||
m;break}e(d,b);d.splice(o,0,b)}this.renderAll()},setActiveObject:function(b){this._activeObject&&this._activeObject.setActive(false);this._activeObject=b;b.setActive(true);this.renderAll();g("object:selected",{target:b});return this},getActiveObject:function(){return this._activeObject},removeActiveObject:function(){this._activeObject&&this._activeObject.setActive(false);this._activeObject=null;return this},setActiveGroup:function(b){this._activeGroup=b;return this},getActiveGroup:function(){return this._activeGroup},
|
||||
removeActiveGroup:function(){var b=this.getActiveGroup();b&&b.destroy();return this.setActiveGroup(null)},item:function(b){return this.getObjects()[b]},deactivateAll:function(){for(var b=this.getObjects(),d=0,m=b.length;d<m;d++)b[d].setActive(false);this.removeActiveGroup();this.removeActiveObject();return this},complexity:function(){return this.getObjects().reduce(function(b,d){b+=d.complexity?d.complexity():0;return b},0)},dispose:function(){this.clear();p(this.getElement(),"mousedown",this._onMouseDown);
|
||||
p(q,"mouseup",this._onMouseUp);p(q,"mousemove",this._onMouseMove);p(h,"resize",this._onResize);return this},clone:function(b){var d=q.createElement("canvas");d.width=this.getWidth();d.height=this.getHeight();var m=this.__clone||(this.__clone=new fabric.Element(d));return m.loadFromJSON(this.toJSON(),function(){b&&b(m)})},_toDataURL:function(b,d){this.clone(function(m){d(m.toDataURL(b))})},_toDataURLWithMultiplier:function(b,d,m){this.clone(function(o){m(o.toDataURLWithMultiplier(b,d))})},_resizeImageToFit:function(b){var d=
|
||||
b.width||b.offsetWidth,m=this.getWidth()/d;if(d)b.width=d*m},cache:{has:function(b,d){d(false)},get:function(){},set:function(){}}});fabric.Element.prototype.toString=function(){return"#<fabric.Element ("+this.complexity()+"): { objects: "+this.getObjects().length+" }>"};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;i<o;i++)for(j=0;j<u;j++){v=
|
||||
i*4*u+j*4;w=(m[v]+m[v+1]+m[v+2])/3;m[v]=w;m[v+1]=w;m[v+2]=w}d.putImageData(b,0,0)},supports:function(b){var d=q.createElement("canvas");if(!d||!d.getContext)return null;var m=d.getContext("2d");if(!m)return null;switch(b){case "getImageData":return typeof m.getImageData!=="undefined";case "toDataURL":return typeof d.toDataURL!=="undefined";default:return null}}})}})();
|
||||
2,left:this.getWidth()/2}},centerObjectH:function(b){b.set("left",this.getCenter().left);this.renderAll();return this},fxCenterObjectH:function(b,d){d=d||{};var m=function(){},o=d.onComplete||m,u=d.onChange||m,v=this;fabric.util.animate({startValue:b.get("left"),endValue:this.getCenter().left,duration:this.FX_DURATION,onChange:function(w){b.set("left",w);v.renderAll();u()},onComplete:function(){b.setCoords();o()}});return this},centerObjectV:function(b){b.set("top",this.getCenter().top);this.renderAll();
|
||||
return this},fxCenterObjectV:function(b,d){d=d||{};var m=function(){},o=d.onComplete||m,u=d.onChange||m,v=this;fabric.util.animate({startValue:b.get("top"),endValue:this.getCenter().top,duration:this.FX_DURATION,onChange:function(w){b.set("top",w);v.renderAll();u()},onComplete:function(){b.setCoords();o()}});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<u;++m)if(b.intersectsWithObject(d[m])){o=m;break}e(d,b);d.splice(o,0,b)}this.renderAll()},setActiveObject:function(b){this._activeObject&&
|
||||
this._activeObject.setActive(false);this._activeObject=b;b.setActive(true);this.renderAll();g("object:selected",{target:b});return this},getActiveObject:function(){return this._activeObject},removeActiveObject:function(){this._activeObject&&this._activeObject.setActive(false);this._activeObject=null;return this},setActiveGroup:function(b){this._activeGroup=b;return this},getActiveGroup:function(){return this._activeGroup},removeActiveGroup:function(){var b=this.getActiveGroup();b&&b.destroy();return this.setActiveGroup(null)},
|
||||
item:function(b){return this.getObjects()[b]},deactivateAll:function(){for(var b=this.getObjects(),d=0,m=b.length;d<m;d++)b[d].setActive(false);this.removeActiveGroup();this.removeActiveObject();return this},complexity:function(){return this.getObjects().reduce(function(b,d){b+=d.complexity?d.complexity():0;return b},0)},dispose:function(){this.clear();p(this.getElement(),"mousedown",this._onMouseDown);p(q,"mouseup",this._onMouseUp);p(q,"mousemove",this._onMouseMove);p(h,"resize",this._onResize);
|
||||
return this},clone:function(b){var d=q.createElement("canvas");d.width=this.getWidth();d.height=this.getHeight();var m=this.__clone||(this.__clone=new fabric.Element(d));return m.loadFromJSON(this.toJSON(),function(){b&&b(m)})},_toDataURL:function(b,d){this.clone(function(m){d(m.toDataURL(b))})},_toDataURLWithMultiplier:function(b,d,m){this.clone(function(o){m(o.toDataURLWithMultiplier(b,d))})},_resizeImageToFit:function(b){var d=b.width||b.offsetWidth,m=this.getWidth()/d;if(d)b.width=d*m},cache:{has:function(b,
|
||||
d){d(false)},get:function(){},set:function(){}}});fabric.Element.prototype.toString=function(){return"#<fabric.Element ("+this.complexity()+"): { objects: "+this.getObjects().length+" }>"};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;i<o;i++)for(j=0;j<u;j++){v=i*4*u+j*4;w=(m[v]+m[v+1]+m[v+2])/3;m[v]=w;m[v+1]=w;m[v+2]=w}d.putImageData(b,0,0)},
|
||||
supports:function(b){var d=q.createElement("canvas");if(!d||!d.getContext)return null;var m=d.getContext("2d");if(!m)return null;switch(b){case "getImageData":return typeof m.getImageData!=="undefined";case "toDataURL":return typeof d.toDataURL!=="undefined";default:return null}}})}})();
|
||||
(function(){var h=this.fabric||(this.fabric={}),q=h.util.object.extend,f=h.util.object.clone,n=h.util.toFixed,l=h.util.string.capitalize,g=h.util.getPointer,c=Array.prototype.slice;if(!h.Object){h.Object=h.util.createClass({type:"object",includeDefaultValues:true,NUM_FRACTION_DIGITS:2,FX_DURATION:500,FX_TRANSITION:"decel",MIN_SCALE_LIMIT:0.1,stateProperties:"top left width height scaleX scaleY flipX flipY theta angle opacity cornersize fill overlayFill stroke strokeWidth fillRule borderScaleFactor transformMatrix".split(" "),
|
||||
options:{top:0,left:0,width:100,height:100,scaleX:1,scaleY:1,flipX:false,flipY:false,theta:0,opacity:1,angle:0,cornersize:10,padding:0,borderColor:"rgba(102,153,255,0.75)",cornerColor:"rgba(102,153,255,0.5)",fill:"rgb(0,0,0)",overlayFill:null,stroke:null,strokeWidth:1,fillRule:"source-over",borderOpacityWhenMoving:0.4,borderScaleFactor:1,transformMatrix:null},callSuper:function(a){var e=this.constructor.superclass.prototype[a];return arguments.length>1?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"?
|
||||
|
|
|
|||
|
|
@ -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() { },
|
||||
|
|
|
|||
Loading…
Reference in a new issue