function slider (a_init, a_tpl) { this.f_setvalue = f_slidersetvalue; this.f_outvalue = f_slideroutvalue; this.f_getpos = f_slidergetpos; // register in the global collection if (!window.a_sliders) window.a_sliders = []; this.n_id = window.a_sliders.length; window.a_sliders[this.n_id] = this; // save config parameters in the slider object var s_key; if (a_tpl) for (s_key in a_tpl) this[s_key] = a_tpl[s_key]; for (s_key in a_init) this[s_key] = a_init[s_key]; s1 = this.s_spanname; s2 = this.s_sourcename; this.n_pix2value = this.n_pathlength / (this.n_maxvalue - this.n_minvalue); if (this.n_value == null) this.n_value = this.n_minvalue; // generate the control's html document.write( '
' + '
' ); this.e_base = $('sl' + this.n_id + 'base'); this.e_slider = $('sl' + this.n_id + 'slider'); // safely hook document/window events if (document.onmousemove != f_slidermousemove) { window.f_savedmousemove = document.onmousemove; document.onmousemove = f_slidermousemove; } if (document.onmouseup != f_slidermouseup) { window.f_savedmouseup = document.onmouseup; document.onmouseup = f_slidermouseup; } // preset to the value in the input box if available this.f_setvalue(this.n_value ? null : 1); this.e_slider.style.visibility = 'visible'; } function f_slidersetvalue (n_value, b_noinputcheck) { if (n_value == null) n_value = this.n_value == null ? this.n_minvalue : this.n_value; if (isnan(n_value)) return false; // round to closest multiple if step is specified if (this.n_step) n_value = math.round((n_value - this.n_minvalue) / this.n_step) * this.n_step + this.n_minvalue; // smooth out the result if (n_value % 1) n_value = math.round(n_value * 1e5) / 1e5; if (n_value < this.n_minvalue) n_value = this.n_minvalue; if (n_value > this.n_maxvalue) n_value = this.n_maxvalue; this.n_value = n_value; // move the slider if (this.b_vertical) this.e_slider.style.top = (this.n_pathtop + this.n_pathlength - math.round((n_value - this.n_minvalue) * this.n_pix2value)) + 'px'; else this.e_slider.style.left = (this.n_pathleft + math.round((n_value - this.n_minvalue) * this.n_pix2value)) + 'px'; // save new value var e_input; if (this.s_name != null) { e_input = $(this.s_name); if(e_input != null) e_input.innerhtml = n_value; } } function f_slideroutvalue (n_value, b_noinputcheck) { if (n_value == null) n_value = this.n_value == null ? this.n_minvalue : this.n_value; if (isnan(n_value)) return false; // round to closest multiple if step is specified if (this.n_step) n_value = math.round((n_value - this.n_minvalue) / this.n_step) * this.n_step + this.n_minvalue; // smooth out the result if (n_value % 1) n_value = math.round(n_value * 1e5) / 1e5; if (n_value < this.n_minvalue) n_value = this.n_minvalue; if (n_value > this.n_maxvalue) n_value = this.n_maxvalue; if(this.s_type =='ajax') { changepage(n_value, this.s_sourcename, this.s_spanname); } else if(this.s_type =='url') { var tarurl = this.s_spanname.replace(/{\$pageid\/}/g, n_value); redirecturl(tarurl); } } // get absolute position of the element in the document function f_slidergetpos (b_vertical, b_base) { var n_pos = 0, s_coord = (b_vertical ? 'top' : 'left'); var o_elem = o_elem2 = b_base ? this.e_base : this.e_slider; while (o_elem) { n_pos += o_elem["offset" + s_coord]; o_elem = o_elem.offsetparent; } o_elem = o_elem2; var n_offset; while (o_elem.tagname != "body") { n_offset = o_elem["scroll" + s_coord]; if (n_offset) n_pos -= o_elem["scroll" + s_coord]; o_elem = o_elem.parentnode; } return n_pos; } function f_slidermousedown (n_id) { window.n_activesliderid = n_id; return false; } function f_slidermouseup (e_event, b_watching) { if (window.n_activesliderid != null) { var o_slider = window.a_sliders[window.n_activesliderid]; o_slider.f_setvalue(o_slider.n_minvalue + (o_slider.b_vertical ? (o_slider.n_pathlength - parseint(o_slider.e_slider.style.top) + o_slider.n_pathtop) : (parseint(o_slider.e_slider.style.left) - o_slider.n_pathleft)) / o_slider.n_pix2value); if (b_watching) return; window.n_activesliderid = null; o_slider.f_outvalue(o_slider.n_minvalue + (o_slider.b_vertical ? (o_slider.n_pathlength - parseint(o_slider.e_slider.style.top) + o_slider.n_pathtop) : (parseint(o_slider.e_slider.style.left) - o_slider.n_pathleft)) / o_slider.n_pix2value); } if (window.f_savedmouseup) { return window.f_savedmouseup(e_event); } } function f_slidermousemove (e_event) { if (!e_event && window.event) e_event = window.event; // save mouse coordinates if (e_event) { window.n_mousex = e_event.clientx + f_scrollleft(); window.n_mousey = e_event.clienty + f_scrolltop(); } // check if in drag mode if (window.n_activesliderid != null) { var o_slider = window.a_sliders[window.n_activesliderid]; var n_pxoffset; if (o_slider.b_vertical) { var n_slidertop = window.n_mousey - o_slider.n_sliderheight / 2 - o_slider.f_getpos(1, 1) - 3; // limit the slider movement if (n_slidertop < o_slider.n_pathtop) n_slidertop = o_slider.n_pathtop; var n_pxmax = o_slider.n_pathtop + o_slider.n_pathlength; if (n_slidertop > n_pxmax) n_slidertop = n_pxmax; o_slider.e_slider.style.top = n_slidertop + 'px'; n_pxoffset = o_slider.n_pathlength - n_slidertop + o_slider.n_pathtop; } else { var n_sliderleft = window.n_mousex - o_slider.n_sliderwidth / 2 - o_slider.f_getpos(0, 1) - 3; // limit the slider movement if (n_sliderleft < o_slider.n_pathleft) n_sliderleft = o_slider.n_pathleft; var n_pxmax = o_slider.n_pathleft + o_slider.n_pathlength; if (n_sliderleft > n_pxmax) n_sliderleft = n_pxmax; o_slider.e_slider.style.left = n_sliderleft + 'px'; n_pxoffset = n_sliderleft - o_slider.n_pathleft; } if (o_slider.b_watch) f_slidermouseup(e_event, 1); return false; } if (window.f_savedmousemove) return window.f_savedmousemove(e_event); } // get the scroller positions of the page function f_scrollleft() { return f_filterresults ( window.pagexoffset ? window.pagexoffset : 0, document.documentelement ? document.documentelement.scrollleft : 0, document.body ? document.body.scrollleft : 0 ); } function f_scrolltop() { return f_filterresults ( window.pageyoffset ? window.pageyoffset : 0, document.documentelement ? document.documentelement.scrolltop : 0, document.body ? document.body.scrolltop : 0 ); } function f_filterresults(n_win, n_docel, n_body) { var n_result = n_win ? n_win : 0; if (n_docel && (!n_result || (n_result > n_docel))) n_result = n_docel; return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result; } function f_slidererror (n_id, s_message) { alert("slider #" + n_id + " error:\n" + s_message); window.n_activesliderid = null; }