Ticket #5647: 5647_html_set_dijitCP.patch

File 5647_html_set_dijitCP.patch, 5.5 kB (added by sfoster, 4 months ago)

[PATCH] [CLA] preview of dijit.layout.ContentPane? refactor to use dojo.html._ContentSetter

  • layout/ContentPane.js

     
    55 
    66dojo.require("dojo.parser"); 
    77dojo.require("dojo.string"); 
     8dojo.require("dojo.html"); 
    89dojo.requireLocalization("dijit", "loading"); 
    910 
    1011dojo.declare( 
     
    3334        // href: String 
    3435        //              The href of the content that displays now. 
    3536        //              Set this at construction if you want to load data externally when the 
    36         //              pane is shown.  (Set preload=true to load it immediately.) 
     37        //              pane is shown.  (Set preload=true to load it immediately.) 
    3738        //              Changing href after creation doesn't have any effect; use attr('href', ...); 
    3839        href: "", 
    3940 
     
    128129 
    129130        _checkIfSingleChild: function(){ 
    130131                // summary: 
    131                 //      Test if we have exactly one widget as a child, and if so assume that we are a container for that widget, 
     132                //      Test if we have exactly one widget as a child, and if so assume that we are a container for that widget, 
    132133                //      and should propogate startup() and resize() calls to it. 
    133134 
    134135                // TODO: if there are two child widgets (a data store and a TabContainer, for example), 
     
    154155        }, 
    155156 
    156157        setHref: function(/*String|Uri*/ href){ 
    157                 dojo.deprecated("dijit.layout.ContentPane.setHref() is deprecated.  Use attr('href', ...) instead.", "", "2.0"); 
     158                dojo.deprecated("dijit.layout.ContentPane.setHref() is deprecated.      Use attr('href', ...) instead.", "", "2.0"); 
    158159                return this.attr("href", href); 
    159160        }, 
    160161        _setHrefAttr: function(/*String|Uri*/ href){ 
     
    181182        }, 
    182183        _setContentAttr: function(/*String|DomNode|Nodelist*/data){ 
    183184                // summary: 
    184                 //              Hook to make attr("content", ...) work. 
     185                //              Hook to make attr("content", ...) work. 
    185186                //              Replaces old content with data content, include style classes from old content 
    186187                //      data: 
    187188                //              the new Content may be String, DomNode or NodeList 
     
    200201 
    201202                this._isDownloaded = false; // must be set after _setContent(..), pathadjust in dojox.layout.ContentPane 
    202203 
    203                 if(this.parseOnLoad){ 
    204                         this._createSubWidgets(); 
    205                 } 
    206  
    207204                if(this.doLayout != "false" && this.doLayout !== false){ 
    208205                        this._checkIfSingleChild(); 
    209206                        if(this._singleChild && this._singleChild.resize){ 
     
    293290 
    294291                var displayState = this._isShown(); 
    295292 
    296                 if(this.href &&  
     293                if(this.href &&  
    297294                        ( 
    298295                                forceLoad || 
    299296                                (this.preload && !this.isLoaded && !this._xhrDfd) || 
     
    367364        }, 
    368365 
    369366        _setContent: function(cont){ 
     367                // summary:  
     368                //      insert the content into the container node,  
     369 
    370370                // first get rid of child widgets 
    371371                this.destroyDescendants(); 
     372                 
     373                // dojo.html.set will take care of the rest of the details 
     374                // we provide an overide for the error handling to ensure the widget gets the errors  
     375                // configure the setter instance with only the relevant widget instance properties 
     376                // NOTE: unless we hook into attr, or provide property setters for each property,  
     377                // we need to re-configure the ContentSetter with each use 
     378                var setter = this._contentSetter;  
     379                if(! (setter && setter instanceof dojo.html._ContentSetter)) { 
     380                        setter = this._contentSetter = new dojo.html._ContentSetter({ 
     381                                node: this.containerNode, 
     382                                _onError: dojo.hitch(this, this._onError), 
     383                                onContentError: dojo.hitch(this, function(e){ 
     384                                        // fires if a domfault occurs when we are appending this.errorMessage 
     385                                        // like for instance if domNode is a UL and we try append a DIV 
     386                                        var errMess = this.onContentError(e); 
     387                                        try{ 
     388                                                this.containerNode.innerHTML = errMess; 
     389                                        }catch(e){ 
     390                                                console.error('Fatal '+this.id+' could not change content due to '+e.message, e); 
     391                                        } 
     392                                })/*, 
     393                                _onError */ 
     394                        }); 
     395                }; 
    372396 
    373                 try{ 
    374                         // ... and then get rid of child dom nodes 
    375                         var node = this.containerNode; 
    376                         while(node.firstChild){ 
    377                                 dojo._destroyElement(node.firstChild); 
    378                         } 
    379                         if(typeof cont == "string"){ 
    380                                 // dijit.ContentPane does only minimal fixes, 
    381                                 // No pathAdjustments, script retrieval, style clean etc 
    382                                 // some of these should be available in the dojox.layout.ContentPane 
    383                                 if(this.extractContent){ 
    384                                         var match = cont.match(/<body[^>]*>\s*([\s\S]+)\s*<\/body>/im); 
    385                                         if(match){ cont = match[1]; } 
    386                                 } 
    387                                 node.innerHTML = cont; 
    388                         }else if(cont.domNode){ 
    389                                 // single widget child 
    390                                 node.appendChild(cont.domNode); 
    391                         }else{ 
    392                                 // domNode or NodeList 
    393                                 if(cont.nodeType){ // domNode (htmlNode 1 or textNode 3) 
    394                                         node.appendChild(cont); 
    395                                 }else{// nodelist or array such as dojo.Nodelist 
    396                                         dojo.forEach(cont, function(n){ 
    397                                                 node.appendChild(n.cloneNode(true)); 
    398                                         }); 
    399                                 } 
    400                         } 
    401                 }catch(e){ 
    402                         // check if a domfault occurs when we are appending this.errorMessage 
    403                         // like for instance if domNode is a UL and we try append a DIV 
    404                         var errMess = this.onContentError(e); 
    405                         try{ 
    406                                 node.innerHTML = errMess; 
    407                         }catch(e){ 
    408                                 console.error('Fatal '+this.id+' could not change content due to '+e.message, e); 
    409                         } 
    410                 } 
     397                var setterParams = dojo.mixin({ 
     398                        cleanContent: this.cleanContent,  
     399                        extractContent: this.extractContent,  
     400                        parseContent: this.parseOnLoad  
     401                }, this._contentSetterParams || {}); 
     402                 
     403                dojo.mixin(setter, setterParams);  
     404                 
     405                setter.set( (dojo.isObject(cont) && cont.domNode) ? cont.domNode : cont ); 
     406 
     407                // setter params must be pulled afresh from the ContentPane each time 
     408                delete this._contentSetterParams 
    411409        }, 
    412410 
    413411        _onError: function(type, err, consoleText){ 
     
    431429                } 
    432430        }, 
    433431 
     432 
    434433        // EVENT's, should be overide-able 
    435434        onLoad: function(e){ 
    436435                // summary: