-
Notifications
You must be signed in to change notification settings - Fork 0
/
asyncsearch.js
76 lines (61 loc) · 2.53 KB
/
asyncsearch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
(function($){
$.asyncsearch = {};
var resultHandlers = [];
(function(_) {
_.addProvider = function( name, resultHandler, params ) {
resultHandlers.push( {
'provider': name,
'handler': resultHandler,
'params': params
});
};
_.executeSearch = function() {
var searchPlugin = this;
// If the provider is a function, it will handle stuff for us
if ( typeof searchPlugin.provider == 'function' ) {
searchPlugin.provider.call( $('#asyncsearch'), $('#asyncsearch').data('term'), _.start);
return;
}
$.post( DOKU_BASE + 'lib/exe/ajax.php', {
'call': 'asyncsearch',
'pluginID': searchPlugin.provider,
'term': $('#asyncsearch').data('term')
} ).success( function( data ) {
searchPlugin.handler.call( $('#asyncsearch'), data);
_.start();
} );
};
_.start = function() {
if ( resultHandlers.length > 0 ) {
$('.asyncsearch.wave').addClass('show');
$('<hr/>').appendTo( $('#asyncsearch') );
_.executeSearch.call( resultHandlers.shift() );
} else {
window.setTimeout( function() {
$('.asyncsearch.wave').removeClass('show');
}, 1000);
}
};
_.appendSpinner = function( $anchor ) {
var $spinnerContainer = $('<div></div>').addClass('loader').appendTo($('<div></div>').addClass('asyncsearch wave').appendTo( $anchor ));
$.each( new Array(10), function( idx ) {
$('<div></div>').addClass('line').css('animation-delay', ((idx+1)/10) + 's' ).appendTo( $spinnerContainer );
});
return $spinnerContainer;
};
_.init = function() {
_.appendSpinner( $($('.page :header').get(0)) ).css('margin-left', '1em');
_.appendSpinner( $('<center></center>').appendTo( $('#asyncsearch').parent() ) );
_.start();
};
})($.asyncsearch);
$($.asyncsearch.init);
})(jQuery);
/** Provider for the QuickPages Search **/
jQuery.asyncsearch.addProvider( 'pagelookup', function( data ){
jQuery('<div></div>').html(data).appendTo(this);
});
/** Provider for the Page Search **/
jQuery.asyncsearch.addProvider( 'pagesearch', function( data ){
jQuery('<div></div>').html(data).appendTo(this);
});