/* Copyright (c) 2004-2006, The Dojo Foundation All Rights Reserved. Licensed under the Academic Free License version 2.1 or above OR the modified BSD license. For more information on Dojo licensing, see: http://dojotoolkit.org/community/licensing.shtml */ dojo.provide("dojo.widget.Parse"); dojo.require("dojo.widget.Manager"); dojo.require("dojo.dom"); // // dojoML parser should be moved out of 'widget', codifying the difference between a 'component' // and a 'widget'. A 'component' being anything that can be generated from a tag. // // a particular dojoML tag would be handled by a registered tagHandler with a hook for a default handler // if the widget system is loaded, a widget builder would be attach itself as the default handler // // widget tags are no longer registered themselves: // they are now arbitrarily namespaced, so we cannot register them all, and the non-prefixed portions // are no longer guaranteed unique // // therefore dojo.widget.tags should go with this parser code out of the widget module // dojo.widget.Parse = function(/*Object*/fragment){ this.propertySetsList = []; this.fragment = fragment; this.createComponents = function(/*Object*/frag, /*Object*/parentComp){ var comps = []; var built = false; // if we have items to parse/create at this level, do it! try{ if(frag && frag.tagName && (frag != frag.nodeRef)){ // these are in fact, not ever for widgets per-se anymore, // but for other markup elements (aka components) var djTags = dojo.widget.tags; // we split so that you can declare multiple // non-destructive components from the same ctor node var tna = String(frag.tagName).split(";"); for(var x=0; x -1) ? name.substring(0,pos) : "dojo"; if(pos > -1){ name = name.substring(pos+1); } var lowerCaseName = name.toLowerCase(); var namespacedName = ns + ":" + lowerCaseName; isNode = (dojo.byId(name) && !dojo.widget.tags[namespacedName]); } if((arguments.length == 1) && (isNode || !isNameStr)){ // we got a DOM node var xp = new dojo.xml.Parse(); // FIXME: we should try to find the parent! var tn = isNode ? dojo.byId(name) : name; return dojo.widget.getParser().createComponents(xp.parseElement(tn, null, true))[0]; } function fromScript(placeKeeperNode, name, props, ns){ props[namespacedName] = { dojotype: [{value: lowerCaseName}], nodeRef: placeKeeperNode, fastMixIn: true }; props.ns = ns; return dojo.widget.getParser().createComponentFromScript(placeKeeperNode, name, props, ns); } props = props||{}; var notRef = false; var tn = null; var h = dojo.render.html.capable; if(h){ tn = document.createElement("span"); } if(!refNode){ notRef = true; refNode = tn; if(h){ dojo.body().appendChild(refNode); } }else if(position){ dojo.dom.insertAtPosition(tn, refNode, position); }else{ // otherwise don't replace, but build in-place tn = refNode; } var widgetArray = fromScript(tn, name.toLowerCase(), props, ns); if( (!widgetArray)||(!widgetArray[0])|| (typeof widgetArray[0].widgetType == "undefined") ){ throw new Error("createWidget: Creation of \"" + name + "\" widget failed."); } try{ if(notRef && widgetArray[0].domNode.parentNode){ widgetArray[0].domNode.parentNode.removeChild(widgetArray[0].domNode); } }catch(e){ /* squelch for Safari */ dojo.debug(e); } return widgetArray[0]; // Widget }