9 var css_url = scriptPath + '/includes/clientside/css/enano_shared.css'; |
9 var css_url = scriptPath + '/includes/clientside/css/enano_shared.css'; |
10 } |
10 } |
11 |
11 |
12 var do_popups = ( is_Safari ) ? '' : ',inlinepopups'; |
12 var do_popups = ( is_Safari ) ? '' : ',inlinepopups'; |
13 var _skin = ( typeof(tinymce_skin) == 'string' ) ? tinymce_skin : 'default'; |
13 var _skin = ( typeof(tinymce_skin) == 'string' ) ? tinymce_skin : 'default'; |
|
14 var editor_img_path = scriptPath + '/images/editor'; |
|
15 |
|
16 // Idle time required for autosave, in seconds |
|
17 var AUTOSAVE_TIMEOUT = 15; |
|
18 var AutosaveTimeoutObj = null; |
14 |
19 |
15 var enano_tinymce_options = { |
20 var enano_tinymce_options = { |
16 mode : "none", |
21 mode : "none", |
17 plugins : 'table,save,safari,pagebreak,style,layer,advhr,insertdatetime,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras' + do_popups, |
22 plugins : 'table,save,safari,pagebreak,style,layer,advhr,insertdatetime,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras' + do_popups, |
18 theme : 'advanced', |
23 theme : 'advanced', |
82 } |
87 } |
83 |
88 |
84 // do we need to enter a captcha before saving the page? |
89 // do we need to enter a captcha before saving the page? |
85 var captcha_hash = ( response.require_captcha ) ? response.captcha_id : false; |
90 var captcha_hash = ( response.require_captcha ) ? response.captcha_id : false; |
86 |
91 |
87 ajaxBuildEditor(response.src, (!response.auth_edit), response.time, response.allow_wysiwyg, captcha_hash, response.revid, response.undo_info); |
92 ajaxBuildEditor((!response.auth_edit), response.time, response.allow_wysiwyg, captcha_hash, response.revid, response.undo_info, response); |
88 } |
93 } |
89 }); |
94 }); |
90 } |
95 } |
91 |
96 |
92 function ajaxBuildEditor(content, readonly, timestamp, allow_wysiwyg, captcha_hash, revid, undo_info) |
97 function ajaxBuildEditor(readonly, timestamp, allow_wysiwyg, captcha_hash, revid, undo_info, response) |
93 { |
98 { |
94 // Set flags |
99 // Set flags |
95 // We don't want the fancy confirmation framework to trigger if the user is only viewing the page source |
100 // We don't want the fancy confirmation framework to trigger if the user is only viewing the page source |
96 if ( !readonly ) |
101 if ( !readonly ) |
97 { |
102 { |
98 editor_open = true; |
103 editor_open = true; |
99 disableUnload(); |
104 disableUnload(); |
100 } |
105 } |
101 |
106 |
102 // Destroy existing contents of page container |
107 // Destroy existing contents of page container |
103 var edcon = document.getElementById('ajaxEditContainer'); |
108 var edcon = document.getElementById('ajaxEditContainer'); |
104 for ( var i = edcon.childNodes.length - 1; i >= 0; i-- ) |
109 for ( var i = edcon.childNodes.length - 1; i >= 0; i-- ) |
105 { |
110 { |
106 edcon.removeChild(edcon.childNodes[i]); |
111 edcon.removeChild(edcon.childNodes[i]); |
107 } |
112 } |
|
113 |
|
114 var content = response.src; |
108 |
115 |
109 // |
116 // |
110 // BUILD EDITOR |
117 // BUILD EDITOR |
111 // |
118 // |
112 |
119 |
172 { |
179 { |
173 ajaxEditorSave(); |
180 ajaxEditorSave(); |
174 return false; |
181 return false; |
175 } |
182 } |
176 |
183 |
|
184 // Draft notice |
|
185 if ( response.have_draft ) |
|
186 { |
|
187 var dn = document.createElement('div'); |
|
188 dn.className = 'warning-box'; |
|
189 dn.id = 'ajax_edit_draft_notice'; |
|
190 dn.innerHTML = '<b>' + $lang.get('editor_msg_have_draft_title') + '</b><br />'; |
|
191 dn.innerHTML += $lang.get('editor_msg_have_draft_body', { author: response.draft_author, time: response.draft_time }); |
|
192 } |
|
193 |
177 // Old-revision notice |
194 // Old-revision notice |
178 if ( revid > 0 ) |
195 if ( revid > 0 ) |
179 { |
196 { |
180 var oldrev_box = document.createElement('div'); |
197 var oldrev_box = document.createElement('div'); |
181 oldrev_box.className = 'usermessage'; |
198 oldrev_box.className = 'usermessage'; |
182 oldrev_box.appendChild(document.createTextNode($lang.get('editor_msg_editing_old_revision'))); |
199 oldrev_box.appendChild(document.createTextNode($lang.get('editor_msg_editing_old_revision'))); |
183 form.appendChild(oldrev_box); |
|
184 } |
200 } |
185 |
201 |
186 // Preview holder |
202 // Preview holder |
187 var preview_anchor = document.createElement('a'); |
203 var preview_anchor = document.createElement('a'); |
188 preview_anchor.name = 'ajax_preview'; |
204 preview_anchor.name = 'ajax_preview'; |
194 // Textarea containing the content |
210 // Textarea containing the content |
195 var ta_wrapper = document.createElement('div'); |
211 var ta_wrapper = document.createElement('div'); |
196 ta_wrapper.style.margin = '10px 0'; |
212 ta_wrapper.style.margin = '10px 0'; |
197 // ta_wrapper.style.clear = 'both'; |
213 // ta_wrapper.style.clear = 'both'; |
198 var textarea = document.createElement('textarea'); |
214 var textarea = document.createElement('textarea'); |
199 textarea.value = content; |
215 ta_wrapper.appendChild(textarea); |
200 textarea._edTimestamp = timestamp; |
216 |
201 textarea.id = 'ajaxEditArea'; |
217 textarea.id = 'ajaxEditArea'; |
202 textarea.rows = '20'; |
218 textarea.rows = '20'; |
203 textarea.cols = '60'; |
219 textarea.cols = '60'; |
204 textarea.style.width = '98.7%'; |
220 textarea.style.width = '98.7%'; |
205 if ( readonly ) |
|
206 { |
|
207 textarea.className = 'mce_readonly'; |
|
208 textarea.setAttribute('readonly', 'readonly'); |
|
209 } |
|
210 ta_wrapper.appendChild(textarea); |
|
211 |
221 |
212 // Revision metadata controls |
222 // Revision metadata controls |
213 var tblholder = document.createElement('div'); |
223 var tblholder = document.createElement('div'); |
214 tblholder.className = 'tblholder'; |
224 tblholder.className = 'tblholder'; |
215 var metatable = document.createElement('table'); |
225 var metatable = document.createElement('table'); |
218 metatable.setAttribute('cellpadding', '4'); |
228 metatable.setAttribute('cellpadding', '4'); |
219 |
229 |
220 if ( readonly ) |
230 if ( readonly ) |
221 { |
231 { |
222 // Close Viewer button |
232 // Close Viewer button |
223 var tr3 = document.createElement('tr'); |
233 var toolbar = ''; |
224 var td3 = document.createElement('th'); |
234 var head = new templateParser(response.toolbar_templates.toolbar_start); |
225 td3.setAttribute('colspan', '2'); |
235 var button = new templateParser(response.toolbar_templates.toolbar_button); |
226 td3.className = 'subhead'; |
236 var tail = new templateParser(response.toolbar_templates.toolbar_end); |
227 |
237 |
228 var btn_cancel = document.createElement('input'); |
238 button.assign_bool({ |
229 btn_cancel.type = 'button'; |
239 show_title: true |
230 btn_cancel.value = $lang.get('editor_btn_closeviewer'); |
240 }); |
231 btn_cancel.onclick = function() { ajaxReset(true); return false; }; |
241 |
232 td3.appendChild(btn_cancel); |
242 // Button: close |
233 tr3.appendChild(td3); |
243 button.assign_vars({ |
234 |
244 TITLE: $lang.get('editor_btn_closeviewer'), |
235 metatable.appendChild(tr3); |
245 IMAGE: editor_img_path + '/discard.gif', |
|
246 FLAGS: 'href="#" onclick="ajaxReset(true); return false;"' |
|
247 }); |
|
248 toolbar += button.run(); |
236 } |
249 } |
237 else |
250 else |
238 { |
251 { |
239 // First row: edit summary |
252 // First row: edit summary |
240 var tr1 = document.createElement('tr'); |
253 var tr1 = document.createElement('tr'); |
330 tr4.appendChild(td4_1); |
343 tr4.appendChild(td4_1); |
331 tr4.appendChild(td4_2); |
344 tr4.appendChild(td4_2); |
332 } |
345 } |
333 |
346 |
334 // Third row: controls |
347 // Third row: controls |
335 var tr3 = document.createElement('tr'); |
348 |
336 var td3 = document.createElement('th'); |
349 var toolbar = ''; |
337 td3.setAttribute('colspan', '2'); |
350 var head = new templateParser(response.toolbar_templates.toolbar_start); |
338 td3.className = 'subhead'; |
351 var button = new templateParser(response.toolbar_templates.toolbar_button); |
339 |
352 var label = new templateParser(response.toolbar_templates.toolbar_label); |
340 var btn_save = document.createElement('input'); |
353 var tail = new templateParser(response.toolbar_templates.toolbar_end); |
341 btn_save.type = 'button'; |
354 |
342 btn_save.value = $lang.get('editor_btn_save'); |
355 button.assign_bool({ |
343 btn_save.onclick = function() { ajaxEditorSave(); return false; }; |
356 show_title: true |
344 td3.appendChild(btn_save); |
357 }); |
345 |
358 |
346 td3.appendChild(document.createTextNode(' ')); |
359 toolbar += head.run(); |
347 |
360 |
348 var btn_preview = document.createElement('input'); |
361 // Button: Save |
349 btn_preview.type = 'button'; |
362 button.assign_vars({ |
350 btn_preview.value = $lang.get('editor_btn_preview'); |
363 TITLE: $lang.get('editor_btn_save'), |
351 btn_preview.onclick = function() { ajaxEditorGenPreview(); return false; }; |
364 IMAGE: editor_img_path + '/save.gif', |
352 td3.appendChild(btn_preview); |
365 FLAGS: 'href="#" onclick="ajaxEditorSave(); return false;"' |
353 |
366 }); |
354 td3.appendChild(document.createTextNode(' ')); |
367 toolbar += button.run(); |
355 |
368 |
356 var btn_revert = document.createElement('input'); |
369 // Button: preview |
357 btn_revert.type = 'button'; |
370 button.assign_vars({ |
358 btn_revert.value = $lang.get('editor_btn_revert'); |
371 TITLE: $lang.get('editor_btn_preview'), |
359 btn_revert.onclick = function() { ajaxEditorRevertToLatest(); return false; }; |
372 IMAGE: editor_img_path + '/preview.gif', |
360 td3.appendChild(btn_revert); |
373 FLAGS: 'href="#" onclick="ajaxEditorGenPreview(); return false;"' |
361 |
374 }); |
362 td3.appendChild(document.createTextNode(' ')); |
375 toolbar += button.run(); |
363 |
376 |
364 var btn_diff = document.createElement('input'); |
377 // Button: revert |
365 btn_diff.type = 'button'; |
378 button.assign_vars({ |
366 btn_diff.value = $lang.get('editor_btn_diff'); |
379 TITLE: $lang.get('editor_btn_revert'), |
367 btn_diff.onclick = function() { ajaxEditorShowDiffs(); return false; }; |
380 IMAGE: editor_img_path + '/revert.gif', |
368 td3.appendChild(btn_diff); |
381 FLAGS: 'href="#" onclick="ajaxEditorRevertToLatest(); return false;"' |
369 |
382 }); |
370 td3.appendChild(document.createTextNode(' ')); |
383 toolbar += button.run(); |
371 |
384 |
372 var btn_cancel = document.createElement('input'); |
385 // Button: diff |
373 btn_cancel.type = 'button'; |
386 button.assign_vars({ |
374 btn_cancel.value = $lang.get('editor_btn_cancel'); |
387 TITLE: $lang.get('editor_btn_diff'), |
375 btn_cancel.onclick = function() { ajaxEditorCancel(); return false; }; |
388 IMAGE: editor_img_path + '/diff.gif', |
376 td3.appendChild(btn_cancel); |
389 FLAGS: 'href="#" onclick="ajaxEditorShowDiffs(); return false;"' |
377 tr3.appendChild(td3); |
390 }); |
|
391 toolbar += button.run(); |
|
392 |
|
393 // Button: cancel |
|
394 button.assign_vars({ |
|
395 TITLE: $lang.get('editor_btn_cancel'), |
|
396 IMAGE: editor_img_path + '/discard.gif', |
|
397 FLAGS: 'href="#" onclick="ajaxEditorCancel(); return false;"' |
|
398 }); |
|
399 toolbar += button.run(); |
|
400 |
|
401 // Separator |
|
402 label.assign_vars({ |
|
403 TITLE: ' ' |
|
404 }); |
|
405 toolbar += label.run(); |
|
406 |
|
407 // Button: Save draft |
|
408 button.assign_vars({ |
|
409 TITLE: $lang.get('editor_btn_savedraft'), |
|
410 IMAGE: editor_img_path + '/savedraft.gif', |
|
411 FLAGS: 'href="#" onclick="ajaxPerformAutosave(); return false;" id="ajax_edit_savedraft_btn"' |
|
412 }); |
|
413 toolbar += button.run(); |
|
414 |
|
415 toolbar += tail.run(); |
378 |
416 |
379 metatable.appendChild(tr1); |
417 metatable.appendChild(tr1); |
380 metatable.appendChild(tr2); |
418 metatable.appendChild(tr2); |
381 if ( captcha_hash ) |
419 if ( captcha_hash ) |
382 { |
420 { |
383 metatable.appendChild(tr4); |
421 metatable.appendChild(tr4); |
384 } |
422 } |
385 metatable.appendChild(tr3); |
423 // metatable.appendChild(tr3); |
386 } |
424 } |
387 tblholder.appendChild(metatable); |
425 tblholder.appendChild(metatable); |
388 |
426 |
389 // Edit disclaimer/notice |
427 // Edit disclaimer/notice |
390 if ( editNotice ) // This is set globally in {JS_DYNAMIC_VARS}. |
428 if ( editNotice ) // This is set globally in {JS_DYNAMIC_VARS}. |
397 |
435 |
398 // Put it all together... |
436 // Put it all together... |
399 form.appendChild(heading); |
437 form.appendChild(heading); |
400 if ( allow_wysiwyg ) |
438 if ( allow_wysiwyg ) |
401 form.appendChild(toggler); |
439 form.appendChild(toggler); |
|
440 |
|
441 if ( dn ) |
|
442 form.appendChild(dn); |
|
443 |
|
444 if ( oldrev_box ) |
|
445 form.appendChild(oldrev_box); |
|
446 |
402 form.appendChild(preview_anchor); |
447 form.appendChild(preview_anchor); |
403 form.appendChild(preview_container); |
448 form.appendChild(preview_container); |
404 form.appendChild(ta_wrapper); |
449 form.appendChild(ta_wrapper); |
405 form.appendChild(tblholder); |
450 form.appendChild(tblholder); |
|
451 form.innerHTML += '<div style="margin: 10px 0 0 0;">' + toolbar + '</div>'; |
406 edcon.appendChild(form); |
452 edcon.appendChild(form); |
407 |
453 |
408 if ( editNotice && !readonly ) |
454 if ( editNotice && !readonly ) |
409 { |
455 { |
410 edcon.appendChild(en_div); |
456 edcon.appendChild(en_div); |
|
457 } |
|
458 |
|
459 // more textarea attribs/init |
|
460 var textarea = document.getElementById('ajaxEditArea'); |
|
461 textarea.as_last_save = 0; |
|
462 textarea.content_orig = content; |
|
463 textarea.used_draft = false; |
|
464 textarea.onkeyup = function() |
|
465 { |
|
466 if ( this.needReset ) |
|
467 { |
|
468 var img = $('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0]; |
|
469 var lbl = $('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0]; |
|
470 img.src = editor_img_path + '/savedraft.gif'; |
|
471 lbl.innerHTML = $lang.get('editor_btn_savedraft'); |
|
472 } |
|
473 if ( AutosaveTimeoutObj ) |
|
474 clearTimeout(AutosaveTimeoutObj); |
|
475 AutosaveTimeoutObj = setTimeout('ajaxAutosaveDraft();', ( AUTOSAVE_TIMEOUT * 1000 )); |
|
476 } |
|
477 |
|
478 if ( readonly ) |
|
479 { |
|
480 textarea.className = 'mce_readonly'; |
|
481 textarea.setAttribute('readonly', 'readonly'); |
411 } |
482 } |
412 |
483 |
413 // If the editor preference is tinymce, switch the editor to TinyMCE now |
484 // If the editor preference is tinymce, switch the editor to TinyMCE now |
414 if ( readCookie('enano_editor_mode') == 'tinymce' && allow_wysiwyg ) |
485 if ( readCookie('enano_editor_mode') == 'tinymce' && allow_wysiwyg ) |
415 { |
486 { |
416 $dynano('ajaxEditArea').switchToMCE(); |
487 $dynano('ajaxEditArea').switchToMCE(); |
417 } |
488 } |
418 $dynano('ajaxEditArea').object.focus(); |
489 $dynano('ajaxEditArea').object.focus(); |
419 } |
490 $dynano('ajaxEditArea').object._edTimestamp = timestamp; |
420 |
491 $dynano('ajaxEditArea').setContent(content); |
421 function ajaxEditorSave() |
492 |
422 { |
493 // Autosave every 5 minutes (m * s * ms) |
423 ajaxSetEditorLoading(); |
494 setInterval('ajaxPerformAutosave();', ( 5 * 60 * 1000 )); |
|
495 } |
|
496 |
|
497 function ajaxEditorSave(is_draft) |
|
498 { |
|
499 if ( !is_draft ) |
|
500 ajaxSetEditorLoading(); |
424 var ta_content = $('ajaxEditArea').getContent(); |
501 var ta_content = $('ajaxEditArea').getContent(); |
425 |
502 |
426 if ( ta_content == '' || ta_content == '<p></p>' || ta_content == '<p> </p>' ) |
503 if ( !is_draft && ( ta_content == '' || ta_content == '<p></p>' || ta_content == '<p> </p>' ) ) |
427 { |
504 { |
428 new messagebox(MB_OK|MB_ICONSTOP, $lang.get('editor_err_no_text_title'), $lang.get('editor_err_no_text_body')); |
505 new messagebox(MB_OK|MB_ICONSTOP, $lang.get('editor_err_no_text_title'), $lang.get('editor_err_no_text_body')); |
429 ajaxUnSetEditorLoading(); |
506 ajaxUnSetEditorLoading(); |
430 return false; |
507 return false; |
|
508 } |
|
509 |
|
510 if ( is_draft ) |
|
511 { |
|
512 // ajaxSetEditorLoading(); |
|
513 var img = $('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0]; |
|
514 var lbl = $('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0]; |
|
515 img.src = scriptPath + '/images/loading.gif'; |
|
516 var d = new Date(); |
|
517 var m = String(d.getMinutes()); |
|
518 if ( m.length < 2 ) |
|
519 m = '0' + m; |
|
520 var time = d.getHours() + ':' + m; |
|
521 lbl.innerHTML = $lang.get('editor_msg_draft_saving'); |
431 } |
522 } |
432 |
523 |
433 var edit_summ = $('enano_editor_field_summary').object.value; |
524 var edit_summ = $('enano_editor_field_summary').object.value; |
434 if ( !edit_summ ) |
525 if ( !edit_summ ) |
435 edit_summ = ''; |
526 edit_summ = ''; |
436 var is_minor = ( $('enano_editor_field_minor').object.checked ) ? 1 : 0; |
527 var is_minor = ( $('enano_editor_field_minor').object.checked ) ? 1 : 0; |
437 var timestamp = $('ajaxEditArea').object._edTimestamp; |
528 var timestamp = $('ajaxEditArea').object._edTimestamp; |
|
529 var used_draft = $('ajaxEditArea').object.used_draft; |
438 |
530 |
439 var json_packet = { |
531 var json_packet = { |
440 src: ta_content, |
532 src: ta_content, |
441 summary: edit_summ, |
533 summary: edit_summ, |
442 minor_edit: is_minor, |
534 minor_edit: is_minor, |
443 time: timestamp |
535 time: timestamp, |
|
536 draft: ( is_draft == true ), |
|
537 used_draft: used_draft |
444 }; |
538 }; |
445 |
539 |
446 // Do we need to add captcha info? |
540 // Do we need to add captcha info? |
447 if ( document.getElementById('enano_editor_field_captcha') ) |
541 if ( document.getElementById('enano_editor_field_captcha') ) |
448 { |
542 { |
507 new messagebox(MB_OK | MB_ICONEXCLAMATION, $lang.get('editor_err_obsolete_title'), $lang.get('editor_err_obsolete_body', { author: response.author, timestamp: response.date_string, page_url: makeUrl(title, false, true) })); |
600 new messagebox(MB_OK | MB_ICONEXCLAMATION, $lang.get('editor_err_obsolete_title'), $lang.get('editor_err_obsolete_body', { author: response.author, timestamp: response.date_string, page_url: makeUrl(title, false, true) })); |
508 return false; |
601 return false; |
509 } |
602 } |
510 if ( response.mode == 'success' ) |
603 if ( response.mode == 'success' ) |
511 { |
604 { |
512 // The save was successful; reset flags and make another request for the new page content |
605 if ( response.is_draft ) |
513 setAjaxLoading(); |
606 { |
514 editor_open = false; |
607 document.getElementById('ajaxEditArea').used_draft = true; |
515 enableUnload(); |
608 document.getElementById('ajaxEditArea').needReset = true; |
516 changeOpac(0, 'ajaxEditContainer'); |
609 var img = $('ajax_edit_savedraft_btn').object.getElementsByTagName('img')[0]; |
517 ajaxGet(stdAjaxPrefix + '&_mode=getpage&noheaders', function() |
610 var lbl = $('ajax_edit_savedraft_btn').object.getElementsByTagName('span')[0]; |
518 { |
611 img.src = scriptPath + '/images/mini-info.png'; |
519 if ( ajax.readyState == 4 && ajax.status == 200 ) |
612 var d = new Date(); |
|
613 var m = String(d.getMinutes()); |
|
614 if ( m.length < 2 ) |
|
615 m = '0' + m; |
|
616 var time = d.getHours() + ':' + m; |
|
617 lbl.innerHTML = $lang.get('editor_msg_draft_saved', { time: time }); |
|
618 } |
|
619 else |
|
620 { |
|
621 // The save was successful; reset flags and make another request for the new page content |
|
622 ajaxUnSetEditorLoading(); |
|
623 setAjaxLoading(); |
|
624 editor_open = false; |
|
625 enableUnload(); |
|
626 changeOpac(0, 'ajaxEditContainer'); |
|
627 ajaxGet(stdAjaxPrefix + '&_mode=getpage&noheaders', function() |
520 { |
628 { |
521 unsetAjaxLoading(); |
629 if ( ajax.readyState == 4 && ajax.status == 200 ) |
522 selectButtonMajor('article'); |
630 { |
523 unselectAllButtonsMinor(); |
631 unsetAjaxLoading(); |
524 |
632 selectButtonMajor('article'); |
525 document.getElementById('ajaxEditContainer').innerHTML = '<div class="usermessage">' + $lang.get('editor_msg_saved') + '</div>' + ajax.responseText; |
633 unselectAllButtonsMinor(); |
526 opacity('ajaxEditContainer', 0, 100, 1000); |
634 |
527 } |
635 document.getElementById('ajaxEditContainer').innerHTML = '<div class="usermessage">' + $lang.get('editor_msg_saved') + '</div>' + ajax.responseText; |
528 }); |
636 opacity('ajaxEditContainer', 0, 100, 1000); |
|
637 } |
|
638 }); |
|
639 } |
529 } |
640 } |
530 } |
641 } |
531 }, true); |
642 }, true); |
532 |
|
533 } |
643 } |
534 |
644 |
535 function ajaxEditorGenPreview() |
645 function ajaxEditorGenPreview() |
536 { |
646 { |
537 ajaxSetEditorLoading(); |
647 ajaxSetEditorLoading(); |
745 var body = document.getElementsByTagName('body')[0]; |
847 var body = document.getElementsByTagName('body')[0]; |
746 body.removeChild(blackout); |
848 body.removeChild(blackout); |
747 } |
849 } |
748 } |
850 } |
749 |
851 |
|
852 function ajaxAutosaveDraft() |
|
853 { |
|
854 var aed = document.getElementById('ajaxEditArea'); |
|
855 if ( !aed ) |
|
856 return false; |
|
857 var last_save = aed.as_last_save; |
|
858 var now = unix_time(); |
|
859 if ( ( last_save + 120 ) < now && aed.value != aed.content_orig ) |
|
860 { |
|
861 ajaxPerformAutosave(); |
|
862 } |
|
863 } |
|
864 |
|
865 function ajaxPerformAutosave() |
|
866 { |
|
867 var aed = document.getElementById('ajaxEditArea'); |
|
868 if ( !aed ) |
|
869 return false; |
|
870 var now = unix_time(); |
|
871 aed.as_last_save = now; |
|
872 |
|
873 var ta_content = $('ajaxEditArea').getContent(); |
|
874 |
|
875 if ( ta_content == '' || ta_content == '<p></p>' || ta_content == '<p> </p>' ) |
|
876 { |
|
877 return false; |
|
878 } |
|
879 |
|
880 ajaxEditorSave(true); |
|
881 } |
|
882 |
|
883 function ajaxEditorUseDraft() |
|
884 { |
|
885 var aed = document.getElementById('ajaxEditArea'); |
|
886 if ( !aed ) |
|
887 return false; |
|
888 ajaxSetEditorLoading(); |
|
889 ajaxGet(stdAjaxPrefix + '&_mode=getsource&get_draft=1', function() |
|
890 { |
|
891 if ( ajax.readyState == 4 && ajax.status == 200 ) |
|
892 { |
|
893 ajaxUnSetEditorLoading(); |
|
894 |
|
895 var response = String(ajax.responseText + ''); |
|
896 if ( response.substr(0, 1) != '{' ) |
|
897 { |
|
898 handle_invalid_json(response); |
|
899 return false; |
|
900 } |
|
901 |
|
902 response = parseJSON(response); |
|
903 if ( response.mode == 'error' ) |
|
904 { |
|
905 unselectAllButtonsMinor(); |
|
906 new messagebox(MB_OK | MB_ICONSTOP, $lang.get('editor_err_server'), response.error); |
|
907 return false; |
|
908 } |
|
909 |
|
910 $('ajaxEditArea').setContent(response.src); |
|
911 $('ajaxEditArea').object.used_draft = true; |
|
912 |
|
913 var dn = $('ajax_edit_draft_notice').object; |
|
914 dn.parentNode.removeChild(dn); |
|
915 } |
|
916 }, true); |
|
917 } |
|
918 |