Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Compete jQuery rewrite; also added option to Update or Rebuild the index

All JS rewritten to use jQuery
JS code now used revealing module pattern to reduce namespace repetition
Revised the instruction text and layout
New updating status message layout
2 options: Rebuild Index or Update Index only
Revised CSS
  • Loading branch information...
commit 73c6efcd6d8a4f75f0c193ebfdfe99e616e7347e 1 parent 05c9d6f
@MrBertie MrBertie authored
View
12 admin.php
@@ -29,13 +29,15 @@ function handle() {
function html() {
echo $this->plugin_locale_xhtml('intro');
-
echo '<div id="plugin__searchindex">';
- echo $this->getLang('nojs');
+ echo '<div class="buttons" id="plugin__searchindex_buttons">' .
+ '<input type="button" class="button" id="plugin__searchindex_rebuild" value="' . $this->getLang('rebuild') . '"/>' .
+ '<p>' . $this->getLang('rebuild_tip') . '</p>' .
+ '<input type="button" class="button" id="plugin__searchindex_update" value="' . $this->getLang('update') . '"/>' .
+ '<p>' . $this->getLang('update_tip') . '</p>' .
+ '</div>';
+ echo '<div class="msg" id="plugin__searchindex_msg"></div>';
echo '</div>';
-
}
-
-
}
//Setup VIM: ex: et ts=4 enc=utf-8 :
View
4 ajax.php
@@ -125,7 +125,7 @@ function ajax_indexpage(){
}
// do the work
- idx_addPage($_POST['page'], false, true);
+ $success = idx_addPage($_POST['page'], false, false);
// we're finished
if(INDEXER_VERSION < 4){
@@ -133,6 +133,6 @@ function ajax_indexpage(){
@rmdir($lock);
}
- print 1;
+ print ($success !== false) ? 1 : 0;
}
View
16 lang/en/intro.txt
@@ -1,12 +1,12 @@
-====== Searchindex Manager ======
+====== SearchIndex Manager ======
-This page allows you to rebuild the index used by the fulltext search.
-This isn't needed generally as the index builds and updates itself while
+This page allows you to update or rebuild the index used by the full-text search.
+This is generally not needed as the index builds and updates itself as
users browse your wiki. However if you just upgraded, added or removed
-a lot of files it may be a good idea to cleanup the the index.
+a lot of files it may be a good idea to clean up the index.
-This manager needs a recent browser as it makes use of modern JavaScript
-to carry out multiple tasks in the background (using [[wp>AJAX]]).
-
-Rebuilding the index takes a long time. You should leave the page open
+Rebuilding the index **can take a long time**. You should leave the page open
until the indexing has finished.
+
+//NOTE: This manager needs a recent browser as it makes use of modern JavaScript
+to carry out multiple tasks in the background (using [[wp>AJAX]]).//
View
12 lang/en/lang.php
@@ -5,13 +5,15 @@
$lang['menu'] = 'Searchindex Manager';
-$lang['nojs'] = 'JavaScript needs to be enabled to run this plugin';
+$lang['update'] = 'Update Index';
+$lang['update_tip'] = 'Just update the search index (usually quicker)';
+$lang['rebuild'] = 'Rebuild Index';
+$lang['rebuild_tip'] = 'Clear then completely rebuild the search index';
-$lang['js']['rebuild'] = 'Rebuild Index';
-$lang['js']['indexing'] = 'Now indexing:';
+$lang['js']['indexing'] = 'Indexed:';
$lang['js']['done'] = 'Finished indexing.';
$lang['js']['pages'] = '%d pages found.';
$lang['js']['clearing'] = 'Clearing index...';
$lang['js']['finding'] = 'Finding pages...';
-
-
+$lang['js']['notindexed'] = 'Skipped: Up-to-date';
+$lang['js']['indexed'] = 'Updated';
View
233 script.js
@@ -2,155 +2,150 @@
* Javascript for searchindex manager plugin
*
* @author Andreas Gohr <andi@splitbrain.org>
+ * @author Symon Bent <hendrybadao@gmail.com>
+ * Complete rewrite using jQuery and revealing module pattern
+ * Separate update and rebuild options
*/
-var plugin_searchindex = {
+var plugin_searchindex = (function() {
- // hold some values
- pages: null,
- page: null,
- sack: null,
- done: 1,
- count: 0,
- output: null,
- lang: null,
+ // public methods/properties
+ var pub = {};
+
+ // private vars
+ var pages = null,
+ page = null,
+ url = null,
+ done = 1,
+ count = 0,
+ $msg = null,
+ $buttons = null,
+ lang = null;
/**
* initialize everything
*/
- init: function(){
- plugin_searchindex.output = $('plugin__searchindex');
- if(!plugin_searchindex.output) return;
-
- plugin_searchindex.sack = new sack(DOKU_BASE + 'lib/plugins/searchindex/ajax.php');
- plugin_searchindex.sack.AjaxFailedAlert = '';
- plugin_searchindex.sack.encodeURIString = false;
- plugin_searchindex.lang = LANG.plugins.searchindex;
+ pub.init = function() {
+ $msg = jQuery('#plugin__searchindex_msg');
+ if( ! $msg) return;
- // init interface
- plugin_searchindex.status('<button id="plugin__searchindex_btn" class="button">'+plugin_searchindex.lang.rebuild+'</button>');
- addEvent($('plugin__searchindex_btn'),'click',plugin_searchindex.go);
- },
+ lang = LANG.plugins.searchindex;
+ url = DOKU_BASE + 'lib/plugins/searchindex/ajax.php';
- /**
- * Gives textual feedback
- */
- status: function(text){
- plugin_searchindex.output.innerHTML = text;
- },
+ $buttons = jQuery('#plugin__searchindex_buttons');
- /**
- * Callback.
- * Executed when the index was cleared.
- * Starts the indexing
- */
- cb_clear: function(){
- var ok = this.response;
- if(ok == 1){
- // start indexing
- window.setTimeout(plugin_searchindex.index,1000);
- }else{
- plugin_searchindex.status(ok);
- // retry
- window.setTimeout(plugin_searchindex.clear,5000);
- }
- },
+ // init interface events
+ jQuery('#plugin__searchindex_update').click(pub.update);
+ jQuery('#plugin__searchindex_rebuild').click(pub.rebuild);
+ };
/**
- * Callback.
- * Executed when the list of pages came back.
- * Starts the index clearing
- */
- cb_pages: function(){
- var data = this.response;
- plugin_searchindex.pages = data.split("\n");
- plugin_searchindex.count = plugin_searchindex.pages.length;
- plugin_searchindex.status(plugin_searchindex.lang.pages.replace(/%d/,plugin_searchindex.pages.length));
-
- // move the first page from the queue
- plugin_searchindex.page = plugin_searchindex.pages.shift();
-
- // start index cleaning
- window.setTimeout(plugin_searchindex.clear,1000);
- },
-
- /**
- * Callback.
- * Returned after indexing one page
- * Calls the next index run.
+ * Gives textual feedback
*/
- cb_index: function(){
- var ok = this.response;
- var wait = 500;
- if(ok == 1){
- // next page from queue
- plugin_searchindex.page = plugin_searchindex.pages.shift();
- plugin_searchindex.done++;
- }else{
- // something went wrong, show message
- plugin_searchindex.status(ok);
- wait = 5000;
+ var message = function(text) {
+ if (text.charAt(0) !== '<') {
+ text = '<p>' + text + '</p>'
}
- // next index run
- window.setTimeout(plugin_searchindex.index,500);
- },
+ $msg.html(text);
+ };
/**
* Starts the indexing of a page.
*/
- index: function(){
- if(plugin_searchindex.page){
- plugin_searchindex.status(plugin_searchindex.lang.indexing+' <b>'+plugin_searchindex.page+'</b> ('+plugin_searchindex.done+'/'+plugin_searchindex.count+')');
- plugin_searchindex.sack.onCompletion = plugin_searchindex.cb_index;
- plugin_searchindex.sack.URLString = '';
- plugin_searchindex.sack.runAJAX('call=indexpage&page='+encodeURI(plugin_searchindex.page));
- }else{
- // we're done
- plugin_searchindex.throbber_off();
- plugin_searchindex.status(plugin_searchindex.lang.done);
+ var index = function() {
+ if (page) {
+ jQuery.post(url, 'call=indexpage&page=' + encodeURI(page), function(response) {
+ var wait = 250;
+ var status = lang.indexed;
+ if (response !== 1) {
+ // either up-to-date or error: skipped
+ status = '<p class="status">' + lang.notindexed + '</p>';
+ }
+ // next page from queue
+ page = pages.shift();
+ done++;
+
+ message('<p>' + lang.indexing + ' ' + done + '/' + count + '</p><p class="name">' + page + '</p>' + status);
+ // next index run
+ window.setTimeout(index, wait);
+ });
+ } else {
+ finished();
}
- },
-
+ };
+
+ var finished = function() {
+ // we're done
+ throbber_off();
+ message(lang.done);
+ window.setTimeout(function() {
+ message('');
+ $buttons.show('slow');
+ }, 3000);
+ };
/**
- * Cleans the index
+ * Cleans the index (ready for complete rebuild)
*/
- clear: function(){
- plugin_searchindex.status(plugin_searchindex.lang.clearing);
- plugin_searchindex.sack.onCompletion = plugin_searchindex.cb_clear;
- plugin_searchindex.sack.URLString = '';
- plugin_searchindex.sack.runAJAX('call=clearindex');
- },
-
+ var clear = function() {
+ message(lang.clearing);
+ jQuery.post(url, 'call=clearindex', function(response) {
+ if (response !== 1) {
+ message(response);
+ // retry
+ window.setTimeout(clear,5000);
+ }
+ });
+ };
+
+ pub.rebuild = function() {
+ pub.update(true);
+ };
/**
- * Starts the whole index rebuild process
+ * Starts the index update
*/
- go: function(){
- plugin_searchindex.throbber_on();
- plugin_searchindex.status(plugin_searchindex.lang.finding);
- plugin_searchindex.sack.onCompletion = plugin_searchindex.cb_pages;
- plugin_searchindex.sack.URLString = '';
- plugin_searchindex.sack.runAJAX('call=pagelist');
- },
+ pub.update = function(rebuild) {
+ rebuild = rebuild || false;
+ $buttons.hide('slow');
+ throbber_on();
+ message(lang.finding);
+ jQuery.post(url, 'call=pagelist', function(response) {
+ if (response != 1) {
+ pages = response.split("\n");
+ count = pages.length;
+ message(lang.pages.replace(/%d/, pages.length));
+
+ // move the first page from the queue
+ page = pages.shift();
+
+ // complete index rebuild?
+ if (rebuild === true) clear();
+
+ // start indexing
+ window.setTimeout(index,1000);
+ } else {
+ finished();
+ }
+ });
+ };
/**
* add a throbber image
*/
- throbber_on: function(){
- plugin_searchindex.output.style['background-image'] = "url('"+DOKU_BASE+'lib/images/throbber.gif'+"')";
- plugin_searchindex.output.style['background-repeat'] = 'no-repeat';
- },
+ var throbber_on = function() {
+ $msg.addClass('updating');
+ };
/**
* Stop the throbber
*/
- throbber_off: function(){
- plugin_searchindex.output.style['background-image'] = 'none';
- }
-};
-
-addInitEvent(function(){
- plugin_searchindex.init();
-});
+ var throbber_off = function() {
+ $msg.removeClass('updating');
+ };
+ // return only public methods/properties
+ return pub;
+})();
-//Setup VIM: ex: et ts=4 enc=utf-8 :
+jQuery(function() {
+ plugin_searchindex.init();
+});
View
52 style.css
@@ -1,10 +1,52 @@
#plugin__searchindex {
- border: solid 1px __border__;
- padding: 2em;
- margin: 2em auto 1em auto;
- vertical-align: middle;
width: 80%;
- text-align: center;
+ margin: 0 auto;
+}
+
+#plugin__searchindex .buttons {
+ vertical-align: middle;
+ padding: 7px 8px;
+ margin: 2.5em auto;
+}
+#plugin__searchindex .buttons .button {
+ float: left;
+ clear: left;
+ margin: 0 1.2em;
+ width: 10em;
+}
+#plugin__searchindex .buttons p {
+ float: left;
+}
+#plugin__searchindex .msg {
+ color: #A0A0A0;
+ border: 0px solid #D7D5D4;
+ border-radius: 3px;
+ -moz-border-radius: 3px;
+ -webkit-border-radius: 3px;
+ overflow: hidden;
+}
+#plugin__searchindex .msg p {
+ margin-left: 24px;
+ margin-bottom: 4px !important;
+}
+#plugin__searchindex .msg p.name,
+#plugin__searchindex .msg p.status {
+ margin-left: 2.2em;
+ font-size: 75%;
+}
+#plugin__searchindex .msg p.name {
+ font-weight: bold;
+}
+#plugin__searchindex .msg p.status {
+ color: #D7D5D4;
+ font-style: italic;
}
+#plugin__searchindex .updating {
+ background-image: url('../../images/throbber.gif');
+ background-repeat: no-repeat;
+ background-position: 5px 4px;
+ border-width: 1px;
+ padding: 3px;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.