3 var sessionStarted
= false;
6 * JQuery Case Insensitive :icontains selector
8 $
.expr
[':'].icontains
= function(obj
, index
, meta
, stack
){
9 return (obj
.textContent
.replace(/\
[[0-9]+\
]/g
, "") || obj
.innerText
.replace(/\
[[0-9]+\
]/g
, "") ||
jQuery(obj
).text().replace(/\
[[0-9]+\
]/g
, "") ||
'').toLowerCase().indexOf(meta
[3].toLowerCase()) >= 0;
13 * Quick Search global vars
16 // Current search results preview table
17 var currentTable
= null;
19 //Hightlighted index in search result preview table
20 var currentIndex
= -1;
24 * Add folding and filtering facilities to class description page.
26 $
(document
).ready(function() {
30 $
('a[id=commitBtn]').hide();
31 $
('a[id=cancelBtn]').hide();
32 // Hide Authenfication form
38 * Highlight the spoted element
40 highlightBlock(currentAnchor());
49 $
(document
.createElement("a"))
53 .css("cursor", "pointer")
55 if($
(this).find("a.fold").html() == "+") {
56 $
(this).find("a.fold").html("-");
58 $
(this).find("a.fold").html("+");
60 $
(this).nextAll().toggle();
63 // Insert search field
66 $
(document
.createElement("li"))
68 $
(document
.createElement("form"))
70 $
(document
.createElement("input"))
75 value
: "quick search..."
83 // Select previous result on "Up"
85 // If already on first result, focus search input
86 if(currentIndex
== 0) {
87 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
89 // Else select previous result
90 } else if(currentIndex
> 0) {
91 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
93 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
94 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
99 // Select next result on "Down"
101 if(currentIndex
< currentTable
.find("tr").length
- 1) {
102 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
104 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
105 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
106 $
("#search").focus();
109 // Go to url on "Enter"
111 if(currentIndex
> -1) {
112 window
.location
= $
(currentTable
.find("tr")[currentIndex]).data("searchDetails").url
;
115 if($
("#search").val().length
== 0)
118 window
.location
= "full-index.html#q=" + $
("#search").val();
119 if(window
.location
.href
.indexOf("full-index.html") > -1) {
125 // Hide results preview on "Escape"
128 if(currentTable
!= null) {
129 currentTable
.remove();
135 if($
("#search").val().length
== 0) {
139 // Remove previous table
140 if(currentTable
!= null) {
141 currentTable
.remove();
144 // Build results table
146 currentTable
= $
(document
.createElement("table"));
148 // Escape regexp related characters in query
149 var query
= $
("#search").val();
150 query
= query
.replace(/\
[/gi
, "\\[");
151 query
= query
.replace(/\|
/gi
, "\\|");
152 query
= query
.replace(/\*/gi
, "\\*");
153 query
= query
.replace(/\
+/gi
, "\\+");
154 query
= query
.replace(/\\/gi
, "\\\\");
155 query
= query
.replace(/\?/gi
, "\\?");
156 query
= query
.replace(/\
(/gi
, "\\(");
157 query
= query
.replace(/\
)/gi
, "\\)");
160 var regexp
= new RegExp("^" + query
, "i");
161 for(var entry
in entries
) {
165 var result
= entry
.match(regexp
);
166 if(result
!= null && result
.toString().toUpperCase() == $
("#search").val().toUpperCase()) {
167 for(var i
= 0; i
< entries
[entry].length
; i
++) {
172 $
(document
.createElement("tr"))
173 .data("searchDetails", {name
: entry
, url
: entries
[entry][i]["url"]})
174 .data("index", index
)
175 .append($
(document
.createElement("td")).html(entry
))
177 $
(document
.createElement("td"))
178 .addClass("entryInfo")
179 .html(entries
[entry][i]["txt"] + " »"))
180 .mouseover( function() {
181 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
182 $
(this).addClass("activeSearchResult");
183 currentIndex
= $
(this).data("index");
185 .mouseout( function() {
186 $
(this).removeClass("activeSearchResult");
189 window
.location
= $
(this).data("searchDetails")["url"];
197 // Initialize table properties
198 currentTable
.attr("id", "searchTable");
199 currentTable
.css("position", "absolute");
200 currentTable
.width($
("#search").outerWidth());
201 $
("header").append(currentTable
);
202 currentTable
.offset({left
: $
("#search").offset().left
+ ($
("#search").outerWidth() - currentTable
.outerWidth()), top
: $
("#search").offset().top
+ $
("#search").outerHeight()});
204 // Preselect first entry
205 if(currentTable
.find("tr").length
> 0) {
207 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
208 $
("#search").focus();
213 .focusout(function() {
214 if($
(this).val() == "") {
215 $
(this).addClass("notUsed");
216 $
(this).val("quick search...");
219 .focusin(function() {
220 if($
(this).val() == "quick search...") {
221 $
(this).removeClass("notUsed");
226 .submit( function() {
232 // Close quicksearch list on click
233 $
(document
).click(function(e
) {
234 if(e
.target
!= $
("#search")[0] && e
.target
!= $
("#searchTable")[0]) {
235 if(currentTable
!= null) {
236 currentTable
.remove();
242 // Insert filter field
243 $
("article.filterable h2, nav.filterable h3")
245 $
(document
.createElement("div"))
248 $
(document
.createElement("input"))
255 $
(this).parent().parent().find("ul li:not(:icontains('" + $
(this).val() + "'))").addClass("hide");
256 $
(this).parent().parent().find("ul li:icontains('" + $
(this).val() + "')").removeClass("hide");
258 .focusout(function() {
259 if($
(this).val() == "") {
260 $
(this).addClass("notUsed");
261 $
(this).val("filter...");
264 .focusin(function() {
265 if($
(this).val() == "filter...") {
266 $
(this).removeClass("notUsed");
273 // Filter toggle between H I R in nav porperties list
274 $
("nav.properties.filterable .filter")
276 $
(document
.createElement("a"))
279 title
: "hide inherited properties"
282 if($
(this).hasClass("hidden")) {
283 $
(this).parent().parent().find("li.inherit").show();
285 $
(this).parent().parent().find("li.inherit").hide();
288 $
(this).toggleClass("hidden");
292 $
(document
.createElement("a"))
295 title
: "hide redefined properties"
298 if($
(this).hasClass("hidden")) {
299 $
(this).parent().parent().find("li.redef").show();
301 $
(this).parent().parent().find("li.redef").hide();
304 $
(this).toggleClass("hidden");
308 $
(document
.createElement("a"))
311 title
: "hide introduced properties"
314 if($
(this).hasClass("hidden")) {
315 $
(this).parent().parent().find("li.intro").show();
317 $
(this).parent().parent().find("li.intro").hide();
320 $
(this).toggleClass("hidden");
324 // Filter toggle between I R in
325 $
("article.properties.filterable .filter, article.classes.filterable .filter")
327 $
(document
.createElement("a"))
330 title
: "hide introduced properties"
333 if($
(this).hasClass("hidden")) {
334 $
(this).parent().parent().find("li.intro").show();
336 $
(this).parent().parent().find("li.intro").hide();
339 $
(this).toggleClass("hidden");
343 $
(document
.createElement("a"))
346 title
: "hide redefined properties"
349 if($
(this).hasClass("hidden")) {
350 $
(this).parent().parent().find("li.redef").show();
352 $
(this).parent().parent().find("li.redef").hide();
355 $
(this).toggleClass("hidden");
362 $
("a[href*='#']").click( function() {
363 highlightBlock($
(this).attr("href").split(/#
/)[1]);
366 //Preload filter fields with query string
368 // Hide Authenfication form
369 $
(".popover").hide();
370 // Display Login modal
371 $
("#logGitHub").click(function(){ displayLogginModal(); });
374 // If cookie existing the session is opened
375 if(sessionStarted
){ userB64
= "Basic " + getUserPass("logginNitdoc"); }
377 // Sign In an github user or Log out him
378 $
("#signIn").click(function(){
380 if($
('#loginGit').val() == "" || $
('#passwordGit').val() == ""){ displayMessage('The comment field is empty!', 40, 45); }
383 userName
= $
('#loginGit').val();
384 password
= $
('#passwordGit').val();
385 repoName
= $
('#repositoryGit').val();
386 branchName
= $
('#branchGit').val();
387 userB64
= "Basic " + base64
.encode(userName
+':'+password
);
388 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+repoName
+':'+branchName
), 1);
389 $
('#loginGit').val("");
390 $
('#passwordGit').val("");
395 // Delete cookie and reset settings
396 del_cookie("logginNitdoc");
398 displayLogginModal();
402 /* Parse current URL and return anchor name */
403 function currentAnchor() {
404 var index
= document
.location
.hash
.indexOf("#");
406 return document
.location
.hash
.substring(index
+ 1);
411 /* Prealod filters field using search query */
412 function preloadFilters() {
413 // Parse URL and get query string
414 var search
= currentAnchor();
416 if(search
== null || search
.indexOf("q=") == -1)
419 search
= search
.substring(2, search
.length
);
421 if(search
== "" || search
== "undefined")
424 $
(":text").val(search
);
426 .removeClass("notUsed")
431 /* Hightlight the spoted block */
432 function highlightBlock(a
) {
437 $
(".highlighted").removeClass("highlighted");
439 var target
= $
("#" + a
);
441 if(target
.is("article")) {
442 target
.parent().addClass("highlighted");
445 target
.addClass("highlighted");
449 function displayLogginModal(){
450 if ($
('.popover').is(':hidden')) { $
('.popover').show(); }
451 else { $
('.popover').hide(); }
455 function updateDisplaying(){
458 $
('#loginGit').hide();
459 $
('#passwordGit').hide();
460 $
('#lbpasswordGit').hide();
461 $
('#lbloginGit').hide();
462 $
('#repositoryGit').hide();
463 $
('#lbrepositoryGit').hide();
464 $
('#lbbranchGit').hide();
465 $
('#branchGit').hide();
466 $
("#liGitHub").attr("class", "current");
467 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
468 $
('#nickName').text(userName
);
469 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
470 $
('#logginMessage').css({'display' : 'block'});
471 $
('#logginMessage').css({'text-align' : 'center'});
472 $
('.popover').css({'height' : '80px'});
473 $
('#signIn').text("Sign out");
474 sessionStarted
= true;
478 sessionStarted
= false;
479 $
('#logginMessage').css({'display' : 'none'});
480 $
("#liGitHub").attr("class", "");
481 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
482 $
('#loginGit').val("");
483 $
('#passwordGit').val("");
484 $
('#nickName').text("");
485 $
('.popover').css({'height' : '280px'});
486 $
('#logginMessage').css({'display' : 'none'});
487 $
('#repositoryGit').val($
('#repoName').attr('name'));
488 $
('#branchGit').val('wikidoc');
489 $
('#signIn').text("Sign In");
490 $
('#loginGit').show();
491 $
('#passwordGit').show();
492 $
('#lbpasswordGit').show();
493 $
('#lbloginGit').show();
494 $
('#repositoryGit').show();
495 $
('#lbrepositoryGit').show();
496 $
('#lbbranchGit').show();
497 $
('#branchGit').show();
501 function setCookie(c_name
, value
, exdays
)
503 var exdate
=new Date();
504 exdate
.setDate(exdate
.getDate() + exdays
);
505 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
506 document
.cookie
=c_name
+ "=" + c_value
;
509 function del_cookie(c_name
)
511 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
514 function getCookie(c_name
)
516 var c_value
= document
.cookie
;
517 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
518 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
519 if (c_start
== -1) { c_value
= null; }
522 c_start
= c_value
.indexOf("=", c_start
) + 1;
523 var c_end
= c_value
.indexOf(";", c_start
);
524 if (c_end
== -1) { c_end
= c_value
.length
; }
525 c_value
= unescape(c_value
.substring(c_start
,c_end
));
530 function getUserPass(c_name
){
531 var cookie
= base64
.decode(getCookie(c_name
));
532 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
535 function checkCookie()
537 var cookie
=getCookie("logginNitdoc");
538 if (cookie
!=null && cookie
!="")
540 cookie
= base64
.decode(cookie
);
541 userName
= cookie
.split(':')[0];
542 repoName
= cookie
.split(':')[2];
543 branchName
= cookie
.split(':')[3];
546 else { return false; }
554 base64
.PADCHAR
= '=';
555 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
556 base64
.getbyte64
= function(s
,i
) {
557 // This is oddly fast, except on Chrome/V8.
558 // Minimal or no improvement in performance by using a
559 // object with properties mapping chars to value (eg. 'A': 0)
560 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
562 throw "Cannot decode base64";
567 base64
.decode
= function(s
) {
570 var getbyte64
= base64
.getbyte64
;
578 throw "Cannot decode base64";
582 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
584 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
587 // either way, we want to ignore this last block
592 for (i
= 0; i
< imax
; i
+= 4) {
593 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
594 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
595 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
600 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
601 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
604 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
605 x
.push(String
.fromCharCode(b10
>> 16));
611 base64
.getbyte
= function(s
,i
) {
612 var x
= s
.charCodeAt(i
);
614 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
620 base64
.encode
= function(s
) {
621 if (arguments
.length
!= 1) {
622 throw "SyntaxError: Not enough arguments";
624 var padchar
= base64
.PADCHAR
;
625 var alpha
= base64
.ALPHA
;
626 var getbyte
= base64
.getbyte
;
634 var imax
= s
.length
- s
.length
% 3;
639 for (i
= 0; i
< imax
; i
+= 3) {
640 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
641 x
.push(alpha
.charAt(b10
>> 18));
642 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
643 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
644 x
.push(alpha
.charAt(b10
& 0x3f));
646 switch (s
.length
- imax
) {
648 b10
= getbyte(s
,i
) << 16;
649 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
653 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
654 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
655 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
661 $
.fn
.spin
= function(opts
) {
662 this.each(function() {
670 if (opts
!== false) {
671 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);