From d05a4d084901262fab88668b763e695e10334b18 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Mon, 28 May 2012 16:15:16 +0000 Subject: [PATCH] update example --- examples/widget_design_patterns/js/example.js | 43 +++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/examples/widget_design_patterns/js/example.js b/examples/widget_design_patterns/js/example.js index 19dd77d1..b8067389 100644 --- a/examples/widget_design_patterns/js/example.js +++ b/examples/widget_design_patterns/js/example.js @@ -45,7 +45,11 @@ Ox.load('UI', function() { color: [128, 128, 128], size: 128 }) - .options(options || {}); + .options(options || {}) + .update({ + color: setColor, + size: setSize + }); /* Ox.Element, and every widget that inherits from it, has a private @@ -55,13 +59,6 @@ Ox.load('UI', function() { `self.setOption` untouched. In this case though, we want to update color and size, so we just overwrite `self.setOption`. */ - self.setOption = function(key, value) { - if (key == 'color') { - setColor(); - } else if (key == 'size') { - setSize(); - } - }; /* The following part of the "constructor" function can be thought of as @@ -141,7 +138,37 @@ Ox.load('UI', function() { `Ox.My.Box({size: 256}).appendTo(Ox.$body).showOptions()` */ + Ox.My.RoundedBox = function(options, self) { + + self = self || {}; + var that = Ox.My.Box({}, self); + that.defaults(Ox.extend(that.defaults(), { + radius: 16 + })) + .options(options || {}) + .update(function(key, value) { + if (key == 'radius') { + setRadius(); + } + }); + + setRadius(); + + function setRadius() { + that.css({ + MozBorderRadius: self.options.radius + 'px', + OBorderRadius: self.options.radius + 'px', + WebkitBorderRadius: self.options.radius + 'px' + }); + } + + return that; + + }; + + window.myBox = Ox.My.Box().appendTo(Ox.$body); + window.myRoundedBox = Ox.My.RoundedBox().appendTo(Ox.$body); return; Ox.My.Box = function(options, self) {