Skip to content
Snippets Groups Projects
Commit a8254dfa authored by Andreas Gohr's avatar Andreas Gohr
Browse files

made ajax quicksearch its own object

This makes it possible for plugin and template authors to overwrite or
extend the quicksearch JavaScript logic.
parent d83e78ed
No related branches found
No related tags found
No related merge requests found
......@@ -5,30 +5,58 @@
* @author Andreas Gohr <andi@splitbrain.org>
* @author Adrian Lang <lang@cosmocode.de>
*/
addInitEvent(function () {
var ajax_quicksearch = {
var inID = 'qsearch__in';
var outID = 'qsearch__out';
inObj: null,
outObj: null,
sackObj: null,
delay: null,
var inObj = document.getElementById(inID);
var outObj = document.getElementById(outID);
init: function(inID, outID) {
// objects found?
if (inObj === null){ return; }
if (outObj === null){ return; }
this.inObj = $(inID);
this.outObj = $(outID);
function clear_results(){
outObj.style.display = 'none';
outObj.innerHTML = '';
}
// objects found?
if (this.inObj === null) return;
if (this.outObj === null) return;
// prepare AJAX
this.sackObj = new sack(DOKU_BASE + 'lib/exe/ajax.php');
this.sackObj.AjaxFailedAlert = '';
this.sackObj.encodeURIString = false;
this.sackObj.onCompletion = ajax_quicksearch.onCompletion;
// attach eventhandler to search field
this.delay = new Delay(function () {
ajax_quicksearch.clear_results();
var value = ajax_quicksearch.inObj.value;
if(value === ''){ return; }
ajax_quicksearch.sackObj.runAJAX('call=qsearch&q=' + encodeURI(value));
});
addEvent(this.inObj, 'keyup', function () {
ajax_quicksearch.clear_results();
ajax_quicksearch.delay.start();
});
// attach eventhandler to output field
addEvent(this.outObj, 'click', function () {
ajax_quicksearch.outObj.style.display = 'none';
});
},
var sack_obj = new sack(DOKU_BASE + 'lib/exe/ajax.php');
sack_obj.AjaxFailedAlert = '';
sack_obj.encodeURIString = false;
sack_obj.onCompletion = function () {
var data = sack_obj.response;
clear_results: function(){
ajax_quicksearch.outObj.style.display = 'none';
ajax_quicksearch.outObj.innerHTML = '';
},
onCompletion: function() {
var data = this.response; // 'this' is sack context
if (data === '') { return; }
var outObj = ajax_quicksearch.outObj;
outObj.innerHTML = data;
outObj.style.display = 'block';
outObj.style['white-space'] = 'nowrap';
......@@ -79,19 +107,12 @@ addInitEvent(function () {
nsR = links[i].innerText.indexOf(')');
}
}
}
};
// attach eventhandler to search field
var delay = new Delay(function () {
clear_results();
var value = inObj.value;
if(value === ''){ return; }
sack_obj.runAJAX('call=qsearch&q=' + encodeURI(value));
});
};
addEvent(inObj, 'keyup', function () {clear_results(); delay.start(); });
// attach eventhandler to output field
addEvent(outObj, 'click', function () {outObj.style.display = 'none'; });
addInitEvent(function(){
ajax_quicksearch.init('qsearch__in','qsearch__out');
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment