Reduce Mootools components.
This commit is contained in:
@@ -52,7 +52,7 @@ web2d.peer.svg.ElementPeer = new Class({
|
||||
this._parent = parent;
|
||||
},
|
||||
|
||||
appendChild:function (elementPeer) {
|
||||
append:function (elementPeer) {
|
||||
// Store parent and child relationship.
|
||||
elementPeer.setParent(this);
|
||||
var children = this.getChildren();
|
||||
@@ -86,7 +86,7 @@ web2d.peer.svg.ElementPeer = new Class({
|
||||
* http://developer.mozilla.org/en/docs/addEvent
|
||||
*/
|
||||
addEvent:function (type, listener) {
|
||||
this._native.addEvent(type, listener);
|
||||
$(this._native).bind(type, listener);
|
||||
},
|
||||
|
||||
fireEvent:function (type, event) {
|
||||
@@ -98,7 +98,7 @@ web2d.peer.svg.ElementPeer = new Class({
|
||||
},
|
||||
|
||||
removeEvent:function (type, listener) {
|
||||
this._native.removeEvent(type, listener);
|
||||
$(this._native).unbind(type, listener);
|
||||
},
|
||||
|
||||
setSize:function (width, height) {
|
||||
@@ -214,12 +214,12 @@ web2d.peer.svg.ElementPeer = new Class({
|
||||
return listeners;
|
||||
},
|
||||
|
||||
positionRelativeTo:function (elem, options) {
|
||||
options = !$defined(options) ? {} : options;
|
||||
options['relativeTo'] = document.id(this._native);
|
||||
elem.position(options);
|
||||
},
|
||||
|
||||
// positionRelativeTo:function (elem, options) {
|
||||
// options = !$defined(options) ? {} : options;
|
||||
// options['relativeTo'] = document.id(this._native);
|
||||
// elem.position(options);
|
||||
// },
|
||||
//
|
||||
|
||||
/**
|
||||
* Move element to the front
|
||||
|
||||
@@ -18,17 +18,17 @@
|
||||
|
||||
web2d.peer.svg.GroupPeer = new Class({
|
||||
Extends: web2d.peer.svg.ElementPeer,
|
||||
initialize : function() {
|
||||
initialize: function () {
|
||||
var svgElement = window.document.createElementNS(this.svgNamespace, 'g');
|
||||
this.parent(svgElement);
|
||||
this._native.setAttribute("preserveAspectRatio", "none");
|
||||
this._coordSize = {width:1,height:1};
|
||||
this._coordSize = {width: 1, height: 1};
|
||||
this._native.setAttribute("focusable", "true");
|
||||
this._position = {x:0,y:0};
|
||||
this._coordOrigin = {x:0,y:0};
|
||||
this._position = {x: 0, y: 0};
|
||||
this._coordOrigin = {x: 0, y: 0};
|
||||
},
|
||||
|
||||
setCoordSize : function(width, height) {
|
||||
setCoordSize: function (width, height) {
|
||||
var change = this._coordSize.width != width || this._coordSize.height != height;
|
||||
this._coordSize.width = width;
|
||||
this._coordSize.height = height;
|
||||
@@ -38,8 +38,8 @@ web2d.peer.svg.GroupPeer = new Class({
|
||||
web2d.peer.utils.EventUtils.broadcastChangeEvent(this, "strokeStyle");
|
||||
},
|
||||
|
||||
getCoordSize : function() {
|
||||
return {width:this._coordSize.width,height:this._coordSize.height};
|
||||
getCoordSize: function () {
|
||||
return {width: this._coordSize.width, height: this._coordSize.height};
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ web2d.peer.svg.GroupPeer = new Class({
|
||||
* * skewY(<skew-angle>), which specifies a skew transformation along the y-axis.
|
||||
**/
|
||||
|
||||
updateTransform : function() {
|
||||
updateTransform: function () {
|
||||
var sx = this._size.width / this._coordSize.width;
|
||||
var sy = this._size.height / this._coordSize.height;
|
||||
|
||||
@@ -73,11 +73,11 @@ web2d.peer.svg.GroupPeer = new Class({
|
||||
this._native.setAttribute("transform", "translate(" + cx + "," + cy + ") scale(" + sx + "," + sy + ")");
|
||||
},
|
||||
|
||||
setOpacity : function(value) {
|
||||
setOpacity: function (value) {
|
||||
this._native.setAttribute("opacity", value);
|
||||
},
|
||||
|
||||
setCoordOrigin : function(x, y) {
|
||||
setCoordOrigin: function (x, y) {
|
||||
var change = x != this._coordOrigin.x || y != this._coordOrigin.y;
|
||||
if ($defined(x)) {
|
||||
this._coordOrigin.x = x;
|
||||
@@ -90,14 +90,14 @@ web2d.peer.svg.GroupPeer = new Class({
|
||||
this.updateTransform();
|
||||
},
|
||||
|
||||
setSize : function(width, height) {
|
||||
setSize: function (width, height) {
|
||||
var change = width != this._size.width || height != this._size.height;
|
||||
this.parent(width, height);
|
||||
if (change)
|
||||
this.updateTransform();
|
||||
},
|
||||
|
||||
setPosition : function(x, y) {
|
||||
setPosition: function (x, y) {
|
||||
var change = x != this._position.x || y != this._position.y;
|
||||
if ($defined(x)) {
|
||||
this._position.x = parseInt(x);
|
||||
@@ -110,16 +110,16 @@ web2d.peer.svg.GroupPeer = new Class({
|
||||
this.updateTransform();
|
||||
},
|
||||
|
||||
getPosition : function() {
|
||||
return {x:this._position.x,y:this._position.y};
|
||||
getPosition: function () {
|
||||
return {x: this._position.x, y: this._position.y};
|
||||
},
|
||||
|
||||
appendChild : function(child) {
|
||||
append: function (child) {
|
||||
this.parent(child);
|
||||
web2d.peer.utils.EventUtils.broadcastChangeEvent(child, "onChangeCoordSize");
|
||||
},
|
||||
|
||||
getCoordOrigin : function () {
|
||||
return {x:this._coordOrigin.x, y:this._coordOrigin.y};
|
||||
getCoordOrigin: function () {
|
||||
return {x: this._coordOrigin.x, y: this._coordOrigin.y};
|
||||
}
|
||||
});
|
||||
@@ -19,27 +19,27 @@
|
||||
|
||||
web2d.peer.svg.TextPeer = new Class({
|
||||
Extends: web2d.peer.svg.ElementPeer,
|
||||
initialize : function() {
|
||||
initialize: function () {
|
||||
var svgElement = window.document.createElementNS(this.svgNamespace, 'text');
|
||||
this.parent(svgElement);
|
||||
this._position = {x:0,y:0};
|
||||
this._position = {x: 0, y: 0};
|
||||
this._font = new web2d.Font("Arial", this);
|
||||
},
|
||||
|
||||
appendChild : function(element) {
|
||||
this._native.appendChild(element._native);
|
||||
append: function (element) {
|
||||
this._native.append(element._native);
|
||||
},
|
||||
|
||||
setTextAlignment : function(align) {
|
||||
setTextAlignment: function (align) {
|
||||
this._textAlign = align;
|
||||
},
|
||||
|
||||
|
||||
getTextAlignment : function() {
|
||||
getTextAlignment: function () {
|
||||
return $defined(this._textAlign) ? this._textAlign : 'left';
|
||||
},
|
||||
|
||||
setText : function(text) {
|
||||
setText: function (text) {
|
||||
// Remove all previous nodes ...
|
||||
while (this._native.firstChild) {
|
||||
this._native.removeChild(this._native.firstChild);
|
||||
@@ -48,38 +48,38 @@ web2d.peer.svg.TextPeer = new Class({
|
||||
this._text = text;
|
||||
if (text) {
|
||||
var lines = text.split('\n');
|
||||
lines.forEach(function(line) {
|
||||
lines.forEach(function (line) {
|
||||
var tspan = window.document.createElementNS(this.svgNamespace, 'tspan');
|
||||
tspan.setAttribute('dy', '1em');
|
||||
tspan.setAttribute('x', this.getPosition().x);
|
||||
|
||||
tspan.textContent = line.length == 0 ? " " : line;
|
||||
this._native.appendChild(tspan);
|
||||
this._native.append(tspan);
|
||||
}.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
getText : function() {
|
||||
getText: function () {
|
||||
return this._text;
|
||||
},
|
||||
|
||||
setPosition : function(x, y) {
|
||||
this._position = {x:x, y:y};
|
||||
setPosition: function (x, y) {
|
||||
this._position = {x: x, y: y};
|
||||
this._native.setAttribute('y', y);
|
||||
this._native.setAttribute('x', x);
|
||||
|
||||
// tspan must be positioned manually.
|
||||
this._native.getElements('tspan').forEach(function(span) {
|
||||
this._native.getElements('tspan').forEach(function (span) {
|
||||
span.setAttribute('x', x);
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
getPosition : function() {
|
||||
getPosition: function () {
|
||||
return this._position;
|
||||
},
|
||||
|
||||
setFont : function(font, size, style, weight) {
|
||||
setFont: function (font, size, style, weight) {
|
||||
if ($defined(font)) {
|
||||
this._font = new web2d.Font(font, this);
|
||||
}
|
||||
@@ -95,41 +95,41 @@ web2d.peer.svg.TextPeer = new Class({
|
||||
this._updateFontStyle();
|
||||
},
|
||||
|
||||
_updateFontStyle : function() {
|
||||
_updateFontStyle: function () {
|
||||
this._native.setAttribute('font-family', this._font.getFontFamily());
|
||||
this._native.setAttribute('font-size', this._font.getGraphSize());
|
||||
this._native.setAttribute('font-style', this._font.getStyle());
|
||||
this._native.setAttribute('font-weight', this._font.getWeight());
|
||||
},
|
||||
|
||||
setColor : function(color) {
|
||||
setColor: function (color) {
|
||||
this._native.setAttribute('fill', color);
|
||||
},
|
||||
|
||||
getColor : function() {
|
||||
getColor: function () {
|
||||
return this._native.getAttribute('fill');
|
||||
},
|
||||
|
||||
setTextSize : function (size) {
|
||||
setTextSize: function (size) {
|
||||
this._font.setSize(size);
|
||||
this._updateFontStyle();
|
||||
},
|
||||
|
||||
setContentSize : function(width, height) {
|
||||
setContentSize: function (width, height) {
|
||||
this._native.xTextSize = width.toFixed(1) + "," + height.toFixed(1);
|
||||
},
|
||||
|
||||
setStyle : function (style) {
|
||||
setStyle: function (style) {
|
||||
this._font.setStyle(style);
|
||||
this._updateFontStyle();
|
||||
},
|
||||
|
||||
setWeight : function (weight) {
|
||||
setWeight: function (weight) {
|
||||
this._font.setWeight(weight);
|
||||
this._updateFontStyle();
|
||||
},
|
||||
|
||||
setFontFamily : function (family) {
|
||||
setFontFamily: function (family) {
|
||||
var oldFont = this._font;
|
||||
this._font = new web2d.Font(family, this);
|
||||
this._font.setSize(oldFont.getSize());
|
||||
@@ -138,21 +138,21 @@ web2d.peer.svg.TextPeer = new Class({
|
||||
this._updateFontStyle();
|
||||
},
|
||||
|
||||
getFont : function () {
|
||||
getFont: function () {
|
||||
return {
|
||||
font:this._font.getFont(),
|
||||
size:parseInt(this._font.getSize()),
|
||||
style:this._font.getStyle(),
|
||||
weight:this._font.getWeight()
|
||||
font: this._font.getFont(),
|
||||
size: parseInt(this._font.getSize()),
|
||||
style: this._font.getStyle(),
|
||||
weight: this._font.getWeight()
|
||||
};
|
||||
},
|
||||
|
||||
setSize : function (size) {
|
||||
setSize: function (size) {
|
||||
this._font.setSize(size);
|
||||
this._updateFontStyle();
|
||||
},
|
||||
|
||||
getWidth : function () {
|
||||
getWidth: function () {
|
||||
var computedWidth;
|
||||
// Firefox hack for this issue:http://stackoverflow.com/questions/6390065/doing-ajax-updates-in-svg-breaks-getbbox-is-there-a-workaround
|
||||
try {
|
||||
@@ -160,12 +160,12 @@ web2d.peer.svg.TextPeer = new Class({
|
||||
computedWidth = this._native.getBBox().width;
|
||||
// Chrome bug is producing this error, oly during page loading. Remove the hack if it works. The issue seems to be
|
||||
// caused when the element is hidden. I don't know why, but it works ...
|
||||
if(computedWidth==0){
|
||||
if (computedWidth == 0) {
|
||||
var bbox = this._native.getBBox();
|
||||
computedWidth = bbox.width;
|
||||
}
|
||||
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
computedWidth = 10;
|
||||
|
||||
}
|
||||
@@ -175,17 +175,17 @@ web2d.peer.svg.TextPeer = new Class({
|
||||
return width;
|
||||
},
|
||||
|
||||
getHeight : function () {
|
||||
getHeight: function () {
|
||||
// Firefox hack for this issue:http://stackoverflow.com/questions/6390065/doing-ajax-updates-in-svg-breaks-getbbox-is-there-a-workaround
|
||||
try {
|
||||
var computedHeight = this._native.getBBox().height;
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
computedHeight = 10;
|
||||
}
|
||||
return parseInt(computedHeight);
|
||||
},
|
||||
|
||||
getHtmlFontSize : function () {
|
||||
getHtmlFontSize: function () {
|
||||
return this._font.getHtmlSize();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
web2d.peer.svg.WorkspacePeer = new Class({
|
||||
Extends: web2d.peer.svg.ElementPeer,
|
||||
initialize : function(element) {
|
||||
initialize: function (element) {
|
||||
this._element = element;
|
||||
var svgElement = window.document.createElementNS(this.svgNamespace, 'svg');
|
||||
this.parent(svgElement);
|
||||
@@ -38,9 +38,9 @@ web2d.peer.svg.WorkspacePeer = new Class({
|
||||
*
|
||||
*/
|
||||
|
||||
setCoordSize : function (width, height) {
|
||||
setCoordSize: function (width, height) {
|
||||
var viewBox = this._native.getAttribute('viewBox');
|
||||
var coords = [0,0,0,0];
|
||||
var coords = [0, 0, 0, 0];
|
||||
if (viewBox != null) {
|
||||
coords = viewBox.split(/ /);
|
||||
}
|
||||
@@ -57,20 +57,20 @@ web2d.peer.svg.WorkspacePeer = new Class({
|
||||
web2d.peer.utils.EventUtils.broadcastChangeEvent(this, "strokeStyle");
|
||||
},
|
||||
|
||||
getCoordSize : function () {
|
||||
getCoordSize: function () {
|
||||
var viewBox = this._native.getAttribute('viewBox');
|
||||
var coords = [1,1,1,1];
|
||||
var coords = [1, 1, 1, 1];
|
||||
if (viewBox != null) {
|
||||
coords = viewBox.split(/ /);
|
||||
}
|
||||
return {width:coords[2],height:coords[3]};
|
||||
return {width: coords[2], height: coords[3]};
|
||||
},
|
||||
|
||||
setCoordOrigin : function (x, y) {
|
||||
setCoordOrigin: function (x, y) {
|
||||
var viewBox = this._native.getAttribute('viewBox');
|
||||
|
||||
// ViewBox min-x ,min-y by default initializated with 0 and 0.
|
||||
var coords = [0,0,0,0];
|
||||
var coords = [0, 0, 0, 0];
|
||||
if (viewBox != null) {
|
||||
coords = viewBox.split(/ /);
|
||||
}
|
||||
@@ -86,23 +86,23 @@ web2d.peer.svg.WorkspacePeer = new Class({
|
||||
this._native.setAttribute('viewBox', coords.join(" "));
|
||||
},
|
||||
|
||||
appendChild : function (child) {
|
||||
append: function (child) {
|
||||
this.parent(child);
|
||||
web2d.peer.utils.EventUtils.broadcastChangeEvent(child, "onChangeCoordSize");
|
||||
},
|
||||
|
||||
getCoordOrigin : function (child) {
|
||||
getCoordOrigin: function (child) {
|
||||
var viewBox = this._native.getAttribute('viewBox');
|
||||
var coords = [1,1,1,1];
|
||||
var coords = [1, 1, 1, 1];
|
||||
if (viewBox != null) {
|
||||
coords = viewBox.split(/ /);
|
||||
}
|
||||
var x = parseFloat(coords[0]);
|
||||
var y = parseFloat(coords[1]);
|
||||
return {x:x,y:y};
|
||||
return {x: x, y: y};
|
||||
},
|
||||
|
||||
getPosition : function () {
|
||||
return {x:0,y:0};
|
||||
getPosition: function () {
|
||||
return {x: 0, y: 0};
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user