/*********************************************************************** * MyLittleJavaScript * ************************************************************************ * Created by Michael Loesler * * * * This script is part of my little forum * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * ***********************************************************************/ /*********************************************************************** * NOTICE: In order to reduce bandwidth usage, a minimized version of * * this script is used by default (posting.min.js). Changes in this * * file do not have any effect unless it is loaded by the template * * (themes/[THEME FOLDER]/main.tpl). * * The minimized version was created with the YUI Compressor * * . * ***********************************************************************/ /** * Klasse fuer BB-Code Schaltflaechen * @param el */ function BBCodeButton(el) { if (!el) return; var buttonGroup = null; var self = this; var htmlEl = null; this.canInsert = function() { return buttonGroup && buttonGroup.getTextArea(); }; this.getCode = function() { return htmlEl.name; }; this.getButtonGroup = function() { return buttonGroup; }; this.addButtonGroup = function(group) { buttonGroup = group; }; this.insertCode = function(obj) { if (!this.canInsert()) return; var txtarea = buttonGroup.getTextArea(); var selectionRange = txtarea.getSelection(); txtarea.insertTextRange( "[" + this.getCode() + "]" + selectionRange + "[/" + this.getCode() + "]" ); }; this.setHTMLElement = function(el) { htmlEl = el; htmlEl.onclick = function(e) { self.insertCode(this); return false; } }; this.getHTMLElement = function(el) { return htmlEl; }; this.setHTMLElement(el); } /** * Sonderbutton - LINK * @param el */ function BBCodeLinkButton(el) { this.constructor(el); var link_bb_code = "link"; var regExpURI = new RegExp(/[http|https|ftp|ftps]:\/\/[a-zA-Z0-9-.][a-zA-Z0-9-.]+(S+)?/); var regExpFID = new RegExp(/[?|&]id=([0-9]+)/); var forumURI = window.location.hostname + window.location.pathname; this.insertCode = function(obj) { if (!this.canInsert()) return; var buttonGroup = this.getButtonGroup(); var txtarea = buttonGroup.getTextArea(); var selectionRange = txtarea.getSelection().trim(); var insert_link = (regExpURI.test( selectionRange ))?window.prompt(lang["bbcode_link_url"], selectionRange):window.prompt(lang["bbcode_link_url"],"http://"); if (!insert_link || insert_link == '' || insert_link == "http://") return; if (insert_link.indexOf(forumURI) > 0 && regExpFID.test(insert_link)) { var msgQuery = regExpFID.exec(insert_link); link_bb_code = "msg"; insert_link = msgQuery[1]; } else link_bb_code = "link"; if (selectionRange == '' || regExpURI.test( selectionRange )) selectionRange = window.prompt(lang["bbcode_link_text"], ""); if (selectionRange != null) { if(selectionRange != '') txtarea.insertTextRange( "["+link_bb_code+"=" + insert_link + "]" + selectionRange + "[/"+link_bb_code+"]" ); else txtarea.insertTextRange( "["+link_bb_code+"]" + insert_link + "[/"+link_bb_code+"]" ); } }; } /** * Sonderbutton mit Promt-Box * @param el * @param quest * @param par */ function BBCodePromtButton(el, quest, par) { this.constructor(el); par = par || ""; this.insertCode = function(obj) { if (!this.canInsert()) return; var buttonGroup = this.getButtonGroup(); var txtarea = buttonGroup.getTextArea(); var selectionRange = txtarea.getSelection().trim(); if (selectionRange == "") { var p = window.prompt(quest, par); if (p && p.trim() != "" && p.trim() != par ) txtarea.insertTextRange( "[" + this.getCode() + "]" + p + "[/" + this.getCode() + "]" ); } else txtarea.insertTextRange( "[" + this.getCode() + "]" + selectionRange + "[/" + this.getCode() + "]" ); }; } /** * Sonderbutton - COLOR * @param el */ function BBCodeColorChooserButton(el) { this.constructor(el); var colors = ['#fff','#ccc','#c0c0c0','#999','#666','#333','#000', '#fcc','#f66','#f00','#c00','#900','#600','#300', '#fc9','#f96','#f90','#f60','#c60','#930','#630', '#ff9','#ff6','#fc6','#fc3','#c93','#963','#633', '#ffc','#ff3','#ff0','#fc0','#990','#660','#330', '#9f9','#6f9','#3f3','#3c0','#090','#060','#030', '#9ff','#3ff','#6cc','#0cc','#399','#366','#033', '#cff','#6ff','#3cf','#36f','#33f','#009','#006', '#ccf','#99f','#66c','#63f','#60c','#339','#309', '#fcf','#f9f','#c6c','#c3c','#939','#636','#303']; var colorTable = document.createElement("table"); var colorTableBody = document.createElementWithAttributes("tbody", [], colorTable); var self = this; var row = document.createElementWithAttributes("tr", [], colorTableBody); for (var i=0; i 0) { obj = { code : "", title : lang["more_smilies_title"], label : lang["more_smilies_label"], classes : "more-smilies", isSmilie: true, childs : list }; createSingleButton(obj, buttonBar); } } } /** * Wandelt die BB-Code-Anleitung in klickbare Elemente um */ var convertInstructionsToButton = function() { if (!document.getElementById("bbcode-bar")) return; var buttonBar = document.getElementById("bbcode-bar"); if (document.getElementById("bbcode-instructions")) { var el = document.getElementById("bbcode-instructions").firstChild; var obj = null; while (el != null) { if (el.nodeName && el.nodeName.toLowerCase() == "dt") { if (obj) createSingleButton(obj, buttonBar); obj = { code : el.id, label : el.title, title : el.firstChild.nodeValue, classes : el.className, childs : [] } } else if (obj && el.nodeName && el.nodeName.toLowerCase() == "dd") { var attChild = { attribute : el.id, label : el.title } obj.childs.push( attChild ); } el = el.nextSibling; } if (obj) createSingleButton(obj, buttonBar); } }; /** * Fuegt einen BB-Button dem Dokument hinzu. * @param button * @param isUserButton */ var addButton = function(button, isUserButton) { isUserButton = isUserButton || false; if (button instanceof BBCodeButton) { button.addButtonGroup(self); if (isUserButton || !hasUserButtons) buttons[ button.getCode() ] = button; else if (buttons[ button.getCode() ]) { var firstHtmlEl = buttons[ button.getCode() ].getHTMLElement(); var lastHtmlEl = button.getHTMLElement(); button.setHTMLElement( firstHtmlEl ); lastHtmlEl.parentNode.removeChild( lastHtmlEl ); buttons[ button.getCode() ] = button; } else if (!isUserButton && hasUserButtons) { var htmlEl = button.getHTMLElement(); htmlEl.parentNode.removeChild( htmlEl ); } } } /** * Erzeugt einen einfachen Klick-Button, der ein SPAN-Element enthaelt * aus einem spezifischen Objekt * @param obj * @param buttonBar */ var createSingleButton = function(obj, buttonBar) { var par = [["className", obj.classes], ["name", obj.code], ["type", "button"], ["title", obj.title]]; var id = obj.code.trim() == ""?"bbcodebutton":"bbcodebutton-"+obj.code; if (obj.isSmilie) par.push(["isSmilie", obj.isSmilie]); else par.push(["id", id]); var b = document.createElementWithAttributes("button", par, buttonBar); var buttonSpan = document.createElement("span"); if (typeof obj.label == "string") buttonSpan.appendChild(document.createTextNode( obj.label )); else buttonSpan.appendChild( obj.label ); b.appendChild(buttonSpan); addButton(createBBCodeButton(b, obj.childs)); }; /** * Erzeugt aus einem normalen Klick-Button ein * BBCodeButton-Objekt (ggf. mit Zusatzoptionen) * @param button * @param list * @return button */ var createBBCodeButton = function(button, list) { var bbCodeButton = null; switch(button.name.toLowerCase()) { case "link": bbCodeButton = new BBCodeLinkButton( button ); break; case "img": if (list && list.length > 1) bbCodeButton = new BBCodeOptionButton(button, list, lang["bbcode_image_url"], "http://" ); else bbCodeButton = new BBCodePromtButton( button, lang["bbcode_image_url"], "http://" ); break; case "color": bbCodeButton = new BBCodeColorChooserButton( button ); break; case "list": bbCodeButton = new BBCodeListButton( button ); break; case "flash": bbCodeButton = new BBCodePopUpButton( button, "index.php?mode=insert_flash", settings["flash_popup_width"], settings["flash_popup_height"]); break; case "upload": bbCodeButton = new BBCodePopUpButton( button, "index.php?mode=upload_image", settings["upload_popup_width"], settings["upload_popup_height"]); break; case "tex": bbCodeButton = new BBCodePromtButton( button, lang["bbcode_tex_code"] ); break; default: if (button.isSmilie && list && list.length > 1) bbCodeButton = new BBCodeSmilieButton( button, list ); else if (button.isSmilie) bbCodeButton = new BBCodeSingleSmilieButton( button ); else if (list && list.length > 1) bbCodeButton = new BBCodeOptionButton( button, list ); else bbCodeButton = new BBCodeButton( button ); break; } return bbCodeButton; } /** * Erzeugt ein Fenster, in dem die Zusatzoptionen * angezeigt werden koennen * @return win */ var createAdditionalOptionsWindow = function() { var w = document.createElementWithAttributes("div", [["id", "bbcode-options"]], document.body); var content = document.createElementWithAttributes("div", [], w); w.style.display = "none"; w.style.position = "absolute"; var timeout = null; w.onmouseover = function(e) { if (timeout) window.clearTimeout(timeout); } w.onmouseout = function(e) { e = e || window.event; var toElement = e.relatedTarget || e.toElement || false; var self = this; if (!this.contains(toElement)) { timeout = window.setTimeout( function() { self.enableOptionList(false); }, 125); } return false; }; w.setOptionList = function(list) { if (!content.firstChild) content.appendChild(list); else content.replaceChild(list, content.firstChild); }; w.enableOptionList = function(enable, pos) { if (pos) { this.style.left = pos.left + "px"; this.style.top = pos.top + "px"; } this.style.display = enable?"":"none"; }; var oldOnKeyPressFunc = window.document.onmousedown; window.document.onkeypress = function(e) { var keyCode = document.getKeyCode(e); if (keyCode == 27) self.enableOptionList(false); if (typeof oldOnKeyPressFunc == "function") oldOnKeyPressFunc(e); } return w; }; /** * Sucht nach Button, die der Nutzer * ins Dokument eingefuegt hat * @param isSmilie */ var initUserBBCodeButtons = function(isSmilie) { isSmilie = isSmilie || false; hasUserButtons = false; var id = isSmilie?"smiley-bar":"bbcode-bar"; if (!document.getElementById(id)) return; var userButtons = document.getElementById(id).getElementsByTagName("button"); if (userButtons && userButtons.length > 0) { for (var i=0; i