diff --git a/examples/ui/widget_design_patterns/css/example.css b/examples/ui/widget_design_patterns/css/example.css index f3cb4ac9..0ca347f9 100644 --- a/examples/ui/widget_design_patterns/css/example.css +++ b/examples/ui/widget_design_patterns/css/example.css @@ -1,6 +1,9 @@ .OxMyBox { float: left; } +.OxMyBox .OxMyText { + padding: 4px; +} .OxMyInvertibleBox { cursor: pointer; } \ No newline at end of file diff --git a/examples/ui/widget_design_patterns/js/example.js b/examples/ui/widget_design_patterns/js/example.js index 4816a2e3..6a614179 100644 --- a/examples/ui/widget_design_patterns/js/example.js +++ b/examples/ui/widget_design_patterns/js/example.js @@ -117,12 +117,13 @@ Ox.load(['Image', 'UI'], function() { Next, we define the widgets public methods, as properties of `that`. (Note that unlike private methods, they are not hoisted.) */ - that.showOptions = function() { + that.displayText = function(text) { /* As there isn't much to do yet, this method just displays the widget's options. */ - that.html(JSON.stringify(self.options).replace(/([,:])/g, '$1 ')); + that.empty(); + text && that.append($('
- Ox.My.RoundedBox({ - color: [255, 0, 0], - radius: 32 - }) - .appendTo(Ox.$body) - .options({size: 256}) - .showOptions(); -- */ - - /* - Its also possible to pass objects or other elements as options - */ - Ox.My.MetaBox = function(options, self) { - - self = self || {}; - var that = Ox.My.Box({}, self); - that.defaults(Ox.extend(that.defaults(), { - boxes: [] - })) - .options(options || {}); - - self.options.boxes.forEach(function(box) { - that.append(box); - }); - - return that; - - }; - - /* - Now its time to create some boxes for this demo: - */ - window.boxes = Ox.My.MetaBox({ - boxes: [ - Ox.My.Box({ - color: [64, 128, 255] + (function() { + var h = Ox.random(360), s = 1, l = 0.5; + window.My = {}; + My.$backgroundBox = Ox.My.Box({ + size: [256, 256] + }) + .append( + My.$box = Ox.My.Box({ + color: Ox.rgb(h, s, l) }), - Ox.My.RoundedBox({ - color: [255, 128, 64] + My.$invertibleBox = Ox.My.InvertibleBox({ + color: Ox.rgb(h + 120, s, l) + }), + My.$metaBox = Ox.My.MetaBox({ + color: Ox.range(2).map(function(y) { + return Ox.range(3).map(function(x) { + return Ox.rgb(h + x * 60 + y * 180, s, l); + }); + }) + }), + My.$pixelBox = Ox.My.PixelBox({ + color: Ox.rgb(h + 120, s, l) }) - ], - size: 384 - }) - .appendTo(Ox.$body); + ) + .appendTo(Ox.$body); + My.$imageBox = Ox.My.ImageBox({ + image: 'png/pandora32.png', + size: [256, 256] + }) + .appendTo(Ox.$body); + Ox.forEach(My, function($element, name) { + $element.bindEvent({ + invert: function() { + My.$box.displayText(name[1].toUpperCase() + name.slice(2)); + } + }) + }); + }()); + });