/* Functions for the advlink plugin popup */ var templates = { "window.open" : "window.open('${url}','${target}','${options}')" }; function preinit() { // Initialize tinyMCE.setWindowArg('mce_windowresize', false); // Import external list url javascript var url = tinyMCE.getParam("external_link_list_url"); if (url != null) { // Fix relative if (url.charAt(0) != '/' && url.indexOf('://') == -1) url = tinyMCE.documentBasePath + "/" + url; document.write(''); } } function changeClass() { var formObj = document.forms[0]; formObj.classes.value = getSelectValue(formObj, 'classlist'); } function init() { tinyMCEPopup.resizeToInnerSize(); var formObj = document.forms[0]; var inst = tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id')); var elm = inst.getFocusElement(); var action = "insert"; var html; document.getElementById('hrefbrowsercontainer').innerHTML = getBrowserHTML('hrefbrowser','href','file','advlink'); document.getElementById('popupurlbrowsercontainer').innerHTML = getBrowserHTML('popupurlbrowser','popupurl','file','advlink'); document.getElementById('linklisthrefcontainer').innerHTML = getLinkListHTML('linklisthref','href'); document.getElementById('anchorlistcontainer').innerHTML = getAnchorListHTML('anchorlist','href'); document.getElementById('targetlistcontainer').innerHTML = getTargetListHTML('targetlist','target'); // Link list html = getLinkListHTML('linklisthref','href'); if (html == "") document.getElementById("linklisthrefrow").style.display = 'none'; else document.getElementById("linklisthrefcontainer").innerHTML = html; // Resize some elements if (isVisible('hrefbrowser')) document.getElementById('href').style.width = '260px'; if (isVisible('popupurlbrowser')) document.getElementById('popupurl').style.width = '180px'; elm = tinyMCE.getParentElement(elm, "a"); if (elm != null && elm.nodeName == "A") action = "update"; formObj.insert.value = tinyMCE.getLang('lang_' + action, 'Insert', true); setPopupControlsDisabled(true); if (action == "update") { var href = tinyMCE.getAttrib(elm, 'href'); href = convertURL(href, elm, true); // Use mce_href if found var mceRealHref = tinyMCE.getAttrib(elm, 'mce_href'); if (mceRealHref != "") { href = mceRealHref; if (tinyMCE.getParam('convert_urls')) href = convertURL(href, elm, true); } var onclick = tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onclick')); // Setup form data setFormValue('href', href); setFormValue('title', tinyMCE.getAttrib(elm, 'title')); setFormValue('id', tinyMCE.getAttrib(elm, 'id')); setFormValue('style', tinyMCE.serializeStyle(tinyMCE.parseStyle(tinyMCE.getAttrib(elm, "style")))); setFormValue('rel', tinyMCE.getAttrib(elm, 'rel')); setFormValue('rev', tinyMCE.getAttrib(elm, 'rev')); setFormValue('charset', tinyMCE.getAttrib(elm, 'charset')); setFormValue('hreflang', tinyMCE.getAttrib(elm, 'hreflang')); setFormValue('dir', tinyMCE.getAttrib(elm, 'dir')); setFormValue('lang', tinyMCE.getAttrib(elm, 'lang')); setFormValue('tabindex', tinyMCE.getAttrib(elm, 'tabindex', typeof(elm.tabindex) != "undefined" ? elm.tabindex : "")); setFormValue('accesskey', tinyMCE.getAttrib(elm, 'accesskey', typeof(elm.accesskey) != "undefined" ? elm.accesskey : "")); setFormValue('type', tinyMCE.getAttrib(elm, 'type')); setFormValue('onfocus', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onfocus'))); setFormValue('onblur', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onblur'))); setFormValue('onclick', onclick); setFormValue('ondblclick', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'ondblclick'))); setFormValue('onmousedown', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onmousedown'))); setFormValue('onmouseup', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onmouseup'))); setFormValue('onmouseover', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onmouseover'))); setFormValue('onmousemove', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onmousemove'))); setFormValue('onmouseout', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onmouseout'))); setFormValue('onkeypress', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onkeypress'))); setFormValue('onkeydown', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onkeydown'))); setFormValue('onkeyup', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onkeyup'))); setFormValue('target', tinyMCE.getAttrib(elm, 'target')); setFormValue('classes', tinyMCE.getAttrib(elm, 'class')); // Parse onclick data if (onclick != null && onclick.indexOf('window.open') != -1) parseWindowOpen(onclick); else parseFunction(onclick); // Select by the values selectByValue(formObj, 'dir', tinyMCE.getAttrib(elm, 'dir')); selectByValue(formObj, 'rel', tinyMCE.getAttrib(elm, 'rel')); selectByValue(formObj, 'rev', tinyMCE.getAttrib(elm, 'rev')); selectByValue(formObj, 'linklisthref', href); if (href.charAt(0) == '#') selectByValue(formObj, 'anchorlist', href); addClassesToList('classlist', 'advlink_styles'); selectByValue(formObj, 'classlist', tinyMCE.getAttrib(elm, 'class'), true); selectByValue(formObj, 'targetlist', tinyMCE.getAttrib(elm, 'target'), true); } else addClassesToList('classlist', 'advlink_styles'); window.focus(); } function setFormValue(name, value) { document.forms[0].elements[name].value = value; } function convertURL(url, node, on_save) { return eval("tinyMCEPopup.windowOpener." + tinyMCE.settings['urlconverter_callback'] + "(url, node, on_save);"); } function parseWindowOpen(onclick) { var formObj = document.forms[0]; // Preprocess center code if (onclick.indexOf('return false;') != -1) { formObj.popupreturn.checked = true; onclick = onclick.replace('return false;', ''); } else formObj.popupreturn.checked = false; var onClickData = parseLink(onclick); if (onClickData != null) { formObj.ispopup.checked = true; setPopupControlsDisabled(false); var onClickWindowOptions = parseOptions(onClickData['options']); var url = onClickData['url']; if (tinyMCE.getParam('convert_urls')) url = convertURL(url, null, true); formObj.popupname.value = onClickData['target']; formObj.popupurl.value = url; formObj.popupwidth.value = getOption(onClickWindowOptions, 'width'); formObj.popupheight.value = getOption(onClickWindowOptions, 'height'); formObj.popupleft.value = getOption(onClickWindowOptions, 'left'); formObj.popuptop.value = getOption(onClickWindowOptions, 'top'); if (formObj.popupleft.value.indexOf('screen') != -1) formObj.popupleft.value = "c"; if (formObj.popuptop.value.indexOf('screen') != -1) formObj.popuptop.value = "c"; formObj.popuplocation.checked = getOption(onClickWindowOptions, 'location') == "yes"; formObj.popupscrollbars.checked = getOption(onClickWindowOptions, 'scrollbars') == "yes"; formObj.popupmenubar.checked = getOption(onClickWindowOptions, 'menubar') == "yes"; formObj.popupresizable.checked = getOption(onClickWindowOptions, 'resizable') == "yes"; formObj.popuptoolbar.checked = getOption(onClickWindowOptions, 'toolbar') == "yes"; formObj.popupstatus.checked = getOption(onClickWindowOptions, 'status') == "yes"; formObj.popupdependent.checked = getOption(onClickWindowOptions, 'dependent') == "yes"; buildOnClick(); } } function parseFunction(onclick) { var formObj = document.forms[0]; var onClickData = parseLink(onclick); // TODO: Add stuff here } function getOption(opts, name) { return typeof(opts[name]) == "undefined" ? "" : opts[name]; } function setPopupControlsDisabled(state) { var formObj = document.forms[0]; formObj.popupname.disabled = state; formObj.popupurl.disabled = state; formObj.popupwidth.disabled = state; formObj.popupheight.disabled = state; formObj.popupleft.disabled = state; formObj.popuptop.disabled = state; formObj.popuplocation.disabled = state; formObj.popupscrollbars.disabled = state; formObj.popupmenubar.disabled = state; formObj.popupresizable.disabled = state; formObj.popuptoolbar.disabled = state; formObj.popupstatus.disabled = state; formObj.popupreturn.disabled = state; formObj.popupdependent.disabled = state; setBrowserDisabled('popupurlbrowser', state); } function parseLink(link) { link = link.replace(new RegExp(''', 'g'), "'"); var fnName = link.replace(new RegExp("\\s*([A-Za-z0-9\.]*)\\s*\\(.*", "gi"), "$1"); // Is function name a template function var template = templates[fnName]; if (template) { // Build regexp var variableNames = template.match(new RegExp("'?\\$\\{[A-Za-z0-9\.]*\\}'?", "gi")); var regExp = "\\s*[A-Za-z0-9\.]*\\s*\\("; var replaceStr = ""; for (var i=0; i'); for (var i=0; i'; html += ''; for (var i=0; i' + name + ''; } html += ''; return html; } function insertAction() { var inst = tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id')); var elm = inst.getFocusElement(); elm = tinyMCE.getParentElement(elm, "a"); tinyMCEPopup.execCommand("mceBeginUndoLevel"); // Create new anchor elements if (elm == null) { if (tinyMCE.isSafari) tinyMCEPopup.execCommand("mceInsertContent", false, '' + inst.selection.getSelectedHTML() + ''); else tinyMCEPopup.execCommand("createlink", false, "#mce_temp_url#"); var elementArray = tinyMCE.getElementsByAttributeValue(inst.getBody(), "a", "href", "#mce_temp_url#"); for (var i=0; i' + tinyMCELinkList[i][0] + ''; html += ''; return html; // tinyMCE.debug('-- image list start --', html, '-- image list end --'); } function getTargetListHTML(elm_id, target_form_element) { var targets = tinyMCE.getParam('theme_advanced_link_targets', '').split(';'); var html = ''; html += ''; return html; } // While loading preinit();