From e91ea5c1942bfc6533e12375b8140ce774c7d8ca Mon Sep 17 00:00:00 2001 From: Andreas Gohr <andi@splitbrain.org> Date: Fri, 3 Jun 2011 13:34:44 +0200 Subject: [PATCH] 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. --- lib/scripts/ajax.js | 87 +++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 38 deletions(-) diff --git a/lib/scripts/ajax.js b/lib/scripts/ajax.js index aa083978c..19d4b86a6 100644 --- a/lib/scripts/ajax.js +++ b/lib/scripts/ajax.js @@ -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)); -- GitLab