/* * Select field scroller * * Copyright (c) 2004, Mackley F. Pexton. All rights reserved. */ /** The Select field scroller functions make and control a scrolling field, define the HTML as normal and then call make_select_scroll(select_field_id [, next_func, prev_func] ); The make_select_scroll() function adds an up button to the top of the list and a down button to the bottom of the list. When the mouse hovers over the buttons, the list is scrolled up or down. New options are added to the list by the functions pointed to by the next_func and prev_func arguments. If they are not assigned, standard selectScroll functions are used to return the next or previous number in the list. The functions are passed the fields is needed for Internet Explorer 6. Its select field options do not sense mouse events. Instead of scrolling, if the item selected from the list is the first or the last, the list is repopulated so the last item becomes the second from the top or the first item is placed in the second to the last place. The keyboard's arrow keys scroll the list too. **/ /* * Construct scrolling select field out of a normal select field. */ function make_select_scroll(id,next_func,prev_func) { //if (navigator.userAgent.match(/MSIE/)) return make_select_scroll.IE(id); // Unfortunately, only Gecko engine looks at event handlers attached to the option tags. if (! navigator.userAgent.match(/Firefox/)) return make_select_scroll.IE(id); var select_field = typeof id == 'object' ? id : document.getElementById(id); // Save functions used to get next and previous Options for list with the list. select_field.next_func = next_func ? next_func : selectScroll.next; select_field.prev_func = prev_func ? prev_func : selectScroll.prev; // Add up scroll button var up_opt = document.createElement("OPTION"); up_opt.value = ''; up_opt.text = make_select_scroll.scroll_up_button; up_opt.selected = false; up_opt.className = 'select-scroll-up'; up_opt.addEventListener('mouseover',selectScroll.start_up,false); up_opt.addEventListener('mouseout',selectScroll.stop,false); up_opt.addEventListener('mouseup',selectScroll.stop,false); select_field.insertBefore(up_opt,select_field.options[0]); // Add down scroll button var dn_opt = document.createElement("OPTION"); dn_opt.value = ''; dn_opt.text = make_select_scroll.scroll_down_button; dn_opt.selected = false; dn_opt.className = 'select-scroll-down'; dn_opt.addEventListener('mouseover',selectScroll.start_down,false); dn_opt.addEventListener('mouseout',selectScroll.stop,false); dn_opt.addEventListener('mouseup',selectScroll.stop,false); select_field.appendChild(dn_opt); // Add event handlers select_field.onchange = selectScroll.check; select_field.onkeypress = selectScroll.check; } make_select_scroll.IE = function(id,next_func,prev_func) { // IE does not capture events assigned to