Changeset 5544
- Timestamp:
- 05/09/08 21:12:14 (4 months ago)
- Location:
- branches/ui-experimental/base
- Files:
-
- 2 modified
-
ui.core.js (modified) (3 diffs)
-
ui.test.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/ui-experimental/base/ui.core.js
r5526 r5544 77 77 78 78 // add widget prototype 79 $[namespace][name].prototype = $.extend({}, widgetPrototype, prototype); 79 var proto = ($[namespace][name].prototype = widgetPrototype); 80 var extend = prototype.extend || []; 81 extend = (typeof extend == "string" ? extend.split(/,?\s+/) : extend); 82 $.each(extend, function(i, base) { 83 // TODO: add support for non-namespaced bases 84 var parts = base.split('.'), 85 baseNamespace = parts[0], 86 baseName = parts[1]; 87 88 // add methods from base object 89 proto[baseName] = {}; 90 $.each($[baseNamespace][baseName], function(prop, val) { 91 proto[baseName][prop] = $.isFunction(val) 92 ? function() { 93 val.apply(proto, arguments); 94 } : val; 95 }); 96 97 // add methods from plugin prototype 98 $.each(prototype[baseName], function(prop, val) { 99 proto[baseName][prop] = $.isFunction(val) 100 ? function() { 101 val.apply(proto, arguments); 102 } : val; 103 }); 104 //basePrototypes[baseName] = $[baseNamespace][baseName]; 105 }); 106 $.extend(true, proto, prototype); 80 107 }; 81 108 /* 82 109 $.widget.merge = function() { 83 110 var ret = {}; … … 95 122 }; 96 123 124 $.widget('ui.funky', { 125 extend: { 126 mouse: $.ui.mouse, 127 keyboard: $.ui.keybaord 128 }, 129 130 init: function() { 131 this.mouse.init(); 132 this.keyboard.init(); 133 134 // funky specific init 135 }, 136 destroy: function() { 137 this.mouse.destroy(); 138 this.keyboard.destroy(); 139 140 // funky specific destroy 141 }, 142 143 foo: function() { 144 // something funky 145 }, 146 147 mouse: { 148 start: function() { 149 // funky stuff for $.ui.mouse to use on start 150 } 151 } 152 }); 153 154 $.widget('ui.draggable', { 155 init: function() { 156 this.mouse.init.apply(this, arguments); 157 // draggable specific stuff 158 }, 159 160 foo: function() { 161 // something draggable specific 162 }, 163 164 mouse: $.extend($.ui.mouse, { 165 // draggable specific functions for the mouse code to work with 166 }) 167 }); 168 */ 97 169 $.ui.color = { 98 170 init: function() { 99 171 var self = this; 100 172 this.element.bind('click', function() { 101 self.color ize();173 self.color.colorize(); 102 174 }); 103 175 }, … … 105 177 this.element.css('background-color', color); 106 178 }, 107 colorize: function() {179 random: function() { 108 180 var r = Math.floor(Math.random() * 255), 109 181 g = Math.floor(Math.random() * 255), 110 182 b = Math.floor(Math.random() * 255); 111 this.bg('rgb(' + r + ', ' + g + ', ' + b + ')'); 183 return 'rgb(' + r + ', ' + g + ', ' + b + ')'; 184 }, 185 colorize: function() { 186 this.color.bg(this.color.random()); 112 187 }, 113 188 colorize2: function() { 114 this. bg(this.options.color.mainColor);189 this.color.bg(this.options.color.mainColor); 115 190 }, 116 191 colorize3: function() { 117 this. bg(this.color.color3.apply(this, arguments));192 this.color.bg(this.color.red()); 118 193 } 119 194 }; -
branches/ui-experimental/base/ui.test.js
r5526 r5544 1 1 ;(function($) { 2 $.widget('ui.test', $.widget.merge({}, $.ui.color, { 2 $.widget('ui.test', { 3 extend: 'ui.color', 4 3 5 init: function() { 4 console.log('test initialized');6 this.color.init(); 5 7 }, 6 8 black: function() { … … 8 10 }, 9 11 color: { 10 color3: function() {11 return '# 00f';12 red: function() { 13 return '#f00'; 12 14 } 13 15 } 14 }) );16 }); 15 17 16 18 $.ui.test.defaults = { 17 19 color: { 18 mainColor: '# f00'20 mainColor: '#00f' 19 21 } 20 22 };
