function MovableModalWindow(Title) { this.Show = Show; this.StartDrag = StartDrag; this.EndDrag = EndDrag; this.MoveFunction = MoveFunction; this.RemoveWindow = RemoveWindow; this.SetWH = SetWH; var ID = "modalBox"; var Title = Title; var Width = 300; var Height = 100; var Drag = false; var DragX = 0; var DragY = 0; var ModalObj = null; var ModalObj2 = null; function StartDrag(e) { var LeftClick = false; if(!e) e = window.event; if (e.which) { LeftClick = (e.which == 1); } else if(e.button) { LeftClick = (e.button == 1); } if(LeftClick) { DragX = fLib.getMousePositionX(e); DragY = fLib.getMousePositionY(e); Drag = true; } } function EndDrag() { Drag = false; } function MoveFunction(e) { if(Drag) { if(!e) e = window.event; diffX = fLib.getMousePositionX(e) - DragX; diffY = fLib.getMousePositionY(e) - DragY; DragX = fLib.getMousePositionX(e); DragY = fLib.getMousePositionY(e); ModalWindow.style.left = parseInt(ModalWindow.style.left, 10) + diffX + 'px'; ModalWindow.style.top = parseInt(ModalWindow.style.top, 10) + diffY + 'px'; if(!browser.isIE) { e.cancelBubble = true; e.returnValue = false; } else { e.preventDefault(); } } } //--------------------------------------------------------------------------- function RemoveWindow() { var docBody = document.getElementsByTagName("body")[0]; fLib.removeEvent("mousemove", this.MoveFunction, document); docBody.removeChild(ModalObj); //docBody.removeChild(ModalObj2); } function SetWH(aW, aH) { Width = aW; Height = aH; } function Show() { var docBody = document.getElementsByTagName("body")[0]; //pokud uz existuje if(document.getElementById(ID)) { return false; } /*ModalObj2 = docBody.appendChild(document.createElement("div")); ModalObj2.style.width = fLib.getDocumentWidth() + "px"; ModalObj2.style.height = fLib.getDocumentHeight() + "px"; fLib.setOpacity(20, ModalObj2); ModalObj2.id = ID; ModalObj2.style.backgroundColor = "#000000";*/ ModalObj = docBody.appendChild(document.createElement("div")); ModalObj.id = ID; ModalObj.style.width = fLib.getDocumentWidth() + "px"; ModalObj.style.height = fLib.getDocumentHeight() + "px"; // okynko ModalWindow = document.createElement("div"); ModalWindow.id = "messageBox"; ModalWindow.style.width = Width + 'px'; // centrovani var posTop = Math.round(((fLib.getWindowHeight() - Height) / 2) + fLib.getTopScroll()); if(posTop < 0) { posTop = 10; } ModalWindow.style.top = posTop + "px"; ModalWindow.style.left = Math.round((fLib.getDocumentWidth() - Width)/2) + "px"; // header Header = document.createElement("div"); Header.appendChild(document.createTextNode(Title)); Header.className = "header"; Header.onmousedown = this.StartDrag; Header.onmouseup = this.EndDrag; ModalWindow.appendChild(Header); fLib.addEvent("mousemove", this.MoveFunction, document); ModalObj.appendChild(ModalWindow); this.ModalObj = ModalObj; this.ModalWindow = ModalWindow; } } //============================================================================== function ConfirmationDialog(s) { var ID = "customConfirm"; var Title = "Potvrzení"; var Message = "Potvrzujete akci?"; var YesAction = s; var Parent = new MovableModalWindow(Title); this.Show = Show; this.OKFunction = OKFunction; this.CancelFunction = CancelFunction; function CancelFunction() { Parent.RemoveWindow(); return true; } function OKFunction() { Parent.RemoveWindow(); window.location.replace(YesAction); return true; } function Show() { Parent.Show(); // text msg = Parent.ModalWindow.appendChild(document.createElement("p")); msg.appendChild(document.createTextNode(Message)); // tlacitka div = Parent.ModalWindow.appendChild(document.createElement("div")); div.id = "btnContainer"; btn1 = div.appendChild(document.createElement("button")); btn1.id = "btn"; //btn1.className = "accept"; btn1.appendChild(document.createTextNode("OK")); btn1.onclick = this.OKFunction; btn1.focus(); btn3 = div.appendChild(document.createElement("button")); btn3.id = "btn"; //btn3.className = "delete"; btn3.appendChild(document.createTextNode("Zrušit")); btn3.onclick = this.CancelFunction; } } function ConfirmationDialogForm(text, callBackOK, callbackCancel) { var ID = "customConfirm"; var Title = "Potvrzení"; var Message = text; var Parent = new MovableModalWindow(Title); var CallBackOk = callBackOK; var CallBackCancel = callbackCancel; this.Show = Show; this.OKFunction = OKFunction; this.CancelFunction = CancelFunction; function CancelFunction() { Parent.RemoveWindow(); if(CallBackCancel != null) { CallBackCancel(); return true; } else { return false; } } function OKFunction() { Parent.RemoveWindow(); CallBackOk(); return true; } function Show() { Parent.Show(); // text msg = Parent.ModalWindow.appendChild(document.createElement("p")); msg.appendChild(document.createTextNode(Message)); // tlacitka div = Parent.ModalWindow.appendChild(document.createElement("div")); div.id = "btnContainer"; btn1 = div.appendChild(document.createElement("button")); btn1.id = "btn"; //btn1.className = "accept"; btn1.appendChild(document.createTextNode("OK")); btn1.onclick = this.OKFunction; btn1.focus(); btn3 = div.appendChild(document.createElement("button")); btn3.id = "btn"; //btn3.className = "delete"; btn3.appendChild(document.createTextNode("Zrušit")); btn3.onclick = this.CancelFunction; } } //============================================================================== function QuestionDialog(s, text) { var ID = "customConfirm"; var Title = "Dotaz"; var Message = text; var YesAction = s; var Parent = new MovableModalWindow(Title); this.Show = Show; this.OKFunction = OKFunction; this.CancelFunction = CancelFunction; this.BackFunction = BackFunction; function CancelFunction() { Parent.RemoveWindow(); return true; } function OKFunction() { Parent.RemoveWindow(); window.location.replace(YesAction); return true; } function BackFunction() { Parent.RemoveWindow(); return true; } function Show() { Parent.Show(); // text msg = Parent.ModalWindow.appendChild(document.createElement("p")); //msg.innerHTML = Message; msg.appendChild(document.createTextNode(Message)); // tlacitka div = Parent.ModalWindow.appendChild(document.createElement("div")); div.id = "btnContainer"; btn1 = div.appendChild(document.createElement("button")); btn1.id = "btn"; //btn1.className = "accept"; btn1.appendChild(document.createTextNode("Uložit")); btn1.onclick = this.OKFunction; btn1.focus(); btn2 = div.appendChild(document.createElement("button")); btn2.id = "btn"; btn2.appendChild(document.createTextNode("Neukládat")); btn2.onclick = this.BackFunction; btn3 = div.appendChild(document.createElement("button")); btn3.id = "btn"; //btn3.className = "delete"; btn3.appendChild(document.createTextNode("Zrušit")); btn3.onclick = this.CancelFunction; } } //============================================================================== function AlertDialog(text) { var ID = "customAlert"; var Title = "Výzva"; var Message = text; var Parent = new MovableModalWindow(Title); this.Show = Show; this.OKFunction = OKFunction; function OKFunction() { Parent.RemoveWindow(); return true; } function Show() { Parent.Show(); // text msg = Parent.ModalWindow.appendChild(document.createElement("p")); msg.innerHTML = Message; // tlacitka div = Parent.ModalWindow.appendChild(document.createElement("div")); div.id = "btnContainer"; btn1 = div.appendChild(document.createElement("button")); btn1.id = "btn"; btn1.appendChild(document.createTextNode("OK")); btn1.onclick = this.OKFunction; btn1.focus(); } } //============================================================================== function QueryDialog(message, callBack, initVal) { var ID = "customQuery"; var Title = "Dotaz"; var Message = message; var CallBack = callBack; var InitVal = initVal; var Parent = new MovableModalWindow(Title); this.Show = Show; this.OKFunction = OKFunction; this.CancelFunction = CancelFunction; function CancelFunction() { Parent.RemoveWindow(); return true; } function OKFunction() { Parent.RemoveWindow(); CallBack(inp.value); return true; } function Show() { Parent.Show(); // text msg = Parent.ModalWindow.appendChild(document.createElement("p")); msg.appendChild(document.createTextNode(Message)); // tlacitka div = Parent.ModalWindow.appendChild(document.createElement("div")); div.id = "btnContainer"; frm = msg.appendChild(document.createElement("form")); inp = frm.appendChild(document.createElement("input")); inp.id = "inp"; frm.onsubmit = this.OKFunction; inp.value = InitVal; inp.focus(); inp.select(); btn1 = div.appendChild(document.createElement("button")); btn1.id = "btn"; //btn1.className = "accept"; btn1.appendChild(document.createTextNode("OK")); btn1.onclick = this.OKFunction; btn3 = div.appendChild(document.createElement("button")); btn3.id = "btn"; //btn3.className = "delete"; btn3.appendChild(document.createTextNode("Zrušit")); btn3.onclick = this.CancelFunction; } } //============================================================================== function EditorDialog(text, callBack) { var ID = "customEdit"; var Title = "Editor"; var Parent = new MovableModalWindow(Title); var CallBack = callBack; var Text = text; var area; this.Show = Show; this.OKFunction = OKFunction; this.CancelFunction = CancelFunction; function OKFunction() { Parent.RemoveWindow(); CallBack(area.value); return true; } function CancelFunction() { Parent.RemoveWindow(); return true; } function Show() { Parent.SetWH(800, 580); Parent.Show(); // textarea area = Parent.ModalWindow.appendChild(document.createElement("textarea")); //Parent.ModalWindow.style.width = "550px"; area.value = Text; area.style.width = "750px"; area.style.height = "450px"; area.style.marginLeft = "auto"; area.style.marginRight = "auto"; area.style.fontFamily = "Courier New, monospace"; area.style.styleFloat = "none"; area.style.cssFloat = "none"; // tlacitka var div = Parent.ModalWindow.appendChild(document.createElement("div")); div.id = "btnContainer"; div.style.clear = "both"; var btn1 = div.appendChild(document.createElement("button")); btn1.id = "btn"; //btn1.className = "accept"; btn1.appendChild(document.createTextNode("OK")); btn1.onclick = this.OKFunction; var btn3 = div.appendChild(document.createElement("button")); btn3.id = "btn"; //btn3.className = "delete"; btn3.appendChild(document.createTextNode("Zrušit")); btn3.onclick = this.CancelFunction; area.focus(); } } //============================================================================== function colorDialog(callback) { var callback = callback; var title = "Vyberte barvu"; var parent = new MovableModalWindow(title); var inp; var table; var step = 15; var label; this.show = show; function show() { parent.SetWH(400, 400); parent.Show(); //barvicky table = document.createElement("table"); setColorTable(0); parent.ModalWindow.appendChild(table); label = document.createElement("div"); label.style.textAlign = "center"; parent.ModalWindow.appendChild(label); //modra barva var tableBlue = document.createElement("table"); tr = document.createElement("tr"); tableBlue.appendChild(tr); for(b = 0; b <= 255; b += step) { addTableCell(0, 0, b, tr, recolor); } parent.ModalWindow.appendChild(tableBlue); tableBlue.style.margin = "5px auto 5px auto"; // text msg = parent.ModalWindow.appendChild(document.createElement("p")); msg.appendChild(document.createTextNode(title)); //form frm = msg.appendChild(document.createElement("form")); inp = frm.appendChild(document.createElement("input")); inp.id = "inp"; frm.onsubmit = OKFunction; inp.value = "#000000"; inp.focus(); inp.select(); // tlacitka var div = parent.ModalWindow.appendChild(document.createElement("div")); div.id = "btnContainer"; div.style.clear = "both"; var btn1 = div.appendChild(document.createElement("button")); btn1.id = "btn"; btn1.appendChild(document.createTextNode("OK")); btn1.onclick = OKFunction; var btn3 = div.appendChild(document.createElement("button")); btn3.id = "btn"; btn3.appendChild(document.createTextNode("Zrušit")); btn3.onclick = cancelFunction; } function setColorTable(b) { //vygenerovat paletku a moznost zadat barvu v HEX var r, g, b, tableBlue, tr, td; for(r = 0; r <= 255; r += step) { tr = document.createElement("tr"); table.appendChild(tr); for(g = 0; g <= 255; g += step) { if(g < r) { addTableCell(Math.abs(r), Math.abs(g), Math.abs(g - b), tr, selectColor, showColor); } else { addTableCell(Math.abs(r), Math.abs(g), Math.abs(r - b), tr, selectColor, showColor); } } } table.style.margin = "5px auto 5px auto"; } function addTableCell(r, g, b, tr, eventHandler, eventOver) { td = document.createElement("td"); td.style.border = "1px solid #000000"; td.style.backgroundColor = "rgb(" + r + ", " + g + ", " + b + ")"; td.style.cursor = "pointer"; td.style.padding = "6px"; fLib.addEvent("click", eventHandler, td); if(eventOver) { fLib.addEvent("mouseover", eventOver, td); } tr.appendChild(td); } function selectColor(e) { var elem = fLib.getEventTarget(e); if(elem != null) { inp.value = colors.toHEX(elem.style.backgroundColor); } } function showColor(e) { var elem = fLib.getEventTarget(e); if(elem != null) { label.innerHTML = colors.toHEX(elem.style.backgroundColor); } } function recolor(e) { var elem = fLib.getEventTarget(e); if(elem != null) { var clr = elem.style.backgroundColor; var b = colors.getB(clr); do { table.removeChild(table.firstChild); } while(table.childNodes.length > 0); setColorTable(b); } } function OKFunction() { parent.RemoveWindow(); callback(inp.value); return true; } function cancelFunction() { parent.RemoveWindow(); return true; } } //============================================================================== function dialogsClass() { var dialog = null; this.confirm = confirm; this.confirmForm = confirmForm; this.question = question; this.alert = alert; this.query = query; this.editor = editor; this.color = color; function confirm(s, text) { dialog = new ConfirmationDialog(s); dialog.Show(); dialog = null; } function confirmForm(text, callBackOK, callBackCancel) { dialog = new ConfirmationDialogForm(text, callBackOK, callBackCancel); dialog.Show(); dialog = null; } function question(s, text) { dialog = new QuestionDialog(s, text); dialog.Show(); dialog = null; } function alert(text) { dialog = new AlertDialog(text); dialog.Show(); dialog = null; } function query(message, callBack, initVal) { dialog = new QueryDialog(message, callBack, initVal); dialog.Show(); dialog = null; } function editor(text, callback) { dialog = new EditorDialog(text, callback); dialog.Show(); dialog = null; } function color(callback) { dialog = new colorDialog(callback); dialog.show(); dialog = null; } } var dialogs = new dialogsClass();