Opened 14 years ago

Closed 13 years ago

Last modified 12 years ago

#153 closed defect (wontfix)

[patch] fix for dojo.style.getNumericStyle

Reported by: eugene@… Owned by: sjmiles
Priority: high Milestone:
Component: Core Version: 0.1
Keywords: Cc:
Blocked By: Blocking:

Description

This patch simplifies dojo.style.getNumericStyle() and makes it more reliable.

Index: style.js
===================================================================
--- style.js	(revision 1784)
+++ style.js	(working copy)
@@ -99,11 +99,8 @@
 	var s = dojo.style.getComputedStyle(element, cssSelector);
 	if (s == ''){ return 0; }
 	if (dojo.lang.isUndefined(s)){ return NaN };
-	var match = s.match(/([d.]+)([a-z]*)/);
-	if (!match || !match[1]) 
-		return NaN;
-	var n = Number(match[1]);
-	return (n == 0 || match[2]=='px' ? n : NaN);
+	var match = s.match(/(d+)(px){0,1}/);
+	return	(!match || !match[1]) ? NaN : Number(match[1]);
 }
 
 dojo.style.getMarginWidth = function(node){

Attachments (2)

dojo.style.patch (610 bytes) - added by eugene@… 14 years ago.
getNumericStyle.diff (599 bytes) - added by david 14 years ago.
slightly modified patch

Download all attachments as: .zip

Change History (8)

Changed 14 years ago by eugene@…

Attachment: dojo.style.patch added

Changed 14 years ago by david

Attachment: getNumericStyle.diff added

slightly modified patch

comment:1 Changed 14 years ago by david

Owner: changed from anonymous to paul

The patch I submitted would work slightly better, but I'm hesitent of applying it until the folks who use this function can test it out.

comment:2 Changed 14 years ago by psowden

Owner: changed from paul to sjmiles@…

I assume you meant to reassign to me :-)

This is patch is based on sjmiles' work, it'd probably be better for him to review.

comment:3 Changed 14 years ago by sjmiles@…

There are a few problems with the simplification:

  • The original code is meant to extract the 'units' designation becuase in future we may support units other than just 'px'.
  • Non-zero values in non-supported units must return NaN
  • Numeric styles can contain decimals (not just integers), so we must allow '.'

comment:4 Changed 13 years ago by dylan

Milestone: 0.4
Owner: changed from sjmiles@… to sjmiles

Can we close this?

comment:5 Changed 13 years ago by sjmiles

Resolution: wontfix
Status: newclosed

Closing this ticket. Please reopen if I missed some important detail.

comment:6 Changed 12 years ago by (none)

Milestone: 0.4

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.