//2004-10-31 - changed "position: absolute" to "position: relative" // --------------------------------------------------------------------- // Beware testing this on Netscape 4.x. // 1. get the latest 4.x sub-version (currently 4.79) // 2. if pages seems to render unreliably, load a different page then // reload the page under test. // 3. why Netscape 4.x requires double-nested SPANs we don't know. // // functions: // slider_render_all() // slider_render() // slider_render_scale() // slider_render_pane() // slider_render_ticks() // slider_render_labels() // slider_render_stylus_up() // slider_render_stylus_down() // // slider_normalise() // slider_align() // // slider_stylus_mousedown() // slider_stylus_mousemove() // slider_stylus_mouseup() // // slider_set_value() // // data: // // a copy of sliders.js must be loaded before this library. // // sliding = a global variable indicating state. // // --------------------------------------------------------------------- var sliding = false; // state for user drag'n'drop // --------------------------------------------------------------------- // create all the sliders in one go function slider_render_all() { var i; for (i=0; iNo browser support for sliders
"); return; } // now write out all the bits slider_render_scale(obj); slider_render_pane(obj); if ( obj.tick_tabs == null ) // calculate tabs between ticks { obj.tick_tabs = (obj.scale_width-obj.tick_width) / (obj.ticks-1.0); } for (i=0; i"); write(""); write(""); } } // --------------------------------------------------------------------- // Background clickable span used for all mouse input // There is a hack here for NS 4.x - neither ID nor NAME // are accessable from event handlers, so we tack the ID onto // the end of the SRC attribute. Still a valid URL and doesn't break NN 4. // If we don't do this, we can't tell which slider it is. function slider_render_pane(obj) { with (window.document) { write("" ); write(""); write(""); } } // --------------------------------------------------------------------- // a mark along the scale function slider_render_tick(i,obj) { with (window.document) { write("" ); write(""); write(""); } } // --------------------------------------------------------------------- // a label for one of the tick marks function slider_render_label(i,obj) { var label_style = "z-index:1; padding:0; margins:0;"; with (window.document) { write("" ); write(obj.labels[i] + ""); } } // --------------------------------------------------------------------- // the stylus on the scale line (the "claw" or "pointer") function slider_render_stylus_up(obj) { with (window.document) { write(""); write(""); write(""); } } // --------------------------------------------------------------------- // the highlighted stylus on the scale line function slider_render_stylus_down(obj) { with (window.document) { write(""); write(""); write(""); } } // --------------------------------------------------------------------- // event handler for 3 classes of browser function slider_stylus_mousedown(obj) { var i; var slider_name; if ( old ) return; if (moz || dom2) { slider_name = obj.currentTarget.id; document.getElementById(slider_name+"up").style.visibility = "hidden"; document.getElementById(slider_name+"down").style.visibility = "visible"; obj.stopPropagation(); obj.preventDefault(); } if ( ie4 || ie5 || ie6 ) { // picks up the tag as src. // picks up the z-index:0 tag if the edge is reached with (window.event.srcElement) { if ( id == parentElement.id + "_pane" ) { slider_name = parentElement.id; } else { slider_name = window.document.activeElement.id; } } document.all(slider_name+"up").style.visibility = "hidden"; document.all(slider_name+"down").style.visibility = "visible"; window.event.cancelBubble = true; window.event.returnValue = false; } if ( nn4 ) { slider_name = obj.target.src; i = slider_name.indexOf("#",0); // the NN 4.x hack slider_name = slider_name.substring(i+1,slider_name.length); window.document.layers[slider_name+"up"].visibility = "hide"; window.document.layers[slider_name+"down"].visibility = "show"; } sliding = true; return false; // for nn4 } // --------------------------------------------------------------------- // event handler for 3 classes of browser function slider_stylus_mousemove(obj) { var slider_name = ""; var config = null; var x = 0; var i = 0; if ( old || !sliding ) return; // find current location and slider data if (moz || dom2) { slider_name = obj.currentTarget.id; x = obj.clientX; obj.stopPropagation(); obj.preventDefault(); } if ( ie4 || ie5 || ie6 ) { // picks up the tag as src. // picks up the z-index:0 tag if the edge is reached // picks up if user move is very fast with (window.event.srcElement) { if ( tagName == "HTML" ) { sliding = false; return; // very fast mouse swipe by user - do nothing } else if ( id == parentElement.id + "_pane" ) { slider_name = parentElement.id; } else { slider_name = window.document.activeElement.id; } } x = window.event.clientX; window.event.cancelBubble = true; window.event.returnValue = false; } if ( nn4 ) { slider_name = obj.target.src; i = slider_name.indexOf("#",0); // the NN 4.x hack slider_name = slider_name.substring(i+1,slider_name.length); x = obj.pageX; } for (i=0; i tag as src. // picks up the z-index:0 tag if the edge is reached with (window.event.srcElement) { if ( id == parentElement.id + "_pane" ) { slider_name = parentElement.id; } else { slider_name = window.document.activeElement.id; } } x = window.event.clientX; window.event.cancelBubble = true; window.event.returnValue = false; } if ( nn4 ) { slider_name = obj.target.src; i = slider_name.indexOf("#",0); // the NN 4.x hack slider_name = slider_name.substring(i+1,slider_name.length); x = obj.pageX; } for (i=0; i= xmax ) ? xmax : x; return x; } // --------------------------------------------------------------------- // if the slider isn't continuous==true , align x with a tick mark. function slider_align(x,obj) { var tab = 0; if (!obj.continuous) // must align with a tick { while ( (x -= obj.tick_tabs) > obj.left - obj.tick_tabs/2 ) { tab++; } x = obj.left + tab * obj.tick_tabs; } return x; } // --------------------------------------------------------------------- // copy the slider setting into a form field. Call this from your own place. function slider_set_value(obj,k) { var i = 0, x = 0, data = null; var objTemp = obj; var strTemp = ""; if (moz || dom2) { x = window.document.getElementById(obj.span_id+"up").style.left; x = x.substring(0,x.length-2) - 0; } if ( ie4 || ie5 || ie6 ) { x = document.all(obj.span_id+"up").style.left; x = x.substring(0,x.length-2) - 0; } if ( nn4 ) { x = window.document.layers[obj.span_id+"up"].left; } x += obj.stylus_width/2; if (!obj.continuous) // must be aligned with a tick { x -= obj.left; while ( (x-=obj.tick_tabs) >= 0 ) { i++; } data = obj.values[i]; } else { i = (x*1.0 - obj.left) / obj.status_width; data = i * (obj.values[object.ticks-1] - obj.values[0]); } objTemp = eval ("document.Survey.Q" + k); objTemp.value = data + ""; }