bgneal@312: tinyMCEPopup.requireLangPack(); bgneal@312: bgneal@312: var LinkDialog = { bgneal@312: preInit : function() { bgneal@312: var url; bgneal@312: bgneal@312: if (url = tinyMCEPopup.getParam("external_link_list_url")) bgneal@312: document.write(''); bgneal@312: }, bgneal@312: bgneal@312: init : function() { bgneal@312: var f = document.forms[0], ed = tinyMCEPopup.editor; bgneal@312: bgneal@312: // Setup browse button bgneal@312: document.getElementById('hrefbrowsercontainer').innerHTML = getBrowserHTML('hrefbrowser', 'href', 'file', 'theme_advanced_link'); bgneal@312: if (isVisible('hrefbrowser')) bgneal@312: document.getElementById('href').style.width = '180px'; bgneal@312: bgneal@312: this.fillClassList('class_list'); bgneal@312: this.fillFileList('link_list', 'tinyMCELinkList'); bgneal@312: this.fillTargetList('target_list'); bgneal@312: bgneal@312: if (e = ed.dom.getParent(ed.selection.getNode(), 'A')) { bgneal@312: f.href.value = ed.dom.getAttrib(e, 'href'); bgneal@312: f.linktitle.value = ed.dom.getAttrib(e, 'title'); bgneal@312: f.insert.value = ed.getLang('update'); bgneal@312: selectByValue(f, 'link_list', f.href.value); bgneal@312: selectByValue(f, 'target_list', ed.dom.getAttrib(e, 'target')); bgneal@312: selectByValue(f, 'class_list', ed.dom.getAttrib(e, 'class')); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: update : function() { bgneal@442: var f = document.forms[0], ed = tinyMCEPopup.editor, e, b, href = f.href.value.replace(/ /g, '%20'); bgneal@312: bgneal@312: tinyMCEPopup.restoreSelection(); bgneal@312: e = ed.dom.getParent(ed.selection.getNode(), 'A'); bgneal@312: bgneal@312: // Remove element if there is no href bgneal@312: if (!f.href.value) { bgneal@312: if (e) { bgneal@312: b = ed.selection.getBookmark(); bgneal@312: ed.dom.remove(e, 1); bgneal@312: ed.selection.moveToBookmark(b); bgneal@312: tinyMCEPopup.execCommand("mceEndUndoLevel"); bgneal@312: tinyMCEPopup.close(); bgneal@312: return; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Create new anchor elements bgneal@312: if (e == null) { bgneal@312: ed.getDoc().execCommand("unlink", false, null); bgneal@442: tinyMCEPopup.execCommand("mceInsertLink", false, "#mce_temp_url#", {skip_undo : 1}); bgneal@312: bgneal@312: tinymce.each(ed.dom.select("a"), function(n) { bgneal@312: if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') { bgneal@312: e = n; bgneal@312: bgneal@312: ed.dom.setAttribs(e, { bgneal@442: href : href, bgneal@312: title : f.linktitle.value, bgneal@312: target : f.target_list ? getSelectValue(f, "target_list") : null, bgneal@312: 'class' : f.class_list ? getSelectValue(f, "class_list") : null bgneal@312: }); bgneal@312: } bgneal@312: }); bgneal@312: } else { bgneal@312: ed.dom.setAttribs(e, { bgneal@442: href : href, bgneal@312: title : f.linktitle.value, bgneal@312: target : f.target_list ? getSelectValue(f, "target_list") : null, bgneal@312: 'class' : f.class_list ? getSelectValue(f, "class_list") : null bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: // Don't move caret if selection was image bgneal@312: if (e.childNodes.length != 1 || e.firstChild.nodeName != 'IMG') { bgneal@312: ed.focus(); bgneal@312: ed.selection.select(e); bgneal@312: ed.selection.collapse(0); bgneal@312: tinyMCEPopup.storeSelection(); bgneal@312: } bgneal@312: bgneal@312: tinyMCEPopup.execCommand("mceEndUndoLevel"); bgneal@312: tinyMCEPopup.close(); bgneal@312: }, bgneal@312: bgneal@312: checkPrefix : function(n) { bgneal@312: if (n.value && Validator.isEmail(n) && !/^\s*mailto:/i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_email'))) bgneal@312: n.value = 'mailto:' + n.value; bgneal@312: bgneal@312: if (/^\s*www\./i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_external'))) bgneal@312: n.value = 'http://' + n.value; bgneal@312: }, bgneal@312: bgneal@312: fillFileList : function(id, l) { bgneal@312: var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl; bgneal@312: bgneal@312: l = window[l]; bgneal@312: bgneal@312: if (l && l.length > 0) { bgneal@312: lst.options[lst.options.length] = new Option('', ''); bgneal@312: bgneal@312: tinymce.each(l, function(o) { bgneal@312: lst.options[lst.options.length] = new Option(o[0], o[1]); bgneal@312: }); bgneal@312: } else bgneal@312: dom.remove(dom.getParent(id, 'tr')); bgneal@312: }, bgneal@312: bgneal@312: fillClassList : function(id) { bgneal@312: var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl; bgneal@312: bgneal@312: if (v = tinyMCEPopup.getParam('theme_advanced_styles')) { bgneal@312: cl = []; bgneal@312: bgneal@312: tinymce.each(v.split(';'), function(v) { bgneal@312: var p = v.split('='); bgneal@312: bgneal@312: cl.push({'title' : p[0], 'class' : p[1]}); bgneal@312: }); bgneal@312: } else bgneal@312: cl = tinyMCEPopup.editor.dom.getClasses(); bgneal@312: bgneal@312: if (cl.length > 0) { bgneal@312: lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), ''); bgneal@312: bgneal@312: tinymce.each(cl, function(o) { bgneal@312: lst.options[lst.options.length] = new Option(o.title || o['class'], o['class']); bgneal@312: }); bgneal@312: } else bgneal@312: dom.remove(dom.getParent(id, 'tr')); bgneal@312: }, bgneal@312: bgneal@312: fillTargetList : function(id) { bgneal@312: var dom = tinyMCEPopup.dom, lst = dom.get(id), v; bgneal@312: bgneal@312: lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), ''); bgneal@312: lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_same'), '_self'); bgneal@312: lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_blank'), '_blank'); bgneal@312: bgneal@312: if (v = tinyMCEPopup.getParam('theme_advanced_link_targets')) { bgneal@312: tinymce.each(v.split(','), function(v) { bgneal@312: v = v.split('='); bgneal@312: lst.options[lst.options.length] = new Option(v[0], v[1]); bgneal@312: }); bgneal@312: } bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: LinkDialog.preInit(); bgneal@312: tinyMCEPopup.onInit.add(LinkDialog.init, LinkDialog);