--- a/includes/clientside/tinymce/themes/advanced/js/link.js Mon May 05 20:06:37 2008 -0400
+++ b/includes/clientside/tinymce/themes/advanced/js/link.js Mon May 05 20:08:44 2008 -0400
@@ -33,9 +33,11 @@
update : function() {
var f = document.forms[0], ed = tinyMCEPopup.editor, e, b;
+ tinyMCEPopup.restoreSelection();
+ e = ed.dom.getParent(ed.selection.getNode(), 'A');
+
// Remove element if there is no href
if (!f.href.value) {
- e = ed.dom.getParent(ed.selection.getNode(), 'A');
if (e) {
tinyMCEPopup.execCommand("mceBeginUndoLevel");
b = ed.selection.getBookmark();
@@ -47,13 +49,42 @@
}
}
- ed.execCommand('mceInsertLink', false, {
- href : f.href.value,
- title : f.linktitle.value,
- target : f.target_list ? f.target_list.options[f.target_list.selectedIndex].value : null,
- 'class' : f.class_list ? f.class_list.options[f.class_list.selectedIndex].value : null
- });
+ tinyMCEPopup.execCommand("mceBeginUndoLevel");
+
+ // Create new anchor elements
+ if (e == null) {
+ tinyMCEPopup.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 : f.href.value,
+ title : f.linktitle.value,
+ target : f.target_list ? f.target_list.options[f.target_list.selectedIndex].value : null,
+ 'class' : f.class_list ? f.class_list.options[f.class_list.selectedIndex].value : null
+ });
+ }
+ });
+ } else {
+ ed.dom.setAttribs(e, {
+ href : f.href.value,
+ title : f.linktitle.value,
+ target : f.target_list ? f.target_list.options[f.target_list.selectedIndex].value : null,
+ 'class' : f.class_list ? f.class_list.options[f.class_list.selectedIndex].value : 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);
+ tinyMCEPopup.storeSelection();
+ }
+
+ tinyMCEPopup.execCommand("mceEndUndoLevel");
tinyMCEPopup.close();
},
@@ -114,7 +145,7 @@
if (v = tinyMCEPopup.getParam('theme_advanced_link_targets')) {
tinymce.each(v.split(','), function(v) {
v = v.split('=');
- html += '<option value="' + v[1] + '">' + v[0] + '</option>';
+ lst.options[lst.options.length] = new Option(v[0], v[1]);
});
}
}