From 93c39205050ad9426cde186c61acf6a454ab9ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 4 Mar 2011 19:46:41 +0000 Subject: [PATCH] Add definition of Base.capitalize() and remove dependencies of String#capitalize(). --- src/color/GrayColor.js | 4 ++-- src/item/PathStyle.js | 8 ++++---- src/paper.js | 6 ++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/color/GrayColor.js b/src/color/GrayColor.js index 25e6578b..4853e204 100644 --- a/src/color/GrayColor.js +++ b/src/color/GrayColor.js @@ -79,10 +79,10 @@ var GrayColor = this.GrayColor = Color.extend({ }; Base.each(componentWeights, function(weight, key) { - fields['get' + key.capitalize()] = function() { + fields['get' + Base.capitalize(key)] = function() { return 1 - this._gray; }; - fields['set' + key.capitalize()] = function(value) { + fields['set' + Base.capitalize(key)] = function(value) { this._cssString = null; this._gray = this._gray * (1 - weight) + weight * (1 - value); }; diff --git a/src/item/PathStyle.js b/src/item/PathStyle.js index cc07f4eb..c1ba48df 100644 --- a/src/item/PathStyle.js +++ b/src/item/PathStyle.js @@ -21,7 +21,7 @@ var PathStyle = this.PathStyle = Base.extend(new function() { Item.inject(Base.each(keys, function(key) { var isColor = !!(key.match(/Color$/)); - fields['set' + key.capitalize()] = function(value) { + fields['set' + Base.capitalize(key)] = function(value) { if (this.item && this.item.children) { for (var i = 0, l = this.item.children.length; i < l; i++) { this.item.children[i].style[key] = value; @@ -31,7 +31,7 @@ var PathStyle = this.PathStyle = Base.extend(new function() { } }; - fields['get' + key.capitalize()] = function() { + fields['get' + Base.capitalize(key)] = function() { if (this.item && this.item.children) { var style; for (var i = 0, l = this.item.children.length; i < l; i++) { @@ -50,11 +50,11 @@ var PathStyle = this.PathStyle = Base.extend(new function() { } }; - this['set' + key.capitalize()] = function(value) { + this['set' + Base.capitalize(key)] = function(value) { this.style[key] = value; }; - this['get' + key.capitalize()] = function() { + this['get' + Base.capitalize(key)] = function() { return this.style[key]; }; }, { beans: true })); diff --git a/src/paper.js b/src/paper.js index 71db94e0..e3d7a814 100644 --- a/src/paper.js +++ b/src/paper.js @@ -9,6 +9,12 @@ var paper = new function() { } }; + Base.capitalize = function(str) { + return str.replace(/\b[a-z]/g, function(match) { + return match.toUpperCase(); + }); + }; + //#include "basic/Point.js" //#include "basic/Size.js" //#include "basic/Rectangle.js"