//---------------------------------------------------------------------------- // Wikispaces Visual Editor // Copyright 2005 Tangient LLC // //---------------------------------------------------------------------------- // static strings (en.js) // // Buttons var lblSubmit = "Submit"; var lblModeRichText = "Switch to RichText Mode"; var lblModeHTML = "Switch to HTML Mode"; var lblSave = "Save"; var lblPrint = "Print"; var lblSelectAll = "Select/Deselect All"; var lblSpellCheck = "Spell Check"; var lblCut = "Cut"; var lblCopy = "Copy"; var lblPaste = "Paste"; var lblUndo = "Undo"; var lblRedo = "Redo"; var lblHR = "Horizontal Rule"; var lblInsertChar = "Insert Special Character"; var lblInsertCode = "Insert Code"; var lblBold = "Bold"; var lblItalic = "Italic"; var lblUnderline = "Underline"; var lblStrikeThrough = "Strike Through"; var lblSuperscript = "Superscript"; var lblSubscript = "Subscript"; var lblAlgnLeft = "Align Left"; var lblAlgnCenter = "Center"; var lblAlgnRight = "Align Right"; var lblJustifyFull = "Justify Full"; var lblOL = "Ordered List"; var lblUL = "Unordered List"; var lblOutdent = "Outdent"; var lblIndent = "Indent"; var lblTextColor = "Text Color"; var lblBgColor = "Background Color"; var lblSearch = "Search And Replace"; var lblInsertLink = "Add Link"; var lblRemoveLink = "Remove Link"; var lblAddImage = "Images and Files"; var lblEmbedMedia = "Embed Media"; var lblEmbedSource = "Source"; var lblInsertTable = "Insert Table"; // Format Dropdown var lblFormat = ''; //lblFormat += ""; lblFormat += ""; lblFormat += ""; lblFormat += ""; lblFormat += ""; lblFormat += ""; // Alerts var lblErrorPreload = "Error preloading content."; // Dialogs // Insert Link var lblLinkType = "Link Type"; var lblLinkOldA = "existing anchor"; var lblLinkNewA = "new anchor"; var lblLinkNoA = "No Existing Anchors"; var lblLinkAnchors = "Anchors"; var lblLinkAddress = "Address"; var lblLinkText = "Link Text"; var lblLinkOpenIn = "Open Link In"; var lblLinkVal0 = "Please enter a URL"; var lblLinkVal1 = "Please enter a space and page name"; var lblLinkSubmit = "OK"; var lblLinkPreview = "Preview"; var lblLinkCancel = "Cancel"; // Insert Table var lblTableRows = "Rows"; var lblTableColumns = "Columns"; var lblTableWidth = "Table width"; var lblTablePx = "pixels"; var lblTablePercent = "percent"; var lblTableBorder = "Border thickness"; var lblTablePadding = "Cell padding"; var lblTableSpacing = "Cell spacing"; var lblTableSubmit = "OK"; var lblTableCancel = "Cancel"; //---------------------------------------------------------------------------- // init and browser testing // // Contants var lang = "en"; // xhtml language var encoding = "utf-8"; // xhtml encoding, english only use "iso-8859-1" var zeroBorder = "#c0c0c0"; // guideline color - see showGuidelines() // Pointers var InsertChar; var InsertTable; var InsertLink; var EmbedMedia; var dlgReplace; var ua = navigator.userAgent.toLowerCase(); var isIE = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1))? true:false; var isGecko = (ua.indexOf("gecko") != -1)? true:false; var isSafari = (ua.indexOf("safari") != -1)? true:false; var isKonqueror = (ua.indexOf("konqueror") != -1)? true:false; var rng; var currentRTE; var currentHTML; var obj_width; var obj_height; var imagesPath; var includesPath; var cssFile; var isRichText = false; if(document.getElementById && document.designMode && !isSafari && !isKonqueror) isRichText = true; function OutputGrabber() { var result = ''; this.add = add; this.dump = dump; function add(string) { result = result + string; } function dump() { return result; } } //---------------------------------------------------------------------------- // rte initialization // function initRTE(imgPath, incPath, css){ imagesPath = imgPath; includesPath = incPath; cssFile = css; if (isIE) { document.onmouseover = raiseButton; document.onmouseout = normalButton; document.onmousedown = lowerButton; document.onmouseup = raiseButton; } } function writeToolbar(rte) { var cancel_url = '/' + (pagename == 'home' ? '' : encodeURIComponent(pagename)); var output = new OutputGrabber(); output.add('
'); output.add(''); output.add(''); output.add(''); output.add(''); output.add(''); output.add(''); output.add(''); output.add(''); output.add(''); //output.add(''); //output.add(''); output.add(''); output.add(''); output.add(''); output.add(''); output.add(''); output.add(''); output.add(''); output.add(''); output.add(''); output.add(''); output.add(''); output.add(''); output.add(''); output.add(''); output.add('
'+lblBold+''+lblItalic+''+lblUnderline+''+lblOL+''+lblUL+''+lblOutdent+''+lblIndent+''+lblHR+''+lblInsertLink+''+lblRemoveLink+''+lblAddImage+''+lblEmbedMedia+''+lblInsertTable+''+lblInsertChar+''+lblInsertCode+'try our floating toolbar Cancel 
'); output.add('
'); document.write(output.dump()); } function writeRichText(rte, height) { currentRTE = rte; var output = new OutputGrabber(); output.add(''); output.add(''); output.add(''); return output.dump(); } function enableDesignMode(rte, html, css) { var frameHtml = "\n" + "\n"; //to reference your stylesheet, set href property below to your stylesheet path and uncomment if(css.length > 0){ frameHtml += "\n"; } else { frameHtml += "\n"; } frameHtml += ""; frameHtml += html; frameHtml += ""; if (document.all){ var oRTE = frames[rte].document; oRTE.open(); oRTE.write(frameHtml); oRTE.close(); oRTE.designMode = "On"; oRTE.attachEvent("onkeydown", ieKeyPress); } else { try { document.getElementById(rte).contentDocument.designMode = "on"; try { var oRTE = document.getElementById(rte).contentWindow.document; oRTE.open(); oRTE.write(frameHtml); oRTE.close(); if (isGecko) { oRTE.addEventListener("keypress", geckoKeyPress, true); //oRTE.addEventListener("focus", function () { dlgCleanUp(rte) }, false); } if (isGecko) { rteCommand(rte, "useCSS", true); } } catch(e) { alert(lblErrorPreload); } } catch(e) { if (isGecko) { setTimeout("enableDesignMode('"+rte+"', currentHTML, '"+css+"');", 200); return; } else { return false; } } } setTimeout('showGuidelines("'+rte+'");', 300); setTimeout('showCursor("'+rte+'");', 300); setTimeout('enableSpellCheck("'+rte+'");', 300); } function enableSpellCheck(rte) { // Turn on firefox spellchecker document.getElementById(rte).contentWindow.document.getElementsByTagName('body')[0].spellcheck=true; } function rteCleanup(rte) { //dlgCleanUp(rte); Fails to actually clean anything up, and causes problems in IE stripGuidelines(rte); rteSync(rte); } function rteSync(rte) { var oHdnField = document.getElementById('hdn'+rte); if(oHdnField.value == null) oHdnField.value = ""; var sRTE; // Clean up the multiple BODY tags that firefox introduces with outdent oRTE = document.getElementById(currentRTE).contentWindow; bodyTags = oRTE.document.getElementsByTagName('HTML')[0].getElementsByTagName('BODY'); for(i=1; i < bodyTags.length; i++) { bodyTags[0].innerHTML = bodyTags[0].innerHTML + bodyTags[i].innerHTML; bodyTags[i].parentNode.removeChild(bodyTags[i]); } if (document.all) { oHdnField.value = frames[rte].document.body.innerHTML; } else { oHdnField.value = document.getElementById(rte).contentWindow.document.body.innerHTML; } } function rteCommand(rte, command, option){ dlgCleanUp(rte); var oRTE; if (document.all) { oRTE = frames[rte]; var oRng = oRTE.document.selection.createRange(); if ((command == 'insertorderedlist' || command == 'insertunorderedlist') && !oRTE.document.queryCommandState('InsertOrderedList') && !oRTE.document.queryCommandState('InsertUnorderedList')) { // fetch selected range // wrap selection in

