1 | // Override the default dialog action |
---|
2 | // Original at line 1153 |
---|
3 | |
---|
4 | // modified from http://trac.wymeditor.org/trac/ticket/63 |
---|
5 | |
---|
6 | // Called in postInit() |
---|
7 | /* |
---|
8 | postInit: function(wym) { |
---|
9 | wym.modal_dialog(wym); |
---|
10 | }, |
---|
11 | |
---|
12 | */ |
---|
13 | |
---|
14 | (function($) { |
---|
15 | |
---|
16 | var $wym_dialog = $([]); |
---|
17 | var modal_dialog; |
---|
18 | var savedSelection; |
---|
19 | |
---|
20 | WYMeditor.editor.prototype.dialog = function( dialogType, dialogFeatures, bodyHtml ) |
---|
21 | { |
---|
22 | var features = dialogFeatures || this._wym._options.dialogFeatures; |
---|
23 | var sBodyHtml = ""; |
---|
24 | |
---|
25 | this._options.dialogLinkHtml = wym_dialogLinkHtml; |
---|
26 | this._options.dialogImageHtml = wym_dialogImageHtml; |
---|
27 | this._options.dialogTableHtml = wym_dialogTableHtml; |
---|
28 | this._options.dialogPasteHtml = wym_dialogPasteHtml; |
---|
29 | |
---|
30 | this._options.dialogHtml = WYMeditor.DIALOG_BODY; |
---|
31 | |
---|
32 | switch( dialogType ) |
---|
33 | { |
---|
34 | case(WYMeditor.DIALOG_LINK): |
---|
35 | sBodyHtml = this._options.dialogLinkHtml; |
---|
36 | break; |
---|
37 | case(WYMeditor.DIALOG_IMAGE): |
---|
38 | sBodyHtml = this._options.dialogImageHtml; |
---|
39 | break; |
---|
40 | case(WYMeditor.DIALOG_TABLE): |
---|
41 | sBodyHtml = this._options.dialogTableHtml; |
---|
42 | break; |
---|
43 | case(WYMeditor.DIALOG_PASTE): |
---|
44 | sBodyHtml = this._options.dialogPasteHtml; |
---|
45 | break; |
---|
46 | case(WYMeditor.PREVIEW): |
---|
47 | sBodyHtml = this._options.dialogPreviewHtml; |
---|
48 | break; |
---|
49 | default: |
---|
50 | sBodyHtml = bodyHtml; |
---|
51 | break; |
---|
52 | } |
---|
53 | |
---|
54 | var h = WYMeditor.Helper; |
---|
55 | |
---|
56 | //construct the dialog |
---|
57 | var dialogHtml = this._options.dialogHtml; |
---|
58 | dialogHtml = h.replaceAll(dialogHtml, WYMeditor.BASE_PATH, this._options.basePath); |
---|
59 | dialogHtml = h.replaceAll(dialogHtml, WYMeditor.DIRECTION, this._options.direction); |
---|
60 | dialogHtml = h.replaceAll(dialogHtml, WYMeditor.DIALOG_TITLE, this.encloseString( dialogType )); |
---|
61 | dialogHtml = h.replaceAll(dialogHtml, WYMeditor.DIALOG_BODY, sBodyHtml); |
---|
62 | dialogHtml = h.replaceAll(dialogHtml, WYMeditor.INDEX, this._index); |
---|
63 | |
---|
64 | dialogHtml = this.replaceStrings(dialogHtml); |
---|
65 | dialogTitle = dialogType.replace("_", " "); |
---|
66 | |
---|
67 | $wym_dialog = $.create_modal_dialog(dialogTitle, dialogHtml); |
---|
68 | modal_dialog = $wym_dialog.data('modal_dialog'); |
---|
69 | modal_dialog.open(); |
---|
70 | |
---|
71 | WYMeditor.INIT_DIALOG(this._index); |
---|
72 | }; |
---|
73 | |
---|
74 | WYMeditor.editor.prototype.modal_dialog = function(wym) |
---|
75 | { |
---|
76 | $('.wym_tools a').click(function(){ |
---|
77 | //savedSelection = rangy.saveRestore.saveSelection(); |
---|
78 | }); |
---|
79 | }; |
---|
80 | |
---|
81 | /* |
---|
82 | Plugin for all dialogs to use to close the window. |
---|
83 | |
---|
84 | Set a really short time out, it seems to need this otherwise it won't close |
---|
85 | after updating the HTML in the editor window. |
---|
86 | */ |
---|
87 | jQuery.fn.closeDialog = function(){ |
---|
88 | |
---|
89 | //rangy.saveRestore.restoreSelection(savedSelection); |
---|
90 | |
---|
91 | setTimeout({ |
---|
92 | run: function() { |
---|
93 | modal_dialog.close(); |
---|
94 | } |
---|
95 | }.run, 250); |
---|
96 | }; |
---|
97 | |
---|
98 | WYMeditor.INIT_DIALOG = function(index) |
---|
99 | { |
---|
100 | var wym = WYMeditor.INSTANCES[index]; |
---|
101 | var doc = window.document; |
---|
102 | var selected = wym.selected(); |
---|
103 | var dialogType = jQuery(wym._options.dialogTypeSelector).val(); |
---|
104 | var sStamp = wym.uniqueStamp(); |
---|
105 | |
---|
106 | switch(dialogType) |
---|
107 | { |
---|
108 | case WYMeditor.DIALOG_LINK: |
---|
109 | //ensure that we select the link to populate the fields |
---|
110 | if(selected && selected.tagName && selected.tagName.toLowerCase != WYMeditor.A) |
---|
111 | selected = jQuery(selected).parentsOrSelf(WYMeditor.A); |
---|
112 | |
---|
113 | //fix MSIE selection if link image has been clicked |
---|
114 | if(!selected && wym._selected_image) |
---|
115 | selected = jQuery(wym._selected_image).parentsOrSelf(WYMeditor.A); |
---|
116 | break; |
---|
117 | default: |
---|
118 | break; |
---|
119 | } |
---|
120 | |
---|
121 | //pre-init functions |
---|
122 | if(jQuery.isFunction(wym._options.preInitDialog)) |
---|
123 | { |
---|
124 | wym._options.preInitDialog(wym,window); |
---|
125 | } |
---|
126 | |
---|
127 | //add css rules from options |
---|
128 | var styles = doc.styleSheets[0]; |
---|
129 | var aCss = eval(wym._options.dialogStyles); |
---|
130 | |
---|
131 | wym.addCssRules(doc, aCss); |
---|
132 | |
---|
133 | //auto populate fields if selected container (e.g. A) |
---|
134 | if(selected) |
---|
135 | { |
---|
136 | jQuery('.wym_css_class', doc).val(jQuery(selected).attr('class')); |
---|
137 | jQuery('.wym_rel', doc).val(jQuery(selected).attr('rel')); |
---|
138 | |
---|
139 | jQuery(wym._options.hrefSelector).val(jQuery(selected).attr(WYMeditor.HREF)); |
---|
140 | jQuery(wym._options.srcSelector).val(jQuery(selected).attr(WYMeditor.SRC)); |
---|
141 | jQuery(wym._options.titleSelector).val(jQuery(selected).attr(WYMeditor.TITLE)); |
---|
142 | jQuery(wym._options.altSelector).val(jQuery(selected).attr(WYMeditor.ALT)); |
---|
143 | } |
---|
144 | |
---|
145 | // Bind the same action to all Cancel buttons |
---|
146 | jQuery(wym._options.cancelSelector, doc).click(function(){ |
---|
147 | jQuery().closeDialog(); |
---|
148 | }); |
---|
149 | |
---|
150 | // Handle Links |
---|
151 | jQuery(wym._options.dialogLinkSelector +" "+ wym._options.submitSelector).submit(function(e){ |
---|
152 | e.preventDefault(); |
---|
153 | |
---|
154 | var sUrl = jQuery(wym._options.hrefSelector, doc).val(); |
---|
155 | |
---|
156 | if(sUrl.length > 0) |
---|
157 | { |
---|
158 | var link; |
---|
159 | |
---|
160 | if (selected[0] && selected[0].tagName.toLowerCase() == WYMeditor.A) { |
---|
161 | link = selected; |
---|
162 | } else { |
---|
163 | wym._exec(WYMeditor.CREATE_LINK, sStamp); |
---|
164 | link = jQuery("a[href=" + sStamp + "]", wym._doc.body); |
---|
165 | } |
---|
166 | |
---|
167 | link.attr(WYMeditor.HREF, sUrl).attr(WYMeditor.TITLE, jQuery(wym._options.titleSelector).val()).attr('class', jQuery('.wym_css_class').val()).attr('rel', jQuery('.wym_rel').val()); |
---|
168 | } |
---|
169 | |
---|
170 | jQuery().closeDialog(); |
---|
171 | }); |
---|
172 | |
---|
173 | //auto populate image fields if selected image |
---|
174 | if(wym._selected_image) |
---|
175 | { |
---|
176 | jQuery(wym._options.dialogImageSelector + " " + wym._options.srcSelector).val(jQuery(wym._selected_image).attr(WYMeditor.SRC)); |
---|
177 | |
---|
178 | jQuery(wym._options.dialogImageSelector + " " + wym._options.titleSelector).val(jQuery(wym._selected_image).attr(WYMeditor.TITLE)); |
---|
179 | |
---|
180 | jQuery(wym._options.dialogImageSelector + " " + wym._options.altSelector).val(jQuery(wym._selected_image).attr(WYMeditor.ALT)); |
---|
181 | } |
---|
182 | |
---|
183 | |
---|
184 | jQuery(wym._options.dialogImageSelector +" "+ wym._options.submitSelector).submit(function() { |
---|
185 | |
---|
186 | var sUrl = jQuery(wym._options.srcSelector).val(); |
---|
187 | |
---|
188 | if(sUrl.length > 0) |
---|
189 | { |
---|
190 | wym._exec(WYMeditor.INSERT_IMAGE, sStamp); |
---|
191 | |
---|
192 | jQuery("img[src$=" + sStamp + "]", wym._doc.body).attr(WYMeditor.SRC, sUrl).attr(WYMeditor.TITLE, jQuery(wym._options.titleSelector).val()).attr(WYMeditor.ALT, jQuery(wym._options.altSelector).val()); |
---|
193 | } |
---|
194 | |
---|
195 | jQuery().closeDialog(); |
---|
196 | }); |
---|
197 | |
---|
198 | jQuery(wym._options.dialogTableSelector +" "+ wym._options.submitSelector).submit(function() { |
---|
199 | |
---|
200 | var iRows = jQuery(wym._options.rowsSelector).val(); |
---|
201 | var iCols = jQuery(wym._options.colsSelector).val(); |
---|
202 | |
---|
203 | if(iRows > 0 && iCols > 0) |
---|
204 | { |
---|
205 | var table = wym._doc.createElement(WYMeditor.TABLE); |
---|
206 | var newRow = null; |
---|
207 | var newCol = null; |
---|
208 | |
---|
209 | var sCaption = jQuery(wym._options.captionSelector).val(); |
---|
210 | |
---|
211 | //we create the caption |
---|
212 | var newCaption = table.createCaption(); |
---|
213 | newCaption.innerHTML = sCaption; |
---|
214 | |
---|
215 | //we create the rows and cells |
---|
216 | for(x=0; x<iRows; x++) { |
---|
217 | newRow = table.insertRow(x); |
---|
218 | for(y=0; y<iCols; y++) {newRow.insertCell(y);} |
---|
219 | } |
---|
220 | |
---|
221 | //set the summary attr |
---|
222 | jQuery(table).attr('summary', jQuery(wym._options.summarySelector).val()); |
---|
223 | |
---|
224 | //append the table after the selected container |
---|
225 | var node = jQuery(wym.findUp(wym.container(), WYMeditor.MAIN_CONTAINERS)).get(0); |
---|
226 | if(!node || !node.parentNode) |
---|
227 | { |
---|
228 | jQuery(wym._doc.body).append(table); |
---|
229 | } |
---|
230 | else |
---|
231 | { |
---|
232 | jQuery(node).after(table); |
---|
233 | } |
---|
234 | } |
---|
235 | |
---|
236 | jQuery().closeDialog(); |
---|
237 | }); |
---|
238 | |
---|
239 | jQuery(wym._options.dialogPasteSelector +" "+ wym._options.submitSelector).submit(function() { |
---|
240 | |
---|
241 | var sText = jQuery(wym._options.textSelector).val(); |
---|
242 | wym.paste(sText); |
---|
243 | |
---|
244 | jQuery().closeDialog(); |
---|
245 | }); |
---|
246 | |
---|
247 | /* Removed this option, it's useless |
---|
248 | jQuery(wym._options.dialogPreviewSelector +" "+ wym._options.previewSelector).click(function(){ |
---|
249 | wym_dialog.html(wym.xhtml()); |
---|
250 | }); |
---|
251 | */ |
---|
252 | |
---|
253 | //pre-init functions |
---|
254 | if(jQuery.isFunction(wym._options.postInitDialog)) |
---|
255 | wym._options.postInitDialog(wym,window); |
---|
256 | |
---|
257 | }; |
---|
258 | |
---|
259 | |
---|
260 | |
---|
261 | |
---|
262 | // Custom Dialogs |
---|
263 | |
---|
264 | var wym_dialogLinkHtml = "<div class='wym_dialog wym_dialog_link'><form>" |
---|
265 | + "<fieldset>" |
---|
266 | + "<input type='hidden' class='wym_dialog_type' value='"+ WYMeditor.DIALOG_LINK + "' />" |
---|
267 | |
---|
268 | + "<div class='row'>" |
---|
269 | + "<label>{URL}</label>" |
---|
270 | + "<input type='text' class='wym_href' value='' size='40' />" |
---|
271 | + "</div>" |
---|
272 | |
---|
273 | + "<div class='row'>" |
---|
274 | + "<label>{Title}</label>" |
---|
275 | + "<input type='text' class='wym_title' value='' size='40' />" |
---|
276 | + "</div>" |
---|
277 | |
---|
278 | + "<div class='row'>" |
---|
279 | + "<label>CSS Class</label>" |
---|
280 | + "<input type='text' class='wym_css_class' value='' size='40' />" |
---|
281 | + "</div>" |
---|
282 | |
---|
283 | + "<div class='row'>" |
---|
284 | + "<label>Target</label>" |
---|
285 | + "<select class='wym_rel'>" |
---|
286 | + "<option value=''>Same Window</option>" |
---|
287 | + "<option value='_blank'>New Window</option>" |
---|
288 | + "</select>" |
---|
289 | + "</div>" |
---|
290 | |
---|
291 | + "<div class='row row-indent'>" |
---|
292 | + "<input class='wym_submit' type='submit' value='{Submit}' />" |
---|
293 | + "<input class='wym_cancel' type='button' value='{Cancel}' />" |
---|
294 | + "</div>" |
---|
295 | |
---|
296 | + "</fieldset>" |
---|
297 | + "</form>" |
---|
298 | + "<fieldset class='page_listing' style='display: none;'><legend>Pages</legend><div class='container'>{PAGES_HTML}</div></fieldset>" |
---|
299 | + "</div>"; |
---|
300 | |
---|
301 | var wym_dialogImageHtml = "<div class='wym_dialog wym_dialog_image'><form>" |
---|
302 | + "<fieldset>" |
---|
303 | + "<input type='hidden' class='wym_dialog_type' value='"+ WYMeditor.DIALOG_IMAGE +"' />" |
---|
304 | |
---|
305 | + "<div class='row'>" |
---|
306 | + "<label>{URL}</label>" |
---|
307 | + "<input type='text' class='wym_src' value='' size='40' />" |
---|
308 | + "</div>" |
---|
309 | |
---|
310 | + "<div class='row'>" |
---|
311 | + "<label>{Alternative_Text}</label>" |
---|
312 | + "<input type='text' class='wym_alt' value='' size='40' />" |
---|
313 | + "</div>" |
---|
314 | |
---|
315 | + "<div class='row'>" |
---|
316 | + "<label>{Title}</label>" |
---|
317 | + "<input type='text' class='wym_title' value='' size='40' />" |
---|
318 | + "</div>" |
---|
319 | |
---|
320 | + "<div class='row row-indent'>" |
---|
321 | + "<input class='wym_submit' type='submit' value='{Submit}' />" |
---|
322 | + "<input class='wym_cancel' type='button' value='{Cancel}' />" |
---|
323 | + "</div>" |
---|
324 | |
---|
325 | + "</fieldset>" |
---|
326 | + "</form>"; |
---|
327 | |
---|
328 | var wym_dialogTableHtml = "<div class='wym_dialog wym_dialog_table'><form>" |
---|
329 | + "<fieldset>" |
---|
330 | + "<input type='hidden' class='wym_dialog_type' value='"+ WYMeditor.DIALOG_TABLE +"' />" |
---|
331 | |
---|
332 | + "<div class='row'>" |
---|
333 | + "<label>{Caption}</label>" |
---|
334 | + "<input type='text' class='wym_caption' value='' size='40' />" |
---|
335 | + "</div>" |
---|
336 | |
---|
337 | + "<div class='row'>" |
---|
338 | + "<label>{Summary}</label>" |
---|
339 | + "<input type='text' class='wym_summary' value='' size='40' />" |
---|
340 | + "</div>" |
---|
341 | |
---|
342 | + "<div class='row'>" |
---|
343 | + "<label>{Number_Of_Rows}</label>" |
---|
344 | + "<input type='text' class='wym_rows' value='3' size='3' />" |
---|
345 | + "</div>" |
---|
346 | |
---|
347 | + "<div class='row'>" |
---|
348 | + "<label>{Number_Of_Cols}</label>" |
---|
349 | + "<input type='text' class='wym_cols' value='2' size='3' />" |
---|
350 | + "</div>" |
---|
351 | |
---|
352 | + "<div class='row row-indent'>" |
---|
353 | + "<input class='wym_submit' type='submit' value='{Submit}' />" |
---|
354 | + "<input class='wym_cancel' type='button' value='{Cancel}' />" |
---|
355 | + "</div>" |
---|
356 | |
---|
357 | + "</fieldset>" |
---|
358 | + "</form>"; |
---|
359 | |
---|
360 | var wym_dialogPasteHtml = "<div class='wym_dialog wym_dialog_paste'><form>" |
---|
361 | + "<fieldset>" |
---|
362 | + "<input type='hidden' class='wym_dialog_type' value='"+ WYMeditor.DIALOG_PASTE +"' />" |
---|
363 | |
---|
364 | + "<div class='row'>" |
---|
365 | + "<textarea class='wym_text' rows='10' cols='50'></textarea>" |
---|
366 | + "</div>" |
---|
367 | |
---|
368 | + "<div class='row row-indent'>" |
---|
369 | + "<input class='wym_submit' type='submit' value='{Submit}' />" |
---|
370 | + "<input class='wym_cancel' type='button' value='{Cancel}' />" |
---|
371 | + "</div>" |
---|
372 | |
---|
373 | + "</fieldset>" |
---|
374 | + "</form>"; |
---|
375 | |
---|
376 | var wym_dialogPreviewHtml = "<div class='wym_dialog wym_dialog_preview'><div>"; |
---|
377 | |
---|
378 | })(jQuery); |
---|