/** * trida pro skryvani elementu */ var Slider = function(elemID, hide, animate, autohide) { this.id = elemID; this.regDelay = 30; this.regK = 0.20; this.lockDelay = 2000; this.lockTimer = null; this.animate = animate; this.initHide = hide; this.children = new Array(); this.autohide = autohide; this.elemOverflow = "hidden"; this.elem = null; this.envelope = null; this.callback = null; this.callbackStart = null; this.visible = !hide; this.autoinit = true; this.offsetHeight = 0; this.origHeight = 0; this.showDebug = false; var self = this; fLib.addEvent("load", function() { if(self.autoinit) { self.init(); } }, window); } Slider.prototype.parseOptions = function(options) { for(i in options) { this[i] = options[i]; } } Slider.prototype.init = function() { var self = this; this.reg = new Regulator( function(size) { self.setValue(size); }, function() { if(self.callback) { self.callback(self); } }, this.currHeight ); this.reg.delay = this.regDelay; this.reg.k = this.regK; this.elem = fLib.getElementById(this.id); if(this.elem !== null) { this.origHeight = fLib.getElemHeight(this.elem) + fLib.getElemPadding(this.elem, "top") + fLib.getElemPadding(this.elem, "bottom"); this.offsetHeight = this.elem.offsetHeight; if(this.showDebug) { alert("sum: " + this.origHeight + " ch: " + this.elem.clientHeight + " oh: " + this.offsetHeight + " h: " + fLib.getElemHeight(this.elem) + " pb: " + fLib.getElemPadding(this.elem, "bottom") + " pt: " + fLib.getElemPadding(this.elem, "top")); } var paddingT = fLib.getStyle(this.elem, "padding-top"); var paddingR = fLib.getStyle(this.elem, "padding-right"); var paddingB = fLib.getStyle(this.elem, "padding-bottom"); var paddingL = fLib.getStyle(this.elem, "padding-left"); this.elem.style.visibility = "visible"; this.elem.style.padding = "0px"; this.elem.style.overflow = this.elemOverflow; this.envelope = document.createElement("div"); fLib.moveChildren(this.elem, this.envelope); this.envelope.style.padding = paddingT + " " + paddingR + " " + paddingB + " " + paddingL; this.elem.appendChild(this.envelope); if(this.autohide) { fLib.addEvent("mousemove", function() { self.lock(); }, this.elem); fLib.addEvent("mouseout", function() { self.unlock(); }, this.elem); } if(this.initHide) { this.currHeight = 0; this.reg.setVal(this.currHeight); this.elem.style.height = "0px"; this.visible = false; } else { this.currHeight = this.origHeight; this.reg.setVal(this.currHeight); this.show(); } } } Slider.prototype.getHeight = function() { return this.origHeight; } Slider.prototype.getOffsetHeight = function() { return this.offsetHeight; } Slider.prototype.getElem = function() { return this.elem; } Slider.prototype.getEnvelope = function() { return this.envelope; } Slider.prototype.setOverflow = function(val) { this.elemOverflow = val; if(this.elem) { this.elem.style.overflow = val; } } Slider.prototype.setCallback = function(val) { this.callback = val; } Slider.prototype.setCallbackStart = function(val) { this.callbackStart = val; } Slider.prototype.toggle = function() { this.reg.stop(); if(this.visible) { this.hide(); } else { this.show(); } if(this.callbackStart) { this.callbackStart(this); } } Slider.prototype.show = function(quick) { if(this.elem !== null) { if(this.animate && !quick) { this.newHeight = this.origHeight; this.reg.setVal(this.currHeight); this.reg.start(this.newHeight); } else { this.reg.stop(); this.setValue(this.origHeight); } this.visible = true; this.unlock(); } } Slider.prototype.hide = function() { if(this.canHide() && this.elem !== null) { this.doHide(); } } Slider.prototype.doHide = function(quick) { if(this.elem !== null) { if(this.animate && !quick) { this.newHeight = 0; this.reg.setVal(this.currHeight); this.reg.start(this.newHeight); } else { this.reg.stop(); this.setValue(0); } this.visible = false; } } Slider.prototype.setValue = function(size) { this.currHeight = size; this.elem.style.height = Math.round(size) + "px"; } Slider.prototype.lock = function() { clearTimeout(this.lockTimer); } Slider.prototype.unlock = function() { if(this.autohide) { clearTimeout(this.lockTimer); var self = this; this.lockTimer = setTimeout(function() { self.hide(); }, this.lockDelay); } } Slider.prototype.canHide = function() { return true; } Slider.prototype.toString = function() { return "Slider: " + this.id; } Slider.prototype.debug = function() { this.showDebug = true; }