From a41fd5dffd87504c71252b0173139721c40aba88 Mon Sep 17 00:00:00 2001 From: kangax Date: Fri, 12 Aug 2011 13:46:17 -0400 Subject: [PATCH] Closes #43. `fabric.Text#set` can now accept object with property/values. --- HEADER.js | 2 +- dist/all.js | 16 ++++++++++++---- src/text.class.js | 13 ++++++++++--- test/unit/text.js | 10 ++++++++++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/HEADER.js b/HEADER.js index 3d49af74..0dc3c26b 100644 --- a/HEADER.js +++ b/HEADER.js @@ -1,6 +1,6 @@ /*! Fabric.js Copyright 2008-2011, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */ -var fabric = fabric || { version: "0.5" }; +var fabric = fabric || { version: "0.5.1" }; if (typeof exports != 'undefined') { exports.fabric = fabric; diff --git a/dist/all.js b/dist/all.js index 49a53d83..86908bb2 100644 --- a/dist/all.js +++ b/dist/all.js @@ -1,6 +1,6 @@ /*! Fabric.js Copyright 2008-2011, Bitsonnet (Juriy Zaytsev, Maxim Chernyak) */ -var fabric = fabric || { version: "0.5" }; +var fabric = fabric || { version: "0.5.1" }; if (typeof exports != 'undefined') { exports.fabric = fabric; @@ -1865,6 +1865,7 @@ fabric.Observable = { fabric.loadSVGFromURL = loadSVGFromURL; fabric.loadSVGFromString = loadSVGFromString; + })(); if (!Array.prototype.indexOf) { @@ -10213,9 +10214,16 @@ fabric.util.object.extend(fabric.Canvas.prototype, { * @chainable */ set: function(name, value) { - this[name] = value; - if (name === 'fontFamily' && this.path) { - this.path = this.path.replace(/(.*?)([^\/]*)(\.font\.js)/, '$1' + value + '$3'); + if (typeof name == 'object') { + for (var prop in name) { + this.set(prop, name[prop]); + } + } + else { + this[name] = value; + if (name === 'fontFamily' && this.path) { + this.path = this.path.replace(/(.*?)([^\/]*)(\.font\.js)/, '$1' + value + '$3'); + } } return this; } diff --git a/src/text.class.js b/src/text.class.js index 859eab46..cbfe15d3 100644 --- a/src/text.class.js +++ b/src/text.class.js @@ -323,9 +323,16 @@ * @chainable */ set: function(name, value) { - this[name] = value; - if (name === 'fontFamily' && this.path) { - this.path = this.path.replace(/(.*?)([^\/]*)(\.font\.js)/, '$1' + value + '$3'); + if (typeof name == 'object') { + for (var prop in name) { + this.set(prop, name[prop]); + } + } + else { + this[name] = value; + if (name === 'fontFamily' && this.path) { + this.path = this.path.replace(/(.*?)([^\/]*)(\.font\.js)/, '$1' + value + '$3'); + } } return this; } diff --git a/test/unit/text.js b/test/unit/text.js index a10a110b..f2aa217e 100644 --- a/test/unit/text.js +++ b/test/unit/text.js @@ -74,6 +74,16 @@ equals(text.set('text', 'bar'), text, 'should be chainable'); }); + test('set with "hash"', function() { + var text = createTextObject(); + + text.set({ opacity: 0.123, fill: 'red', fontFamily: 'blah' }); + + equals(0.123, text.getOpacity()); + equals('red', text.getFill()); + equals('blah', text.get('fontFamily')); + }); + test('setColor', function(){ var text = createTextObject(); ok(typeof text.setColor == 'function');