includes/clientside/tinymce/plugins/advlink/js/advlink.js
changeset 543 dffcbfbc4e59
parent 476 f26a69c40431
child 778 57ce13805b6f
--- a/includes/clientside/tinymce/plugins/advlink/js/advlink.js	Mon May 05 20:06:37 2008 -0400
+++ b/includes/clientside/tinymce/plugins/advlink/js/advlink.js	Mon May 05 20:08:44 2008 -0400
@@ -14,8 +14,9 @@
 }
 
 function changeClass() {
-	var formObj = document.forms[0];
-	formObj.classes.value = getSelectValue(formObj, 'classlist');
+	var f = document.forms[0];
+
+	f.classes.value = getSelectValue(f, 'classlist');
 }
 
 function init() {
@@ -109,8 +110,6 @@
 		selectByValue(formObj, 'targetlist', inst.dom.getAttrib(elm, 'target'), true);
 	} else
 		addClassesToList('classlist', 'advlink_styles');
-
-	window.focus();
 }
 
 function checkPrefix(n) {
@@ -236,7 +235,7 @@
 		regExp += "\\);?";
 
 		// Build variable array
-		var variables = new Array();
+		var variables = [];
 		variables["_function"] = fnName;
 		var variableValues = link.replace(new RegExp(regExp, "gi"), replaceStr).split('<delim>');
 		for (var i=0; i<variableNames.length; i++)
@@ -250,7 +249,7 @@
 
 function parseOptions(opts) {
 	if (opts == null || opts == "")
-		return new Array();
+		return [];
 
 	// Cleanup the options
 	opts = opts.toLowerCase();
@@ -258,7 +257,7 @@
 	opts = opts.replace(/[^0-9a-z=,]/g, "");
 
 	var optionChunks = opts.split(',');
-	var options = new Array();
+	var options = [];
 
 	for (var i=0; i<optionChunks.length; i++) {
 		var parts = optionChunks[i].split('=');
@@ -406,44 +405,19 @@
 		tinyMCEPopup.execCommand("CreateLink", false, "#mce_temp_url#", {skip_undo : 1});
 
 		elementArray = tinymce.grep(inst.dom.select("a"), function(n) {return inst.dom.getAttrib(n, 'href') == '#mce_temp_url#';});
-		for (i=0; i<elementArray.length; i++) {
-			elm = elementArray[i];
-
-			// Move cursor to end
-			try {
-				tinyMCEPopup.editor.selection.collapse(false);
-			} catch (ex) {
-				// Ignore
-			}
-
-			// Move cursor behind the new anchor
-			// Don't remember why this was needed so it's now removed
-			/*
-			if (tinyMCE.isGecko) {
-				var sp = inst.getDoc().createTextNode(" ");
-
-				if (elm.nextSibling)
-					elm.parentNode.insertBefore(sp, elm.nextSibling);
-				else
-					elm.parentNode.appendChild(sp);
-
-				// Set range after link
-				var rng = inst.getDoc().createRange();
-				rng.setStartAfter(elm);
-				rng.setEndAfter(elm);
-
-				// Update selection
-				var sel = inst.getSel();
-				sel.removeAllRanges();
-				sel.addRange(rng);
-			}
-			*/
-
-			setAllAttribs(elm);
-		}
+		for (i=0; i<elementArray.length; i++)
+			setAllAttribs(elm = elementArray[i]);
 	} else
 		setAllAttribs(elm);
 
+	// Don't move caret if selection was image
+	if (elm.childNodes.length != 1 || elm.firstChild.nodeName != 'IMG') {
+		inst.focus();
+		inst.selection.select(elm);
+		inst.selection.collapse(0);
+		tinyMCEPopup.storeSelection();
+	}
+
 	tinyMCEPopup.execCommand("mceEndUndoLevel");
 	tinyMCEPopup.close();
 }