From c4cc4084659f6215a411a5e1c5e36cae985a34ca Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Mon, 24 Aug 2009 15:26:35 +0000 Subject: [PATCH] Fixed issue 112: Values for certain attributes must now be numbers, enter/return on field now updates value in Opera git-svn-id: http://svg-edit.googlecode.com/svn/trunk@453 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svg-editor.html | 2 ++ editor/svg-editor.js | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/editor/svg-editor.html b/editor/svg-editor.html index 4869e32f..87397f54 100644 --- a/editor/svg-editor.html +++ b/editor/svg-editor.html @@ -37,6 +37,7 @@ +
@@ -264,6 +265,7 @@
+
diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 145ff704..7eb1d36a 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -25,6 +25,8 @@ function svg_edit_setup() { var selectedElement = null; var multiselected = false; var editingsource = false; + var length_attrs = ['x','y','x1','x2','y1','y2','cx','cy','width','height','r','rx','ry','width','height','radius']; + var length_types = ['em','ex','px','cm','mm','in','pt','pc','%']; var fillPaint = new $.jGraduate.Paint({solidColor: "FF0000"}); // solid red var strokePaint = new $.jGraduate.Paint({solidColor: "000000"}); // solid black @@ -308,7 +310,31 @@ function svg_edit_setup() { }); $('.attr_changer').change(function() { - svgCanvas.changeSelectedAttribute(this.getAttribute("alt"), this.value); + var attr = this.getAttribute("alt"); + var val = this.value; + var valid = false; + if($.inArray(attr, length_attrs) != -1) { + if(!isNaN(val)) { + valid = true; + } else { + //TODO: Allow the values in length_types, then uncomment this: +// val = val.toLowerCase(); +// $.each(length_types, function(i, unit) { +// if(valid) return; +// var re = new RegExp('^-?[\\d\\.]+' + unit + '$'); +// if(re.test(val)) valid = true; +// }); + } + } else valid = true; + + if(!valid) { + alert('Invalid value given for' + $(this).attr('title').replace('Change','') + + '.'); + this.value = selectedElement.getAttribute(attr); + return false; + } + + svgCanvas.changeSelectedAttribute(attr, val); }); $('.palette_item').click(function(evt){ @@ -705,6 +731,10 @@ function svg_edit_setup() { var disable = !(item.length > 2 && !item[2]); $(document).bind('keydown', {combi:item[0], disableInInput: disable}, item[1]); }); + + $('.attr_changer').bind('keydown', {combi:'return', disableInInput: false}, + function(evt) {$(this).change();evt.preventDefault();} + ); } setKeyBindings();