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() {
29 * Highlight the spoted element
31 highlightBlock(currentAnchor());
40 $
(document
.createElement("a"))
44 .css("cursor", "pointer")
46 if($
(this).find("a.fold").html() == "+") {
47 $
(this).find("a.fold").html("-");
49 $
(this).find("a.fold").html("+");
51 $
(this).nextAll().toggle();
54 // Insert search field
57 $
(document
.createElement("li"))
59 $
(document
.createElement("form"))
61 $
(document
.createElement("input"))
66 value
: "quick search..."
74 // Select previous result on "Up"
76 // If already on first result, focus search input
77 if(currentIndex
== 0) {
78 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
80 // Else select previous result
81 } else if(currentIndex
> 0) {
82 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
84 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
85 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
90 // Select next result on "Down"
92 if(currentIndex
< currentTable
.find("tr").length
- 1) {
93 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
95 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
96 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
100 // Go to url on "Enter"
102 if(currentIndex
> -1) {
103 window
.location
= $
(currentTable
.find("tr")[currentIndex]).data("searchDetails").url
;
106 if($
("#search").val().length
== 0)
109 window
.location
= "full-index.html#q=" + $
("#search").val();
110 if(window
.location
.href
.indexOf("full-index.html") > -1) {
116 // Hide results preview on "Escape"
119 if(currentTable
!= null) {
120 currentTable
.remove();
126 if($
("#search").val().length
== 0) {
130 // Remove previous table
131 if(currentTable
!= null) {
132 currentTable
.remove();
135 // Build results table
137 currentTable
= $
(document
.createElement("table"));
139 // Escape regexp related characters in query
140 var query
= $
("#search").val();
141 query
= query
.replace(/\
[/gi
, "\\[");
142 query
= query
.replace(/\|
/gi
, "\\|");
143 query
= query
.replace(/\*/gi
, "\\*");
144 query
= query
.replace(/\
+/gi
, "\\+");
145 query
= query
.replace(/\\/gi
, "\\\\");
146 query
= query
.replace(/\?/gi
, "\\?");
147 query
= query
.replace(/\
(/gi
, "\\(");
148 query
= query
.replace(/\
)/gi
, "\\)");
151 var regexp
= new RegExp("^" + query
, "i");
152 for(var entry
in entries
) {
156 var result
= entry
.match(regexp
);
157 if(result
!= null && result
.toString().toUpperCase() == $
("#search").val().toUpperCase()) {
158 for(var i
= 0; i
< entries
[entry].length
; i
++) {
163 $
(document
.createElement("tr"))
164 .data("searchDetails", {name
: entry
, url
: entries
[entry][i]["url"]})
165 .data("index", index
)
166 .append($
(document
.createElement("td")).html(entry
))
168 $
(document
.createElement("td"))
169 .addClass("entryInfo")
170 .html(entries
[entry][i]["txt"] + " »"))
171 .mouseover( function() {
172 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
173 $
(this).addClass("activeSearchResult");
174 currentIndex
= $
(this).data("index");
176 .mouseout( function() {
177 $
(this).removeClass("activeSearchResult");
180 window
.location
= $
(this).data("searchDetails")["url"];
188 // Initialize table properties
189 currentTable
.attr("id", "searchTable");
190 currentTable
.css("position", "absolute");
191 currentTable
.width($
("#search").outerWidth());
192 $
("header").append(currentTable
);
193 currentTable
.offset({left
: $
("#search").offset().left
+ ($
("#search").outerWidth() - currentTable
.outerWidth()), top
: $
("#search").offset().top
+ $
("#search").outerHeight()});
195 // Preselect first entry
196 if(currentTable
.find("tr").length
> 0) {
198 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
199 $
("#search").focus();
204 .focusout(function() {
205 if($
(this).val() == "") {
206 $
(this).addClass("notUsed");
207 $
(this).val("quick search...");
210 .focusin(function() {
211 if($
(this).val() == "quick search...") {
212 $
(this).removeClass("notUsed");
217 .submit( function() {
223 // Close quicksearch list on click
224 $
(document
).click(function(e
) {
225 if(e
.target
!= $
("#search")[0] && e
.target
!= $
("#searchTable")[0]) {
226 if(currentTable
!= null) {
227 currentTable
.remove();
233 // Insert filter field
234 $
("article.filterable h2, nav.filterable h3")
236 $
(document
.createElement("div"))
239 $
(document
.createElement("input"))
246 $
(this).parent().parent().find("ul li:not(:icontains('" + $
(this).val() + "'))").addClass("hide");
247 $
(this).parent().parent().find("ul li:icontains('" + $
(this).val() + "')").removeClass("hide");
249 .focusout(function() {
250 if($
(this).val() == "") {
251 $
(this).addClass("notUsed");
252 $
(this).val("filter...");
255 .focusin(function() {
256 if($
(this).val() == "filter...") {
257 $
(this).removeClass("notUsed");
264 // Filter toggle between H I R in nav porperties list
265 $
("nav.properties.filterable .filter")
267 $
(document
.createElement("a"))
270 title
: "hide inherited properties"
273 if($
(this).hasClass("hidden")) {
274 $
(this).parent().parent().find("li.inherit").show();
276 $
(this).parent().parent().find("li.inherit").hide();
279 $
(this).toggleClass("hidden");
283 $
(document
.createElement("a"))
286 title
: "hide redefined properties"
289 if($
(this).hasClass("hidden")) {
290 $
(this).parent().parent().find("li.redef").show();
292 $
(this).parent().parent().find("li.redef").hide();
295 $
(this).toggleClass("hidden");
299 $
(document
.createElement("a"))
302 title
: "hide introduced properties"
305 if($
(this).hasClass("hidden")) {
306 $
(this).parent().parent().find("li.intro").show();
308 $
(this).parent().parent().find("li.intro").hide();
311 $
(this).toggleClass("hidden");
315 // Filter toggle between I R in
316 $
("article.properties.filterable .filter, article.classes.filterable .filter")
318 $
(document
.createElement("a"))
321 title
: "hide introduced properties"
324 if($
(this).hasClass("hidden")) {
325 $
(this).parent().parent().find("li.intro").show();
327 $
(this).parent().parent().find("li.intro").hide();
330 $
(this).toggleClass("hidden");
334 $
(document
.createElement("a"))
337 title
: "hide redefined properties"
340 if($
(this).hasClass("hidden")) {
341 $
(this).parent().parent().find("li.redef").show();
343 $
(this).parent().parent().find("li.redef").hide();
346 $
(this).toggleClass("hidden");
353 $
("a[href*='#']").click( function() {
354 highlightBlock($
(this).attr("href").split(/#
/)[1]);
357 //Preload filter fields with query string
359 // Hide Authenfication form
360 $
(".popover").hide();
361 // Display Login modal
362 $
("#logGitHub").click(function(){ displayLogginModal(); });
365 // If cookie existing the session is opened
366 if(sessionStarted
){ userB64
= "Basic " + getUserPass("logginNitdoc"); }
368 // Sign In an github user or Log out him
369 $
("#signIn").click(function(){
371 if($
('#loginGit').val() == "" || $
('#passwordGit').val() == ""){ displayMessage('The comment field is empty!', 40, 45); }
374 userName
= $
('#loginGit').val();
375 password
= $
('#passwordGit').val();
376 repoName
= $
('#repositoryGit').val();
377 branchName
= $
('#branchGit').val();
378 userB64
= "Basic " + base64
.encode(userName
+':'+password
);
379 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+repoName
+':'+branchName
), 1);
380 $
('#loginGit').val("");
381 $
('#passwordGit').val("");
386 // Delete cookie and reset settings
387 del_cookie("logginNitdoc");
389 displayLogginModal();
393 /* Parse current URL and return anchor name */
394 function currentAnchor() {
395 var index
= document
.location
.hash
.indexOf("#");
397 return document
.location
.hash
.substring(index
+ 1);
402 /* Prealod filters field using search query */
403 function preloadFilters() {
404 // Parse URL and get query string
405 var search
= currentAnchor();
407 if(search
== null || search
.indexOf("q=") == -1)
410 search
= search
.substring(2, search
.length
);
412 if(search
== "" || search
== "undefined")
415 $
(":text").val(search
);
417 .removeClass("notUsed")
422 /* Hightlight the spoted block */
423 function highlightBlock(a
) {
428 $
(".highlighted").removeClass("highlighted");
430 var target
= $
("#" + a
);
432 if(target
.is("article")) {
433 target
.parent().addClass("highlighted");
436 target
.addClass("highlighted");
440 function displayLogginModal(){
441 if ($
('.popover').is(':hidden')) { $
('.popover').show(); }
442 else { $
('.popover').hide(); }
446 function updateDisplaying(){
449 $
('#loginGit').hide();
450 $
('#passwordGit').hide();
451 $
('#lbpasswordGit').hide();
452 $
('#lbloginGit').hide();
453 $
('#repositoryGit').hide();
454 $
('#lbrepositoryGit').hide();
455 $
('#lbbranchGit').hide();
456 $
('#branchGit').hide();
457 $
("#liGitHub").attr("class", "current");
458 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
459 $
('#nickName').text(userName
);
460 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
461 $
('#logginMessage').css({'display' : 'block'});
462 $
('#logginMessage').css({'text-align' : 'center'});
463 $
('.popover').css({'height' : '80px'});
464 $
('#signIn').text("Sign out");
465 sessionStarted
= true;
469 sessionStarted
= false;
470 $
('#logginMessage').css({'display' : 'none'});
471 $
("#liGitHub").attr("class", "");
472 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
473 $
('#loginGit').val("");
474 $
('#passwordGit').val("");
475 $
('#nickName').text("");
476 $
('.popover').css({'height' : '280px'});
477 $
('#logginMessage').css({'display' : 'none'});
478 $
('#repositoryGit').val($
('#repoName').attr('name'));
479 $
('#branchGit').val('wikidoc');
480 $
('#signIn').text("Sign In");
481 $
('#loginGit').show();
482 $
('#passwordGit').show();
483 $
('#lbpasswordGit').show();
484 $
('#lbloginGit').show();
485 $
('#repositoryGit').show();
486 $
('#lbrepositoryGit').show();
487 $
('#lbbranchGit').show();
488 $
('#branchGit').show();
492 function setCookie(c_name
, value
, exdays
)
494 var exdate
=new Date();
495 exdate
.setDate(exdate
.getDate() + exdays
);
496 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
497 document
.cookie
=c_name
+ "=" + c_value
;
500 function del_cookie(c_name
)
502 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
505 function getCookie(c_name
)
507 var c_value
= document
.cookie
;
508 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
509 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
510 if (c_start
== -1) { c_value
= null; }
513 c_start
= c_value
.indexOf("=", c_start
) + 1;
514 var c_end
= c_value
.indexOf(";", c_start
);
515 if (c_end
== -1) { c_end
= c_value
.length
; }
516 c_value
= unescape(c_value
.substring(c_start
,c_end
));
521 function getUserPass(c_name
){
522 var cookie
= base64
.decode(getCookie(c_name
));
523 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
526 function checkCookie()
528 var cookie
=getCookie("logginNitdoc");
529 if (cookie
!=null && cookie
!="")
531 cookie
= base64
.decode(cookie
);
532 userName
= cookie
.split(':')[0];
533 repoName
= cookie
.split(':')[2];
534 branchName
= cookie
.split(':')[3];
537 else { return false; }
545 base64
.PADCHAR
= '=';
546 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
547 base64
.getbyte64
= function(s
,i
) {
548 // This is oddly fast, except on Chrome/V8.
549 // Minimal or no improvement in performance by using a
550 // object with properties mapping chars to value (eg. 'A': 0)
551 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
553 throw "Cannot decode base64";
558 base64
.decode
= function(s
) {
561 var getbyte64
= base64
.getbyte64
;
569 throw "Cannot decode base64";
573 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
575 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
578 // either way, we want to ignore this last block
583 for (i
= 0; i
< imax
; i
+= 4) {
584 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
585 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
586 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
591 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
592 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
595 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
596 x
.push(String
.fromCharCode(b10
>> 16));
602 base64
.getbyte
= function(s
,i
) {
603 var x
= s
.charCodeAt(i
);
605 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
611 base64
.encode
= function(s
) {
612 if (arguments
.length
!= 1) {
613 throw "SyntaxError: Not enough arguments";
615 var padchar
= base64
.PADCHAR
;
616 var alpha
= base64
.ALPHA
;
617 var getbyte
= base64
.getbyte
;
625 var imax
= s
.length
- s
.length
% 3;
630 for (i
= 0; i
< imax
; i
+= 3) {
631 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
632 x
.push(alpha
.charAt(b10
>> 18));
633 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
634 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
635 x
.push(alpha
.charAt(b10
& 0x3f));
637 switch (s
.length
- imax
) {
639 b10
= getbyte(s
,i
) << 16;
640 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
644 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
645 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
646 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
652 $
.fn
.spin
= function(opts
) {
653 this.each(function() {
661 if (opts
!== false) {
662 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);