Changeset 14602

Show
Ignore:
Timestamp:
07/28/08 08:30:39 (6 months ago)
Author:
dante
Message:

fixes #7298 - add a placeAt method to _Widget for simple (and chainable) dom manipulation on a per-widget basis.
!strict

Location:
dijit/trunk
Files:
1 added
1 modified

Legend:

Unmodified
Added
Removed
  • dijit/trunk/_Widget.js

    r14558 r14602  
    562562 
    563563                if(this.containerNode){ 
    564                         var list= dojo.query('[widgetId]', this.containerNode); 
     564                        var list = dojo.query('[widgetId]', this.containerNode); 
    565565                        return list.map(dijit.byNode);          // Array 
    566566                }else{ 
     
    580580                //              and registers for disconnect() on widget destroy. 
    581581                //      description: 
    582                 //              provide widget-specific analog to dojo.connect, except with the 
     582                //              Provide widget-specific analog to dojo.connect, except with the 
    583583                //              implicit use of this widget as the target object. 
    584584                //              This version of connect also provides a special "ondijitclick" 
     
    656656                //              and false if not 
    657657                return this.focus && (dojo.style(this.domNode, "display") != "none"); 
     658        }, 
     659         
     660        placeAt: function(/* String|DomNode|_Widget */reference, /* String?|Int? */position){ 
     661                // summary: Place this widget's domNode reference somewhere in the DOM based 
     662                //              on standard dojo.place conventions, or passing a Widget reference that 
     663                //              contains and addChild member. 
     664                // 
     665                // description: 
     666                //              A convenience function provided in all _Widgets, providing a simple 
     667                //              shorthand mechanism to put an existing (or newly created) Widget 
     668                //              somewhere in the dom, and allow chaining. 
     669                // 
     670                //      reference:  
     671                //              The String id of a domNode, a domNode reference, or a reference to a Widget posessing  
     672                //              an addChild method. 
     673                // 
     674                //      position:  
     675                //              If passed a string or domNode reference, the position argument 
     676                //              accepts a string just as dojo.place does, one of: "first", "last",  
     677                //              "before", or "after".  
     678                // 
     679                //              If passed a _Widget reference, and that widget reference has an ".addChild" method,  
     680                //              it will be called passing this widget instance into that method, supplying the optional 
     681                //              position index passed. 
     682                // 
     683                // example: 
     684                // |    // create a Button with no srcNodeRef, and place it in the body: 
     685                // |    var button = new dijit.form.Button({ label:"click" }).placeAt(dojo.body()); 
     686                // |    // now, 'button' is still the widget reference to the newly created button 
     687                // |    dojo.connect(button, "onClick", function(e){ console.log('click'); }); 
     688                // 
     689                // example: 
     690                // |    // create a button out of a node with id="src" and append it to id="wrapper": 
     691                // |    var button = new dijit.form.Button({},"src").placeAt("wrapper"); 
     692                // 
     693                // example: 
     694                // |    // place a new button as the first element of some div 
     695                // |    var button = new dijit.form.Button({ label:"click" }).placeAt("wrapper","first"); 
     696                // 
     697                // example:  
     698                // |    // create a contentpane and add it to a TabContainer 
     699                // |    var tc = dijit.byId("myTabs"); 
     700                // |    new dijit.layout.ContentPane({ href:"foo.html", title:"Wow!" }).placeAt(tc) 
     701                // 
     702                // example:  
     703                // |    // add a new pane to a BorderContainer and set the content in one pass.  
     704                // |    var bc = dijit.byId("bc1"); 
     705                // |    new dijit.layout.ContentPane({ 
     706                // |            region:"left", 
     707                // |            style:"width:100px" 
     708                // |    }).placeAt(bc).setContent("<p>wowzers</p>"); 
     709                // 
     710                if(reference["declaredClass"] && reference["addChild"]){ 
     711                        reference.addChild(this, position); 
     712                }else{ 
     713                        var n = dojo.byId(reference); 
     714                        dojo.place(this.domNode, n, position || "last"); 
     715                } 
     716                return this; 
    658717        } 
     718 
    659719});