508 lines
13 KiB
JavaScript
508 lines
13 KiB
JavaScript
/** flexicon js functions
|
|
* @version 1.0.4
|
|
* @since 2007-04-29
|
|
* @author martin lenzelbauer
|
|
*
|
|
*/
|
|
|
|
|
|
// === GENERAL EDITING ========================================================= //
|
|
|
|
var dataTransferStarted = false;
|
|
|
|
//labels the page as not saved
|
|
function unsave(){
|
|
document.getElementById("saved").value = 0;
|
|
}
|
|
|
|
//checks if the current document is saved
|
|
function checkSubmit(){
|
|
if(dataTransferStarted){
|
|
return false;
|
|
}
|
|
var doSave = true;
|
|
if(document.getElementById("action").value == "cancel" && document.getElementById("saved").value == 0){
|
|
doSave = confirm("Ungespeicherte Daten verwerfen?");
|
|
}
|
|
if(doSave){
|
|
dataTransferStarted = true;
|
|
}
|
|
return doSave;
|
|
}
|
|
|
|
//enables a new data transfer
|
|
function enableDataTransfer(){
|
|
dataTransferStarted = false;
|
|
}
|
|
|
|
//writes the action into a hidden input field
|
|
function setAction(action, pos, type){
|
|
document.getElementById("action").value = action;
|
|
document.getElementById("position").value = pos;
|
|
document.getElementById("type").value = type;
|
|
}
|
|
|
|
//writes the action for downloading a file
|
|
function download(type){
|
|
setAction(type, 0, 0);
|
|
setTimeout("enableDataTransfer()", 1000);
|
|
}
|
|
|
|
//writes the action for previewing the element
|
|
function showPreview(id){
|
|
window.open("../preview.php?id="+id);
|
|
}
|
|
|
|
//writes the action for inserting a new element
|
|
function insertElement(type, pos){
|
|
document.getElementById("action").value = "insert";
|
|
document.getElementById("position").value = pos;
|
|
document.getElementById("type").value = type;
|
|
if(!dataTransferStarted){
|
|
document.forms[0].submit();
|
|
dataTransferStarted = true;
|
|
}
|
|
}
|
|
|
|
//writes the action for moving an element
|
|
function moveElement(direction, pos){
|
|
document.getElementById("action").value = "move"+direction;
|
|
document.getElementById("position").value = pos;
|
|
if(!dataTransferStarted){
|
|
document.forms[0].submit();
|
|
dataTransferStarted = true;
|
|
}
|
|
}
|
|
|
|
//writes the action for deleting an element
|
|
function deleteElement(pos){
|
|
if(confirm("Diese Element löschen?")){
|
|
document.getElementById("action").value = "delete";
|
|
document.getElementById("position").value = pos;
|
|
if(!dataTransferStarted){
|
|
document.forms[0].submit();
|
|
dataTransferStarted = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
//writes the action for recycling a page element
|
|
function recyclePage(pos){
|
|
document.getElementById("action").value = "recycle";
|
|
document.getElementById("position").value = pos;
|
|
if(!dataTransferStarted){
|
|
document.forms[0].submit();
|
|
dataTransferStarted = true;
|
|
}
|
|
}
|
|
|
|
//writes the action for cutting a page element
|
|
function cutPage(pos){
|
|
document.getElementById("action").value = "cut";
|
|
document.getElementById("position").value = pos;
|
|
if(!dataTransferStarted){
|
|
document.forms[0].submit();
|
|
dataTransferStarted = true;
|
|
}
|
|
}
|
|
|
|
|
|
//writes the action for pasting a page element
|
|
function pastePage(pos){
|
|
document.getElementById("action").value = "paste";
|
|
document.getElementById("position").value = pos;
|
|
if(!dataTransferStarted){
|
|
document.forms[0].submit();
|
|
dataTransferStarted = true;
|
|
}
|
|
}
|
|
|
|
//loads a new page
|
|
function loadPage(path){
|
|
if(dataTransferStarted){
|
|
return;
|
|
}
|
|
var doSave = true;
|
|
if(document.getElementById("saved").value == 0){
|
|
doSave = confirm("Ungespeicherte Daten verwerfen?");
|
|
}
|
|
if(doSave){
|
|
document.getElementById("action").value = "load";
|
|
document.getElementById("position").value = path;
|
|
dataTransferStarted = true;
|
|
document.forms[0].submit();
|
|
}
|
|
}
|
|
|
|
|
|
//logs out the current user
|
|
function logout(){
|
|
if(dataTransferStarted){
|
|
return;
|
|
}
|
|
var doSave = true;
|
|
if(document.getElementById("saved").value == 0){
|
|
doSave = confirm("Ungespeicherte Daten verwerfen?");
|
|
}
|
|
if(doSave){
|
|
document.getElementById("action").value = "logout";
|
|
dataTransferStarted = true;
|
|
document.forms[0].submit();
|
|
}
|
|
}
|
|
|
|
|
|
//selects/deselects all checkboxes
|
|
function selectAllCheckboxes(masterBox, id){
|
|
var checked = false;
|
|
var checkBox;
|
|
var count = 0;
|
|
if(masterBox.checked){
|
|
checked = true;
|
|
}
|
|
checkBox = document.getElementById(id + count);
|
|
while(checkBox != null){
|
|
checkBox.checked = checked;
|
|
count++;
|
|
checkBox = document.getElementById(id + count);
|
|
}
|
|
}
|
|
|
|
|
|
// === TEXT EDITING ============================================================ //
|
|
|
|
//saves the current caret position
|
|
function saveCaretPos(node) {
|
|
if(node.createTextRange){
|
|
node.caretPos = document.selection.createRange().duplicate();
|
|
}
|
|
unsave();
|
|
}
|
|
|
|
//inserts a text at the current caret position
|
|
function insertText(text, targetId){
|
|
|
|
var node = document.getElementById(targetId);
|
|
|
|
//FF
|
|
if(document.getSelection){
|
|
var start = node.selectionStart;
|
|
var end = node.selectionEnd;
|
|
var t = node.value;
|
|
node.value = t.substring(0, start) + text + t.substring(start);
|
|
}
|
|
|
|
//IE
|
|
else if(document.selection){
|
|
if(node.caretPos){
|
|
node.caretPos.text = text;
|
|
}
|
|
else{
|
|
node.value = text;
|
|
}
|
|
}
|
|
|
|
node.focus();
|
|
}
|
|
|
|
|
|
//inserts a [f]bold[/f] formatted text
|
|
function insertBold(targetId){
|
|
var text = prompt("Text, der fett geschrieben werden soll:", "");
|
|
if(text == null){
|
|
return;
|
|
}
|
|
insertText("[f]"+text+"[/f]", targetId);
|
|
}
|
|
|
|
//inserts a [k]italic[/k] formatted text
|
|
function insertItalic(targetId){
|
|
var text = prompt("Text, der kursiv geschrieben werden soll:", "");
|
|
if(text == null){
|
|
return;
|
|
}
|
|
insertText("[k]"+text+"[/k]", targetId);
|
|
}
|
|
|
|
//inserts a hyperlink
|
|
function insertLink(targetId){
|
|
var textarea = document.getElementById(targetId);
|
|
var url = prompt("Zieladresse:", "http://");
|
|
if(url == null){
|
|
return;
|
|
}
|
|
var urltext = prompt("Text, der als Link angezeigt werden soll:", url);
|
|
if(urltext == null){
|
|
return;
|
|
}
|
|
var newwindow = prompt("Soll der Link in einem neuen Fenster geöffnet werden?\n (1=ja, 0=nein)", "1");
|
|
if(newwindow == "1"){
|
|
newwindow = "ja";
|
|
}
|
|
else{
|
|
newwindow = "nein";
|
|
}
|
|
insertText("[url="+url+" neu="+newwindow+"]"+urltext+"[/url]", targetId);
|
|
}
|
|
|
|
//inserts a e-mail link
|
|
function insertMail(targetId){
|
|
var textarea = document.getElementById(targetId);
|
|
var url = prompt("E-Mail Adresse:", "");
|
|
if(url == null){
|
|
return;
|
|
}
|
|
var urltext = prompt("Text, der als Link angezeigt werden soll:", url);
|
|
if(urltext == null){
|
|
return;
|
|
}
|
|
insertText("[url=mailto:"+url+" neu=ja]"+urltext+"[/url]", targetId);
|
|
}
|
|
|
|
//inserts a button for a print version
|
|
function insertPrintVersion(targetId){
|
|
var textarea = document.getElementById(targetId);
|
|
insertText("[print] ", targetId);
|
|
}
|
|
|
|
|
|
|
|
// === BACKGROUND HIGHLIGHTING ======================================================= //
|
|
|
|
//changes the background color of a html element to the given color
|
|
function changeBackground(node, color){
|
|
node.style.backgroundColor = color;
|
|
}
|
|
|
|
// === IMAGE PRELOADING ============================================================== //
|
|
|
|
|
|
var preloadImages;
|
|
var preloadImg ;
|
|
var preloadIndex;
|
|
var preloadInterval;
|
|
|
|
|
|
//starts image preloading
|
|
function preloadImages(startIndex){
|
|
return;
|
|
preloadImages = new Array("arrow_down.png", "arrow_up.png",
|
|
"category1.png", "category2.png",
|
|
"date1.png", "date2.png",
|
|
"delete1.png", "delete2.png",
|
|
"email_link1.png", "email_link2.png",
|
|
"event1.png",
|
|
"file1.png", "file2.png",
|
|
"gallery1.png", "gallery2.png",
|
|
"header1.png", "header2.png",
|
|
"html1.png", "html2.png",
|
|
"hyperlink1.png", "hyperlink2.png",
|
|
"image1.png", "image2.png",
|
|
"logout.png",
|
|
"menu1.png", "menu2.png",
|
|
"movedown1.png", "movedown2.png", "movedown3.png",
|
|
"moveup1.png", "moveup2.png", "moveup3.png",
|
|
"person1.png", "person2.png",
|
|
"personpage1.png", "personpage2.png",
|
|
"phppage1.png", "phppage2.png",
|
|
"print1.png", "print2.png",
|
|
"recyclepage1.png", "recyclepage2.png",
|
|
"reduction1.png", "reduction2.png",
|
|
"stdpage1.png", "stdpage2.png",
|
|
"template1.png", "template2.png",
|
|
"text1.png", "text2.png",
|
|
"text_bold1.png", "text_bold2.png",
|
|
"text_italic1.png", "text_italic2.png",
|
|
"ticket1.png",
|
|
"trash.png",
|
|
"website1.png", "website2.png"
|
|
);
|
|
if(startIndex >= preloadImages.length){
|
|
return;
|
|
}
|
|
preloadIndex = startIndex;
|
|
preloadNextImage();
|
|
}
|
|
|
|
|
|
//loads next image
|
|
function preloadNextImage(){
|
|
if(preloadIndex >= preloadImages.length){
|
|
clearInterval(preloadInterval);
|
|
return;
|
|
}
|
|
preloadImg = new Image();
|
|
preloadImg.src = preloadImages[preloadIndex];
|
|
clearInterval(preloadInterval);
|
|
preloadInterval = setInterval("preloadStatus()", 200);
|
|
}
|
|
|
|
//checks the preload status
|
|
function preloadStatus(){
|
|
if(preloadImg.complete){
|
|
preloadIndex++;
|
|
document.getElementById("preloadindex").value = preloadIndex;
|
|
preloadNextImage();
|
|
}
|
|
}
|
|
|
|
|
|
// === IMAGE SWAPPING ============================================================== //
|
|
|
|
//swaps a rollover image
|
|
function swapImage(node, no){
|
|
var file = node.src;
|
|
node.src = file.substring(0, file.length-5) + no + ".png";
|
|
}
|
|
|
|
|
|
// === DATA TRANSFER =============================================================== //
|
|
|
|
var dataTransferWidth = 400;
|
|
var dataTransferHeight = 300;
|
|
|
|
|
|
//creates the "data transfer" div
|
|
function initDataTransfer(){
|
|
if(document.createElement){
|
|
var el = document.createElement('div');
|
|
el.id = "datatransfer";
|
|
with(el.style){
|
|
position = "absolute";
|
|
display = "none";
|
|
}
|
|
//el.innerHTML = "Daten werden übertragen";
|
|
document.body.appendChild(el);
|
|
}
|
|
}
|
|
|
|
//shows the "data transfer" div
|
|
function showDataTransfer(){
|
|
document.getElementById("datatransfer").style.display = "block";
|
|
setInterval("updateDataTransfer()", 200);
|
|
}
|
|
|
|
//updates the "data tranfer" div to keep it on the correct position
|
|
function updateDataTransfer(){
|
|
var el = document.getElementById("datatransfer");
|
|
//ff
|
|
if(window.innerWidth){
|
|
el.style.left = window.innerWidth/2 - dataTransferWidth/2 + "px";
|
|
el.style.top = window.innerHeight/2 - dataTransferHeight/2 + window.pageYOffset + "px";
|
|
}
|
|
//ie
|
|
else{
|
|
el.style.left = document.documentElement.clientWidth/2 - dataTransferWidth/2 + "px";
|
|
el.style.top = document.documentElement.clientHeight/2 - dataTransferHeight/2 + document.documentElement.scrollTop + "px";
|
|
}
|
|
/*if(el.innerHTML.length < 80){
|
|
el.innerHTML += ".";
|
|
}*/
|
|
}
|
|
|
|
|
|
// === GALLERY ============================================================== //
|
|
|
|
//opens gallery for editing
|
|
function openGallery(position){
|
|
if(document.getElementById("saved").value == 0 && confirm("Aktuelle Änderungen speichern?")){
|
|
document.getElementById("action").value = "openGalleryAndSave";
|
|
}
|
|
else{
|
|
document.getElementById("action").value = "openGallery";
|
|
}
|
|
document.getElementById("position").value = position;
|
|
dataTransferStarted = true;
|
|
document.forms[0].submit();
|
|
}
|
|
|
|
|
|
// === TICKETS ================================================================= //
|
|
|
|
//loads an event
|
|
function loadEvent(id){
|
|
document.getElementById("action").value = "loadEvent";
|
|
document.getElementById("position").value = id;
|
|
dataTransfertStarted = true;
|
|
document.forms[0].submit();
|
|
}
|
|
|
|
//deletes an event
|
|
function deleteEvent(id){
|
|
if(confirm("Diese Veranstaltung löschen?")){
|
|
document.getElementById("action").value = "deleteEvent";
|
|
document.getElementById("position").value = id;
|
|
dataTransfertStarted = true;
|
|
document.forms[0].submit();
|
|
}
|
|
}
|
|
|
|
//asks if all tickets should be deleted if the reservation type is changed
|
|
function changeReservationType(ask){
|
|
var type = document.getElementById("oldReservationType").value;
|
|
if(ask){
|
|
if(confirm("Bisherige Reservierungen verwerfen und Reservierungstyp ändern?")){
|
|
document.forms[0].submit();
|
|
}
|
|
else{
|
|
document.getElementById("newReservationType").value = type;
|
|
}
|
|
}
|
|
else{
|
|
document.forms[0].submit()
|
|
}
|
|
}
|
|
|
|
//gets xml data from flash
|
|
function setXML(foo){
|
|
document.getElementById("xmldata").value = foo;
|
|
}
|
|
|
|
//returns reference to flash object
|
|
function getFlash(movieName){
|
|
if(window.document[movieName]){
|
|
return window.document[movieName];
|
|
}
|
|
if(navigator.appName.indexOf("Microsoft Internet") == -1){
|
|
if (document.embeds && document.embeds[movieName]){
|
|
return document.embeds[movieName];
|
|
}
|
|
}
|
|
else {
|
|
return document.getElementById(movieName);
|
|
}
|
|
}
|
|
|
|
//shows detail view of a customer
|
|
function showCustomer(id, tr){
|
|
if(tr.firstChild.firstChild.style.overflow == "visible"){
|
|
for(i=0; i<tr.childNodes.length; i++){
|
|
tr.childNodes[i].firstChild.style.overflow = "hidden";
|
|
tr.childNodes[i].firstChild.style.backgroundColor = "#FFFFFF";
|
|
tr.childNodes[i].firstChild.style.height = "14px";
|
|
}
|
|
}
|
|
else{
|
|
for(i=0; i<tr.childNodes.length; i++){
|
|
tr.childNodes[i].firstChild.style.height = "100px";
|
|
tr.childNodes[i].firstChild.style.overflow = "visible";
|
|
tr.childNodes[i].firstChild.style.backgroundColor = "#EEEEEE";
|
|
}
|
|
}
|
|
/*
|
|
if(document.getElementById("cc" + id).style.display == "block"){
|
|
document.getElementById("cc" + id).style.display = "none";
|
|
document.getElementById("ce" + id).style.display = "none";
|
|
document.getElementById("cn" + id).style.display = "none";
|
|
document.getElementById("ca" + id).style.display = "none";
|
|
tr.style.backgroundColor = "#FFFFFF";
|
|
}
|
|
else{
|
|
document.getElementById("cc" + id).style.display = "block";
|
|
document.getElementById("ce" + id).style.display = "block";
|
|
document.getElementById("cn" + id).style.display = "block";
|
|
document.getElementById("ca" + id).style.display = "block";
|
|
tr.style.backgroundColor = "#EEEEEE";
|
|
}
|
|
*/
|
|
} |