1/** 2 * Javascript for searchindex manager plugin 3 * 4 * @author Andreas Gohr <andi@splitbrain.org> 5 */ 6 7/** 8 * Class to hold some values 9 */ 10function plugin_searchindex_class(){ 11 this.pages = null; 12 this.page = null; 13 this.sack = null; 14 this.done = 1; 15 this.count = 0; 16} 17var pl_si = new plugin_searchindex_class(); 18pl_si.sack = new sack(DOKU_BASE + 'lib/plugins/searchindex/ajax.php'); 19pl_si.sack.AjaxFailedAlert = ''; 20pl_si.sack.encodeURIString = false; 21 22/** 23 * Display the loading gif 24 */ 25function plugin_searchindex_throbber(on){ 26 obj = document.getElementById('pl_si_throbber'); 27 if(on){ 28 obj.style.visibility='visible'; 29 }else{ 30 obj.style.visibility='hidden'; 31 } 32} 33 34/** 35 * Gives textual feedback 36 */ 37function plugin_searchindex_status(text){ 38 obj = document.getElementById('pl_si_out'); 39 obj.innerHTML = text; 40} 41 42/** 43 * Callback. Gets the list of all pages 44 */ 45function plugin_searchindex_cb_clear(){ 46 ok = this.response; 47 if(ok == 1){ 48 // start indexing 49 window.setTimeout("plugin_searchindex_index()",1000); 50 }else{ 51 plugin_searchindex_status(ok); 52 // retry 53 window.setTimeout("plugin_searchindex_clear()",5000); 54 } 55} 56 57/** 58 * Callback. Gets the list of all pages 59 */ 60function plugin_searchindex_cb_pages(){ 61 data = this.response; 62 pl_si.pages = data.split("\n"); 63 pl_si.count = pl_si.pages.length; 64 plugin_searchindex_status(pl_si.pages.length+" pages found"); 65 66 pl_si.page = pl_si.pages.shift(); 67 window.setTimeout("plugin_searchindex_clear()",1000); 68} 69 70/** 71 * Callback. Gets the info if indexing of a page was successful 72 * 73 * Calls the next index run. 74 */ 75function plugin_searchindex_cb_index(){ 76 ok = this.response; 77 if(ok == 1){ 78 pl_si.page = pl_si.pages.shift(); 79 pl_si.done++; 80 // get next one 81 window.setTimeout("plugin_searchindex_index()",1000); 82 }else{ 83 plugin_searchindex_status(ok); 84 // get next one 85 window.setTimeout("plugin_searchindex_index()",5000); 86 } 87} 88 89/** 90 * Starts the indexing of a page. 91 */ 92function plugin_searchindex_index(){ 93 if(pl_si.page){ 94 plugin_searchindex_status('indexing '+pl_si.page+' ('+pl_si.done+'/'+pl_si.count+')'); 95 pl_si.sack.onCompletion = plugin_searchindex_cb_index; 96 pl_si.sack.URLString = ''; 97 pl_si.sack.runAJAX('call=indexpage&page='+encodeURI(pl_si.page)); 98 }else{ 99 plugin_searchindex_status('finished'); 100 plugin_searchindex_throbber(false); 101 } 102} 103 104/** 105 * Cleans the index 106 */ 107function plugin_searchindex_clear(){ 108 plugin_searchindex_status('clearing index...'); 109 pl_si.sack.onCompletion = plugin_searchindex_cb_clear; 110 pl_si.sack.URLString = ''; 111 pl_si.sack.runAJAX('call=clearindex'); 112} 113 114/** 115 * Starts the whole index rebuild process 116 */ 117function plugin_searchindex_go(){ 118 document.getElementById('pl_si_gobtn').style.display = 'none'; 119 plugin_searchindex_throbber(true); 120 121 plugin_searchindex_status('Finding all pages'); 122 pl_si.sack.onCompletion = plugin_searchindex_cb_pages; 123 pl_si.sack.URLString = ''; 124 pl_si.sack.runAJAX('call=pagelist'); 125} 126 127//Setup VIM: ex: et ts=4 enc=utf-8 : 128