1 $(document
).ready(function() {
2 var query
= $('#query');
4 // fix to avoid autocomplete if element is not present.
5 // the autocomplete source is minified and we've got a demo to run..
6 // new-host wizard fails without this
10 serviceUrl
:_site_domain
+ _index_page
+ '/ajax/global_search/',
12 //delimiter: /(,|;)\s*/, // regex or character
15 deferRequestBy
: 300, //miliseconds
17 onSelect: function(value
, data
){ do_redirect(value
, data
); }
21 var search_old_refresh
= 0;
22 query
.focus(function() {
23 search_old_refresh
= current_interval
;
25 $("#ninja_refresh_control").attr('checked', true);
26 $('#ninja_refresh_lable').css('font-weight', 'bold');
29 query
.blur(function() {
30 if (current_interval
=== 0 && search_old_refresh
!== 0) {
31 current_interval
= search_old_refresh
;
32 ninja_refresh(current_interval
);
33 $("#ninja_refresh_control").attr('checked', false);
34 $('#ninja_refresh_lable').css('font-weight', '');
39 // function from http://forums.devshed.com/t39065/s84ded709f924610aa44fff827511aba3.html
40 // author appears to be Robert Pollard
44 if (!arguments
|| arguments
.length
< 1 || !RegExp
)
48 var str
= arguments
[0];
49 var re
= /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
50 var a
= b
= [], numSubstitutions
= 0, numMatches
= 0;
51 while (a
= re
.exec(str
))
53 var leftpart
= a
[1], pPad
= a
[2], pJustify
= a
[3], pMinLength
= a
[4];
54 var pPrecision
= a
[5], pType
= a
[6], rightPart
= a
[7];
64 if (numSubstitutions
>= arguments
.length
)
66 alert('Error! Not enough function arguments (' + (arguments
.length
- 1)
67 + ', excluding the string)\n'
68 + 'for the number of substitution parameters in string ('
69 + numSubstitutions
+ ' so far).');
71 var param
= arguments
[numSubstitutions
];
73 if (pPad
&& pPad
.substr(0,1) == "'") pad
= leftpart
.substr(1,1);
74 else if (pPad
) pad
= pPad
;
75 var justifyRight
= true;
76 if (pJustify
&& pJustify
=== "-") justifyRight
= false;
78 if (pMinLength
) minLength
= parseInt(pMinLength
);
80 if (pPrecision
&& pType
== 'f')
81 precision
= parseInt(pPrecision
.substring(1));
86 subst
= parseInt(param
).toString(2);
89 subst
= String
.fromCharCode(parseInt(param
));
92 subst
= parseInt(param
) ? parseInt(param
) : 0;
95 subst
= Math
.abs(param
);
98 subst
= (precision
> -1)
99 ? Math
.round(parseFloat(param
) * Math
.pow(10, precision
))
100 / Math
.pow(10, precision
)
104 subst
= parseInt(param
).toString(8);
110 subst
= ('' + parseInt(param
).toString(16)).toLowerCase();
113 subst
= ('' + parseInt(param
).toString(16)).toUpperCase();
116 var padLeft
= minLength
- subst
.toString().length
;
119 var arrTmp
= new Array(padLeft
+1);
120 var padding
= arrTmp
.join(pad
?pad
:" ");
127 str
= leftpart
+ padding
+ subst
+ rightPart
;
134 function do_redirect(value
, data
)
136 // if user clicked on information message about
137 // nr of rows returned, we shouldn't do anything
143 var match
= value
.split(';');
148 var str
= sprintf(data
[0], encodeURIComponent(data
[1]), value
);
149 self
.location
.href
= _site_domain
+ _index_page
+ str
;