From 8315756720eee805c8422277363ef3d6069c1c60 Mon Sep 17 00:00:00 2001 From: Romain Louis Date: Fri, 2 Nov 2007 03:38:39 +0000 Subject: [PATCH] DropdownTimeField javascript adding git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@44178 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- javascript/DropdownTimeField.js | 102 ++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 javascript/DropdownTimeField.js diff --git a/javascript/DropdownTimeField.js b/javascript/DropdownTimeField.js new file mode 100644 index 000000000..38b77c65e --- /dev/null +++ b/javascript/DropdownTimeField.js @@ -0,0 +1,102 @@ +var DropdownTime = []; + +TimeBehaviour = { + initialise : function () { + this.isOpen = false; + + this.icon = $( this.id + '-icon' ); + + this.icon.onclick = this.toggle.bind( this ); + + this.dropdowntime = $( this.id + '-dropdowntime' ); + + var dropdown = + ''; + + this.dropdowntime.innerHTML = dropdown; + + DropdownTime[ DropdownTime.length ] = this.dropdowntime; + + this.selectTag = $( this.id + '-dropdowntime' + '-select' ); + + this.selectTag.onchange = this.updateValue.bind( this ); + }, + + toggle : function() { + if( this.isOpen ) + this.close(); + else + this.open(); + }, + + open : function() { + this.isOpen = true; + for( var i = 0; i < DropdownTime.length ; i++ ) { + var dropdowntime = DropdownTime[i]; + if( dropdowntime == this.dropdowntime ) + Element.addClassName( dropdowntime, 'focused' ); + else + Element.removeClassName( dropdowntime, 'focused' ); + } + }, + + close : function() { + this.isOpen = false; + Element.removeClassName( this.dropdowntime, 'focused' ); + }, + + updateValue : function() { + if( this.selectTag.selectedIndex != null ) { + var timeValue = this.selectTag.options[ this.selectTag.selectedIndex ].value; + this.value = timeValue; + } + this.close(); + } +}; + +Behaviour.register({ + 'div.dropdowntime input' : TimeBehaviour, + 'li.dropdowntime input' : TimeBehaviour +}); \ No newline at end of file