function SpinnerRegister() { var inputs=$$('input.Spinner'); for(i=0; i this.max_) num = this.max_; val = String(num); } if (this.aux_) this.aux_.appendChild(document.createTextNode(val)); if (this.input_) this.input_.value = val; } if (serialized != URLSerialize(this.Value())) this.init(); else this.store_value(); }, Value: function(){ var val = ""; if (this.input_) val = this.input_.value; else if (this.aux_) val = this.aux_.text; if (!this.validate(val, true)) return optional(); var num = parseInt(val, 10); return isNaN(num) ? optional() : optional(this.type(num)); }, Title: function(){ return this.title_ || null; }, SetAttribute: function(nam, val){ switch (nam){ case "min": case "max": var num = parseInt(val, 10); if (!isNaN(num)) this[nam + "_"] = num; break; case "visibility": if (Spinner.visibility_modes.indexOf(val) == -1) return; if (this.visibility_ == val) return; var elems = [this.aux_, this.cont_]; var visible = [["yes", "no"].indexOf(val) == -1, "yes" == val]; for (var iii = 0; iii < elems.length; ++iii) if (elems[iii]) Element.setStyle(elems[iii], {"display": visible[iii] ? "" : "none"}); if (visible[0]){ if (!this.aux_){ this.aux_ = document.createElement("span"); Element.writeAttribute(this.aux_, "class", String(Element.readAttribute(this.cont_, "class")) + " Spinner_" + val); for (var iii = 0; iii < this.cont_.attributes.length; ++iii){ var attr = this.cont_.attributes[iii]; if (["id", "localid", "class"].indexOf(attr.name) != -1) continue; this.aux_.setAttribute(attr.name, attr.value); if ("style" == attr.name) Element.setStyle(this.aux_, {"display": ""}); } if (this.width_){ Element.setStyle(this.aux_, {"width": this.width_}); delete this.width_; } this.update_aux_value(); }else{ if (this.visibility_) Element.removeClassName(this.aux_, "Spinner_" + this.visibility_); Element.addClassName(this.aux_, "Spinner_" + val); } this.aux_.setAttribute(nam, val); if (!this.attached(this.aux_)) this.cont_.parentNode.insertBefore(this.aux_, this.cont_); }else if (this.aux_ && this.attached(this.aux_)) this.aux_.parentNode.removeChild(this.aux_); if ("link" == val){ if (!this.aux_callbacks_) this.add_callbacks(this.aux_callbacks_ = [[this.aux_, "click", this.click.bind(this)]]); }else if (this.aux_ && this.aux_callbacks_){ this.remove_callbacks(this.aux_callbacks_); delete this.aux_callbacks_; } if (visible[1]){ if (!this.cont_callbacks_){ var onfocus = function(event){ this.Focus(); Event.stop(event); }.bindAsEventListener(this); this.add_callbacks(this.cont_callbacks_ = [// [this.buttons_[0], "click", this.up.bind(this)], [this.buttons_[1], "click", this.down.bind(this)], [this.buttons_[0], "focus", onfocus], [this.buttons_[1], "focus", onfocus], // [this.input_, SuperclassInput.keypress_name(), this.keypress.bindAsEventListener(this)], [this.input_, "keypress", this.keypress.bindAsEventListener(this)], [this.input_, "keydown", this.keydown.bindAsEventListener(this)], [this.input_, "change", this.update.bind(this)], [this.input_, Prototype.Browser.IE ? "propertychange" : "input", this.oninput.bindAsEventListener(this)]// ]); } }else if (this.cont_callbacks_){ this.remove_callbacks(this.cont_callbacks_); delete this.cont_callbacks_; } this.visibility_ = val; break; case "title": case "tip": this[nam + "_"] = val; break; case "htmlid": case "hidden": break; case "width": var style = {"width": val}; if (this.input_) Element.setStyle(this.input_, style); if (this.aux_) Element.setStyle(this.aux_, style); else this.width_ = val; break; default: var elems = [this.aux_, this.input_]; for (var iii = 0; iii < elems.length; ++iii) if (elems[iii]) elems[iii].setAttribute(nam, val); break; } }, attached: function(node){ if (!node) return false; if (!node.parentNode) return false; if (node.parentNode.nodeType != Node.ELEMENT_NODE) return false; return true; }, Focus: function(){ if (this.input_) this.input_.focus(); }, add_callbacks: function(arr){ arr.each(function(args){ Event.observe.apply(null, args); }); }, remove_callbacks: function(arr){ arr.each(function(args){ Event.stopObserving.apply(null, args); }); }, click: function(){ new AEvent("CLICK", {}, this); }, change: function(){ this.update_aux_value(); this.store_value(); this.clear_oninput_timer(); new AEvent("CHANGE", {}, this); }, update_aux_value: function(){ if (!this.aux_ || !this.input_) return; var val = this.input_.value; while (this.aux_.firstChild) this.aux_.removeChild(this.aux_.firstChild); if (val) this.aux_.appendChild(document.createTextNode(val)); }, store_value: function(){ this.stored_value_ = URLSerialize(this.Value()); }, check_change: function(){ if (URLSerialize(this.Value()) != this.stored_value_) this.change(); }, init: function(){ this.update_aux_value(); this.store_value(); new AEvent("WM_INIT", {}, this); }, up: function(){ var val = URLSerialize(this.Value()); this.inc(); if (URLSerialize(this.Value()) != val) this.change(); }, down: function(){ var val = URLSerialize(this.Value()); this.dec(); if (URLSerialize(this.Value()) != val) this.change(); }, inc: function(){ if (!this.input_) return; var num = parseInt(this.input_.value, 10); if (isNaN(num)) num = this.min_ || 0; else num = Math.max(this.min_, num + 1); if (num > this.max_) num = this.max_; this.input_.value = String(num); }, dec: function(){ if (!this.input_) return; var num = parseInt(this.input_.value, 10); // if (isNaN(num)) num = this.max_ || 0; if (isNaN(num)) num = 0; else num = Math.min(this.max_, num - 1);; if (num < this.min_) num = this.min_; this.input_.value = String(num); }, clear_timers: function(button){ if (!button) return; if (button.delayer_){ window.clearTimeout(button.delayer_); button.delayer_ = null; } if (button.repeater_){ window.clearInterval(button.repeater_); button.repeater_ = null; } }, bind_timer: function(button, func){ var mouseup = function(){ if (button.handlers_) this.remove_callbacks(button.handlers_); this.clear_timers(button); if (URLSerialize(this.Value()) != button.value_) this.change(); button.value_ = null; }.bind(this); Event.observe(button, "mousedown", function(){ this.clear_timers(button); button.delayer_ = window.setTimeout(function(){ func(); button.repeater_ = window.setInterval(func, 50); }, 300); button.value_ = URLSerialize(this.Value()); if (typeof button.handlers_ == "undefined") button.handlers_ = [ [document, "mouseup", mouseup], [button, "mouseup", mouseup], [button, "mouseout", mouseup] ]; this.add_callbacks(button.handlers_); }.bind(this)); }, charcode: function(event){ if (!event) return 0; if (typeof event.charCode != "undefined" && event.charCode!=0) return event.charCode; if (typeof event.which != "undefined") return event.which; return event.keyCode; }, keydown: function(event) { if (event.ctrlKey || event.altKey) return HideTip(); var key = event.which || event.keyCode; /* switch(key) { case Event.KEY_UP: case Event.KEY_DOWN: {*/ if(key==Event.KEY_UP || key==Event.KEY_DOWN) {{ var caret = this.input_.value.length - getSelectionEnd(this.input_); this[key == Event.KEY_UP ? "up" : "down"](); setCaretPosition(this.input_, this.input_.value.length - caret); Event.stop(event); return false; } } }, keypress: function(event){ if (event.ctrlKey || event.altKey) return HideTip(); var key = event.which || event.keyCode; /* switch(key) { case Event.KEY_UP: case Event.KEY_DOWN: { var caret = this.input_.value.length - getSelectionEnd(this.input_); this[key == Event.KEY_UP ? "up" : "down"](); setCaretPosition(this.input_, this.input_.value.length - caret); Event.stop(event); return false; } case Event.KEY_LEFT: case Event.KEY_RIGHT: case Event.KEY_DELETE: case Event.KEY_END: case Event.KEY_HOME: return; }*/ { var code = this.charcode(event); if (!SuperclassInput.isVisibleCharacter(code)) return HideTip(); var str = String.fromCharCode(code); if (str == "-" || str >= "0" && str <= "9") { var ss = getSelectionStart(this.input_); var se = getSelectionEnd(this.input_); var val = this.input_.value; if (!this.validate(val.substr(0, ss) + str + val.substr(se), false)){ this.display_error(); Event.stop(event); } else HideTip(); event.stopPropagation(); //return false; } else Event.stop(event); } }, validate: function(val, strict){ if (!val) return true; if (!val.match(/^-?\d*$/)) return false; if ("-" == val && !strict && this.min_ < 0) return true; var num = parseInt(val, 10); if (isNaN(num)) return false; if (strict) return num >= this.min_ && num <= this.max_; else return (num >= this.min_ || num >= 0 && this.min_ > 0) && (num <= this.max_ || num <= 0 && this.max_ < 0); }, display_error: function(){ if (this.tip_) ShowTip(this.input_, this.tip_); new BlinkAnimation(this.input_, "Spinner_error"); }, update: function(){ if (!this.validate(this.input_.value, true)){ if (typeof this.tip_callback_ == "undefined") this.tip_callback_ = [document, "mousedown", this.hide_tip.bind(this)]; this.add_callbacks([this.tip_callback_]); this.tip_timeout_ = window.setTimeout(this.hide_tip.bind(this), 2000); return void this.display_error(); }else HideTip(); this.check_change(); }, hide_tip: function(){ HideTip(); if (typeof this.tip_timeout_ != "undefined"){ window.clearTimeout(this.tip_timeout_); delete this.tip_timeout_; } if (typeof this.tip_callback_ != "undefined"){ this.remove_callbacks([this.tip_callback_]); delete this.tip_callback_; } }, clear_oninput_timer: function(){ if (this.oninput_timer_){ window.clearTimeout(this.oninput_timer_); delete this.oninput_timer_; } }, oninput: function(event){ this.clear_oninput_timer(); this.oninput_timer_ = function(){ new AEvent("INPUT", {}, this); }.bind(this).defer(); } }); Spinner.visibility_modes = ["yes", "ro", "vo", "link", "no"]; var Int64Input = Class.create(Spinner, { initialize: function($super, id){ $super(id); this.max_ = Math.pow(2, 53) - 1; }, type: int64 });