Changeset 4420

Show
Ignore:
Timestamp:
06/17/06 01:39:37 (4 years ago)
Author:
alex
Message:

merging the final version of IBM's namespacing patch

Location:
trunk
Files:
4 added
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/buildscripts/buildUtil.js

    r4238 r4420  
    2929        load("../src/hostenv_rhino.js"); 
    3030        load("../src/bootstrap2.js"); 
     31 
    3132        // FIXME: is this really what we want to say? 
    3233        dojo.render.html.capable = true; 
     
    5960        dojo.hostenv.loadedUris.push("../src/bootstrap2.js"); 
    6061         
     62        dojo.hostenv.loadedUris.push("../src/namespace.js"); 
    6163         
    6264        if(dependencies["prefixes"]){ 
  • trunk/dojo.js

    r4185 r4420  
    2727         
    2828                tmps.push("bootstrap2.js"); 
     29                tmps.push("namespace.js"); 
    2930         
    3031                if((this["djConfig"])&&(djConfig["baseScriptUri"])){ 
  • trunk/src/loader.js

    r4275 r4420  
    272272        // things slightly diffrently 
    273273        var nsyms = modulename.split("."); 
     274        if(djConfig.autoLoadNamespace){ dojo.getNamespace(syms[0]); } 
    274275        if(last=="*"){ 
    275276                modulename = (nsyms.slice(0, -1)).join('.'); 
  • trunk/src/uri/Uri.js

    r2547 r4420  
    33dojo.uri = new function() { 
    44        this.joinPath = function() { 
    5                 // DEPRECATED: use the dojo.uri.Uri object instead 
     5                dojo.deprecated("dojo.uri.joinPath", "use the dojo.uri.Uri object instead", "0.4"); 
    66                var arr = []; 
    77                for(var i = 0; i < arguments.length; i++) { arr.push(arguments[i]); } 
     
    1313                return new dojo.uri.Uri(dojo.hostenv.getBaseScriptUri(), uri); 
    1414        } 
    15                  
     15 
     16        //returns a URI of a widget in a namespace, for example dojo.uri.nsUri("dojo","Editor"), or dojo.uri.nsUri("customNS","someWidget") 
     17        this.nsUri = function(namespace,uri){ 
     18                var ns = dojo.getNamespace(namespace); 
     19                if(!ns){ 
     20                        return null; 
     21                } 
     22                var loc = ns.location; 
     23                if(loc.lastIndexOf("/") != loc.length - 1){ 
     24                        loc += "/"; 
     25                } 
     26                return new dojo.uri.Uri(dojo.hostenv.getBaseScriptUri()+loc,uri); 
     27        }  
     28 
    1629        this.Uri = function (/*uri1, uri2, [...]*/) { 
    1730                // An object representing a Uri. 
  • trunk/src/widget/DomWidget.js

    r4398 r4420  
    390390 
    391391        getFragNodeRef: function(frag){ 
    392                 if( !frag || !frag["dojo:"+this.widgetType.toLowerCase()] ){ 
    393                         dojo.raise("Error: no frag for widget type " + this.widgetType + 
    394                                 ", id " + this.widgetId + " (maybe a widget has set it's type incorrectly)"); 
    395                 } 
    396                 return (frag ? frag["dojo:"+this.widgetType.toLowerCase()]["nodeRef"] : null); 
     392                if(!frag || !frag[this.namespace+":"+this.widgetType.toLowerCase()]){ 
     393                        dojo.raise("Error: no frag for widget type " + this.widgetType 
     394                                + " with namespace "+this.namespace + ", id " + this.widgetId 
     395                                + " (maybe a widget has set it's type incorrectly)"); 
     396                } 
     397                return frag ? frag[this.namespace+":"+this.widgetType.toLowerCase()]["nodeRef"] : null; 
    397398        }, 
    398399         
  • trunk/src/widget/Parse.js

    r4270 r4420  
    99         
    1010        this.createComponents = function(frag, parentComp){ 
    11                 var comps = [ ]; 
     11                var comps = []; 
    1212                var built = false; 
    1313                // if we have items to parse/create at this level, do it! 
     
    2020                                for(var x=0; x<tna.length; x++){ 
    2121                                        var ltn = (tna[x].replace(/^\s+|\s+$/g, "")).toLowerCase(); 
     22 
     23                                //if we don't already have a tag registered for this widget, try to load it's 
     24                                //namespace, if it has one 
     25                                if(!djTags[ltn] && dojo.getNamespace && dojo.lang.isString(ltn)){ 
     26                                    var pos = ltn.indexOf(":"); 
     27                                    if(pos > 0){ 
     28                                        var nsName = ltn.substring(0,pos); 
     29                                        var ns = dojo.getNamespace(nsName); 
     30                                        var tagName = ltn.substring(pos+1,ltn.length); 
     31                                        var domain = null; 
     32                                        var dojoDomain = frag[ltn]["dojoDomain"] || frag[ltn]["dojodomain"];  
     33                                        if(dojoDomain){ 
     34                                                domain = dojoDomain[0].value; 
     35                                        } 
     36                                        if(ns){ 
     37                                            ns.load(tagName, domain); 
     38                                        } 
     39                                    } 
     40                                } 
     41 
    2242                                        if(djTags[ltn]){ 
    2343                                                built = true; 
     
    2646                                                comps.push(ret); 
    2747                                        }else{ 
    28                                                 if((dojo.lang.isString(ltn))&&(ltn.substr(0, 5)=="dojo:")){ 
    29                                                         dojo.debug("no tag handler registed for type: ", ltn); 
    30                                                 } 
     48                                                if(dojo.lang.isString(ltn) && (ltn.substr(0, 5)=="dojo:")){ 
     49                                                        dojo.debug("no tag handler registered for type: ", ltn); 
     50                                    } //TODO: else? what if it's not dojo:? is it still an error? 
    3151                                        } 
    3252                                } 
     
    3454                }catch(e){ 
    3555                        dojo.debug("dojo.widget.Parse: error:", e); 
    36                         // throw(e); 
     56                        // throw e; 
    3757                        // IE is such a bitch sometimes 
    3858                } 
     
    199219                properties is an object of name value pairs 
    200220        */ 
    201         this.createComponentFromScript = function(nodeRef, componentName, properties){ 
    202                 var ltn = "dojo:" + componentName.toLowerCase(); 
     221        this.createComponentFromScript = function(nodeRef, componentName, properties, namespace){ 
     222                if(!namespace){ 
     223                        namespace = "dojo"; 
     224                } 
     225                var ltn = namespace + ":" + componentName.toLowerCase(); 
    203226                if(dojo.widget.tags[ltn]){ 
    204227                        properties.fastMixIn = true; 
    205228                        return [dojo.widget.tags[ltn](properties, this, null, null, properties)]; 
    206229                }else{ 
    207                         if(ltn.substr(0, 5)=="dojo:"){ 
    208                                 dojo.debug("no tag handler registed for type: ", ltn); 
    209                         } 
     230                        dojo.debug("no tag handler registered for type: ", ltn); 
    210231                } 
    211232        } 
     
    229250 * @param refNode  If the last argument is specified this node is used as 
    230251 *                 a reference for inserting this node into a DOM tree else 
    231  *                 it beomces the domNode 
     252 *                 it becomes the domNode 
    232253 * @param position The position to insert this widget's node relative to the 
    233254 *                 refNode argument 
    234255 * @return The new Widget object 
    235256 */ 
    236   
    237 dojo.widget.createWidget = function(name, props, refNode, position){ 
    238         var lowerCaseName = name.toLowerCase(); 
    239         var namespacedName = "dojo:" + lowerCaseName; 
    240         var isNode = ( dojo.byId(name) && (!dojo.widget.tags[namespacedName]) ); 
    241  
    242         // if we got a node or an unambiguious ID, build a widget out of it 
    243         if(     (arguments.length==1) && ((typeof name != "string")||(isNode)) ){ 
    244                 // we got a DOM node 
    245                 var xp = new dojo.xml.Parse(); 
    246                 // FIXME: we should try to find the parent! 
    247                 var tn = (isNode) ? dojo.byId(name) : name; 
    248                 return dojo.widget.getParser().createComponents(xp.parseElement(tn, null, true))[0]; 
    249         } 
    250  
    251         function fromScript (placeKeeperNode, name, props) { 
     257 
     258dojo.widget.createWidget = function(name, props, refNode, position, namespace){ 
     259        if(!namespace){ 
     260                namespace = "dojo"; 
     261        } 
     262 
     263        function fromScript(placeKeeperNode, name, props, namespace){ 
     264                if(!namespace){ 
     265                        namespace="dojo"; 
     266                } 
     267                var lowerCaseName = name.toLowerCase(); 
     268                var namespacedName = namespace+":" + lowerCaseName; 
    252269                props[namespacedName] = {  
    253270                        dojotype: [{value: lowerCaseName}], 
     
    256273                }; 
    257274                return dojo.widget.getParser().createComponentFromScript( 
    258                         placeKeeperNode, name, props, true); 
     275                        placeKeeperNode, name, props, namespace); 
    259276        } 
    260277 
     
    263280                        "argument order is now of the form " + 
    264281                        "dojo.widget.createWidget(NAME, [PROPERTIES, [REFERENCENODE, [POSITION]]])", "0.4"); 
    265                 return fromScript(name, props, refNode); 
     282                return fromScript(name, props, refNode, namespace); 
    266283        } 
    267284         
     
    284301                tn = refNode; 
    285302        } 
    286         var widgetArray = fromScript(tn, name, props); 
     303        var widgetArray = fromScript(tn, name, props, namespace); 
    287304        if (!widgetArray || !widgetArray[0] || typeof widgetArray[0].widgetType == "undefined") { 
    288305                throw new Error("createWidget: Creation of \"" + name + "\" widget failed."); 
  • trunk/src/widget/Widget.js

    r4332 r4420  
    3636        widgetType: "Widget", // used for building generic widgets 
    3737 
     38        namespace: "dojo", //defaults to 'dojo' 
     39 
    3840        toString: function() { 
    3941                return '[Widget ' + this.widgetType + ', ' + (this.widgetId || 'NO ID') + ']'; 
     
    8082        }, 
    8183 
    82         create: function(args, fragment, parentComp){ 
     84        create: function(args, fragment, parentComp, namespace){ 
     85                if(namespace){ 
     86                        this.namespace = namespace; 
     87                } 
    8388                // dojo.debug(this.widgetType, "create"); 
    8489                this.satisfyPropertySets(args, fragment, parentComp); 
     
    285290                                                // other object types intelligently? 
    286291 
    287                                                 // if we defined a URI, we probablt want to allow plain strings 
     292                                                // if we defined a URI, we probably want to allow plain strings 
    288293                                                // to override it 
    289294                                                if (this[x] instanceof dojo.uri.Uri){ 
     
    496501        // FIXME: we don't seem to be doing anything with this! 
    497502        // var propertySets = parser.getPropertySets(frag); 
    498         var localProperties = localProps || parser.parseProperties(frag["dojo:"+stype]); 
     503        var localProperties = localProps || parser.parseProperties(frag[frag.namespace+":"+stype]); 
    499504        // var tic = new Date(); 
    500505        var twidget = dojo.widget.manager.getImplementation(stype); 
     
    505510        } 
    506511        localProperties["dojoinsertionindex"] = insertionIndex; 
    507         // FIXME: we loose no less than 5ms in construction! 
    508         var ret = twidget.create(localProperties, frag, parentComp); 
     512        // FIXME: we lose no less than 5ms in construction! 
     513        var ret = twidget.create(localProperties, frag, parentComp, frag.namespace); 
    509514        // dojo.debug(new Date() - tic); 
    510515        return ret; 
    511516} 
    512517 
     518//TODO: add namespace support to this 
    513519/* 
    514520 * Create a widget constructor function (aka widgetClass) 
  • trunk/src/xml/Parse.js

    r3693 r4420  
    3131        function getDojoTagName (node) { 
    3232                var tagName = node.tagName; 
    33                 if (tagName.substr(0,5).toLowerCase() != "dojo:") { 
    34                          
    35                         if (tagName.substr(0,4).toLowerCase() == "dojo") { 
    36                                 // FIXME: this assuumes tag names are always lower case 
    37                                 return "dojo:" + tagName.substring(4).toLowerCase(); 
     33                if(tagName.substr(0,5).toLowerCase() == "dojo:"){ 
     34                        return tagName.toLowerCase(); 
     35                } 
     36 
     37                if(tagName.substr(0,4).toLowerCase() == "dojo"){ 
     38                        // FIXME: this assumes tag names are always lower case 
     39                        return "dojo:" + tagName.substring(4).toLowerCase(); 
     40                } 
     41 
     42                // allow lower-casing 
     43                var djt = node.getAttribute("dojoType") || node.getAttribute("dojotype"); 
     44                if(djt){ 
     45                        if(djt.indexOf(":")<0){ 
     46                                djt = "dojo:"+djt; 
    3847                        } 
     48                        return djt.toLowerCase(); 
     49                } 
    3950                 
    40                         // allow lower-casing 
    41                         var djt = node.getAttribute("dojoType") || node.getAttribute("dojotype"); 
    42                         if (djt) { return "dojo:" + djt.toLowerCase(); } 
    43                          
    44                         if (node.getAttributeNS && node.getAttributeNS(dojo.dom.dojoml,"type")) { 
    45                                 return "dojo:" + node.getAttributeNS(dojo.dom.dojoml,"type").toLowerCase(); 
    46                         } 
    47                         try { 
    48                                 // FIXME: IE really really doesn't like this, so we squelch 
    49                                 // errors for it 
    50                                 djt = node.getAttribute("dojo:type"); 
    51                         } catch (e) { /* FIXME: log? */ } 
     51                if(node.getAttributeNS && node.getAttributeNS(dojo.dom.dojoml,"type")){ 
     52                        return "dojo:" + node.getAttributeNS(dojo.dom.dojoml,"type").toLowerCase(); 
     53                } 
     54                try{ 
     55                        // FIXME: IE really really doesn't like this, so we squelch errors for it 
     56                        djt = node.getAttribute("dojo:type"); 
     57                }catch(e){ /* FIXME: log? */ } 
    5258 
    53                         if (djt) { return "dojo:"+djt.toLowerCase(); } 
    54                  
    55                         if (!dj_global["djConfig"] || !djConfig["ignoreClassNames"]) { 
    56                                 // FIXME: should we make this optionally enabled via djConfig? 
    57                                 var classes = node.className||node.getAttribute("class"); 
    58                                 // FIXME: following line, without check for existence of classes.indexOf 
    59                                 // breaks firefox 1.5's svg widgets 
    60                                 if (classes && classes.indexOf && classes.indexOf("dojo-") != -1) { 
    61                                         var aclasses = classes.split(" "); 
    62                                         for(var x=0; x<aclasses.length; x++){ 
    63                                                 if (aclasses[x].length > 5 && aclasses[x].indexOf("dojo-") >= 0) { 
    64                                                         return "dojo:"+aclasses[x].substr(5).toLowerCase(); 
    65                                                 } 
     59                if(djt){ return "dojo:"+djt.toLowerCase(); } 
     60         
     61                if(!dj_global["djConfig"] || !djConfig["ignoreClassNames"]){  
     62                        // FIXME: should we make this optionally enabled via djConfig? 
     63                        var classes = node.className||node.getAttribute("class"); 
     64                        // FIXME: following line, without check for existence of classes.indexOf 
     65                        // breaks firefox 1.5's svg widgets 
     66                        if(classes && classes.indexOf && classes.indexOf("dojo-") != -1){ 
     67                            var aclasses = classes.split (" "); 
     68                            for(var x=0; x<aclasses.length; x++){ 
     69                                if(aclasses[x].length > 5 && aclasses[x].indexOf("dojo-") >= 0){ 
     70                                    return "dojo:"+aclasses[x].substr(5).toLowerCase();  
    6671                                        } 
    6772                                } 
     
    6974                 
    7075                } 
     76 
    7177                return tagName.toLowerCase(); 
    7278        } 
     
    7480        this.parseElement = function(node, hasParentNodeSet, optimizeForDojoML, thisIdx){ 
    7581 
    76         // if parseWidgets="false" don't search inside this node for widgets 
    77         if (node.getAttribute("parseWidgets") == "false") { 
    78             return {}; 
    79         } 
    80  
    8182                // TODO: make this namespace aware 
    8283                var parsedNodeSet = {}; 
    8384 
     85                //There's a weird bug in IE where it counts end tags, e.g. </dojo:button> as nodes that should be parsed.  Ignore these 
     86                if(node.tagName && node.tagName.indexOf("/") == 0){ 
     87                        return null; 
     88                } 
     89 
    8490                var tagName = getDojoTagName(node); 
    8591                parsedNodeSet[tagName] = []; 
    86                 if((!optimizeForDojoML)||(tagName.substr(0,4).toLowerCase()=="dojo")){ 
    87                         var attributeSet = parseAttributes(node); 
     92                if(tagName.substr(0,4).toLowerCase()=="dojo"){ 
     93                        parsedNodeSet.namespace = "dojo"; 
     94                }else{ 
     95                        var pos = tagName.indexOf(":"); 
     96                        if(pos > 0){ 
     97                            parsedNodeSet.namespace = tagName.substring(0,pos); 
     98                        } 
     99                } 
     100 
     101                if(!optimizeForDojoML||dojo.getNamespace(parsedNodeSet.namespace)){ 
     102                        var attributeSet = this.parseAttributes(node); 
    88103                        for(var attr in attributeSet){ 
    89104                                if((!parsedNodeSet[tagName][attr])||(typeof parsedNodeSet[tagName][attr] != "array")){ 
     
    99114                        parsedNodeSet.tagName = tagName; 
    100115                        parsedNodeSet.index = thisIdx||0; 
     116 
     117                        //    dojo.debug("parseElement: set the element tagName = "+parsedNodeSet.tagName+" and namespace to "+parsedNodeSet.namespace); 
    101118                } 
    102          
     119 
    103120                var count = 0; 
    104                 var tcn, i = 0, nodes = node.childNodes; 
    105                 while(tcn = nodes[i++]){ 
     121                for(var i = 0; i < node.childNodes.length; i++){ 
     122                        var tcn = node.childNodes.item(i); 
    106123                        switch(tcn.nodeType){ 
    107124                                case  dojo.dom.ELEMENT_NODE: // element nodes, call this function recursively 
     
    148165                } 
    149166                //return (hasParentNodeSet) ? parsedNodeSet[node.tagName] : parsedNodeSet; 
     167                //if(parsedNodeSet.tagName)dojo.debug("parseElement: RETURNING NODE WITH TAGNAME "+parsedNodeSet.tagName); 
    150168                return parsedNodeSet; 
    151169        } 
    152170 
    153171        /* parses a set of attributes on a node into an object tree */ 
    154         function parseAttributes(node) { 
     172        this.parseAttributes = function(node){ 
    155173                // TODO: make this namespace aware 
    156174                var parsedAttributeSet = {}; 
  • trunk/tests/widget/test_Accordion.html

    r3407 r4420  
    1010</script> 
    1111<script type="text/javascript" src="../../dojo.js"></script> 
    12 <script language="JavaScript" type="text/javascript"> 
    13         dojo.require("dojo.widget.Tree"); 
    14         dojo.require("dojo.widget.TreeNode"); 
    15         dojo.require("dojo.widget.AccordionContainer"); 
    16         dojo.require("dojo.widget.ContentPane"); 
     12<script type="text/javascript"> 
     13        dojo.require("dojo.widget.*"); 
    1714</script> 
    1815