source: trunk/template-common/inputfix.htc @ 1608

Last change on this file since 1608 was 1608, checked in by rvelices, 17 years ago

fix potential incompatibility with events directly in the template
(use attachEvent instead of onfocus)

File size: 1.0 KB
Line 
1<public:attach event="oncontentready"  onevent="fixElements()" />
2
3<script langage=javascript>
4
5function setFocusStyle()
6{
7  window.event.srcElement.className += ' focus';
8}
9
10function setBlurStyle()
11{
12  window.event.srcElement.className = window.event.srcElement.className.replace( ' focus', ' nofocus');
13}
14
15function setClassFromType()
16{
17  this.className += ' ' + this.type;
18}
19
20function fixElements()
21{
22  for ( var i=0; i<this.elements.length; i++ )
23  {
24    var elem=this.elements[i];
25    switch ( elem.tagName )
26    {
27      case "INPUT":
28        elem.className += ' ' + elem.type;
29        if ( (elem.type != "radio") && (elem.type != "checkbox") )
30        { /* setting focus/nofocus on those is a mess to handle in css */
31          elem.attachEvent( 'onfocus', setFocusStyle );
32          elem.attachEvent( 'onblur', setBlurStyle );
33        }
34      break;
35      case "SELECT":
36      case "TEXTAREA":
37        elem.attachEvent( 'onfocus', setFocusStyle );
38        elem.attachEvent( 'onblur', setBlurStyle );
39    }
40  }
41}
42</script>
Note: See TracBrowser for help on using the repository browser.