includes/clientside/tinymce/themes/advanced/jscripts/anchor.js
changeset 1 fe660c52c48f
equal deleted inserted replaced
0:902822492a68 1:fe660c52c48f
       
     1 var action, element;
       
     2 
       
     3 function init() {
       
     4 	tinyMCEPopup.resizeToInnerSize();
       
     5 
       
     6 	var inst = tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id'));
       
     7 	var anchor = tinyMCE.getParentElement(inst.getFocusElement(), "a", "name");
       
     8 	var img = inst.getFocusElement();
       
     9 	action = 'insert';
       
    10 
       
    11 	if (anchor != null) {
       
    12 		element = anchor;
       
    13 		action = "update";
       
    14 	}
       
    15 
       
    16 	if (tinyMCE.getAttrib(img, "class") == "mceItemAnchor") {
       
    17 		element = img;
       
    18 		action = "update";
       
    19 	}
       
    20 
       
    21 	if (action == "update")
       
    22 		document.forms[0].anchorName.value = element.nodeName == "IMG" ? element.getAttribute("title") : element.getAttribute("name");
       
    23 
       
    24 	document.forms[0].insert.value = tinyMCE.getLang('lang_' + action, 'Insert', true);
       
    25 }
       
    26 
       
    27 function insertAnchor() {
       
    28 	var inst = tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id'));
       
    29 	var name = document.forms[0].anchorName.value, e;
       
    30 
       
    31 	tinyMCEPopup.execCommand("mceBeginUndoLevel");
       
    32 
       
    33 	if (action == "update") {
       
    34 		if (element.nodeName == "IMG")
       
    35 			element.setAttribute("title", name);
       
    36 		else
       
    37 			element.setAttribute("name", name);
       
    38 	} else {
       
    39 		var rng = inst.getRng();
       
    40 
       
    41 		if (rng.collapse)
       
    42 			rng.collapse(false);
       
    43 
       
    44 		name = name.replace(/&/g, '&');
       
    45 		name = name.replace(/\"/g, '"');
       
    46 		name = name.replace(/</g, '&lt;');
       
    47 		name = name.replace(/>/g, '&gt;');
       
    48 
       
    49 		// Fix for bug #1447335
       
    50 		if (tinyMCE.isGecko)
       
    51 			html = '<a id="mceNewAnchor" name="' + name + '"></a>';
       
    52 		else
       
    53 			html = '<a name="' + name + '"></a>';
       
    54 
       
    55 		tinyMCEPopup.execCommand("mceInsertContent", false, html);
       
    56 
       
    57 		// Fix for bug #1447335 force cursor after the anchor element
       
    58 		if (tinyMCE.isGecko) {
       
    59 			e = inst.getDoc().getElementById('mceNewAnchor');
       
    60 
       
    61 			if (e) {
       
    62 				inst.selection.selectNode(e, true, false, false);
       
    63 				e.removeAttribute('id');
       
    64 			}
       
    65 		}
       
    66 
       
    67 		tinyMCE.handleVisualAid(inst.getBody(), true, inst.visualAid, inst);
       
    68 	}
       
    69 
       
    70 	tinyMCEPopup.execCommand("mceEndUndoLevel");
       
    71 
       
    72 	tinyMCE.triggerNodeChange();
       
    73 	tinyMCEPopup.close();
       
    74 }