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