From 36e0fbd2d5b256975b18cf6d52ec35df52433cc4 Mon Sep 17 00:00:00 2001 From: Ahmad Syazwan Date: Fri, 25 May 2012 04:04:22 +0000 Subject: [PATCH] Fix issue 934. Patch by adambender. git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2083 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svg-editor.js | 3 ++- editor/units.js | 4 ++-- test/units_test.html | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/editor/svg-editor.js b/editor/svg-editor.js index d720af3d..54f5a66c 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -1908,7 +1908,7 @@ $('.attr_changer').change(function() { var attr = this.getAttribute("data-attr"); var val = this.value; - var valid = svgedit.units.isValidUnit(attr, val); + var valid = svgedit.units.isValidUnit(attr, val, selectedElement); if(!valid) { $.alert(uiStrings.notification.invalidAttrValGiven); @@ -1941,6 +1941,7 @@ else { svgCanvas.changeSelectedAttribute(attr, val); } + this.blur(); }); // Prevent selection of elements when shift-clicking diff --git a/editor/units.js b/editor/units.js index 8be858cb..f2b30e70 100644 --- a/editor/units.js +++ b/editor/units.js @@ -241,7 +241,7 @@ svgedit.units.convertToNum = function(attr, val) { // Parameters: // attr - String with the name of the attribute associated with the value // val - String with the attribute value to check -svgedit.units.isValidUnit = function(attr, val) { +svgedit.units.isValidUnit = function(attr, val, selectedElement) { var valid = false; if(unit_attrs.indexOf(attr) >= 0) { // True if it's just a number @@ -267,7 +267,7 @@ svgedit.units.isValidUnit = function(attr, val) { // not already present try { var elem = elementContainer_.getElement(val); - result = (elem == null); + result = (elem == null || elem === selectedElement); } catch(e) {} return result; } else { diff --git a/test/units_test.html b/test/units_test.html index ba174151..116f20e8 100644 --- a/test/units_test.html +++ b/test/units_test.html @@ -17,10 +17,10 @@ function setUp() { svgedit.units.init({ getBaseUnit: function() { return "cm"; }, - getElement: function() { return null; }, getHeight: function() { return 600; }, getWidth: function() { return 800; }, - getRoundDigits: function() { return 4; } + getRoundDigits: function() { return 4; }, + getElement:function(elementId){ return document.getElementById(elementId);} }); } @@ -47,7 +47,7 @@ }); test('Test svgedit.units.isValidUnit()', function() { - expect(14); + expect(18); setUp(); @@ -67,6 +67,12 @@ ok(isValidUnit("-0.4em")); ok(isValidUnit("-0.ex")); ok(isValidUnit("40.123%")); + + + equals(isValidUnit("id","uniqueId",document.getElementById("uniqueId")), true); + equals(isValidUnit("id","newId",document.getElementById("uniqueId")), true); + equals(isValidUnit("id","uniqueId"), false); + equals(isValidUnit("id","uniqueId",document.getElementById("nonUniqueId")), false); }); }); @@ -78,6 +84,12 @@
+
+ + +
+