tinyMCEPopup.requireLangPack(); var LinkDialog = { init : function(ed) { var action, elm, f = document.forms[0]; this.editor = ed; elm = ed.dom.getParent(ed.selection.getNode(), 'A'); v = ed.dom.getAttrib(elm, 'href'); if (v) { this.action = 'update'; f.linkUrl.value = v; } f.insert.value = ed.getLang(elm ? 'update' : 'insert'); }, update : function() { var ed = this.editor; var e = ed.dom.getParent(ed.selection.getNode(), 'A'); var href = document.forms[0].linkUrl.value; tinyMCEPopup.restoreSelection(); ed.execCommand("mceBeginUndoLevel"); if (!href) { // Remove link element if (e) { var b = ed.selection.getBookmark(); ed.dom.remove(e, 1); ed.selection.moveToBookmark(b); } } else { // Create new link element if (e == null) { ed.getDoc().execCommand("unlink", false, null); ed.execCommand("CreateLink", false, "#mce_temp_url#", {skip_undo : 1}); tinymce.each(ed.dom.select("a"), function(n) { if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') { e = n; ed.dom.setAttribs(e, { href : href, title : "", target : null, 'class' : null }); } }); } else { ed.dom.setAttribs(e, { href : href, title : "", target : null, 'class' : null }); } // Don't move caret if selection was image if (e.childNodes.length != 1 || e.firstChild.nodeName != 'IMG') { ed.focus(); ed.selection.select(e); ed.selection.collapse(0); } } ed.execCommand("mceEndUndoLevel"); tinyMCEPopup.close(); } }; tinyMCEPopup.onInit.add(LinkDialog.init, LinkDialog);