Mercurial > hg > digilib
comparison client/digitallibrary/greyskin/baselib.js @ 438:36dd0500bf66
support for sliders started
author | hertzhaft |
---|---|
date | Fri, 13 Jan 2006 12:01:07 +0100 |
parents | 3331355ae632 |
children | ae111f1cd044 |
comparison
equal
deleted
inserted
replaced
437:22441d2678ba | 438:36dd0500bf66 |
---|---|
629 } | 629 } |
630 return true; | 630 return true; |
631 } | 631 } |
632 | 632 |
633 function registerEventById(type, id, handler) { | 633 function registerEventById(type, id, handler) { |
634 registerEvent(type, document.getElementById(id), handler); | 634 registerEvent(type, getElement(id), handler); |
635 } | 635 } |
636 | 636 |
637 function unregisterEventById(type, id, handler) { | 637 function unregisterEventById(type, id, handler) { |
638 unregisterEvent(type, document.getElementById(id), handler); | 638 unregisterEvent(type, getElement(id), handler); |
639 } | 639 } |
640 | 640 |
641 function stopEvent(e) { | 641 function stopEvent(e) { |
642 if (!e) var e = window.event; | 642 if (!e) var e = window.event; |
643 e.cancelBubble = true; | 643 e.cancelBubble = true; |
768 delete this[key]; | 768 delete this[key]; |
769 } | 769 } |
770 | 770 |
771 // :tabSize=4:indentSize=4:noTabs=true: | 771 // :tabSize=4:indentSize=4:noTabs=true: |
772 | 772 |
773 function Slider(id, valMin, valMax, valStart, stepSize, onChange) { | |
774 // a (horizontal) slider widget | |
775 this.id = id; | |
776 this.elem = getElement(id); | |
777 this.slider = getElement(id + ".slider"); // the slider handle | |
778 this.input = getElement(id + ".input", 1); // optional input field | |
779 this.bar = getElement(id + ".bar"); // the slider bar | |
780 this.barRect = getElementRect(this.bar); | |
781 this.minX = this.barRect.x; | |
782 this.maxX = this.minX + this.barRect.width; | |
783 this.valMin = valMin; | |
784 this.valMax = valMax; | |
785 this.valStart = valStart; | |
786 this.value = valStart; | |
787 this.stepSize = stepSize; | |
788 this.valueLabel = getElement(id + ".value", 1); | |
789 this.valMinLabel = getElement(id + ".valmin", 1); | |
790 this.valMaxLabel = getElement(id + ".valmax", 1); | |
791 this.onChange = onChange ? onChange : function() {}; | |
792 return this; | |
793 } | |
794 | |
795 Slider.prototype.show = function(show) { | |
796 showElement(this.elem, show); | |
797 } | |
798 | |
799 Slider.prototype.activate = function() { | |
800 } | |
801 | |
802 Slider.prototype.disable = function() { | |
803 } | |
804 | |
805 Slider.prototype.reset = function() { | |
806 this.setValue(this.startVal); | |
807 } | |
808 | |
809 Slider.prototype.setValue = function(newVal) { | |
810 // sets slider to new value and updates | |
811 this.value = newVal; | |
812 this.update; | |
813 } | |
814 | |
815 Slider.prototype.update = function() { | |
816 // updates slider position to new value | |
817 } | |
818 | |
819 Slider.prototype.setupEvents = function() { | |
820 // installs all event callbacks | |
821 registerEvent("mousedown", this.slider, this.onDragStart); | |
822 } | |
823 | |
824 Slider.prototype.onDragStart = function(evt) { | |
825 unregisterEvent("mousedown", this.slider, this.onDragStart); | |
826 registerEvent("mousemove", document, this.onDrag); | |
827 registerEvent("mouseup", document, this.onDragEnd); | |
828 this.startPos = evtPosition(evt); | |
829 return stopEvent(evt); | |
830 } | |
831 | |
832 Slider.prototype.onDrag = function(evt) { | |
833 var pos = evtPosition(evt); | |
834 var dx = pos.x - this.startPos; | |
835 // move birdArea div, keeping size | |
836 newRect = new Rectangle(startPos.x, startPos.y, dx, dy); | |
837 pixel.innerHTML = (xDir ? dx : dy) + " px"; | |
838 moveElement(calDiv, newRect); | |
839 showElement(calDiv, true); | |
840 return stopEvent(evt); | |
841 } | |
842 | |
843 Slider.prototype.onDragEnd = function(evt) { | |
844 unregisterEvent("mousemove", document, this.onDrag); | |
845 unregisterEvent("mouseup", document, this.onDragEnd); | |
846 this.onChange(this.value); | |
847 return stopEvent(evt); | |
848 } | |
849 | |
850 Slider.prototype.onInputChange = function() { | |
851 this.onChange(this.value); | |
852 } | |
853 |