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

Fixed quick search

This was broken by the JQuery port. This patch makes the page search
work again and also removes the anonymous wrapper function around
ajax_quicksearch again.
parent 40c1e778
No related branches found
No related tags found
No related merge requests found
......@@ -7,43 +7,45 @@
* @author Michal Rezler <m.rezler@centrum.cz>
*/
(function ($) {
var init, clear_results, onCompletion;
var ajax_quicksearch = {
inObj: null,
outObj: null,
delay: null,
};
init = function(inID, outID) {
ajax_quicksearch.inObj = $(inID);
ajax_quicksearch.outObj = $(outID);
var ajax_quicksearch = {
inObj: null, // jquery object
outObj: null, // jquery object
delay: null,
/**
* initialize the quick search
*
* Attaches the event handlers
*
* @param input element (JQuery selector/DOM obj)
* @param output element (JQuery selector/DOM obj)
*/
init: function(input, output) {
ajax_quicksearch.inObj = jQuery(input);
ajax_quicksearch.outObj = jQuery(output);
// objects found?
if (ajax_quicksearch.inObj === null) return;
if (ajax_quicksearch.outObj === null) return;
if (ajax_quicksearch.inObj === []) return;
if (ajax_quicksearch.outObj === []) return;
// attach eventhandler to search field
ajax_quicksearch.delay = new Delay(function () {
ajax_quicksearch.clear_results();
var value = ajax_quicksearch.inObj.value;
var value = ajax_quicksearch.inObj.val();
if(value === ''){ return; }
$.post(
jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
{
call: 'qsearch',
q: encodeURI(value)
},
function (data) {
onCompletion(data);
},
ajax_quicksearch.onCompletion,
'html'
);
});
$(ajax_quicksearch.inObj).keyup(
ajax_quicksearch.inObj.keyup(
function() {
ajax_quicksearch.clear_results();
ajax_quicksearch.delay.start();
......@@ -51,34 +53,43 @@
);
// attach eventhandler to output field
$(ajax_quicksearch.outObj).click(
function() {
ajax_quicksearch.outObj.hide();
}
ajax_quicksearch.outObj.click(
ajax_quicksearch.outObj.hide
);
};
},
clear_results = function(){
/**
* Empty and hide the output div
*/
clear_results: function(){
ajax_quicksearch.outObj.hide();
ajax_quicksearch.outObj.text('');
};
onCompletion = function(data) {
},
/**
* Callback. Reformat and display the results.
*
* Namespaces are shortened here to keep the results from overflowing
* or wrapping
*
* @param data The result HTML
*/
onCompletion: function(data) {
if (data === '') { return; }
var outObj = ajax_quicksearch.outObj;
outObj.text(data);
outObj.html(data);
outObj.show();
outObj.css('white-space', 'nowrap');
// shorten namespaces if too long
var width = outObj.clientWidth;
var links = $('ajax_quicksearch outObj a');
var links = outObj.find('a');
for (var i=0; i<links.length; i++) {
var content = links[i].text();
var content = links[i].text;
// maximum allowed width:
var max = width - links[i].offsetLeft;
......@@ -121,10 +132,10 @@
nsR = content.indexOf(')');
}
}
};
}
};
$(function () {
init('qsearch__in','qsearch__out');
});
jQuery(function () {
ajax_quicksearch.init('#qsearch__in','#qsearch__out');
});
}(jQuery));
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