if not already present if (oRng.htmlText == '') { if (command == 'insertunorderedlist') { oRng.pasteHTML('

'); } else { oRng.pasteHTML('
  1.  
'); } oRng.moveStart('character', -1); oRng.select(); updateHierarchy(); return true; } else if (!oRng.htmlText.match(/^\s*]*)?>/i)) { // drop extra
s off end, if present var postHtmlText = ''; var htmlText = oRng.htmlText; while (matches = htmlText.match(/(\s*)$/i)) { postHtmlText += matches[1]; htmlText = htmlText.replace(/\s*$/i, ''); } sUnique = new Date().getTime(); oRng.pasteHTML('

' + htmlText + '

' + postHtmlText); oP = oRTE.document.getElementById(sUnique); oRng.moveToElementText(oP); oRng.select(); } // execute command oRTE.focus(); oRTE.document.execCommand(command, false, option); oRTE.focus(); // clean BR elements out of all LIs splitOnBr("li", oRTE.document); oRng.select(); updateHierarchy(); return true; } if (command == 'formatblock') { var oRng = oRTE.document.selection.createRange(); var htmlText = oRng.htmlText; if (htmlText != '') { parentNode = ieGetParent(); sTag = option.toUpperCase().replace(/[<>]/g, ''); // tag is h* if (sTag.match(/^H\d$/)) { if (parentNode.nodeName.match(/^H\d$/)) { if (parentNode.nodeName != sTag) { // change of h* tag var sPreserve = parentNode.innerHTML; var oNewNode = oRTE.document.createElement(sTag); parentNode.replaceNode(oNewNode); oNewNode.innerHTML = sPreserve; splitOnBr(sTag, oRTE.document); } else { // same h* tag return false; } } else { htmlText = htmlText.replace(/\s*$/i, ''); htmlText = htmlText.replace(/^\s*

/i, ''); htmlText = htmlText.replace(/<\/p>\s*$/i, ''); oRng.pasteHTML('<' + sTag + '>' + htmlText + ''); splitOnBr(sTag, oRTE.document); } // tag is p, parent is h* } else if (parentNode != null && parentNode.nodeName.match(/^H\d$/)) { var sPreserve = parentNode.innerHTML; var oNewNode = oRTE.document.createElement("SPAN"); parentNode.replaceNode(oNewNode); oNewNode.innerHTML = sPreserve; } oRng.select(); oRTE.focus(); } return true; } } else { oRTE = document.getElementById(rte).contentWindow; } try { oRTE.focus(); oRTE.document.execCommand(command, false, option); oRTE.focus(); if (command != 'useCSS') { detectedChangeDelayed(); } } catch(e) { } } //---------------------------------------------------------------------------- // dialog boxes // function dlgInsertChar(rte, command) { self.command = command; currentRTE = rte; InsertChar = popUpWin(includesPath+'insert_char.htm', 'InsertChar', 500, 200, 'status=yes,resizable=yes,', rte); } function dlgInsertTable(rte, command) { self.command = command; currentRTE = rte; InsertTable = popUpWin(includesPath + 'insert_table.htm', 'InsertTable', 500, 200, 'status=yes,resizable=yes,', rte); } function dlgInsertImg(rte, command) { toggleImageEditTool(); } function urlencode(s) { return(encodeURIComponent(s.replace('+', ' '))); } function urldecode(s) { return(decodeURIComponent(s)); } function dlgInsertLink(rte, command) { self.command = command; oNode = selectParent('A'); rng = setRange(rte); var linkText = ''; var spaceName = ''; var pageName = ''; var anchorName = ''; var extLink = ''; var extProt = ''; if (!selectedImage) { if (isIE) { linkText = stripHTML(rng.htmlText); } else { linkText = stripHTML(rng.toString()); } } if (oNode) { var hrefText = oNode.getAttribute('href', 2) + ''; // URLs can point to the instance domain rWikispacesURL = new RegExp(''); var domain = siteDomainShort.replace('.', '\.'); rWikispacesURL.compile('^http[s]?://([a-z0-9-]+)\.(' + domain + ')/([^#]+)(#(.+)){0,1}$', 'gi'); // They can point to the current domain, which might be a custom domain and not the instance domain rCurrentDomainURL = new RegExp(''); domain = location.hostname.replace('.', '\.'); rCurrentDomainURL.compile('^http[s]?://(' + domain + ')/([^#]+)(#(.+)){0,1}$', 'gi'); // They might be relative links in the current space rWikispacesURLPage = new RegExp(''); rWikispacesURLPage.compile( '^/([^#]+)(#(.+)){0,1}$', 'i'); // Or they might be external links off the site rURL = new RegExp(''); rURL.compile('^((http|https|ftp|mailto):(\/\/)?)(.*)$', 'i'); var sWikispacesURL = rWikispacesURL.exec(hrefText); var sCurrentDomainURL = rCurrentDomainURL.exec(hrefText); if (sWikispacesURL) { spaceName = sWikispacesURL[1]; pageName = sWikispacesURL[3]; anchorName = (sWikispacesURL[5]) ? sWikispacesURL[5] : ''; } else if (sCurrentDomainURL) { spaceName = ''; pageName = sCurrentDomainURL[2]; anchorName = (sCurrentDomainURL[4]) ? sCurrentDomainURL[5] : ''; } else { var sWikispacesURLPage = rWikispacesURLPage.exec(hrefText); if (sWikispacesURLPage) { spaceName = ''; pageName = sWikispacesURLPage[1]; anchorName = (sWikispacesURLPage[3]) ? sWikispacesURLPage[3] : ''; } else { var sURL = rURL.exec(hrefText); if (sURL) { extProt = sURL[2]; extLink = sURL[4]; } } } } var mode = 'text'; if (selectedImage && selectedImage.src) { mode = 'image'; } sPopupURI = '/page/insertlink/?' + 'text=' + encodeURIComponent(linkText) + '&space=' + encodeURIComponent(spaceName) + '&page=' + encodeURIComponent(pageName) + '&anchor=' + encodeURIComponent(anchorName) + '&extLink=' + encodeURIComponent(extLink) + '&extProt=' + encodeURIComponent(extProt) + '&mode=' + encodeURIComponent(mode); rteSync(rte); InsertLink = popUpWin(sPopupURI, 'InsertLink', 640, 320, 'status=yes,resizable=yes,', rte); } function dlgEmbedMedia(rte) { sPopupURI = '/page/embedmedia/' + encodeURIComponent(pagename) + '/'; if (selectedMedia) { sPopupURI += '?media=' + encodeURIComponent(selectedMedia.id); } rteSync(rte); EmbedMedia = popUpWin(sPopupURI, 'EmbedMedia', 740, 520, 'status=yes,resizable=yes,scrollbars=yes,', rte); } function dlgCleanUp(rte){ if (InsertChar != null) InsertChar.close(); InsertChar=null; if (InsertTable != null) InsertTable.close(); InsertTable=null; if (InsertLink != null) InsertLink.close(); InsertLink=null; if (EmbedMedia != null) EmbedMedia.close(); EmbedMedia=null; if (dlgReplace != null) dlgReplace.close(); dlgReplace=null; } //---------------------------------------------------------------------------- // dialog support methods // function popUpWin (url, win, width, height, options, rte) { dlgCleanUp(rte); var leftPos = (screen.availWidth - width) / 2; var topPos = (screen.availHeight - height) / 2; options += 'width=' + width + ',height=' + height + ',left=' + leftPos + ',top=' + topPos; return window.open(url, win, options); } function selectFont(rte, selectname){ var idx = document.getElementById(selectname).selectedIndex; var selected = document.getElementById(selectname).options[idx].value; var cmd = selectname.replace('_'+rte, ''); rteCommand(rte, cmd, selected); document.getElementById(selectname).selectedIndex = 0; } function moveSelectionIntoEditor(win) { // IE range/selection support is trash, but it doesn't seem to have the bug that firefox has where // the selection ends up outside the body if (document.all) { return; } var sel = win.getSelection(); var range = sel.getRangeAt(0); var startContainer = range.startContainer; var bodyElement = win.document.getElementById('editor_body'); // Make a new range inside the body if the current range is inside the HTML element (or worse) if (startContainer != bodyElement && !Element.childOf(startContainer, bodyElement)) { var newRange = win.document.createRange(); newRange.setStart(win.document.getElementById('editor_body'), 0); newRange.setStart(win.document.getElementById('editor_body'), 0); newRange.collapse(true); sel.addRange(newRange); sel.removeRange(range); } } function insertHTML(html) { var rte = currentRTE; var oRTE; if (document.all) { oRTE = frames[rte]; } else { oRTE = document.getElementById(rte).contentWindow; } moveSelectionIntoEditor(oRTE); if (document.all) { oRTE.focus(); var oRng = oRTE.document.selection.createRange(); oRng.pasteHTML(html); oRng.collapse(false); oRng.select(); } else { // delete selected text var oSel = oRTE.getSelection() ; for (var i = 0; i < oSel.rangeCount; i++) { oSel.getRangeAt(i).deleteContents(); } // reset range var oRange = oSel.getRangeAt(0); var oFragment = oRange.createContextualFragment(html); var oLastNode = oFragment.lastChild; oRange.insertNode(oFragment); //oRange.setEndAfter(oLastNode); //oRange.setStartAfter(oLastNode); oSel.removeAllRanges(); oSel = oRTE.getSelection(); oSel.addRange(oRange); oRTE.focus(); } detectedChangeDelayed(); } function insertNodeAtSelection(win, insertNode) { // get current selection moveSelectionIntoEditor(win); var sel = win.getSelection(); var updateSel = true; // get the first range of the selection // (there's almost always only one range) var range = sel.getRangeAt(0); // deselect everything sel.removeAllRanges(); // remove content of current selection from document range.deleteContents(); // get location of current selection var container = range.startContainer; var pos = range.startOffset; // make a new range for the new selection range=document.createRange(); if (container.nodeType==3 && insertNode.nodeType==3) { // if we insert text in a textnode, do optimized insertion container.insertData(pos, insertNode.nodeValue); // put cursor after inserted text range.setEnd(container, pos+insertNode.length); range.setStart(container, pos+insertNode.length); } else { var afterNode; if (container.nodeType==3) { // when inserting into a textnode // we create 2 new textnodes // and put the insertNode in between var textNode = container; container = textNode.parentNode; var text = textNode.nodeValue; // text before the split var textBefore = text.substr(0,pos); // text after the split var textAfter = text.substr(pos); var beforeNode = document.createTextNode(textBefore); afterNode = document.createTextNode(textAfter); // insert the 3 new nodes before the old one container.insertBefore(afterNode, textNode); container.insertBefore(insertNode, afterNode); container.insertBefore(beforeNode, insertNode); // remove the old node container.removeChild(textNode); } else { // else simply insert the node afterNode = container.childNodes[pos]; container.insertBefore(insertNode, afterNode); } if (afterNode != null) { range.setEnd(afterNode, 0); range.setStart(afterNode, 0); } else { range.setEnd(container, 0); range.setStart(container, 0); } } sel.addRange(range); detectedChangeDelayed(); }; // store the currently-selected text range // function setRange(rte){ var oRTE; if (document.all) { oRTE = frames[rte]; var selection = oRTE.document.selection; if (selection != null) rng = selection.createRange(); } else { oRTE = document.getElementById(rte).contentWindow; var selection = oRTE.getSelection(); rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange(); } return rng; } function stripHTML(strU) { var strN = strU.replace(/(<([^>]+)>)/ig,""); strN = strN.replace(/\r\n/g," "); strN = strN.replace(/\n/g," "); strN = strN.replace(/\r/g," "); return strN; } function showCursor(rte) { if (document.all) { oRTE = frames[rte]; oRTE.focus(); //oSel = oRTE.getSelection(); TODO - IE } else { oRTE = document.getElementById(rte).contentWindow; oRTE.focus(); oNode = oRTE.document.getElementById("editor_body").lastChild; oRange = document.createRange(); oRange.setEndAfter(oNode); oRange.setStartAfter(oNode); oSel = oRTE.getSelection(); oSel.addRange(oRange); oRTE.focus(); } } function showGuidelines(rte) { if (rte.length == 0) rte = currentRTE; var oRTE; if(document.all) { oRTE = frames[rte]; } else { oRTE = document.getElementById(rte).contentWindow; } var tables = oRTE.document.getElementsByTagName("table"); for (var i=0; i' + '<' + parentNode.nodeName + ' dom="tired">'); var oRange = oRTE.document.selection.createRange(); oRange.select(); return false; } */ // insert
and following nbsp insertHTML('
 '); // remove nbsp var oRange = oRTE.document.selection.createRange(); oRange.moveStart('character', -1); oRange.select(); oRTE.document.selection.clear(); return false; } break; case 9: // tab if (!(e.ctrlKey || e.altKey)) { // add indent if inside list if (oRTE.document.queryCommandState('InsertOrderedList') || oRTE.document.queryCommandState('InsertUnorderedList')) { if (e.shiftKey) { rteCommand(currentRTE, 'outdent', ''); return false; } else { rteCommand(currentRTE, 'indent', ''); return false; } } } break; } } function ieGetParent() { var oNode = null; oRTE = frames[currentRTE]; oRTE.focus(); var oRange = oRTE.document.selection.createRange(); oNode = oRange.parentElement(); while (oNode) { if (oNode.nodeType == 1 && oNode.nodeName != 'P' && oNode.nodeName != 'SPAN' && oNode.nodeName != 'A') { return(oNode); } if (oNode.parentNode) { oNode = oNode.parentNode; } else { return null; } } } function raiseButton(e) { var el = window.event.srcElement; className = el.className; if (className == 'rteImg' || className == 'rteImgDn') { el.className = 'rteImgUp'; } } function normalButton(e) { var el = window.event.srcElement; className = el.className; if (className == 'rteImgUp' || className == 'rteImgDn') { el.className = 'rteImg'; } } function lowerButton(e) { var el = window.event.srcElement; className = el.className; if (className == 'rteImg' || className == 'rteImgUp') { el.className = 'rteImgDn'; } } function splitOnBr(tag, d) { listElements = d.body.getElementsByTagName(tag); for (i = 0; i < listElements.length; i++) { oLiChildren = listElements.item(i).childNodes; // descend into paragraphs if (oLiChildren.length > 0 && oLiChildren.item(0).tagName == 'p' || oLiChildren.item(0).tagName == 'P') { oLiChildren = oLiChildren.item(0).childNodes; } lastLi = listElements.item(i); var oNewLi = d.createElement(tag); isBrFound = false; j = 0; while (oLiChildren.length > j) { if (oLiChildren.item(j).nodeType == 1 && (oLiChildren.item(j).tagName == 'br' || oLiChildren.item(j).tagName == 'BR')) { if (oNewLi.childNodes.length) { lastLi = lastLi.insertAdjacentElement("afterEnd", oNewLi); } var oNewLi = d.createElement(tag); oLiChildren.item(j).removeNode(); isBrFound = true; } else { if (isBrFound) { oNewLi.appendChild(oLiChildren.item(j).cloneNode(true)); oLiChildren.item(j).removeNode(); } else { j++; } } } if (oNewLi.childNodes.length) { lastLi = lastLi.insertAdjacentElement("afterEnd", oNewLi); } } } function customEditorStart(contentStorageId) { var editorHighlightContent = false; if ('' == document.getElementById(contentStorageId).innerHTML || 'Type in the content of your new page here.' == document.getElementById(contentStorageId).innerHTML) { editorHighlightContent = true; document.getElementById(contentStorageId).innerHTML = 'Type in the content of your new page here.'; } try { // best guess height for now var height = Element.getDimensions(document.getElementById(contentStorageId)).height; if (height < 300) { height = 300; } document.getElementById('editor').innerHTML = writeRichText(editorId, height); enableDesignMode(editorId, document.getElementById(contentStorageId).innerHTML, stylesheetUrl); if (editorHighlightContent) { setTimeout("rteCommand(editorId, 'selectall', '')", 200); } if (document.all) { oRTE = frames[editorId].document; } else { oRTE = document.getElementById(editorId).contentWindow.document; } Event.observe(oRTE, "keyup", lookForChange, true); Event.observe(oRTE, "mousedown", clickImage, true); //Event.observe(oRTE, "keyup", preventNewlines, true); // Can't attach it now, so wait a second //setTimeout("attachPasteHandler();", 200); Event.observe(oRTE, "keyup", function() {setTimeout('updateHierarchy()', 10)}, true); Event.observe(oRTE, "mouseup", function() {setTimeout('updateHierarchy()', 10)}, true); //window.onscroll = scrollDetected; // Can't use Event.observe for some reason if (Cookie.get('floatingToolbar') == 1) { floatToolbar(); } } catch (e) { return false; } return true; } function scrollDetected(e) { return; var toolbar = document.getElementById('Buttons1_'+currentRTE); // TODO: verify this in both browsers, looks like overkill if (window.innerHeight) { pos = window.pageYOffset; } else if (document.documentElement && document.documentElement.scrollTop) { pos = document.documentElement.scrollTop; } else if (document.body) { pos = document.body.scrollTop; } if (pos > toolbar.offsetTop) { floatToolbar(); } else { if (toolbarPopup) { toolbarPopup.hide(); } } } function preventNewlines(e) { // Handle CTRL-V, Shift-INS in Firefox and Shift-Enter in both browsers, and look for
inside of a

  • if (((e.ctrlKey && e.keyCode == e.DOM_VK_V) || (e.shiftKey && e.keyCode == e.DOM_VK_INSERT) || (e.shiftKey && e.keyCode == 13)) && isSelectionUnderTag(currentRTE, 'LI') != false) { var liElement = isSelectionUnderTag(currentRTE, 'LI'); removeBrFromElement(liElement); } } function lookForChange(e) { keycode = e.keyCode; shiftKey = e.shiftKey; if (keycode == Event.KEY_ESC || keycode == Event.KEY_LEFT || keycode == Event.KEY_UP || keycode == Event.KEY_RIGHT || keycode == Event.KEY_DOWN || keycode == 16 // shift || keycode == 17 // ctrl || keycode == 18 // alt || keycode == 20 // capslock || keycode == 91 // windows key || keycode == 93 // windows menu key || keycode == 33 // page up || keycode == 34 // page down || keycode == 35 // end || keycode == 36 // home || keycode == 45 // insert || keycode == 255 // bios specific keys ) { return; } else { detectedChange(); } } /** * IE Only paste handler. Need to schedule this after the body loads, so attachPasteHandler need to be called from a * setTimeout() */ function attachPasteHandler() { Event.observe(frames[editorId].document.getElementsByTagName('body')[0], "beforepaste", handlePaste, false); } function handlePaste(e) { var liElement = isSelectionUnderTag(currentRTE, 'LI'); var data = frames[editorId].clipboardData.getData("Text"); var regex = new RegExp('(\n)', "mgi"); var newData = data.replace(regex, ''); alert(data); alert(newData); if (liElement && data != newData) { alert('scheduling'); setTimeout(function() {removeBrFromElement(liElement)}, 100); } } /* * Remove the newline added to an element. */ function removeBrFromElement(element) { alert('trying to remove br'); var regex = new RegExp('()', 'mgi'); var oldHtml = element.innerHTML; newHtml = oldHtml.replace(regex, ''); if (oldHtml != newHtml) { element.innerHTML = newHtml; if (document.getSelection) { document.getElementById(editorId).contentWindow.getSelection().getRangeAt(0).collapse(false); } else { sel = frames[editorId].document.selection.createRange(); sel.endContainer = sel.startContainer; sel.endOffset = sel.startOffset; } alert('Newlines are not supported in lists'); } } function getSelectionContainer(rte) { if (selectedImage) { oNode = selectedImage; return oNode; } if (selectedMedia) { oNode = selectedImage; return oNode; } if(document.all){ oRTE = frames[rte]; oRTE.focus(); oRange = oRTE.document.selection.createRange(); return oRange.parentElement(); } else { oRTE = document.getElementById(currentRTE).contentWindow; oRTE.focus(); oNode = oRTE.window.getSelection().getRangeAt(0).commonAncestorContainer; return oNode; } } function isSelectionUnderTag(rte, tagName) { oNode = getSelectionContainer(rte); examineNode = oNode; while(examineNode != null) { if (examineNode.tagName == tagName) { return examineNode; } examineNode = examineNode.parentNode; } return false; } function updateHierarchy() { var elem = getSelectionContainer(currentRTE); var parentString = ''; unsetAllButtons(); while(elem && elem.tagName != 'BODY') { if (elem.tagName) { setChildStatus(elem); parentString = elem.tagName + ' > ' + parentString; } else { parentString = 'text > ' + parentString; } elem = elem.parentNode; } if (selectedMedia) { setButton('rteMediaBtn'); document.getElementById('rteImageBtn').className = 'rteImg'; } document.getElementById('hierarchy').innerHTML = parentString; } function unsetAllButtons() { document.getElementById('rteBoldBtn').className = 'rteImg'; document.getElementById('rteItalicBtn').className = 'rteImg'; document.getElementById('rteUnderlineBtn').className = 'rteImg'; document.getElementById('rteOrderedListBtn').className = 'rteImg'; document.getElementById('rteUnorderedListBtn').className = 'rteImg'; document.getElementById('rteLinkBtn').className = 'rteImg'; document.getElementById('rteImageBtn').className = 'rteImg'; document.getElementById('rteMediaBtn').className = 'rteImg'; document.getElementById('rteTableBtn').className = 'rteImg'; document.getElementById('rteCodeBtn').className = 'rteImg'; setFormat('p'); } function setFormat(value) { var options = document.getElementById('formatblock_'+currentRTE).options; for (i=0; i') { document.getElementById('formatblock_'+currentRTE).selectedIndex = i; } } // Disable format dropdown on code/pre if (value == 'pre' || value == 'code') { document.getElementById('formatblock_'+currentRTE).disabled = true; } else { document.getElementById('formatblock_'+currentRTE).disabled = false; } } function setChildStatus(node) { switch (node.tagName) { case "STRONG": case "B": setButton('rteBoldBtn'); break; case "EM": case "I": setButton('rteItalicBtn'); break; case "U": setButton('rteUnderlineBtn'); break; case "OL": setButton("rteOrderedListBtn"); break; case "UL": setButton("rteUnorderedListBtn"); break; case "A": setButton("rteLinkBtn"); break; case "IMG": setButton("rteImageBtn"); break; case "TABLE": setButton("rteTableBtn"); break; case "H1": setFormat('h1'); break; case "H2": setFormat('h2'); break; case "H3": setFormat('h3'); break; case "PRE": setCodeFormat(node.className); setButton('rteCodeBtn'); break; } if (node.style.fontStyle == 'italic') { setButton('rteItalicBtn'); } if (node.style.fontWeight == 'bold') { setButton('rteBoldBtn'); } if (node.style.textDecoration == 'underline') { setButton('rteUnderlineBtn'); } } function setCodeFormat(className) { setFormat('code'); var optionValue = 'Code'; if (className) { optionValue += ' (' + className + ')'; } document.getElementById('formatblock_'+currentRTE).options[document.getElementById('formatblock_'+currentRTE).selectedIndex].innerHTML = optionValue; } function setButton(buttonName) { document.getElementById(buttonName).className = 'rteImg rteImgUp'; } function textEditorSubmit() { autosaveSync(); if (conflictingEditDetected && editorSaving) { showConcurrentEditorPopup(); editorSaving = false; return confirm("Someone else has made changes to this page since you started editing.\n\nIf you click OK, we will save your page and overwrite their changes. You will still be able to look back at their changes from the page history tab.\n\nIf you click Cancel, you can either cancel your edit entirely and start again with the latest copy of the page, or use the Page Activity window to look at the changes they have made."); } return true; } function visualEditorSubmit() { autosaveSync(); rteCleanup(editorId); if (conflictingEditDetected && editorSaving) { showConcurrentEditorPopup(); editorSaving = false; return confirm("Someone else has made changes to this page since you started editing.\n\nIf you click OK, we will save your page and overwrite their changes. You will still be able to look back at their changes from the page history tab.\n\nIf you click Cancel, you can either cancel your edit entirely and start again with the latest copy of the page, or use the Page Activity window to look at the changes they have made."); } return true; } function insertInTextEditor(myValue) { var myField = document.getElementById('textEditor'); //IE support if (document.selection) { myField.focus(); sel = document.selection.createRange(); sel.text = myValue; } //MOZILLA/NETSCAPE support else if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); } else { myField.value += myValue; } detectedChange(); } var toolbarPopup; var originalToolbar; function floatToolbar() { var originalCenter = Math.floor(Position.cumulativeOffset(document.getElementById('editor'))[0] + (Element.getDimensions(document.getElementById('editor'))['width'] / 2)); document.getElementById('tryFloatingToolbar').innerHTML = ''; var toolbar = document.getElementById('Buttons1_' + editorId); originalToolbar = toolbar.parentNode.removeChild(toolbar); originalToolbar.className = ''; toolbarPopup = new Window('toolbarPopup', { minWidth: 300, title: 'Visual Editor', resizable: false, maximizable: false, minimizable: false, className: 'wikispaces', showEffect: Element.show, hideEffect: Element.hide, helpText: ''}); toolbarPopup.setContent(toolbar, true, true); toolbarPopup.setDestroyOnClose(); toolbarPopup.show(); toolbarPopup.toFront(); toolbarPopup.updateWidth(); toolbarPopup.updateHeight(); // Find left location var toolbarWidth = Element.getDimensions(toolbarPopup.element)['width'] / 2; var newLeft = Math.floor(originalCenter - toolbarWidth); toolbarPopup.element.style.left = newLeft + 'px'; // Find top location (and maintain it for IE scrolling) if (document.all) { toolbarPopup.element.style.top = document.documentElement.scrollTop + 'px'; scrollToolbarPopup = function() { if (toolbarPopup) { toolbarPopup.element.style.top = document.documentElement.scrollTop + 'px'; } }; registerOnScroll(scrollToolbarPopup); } else { toolbarPopup.element.style.position = 'fixed'; toolbarPopup.element.style.top = '0px'; } // workaround for slight undersizing of window; avoid horizontal scrollbar toolbarPopup.getContent().style.overflow = 'hidden'; Windows.addObserver({ onClose: function(eventName, win) { if (win == toolbarPopup) { unFloatToolbar(); toolbarPopup = null; //window.location = '/' + pagename; } }}); Cookie.set('floatingToolbar', 1, undefined); } function unFloatToolbar() { document.getElementById('Buttons1_container').appendChild(originalToolbar); document.getElementById('tryFloatingToolbar').innerHTML = 'float toolbar'; originalToolbar.className = 'rteBk'; Cookie.set('floatingToolbar', 0, undefined); } var codePopup; var cursorPos; function openCodePopup() { // Save cursor position in IE if (document.selection) { cursorPos=document.selection.createRange().duplicate(); } if (document.getElementById('formatblock_'+currentRTE).options[document.getElementById('formatblock_'+currentRTE).selectedIndex].value == '') { alert('You cannot insert a code block inside another code block'); return; } if (!codePopup) { codePopup = new Window('codePopup', { minWidth: 300, title: 'Insert Code', resizable: false, maximizable: false, minimizable: false, className: 'wikispaces', showEffect: Element.show, hideEffect: Element.hide }); codePopup.setContent(document.getElementById('codePopupContents'), true, true); } codePopup.showCenter(); codePopup.toFront(); } function insertCode() { var code = document.codeForm.code.value; code = code.escapeHTML(); var format = document.codeForm.format.value; if (!format) { format = 'text'; } // restore cursor position in IE if (cursorPos) { cursorPos.select(); } insertInEditor('
    ' + code + '
    '); document.codeForm.reset(); Windows.close('codePopup'); } var onScrollFunctions = Array(); function registerOnScroll(func) { onScrollFunctions[onScrollFunctions.length] = func; } window.onscroll = function() { for(i=0; i