1function isBlank(s){ 2 if ((s === null) || (s.length === 0)){ 3 return true; 4 } 5 6 for (var i = 0; i < s.length; i++){ 7 var c = s.charAt(i); 8 if ((c != ' ') && (c != '\n') && (c != '\t')){ 9 return false; 10 } 11 } 12 return true; 13} 14 15function validate(frm){ 16 if (isBlank(frm.mail.value) || frm.mail.value.indexOf("@") == -1){ 17 frm.mail.focus(); 18 return false; 19 } 20 if (isBlank(frm.name.value)){ 21 frm.name.focus(); 22 return false; 23 } 24 25 if (isBlank(frm.text.value)){ 26 frm.text.focus(); 27 return false; 28 } 29} 30 31/** 32 * AJAX preview 33 * 34 * @author Michael Klier <chi@chimeric.de> 35 */ 36function discussion_ajax_preview() { 37 if(!document.getElementById) return; 38 39 var textarea = $('discussion__comment_text'); 40 var comment = textarea.value; 41 if(!comment) return; 42 43 var preview = $('discussion__comment_preview'); 44 var wikisyntaxok = $('discussion__comment_wikisyntaxok'); 45 46 // We use SACK to do the AJAX requests 47 var ajax = new sack(DOKU_BASE+'lib/plugins/discussion/ajax.php'); 48 ajax_qsearch.sack.AjaxFailedAlert = ''; 49 ajax_qsearch.sack.encodeURIString = false; 50 51 // define callback 52 ajax.onCompletion = function(){ 53 var data = this.response; 54 if(data === ''){ return; } 55 preview.style.visibility = 'hidden'; 56 preview.innerHTML = data; 57 preview.style.visibility = 'visible'; 58 }; 59 60 ajax.runAJAX('comment='+comment+'&wikisyntaxok='+wikisyntaxok.value); 61} 62 63// init toolbar 64addInitEvent(function() {initToolbar("discussion__comment_toolbar", "discussion__comment_text", toolbar)}); 65 66// init preview button 67addInitEvent(function() { 68 var btn = $('discussion__btn_preview'); 69 if(!btn) return; 70 addEvent(btn, 'click', discussion_ajax_preview); 71}); 72