/* * zobrazi bud jeden nebo vice obrazku pres celou plochu prohlizece * * pokud zobrazuje vice obrazku, zobrazuje i sipky vlevo a vpravo * * pri prejizdeni mysi pres obrazek zobrazuje navigaci a tlacitko zavrit * pri kliku mimo obrazek se zavre taky * * (c) 2010, jlx@seznam.cz */ var QuickShow = function() { this.imgLayer = null; this.imgLayer2 = null; this.msgLayer = null; this.nextButt = null; this.prevButt = null; this.closeButt = null; this.currentImgElem = null; this.imgObjectTmp = new Image; this.loader = new Image; this.loading = true; this.offset = 15; this.imgH = 0; this.images = new Array(); this.currentImg = 0; this.buttonPaddingBigX; this.buttonPaddingBigY; this.buttonPaddingSmall = 10; this.buttonSize = 40; this.loaderImgPath = "images/loader.gif"; this.prevImgPath = "images/arr_prev.png"; this.nextImgPath = "images/arr_next.png"; this.closeImgPath = "images/close.png"; }; //tlacitko doleva doprava QuickShow.prototype.setNavButton = function(aSrc) { var butt = document.createElement("img"); butt.src = aSrc; butt.style.position = "absolute"; butt.style.cursor = "pointer"; butt.style.display = "none"; return butt; }; //zobrazit obrazek pres cele okno QuickShow.prototype.display = function(linkStr) { var docBody = document.getElementsByTagName("body")[0]; this.loader.src = this.loaderImgPath; this.currentImgElem = this.loader; this.imgLayer = document.createElement("div"); this.imgLayer2 = document.createElement("div"); this.prevButt = this.setNavButton(this.prevImgPath); this.nextButt = this.setNavButton(this.nextImgPath); this.closeButt = this.setNavButton(this.closeImgPath); this.imgLayer.style.position = "absolute"; this.imgLayer.style.zIndex = 1000; this.imgLayer.style.top = "0px"; this.imgLayer.style.left = "0px"; this.imgLayer.style.width = "100%"; this.imgLayer.style.height = fLib.getDocumentHeight() + "px"; this.imgLayer.style.textAlign = "center"; this.imgLayer2.style.position = "absolute"; this.imgLayer2.style.zIndex = 1000; this.imgLayer2.style.top = "0px"; this.imgLayer2.style.left = "0px"; this.imgLayer2.style.width = "100%"; this.imgLayer2.style.height = fLib.getDocumentHeight() + "px"; this.imgLayer2.style.backgroundColor = "#000000"; fLib.setOpacity(this.imgLayer2, 70); this.imgObjectTmp.style.padding = "10px"; this.imgObjectTmp.style.background = "#FFFFFF"; this.imgObjectTmp.style.borderRadius = "10px"; this.imgObjectTmp.style.boxShadow = "5px 5px 10px 0px #222222"; this.loader.style.padding = "10px"; this.loader.style.background = "#FFFFFF"; this.loader.style.borderRadius = "10px"; this.loader.style.boxShadow = "5px 5px 10px 0px #222222"; this.imgLayer.appendChild(this.prevButt); this.imgLayer.appendChild(this.currentImgElem); this.imgLayer.appendChild(this.nextButt); this.imgLayer.appendChild(this.closeButt); docBody.appendChild(this.imgLayer2); docBody.appendChild(this.imgLayer); var self = this; this.keyEventHandler = function(e) { return self.keyPressed(e); }; this.resizeOrScrollEventHandler = function() { self.repairSize(); }; this.mouseOverEventHandler = function() { self.showPrevNext(); }; this.mouseOutEventHandler = function() { self.hidePrevNext(); }; fLib.addEvent("click", function(e) { self.hide(e); }, this.imgLayer); fLib.addEvent("click", function(e) { self.prevImage(e); }, this.prevButt); fLib.addEvent("click", function(e) { self.nextImage(e); }, this.nextButt); fLib.addEvent("click", function(e) { self.hide(e); }, this.closeButt); fLib.addEvent("click", function(e) { fLib.stopPropagation(e); }, this.imgObjectTmp); fLib.addEvent("mouseover", this.mouseOverEventHandler, this.imgObjectTmp); fLib.addEvent("mouseover", this.mouseOverEventHandler, this.closeButt); fLib.addEvent("mouseover", this.mouseOverEventHandler, this.prevButt); fLib.addEvent("mouseover", this.mouseOverEventHandler, this.nextButt); fLib.addEvent("mouseout", this.mouseOutEventHandler, this.imgObjectTmp); fLib.addEvent("mouseout", this.mouseOutEventHandler, this.closeButt); fLib.addEvent("mouseout", this.mouseOutEventHandler, this.prevButt); fLib.addEvent("mouseout", this.mouseOutEventHandler, this.nextButt); fLib.addEvent("resize", this.resizeOrScrollEventHandler, window); fLib.addEvent("scroll", this.resizeOrScrollEventHandler, window); fLib.addEvent("keypress", this.keyEventHandler, document); this.setImage(linkStr); }; QuickShow.prototype.keyPressed = function(e) { var event = e || window.event; var code = this.getKeyCode(e); if(code == 36) { this.firstImage(event); } if(code == 35) { this.lastImage(event); } if(code == 37) { this.prevImage(event); } if(code == 39) { this.nextImage(event); } if(code == 27) { this.hide(event); } return false; }; QuickShow.prototype.getKeyCode = function(e) { if(e.keyCode) { return e.keyCode; } else if(e.which) { return e.which; } }; //skryt a zrusit QuickShow.prototype.hide = function(e) { fLib.stopPropagation(e); var docBody = document.getElementsByTagName("body")[0]; docBody.removeChild(this.imgLayer); docBody.removeChild(this.imgLayer2); fLib.removeEvent("keypress", this.keyEventHandler, document); fLib.removeEvent("resize", this.resizeOrScrollEventHandler, window); fLib.removeEvent("scroll", this.resizeOrScrollEventHandler, window); }; //prepocitat umisteni hlavniho obrazku QuickShow.prototype.setImgPosition = function() { var winH = fLib.getWindowHeight(); this.buttonPaddingBigY = Math.max(0, Math.round((this.imgObjectTmp.height / 2) - this.buttonSize - 20)); this.currentImgElem.style.marginTop = fLib.getTopScroll() + ((winH - this.currentImgElem.height) / 2) + "px"; if(!this.loading) { this.prevButt.style.paddingTop = this.buttonPaddingBigY + "px"; this.prevButt.style.paddingBottom = this.buttonPaddingBigY + "px"; this.prevButt.style.top = fLib.getTopScroll() + (((winH - this.buttonSize) / 2) - this.buttonPaddingBigY) + "px"; this.nextButt.style.paddingTop = this.buttonPaddingBigY + "px"; this.nextButt.style.paddingBottom = this.buttonPaddingBigY + "px"; this.nextButt.style.top = fLib.getTopScroll() + (((winH - this.buttonSize) / 2) - this.buttonPaddingBigY) + "px"; this.closeButt.style.marginTop = -15 + fLib.getTopScroll() + ((winH - this.currentImgElem.height) / 2) + "px"; } }; //pri zmene velikosti okna QuickShow.prototype.repairSize = function() { //posunuti obrazku this.setImgPosition(); //zmena velikosti divu this.imgLayer.style.width = "100%"; this.imgLayer.style.height = fLib.getDocumentHeight() + "px"; this.imgLayer2.style.width = "100%"; this.imgLayer2.style.height = fLib.getDocumentHeight() + "px"; }; //zobrazi anim. gif QuickShow.prototype.showLoader = function() { this.currentImgElem = fLib.swapElemetnts(this.loader, this.currentImgElem); this.setImgPosition(); }; QuickShow.prototype.setImage = function(aImg) { var self = this; this.loading = true; this.hidePrevNext(); this.showLoader(); if(this.imgObjectTmp.src != aImg) { this.imgObjectTmp.src = aImg; this.imgObjectTmp.onload = function() { setTimeout(function() { self.swapImages(); }, 300); }; } else { setTimeout(function() { self.swapImages(); }, 300); } this.currentImg = fLib.arIndexOf(this.images, aImg); this.showPrevNext(); }; QuickShow.prototype.swapImages = function() { this.currentImgElem = fLib.swapElemetnts(this.imgObjectTmp, this.currentImgElem); this.loading = false; this.setImgPosition(); }; //zobrazi navigaci QuickShow.prototype.showPrevNext = function() { if(!this.loading) { this.buttonPaddingBigX = Math.round((this.imgObjectTmp.width / 2) - this.buttonPaddingSmall - this.buttonSize); var imgOffset = Math.round((fLib.getWindowWidth() - this.imgObjectTmp.width) / 2) - 10; if(this.currentImg > 0) { this.prevButt.style.paddingRight = this.buttonPaddingBigX + "px"; this.prevButt.style.left = (imgOffset - this.offset) + "px"; fLib.setDisplay(this.prevButt, "block"); } if(this.currentImg < this.images.length - 1) { this.nextButt.style.paddingLeft = this.buttonPaddingBigX + "px"; this.nextButt.style.right = (imgOffset - this.offset) + "px"; fLib.setDisplay(this.nextButt, "block"); } this.closeButt.style.paddingLeft = this.buttonPaddingBigX + "px"; this.closeButt.style.right = (imgOffset - this.offset) + "px"; this.closeButt.style.top = "0px"; fLib.setDisplay(this.closeButt, "block"); } }; //skryje navigaci QuickShow.prototype.hidePrevNext = function() { fLib.setDisplay(this.prevButt, "none"); fLib.setDisplay(this.nextButt, "none"); fLib.setDisplay(this.closeButt, "none"); }; //dalsi obrazek QuickShow.prototype.nextImage = function(e) { fLib.stopPropagation(e); if(this.currentImg + 1 < this.images.length) { var n = this.currentImg + 1; this.setImage(this.images[n]); } }; //predchozi obrazek QuickShow.prototype.prevImage = function(e) { fLib.stopPropagation(e); if(this.currentImg - 1 >= 0) { var n = this.currentImg - 1; this.setImage(this.images[n]); } }; //dalsi obrazek QuickShow.prototype.firstImage = function(e) { fLib.stopPropagation(e); this.setImage(this.images[0]); }; //dalsi obrazek QuickShow.prototype.lastImage = function(e) { fLib.stopPropagation(e); this.setImage(this.images[this.images.length - 1]); }; //prida obrazek do seznamu QuickShow.prototype.addImage = function(aPath) { aPath = fLib.strReplace("&", "&", aPath); this.images.push(aPath); }; QuickShow.prototype.clearImages = function() { this.images = new Array(); }; QuickShow.prototype.getImageCount = function() { return this.images.length; }; QuickShow.prototype.loadControlImages = function(loader, prev, next, close) { this.loaderImgPath = loader; this.prevImgPath = prev; this.nextImgPath = next; this.closeImgPath = close; }; //------------------------------------------------------------------------------ /** * najde ve strukture vsechny linky a jejich href pouzije jako src pro obrazek * * @param contID */ QuickShow.prototype.createFromDOM = function(contID) { var cont = document.getElementById(contID); if(cont) { var anchors = cont.getElementsByTagName("a"); for(var i = 0; i < anchors.length; i++) { this.addImage(anchors[i].href); anchors[i].onclick = this.createAnchorCallback(anchors[i].href); anchors[i].href = "javascript:void(0);"; } } }; QuickShow.prototype.createAnchorCallback = function(url) { var self = this; return function() { self.display(url); }; };