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