/* 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.RadioGroup"); dojo.require("dojo.lang.common"); dojo.require("dojo.event.browser"); dojo.require("dojo.html.selection"); dojo.require("dojo.widget.*"); dojo.require("dojo.widget.HtmlWidget"); dojo.widget.defineWidget( "dojo.widget.RadioGroup", dojo.widget.HtmlWidget, function(){ // summary: // Widget that provides useful/common functionality that may be desirable // when interacting with ul/ol html lists. // // The core behaviour of the lists this widget manages is expected to be determined // by the css class names defined: // // "radioGroup" - Applied to main ol or ul // "selected" - Applied to the currently selected li, if any. // "itemContent" - Applied to the content contained in a li, this widget embeds a span // within each
to contain the contents of the li. // This widget was mostly developed under supervision/guidance from Tom Trenka. // selectedItem: DomNode: Currently selected li, if any this.selectedItem=null; // items: DomNode[]: Array of li nodes being managed by widget this.items=[]; // selected: String[]: List of optional ids specifying which li's should be selected by default this.selected=[]; // groupCssClass: String: Css class applied to main ol or ul, value is "radioGroup" this.groupCssClass="radioGroup"; // selectedCssClass: String: Css class applied to the currently selected li, if any. value of "selected" this.selectedCssClass="selected"; // itemContentCssClass: String: Css class Applied to the content contained in a li, this widget embeds a span // within each to contain the contents of the li. value is "itemContent" this.itemContentCssClass="itemContent"; }, { isContainer:false, templatePath: null, templateCssPath: null, postCreate:function(){ // summary: Parses content of widget and sets up the default state of any // default selections / etc. The onSelect function will also be fired for any // default selections. this._parseStructure(); dojo.html.addClass(this.domNode, this.groupCssClass); this._setupChildren(); dojo.event.browser.addListener(this.domNode, "onclick", dojo.lang.hitch(this, "onSelect")); if (this.selectedItem){ this._selectItem(this.selectedItem); } }, _parseStructure: function() { // summary: Sets local radioGroup and items properties, also validates // that domNode contains an expected list. // // Exception raised if a ul or ol node can't be found in this widgets domNode. if(this.domNode.tagName.toLowerCase() != "ul" && this.domNode.tagName.toLowerCase() != "ol") { dojo.raise("RadioGroup: Expected ul or ol content."); return; } this.items=[]; // reset the items. var nl=this.domNode.getElementsByTagName("li"); for (var i=0; i