includes/clientside/tinymce/themes/advanced/js/link.js
changeset 543 dffcbfbc4e59
parent 395 fa4c5ecb7c9a
child 1193 e3b94bd055dc
equal deleted inserted replaced
542:5841df0ab575 543:dffcbfbc4e59
    31 	},
    31 	},
    32 
    32 
    33 	update : function() {
    33 	update : function() {
    34 		var f = document.forms[0], ed = tinyMCEPopup.editor, e, b;
    34 		var f = document.forms[0], ed = tinyMCEPopup.editor, e, b;
    35 
    35 
       
    36 		tinyMCEPopup.restoreSelection();
       
    37 		e = ed.dom.getParent(ed.selection.getNode(), 'A');
       
    38 
    36 		// Remove element if there is no href
    39 		// Remove element if there is no href
    37 		if (!f.href.value) {
    40 		if (!f.href.value) {
    38 			e = ed.dom.getParent(ed.selection.getNode(), 'A');
       
    39 			if (e) {
    41 			if (e) {
    40 				tinyMCEPopup.execCommand("mceBeginUndoLevel");
    42 				tinyMCEPopup.execCommand("mceBeginUndoLevel");
    41 				b = ed.selection.getBookmark();
    43 				b = ed.selection.getBookmark();
    42 				ed.dom.remove(e, 1);
    44 				ed.dom.remove(e, 1);
    43 				ed.selection.moveToBookmark(b);
    45 				ed.selection.moveToBookmark(b);
    45 				tinyMCEPopup.close();
    47 				tinyMCEPopup.close();
    46 				return;
    48 				return;
    47 			}
    49 			}
    48 		}
    50 		}
    49 
    51 
    50 		ed.execCommand('mceInsertLink', false, {
    52 		tinyMCEPopup.execCommand("mceBeginUndoLevel");
    51 			href : f.href.value,
       
    52 			title : f.linktitle.value,
       
    53 			target : f.target_list ? f.target_list.options[f.target_list.selectedIndex].value : null,
       
    54 			'class' : f.class_list ? f.class_list.options[f.class_list.selectedIndex].value : null
       
    55 		});
       
    56 
    53 
       
    54 		// Create new anchor elements
       
    55 		if (e == null) {
       
    56 			tinyMCEPopup.execCommand("CreateLink", false, "#mce_temp_url#", {skip_undo : 1});
       
    57 
       
    58 			tinymce.each(ed.dom.select("a"), function(n) {
       
    59 				if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') {
       
    60 					e = n;
       
    61 
       
    62 					ed.dom.setAttribs(e, {
       
    63 						href : f.href.value,
       
    64 						title : f.linktitle.value,
       
    65 						target : f.target_list ? f.target_list.options[f.target_list.selectedIndex].value : null,
       
    66 						'class' : f.class_list ? f.class_list.options[f.class_list.selectedIndex].value : null
       
    67 					});
       
    68 				}
       
    69 			});
       
    70 		} else {
       
    71 			ed.dom.setAttribs(e, {
       
    72 				href : f.href.value,
       
    73 				title : f.linktitle.value,
       
    74 				target : f.target_list ? f.target_list.options[f.target_list.selectedIndex].value : null,
       
    75 				'class' : f.class_list ? f.class_list.options[f.class_list.selectedIndex].value : null
       
    76 			});
       
    77 		}
       
    78 
       
    79 		// Don't move caret if selection was image
       
    80 		if (e.childNodes.length != 1 || e.firstChild.nodeName != 'IMG') {
       
    81 			ed.focus();
       
    82 			ed.selection.select(e);
       
    83 			ed.selection.collapse(0);
       
    84 			tinyMCEPopup.storeSelection();
       
    85 		}
       
    86 
       
    87 		tinyMCEPopup.execCommand("mceEndUndoLevel");
    57 		tinyMCEPopup.close();
    88 		tinyMCEPopup.close();
    58 	},
    89 	},
    59 
    90 
    60 	checkPrefix : function(n) {
    91 	checkPrefix : function(n) {
    61 		if (n.value && Validator.isEmail(n) && !/^\s*mailto:/i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_email')))
    92 		if (n.value && Validator.isEmail(n) && !/^\s*mailto:/i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_email')))
   112 		lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_blank'), '_blank');
   143 		lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_blank'), '_blank');
   113 
   144 
   114 		if (v = tinyMCEPopup.getParam('theme_advanced_link_targets')) {
   145 		if (v = tinyMCEPopup.getParam('theme_advanced_link_targets')) {
   115 			tinymce.each(v.split(','), function(v) {
   146 			tinymce.each(v.split(','), function(v) {
   116 				v = v.split('=');
   147 				v = v.split('=');
   117 				html += '<option value="' + v[1] + '">' + v[0] + '</option>';
   148 				lst.options[lst.options.length] = new Option(v[0], v[1]);
   118 			});
   149 			});
   119 		}
   150 		}
   120 	}
   151 	}
   121 };
   152 };
   122 
   153