home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / toolkit.jar / content / global / radioBindings.xml < prev    next >
Extensible Markup Language  |  2001-02-14  |  5KB  |  146 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="xulBindings"
  4.    xmlns="http://www.mozilla.org/xbl"
  5.    xmlns:html="http://www.w3.org/1999/xhtml"
  6.    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  7.  
  8.   <binding id="radio" extends="chrome://global/content/xulBindings.xml#checkbox">
  9.     <implementation>
  10.       <property name="data" onset="this.setAttribute('data',val); return val;"
  11.                             onget="return this.getAttribute('data');"/>
  12.       <property name="group" onset="this.setAttribute('group',val); return val;"
  13.                             onget="return this.getAttribute('group');"/>
  14.     </implementation>
  15.   </binding>
  16.   
  17.   <binding id="radiogroup" extends="xul:box">
  18.  
  19.     <implementation>
  20.       <property name="data" onset="this.setAttribute('data',val); return val;"
  21.                             onget="return this.getAttribute('data');"/>
  22.       <property name="selectedItem">
  23.         <getter>
  24.         <![CDATA[
  25.           var groupElements = this.getElementsByAttribute( "group", this.id );
  26.           for( var i = 0; i < groupElements.length; i++ )
  27.             {
  28.               if( groupElements[i].checked || 
  29.                   groupElements[i].getAttribute( "checked" ) == "true" )
  30.                 return groupElements[i];
  31.             }
  32.         ]]>
  33.         </getter>
  34.         <setter>
  35.         <![CDATA[
  36.           var aDOMElement = val;
  37.           if (this.getAttribute("focused") == "true") 
  38.             val.setAttribute("focused", "true");
  39.           this.data = aDOMElement.data;
  40.  
  41.           aDOMElement.checked = true;
  42.           
  43.           // uncheck all other group nodes
  44.           var groupElements = this.getElementsByAttribute( "group", aDOMElement.group );
  45.           for( var i = 0; i < groupElements.length; i++ )
  46.             {
  47.               if( groupElements[i] != aDOMElement && groupElements[i].checked )
  48.                 {
  49.                   groupElements[i].checked = false;
  50.                   groupElements[i].removeAttribute("checked");
  51.                   groupElements[i].removeAttribute("focused");
  52.                 }
  53.             }
  54.           return val;
  55.         ]]>
  56.         </setter>        
  57.       </property>
  58.       <method name="checkAdjacentElement">
  59.         <parameter name="aNextFlag"/>
  60.         <body>
  61.         <![CDATA[
  62.           var radios = this.getElementsByTagName("radio");
  63.           for (var i = 0; i < radios.length; i++ ) {
  64.             if (radios[i] != this.selectedItem) 
  65.               continue;
  66.             if (aNextFlag) {
  67.               var index = i + 1 < radios.length ? i + 1 : 0;
  68.               this.selectedItem = radios[index];
  69.               break;
  70.             }
  71.             else {
  72.               
  73.               var index = i - 1 >= 0 ? i - 1 : radios.length - 1;
  74.               this.selectedItem = radios[index];
  75.               break;
  76.             }
  77.           }
  78.         ]]>
  79.         </body>
  80.       </method>
  81.     </implementation>
  82.     <handlers>
  83.       <handler event="click">
  84.        <![CDATA[
  85.         try
  86.           {
  87.             if (!event.target.disabled && 
  88.                 event.target.localName == "radio" &&
  89.                 event.button == 1)
  90.               this.selectedItem = event.target;
  91.           }
  92.         catch(e)
  93.           {
  94.           }
  95.        ]]>
  96.       </handler>
  97.       <handler event="keypress" key=" ">
  98.        <![CDATA[
  99.         try
  100.           {
  101.             if (!event.target.disabled && event.target.localName == "radio")
  102.               this.selectedItem = event.target;
  103.           }
  104.         catch(e)
  105.           {
  106.           }
  107.        ]]>
  108.       </handler>    
  109.       
  110.       <!-- keyboard navigation -->
  111.       <!-- Here's how keyboard navigation works in radio groups on Windows:
  112.            The group takes 'focus'
  113.            The user is then free to navigate around inside the group
  114.            using the arrow keys. Accessing previous or following radio buttons
  115.            is done solely through the arrow keys and not the tab button. Tab
  116.            takes you to the next widget in the tab order -->
  117.       <handler event="keypress" keycode="VK_UP">
  118.         this.checkAdjacentElement(false);
  119.       </handler>
  120.       <handler event="keypress" keycode="VK_LEFT">
  121.         this.checkAdjacentElement(false);
  122.       </handler>
  123.       <handler event="keypress" keycode="VK_DOWN">
  124.         this.checkAdjacentElement(true);
  125.       </handler>
  126.       <handler event="keypress" keycode="VK_RIGHT">
  127.         this.checkAdjacentElement(true);
  128.       </handler>
  129.  
  130.       <!-- set a focused attribute on the selected item when the group
  131.            receives focus so that we can style it as if it were focused even though
  132.            it is not (Windows platform behaviour is for the group to receive focus,
  133.            not the item -->
  134.       <handler event="focus">
  135.         this.setAttribute("focused", "true");
  136.         this.selectedItem.setAttribute("focused", "true");
  137.       </handler>
  138.       <handler event="blur">
  139.         this.removeAttribute("focused");
  140.         this.selectedItem.removeAttribute("focused");
  141.       </handler>
  142.     </handlers>
  143.   </binding>
  144.   
  145. </bindings>
  146.