/* 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.Manager"); dojo.require("dojo.lang.array"); dojo.require("dojo.lang.func"); dojo.require("dojo.event.*"); // summary // Manager class for the widgets. // This is an internal class used by dojo; users shouldn't call this class directly. dojo.widget.manager = new function(){ this.widgets = []; this.widgetIds = []; // map of widgetId-->widget for widgets without parents (top level widgets) this.topWidgets = {}; var widgetTypeCtr = {}; var renderPrefixCache = []; this.getUniqueId = function (widgetType) { var widgetId; do{ widgetId = widgetType + "_" + (widgetTypeCtr[widgetType] != undefined ? ++widgetTypeCtr[widgetType] : widgetTypeCtr[widgetType] = 0); }while(this.getWidgetById(widgetId)); return widgetId; } this.add = function(widget){ //dojo.profile.start("dojo.widget.manager.add"); this.widgets.push(widget); // Opera9 uses ID (caps) if(!widget.extraArgs["id"]){ widget.extraArgs["id"] = widget.extraArgs["ID"]; } // FIXME: the rest of this method is very slow! if(widget.widgetId == ""){ if(widget["id"]){ widget.widgetId = widget["id"]; }else if(widget.extraArgs["id"]){ widget.widgetId = widget.extraArgs["id"]; }else{ widget.widgetId = this.getUniqueId(widget.ns+'_'+widget.widgetType); } } if(this.widgetIds[widget.widgetId]){ dojo.debug("widget ID collision on ID: "+widget.widgetId); } this.widgetIds[widget.widgetId] = widget; // Widget.destroy already calls removeById(), so we don't need to // connect() it here //dojo.profile.end("dojo.widget.manager.add"); } this.destroyAll = function(){ for(var x=this.widgets.length-1; x>=0; x--){ try{ // this.widgets[x].destroyChildren(); this.widgets[x].destroy(true); delete this.widgets[x]; }catch(e){ } } } // FIXME: we should never allow removal of the root widget until all others // are removed! this.remove = function(widgetIndex){ if(dojo.lang.isNumber(widgetIndex)){ var tw = this.widgets[widgetIndex].widgetId; delete this.widgetIds[tw]; this.widgets.splice(widgetIndex, 1); }else{ this.removeById(widgetIndex); } } // FIXME: suboptimal performance this.removeById = function(id) { if(!dojo.lang.isString(id)){ id = id["widgetId"]; if(!id){ dojo.debug("invalid widget or id passed to removeById"); return; } } for (var i=0; i.widget by convention dojo.ns.register(ns, ns + '.widget'); nsObj = dojo.ns.get(ns); } // allow the namespace to resolve the widget module if(nsObj){nsObj.resolve(widgetName);} // locate a widget implementation in the registered module for our current rendering environment impl = findImplementation(lowerCaseWidgetName, nsObj.module); if(impl){return(imps[lowerCaseWidgetName] = impl)}; // try to load a manifest to resolve this implemenation nsObj = dojo.ns.require(ns); if((nsObj)&&(nsObj.resolver)){ nsObj.resolve(widgetName); impl = findImplementation(lowerCaseWidgetName, nsObj.module); if(impl){return(imps[lowerCaseWidgetName] = impl)}; } // this is an error condition under new rules dojo.deprecated('dojo.widget.Manager.getImplementationName', 'Could not locate widget implementation for "' + widgetName + '" in "' + nsObj.module + '" registered to namespace "' + nsObj.name + '". ' + "Developers must specify correct namespaces for all non-Dojo widgets", "0.5"); // backward compat: if the user has not specified any namespace and their widget is not in dojo.widget.* // search registered widget packages [sic] // note: registerWidgetPackage itself is now deprecated for(var i=0; i 0) { return widgets[n]; } return widgets; } g("registerWidgetPackage"); g("getImplementation", "getWidgetImplementation"); g("getImplementationName", "getWidgetImplementationName"); dw.widgets = dwm.widgets; dw.widgetIds = dwm.widgetIds; dw.root = dwm.root; })();