mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-19 11:01:08 +00:00
Rename canvas_*.class.js files to just *.class.js
This commit is contained in:
parent
41917f57b4
commit
2340a98526
46 changed files with 333 additions and 527 deletions
264
dist/all.js
vendored
264
dist/all.js
vendored
|
|
@ -1,7 +1,10 @@
|
|||
/*! Fabric.js Copyright 2010, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */
|
||||
|
||||
if (typeof console == 'undefined') {
|
||||
var console = { log: function() { }, warn: function() { } };
|
||||
var console = {
|
||||
log: function() { },
|
||||
warn: function() { }
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -414,10 +417,10 @@ replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
|
|||
|
||||
(function (global) {
|
||||
|
||||
var fabric = this.fabric || (this.fabric = { });
|
||||
fabric.base = { };
|
||||
var fabric = this.fabric || (this.fabric = { }),
|
||||
slice = Array.prototype.slice;
|
||||
|
||||
var slice = Array.prototype.slice;
|
||||
fabric.util = { };
|
||||
|
||||
if (!Array.prototype.indexOf) {
|
||||
Array.prototype.indexOf = function(value, from) {
|
||||
|
|
@ -574,7 +577,7 @@ function min(array, byProperty) {
|
|||
return result;
|
||||
}
|
||||
|
||||
fabric.base.array = {
|
||||
fabric.util.array = {
|
||||
invoke: invoke,
|
||||
min: min,
|
||||
max: max
|
||||
|
|
@ -590,7 +593,7 @@ function clone(object) {
|
|||
return extend({ }, object);
|
||||
}
|
||||
|
||||
fabric.base.object = {
|
||||
fabric.util.object = {
|
||||
extend: extend,
|
||||
clone: clone
|
||||
};
|
||||
|
|
@ -610,7 +613,7 @@ function capitalize(string) {
|
|||
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
|
||||
}
|
||||
|
||||
fabric.base.string = {
|
||||
fabric.util.string = {
|
||||
camelize: camelize,
|
||||
capitalize: capitalize
|
||||
};
|
||||
|
|
@ -684,7 +687,7 @@ if (!Function.prototype.bind) {
|
|||
return klass;
|
||||
}
|
||||
|
||||
fabric.base.createClass = createClass;
|
||||
fabric.util.createClass = createClass;
|
||||
})();
|
||||
|
||||
(function (global) {
|
||||
|
|
@ -827,8 +830,8 @@ if (!Function.prototype.bind) {
|
|||
};
|
||||
}
|
||||
|
||||
fabric.base.addListener = addListener;
|
||||
fabric.base.removeListener = removeListener;
|
||||
fabric.util.addListener = addListener;
|
||||
fabric.util.removeListener = removeListener;
|
||||
|
||||
|
||||
var customEventListeners = { };
|
||||
|
|
@ -854,8 +857,8 @@ if (!Function.prototype.bind) {
|
|||
}
|
||||
}
|
||||
|
||||
fabric.base.observeEvent = observeEvent;
|
||||
fabric.base.fireEvent = fireEvent;
|
||||
fabric.util.observeEvent = observeEvent;
|
||||
fabric.util.fireEvent = fireEvent;
|
||||
|
||||
function getPointer(event) {
|
||||
return { x: pointerX(event), y: pointerY(event) };
|
||||
|
|
@ -879,7 +882,7 @@ if (!Function.prototype.bind) {
|
|||
(docElement.clientTop || 0));
|
||||
}
|
||||
|
||||
fabric.base.getPointer = getPointer;
|
||||
fabric.util.getPointer = getPointer;
|
||||
})(this);
|
||||
(function () {
|
||||
|
||||
|
|
@ -936,7 +939,7 @@ if (!Function.prototype.bind) {
|
|||
};
|
||||
}
|
||||
|
||||
fabric.base.setStyle = setStyle;
|
||||
fabric.util.setStyle = setStyle;
|
||||
|
||||
})();
|
||||
function getById(id) {
|
||||
|
|
@ -1021,7 +1024,7 @@ function falseFunction() { return false; };
|
|||
return element;
|
||||
}
|
||||
|
||||
fabric.base.makeElementUnselectable = makeElementUnselectable
|
||||
fabric.util.makeElementUnselectable = makeElementUnselectable
|
||||
})();
|
||||
|
||||
(function(){
|
||||
|
|
@ -1052,11 +1055,11 @@ function falseFunction() { return false; };
|
|||
callback();
|
||||
}
|
||||
|
||||
fabric.base.getScript = getScript;
|
||||
fabric.util.getScript = getScript;
|
||||
|
||||
var Jaxer = this.Jaxer;
|
||||
if (Jaxer && Jaxer.load) {
|
||||
fabric.base.getScript = getScriptJaxer;
|
||||
fabric.util.getScript = getScriptJaxer;
|
||||
}
|
||||
})();
|
||||
|
||||
|
|
@ -1086,13 +1089,13 @@ function animate(options) {
|
|||
}, 10);
|
||||
}
|
||||
|
||||
fabric.base.getById = getById;
|
||||
fabric.base.toArray = toArray;
|
||||
fabric.base.makeElement = makeElement;
|
||||
fabric.base.addClass = addClass;
|
||||
fabric.base.wrapElement = wrapElement;
|
||||
fabric.base.getElementOffset = getElementOffset;
|
||||
fabric.base.animate = animate;
|
||||
fabric.util.getById = getById;
|
||||
fabric.util.toArray = toArray;
|
||||
fabric.util.makeElement = makeElement;
|
||||
fabric.util.addClass = addClass;
|
||||
fabric.util.wrapElement = wrapElement;
|
||||
fabric.util.getElementOffset = getElementOffset;
|
||||
fabric.util.animate = animate;
|
||||
|
||||
(function(){
|
||||
|
||||
|
|
@ -1153,20 +1156,11 @@ fabric.base.animate = animate;
|
|||
return request;
|
||||
};
|
||||
|
||||
fabric.base.request = request;
|
||||
fabric.util.request = request;
|
||||
})();
|
||||
|
||||
})(this);
|
||||
|
||||
(function(){
|
||||
|
||||
var fabric = this.fabric || (this.fabric = { });
|
||||
|
||||
if (fabric.util) {
|
||||
console.warn('fabric.util is already defined');
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* Removes value from an array.
|
||||
|
|
@ -1216,13 +1210,13 @@ fabric.base.animate = animate;
|
|||
return parseFloat(Number(number).toFixed(fractionDigits));
|
||||
}
|
||||
|
||||
fabric.util = {
|
||||
removeFromArray: removeFromArray,
|
||||
degreesToRadians: degreesToRadians,
|
||||
toFixed: toFixed,
|
||||
getRandomInt: getRandomInt
|
||||
};
|
||||
fabric.util.removeFromArray = removeFromArray;
|
||||
fabric.util.degreesToRadians = degreesToRadians;
|
||||
fabric.util.toFixed = toFixed;
|
||||
fabric.util.getRandomInt = getRandomInt;
|
||||
})();
|
||||
|
||||
})(this);
|
||||
(function(){
|
||||
|
||||
var fabric = this.fabric || (this.fabric = { });
|
||||
|
|
@ -1281,8 +1275,8 @@ fabric.base.animate = animate;
|
|||
return memo;
|
||||
}, { });
|
||||
|
||||
ownAttributes = fabric.base.object.extend(fabric.parseStyleAttribute(element), ownAttributes);
|
||||
return fabric.base.object.extend(parentAttributes, ownAttributes);
|
||||
ownAttributes = fabric.util.object.extend(fabric.parseStyleAttribute(element), ownAttributes);
|
||||
return fabric.util.object.extend(parentAttributes, ownAttributes);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -1469,7 +1463,7 @@ fabric.base.animate = animate;
|
|||
*/
|
||||
function parseElements(elements, options) {
|
||||
var _elements = elements.map(function(el) {
|
||||
var klass = fabric[fabric.base.string.capitalize(el.tagName)];
|
||||
var klass = fabric[fabric.util.string.capitalize(el.tagName)];
|
||||
if (klass && klass.fromElement) {
|
||||
try {
|
||||
return klass.fromElement(el, options);
|
||||
|
|
@ -1519,7 +1513,7 @@ fabric.base.animate = animate;
|
|||
|
||||
return function(doc, callback) {
|
||||
if (!doc) return;
|
||||
var descendants = fabric.base.toArray(doc.getElementsByTagName('*'));
|
||||
var descendants = fabric.util.toArray(doc.getElementsByTagName('*'));
|
||||
|
||||
var elements = descendants.filter(function(el) {
|
||||
return reAllowedSVGTagNames.test(el.tagName) &&
|
||||
|
|
@ -1551,7 +1545,7 @@ fabric.base.animate = animate;
|
|||
height: height
|
||||
};
|
||||
|
||||
var elements = fabric.parseElements(elements, fabric.base.object.clone(options));
|
||||
var elements = fabric.parseElements(elements, fabric.util.object.clone(options));
|
||||
if (!elements || (elements && !elements.length)) return;
|
||||
|
||||
if (callback) {
|
||||
|
|
@ -1560,7 +1554,7 @@ fabric.base.animate = animate;
|
|||
};
|
||||
})();
|
||||
|
||||
fabric.base.object.extend(fabric, {
|
||||
fabric.util.object.extend(fabric, {
|
||||
parseAttributes: parseAttributes,
|
||||
parseElements: parseElements,
|
||||
parseStyleAttribute: parseStyleAttribute,
|
||||
|
|
@ -2080,7 +2074,7 @@ fabric.base.animate = animate;
|
|||
STROKE_OFFSET = 0.5,
|
||||
FX_TRANSITION = 'decel',
|
||||
|
||||
getPointer = fabric.base.getPointer,
|
||||
getPointer = fabric.util.getPointer,
|
||||
|
||||
cursorMap = {
|
||||
'tr': 'ne-resize',
|
||||
|
|
@ -2241,7 +2235,7 @@ fabric.base.animate = animate;
|
|||
this.calcOffset();
|
||||
};
|
||||
|
||||
fabric.base.object.extend(fabric.Element.prototype, {
|
||||
fabric.util.object.extend(fabric.Element.prototype, {
|
||||
|
||||
selectionColor: 'rgba(100,100,255,0.3)', // blue
|
||||
selectionBorderColor: 'rgba(255,255,255,0.3)',
|
||||
|
|
@ -2266,7 +2260,7 @@ fabric.base.animate = animate;
|
|||
* @chainable
|
||||
*/
|
||||
calcOffset: function () {
|
||||
this._offset = fabric.base.getElementOffset(this.getElement());
|
||||
this._offset = fabric.util.getElementOffset(this.getElement());
|
||||
return this;
|
||||
},
|
||||
|
||||
|
|
@ -2302,7 +2296,7 @@ fabric.base.animate = animate;
|
|||
*
|
||||
*/
|
||||
_initElement: function (canvasEl) {
|
||||
var el = fabric.base.getById(canvasEl);
|
||||
var el = fabric.util.getById(canvasEl);
|
||||
this._oElement = el || document.createElement('canvas');
|
||||
|
||||
if (typeof this._oElement.getContext === 'undefined') {
|
||||
|
|
@ -2327,12 +2321,12 @@ fabric.base.animate = animate;
|
|||
* @method _initWrapperElement
|
||||
*/
|
||||
_initWrapperElement: function (width, height) {
|
||||
var wrapper = fabric.base.wrapElement(this.getElement(), 'div', { className: 'canvas_container' });
|
||||
fabric.base.setStyle(wrapper, {
|
||||
var wrapper = fabric.util.wrapElement(this.getElement(), 'div', { className: 'canvas_container' });
|
||||
fabric.util.setStyle(wrapper, {
|
||||
width: width + 'px',
|
||||
height: height + 'px'
|
||||
});
|
||||
fabric.base.makeElementUnselectable(wrapper);
|
||||
fabric.util.makeElementUnselectable(wrapper);
|
||||
this.wrapper = wrapper;
|
||||
},
|
||||
|
||||
|
|
@ -2341,7 +2335,7 @@ fabric.base.animate = animate;
|
|||
* @method _setElementStyle
|
||||
*/
|
||||
_setElementStyle: function (width, height) {
|
||||
fabric.base.setStyle(this.getElement(), {
|
||||
fabric.util.setStyle(this.getElement(), {
|
||||
position: 'absolute',
|
||||
width: width + 'px',
|
||||
height: height + 'px',
|
||||
|
|
@ -2358,7 +2352,7 @@ fabric.base.animate = animate;
|
|||
* See configuration documentation for more details.
|
||||
*/
|
||||
_initConfig: function (oConfig) {
|
||||
fabric.base.object.extend(this._oConfig, oConfig || { });
|
||||
fabric.util.object.extend(this._oConfig, oConfig || { });
|
||||
|
||||
this._oConfig.width = parseInt(this._oElement.width, 10) || 0;
|
||||
this._oConfig.height = parseInt(this._oElement.height, 10) || 0;
|
||||
|
|
@ -2382,10 +2376,10 @@ fabric.base.animate = animate;
|
|||
this._onMouseMove = function (e){ _this.__onMouseMove(e); };
|
||||
this._onResize = function (e) { _this.calcOffset() };
|
||||
|
||||
fabric.base.addListener(this._oElement, 'mousedown', this._onMouseDown);
|
||||
fabric.base.addListener(document, 'mousemove', this._onMouseMove);
|
||||
fabric.base.addListener(document, 'mouseup', this._onMouseUp);
|
||||
fabric.base.addListener(window, 'resize', this._onResize);
|
||||
fabric.util.addListener(this._oElement, 'mousedown', this._onMouseDown);
|
||||
fabric.util.addListener(document, 'mousemove', this._onMouseMove);
|
||||
fabric.util.addListener(document, 'mouseup', this._onMouseUp);
|
||||
fabric.util.addListener(window, 'resize', this._onResize);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -2417,7 +2411,7 @@ fabric.base.animate = animate;
|
|||
if (typeof element.getContext === 'undefined') {
|
||||
throw CANVAS_INIT_ERROR;
|
||||
}
|
||||
fabric.base.makeElementUnselectable(oContainer);
|
||||
fabric.util.makeElementUnselectable(oContainer);
|
||||
return oContainer;
|
||||
},
|
||||
|
||||
|
|
@ -2529,7 +2523,7 @@ fabric.base.animate = animate;
|
|||
target = transform.target;
|
||||
|
||||
if (target.__scaling) {
|
||||
fabric.base.fireEvent('object:scaled', { target: target });
|
||||
fabric.util.fireEvent('object:scaled', { target: target });
|
||||
target.__scaling = false;
|
||||
}
|
||||
|
||||
|
|
@ -2539,7 +2533,7 @@ fabric.base.animate = animate;
|
|||
|
||||
if (target.hasStateChanged()) {
|
||||
target.isMoving = false;
|
||||
fabric.base.fireEvent('object:modified', { target: target });
|
||||
fabric.util.fireEvent('object:modified', { target: target });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2552,7 +2546,7 @@ fabric.base.animate = animate;
|
|||
if (activeGroup) {
|
||||
if (activeGroup.hasStateChanged() &&
|
||||
activeGroup.containsPoint(this.getPointer(e))) {
|
||||
fabric.base.fireEvent('group:modified', { target: activeGroup });
|
||||
fabric.util.fireEvent('group:modified', { target: activeGroup });
|
||||
}
|
||||
activeGroup.setObjectsCoords();
|
||||
activeGroup.set('isMoving', false);
|
||||
|
|
@ -2653,15 +2647,15 @@ fabric.base.animate = animate;
|
|||
deactivateAllWithDispatch: function () {
|
||||
var activeGroup = this.getActiveGroup();
|
||||
if (activeGroup) {
|
||||
fabric.base.fireEvent('before:group:destroyed', {
|
||||
fabric.util.fireEvent('before:group:destroyed', {
|
||||
target: activeGroup
|
||||
});
|
||||
}
|
||||
this.deactivateAll();
|
||||
if (activeGroup) {
|
||||
fabric.base.fireEvent('after:group:destroyed');
|
||||
fabric.util.fireEvent('after:group:destroyed');
|
||||
}
|
||||
fabric.base.fireEvent('selection:cleared');
|
||||
fabric.util.fireEvent('selection:cleared');
|
||||
return this;
|
||||
},
|
||||
|
||||
|
|
@ -2722,7 +2716,7 @@ fabric.base.animate = animate;
|
|||
else {
|
||||
activeGroup.add(target);
|
||||
}
|
||||
fabric.base.fireEvent('group:selected', { target: activeGroup });
|
||||
fabric.util.fireEvent('group:selected', { target: activeGroup });
|
||||
activeGroup.setActive(true);
|
||||
}
|
||||
else {
|
||||
|
|
@ -2970,7 +2964,7 @@ fabric.base.animate = animate;
|
|||
}
|
||||
if (group.length === 1) {
|
||||
this.setActiveObject(group[0]);
|
||||
fabric.base.fireEvent('object:selected', {
|
||||
fabric.util.fireEvent('object:selected', {
|
||||
target: group[0]
|
||||
});
|
||||
}
|
||||
|
|
@ -2978,7 +2972,7 @@ fabric.base.animate = animate;
|
|||
var group = new fabric.Group(group);
|
||||
this.setActiveGroup(group);
|
||||
group.saveCoords();
|
||||
fabric.base.fireEvent('group:selected', { target: group });
|
||||
fabric.util.fireEvent('group:selected', { target: group });
|
||||
}
|
||||
this.renderAll();
|
||||
},
|
||||
|
|
@ -3508,7 +3502,7 @@ fabric.base.animate = animate;
|
|||
switch (o.type) {
|
||||
case 'image':
|
||||
case 'font':
|
||||
fabric[fabric.base.string.capitalize(o.type)].fromObject(o, function (o) {
|
||||
fabric[fabric.util.string.capitalize(o.type)].fromObject(o, function (o) {
|
||||
_this.add(o);
|
||||
if (++numLoadedImages === numTotalImages) {
|
||||
if (callback) callback();
|
||||
|
|
@ -3516,7 +3510,7 @@ fabric.base.animate = animate;
|
|||
});
|
||||
break;
|
||||
default:
|
||||
var klass = fabric[fabric.base.string.camelize(fabric.base.string.capitalize(o.type))];
|
||||
var klass = fabric[fabric.util.string.camelize(fabric.util.string.capitalize(o.type))];
|
||||
if (klass && klass.fromObject) {
|
||||
_this.add(klass.fromObject(o));
|
||||
}
|
||||
|
|
@ -3589,7 +3583,7 @@ fabric.base.animate = animate;
|
|||
_this.loadImageFromURL(path, function (image) {
|
||||
image.setSourcePath(path);
|
||||
|
||||
fabric.base.object.extend(image, obj);
|
||||
fabric.util.object.extend(image, obj);
|
||||
image.setAngle(obj.angle);
|
||||
|
||||
onObjectLoaded(image, index);
|
||||
|
|
@ -3611,7 +3605,7 @@ fabric.base.animate = animate;
|
|||
}
|
||||
}
|
||||
|
||||
fabric.base.getScript(path, onscriptload);
|
||||
fabric.util.getScript(path, onscriptload);
|
||||
}
|
||||
else {
|
||||
_this.loadSVGFromURL(path, function (elements, options) {
|
||||
|
|
@ -3624,7 +3618,7 @@ fabric.base.animate = animate;
|
|||
object.setSourcePath(path);
|
||||
|
||||
if (!(object instanceof fabric.PathGroup)) {
|
||||
fabric.base.object.extend(object, obj);
|
||||
fabric.util.object.extend(object, obj);
|
||||
if (typeof obj.angle !== 'undefined') {
|
||||
object.setAngle(obj.angle);
|
||||
}
|
||||
|
|
@ -3873,7 +3867,7 @@ fabric.base.animate = animate;
|
|||
|
||||
this.renderAll();
|
||||
|
||||
fabric.base.fireEvent('object:selected', { target: object });
|
||||
fabric.util.fireEvent('object:selected', { target: object });
|
||||
return this;
|
||||
},
|
||||
|
||||
|
|
@ -3980,10 +3974,10 @@ fabric.base.animate = animate;
|
|||
*/
|
||||
dispose: function () {
|
||||
this.clear();
|
||||
fabric.base.removeListener(this.getElement(), 'mousedown', this._onMouseDown);
|
||||
fabric.base.removeListener(document, 'mouseup', this._onMouseUp);
|
||||
fabric.base.removeListener(document, 'mousemove', this._onMouseMove);
|
||||
fabric.base.removeListener(window, 'resize', this._onResize);
|
||||
fabric.util.removeListener(this.getElement(), 'mousedown', this._onMouseDown);
|
||||
fabric.util.removeListener(document, 'mouseup', this._onMouseUp);
|
||||
fabric.util.removeListener(document, 'mousemove', this._onMouseMove);
|
||||
fabric.util.removeListener(window, 'resize', this._onResize);
|
||||
return this;
|
||||
},
|
||||
|
||||
|
|
@ -4049,7 +4043,7 @@ fabric.base.animate = animate;
|
|||
'{ objects: ' + this.getObjects().length + ' }>';
|
||||
};
|
||||
|
||||
fabric.base.object.extend(fabric.Element, {
|
||||
fabric.util.object.extend(fabric.Element, {
|
||||
|
||||
/**
|
||||
* @property EMPTY_JSON
|
||||
|
|
@ -4139,7 +4133,7 @@ fabric.base.animate = animate;
|
|||
* @class Object
|
||||
* @memberOf Canvas
|
||||
*/
|
||||
fabric.Object = fabric.base.createClass({
|
||||
fabric.Object = fabric.util.createClass({
|
||||
|
||||
type: 'object',
|
||||
|
||||
|
|
@ -4221,7 +4215,7 @@ fabric.base.animate = animate;
|
|||
},
|
||||
|
||||
setOptions: function(options) {
|
||||
this.options = fabric.base.object.extend(this._getOptions(), options);
|
||||
this.options = fabric.util.object.extend(this._getOptions(), options);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -4229,7 +4223,7 @@ fabric.base.animate = animate;
|
|||
* @method _getOptions
|
||||
*/
|
||||
_getOptions: function() {
|
||||
return fabric.base.object.extend(fabric.base.object.clone(this._getSuperOptions()), this.options);
|
||||
return fabric.util.object.extend(fabric.util.object.clone(this._getSuperOptions()), this.options);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -4361,7 +4355,7 @@ fabric.base.animate = animate;
|
|||
* @return {String}
|
||||
*/
|
||||
toString: function() {
|
||||
return "#<fabric." + fabric.base.string.capitalize(this.type) + ">";
|
||||
return "#<fabric." + fabric.util.string.capitalize(this.type) + ">";
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -4771,7 +4765,7 @@ fabric.base.animate = animate;
|
|||
el.width = this.getWidth();
|
||||
el.height = this.getHeight();
|
||||
|
||||
fabric.base.wrapElement(el, 'div');
|
||||
fabric.util.wrapElement(el, 'div');
|
||||
|
||||
var canvas = new fabric.Element(el);
|
||||
canvas.backgroundColor = 'transparent';
|
||||
|
|
@ -4897,7 +4891,7 @@ fabric.base.animate = animate;
|
|||
* @return {String|Boolean} corner code (tl, tr, bl, br, etc.), or false if nothing is found
|
||||
*/
|
||||
_findTargetCorner: function(e, offset) {
|
||||
var pointer = fabric.base.getPointer(e),
|
||||
var pointer = fabric.util.getPointer(e),
|
||||
ex = pointer.x - offset.left,
|
||||
ey = pointer.y - offset.top,
|
||||
xpoints,
|
||||
|
|
@ -5262,7 +5256,7 @@ fabric.base.animate = animate;
|
|||
onChange = callbacks.onChange || empty,
|
||||
_this = this;
|
||||
|
||||
fabric.base.animate({
|
||||
fabric.util.animate({
|
||||
startValue: this.get('angle'),
|
||||
endValue: this._getAngleValueForStraighten(),
|
||||
duration: this.FX_DURATION,
|
||||
|
|
@ -5296,7 +5290,7 @@ fabric.base.animate = animate;
|
|||
onChange = callbacks.onChange || empty,
|
||||
_this = this;
|
||||
|
||||
fabric.base.animate({
|
||||
fabric.util.animate({
|
||||
startValue: this.get('opacity'),
|
||||
endValue: 0,
|
||||
duration: this.FX_DURATION,
|
||||
|
|
@ -5347,7 +5341,7 @@ fabric.base.animate = animate;
|
|||
return;
|
||||
}
|
||||
|
||||
fabric.Line = fabric.base.createClass(fabric.Object, {
|
||||
fabric.Line = fabric.util.createClass(fabric.Object, {
|
||||
|
||||
type: 'line',
|
||||
|
||||
|
|
@ -5401,7 +5395,7 @@ fabric.base.animate = animate;
|
|||
* @return {Object}
|
||||
*/
|
||||
toObject: function() {
|
||||
return fabric.base.object.extend(this.callSuper('toObject'), {
|
||||
return fabric.util.object.extend(this.callSuper('toObject'), {
|
||||
x1: this.get('x1'),
|
||||
y1: this.get('y1'),
|
||||
x2: this.get('x2'),
|
||||
|
|
@ -5427,7 +5421,7 @@ fabric.base.animate = animate;
|
|||
parsedAttributes.x2 || 0,
|
||||
parsedAttributes.y2 || 0
|
||||
];
|
||||
return new fabric.Line(points, fabric.base.object.extend(parsedAttributes, options));
|
||||
return new fabric.Line(points, fabric.util.object.extend(parsedAttributes, options));
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -5453,7 +5447,7 @@ fabric.base.animate = animate;
|
|||
return;
|
||||
}
|
||||
|
||||
fabric.Circle = fabric.base.createClass(fabric.Object, /** @lends fabric.Circle.prototype */ {
|
||||
fabric.Circle = fabric.util.createClass(fabric.Object, /** @lends fabric.Circle.prototype */ {
|
||||
|
||||
/**
|
||||
* @field
|
||||
|
|
@ -5482,7 +5476,7 @@ fabric.base.animate = animate;
|
|||
* @return {Object} object representation of an instance
|
||||
*/
|
||||
toObject: function() {
|
||||
return fabric.base.object.extend(this.callSuper('toObject'), {
|
||||
return fabric.util.object.extend(this.callSuper('toObject'), {
|
||||
radius: this.get('radius')
|
||||
});
|
||||
},
|
||||
|
|
@ -5531,7 +5525,7 @@ fabric.base.animate = animate;
|
|||
if (!isValidRadius(parsedAttributes)) {
|
||||
throw Error('value of `r` attribute is required and can not be negative');
|
||||
}
|
||||
return new fabric.Circle(fabric.base.object.extend(parsedAttributes, options));
|
||||
return new fabric.Circle(fabric.util.object.extend(parsedAttributes, options));
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -5561,7 +5555,7 @@ fabric.base.animate = animate;
|
|||
return;
|
||||
}
|
||||
|
||||
fabric.Ellipse = fabric.base.createClass(fabric.Object, {
|
||||
fabric.Ellipse = fabric.util.createClass(fabric.Object, {
|
||||
|
||||
type: 'ellipse',
|
||||
|
||||
|
|
@ -5589,7 +5583,7 @@ fabric.base.animate = animate;
|
|||
* @return {Object} object representation of an instance
|
||||
*/
|
||||
toObject: function() {
|
||||
return fabric.base.object.extend(this.callSuper('toObject'), {
|
||||
return fabric.util.object.extend(this.callSuper('toObject'), {
|
||||
rx: this.get('rx'),
|
||||
ry: this.get('ry')
|
||||
})
|
||||
|
|
@ -5644,7 +5638,7 @@ fabric.base.animate = animate;
|
|||
*/
|
||||
fabric.Ellipse.fromElement = function(element, options) {
|
||||
var parsedAttributes = fabric.parseAttributes(element, fabric.Ellipse.ATTRIBUTE_NAMES);
|
||||
return new fabric.Ellipse(fabric.base.object.extend(parsedAttributes, options));
|
||||
return new fabric.Ellipse(fabric.util.object.extend(parsedAttributes, options));
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -5670,7 +5664,7 @@ fabric.base.animate = animate;
|
|||
* @class Rect
|
||||
* @extends fabric.Object
|
||||
*/
|
||||
fabric.Rect = fabric.base.createClass(fabric.Object, /** @lends fabric.Rect.prototype */ {
|
||||
fabric.Rect = fabric.util.createClass(fabric.Object, /** @lends fabric.Rect.prototype */ {
|
||||
|
||||
type: 'rect',
|
||||
|
||||
|
|
@ -5781,7 +5775,7 @@ fabric.base.animate = animate;
|
|||
var parsedAttributes = fabric.parseAttributes(element, fabric.Rect.ATTRIBUTE_NAMES);
|
||||
parsedAttributes = _setDefaultLeftTopValues(parsedAttributes);
|
||||
|
||||
var rect = new fabric.Rect(fabric.base.object.extend(options || { }, parsedAttributes));
|
||||
var rect = new fabric.Rect(fabric.util.object.extend(options || { }, parsedAttributes));
|
||||
rect._normalizeLeftTopProperties(parsedAttributes);
|
||||
|
||||
return rect;
|
||||
|
|
@ -5807,7 +5801,7 @@ fabric.base.animate = animate;
|
|||
return;
|
||||
}
|
||||
|
||||
fabric.Polyline = fabric.base.createClass(fabric.Object, {
|
||||
fabric.Polyline = fabric.util.createClass(fabric.Object, {
|
||||
|
||||
type: 'polyline',
|
||||
|
||||
|
|
@ -5895,7 +5889,7 @@ fabric.base.animate = animate;
|
|||
var points = fabric.parsePointsAttribute(element.getAttribute('points')),
|
||||
parsedAttributes = fabric.parseAttributes(element, ATTRIBUTE_NAMES);
|
||||
|
||||
return new fabric.Polyline(points, fabric.base.object.extend(parsedAttributes, options));
|
||||
return new fabric.Polyline(points, fabric.util.object.extend(parsedAttributes, options));
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -5922,7 +5916,7 @@ fabric.base.animate = animate;
|
|||
function byX(p) { return p.x; }
|
||||
function byY(p) { return p.y; }
|
||||
|
||||
fabric.Polygon = fabric.base.createClass(fabric.Object, {
|
||||
fabric.Polygon = fabric.util.createClass(fabric.Object, {
|
||||
|
||||
type: 'polygon',
|
||||
|
||||
|
|
@ -5947,10 +5941,10 @@ fabric.base.animate = animate;
|
|||
_calcDimensions: function() {
|
||||
|
||||
var points = this.points,
|
||||
minX = fabric.base.array.min(points, 'x'),
|
||||
minY = fabric.base.array.min(points, 'y'),
|
||||
maxX = fabric.base.array.max(points, 'x'),
|
||||
maxY = fabric.base.array.max(points, 'y');
|
||||
minX = fabric.util.array.min(points, 'x'),
|
||||
minY = fabric.util.array.min(points, 'y'),
|
||||
maxX = fabric.util.array.max(points, 'x'),
|
||||
maxY = fabric.util.array.max(points, 'y');
|
||||
|
||||
this.width = maxX - minX;
|
||||
this.height = maxY - minY;
|
||||
|
|
@ -5977,7 +5971,7 @@ fabric.base.animate = animate;
|
|||
* @return {Object} object representation of an instance
|
||||
*/
|
||||
toObject: function() {
|
||||
return fabric.base.object.extend(this.callSuper('toObject'), {
|
||||
return fabric.util.object.extend(this.callSuper('toObject'), {
|
||||
points: this.points.concat()
|
||||
});
|
||||
},
|
||||
|
|
@ -6029,7 +6023,7 @@ fabric.base.animate = animate;
|
|||
var points = fabric.parsePointsAttribute(element.getAttribute('points')),
|
||||
parsedAttributes = fabric.parseAttributes(element, fabric.Polygon.ATTRIBUTE_NAMES);
|
||||
|
||||
return new fabric.Polygon(points, fabric.base.object.extend(parsedAttributes, options));
|
||||
return new fabric.Polygon(points, fabric.util.object.extend(parsedAttributes, options));
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -6057,7 +6051,7 @@ fabric.base.animate = animate;
|
|||
return;
|
||||
}
|
||||
|
||||
fabric.Path = fabric.base.createClass(fabric.Object, {
|
||||
fabric.Path = fabric.util.createClass(fabric.Object, {
|
||||
|
||||
type: 'path',
|
||||
|
||||
|
|
@ -6105,7 +6099,7 @@ fabric.base.animate = animate;
|
|||
this.path = this._parsePath();
|
||||
|
||||
if (!isWidthSet || !isHeightSet) {
|
||||
fabric.base.object.extend(this, this._parseDimensions());
|
||||
fabric.util.object.extend(this, this._parseDimensions());
|
||||
if (isWidthSet) {
|
||||
this.width = this.options.width;
|
||||
}
|
||||
|
|
@ -6354,7 +6348,7 @@ fabric.base.animate = animate;
|
|||
* @return {Object}
|
||||
*/
|
||||
toObject: function() {
|
||||
var o = fabric.base.object.extend(this.callSuper('toObject'), {
|
||||
var o = fabric.util.object.extend(this.callSuper('toObject'), {
|
||||
path: this.path
|
||||
});
|
||||
if (this.sourcePath) {
|
||||
|
|
@ -6458,15 +6452,15 @@ fabric.base.animate = animate;
|
|||
|
||||
}, this);
|
||||
|
||||
var minX = fabric.base.array.min(aX),
|
||||
minY = fabric.base.array.min(aY),
|
||||
var minX = fabric.util.array.min(aX),
|
||||
minY = fabric.util.array.min(aY),
|
||||
deltaX = deltaY = 0;
|
||||
|
||||
var o = {
|
||||
top: minY - deltaY,
|
||||
left: minX - deltaX,
|
||||
bottom: fabric.base.array.max(aY) - deltaY,
|
||||
right: fabric.base.array.max(aX) - deltaX
|
||||
bottom: fabric.util.array.max(aY) - deltaY,
|
||||
right: fabric.util.array.max(aX) - deltaX
|
||||
};
|
||||
|
||||
o.width = o.right - o.left;
|
||||
|
|
@ -6499,7 +6493,7 @@ fabric.base.animate = animate;
|
|||
var parsedAttributes = fabric.parseAttributes(element, ATTRIBUTE_NAMES),
|
||||
path = parsedAttributes.d;
|
||||
delete parsedAttributes.d;
|
||||
return new fabric.Path(path, fabric.base.object.extend(parsedAttributes, options));
|
||||
return new fabric.Path(path, fabric.util.object.extend(parsedAttributes, options));
|
||||
}
|
||||
})();
|
||||
|
||||
|
|
@ -6512,7 +6506,7 @@ fabric.base.animate = animate;
|
|||
return;
|
||||
}
|
||||
|
||||
fabric.PathGroup = fabric.base.createClass(fabric.Path, {
|
||||
fabric.PathGroup = fabric.util.createClass(fabric.Path, {
|
||||
|
||||
type: 'path-group',
|
||||
forceFillOverwrite: false,
|
||||
|
|
@ -6606,8 +6600,8 @@ fabric.base.animate = animate;
|
|||
*/
|
||||
toObject: function() {
|
||||
var _super = fabric.Object.prototype.toObject;
|
||||
return fabric.base.object.extend(_super.call(this), {
|
||||
paths: fabric.base.array.invoke(this.getObjects(), 'clone'),
|
||||
return fabric.util.object.extend(_super.call(this), {
|
||||
paths: fabric.util.array.invoke(this.getObjects(), 'clone'),
|
||||
sourcePath: this.sourcePath
|
||||
});
|
||||
},
|
||||
|
|
@ -6712,7 +6706,7 @@ fabric.base.animate = animate;
|
|||
return;
|
||||
}
|
||||
|
||||
fabric.Group = fabric.base.createClass(fabric.Object, {
|
||||
fabric.Group = fabric.util.createClass(fabric.Object, {
|
||||
|
||||
/**
|
||||
* @property type
|
||||
|
|
@ -6734,7 +6728,7 @@ fabric.base.animate = animate;
|
|||
this._updateObjectsCoords();
|
||||
|
||||
if (options) {
|
||||
fabric.base.object.extend(this, options);
|
||||
fabric.util.object.extend(this, options);
|
||||
}
|
||||
this._setOpacityIfSame();
|
||||
|
||||
|
|
@ -6867,8 +6861,8 @@ fabric.base.animate = animate;
|
|||
* @return {Object} object representation of an instance
|
||||
*/
|
||||
toObject: function() {
|
||||
return fabric.base.object.extend(this.callSuper('toObject'), {
|
||||
objects: fabric.base.array.invoke(this.objects, 'clone')
|
||||
return fabric.util.object.extend(this.callSuper('toObject'), {
|
||||
objects: fabric.util.array.invoke(this.objects, 'clone')
|
||||
});
|
||||
},
|
||||
|
||||
|
|
@ -7079,10 +7073,10 @@ fabric.base.animate = animate;
|
|||
}
|
||||
};
|
||||
|
||||
minX = fabric.base.array.min(aX);
|
||||
maxX = fabric.base.array.max(aX);
|
||||
minY = fabric.base.array.min(aY);
|
||||
maxY = fabric.base.array.max(aY);
|
||||
minX = fabric.util.array.min(aX);
|
||||
maxX = fabric.util.array.max(aX);
|
||||
minY = fabric.util.array.min(aY);
|
||||
maxY = fabric.util.array.max(aY);
|
||||
|
||||
width = maxX - minX;
|
||||
height = maxY - minY;
|
||||
|
|
@ -7146,7 +7140,7 @@ fabric.base.animate = animate;
|
|||
return;
|
||||
}
|
||||
|
||||
fabric.Text = fabric.base.createClass(fabric.Object, {
|
||||
fabric.Text = fabric.util.createClass(fabric.Object, {
|
||||
|
||||
options: {
|
||||
top: 10,
|
||||
|
|
@ -7164,7 +7158,7 @@ fabric.base.animate = animate;
|
|||
this.initStateProperties();
|
||||
this.text = text;
|
||||
this.setOptions(options);
|
||||
fabric.base.object.extend(this, this.options);
|
||||
fabric.util.object.extend(this, this.options);
|
||||
this.theta = this.angle * (Math.PI/180);
|
||||
this.width = this.getWidth();
|
||||
this.setCoords();
|
||||
|
|
@ -7238,7 +7232,7 @@ fabric.base.animate = animate;
|
|||
* @return {Object} object representation of an instance
|
||||
*/
|
||||
toObject: function() {
|
||||
return fabric.base.object.extend(this.callSuper('toObject'), {
|
||||
return fabric.util.object.extend(this.callSuper('toObject'), {
|
||||
text: this.text,
|
||||
fontsize: this.fontsize,
|
||||
fontweight: this.fontweight,
|
||||
|
|
@ -7305,7 +7299,7 @@ fabric.base.animate = animate;
|
|||
* @return {fabric.Text} an instance
|
||||
*/
|
||||
fabric.Text.fromObject = function(object) {
|
||||
return new fabric.Text(object.text, fabric.base.object.clone(object));
|
||||
return new fabric.Text(object.text, fabric.util.object.clone(object));
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -7337,7 +7331,7 @@ fabric.base.animate = animate;
|
|||
}
|
||||
|
||||
|
||||
fabric.Image = fabric.base.createClass(fabric.Object, {
|
||||
fabric.Image = fabric.util.createClass(fabric.Object, {
|
||||
|
||||
maxwidth: null,
|
||||
maxheight: null,
|
||||
|
|
@ -7460,7 +7454,7 @@ fabric.base.animate = animate;
|
|||
* @return {Object} object representation of an instance
|
||||
*/
|
||||
toObject: function() {
|
||||
return fabric.base.object.extend(this.callSuper('toObject'), {
|
||||
return fabric.util.object.extend(this.callSuper('toObject'), {
|
||||
src: this.getSrc()
|
||||
});
|
||||
},
|
||||
|
|
@ -7570,8 +7564,8 @@ fabric.base.animate = animate;
|
|||
* @param {HTMLImageElement|String} el The element representing the image
|
||||
*/
|
||||
_initElement: function(element) {
|
||||
this.setElement(fabric.base.getById(element));
|
||||
fabric.base.addClass(this.getElement(), fabric.Image.CSS_CANVAS);
|
||||
this.setElement(fabric.util.getById(element));
|
||||
fabric.util.addClass(this.getElement(), fabric.Image.CSS_CANVAS);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
2
dist/all.min.js
vendored
2
dist/all.min.js
vendored
File diff suppressed because one or more lines are too long
45
fabric.js
45
fabric.js
|
|
@ -1,36 +1,37 @@
|
|||
/*! Fabric.js Copyright 2010, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */
|
||||
|
||||
if (typeof console == 'undefined') {
|
||||
var console = { log: function() { }, warn: function() { } };
|
||||
var console = {
|
||||
log: function() { },
|
||||
warn: function() { }
|
||||
};
|
||||
}
|
||||
|
||||
//= require "lib/json2"
|
||||
|
||||
//= require "src/canvas_base"
|
||||
//= require "src/util"
|
||||
//= require "src/parser"
|
||||
|
||||
//= require "src/point.class"
|
||||
//= require "src/intersection.class"
|
||||
|
||||
//= require "src/canvas_util"
|
||||
//= require "src/canvas_parser"
|
||||
//= require "src/color.class"
|
||||
|
||||
//= require "src/canvas_point.class"
|
||||
//= require "src/canvas_intersection.class"
|
||||
//= require "src/element.class"
|
||||
|
||||
//= require "src/canvas_color.class"
|
||||
//= require "src/object.class"
|
||||
//= require "src/line.class"
|
||||
//= require "src/circle.class"
|
||||
//= require "src/ellipse.class"
|
||||
//= require "src/rect.class"
|
||||
//= require "src/polyline.class"
|
||||
//= require "src/polygon.class"
|
||||
|
||||
//= require "src/canvas_element.class"
|
||||
//= require "src/path.class"
|
||||
//= require "src/path_group.class"
|
||||
|
||||
//= require "src/canvas_object.class"
|
||||
//= require "src/canvas_line.class"
|
||||
//= require "src/canvas_circle.class"
|
||||
//= require "src/canvas_ellipse.class"
|
||||
//= require "src/canvas_rect.class"
|
||||
//= require "src/canvas_polyline.class"
|
||||
//= require "src/canvas_polygon.class"
|
||||
//= require "src/group.class"
|
||||
|
||||
//= require "src/canvas_path.class"
|
||||
//= require "src/canvas_path_group.class"
|
||||
//= require "src/text.class"
|
||||
|
||||
//= require "src/canvas_group.class"
|
||||
|
||||
//= require "src/canvas_text.class"
|
||||
|
||||
//= require "src/canvas_image.class"
|
||||
//= require "src/image.class"
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
(function (global) {
|
||||
|
||||
var fabric = this.fabric || (this.fabric = { });
|
||||
fabric.base = { };
|
||||
|
||||
var slice = Array.prototype.slice;
|
||||
|
||||
//= require "canvas_base/lang_array"
|
||||
//= require "canvas_base/lang_object"
|
||||
//= require "canvas_base/lang_string"
|
||||
//= require "canvas_base/lang_function"
|
||||
|
||||
//= require "canvas_base/lang_class"
|
||||
|
||||
//= require "canvas_base/dom_event"
|
||||
//= require "canvas_base/dom_style"
|
||||
//= require "canvas_base/dom_misc"
|
||||
|
||||
//= require "canvas_base/dom_request"
|
||||
|
||||
})(this);
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
//= require "canvas_object.class"
|
||||
//= require "object.class"
|
||||
|
||||
(function() {
|
||||
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
return;
|
||||
}
|
||||
|
||||
fabric.Circle = fabric.base.createClass(fabric.Object, /** @lends fabric.Circle.prototype */ {
|
||||
fabric.Circle = fabric.util.createClass(fabric.Object, /** @lends fabric.Circle.prototype */ {
|
||||
|
||||
/**
|
||||
* @field
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
* @return {Object} object representation of an instance
|
||||
*/
|
||||
toObject: function() {
|
||||
return fabric.base.object.extend(this.callSuper('toObject'), {
|
||||
return fabric.util.object.extend(this.callSuper('toObject'), {
|
||||
radius: this.get('radius')
|
||||
});
|
||||
},
|
||||
|
|
@ -89,7 +89,7 @@
|
|||
if (!isValidRadius(parsedAttributes)) {
|
||||
throw Error('value of `r` attribute is required and can not be negative');
|
||||
}
|
||||
return new fabric.Circle(fabric.base.object.extend(parsedAttributes, options));
|
||||
return new fabric.Circle(fabric.util.object.extend(parsedAttributes, options));
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
STROKE_OFFSET = 0.5,
|
||||
FX_TRANSITION = 'decel',
|
||||
|
||||
getPointer = fabric.base.getPointer,
|
||||
getPointer = fabric.util.getPointer,
|
||||
|
||||
cursorMap = {
|
||||
'tr': 'ne-resize',
|
||||
|
|
@ -182,7 +182,7 @@
|
|||
this.calcOffset();
|
||||
};
|
||||
|
||||
fabric.base.object.extend(fabric.Element.prototype, {
|
||||
fabric.util.object.extend(fabric.Element.prototype, {
|
||||
|
||||
selectionColor: 'rgba(100,100,255,0.3)', // blue
|
||||
selectionBorderColor: 'rgba(255,255,255,0.3)',
|
||||
|
|
@ -207,7 +207,7 @@
|
|||
* @chainable
|
||||
*/
|
||||
calcOffset: function () {
|
||||
this._offset = fabric.base.getElementOffset(this.getElement());
|
||||
this._offset = fabric.util.getElementOffset(this.getElement());
|
||||
return this;
|
||||
},
|
||||
|
||||
|
|
@ -244,7 +244,7 @@
|
|||
*
|
||||
*/
|
||||
_initElement: function (canvasEl) {
|
||||
var el = fabric.base.getById(canvasEl);
|
||||
var el = fabric.util.getById(canvasEl);
|
||||
this._oElement = el || document.createElement('canvas');
|
||||
|
||||
if (typeof this._oElement.getContext === 'undefined') {
|
||||
|
|
@ -269,12 +269,12 @@
|
|||
* @method _initWrapperElement
|
||||
*/
|
||||
_initWrapperElement: function (width, height) {
|
||||
var wrapper = fabric.base.wrapElement(this.getElement(), 'div', { className: 'canvas_container' });
|
||||
fabric.base.setStyle(wrapper, {
|
||||
var wrapper = fabric.util.wrapElement(this.getElement(), 'div', { className: 'canvas_container' });
|
||||
fabric.util.setStyle(wrapper, {
|
||||
width: width + 'px',
|
||||
height: height + 'px'
|
||||
});
|
||||
fabric.base.makeElementUnselectable(wrapper);
|
||||
fabric.util.makeElementUnselectable(wrapper);
|
||||
this.wrapper = wrapper;
|
||||
},
|
||||
|
||||
|
|
@ -283,7 +283,7 @@
|
|||
* @method _setElementStyle
|
||||
*/
|
||||
_setElementStyle: function (width, height) {
|
||||
fabric.base.setStyle(this.getElement(), {
|
||||
fabric.util.setStyle(this.getElement(), {
|
||||
position: 'absolute',
|
||||
width: width + 'px',
|
||||
height: height + 'px',
|
||||
|
|
@ -300,7 +300,7 @@
|
|||
* See configuration documentation for more details.
|
||||
*/
|
||||
_initConfig: function (oConfig) {
|
||||
fabric.base.object.extend(this._oConfig, oConfig || { });
|
||||
fabric.util.object.extend(this._oConfig, oConfig || { });
|
||||
|
||||
this._oConfig.width = parseInt(this._oElement.width, 10) || 0;
|
||||
this._oConfig.height = parseInt(this._oElement.height, 10) || 0;
|
||||
|
|
@ -324,10 +324,10 @@
|
|||
this._onMouseMove = function (e){ _this.__onMouseMove(e); };
|
||||
this._onResize = function (e) { _this.calcOffset() };
|
||||
|
||||
fabric.base.addListener(this._oElement, 'mousedown', this._onMouseDown);
|
||||
fabric.base.addListener(document, 'mousemove', this._onMouseMove);
|
||||
fabric.base.addListener(document, 'mouseup', this._onMouseUp);
|
||||
fabric.base.addListener(window, 'resize', this._onResize);
|
||||
fabric.util.addListener(this._oElement, 'mousedown', this._onMouseDown);
|
||||
fabric.util.addListener(document, 'mousemove', this._onMouseMove);
|
||||
fabric.util.addListener(document, 'mouseup', this._onMouseUp);
|
||||
fabric.util.addListener(window, 'resize', this._onResize);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -361,7 +361,7 @@
|
|||
// if that didn't work, throw error
|
||||
throw CANVAS_INIT_ERROR;
|
||||
}
|
||||
fabric.base.makeElementUnselectable(oContainer);
|
||||
fabric.util.makeElementUnselectable(oContainer);
|
||||
return oContainer;
|
||||
},
|
||||
|
||||
|
|
@ -476,7 +476,7 @@
|
|||
target = transform.target;
|
||||
|
||||
if (target.__scaling) {
|
||||
fabric.base.fireEvent('object:scaled', { target: target });
|
||||
fabric.util.fireEvent('object:scaled', { target: target });
|
||||
target.__scaling = false;
|
||||
}
|
||||
|
||||
|
|
@ -488,7 +488,7 @@
|
|||
// only fire :modified event if target coordinates were changed during mousedown-mouseup
|
||||
if (target.hasStateChanged()) {
|
||||
target.isMoving = false;
|
||||
fabric.base.fireEvent('object:modified', { target: target });
|
||||
fabric.util.fireEvent('object:modified', { target: target });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -502,7 +502,7 @@
|
|||
if (activeGroup) {
|
||||
if (activeGroup.hasStateChanged() &&
|
||||
activeGroup.containsPoint(this.getPointer(e))) {
|
||||
fabric.base.fireEvent('group:modified', { target: activeGroup });
|
||||
fabric.util.fireEvent('group:modified', { target: activeGroup });
|
||||
}
|
||||
activeGroup.setObjectsCoords();
|
||||
activeGroup.set('isMoving', false);
|
||||
|
|
@ -609,15 +609,15 @@
|
|||
deactivateAllWithDispatch: function () {
|
||||
var activeGroup = this.getActiveGroup();
|
||||
if (activeGroup) {
|
||||
fabric.base.fireEvent('before:group:destroyed', {
|
||||
fabric.util.fireEvent('before:group:destroyed', {
|
||||
target: activeGroup
|
||||
});
|
||||
}
|
||||
this.deactivateAll();
|
||||
if (activeGroup) {
|
||||
fabric.base.fireEvent('after:group:destroyed');
|
||||
fabric.util.fireEvent('after:group:destroyed');
|
||||
}
|
||||
fabric.base.fireEvent('selection:cleared');
|
||||
fabric.util.fireEvent('selection:cleared');
|
||||
return this;
|
||||
},
|
||||
|
||||
|
|
@ -681,7 +681,7 @@
|
|||
else {
|
||||
activeGroup.add(target);
|
||||
}
|
||||
fabric.base.fireEvent('group:selected', { target: activeGroup });
|
||||
fabric.util.fireEvent('group:selected', { target: activeGroup });
|
||||
activeGroup.setActive(true);
|
||||
}
|
||||
else {
|
||||
|
|
@ -948,7 +948,7 @@
|
|||
// do not create group for 1 element only
|
||||
if (group.length === 1) {
|
||||
this.setActiveObject(group[0]);
|
||||
fabric.base.fireEvent('object:selected', {
|
||||
fabric.util.fireEvent('object:selected', {
|
||||
target: group[0]
|
||||
});
|
||||
}
|
||||
|
|
@ -956,7 +956,7 @@
|
|||
var group = new fabric.Group(group);
|
||||
this.setActiveGroup(group);
|
||||
group.saveCoords();
|
||||
fabric.base.fireEvent('group:selected', { target: group });
|
||||
fabric.util.fireEvent('group:selected', { target: group });
|
||||
}
|
||||
this.renderAll();
|
||||
},
|
||||
|
|
@ -1503,7 +1503,7 @@
|
|||
switch (o.type) {
|
||||
case 'image':
|
||||
case 'font':
|
||||
fabric[fabric.base.string.capitalize(o.type)].fromObject(o, function (o) {
|
||||
fabric[fabric.util.string.capitalize(o.type)].fromObject(o, function (o) {
|
||||
_this.add(o);
|
||||
if (++numLoadedImages === numTotalImages) {
|
||||
if (callback) callback();
|
||||
|
|
@ -1511,7 +1511,7 @@
|
|||
});
|
||||
break;
|
||||
default:
|
||||
var klass = fabric[fabric.base.string.camelize(fabric.base.string.capitalize(o.type))];
|
||||
var klass = fabric[fabric.util.string.camelize(fabric.util.string.capitalize(o.type))];
|
||||
if (klass && klass.fromObject) {
|
||||
_this.add(klass.fromObject(o));
|
||||
}
|
||||
|
|
@ -1585,7 +1585,7 @@
|
|||
_this.loadImageFromURL(path, function (image) {
|
||||
image.setSourcePath(path);
|
||||
|
||||
fabric.base.object.extend(image, obj);
|
||||
fabric.util.object.extend(image, obj);
|
||||
image.setAngle(obj.angle);
|
||||
|
||||
onObjectLoaded(image, index);
|
||||
|
|
@ -1608,7 +1608,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
fabric.base.getScript(path, onscriptload);
|
||||
fabric.util.getScript(path, onscriptload);
|
||||
}
|
||||
else {
|
||||
_this.loadSVGFromURL(path, function (elements, options) {
|
||||
|
|
@ -1623,7 +1623,7 @@
|
|||
// copy parameters from serialied json to object (left, top, scaleX, scaleY, etc.)
|
||||
// skip this step if an object is a PathGroup, since we already passed it options object before
|
||||
if (!(object instanceof fabric.PathGroup)) {
|
||||
fabric.base.object.extend(object, obj);
|
||||
fabric.util.object.extend(object, obj);
|
||||
if (typeof obj.angle !== 'undefined') {
|
||||
object.setAngle(obj.angle);
|
||||
}
|
||||
|
|
@ -1880,7 +1880,7 @@
|
|||
|
||||
this.renderAll();
|
||||
|
||||
fabric.base.fireEvent('object:selected', { target: object });
|
||||
fabric.util.fireEvent('object:selected', { target: object });
|
||||
return this;
|
||||
},
|
||||
|
||||
|
|
@ -1987,10 +1987,10 @@
|
|||
*/
|
||||
dispose: function () {
|
||||
this.clear();
|
||||
fabric.base.removeListener(this.getElement(), 'mousedown', this._onMouseDown);
|
||||
fabric.base.removeListener(document, 'mouseup', this._onMouseUp);
|
||||
fabric.base.removeListener(document, 'mousemove', this._onMouseMove);
|
||||
fabric.base.removeListener(window, 'resize', this._onResize);
|
||||
fabric.util.removeListener(this.getElement(), 'mousedown', this._onMouseDown);
|
||||
fabric.util.removeListener(document, 'mouseup', this._onMouseUp);
|
||||
fabric.util.removeListener(document, 'mousemove', this._onMouseMove);
|
||||
fabric.util.removeListener(window, 'resize', this._onResize);
|
||||
return this;
|
||||
},
|
||||
|
||||
|
|
@ -2059,7 +2059,7 @@
|
|||
'{ objects: ' + this.getObjects().length + ' }>';
|
||||
};
|
||||
|
||||
fabric.base.object.extend(fabric.Element, {
|
||||
fabric.util.object.extend(fabric.Element, {
|
||||
|
||||
/**
|
||||
* @property EMPTY_JSON
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
//= require "canvas_object.class"
|
||||
//= require "object.class"
|
||||
|
||||
(function(){
|
||||
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
return;
|
||||
}
|
||||
|
||||
fabric.Ellipse = fabric.base.createClass(fabric.Object, {
|
||||
fabric.Ellipse = fabric.util.createClass(fabric.Object, {
|
||||
|
||||
type: 'ellipse',
|
||||
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
* @return {Object} object representation of an instance
|
||||
*/
|
||||
toObject: function() {
|
||||
return fabric.base.object.extend(this.callSuper('toObject'), {
|
||||
return fabric.util.object.extend(this.callSuper('toObject'), {
|
||||
rx: this.get('rx'),
|
||||
ry: this.get('ry')
|
||||
})
|
||||
|
|
@ -93,7 +93,7 @@
|
|||
*/
|
||||
fabric.Ellipse.fromElement = function(element, options) {
|
||||
var parsedAttributes = fabric.parseAttributes(element, fabric.Ellipse.ATTRIBUTE_NAMES);
|
||||
return new fabric.Ellipse(fabric.base.object.extend(parsedAttributes, options));
|
||||
return new fabric.Ellipse(fabric.util.object.extend(parsedAttributes, options));
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
//= require "canvas_object.class"
|
||||
//= require "object.class"
|
||||
|
||||
(function(){
|
||||
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
return;
|
||||
}
|
||||
|
||||
fabric.Group = fabric.base.createClass(fabric.Object, {
|
||||
fabric.Group = fabric.util.createClass(fabric.Object, {
|
||||
|
||||
/**
|
||||
* @property type
|
||||
|
|
@ -29,7 +29,7 @@
|
|||
this._updateObjectsCoords();
|
||||
|
||||
if (options) {
|
||||
fabric.base.object.extend(this, options);
|
||||
fabric.util.object.extend(this, options);
|
||||
}
|
||||
this._setOpacityIfSame();
|
||||
|
||||
|
|
@ -165,8 +165,8 @@
|
|||
* @return {Object} object representation of an instance
|
||||
*/
|
||||
toObject: function() {
|
||||
return fabric.base.object.extend(this.callSuper('toObject'), {
|
||||
objects: fabric.base.array.invoke(this.objects, 'clone')
|
||||
return fabric.util.object.extend(this.callSuper('toObject'), {
|
||||
objects: fabric.util.array.invoke(this.objects, 'clone')
|
||||
});
|
||||
},
|
||||
|
||||
|
|
@ -377,10 +377,10 @@
|
|||
}
|
||||
};
|
||||
|
||||
minX = fabric.base.array.min(aX);
|
||||
maxX = fabric.base.array.max(aX);
|
||||
minY = fabric.base.array.min(aY);
|
||||
maxY = fabric.base.array.max(aY);
|
||||
minX = fabric.util.array.min(aX);
|
||||
maxX = fabric.util.array.max(aX);
|
||||
minY = fabric.util.array.min(aY);
|
||||
maxY = fabric.util.array.max(aY);
|
||||
|
||||
width = maxX - minX;
|
||||
height = maxY - minY;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
//= require "canvas_object.class"
|
||||
//= require "object.class"
|
||||
|
||||
(function() {
|
||||
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
}
|
||||
|
||||
|
||||
fabric.Image = fabric.base.createClass(fabric.Object, {
|
||||
fabric.Image = fabric.util.createClass(fabric.Object, {
|
||||
|
||||
maxwidth: null,
|
||||
maxheight: null,
|
||||
|
|
@ -145,7 +145,7 @@
|
|||
* @return {Object} object representation of an instance
|
||||
*/
|
||||
toObject: function() {
|
||||
return fabric.base.object.extend(this.callSuper('toObject'), {
|
||||
return fabric.util.object.extend(this.callSuper('toObject'), {
|
||||
src: this.getSrc()
|
||||
});
|
||||
},
|
||||
|
|
@ -255,8 +255,8 @@
|
|||
* @param {HTMLImageElement|String} el The element representing the image
|
||||
*/
|
||||
_initElement: function(element) {
|
||||
this.setElement(fabric.base.getById(element));
|
||||
fabric.base.addClass(this.getElement(), fabric.Image.CSS_CANVAS);
|
||||
this.setElement(fabric.util.getById(element));
|
||||
fabric.util.addClass(this.getElement(), fabric.Image.CSS_CANVAS);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
//= require 'canvas_point.class'
|
||||
//= require 'point.class'
|
||||
|
||||
(function() {
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
//= require "canvas_object.class"
|
||||
//= require "object.class"
|
||||
|
||||
(function(){
|
||||
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
return;
|
||||
}
|
||||
|
||||
fabric.Line = fabric.base.createClass(fabric.Object, {
|
||||
fabric.Line = fabric.util.createClass(fabric.Object, {
|
||||
|
||||
type: 'line',
|
||||
|
||||
|
|
@ -62,7 +62,7 @@
|
|||
* @return {Object}
|
||||
*/
|
||||
toObject: function() {
|
||||
return fabric.base.object.extend(this.callSuper('toObject'), {
|
||||
return fabric.util.object.extend(this.callSuper('toObject'), {
|
||||
x1: this.get('x1'),
|
||||
y1: this.get('y1'),
|
||||
x2: this.get('x2'),
|
||||
|
|
@ -89,7 +89,7 @@
|
|||
parsedAttributes.x2 || 0,
|
||||
parsedAttributes.y2 || 0
|
||||
];
|
||||
return new fabric.Line(points, fabric.base.object.extend(parsedAttributes, options));
|
||||
return new fabric.Line(points, fabric.util.object.extend(parsedAttributes, options));
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
* @class Object
|
||||
* @memberOf Canvas
|
||||
*/
|
||||
fabric.Object = fabric.base.createClass({
|
||||
fabric.Object = fabric.util.createClass({
|
||||
|
||||
type: 'object',
|
||||
|
||||
|
|
@ -107,7 +107,7 @@
|
|||
|
||||
setOptions: function(options) {
|
||||
// this.constructor.superclass.prototype.options -> this.options -> options
|
||||
this.options = fabric.base.object.extend(this._getOptions(), options);
|
||||
this.options = fabric.util.object.extend(this._getOptions(), options);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -115,7 +115,7 @@
|
|||
* @method _getOptions
|
||||
*/
|
||||
_getOptions: function() {
|
||||
return fabric.base.object.extend(fabric.base.object.clone(this._getSuperOptions()), this.options);
|
||||
return fabric.util.object.extend(fabric.util.object.clone(this._getSuperOptions()), this.options);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -248,7 +248,7 @@
|
|||
* @return {String}
|
||||
*/
|
||||
toString: function() {
|
||||
return "#<fabric." + fabric.base.string.capitalize(this.type) + ">";
|
||||
return "#<fabric." + fabric.util.string.capitalize(this.type) + ">";
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -672,7 +672,7 @@
|
|||
el.width = this.getWidth();
|
||||
el.height = this.getHeight();
|
||||
|
||||
fabric.base.wrapElement(el, 'div');
|
||||
fabric.util.wrapElement(el, 'div');
|
||||
|
||||
var canvas = new fabric.Element(el);
|
||||
canvas.backgroundColor = 'transparent';
|
||||
|
|
@ -799,7 +799,7 @@
|
|||
* @return {String|Boolean} corner code (tl, tr, bl, br, etc.), or false if nothing is found
|
||||
*/
|
||||
_findTargetCorner: function(e, offset) {
|
||||
var pointer = fabric.base.getPointer(e),
|
||||
var pointer = fabric.util.getPointer(e),
|
||||
ex = pointer.x - offset.left,
|
||||
ey = pointer.y - offset.top,
|
||||
xpoints,
|
||||
|
|
@ -1170,7 +1170,7 @@
|
|||
onChange = callbacks.onChange || empty,
|
||||
_this = this;
|
||||
|
||||
fabric.base.animate({
|
||||
fabric.util.animate({
|
||||
startValue: this.get('angle'),
|
||||
endValue: this._getAngleValueForStraighten(),
|
||||
duration: this.FX_DURATION,
|
||||
|
|
@ -1204,7 +1204,7 @@
|
|||
onChange = callbacks.onChange || empty,
|
||||
_this = this;
|
||||
|
||||
fabric.base.animate({
|
||||
fabric.util.animate({
|
||||
startValue: this.get('opacity'),
|
||||
endValue: 0,
|
||||
duration: this.FX_DURATION,
|
||||
|
|
@ -61,8 +61,8 @@
|
|||
|
||||
// add values parsed from style
|
||||
// TODO (kangax): check the presedence of values from the style attribute
|
||||
ownAttributes = fabric.base.object.extend(fabric.parseStyleAttribute(element), ownAttributes);
|
||||
return fabric.base.object.extend(parentAttributes, ownAttributes);
|
||||
ownAttributes = fabric.util.object.extend(fabric.parseStyleAttribute(element), ownAttributes);
|
||||
return fabric.util.object.extend(parentAttributes, ownAttributes);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -260,7 +260,7 @@
|
|||
function parseElements(elements, options) {
|
||||
// transform svg elements to fabric.Path elements
|
||||
var _elements = elements.map(function(el) {
|
||||
var klass = fabric[fabric.base.string.capitalize(el.tagName)];
|
||||
var klass = fabric[fabric.util.string.capitalize(el.tagName)];
|
||||
if (klass && klass.fromElement) {
|
||||
try {
|
||||
return klass.fromElement(el, options);
|
||||
|
|
@ -313,7 +313,7 @@
|
|||
|
||||
return function(doc, callback) {
|
||||
if (!doc) return;
|
||||
var descendants = fabric.base.toArray(doc.getElementsByTagName('*'));
|
||||
var descendants = fabric.util.toArray(doc.getElementsByTagName('*'));
|
||||
|
||||
var elements = descendants.filter(function(el) {
|
||||
return reAllowedSVGTagNames.test(el.tagName) &&
|
||||
|
|
@ -346,7 +346,7 @@
|
|||
height: height
|
||||
};
|
||||
|
||||
var elements = fabric.parseElements(elements, fabric.base.object.clone(options));
|
||||
var elements = fabric.parseElements(elements, fabric.util.object.clone(options));
|
||||
if (!elements || (elements && !elements.length)) return;
|
||||
|
||||
if (callback) {
|
||||
|
|
@ -355,7 +355,7 @@
|
|||
};
|
||||
})();
|
||||
|
||||
fabric.base.object.extend(fabric, {
|
||||
fabric.util.object.extend(fabric, {
|
||||
parseAttributes: parseAttributes,
|
||||
parseElements: parseElements,
|
||||
parseStyleAttribute: parseStyleAttribute,
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
//= require "canvas_object.class"
|
||||
//= require "object.class"
|
||||
|
||||
(function(){
|
||||
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
}
|
||||
|
||||
// Instance methods
|
||||
fabric.Path = fabric.base.createClass(fabric.Object, {
|
||||
fabric.Path = fabric.util.createClass(fabric.Object, {
|
||||
|
||||
type: 'path',
|
||||
|
||||
|
|
@ -63,7 +63,7 @@
|
|||
this.path = this._parsePath();
|
||||
|
||||
if (!isWidthSet || !isHeightSet) {
|
||||
fabric.base.object.extend(this, this._parseDimensions());
|
||||
fabric.util.object.extend(this, this._parseDimensions());
|
||||
if (isWidthSet) {
|
||||
this.width = this.options.width;
|
||||
}
|
||||
|
|
@ -320,7 +320,7 @@
|
|||
* @return {Object}
|
||||
*/
|
||||
toObject: function() {
|
||||
var o = fabric.base.object.extend(this.callSuper('toObject'), {
|
||||
var o = fabric.util.object.extend(this.callSuper('toObject'), {
|
||||
path: this.path
|
||||
});
|
||||
if (this.sourcePath) {
|
||||
|
|
@ -430,15 +430,15 @@
|
|||
|
||||
}, this);
|
||||
|
||||
var minX = fabric.base.array.min(aX),
|
||||
minY = fabric.base.array.min(aY),
|
||||
var minX = fabric.util.array.min(aX),
|
||||
minY = fabric.util.array.min(aY),
|
||||
deltaX = deltaY = 0;
|
||||
|
||||
var o = {
|
||||
top: minY - deltaY,
|
||||
left: minX - deltaX,
|
||||
bottom: fabric.base.array.max(aY) - deltaY,
|
||||
right: fabric.base.array.max(aX) - deltaX
|
||||
bottom: fabric.util.array.max(aY) - deltaY,
|
||||
right: fabric.util.array.max(aX) - deltaX
|
||||
};
|
||||
|
||||
o.width = o.right - o.left;
|
||||
|
|
@ -471,6 +471,6 @@
|
|||
var parsedAttributes = fabric.parseAttributes(element, ATTRIBUTE_NAMES),
|
||||
path = parsedAttributes.d;
|
||||
delete parsedAttributes.d;
|
||||
return new fabric.Path(path, fabric.base.object.extend(parsedAttributes, options));
|
||||
return new fabric.Path(path, fabric.util.object.extend(parsedAttributes, options));
|
||||
}
|
||||
})();
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
//= require "canvas_path.class"
|
||||
//= require "path.class"
|
||||
|
||||
(function(){
|
||||
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
return;
|
||||
}
|
||||
|
||||
fabric.PathGroup = fabric.base.createClass(fabric.Path, {
|
||||
fabric.PathGroup = fabric.util.createClass(fabric.Path, {
|
||||
|
||||
type: 'path-group',
|
||||
forceFillOverwrite: false,
|
||||
|
|
@ -105,8 +105,8 @@
|
|||
*/
|
||||
toObject: function() {
|
||||
var _super = fabric.Object.prototype.toObject;
|
||||
return fabric.base.object.extend(_super.call(this), {
|
||||
paths: fabric.base.array.invoke(this.getObjects(), 'clone'),
|
||||
return fabric.util.object.extend(_super.call(this), {
|
||||
paths: fabric.util.array.invoke(this.getObjects(), 'clone'),
|
||||
sourcePath: this.sourcePath
|
||||
});
|
||||
},
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
//= require "canvas_object.class"
|
||||
//= require "object.class"
|
||||
|
||||
(function(){
|
||||
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
function byX(p) { return p.x; }
|
||||
function byY(p) { return p.y; }
|
||||
|
||||
fabric.Polygon = fabric.base.createClass(fabric.Object, {
|
||||
fabric.Polygon = fabric.util.createClass(fabric.Object, {
|
||||
|
||||
type: 'polygon',
|
||||
|
||||
|
|
@ -37,10 +37,10 @@
|
|||
_calcDimensions: function() {
|
||||
|
||||
var points = this.points,
|
||||
minX = fabric.base.array.min(points, 'x'),
|
||||
minY = fabric.base.array.min(points, 'y'),
|
||||
maxX = fabric.base.array.max(points, 'x'),
|
||||
maxY = fabric.base.array.max(points, 'y');
|
||||
minX = fabric.util.array.min(points, 'x'),
|
||||
minY = fabric.util.array.min(points, 'y'),
|
||||
maxX = fabric.util.array.max(points, 'x'),
|
||||
maxY = fabric.util.array.max(points, 'y');
|
||||
|
||||
this.width = maxX - minX;
|
||||
this.height = maxY - minY;
|
||||
|
|
@ -67,7 +67,7 @@
|
|||
* @return {Object} object representation of an instance
|
||||
*/
|
||||
toObject: function() {
|
||||
return fabric.base.object.extend(this.callSuper('toObject'), {
|
||||
return fabric.util.object.extend(this.callSuper('toObject'), {
|
||||
points: this.points.concat()
|
||||
});
|
||||
},
|
||||
|
|
@ -120,7 +120,7 @@
|
|||
var points = fabric.parsePointsAttribute(element.getAttribute('points')),
|
||||
parsedAttributes = fabric.parseAttributes(element, fabric.Polygon.ATTRIBUTE_NAMES);
|
||||
|
||||
return new fabric.Polygon(points, fabric.base.object.extend(parsedAttributes, options));
|
||||
return new fabric.Polygon(points, fabric.util.object.extend(parsedAttributes, options));
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
//= require "canvas_object.class"
|
||||
//= require "object.class"
|
||||
|
||||
(function(){
|
||||
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
return;
|
||||
}
|
||||
|
||||
fabric.Polyline = fabric.base.createClass(fabric.Object, {
|
||||
fabric.Polyline = fabric.util.createClass(fabric.Object, {
|
||||
|
||||
type: 'polyline',
|
||||
|
||||
|
|
@ -98,7 +98,7 @@
|
|||
var points = fabric.parsePointsAttribute(element.getAttribute('points')),
|
||||
parsedAttributes = fabric.parseAttributes(element, ATTRIBUTE_NAMES);
|
||||
|
||||
return new fabric.Polyline(points, fabric.base.object.extend(parsedAttributes, options));
|
||||
return new fabric.Polyline(points, fabric.util.object.extend(parsedAttributes, options));
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
//= require "canvas_object.class"
|
||||
//= require "object.class"
|
||||
|
||||
(function(){
|
||||
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
* @class Rect
|
||||
* @extends fabric.Object
|
||||
*/
|
||||
fabric.Rect = fabric.base.createClass(fabric.Object, /** @lends fabric.Rect.prototype */ {
|
||||
fabric.Rect = fabric.util.createClass(fabric.Object, /** @lends fabric.Rect.prototype */ {
|
||||
|
||||
type: 'rect',
|
||||
|
||||
|
|
@ -125,7 +125,7 @@
|
|||
var parsedAttributes = fabric.parseAttributes(element, fabric.Rect.ATTRIBUTE_NAMES);
|
||||
parsedAttributes = _setDefaultLeftTopValues(parsedAttributes);
|
||||
|
||||
var rect = new fabric.Rect(fabric.base.object.extend(options || { }, parsedAttributes));
|
||||
var rect = new fabric.Rect(fabric.util.object.extend(options || { }, parsedAttributes));
|
||||
rect._normalizeLeftTopProperties(parsedAttributes);
|
||||
|
||||
return rect;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
//= require "canvas_object.class"
|
||||
//= require "object.class"
|
||||
|
||||
(function(){
|
||||
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
return;
|
||||
}
|
||||
|
||||
fabric.Text = fabric.base.createClass(fabric.Object, {
|
||||
fabric.Text = fabric.util.createClass(fabric.Object, {
|
||||
|
||||
options: {
|
||||
top: 10,
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
this.initStateProperties();
|
||||
this.text = text;
|
||||
this.setOptions(options);
|
||||
fabric.base.object.extend(this, this.options);
|
||||
fabric.util.object.extend(this, this.options);
|
||||
this.theta = this.angle * (Math.PI/180);
|
||||
this.width = this.getWidth();
|
||||
this.setCoords();
|
||||
|
|
@ -110,7 +110,7 @@
|
|||
* @return {Object} object representation of an instance
|
||||
*/
|
||||
toObject: function() {
|
||||
return fabric.base.object.extend(this.callSuper('toObject'), {
|
||||
return fabric.util.object.extend(this.callSuper('toObject'), {
|
||||
text: this.text,
|
||||
fontsize: this.fontsize,
|
||||
fontweight: this.fontweight,
|
||||
|
|
@ -177,7 +177,7 @@
|
|||
* @return {fabric.Text} an instance
|
||||
*/
|
||||
fabric.Text.fromObject = function(object) {
|
||||
return new fabric.Text(object.text, fabric.base.object.clone(object));
|
||||
return new fabric.Text(object.text, fabric.util.object.clone(object));
|
||||
};
|
||||
|
||||
/**
|
||||
23
src/util.js
Normal file
23
src/util.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
(function (global) {
|
||||
|
||||
var fabric = this.fabric || (this.fabric = { }),
|
||||
slice = Array.prototype.slice;
|
||||
|
||||
fabric.util = { };
|
||||
|
||||
//= require "util/lang_array"
|
||||
//= require "util/lang_object"
|
||||
//= require "util/lang_string"
|
||||
//= require "util/lang_function"
|
||||
|
||||
//= require "util/lang_class"
|
||||
|
||||
//= require "util/dom_event"
|
||||
//= require "util/dom_style"
|
||||
//= require "util/dom_misc"
|
||||
|
||||
//= require "util/dom_request"
|
||||
|
||||
//= require "util/misc"
|
||||
|
||||
})(this);
|
||||
|
|
@ -140,8 +140,8 @@
|
|||
};
|
||||
}
|
||||
|
||||
fabric.base.addListener = addListener;
|
||||
fabric.base.removeListener = removeListener;
|
||||
fabric.util.addListener = addListener;
|
||||
fabric.util.removeListener = removeListener;
|
||||
|
||||
|
||||
var customEventListeners = { };
|
||||
|
|
@ -167,8 +167,8 @@
|
|||
}
|
||||
}
|
||||
|
||||
fabric.base.observeEvent = observeEvent;
|
||||
fabric.base.fireEvent = fireEvent;
|
||||
fabric.util.observeEvent = observeEvent;
|
||||
fabric.util.fireEvent = fireEvent;
|
||||
|
||||
// TODO (kangax): this method needs fixing
|
||||
function getPointer(event) {
|
||||
|
|
@ -193,5 +193,5 @@
|
|||
(docElement.clientTop || 0));
|
||||
}
|
||||
|
||||
fabric.base.getPointer = getPointer;
|
||||
fabric.util.getPointer = getPointer;
|
||||
})(this);
|
||||
|
|
@ -82,7 +82,7 @@ function falseFunction() { return false; };
|
|||
return element;
|
||||
}
|
||||
|
||||
fabric.base.makeElementUnselectable = makeElementUnselectable
|
||||
fabric.util.makeElementUnselectable = makeElementUnselectable
|
||||
})();
|
||||
|
||||
(function(){
|
||||
|
|
@ -115,11 +115,11 @@ function falseFunction() { return false; };
|
|||
callback();
|
||||
}
|
||||
|
||||
fabric.base.getScript = getScript;
|
||||
fabric.util.getScript = getScript;
|
||||
|
||||
var Jaxer = this.Jaxer;
|
||||
if (Jaxer && Jaxer.load) {
|
||||
fabric.base.getScript = getScriptJaxer;
|
||||
fabric.util.getScript = getScriptJaxer;
|
||||
}
|
||||
})();
|
||||
|
||||
|
|
@ -149,10 +149,10 @@ function animate(options) {
|
|||
}, 10);
|
||||
}
|
||||
|
||||
fabric.base.getById = getById;
|
||||
fabric.base.toArray = toArray;
|
||||
fabric.base.makeElement = makeElement;
|
||||
fabric.base.addClass = addClass;
|
||||
fabric.base.wrapElement = wrapElement;
|
||||
fabric.base.getElementOffset = getElementOffset;
|
||||
fabric.base.animate = animate;
|
||||
fabric.util.getById = getById;
|
||||
fabric.util.toArray = toArray;
|
||||
fabric.util.makeElement = makeElement;
|
||||
fabric.util.addClass = addClass;
|
||||
fabric.util.wrapElement = wrapElement;
|
||||
fabric.util.getElementOffset = getElementOffset;
|
||||
fabric.util.animate = animate;
|
||||
|
|
@ -57,5 +57,5 @@
|
|||
return request;
|
||||
};
|
||||
|
||||
fabric.base.request = request;
|
||||
fabric.util.request = request;
|
||||
})();
|
||||
|
|
@ -53,6 +53,6 @@
|
|||
};
|
||||
}
|
||||
|
||||
fabric.base.setStyle = setStyle;
|
||||
fabric.util.setStyle = setStyle;
|
||||
|
||||
})();
|
||||
|
|
@ -154,7 +154,7 @@ function min(array, byProperty) {
|
|||
return result;
|
||||
}
|
||||
|
||||
fabric.base.array = {
|
||||
fabric.util.array = {
|
||||
invoke: invoke,
|
||||
min: min,
|
||||
max: max
|
||||
|
|
@ -59,5 +59,5 @@
|
|||
return klass;
|
||||
}
|
||||
|
||||
fabric.base.createClass = createClass;
|
||||
fabric.util.createClass = createClass;
|
||||
})();
|
||||
|
|
@ -9,7 +9,7 @@ function clone(object) {
|
|||
return extend({ }, object);
|
||||
}
|
||||
|
||||
fabric.base.object = {
|
||||
fabric.util.object = {
|
||||
extend: extend,
|
||||
clone: clone
|
||||
};
|
||||
|
|
@ -14,7 +14,7 @@ function capitalize(string) {
|
|||
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
|
||||
}
|
||||
|
||||
fabric.base.string = {
|
||||
fabric.util.string = {
|
||||
camelize: camelize,
|
||||
capitalize: capitalize
|
||||
};
|
||||
|
|
@ -1,12 +1,5 @@
|
|||
(function(){
|
||||
|
||||
var fabric = this.fabric || (this.fabric = { });
|
||||
|
||||
if (fabric.util) {
|
||||
console.warn('fabric.util is already defined');
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* Removes value from an array.
|
||||
|
|
@ -56,10 +49,8 @@
|
|||
return parseFloat(Number(number).toFixed(fractionDigits));
|
||||
}
|
||||
|
||||
fabric.util = {
|
||||
removeFromArray: removeFromArray,
|
||||
degreesToRadians: degreesToRadians,
|
||||
toFixed: toFixed,
|
||||
getRandomInt: getRandomInt
|
||||
};
|
||||
fabric.util.removeFromArray = removeFromArray;
|
||||
fabric.util.degreesToRadians = degreesToRadians;
|
||||
fabric.util.toFixed = toFixed;
|
||||
fabric.util.getRandomInt = getRandomInt;
|
||||
})();
|
||||
|
|
@ -44,7 +44,7 @@
|
|||
|
||||
circle.set('left', 100).set('top', 200).set('radius', 15);
|
||||
|
||||
var augmentedProperties = fabric.base.object.extend(fabric.base.object.clone(defaultProperties), {
|
||||
var augmentedProperties = fabric.util.object.extend(fabric.util.object.clone(defaultProperties), {
|
||||
left: 100,
|
||||
top: 200,
|
||||
radius: 15
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
function makeRect(options) {
|
||||
var defaultOptions = { width: 10, height: 10 };
|
||||
return new fabric.Rect(fabric.base.object.extend(defaultOptions, options || { }));
|
||||
return new fabric.Rect(fabric.util.object.extend(defaultOptions, options || { }));
|
||||
}
|
||||
|
||||
module('fabric.Element', {
|
||||
|
|
@ -158,7 +158,7 @@
|
|||
test('getPointer', function() {
|
||||
ok(typeof canvas.getPointer == 'function');
|
||||
|
||||
fabric.base.addListener(canvasEl, 'click', function(e) {
|
||||
fabric.util.addListener(canvasEl, 'click', function(e) {
|
||||
var pointer = canvas.getPointer(e);
|
||||
equals(pointer.x, 101, 'pointer.x should be correct');
|
||||
equals(pointer.y, 102, 'pointer.y should be correct');
|
||||
|
|
@ -526,16 +526,16 @@
|
|||
};
|
||||
var target;
|
||||
|
||||
fabric.base.observeEvent('before:group:destroyed', function (e) {
|
||||
fabric.util.observeEvent('before:group:destroyed', function (e) {
|
||||
eventsFired.beforeGroupDestroyed = true;
|
||||
equals(canvas.getActiveGroup(), e.memo.target, 'event should have active group as its `target` property');
|
||||
});
|
||||
|
||||
fabric.base.observeEvent('after:group:destroyed', function(){
|
||||
fabric.util.observeEvent('after:group:destroyed', function(){
|
||||
eventsFired.afterGroupDestroyed = true;
|
||||
});
|
||||
|
||||
fabric.base.observeEvent('selection:cleared', function(){
|
||||
fabric.util.observeEvent('selection:cleared', function(){
|
||||
eventsFired.selectionCleared = true;
|
||||
});
|
||||
|
||||
|
|
@ -647,7 +647,7 @@
|
|||
canvas.add(rect);
|
||||
|
||||
var canvasEl = canvas.getElement(),
|
||||
canvasOffset = fabric.base.getElementOffset(canvasEl);
|
||||
canvasOffset = fabric.util.getElementOffset(canvasEl);
|
||||
|
||||
var eventStub = {
|
||||
pageX: canvasOffset.left + 100,
|
||||
|
|
@ -700,7 +700,7 @@
|
|||
asyncTest('resizeImageToFit', function() {
|
||||
ok(typeof canvas._resizeImageToFit == 'function');
|
||||
|
||||
var imgEl = fabric.base.makeElement('img', { src: '../fixtures/very_large_image.jpg' }),
|
||||
var imgEl = fabric.util.makeElement('img', { src: '../fixtures/very_large_image.jpg' }),
|
||||
ORIGINAL_WIDTH = 3888,
|
||||
ORIGINAL_HEIGHT = 2592;
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
|
||||
ellipse.set('left', 100).set('top', 200).set('rx', 15).set('ry', 25);
|
||||
|
||||
var augmentedProperties = fabric.base.object.extend(fabric.base.object.clone(defaultProperties), {
|
||||
var augmentedProperties = fabric.util.object.extend(fabric.util.object.clone(defaultProperties), {
|
||||
left: 100,
|
||||
top: 200,
|
||||
rx: 15,
|
||||
|
|
|
|||
|
|
@ -271,10 +271,10 @@
|
|||
ok(typeof group.setActive == 'function');
|
||||
|
||||
group.setActive(false);
|
||||
same([false, false], fabric.base.array.invoke(group.getObjects(), 'isActive'));
|
||||
same([false, false], fabric.util.array.invoke(group.getObjects(), 'isActive'));
|
||||
|
||||
group.setActive(true);
|
||||
same([true, true], fabric.base.array.invoke(group.getObjects(), 'isActive'));
|
||||
same([true, true], fabric.util.array.invoke(group.getObjects(), 'isActive'));
|
||||
});
|
||||
|
||||
test('fromObject', function() {
|
||||
|
|
|
|||
|
|
@ -87,16 +87,16 @@
|
|||
ok(fabric.parseElements);
|
||||
|
||||
function getOptions(options) {
|
||||
return fabric.base.object.extend(fabric.base.object.clone({
|
||||
return fabric.util.object.extend(fabric.util.object.clone({
|
||||
left: 10, top: 20, width: 30, height: 40
|
||||
}), options || { });
|
||||
}
|
||||
|
||||
var elements = [
|
||||
fabric.base.makeElement('rect', getOptions()),
|
||||
fabric.base.makeElement('circle', getOptions({ r: 14 })),
|
||||
fabric.base.makeElement('path', getOptions({ d: 'M 100 100 L 300 100 L 200 300 z' })),
|
||||
fabric.base.makeElement('inexistent', getOptions())
|
||||
fabric.util.makeElement('rect', getOptions()),
|
||||
fabric.util.makeElement('circle', getOptions({ r: 14 })),
|
||||
fabric.util.makeElement('path', getOptions({ d: 'M 100 100 L 300 100 L 200 300 z' })),
|
||||
fabric.util.makeElement('inexistent', getOptions())
|
||||
];
|
||||
|
||||
var parsedElements, error;
|
||||
|
|
@ -206,7 +206,7 @@
|
|||
ok(fabric.parseSVGDocument);
|
||||
|
||||
var data;
|
||||
fabric.base.request('../fixtures/path.svg', {
|
||||
fabric.util.request('../fixtures/path.svg', {
|
||||
method: 'get',
|
||||
onComplete: function(resp) {
|
||||
var doc = resp.responseXML;
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@
|
|||
|
||||
var src = 'http://example.com/';
|
||||
path.setSourcePath(src);
|
||||
same(fabric.base.object.extend(fabric.base.object.clone(REFERENCE_PATH_OBJECT), {
|
||||
same(fabric.util.object.extend(fabric.util.object.clone(REFERENCE_PATH_OBJECT), {
|
||||
path: src
|
||||
}), path.toDatalessObject());
|
||||
});
|
||||
|
|
@ -111,7 +111,7 @@
|
|||
var path = fabric.Path.fromElement(elPath);
|
||||
ok(path instanceof fabric.Path);
|
||||
|
||||
same(fabric.base.object.extend(REFERENCE_PATH_OBJECT, {
|
||||
same(fabric.util.object.extend(REFERENCE_PATH_OBJECT, {
|
||||
transformMatrix: [2, 0, 0, 2, 0, 0]
|
||||
}), path.toObject());
|
||||
|
||||
|
|
|
|||
|
|
@ -66,10 +66,10 @@
|
|||
ok(typeof pathGroup.toObject == 'function');
|
||||
var object = pathGroup.toObject();
|
||||
|
||||
/*same(fabric.base.object.extend(fabric.base.object.clone(REFERENCE_PATH_GROUP_OBJECT), {
|
||||
/*same(fabric.util.object.extend(fabric.util.object.clone(REFERENCE_PATH_GROUP_OBJECT), {
|
||||
paths: object.paths
|
||||
}), object);
|
||||
console.log(fabric.base.object.extend(fabric.base.object.clone(REFERENCE_PATH_GROUP_OBJECT), {
|
||||
console.log(fabric.util.object.extend(fabric.util.object.clone(REFERENCE_PATH_GROUP_OBJECT), {
|
||||
paths: object.paths
|
||||
}), object);*/
|
||||
});
|
||||
|
|
@ -99,7 +99,7 @@
|
|||
ok(typeof pathGroup.toDatalessObject == 'function');
|
||||
|
||||
pathGroup.setSourcePath('http://example.com/');
|
||||
var expectedObject = fabric.base.object.extend(fabric.base.object.clone(REFERENCE_PATH_GROUP_OBJECT), {
|
||||
var expectedObject = fabric.util.object.extend(fabric.util.object.clone(REFERENCE_PATH_GROUP_OBJECT), {
|
||||
'paths': 'http://example.com/',
|
||||
'sourcePath': 'http://example.com/'
|
||||
});
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@
|
|||
var polygonWithAttrs = fabric.Polygon.fromElement(elPolygonWithAttrs);
|
||||
var expectedPoints = [{x: 10, y: 10}, {x: 20, y: 20}, {x: 30, y: 30}, {x: 10, y: 10}];
|
||||
|
||||
same(fabric.base.object.extend(REFERENCE_OBJECT, {
|
||||
same(fabric.util.object.extend(REFERENCE_OBJECT, {
|
||||
'width': 20,
|
||||
'height': 20,
|
||||
'fill': 'rgb(255,255,255)',
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@
|
|||
var polylineWithAttrs = fabric.Polyline.fromElement(elPolylineWithAttrs);
|
||||
//var expectedPoints = [{x: 10, y: 10}, {x: 20, y: 20}, {x: 30, y: 30}, {x: 10, y: 10}];
|
||||
/*
|
||||
same(fabric.base.object.extend(REFERENCE_OBJECT, {
|
||||
same(fabric.util.object.extend(REFERENCE_OBJECT, {
|
||||
'width': 20,
|
||||
'height': 20,
|
||||
'fill': 'rgb(255,255,255)',
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@
|
|||
var rectWithAttrs = fabric.Rect.fromElement(elRectWithAttrs);
|
||||
ok(rectWithAttrs instanceof fabric.Rect);
|
||||
|
||||
var expectedObject = fabric.base.object.extend(REFERENCE_RECT, {
|
||||
var expectedObject = fabric.util.object.extend(REFERENCE_RECT, {
|
||||
left: 121,
|
||||
top: 186.5,
|
||||
width: 222,
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||
<title>APE extensions unit tests</title>
|
||||
|
||||
<script src="http://yui.yahooapis.com/2.7.0/build/yuiloader/yuiloader-min.js" type="text/javascript"></script>
|
||||
|
||||
<script src="../bootstrap.js" type="text/javascript"></script>
|
||||
<script src="ape_extensions.js" type="text/javascript"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h2>APE extensions unit tests</h2>
|
||||
<div id="testlog"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
function init() {
|
||||
new Test.Unit.Runner({
|
||||
testGetElement: function() {
|
||||
this.assertRespondsTo('getElement', APE);
|
||||
|
||||
var el = document.createElement('div');
|
||||
el.id = 'foo';
|
||||
document.body.appendChild(el);
|
||||
|
||||
this.assertIdentical(el, APE.getElement('foo'));
|
||||
this.assertIdentical(el, APE.getElement(el));
|
||||
},
|
||||
testEventPublisherRemove: function() {
|
||||
|
||||
this.assertRespondsTo('remove', APE.EventPublisher);
|
||||
|
||||
|
||||
var docEl = document.documentElement;
|
||||
var numInvocations = 0;
|
||||
|
||||
function onclick() {
|
||||
numInvocations++;
|
||||
}
|
||||
|
||||
APE.EventPublisher.add(docEl, 'onclick', onclick);
|
||||
Event.simulate(docEl, 'click');
|
||||
this.assertIdentical(1, numInvocations);
|
||||
|
||||
APE.EventPublisher.remove(docEl, 'onclick', onclick);
|
||||
Event.simulate(docEl, 'click');
|
||||
this.assertIdentical(1, numInvocations, 'listener should be removed');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
||||
"http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||
<title>Prototype extensions unit tests</title>
|
||||
|
||||
<script src="http://yui.yahooapis.com/2.7.0/build/yuiloader/yuiloader-min.js" type="text/javascript"></script>
|
||||
|
||||
<script src="../bootstrap.js" type="text/javascript"></script>
|
||||
<script src="prototype_extensions.js" type="text/javascript"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Prototype extensions unit tests</h2>
|
||||
<div id="testlog"></div>
|
||||
</body>
|
||||
</html>
|
||||
114
test/unit/extensions/prototype_extensions.js
vendored
114
test/unit/extensions/prototype_extensions.js
vendored
|
|
@ -1,114 +0,0 @@
|
|||
function init() {
|
||||
|
||||
var global = (function(){ return this; })();
|
||||
|
||||
new Test.Unit.Runner({
|
||||
testFalseFunction: function() {
|
||||
this.assertRespondsTo('falseFunction', Prototype);
|
||||
this.assertIdentical(false, Prototype.falseFunction());
|
||||
},
|
||||
testGetScript: function() {
|
||||
this.assert(Prototype.getScript);
|
||||
this.assertUndefined(global.foo);
|
||||
|
||||
var callbackFired = false;
|
||||
|
||||
Prototype.getScript('../../fixtures/test_script.js', function(){
|
||||
callbackFired = true;
|
||||
});
|
||||
|
||||
this.wait(500, function(){
|
||||
this.assertIdentical('bar', global.foo);
|
||||
this.assert(callbackFired);
|
||||
});
|
||||
},
|
||||
|
||||
testButtonEnableDisable: function(){
|
||||
var buttonEl = document.createElement('button');
|
||||
|
||||
this.assertRespondsTo('enable', buttonEl);
|
||||
this.assertRespondsTo('disable', buttonEl);
|
||||
|
||||
buttonEl.disabled = true;
|
||||
|
||||
buttonEl.enable();
|
||||
this.assert(!buttonEl.disabled);
|
||||
|
||||
buttonEl.disable();
|
||||
this.assert(buttonEl.disabled);
|
||||
},
|
||||
|
||||
testMakeUnselectable: function() {
|
||||
var el = document.createElement('div');
|
||||
|
||||
this.assertRespondsTo('makeUnselectable', el);
|
||||
|
||||
el.makeUnselectable();
|
||||
this.assertIdentical(false, el.onselectstart(), 'onselectstart should be a function that returns `false`');
|
||||
},
|
||||
|
||||
testAssertEnumEqualUnordered: function() {
|
||||
this.assertRespondsTo('assertEnumEqualUnordered', this);
|
||||
|
||||
this.assert(Test.Unit.Assertions._isEnumEqualUnordered([1,2,3], [1,2,3]));
|
||||
this.assert(Test.Unit.Assertions._isEnumEqualUnordered([1,2,3], [1,3,2]));
|
||||
this.assert(Test.Unit.Assertions._isEnumEqualUnordered([1,2,3], [2,1,3]));
|
||||
this.assert(Test.Unit.Assertions._isEnumEqualUnordered([1,2,3], [2,3,1]));
|
||||
this.assert(Test.Unit.Assertions._isEnumEqualUnordered([1,2,3], [3,1,2]));
|
||||
this.assert(Test.Unit.Assertions._isEnumEqualUnordered([1,2,3], [3,2,1]));
|
||||
|
||||
this.assert(!Test.Unit.Assertions._isEnumEqualUnordered([1,2,3], [1,1,1]));
|
||||
this.assert(!Test.Unit.Assertions._isEnumEqualUnordered([4,5,6], [1,2,3]));
|
||||
|
||||
this.assert(!Test.Unit.Assertions._isEnumEqualUnordered([1,2,3], ['1',2,3]));
|
||||
},
|
||||
|
||||
testAssertObjectIdentical: function() {
|
||||
this.assertRespondsTo('assertObjectIdentical', this);
|
||||
|
||||
// Array objects
|
||||
this.assert(Test.Unit.Assertions._isIdenticalRecursive([1,2,3], [1,2,3]));
|
||||
this.assert(!Test.Unit.Assertions._isIdenticalRecursive([1,2,3], [3,2,1]));
|
||||
this.assert(Test.Unit.Assertions._isIdenticalRecursive([], []));
|
||||
this.assert(Test.Unit.Assertions._isIdenticalRecursive(
|
||||
[false, false, true, false, true],
|
||||
[false, false, true, false, true]
|
||||
));
|
||||
|
||||
// Object objects
|
||||
this.assert(Test.Unit.Assertions._isIdenticalRecursive(
|
||||
{ x: 1, y: 2 },
|
||||
{ x: 1, y: 2 }
|
||||
));
|
||||
this.assert(Test.Unit.Assertions._isIdenticalRecursive(
|
||||
{ foo: true, bar: 12, baz: [12, 13, 14], qux: { x: null, y: 'boo' } },
|
||||
{ foo: true, bar: 12, baz: [12, 13, 14], qux: { x: null, y: 'boo' } }
|
||||
));
|
||||
|
||||
this.assert(Test.Unit.Assertions._isIdenticalRecursive(function(){}, function(){}));
|
||||
this.assert(Test.Unit.Assertions._isIdenticalRecursive(
|
||||
{ x: undefined, y: null, z: NaN },
|
||||
{ x: undefined, y: null, z: NaN }
|
||||
));
|
||||
|
||||
this.assert(Test.Unit.Assertions._isIdenticalRecursive(
|
||||
{ level1: { level2: { level3: { level4: { level5: 'boo' } }}, x: 1.1234 }},
|
||||
{ level1: { level2: { level3: { level4: { level5: 'boo' } }}, x: 1.1234 }}
|
||||
));
|
||||
|
||||
this.assert(!Test.Unit.Assertions._isIdenticalRecursive({ x: 1 }, { }));
|
||||
this.assert(Test.Unit.Assertions._isIdenticalRecursive({ }, { }));
|
||||
|
||||
// primitives
|
||||
this.assert(Test.Unit.Assertions._isIdenticalRecursive(5, 5));
|
||||
this.assert(!Test.Unit.Assertions._isIdenticalRecursive(5, '5'));
|
||||
|
||||
this.assert(Test.Unit.Assertions._isIdenticalRecursive(NaN, NaN));
|
||||
this.assert(Test.Unit.Assertions._isIdenticalRecursive('x', 'x'));
|
||||
this.assert(Test.Unit.Assertions._isIdenticalRecursive(false, false));
|
||||
this.assert(Test.Unit.Assertions._isIdenticalRecursive(null, null));
|
||||
this.assert(Test.Unit.Assertions._isIdenticalRecursive(undefined, undefined));
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue