improved gripRadius ternary assignment in Selector and misc formating

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2385 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Bruno Heridet 2013-02-14 12:47:32 +00:00
parent a9ab2f2c7e
commit d51f96012b
1 changed files with 23 additions and 25 deletions

View File

@ -24,9 +24,7 @@ if (!svgedit.select) {
var svgFactory_; var svgFactory_;
var config_; var config_;
var selectorManager_; // A Singleton var selectorManager_; // A Singleton
var gripRadius = svgedit.browser.isTouch() ? 10 : 4;
var gripRadius;
svgedit.browser.isTouch() ? gripRadius = 10 : gripRadius = 4;
// Class: svgedit.select.Selector // Class: svgedit.select.Selector
// Private class for DOM element selection boxes // Private class for DOM element selection boxes
@ -102,11 +100,11 @@ svgedit.select.Selector.prototype.reset = function(e) {
svgedit.select.Selector.prototype.updateGripCursors = function(angle) { svgedit.select.Selector.prototype.updateGripCursors = function(angle) {
var dir_arr = []; var dir_arr = [];
var steps = Math.round(angle / 45); var steps = Math.round(angle / 45);
if(steps < 0) steps += 8; if (steps < 0) steps += 8;
for (var dir in selectorManager_.selectorGrips) { for (var dir in selectorManager_.selectorGrips) {
dir_arr.push(dir); dir_arr.push(dir);
} }
while(steps > 0) { while (steps > 0) {
dir_arr.push(dir_arr.shift()); dir_arr.push(dir_arr.shift());
steps--; steps--;
} }
@ -114,7 +112,7 @@ svgedit.select.Selector.prototype.updateGripCursors = function(angle) {
for (var dir in selectorManager_.selectorGrips) { for (var dir in selectorManager_.selectorGrips) {
selectorManager_.selectorGrips[dir].setAttribute('style', ('cursor:' + dir_arr[i] + '-resize')); selectorManager_.selectorGrips[dir].setAttribute('style', ('cursor:' + dir_arr[i] + '-resize'));
i++; i++;
}; }
}; };
// Function: svgedit.select.Selector.showGrips // Function: svgedit.select.Selector.showGrips
@ -128,7 +126,7 @@ svgedit.select.Selector.prototype.showGrips = function(show) {
selectorManager_.selectorGripsGroup.setAttribute('display', bShow); selectorManager_.selectorGripsGroup.setAttribute('display', bShow);
var elem = this.selectedElement; var elem = this.selectedElement;
this.hasGrips = show; this.hasGrips = show;
if(elem && show) { if (elem && show) {
this.selectorGroup.appendChild(selectorManager_.selectorGripsGroup); this.selectorGroup.appendChild(selectorManager_.selectorGripsGroup);
this.updateGripCursors(svgedit.utilities.getRotationAngle(elem)); this.updateGripCursors(svgedit.utilities.getRotationAngle(elem));
} }
@ -163,17 +161,17 @@ svgedit.select.Selector.prototype.resize = function() {
m.f *= current_zoom; m.f *= current_zoom;
var bbox = svgedit.utilities.getBBox(selected); var bbox = svgedit.utilities.getBBox(selected);
if(tagName === 'g' && !$.data(selected, 'gsvg')) { if (tagName === 'g' && !$.data(selected, 'gsvg')) {
// The bbox for a group does not include stroke vals, so we // The bbox for a group does not include stroke vals, so we
// get the bbox based on its children. // get the bbox based on its children.
var stroked_bbox = svgFactory_.getStrokedBBox(selected.childNodes); var stroked_bbox = svgFactory_.getStrokedBBox(selected.childNodes);
if(stroked_bbox) { if (stroked_bbox) {
bbox = stroked_bbox; bbox = stroked_bbox;
} }
} }
// apply the transforms // apply the transforms
var l=bbox.x, t=bbox.y, w=bbox.width, h=bbox.height, var l = bbox.x, t = bbox.y, w = bbox.width, h = bbox.height,
bbox = {x:l, y:t, width:w, height:h}; bbox = {x:l, y:t, width:w, height:h};
// we need to handle temporary transforms too // we need to handle temporary transforms too
@ -234,7 +232,7 @@ svgedit.select.Selector.prototype.resize = function() {
this.selectorGroup.setAttribute('transform', xform); this.selectorGroup.setAttribute('transform', xform);
// TODO(codedread): Is this if needed? // TODO(codedread): Is this if needed?
// if(selected === selectedElements[0]) { // if (selected === selectedElements[0]) {
this.gripCoords = { this.gripCoords = {
'nw': [nbax, nbay], 'nw': [nbax, nbay],
'ne': [nbax+nbaw, nbay], 'ne': [nbax+nbaw, nbay],
@ -246,11 +244,11 @@ svgedit.select.Selector.prototype.resize = function() {
's': [nbax + (nbaw)/2, nbay + nbah] 's': [nbax + (nbaw)/2, nbay + nbah]
}; };
for(var dir in this.gripCoords) { for (var dir in this.gripCoords) {
var coords = this.gripCoords[dir]; var coords = this.gripCoords[dir];
selectedGrips[dir].setAttribute('cx', coords[0]); selectedGrips[dir].setAttribute('cx', coords[0]);
selectedGrips[dir].setAttribute('cy', coords[1]); selectedGrips[dir].setAttribute('cy', coords[1]);
}; }
// we want to go 20 pixels in the negative transformed y direction, ignoring scale // we want to go 20 pixels in the negative transformed y direction, ignoring scale
mgr.rotateGripConnector.setAttribute('x1', nbax + (nbaw)/2); mgr.rotateGripConnector.setAttribute('x1', nbax + (nbaw)/2);
@ -373,7 +371,7 @@ svgedit.select.SelectorManager.prototype.initGroup = function() {
); );
$.data(this.rotateGrip, 'type', 'rotate'); $.data(this.rotateGrip, 'type', 'rotate');
if($('#canvasBackground').length) return; if ($('#canvasBackground').length) return;
var dims = config_.dimensions; var dims = config_.dimensions;
var canvasbg = svgFactory_.createSVGElement({ var canvasbg = svgFactory_.createSVGElement({