annotate WebContent/jscripts/tiny_mce/themes/advanced/js/link.js @ 8:11baadcdd2c8

start of new Annotator API implementation.
author casties
date Mon, 19 Mar 2012 14:50:28 +0100
parents 0be9d53a6967
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1 tinyMCEPopup.requireLangPack();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
2
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
3 var LinkDialog = {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
4 preInit : function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
5 var url;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
6
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
7 if (url = tinyMCEPopup.getParam("external_link_list_url"))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
8 document.write('<script language="javascript" type="text/javascript" src="' + tinyMCEPopup.editor.documentBaseURI.toAbsolute(url) + '"></script>');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
9 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
10
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
11 init : function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
12 var f = document.forms[0], ed = tinyMCEPopup.editor;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
13
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
14 // Setup browse button
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
15 document.getElementById('hrefbrowsercontainer').innerHTML = getBrowserHTML('hrefbrowser', 'href', 'file', 'theme_advanced_link');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
16 if (isVisible('hrefbrowser'))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
17 document.getElementById('href').style.width = '180px';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
18
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
19 this.fillClassList('class_list');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
20 this.fillFileList('link_list', 'tinyMCELinkList');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
21 this.fillTargetList('target_list');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
22
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
23 if (e = ed.dom.getParent(ed.selection.getNode(), 'A')) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
24 f.href.value = ed.dom.getAttrib(e, 'href');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
25 f.linktitle.value = ed.dom.getAttrib(e, 'title');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
26 f.insert.value = ed.getLang('update');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
27 selectByValue(f, 'link_list', f.href.value);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
28 selectByValue(f, 'target_list', ed.dom.getAttrib(e, 'target'));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
29 selectByValue(f, 'class_list', ed.dom.getAttrib(e, 'class'));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
30 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
31 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
32
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
33 update : function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
34 var f = document.forms[0], ed = tinyMCEPopup.editor, e, b, href = f.href.value.replace(/ /g, '%20');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
35
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
36 tinyMCEPopup.restoreSelection();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
37 e = ed.dom.getParent(ed.selection.getNode(), 'A');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
38
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
39 // Remove element if there is no href
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
40 if (!f.href.value) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
41 if (e) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
42 b = ed.selection.getBookmark();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
43 ed.dom.remove(e, 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
44 ed.selection.moveToBookmark(b);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
45 tinyMCEPopup.execCommand("mceEndUndoLevel");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
46 tinyMCEPopup.close();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
47 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
48 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
49 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
50
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
51 // Create new anchor elements
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
52 if (e == null) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
53 ed.getDoc().execCommand("unlink", false, null);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
54 tinyMCEPopup.execCommand("mceInsertLink", false, "#mce_temp_url#", {skip_undo : 1});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
55
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
56 tinymce.each(ed.dom.select("a"), function(n) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
57 if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
58 e = n;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
59
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
60 ed.dom.setAttribs(e, {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
61 href : href,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
62 title : f.linktitle.value,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
63 target : f.target_list ? getSelectValue(f, "target_list") : null,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
64 'class' : f.class_list ? getSelectValue(f, "class_list") : null
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
65 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
66 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
67 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
68 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
69 ed.dom.setAttribs(e, {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
70 href : href,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
71 title : f.linktitle.value,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
72 target : f.target_list ? getSelectValue(f, "target_list") : null,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
73 'class' : f.class_list ? getSelectValue(f, "class_list") : null
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
74 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
75 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
76
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
77 // Don't move caret if selection was image
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
78 if (e.childNodes.length != 1 || e.firstChild.nodeName != 'IMG') {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
79 ed.focus();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
80 ed.selection.select(e);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
81 ed.selection.collapse(0);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
82 tinyMCEPopup.storeSelection();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
83 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
84
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
85 tinyMCEPopup.execCommand("mceEndUndoLevel");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
86 tinyMCEPopup.close();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
87 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
88
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
89 checkPrefix : function(n) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
90 if (n.value && Validator.isEmail(n) && !/^\s*mailto:/i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_email')))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
91 n.value = 'mailto:' + n.value;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
92
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
93 if (/^\s*www\./i.test(n.value) && confirm(tinyMCEPopup.getLang('advanced_dlg.link_is_external')))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
94 n.value = 'http://' + n.value;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
95 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
96
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
97 fillFileList : function(id, l) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
98 var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
99
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
100 l = window[l];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
101
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
102 if (l && l.length > 0) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
103 lst.options[lst.options.length] = new Option('', '');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
104
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
105 tinymce.each(l, function(o) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
106 lst.options[lst.options.length] = new Option(o[0], o[1]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
107 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
108 } else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
109 dom.remove(dom.getParent(id, 'tr'));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
110 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
111
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
112 fillClassList : function(id) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
113 var dom = tinyMCEPopup.dom, lst = dom.get(id), v, cl;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
114
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
115 if (v = tinyMCEPopup.getParam('theme_advanced_styles')) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
116 cl = [];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
117
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
118 tinymce.each(v.split(';'), function(v) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
119 var p = v.split('=');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
120
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
121 cl.push({'title' : p[0], 'class' : p[1]});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
122 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
123 } else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
124 cl = tinyMCEPopup.editor.dom.getClasses();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
125
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
126 if (cl.length > 0) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
127 lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), '');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
128
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
129 tinymce.each(cl, function(o) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
130 lst.options[lst.options.length] = new Option(o.title || o['class'], o['class']);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
131 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
132 } else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
133 dom.remove(dom.getParent(id, 'tr'));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
134 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
135
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
136 fillTargetList : function(id) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
137 var dom = tinyMCEPopup.dom, lst = dom.get(id), v;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
138
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
139 lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('not_set'), '');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
140 lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_same'), '_self');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
141 lst.options[lst.options.length] = new Option(tinyMCEPopup.getLang('advanced_dlg.link_target_blank'), '_blank');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
142
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
143 if (v = tinyMCEPopup.getParam('theme_advanced_link_targets')) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
144 tinymce.each(v.split(','), function(v) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
145 v = v.split('=');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
146 lst.options[lst.options.length] = new Option(v[0], v[1]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
147 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
148 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
149 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
150 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
151
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
152 LinkDialog.preInit();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
153 tinyMCEPopup.onInit.add(LinkDialog.init, LinkDialog);