includes/clientside/tinymce/themes/advanced/js/link.js
changeset 335 67bd3121a12e
child 395 fa4c5ecb7c9a
equal deleted inserted replaced
334:c72b545f1304 335:67bd3121a12e
       
     1 tinyMCEPopup.requireLangPack();
       
     2 
       
     3 var LinkDialog = {
       
     4 	preInit : function() {
       
     5 		var url;
       
     6 
       
     7 		if (url = tinyMCEPopup.getParam("external_link_list_url"))
       
     8 			document.write('<script language="javascript" type="text/javascript" src="' + tinyMCEPopup.editor.documentBaseURI.toAbsolute(url) + '"></script>');
       
     9 	},
       
    10 
       
    11 	init : function() {
       
    12 		var f = document.forms[0], ed = tinyMCEPopup.editor;
       
    13 
       
    14 		// Setup browse button
       
    15 		document.getElementById('hrefbrowsercontainer').innerHTML = getBrowserHTML('hrefbrowser', 'href', 'file', 'theme_advanced_link');
       
    16 		if (isVisible('hrefbrowser'))
       
    17 			document.getElementById('href').style.width = '180px';
       
    18 
       
    19 		this.fillClassList('class_list');
       
    20 		this.fillFileList('link_list', 'tinyMCELinkList');
       
    21 		this.fillTargetList('target_list');
       
    22 
       
    23 		if (e = ed.dom.getParent(ed.selection.getNode(), 'A')) {
       
    24 			f.href.value = ed.dom.getAttrib(e, 'href');
       
    25 			f.linktitle.value = ed.dom.getAttrib(e, 'title');
       
    26 			f.insert.value = ed.getLang('update');
       
    27 			selectByValue(f, 'link_list', f.href.value);
       
    28 			selectByValue(f, 'target_list', ed.dom.getAttrib(e, 'target'));
       
    29 			selectByValue(f, 'class_list', ed.dom.getAttrib(e, 'class'));
       
    30 		}
       
    31 	},
       
    32 
       
    33 	update : function() {
       
    34 		var f = document.forms[0], ed = tinyMCEPopup.editor, e;
       
    35 
       
    36 		ed.execCommand('mceInsertLink', false, {
       
    37 			href : f.href.value,
       
    38 			title : f.linktitle.value,
       
    39 			target : f.target_list ? f.target_list.options[f.target_list.selectedIndex].value : null,
       
    40 			'class' : f.class_list ? f.class_list.options[f.class_list.selectedIndex].value : null
       
    41 		});
       
    42 
       
    43 		tinyMCEPopup.close();
       
    44 	},
       
    45 
       
    46 	checkPrefix : function(n) {
       
    47 		if (Validator.isEmail(n) && !/^\s*mailto:/i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_email')))
       
    48 			n.value = 'mailto:' + n.value;
       
    49 
       
    50 		if (/^\s*www./i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_external')))
       
    51 			n.value = 'http://' + n.value;
       
    52 	},
       
    53 
       
    54 	fillFileList : function(id, l) {
       
    55 		var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
       
    56 
       
    57 		l = window[l];
       
    58 
       
    59 		if (l && l.length > 0) {
       
    60 			lst.options[lst.options.length] = new Option('', '');
       
    61 
       
    62 			tinymce.each(l, function(o) {
       
    63 				lst.options[lst.options.length] = new Option(o[0], o[1]);
       
    64 			});
       
    65 		} else
       
    66 			dom.remove(dom.getParent(id, 'tr'));
       
    67 	},
       
    68 
       
    69 	fillClassList : function(id) {
       
    70 		var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
       
    71 
       
    72 		if (v = tinyMCEPopup.getParam('theme_advanced_styles')) {
       
    73 			cl = [];
       
    74 
       
    75 			tinymce.each(v.split(';'), function(v) {
       
    76 				var p = v.split('=');
       
    77 
       
    78 				cl.push({'title' : p[0], 'class' : p[1]});
       
    79 			});
       
    80 		} else
       
    81 			cl = tinyMCEPopup.editor.dom.getClasses();
       
    82 
       
    83 		if (cl.length > 0) {
       
    84 			lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), '');
       
    85 
       
    86 			tinymce.each(cl, function(o) {
       
    87 				lst.options[lst.options.length] = new Option(o.title || o['class'], o['class']);
       
    88 			});
       
    89 		} else
       
    90 			dom.remove(dom.getParent(id, 'tr'));
       
    91 	},
       
    92 
       
    93 	fillTargetList : function(id) {
       
    94 		var dom = tinyMCEPopup.dom, lst = dom.get(id), v;
       
    95 
       
    96 		lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), '');
       
    97 		lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_same'), '_self');
       
    98 		lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_blank'), '_blank');
       
    99 
       
   100 		if (v = tinyMCEPopup.getParam('theme_advanced_link_targets')) {
       
   101 			tinymce.each(v.split(','), function(v) {
       
   102 				v = v.split('=');
       
   103 				html += '<option value="' + v[1] + '">' + v[0] + '</option>';
       
   104 			});
       
   105 		}
       
   106 	}
       
   107 };
       
   108 
       
   109 LinkDialog.preInit();
       
   110 tinyMCEPopup.onInit.add(LinkDialog.init, LinkDialog);