Bug Tracker

Changeset 5544

Show
Ignore:
Timestamp:
05/09/08 21:12:14 (4 months ago)
Author:
scott.gonzalez
Message:

UI experimental: Totally busted plugin inheritance.

Location:
branches/ui-experimental/base
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/ui-experimental/base/ui.core.js

    r5526 r5544  
    7777         
    7878        // 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); 
    80107    }; 
    81      
     108    /* 
    82109    $.widget.merge = function() { 
    83110        var ret = {}; 
     
    95122    }; 
    96123     
     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    */ 
    97169    $.ui.color = { 
    98170        init: function() { 
    99171            var self = this; 
    100172            this.element.bind('click', function() { 
    101                 self.colorize(); 
     173                self.color.colorize(); 
    102174            }); 
    103175        }, 
     
    105177            this.element.css('background-color', color); 
    106178        }, 
    107         colorize: function() { 
     179        random: function() { 
    108180            var r = Math.floor(Math.random() * 255), 
    109181                g = Math.floor(Math.random() * 255), 
    110182                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()); 
    112187        }, 
    113188        colorize2: function() { 
    114             this.bg(this.options.color.mainColor); 
     189            this.color.bg(this.options.color.mainColor); 
    115190        }, 
    116191        colorize3: function() { 
    117             this.bg(this.color.color3.apply(this, arguments)); 
     192            this.color.bg(this.color.red()); 
    118193        } 
    119194    }; 
  • branches/ui-experimental/base/ui.test.js

    r5526 r5544  
    11;(function($) { 
    2     $.widget('ui.test', $.widget.merge({}, $.ui.color, { 
     2    $.widget('ui.test', { 
     3        extend: 'ui.color', 
     4         
    35        init: function() { 
    4             console.log('test initialized'); 
     6            this.color.init(); 
    57        }, 
    68        black: function() { 
     
    810        }, 
    911        color: { 
    10             color3: function() { 
    11                 return '#00f'; 
     12            red: function() { 
     13                return '#f00'; 
    1214            } 
    1315        } 
    14     })); 
     16    }); 
    1517     
    1618    $.ui.test.defaults = { 
    1719        color: { 
    18             mainColor: '#f00' 
     20            mainColor: '#00f' 
    1921        } 
    2022    };