3 var sessionStarted
= false;
7 * JQuery Case Insensitive :icontains selector
9 $
.expr
[':'].icontains
= function(obj
, index
, meta
, stack
){
10 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;
14 * Quick Search global vars
17 // Current search results preview table
18 var currentTable
= null;
20 //Hightlighted index in search result preview table
21 var currentIndex
= -1;
25 * Add folding and filtering facilities to class description page.
27 $
(document
).ready(function() {
31 $
('a[id=commitBtn]').hide();
32 $
('a[id=cancelBtn]').hide();
33 // Hide Authenfication form
39 * Highlight the spoted element
41 highlightBlock(currentAnchor());
50 $
(document
.createElement("a"))
54 .css("cursor", "pointer")
56 if($
(this).find("a.fold").html() == "+") {
57 $
(this).find("a.fold").html("-");
59 $
(this).find("a.fold").html("+");
61 $
(this).nextAll().toggle();
64 // Insert search field
67 $
(document
.createElement("li"))
69 $
(document
.createElement("form"))
71 $
(document
.createElement("input"))
76 value
: "quick search..."
84 // Select previous result on "Up"
86 // If already on first result, focus search input
87 if(currentIndex
== 0) {
88 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
90 // Else select previous result
91 } else if(currentIndex
> 0) {
92 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
94 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
95 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
100 // Select next result on "Down"
102 if(currentIndex
< currentTable
.find("tr").length
- 1) {
103 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
105 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
106 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
107 $
("#search").focus();
110 // Go to url on "Enter"
112 if(currentIndex
> -1) {
113 window
.location
= $
(currentTable
.find("tr")[currentIndex]).data("searchDetails").url
;
116 if($
("#search").val().length
== 0)
119 window
.location
= "full-index.html#q=" + $
("#search").val();
120 if(window
.location
.href
.indexOf("full-index.html") > -1) {
126 // Hide results preview on "Escape"
129 if(currentTable
!= null) {
130 currentTable
.remove();
136 if($
("#search").val().length
== 0) {
140 // Remove previous table
141 if(currentTable
!= null) {
142 currentTable
.remove();
145 // Build results table
147 currentTable
= $
(document
.createElement("table"));
149 // Escape regexp related characters in query
150 var query
= $
("#search").val();
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
, "\\(");
158 query
= query
.replace(/\
)/gi
, "\\)");
161 var regexp
= new RegExp("^" + query
, "i");
162 for(var entry
in entries
) {
166 var result
= entry
.match(regexp
);
167 if(result
!= null && result
.toString().toUpperCase() == $
("#search").val().toUpperCase()) {
168 for(var i
= 0; i
< entries
[entry].length
; i
++) {
173 $
(document
.createElement("tr"))
174 .data("searchDetails", {name
: entry
, url
: entries
[entry][i]["url"]})
175 .data("index", index
)
176 .append($
(document
.createElement("td")).html(entry
))
178 $
(document
.createElement("td"))
179 .addClass("entryInfo")
180 .html(entries
[entry][i]["txt"] + " »"))
181 .mouseover( function() {
182 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
183 $
(this).addClass("activeSearchResult");
184 currentIndex
= $
(this).data("index");
186 .mouseout( function() {
187 $
(this).removeClass("activeSearchResult");
190 window
.location
= $
(this).data("searchDetails")["url"];
198 // Initialize table properties
199 currentTable
.attr("id", "searchTable");
200 currentTable
.css("position", "absolute");
201 currentTable
.width($
("#search").outerWidth());
202 $
("header").append(currentTable
);
203 currentTable
.offset({left
: $
("#search").offset().left
+ ($
("#search").outerWidth() - currentTable
.outerWidth()), top
: $
("#search").offset().top
+ $
("#search").outerHeight()});
205 // Preselect first entry
206 if(currentTable
.find("tr").length
> 0) {
208 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
209 $
("#search").focus();
214 .focusout(function() {
215 if($
(this).val() == "") {
216 $
(this).addClass("notUsed");
217 $
(this).val("quick search...");
220 .focusin(function() {
221 if($
(this).val() == "quick search...") {
222 $
(this).removeClass("notUsed");
227 .submit( function() {
233 // Close quicksearch list on click
234 $
(document
).click(function(e
) {
235 if(e
.target
!= $
("#search")[0] && e
.target
!= $
("#searchTable")[0]) {
236 if(currentTable
!= null) {
237 currentTable
.remove();
243 // Insert filter field
244 $
("article.filterable h2, nav.filterable h3")
246 $
(document
.createElement("div"))
249 $
(document
.createElement("input"))
256 $
(this).parent().parent().find("ul li:not(:icontains('" + $
(this).val() + "'))").addClass("hide");
257 $
(this).parent().parent().find("ul li:icontains('" + $
(this).val() + "')").removeClass("hide");
259 .focusout(function() {
260 if($
(this).val() == "") {
261 $
(this).addClass("notUsed");
262 $
(this).val("filter...");
265 .focusin(function() {
266 if($
(this).val() == "filter...") {
267 $
(this).removeClass("notUsed");
274 // Filter toggle between H I R in nav porperties list
275 $
("nav.properties.filterable .filter")
277 $
(document
.createElement("a"))
280 title
: "hide inherited properties"
283 if($
(this).hasClass("hidden")) {
284 $
(this).parent().parent().find("li.inherit").show();
286 $
(this).parent().parent().find("li.inherit").hide();
289 $
(this).toggleClass("hidden");
293 $
(document
.createElement("a"))
296 title
: "hide redefined properties"
299 if($
(this).hasClass("hidden")) {
300 $
(this).parent().parent().find("li.redef").show();
302 $
(this).parent().parent().find("li.redef").hide();
305 $
(this).toggleClass("hidden");
309 $
(document
.createElement("a"))
312 title
: "hide introduced properties"
315 if($
(this).hasClass("hidden")) {
316 $
(this).parent().parent().find("li.intro").show();
318 $
(this).parent().parent().find("li.intro").hide();
321 $
(this).toggleClass("hidden");
325 // Filter toggle between I R in
326 $
("article.properties.filterable .filter, article.classes.filterable .filter")
328 $
(document
.createElement("a"))
331 title
: "hide introduced properties"
334 if($
(this).hasClass("hidden")) {
335 $
(this).parent().parent().find("li.intro").show();
337 $
(this).parent().parent().find("li.intro").hide();
340 $
(this).toggleClass("hidden");
344 $
(document
.createElement("a"))
347 title
: "hide redefined properties"
350 if($
(this).hasClass("hidden")) {
351 $
(this).parent().parent().find("li.redef").show();
353 $
(this).parent().parent().find("li.redef").hide();
356 $
(this).toggleClass("hidden");
363 $
("a[href*='#']").click( function() {
364 highlightBlock($
(this).attr("href").split(/#
/)[1]);
367 //Preload filter fields with query string
369 // Hide Authenfication form
370 $
(".popover").hide();
371 // Display Login modal
372 $
("#logGitHub").click(function(){ displayLogginModal(); });
375 // If cookie existing the session is opened
376 if(sessionStarted
){ userB64
= "Basic " + getUserPass("logginNitdoc"); }
378 // Sign In an github user or Log out him
379 $
("#signIn").click(function(){
381 if($
('#loginGit').val() == "" || $
('#passwordGit').val() == ""){ displayMessage('The comment field is empty!', 40, 45); }
384 userName
= $
('#loginGit').val();
385 password
= $
('#passwordGit').val();
386 repoName
= $
('#repositoryGit').val();
387 branchName
= $
('#branchGit').val();
388 userB64
= "Basic " + base64
.encode(userName
+':'+password
);
389 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+repoName
+':'+branchName
), 1);
390 $
('#loginGit').val("");
391 $
('#passwordGit').val("");
396 // Delete cookie and reset settings
397 del_cookie("logginNitdoc");
399 displayLogginModal();
403 $
('pre[class=text_label]').click(function(){
404 // the customer is loggued ?
405 if(!sessionStarted || userName
== ""){
406 // No => nothing happen
410 var arrayNew
= $
(this).text().split('\n');
411 var lNew
= arrayNew
.length
- 1;
414 for (var i
= 0; i
< lNew
; i
++) {
415 adapt
+= arrayNew
[i];
416 if(i
< lNew
-1){ adapt
+= "\n"; }
422 $
(this).next().show();
423 // Show cancel button
424 $
(this).next().next().show();
425 // Show commit button
426 $
(this).next().next().next().show();
427 // Add text in edit box
428 if($
(this).next().val() == ""){ $
(this).next().val(adapt
); }
430 $
(this).next().height($
(this).next().prop("scrollHeight"));
432 $
(this).next().select();
433 preElement
= $
(this);
437 $
('a[id=cancelBtn]').click(function(){
438 if(editComment
> 0){ editComment
-= 1; }
442 $
(this).next().hide();
444 $
(this).prev().hide();
446 $
(this).prev().prev().show();
451 /* Parse current URL and return anchor name */
452 function currentAnchor() {
453 var index
= document
.location
.hash
.indexOf("#");
455 return document
.location
.hash
.substring(index
+ 1);
460 /* Prealod filters field using search query */
461 function preloadFilters() {
462 // Parse URL and get query string
463 var search
= currentAnchor();
465 if(search
== null || search
.indexOf("q=") == -1)
468 search
= search
.substring(2, search
.length
);
470 if(search
== "" || search
== "undefined")
473 $
(":text").val(search
);
475 .removeClass("notUsed")
480 /* Hightlight the spoted block */
481 function highlightBlock(a
) {
486 $
(".highlighted").removeClass("highlighted");
488 var target
= $
("#" + a
);
490 if(target
.is("article")) {
491 target
.parent().addClass("highlighted");
494 target
.addClass("highlighted");
498 function displayLogginModal(){
499 if ($
('.popover').is(':hidden')) { $
('.popover').show(); }
500 else { $
('.popover').hide(); }
504 function updateDisplaying(){
507 $
('#loginGit').hide();
508 $
('#passwordGit').hide();
509 $
('#lbpasswordGit').hide();
510 $
('#lbloginGit').hide();
511 $
('#repositoryGit').hide();
512 $
('#lbrepositoryGit').hide();
513 $
('#lbbranchGit').hide();
514 $
('#branchGit').hide();
515 $
("#liGitHub").attr("class", "current");
516 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
517 $
('#nickName').text(userName
);
518 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
519 $
('#logginMessage').css({'display' : 'block'});
520 $
('#logginMessage').css({'text-align' : 'center'});
521 $
('.popover').css({'height' : '80px'});
522 $
('#signIn').text("Sign out");
523 sessionStarted
= true;
527 sessionStarted
= false;
528 $
('#logginMessage').css({'display' : 'none'});
529 $
("#liGitHub").attr("class", "");
530 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
531 $
('#loginGit').val("");
532 $
('#passwordGit').val("");
533 $
('#nickName').text("");
534 $
('.popover').css({'height' : '280px'});
535 $
('#logginMessage').css({'display' : 'none'});
536 $
('#repositoryGit').val($
('#repoName').attr('name'));
537 $
('#branchGit').val('wikidoc');
538 $
('#signIn').text("Sign In");
539 $
('#loginGit').show();
540 $
('#passwordGit').show();
541 $
('#lbpasswordGit').show();
542 $
('#lbloginGit').show();
543 $
('#repositoryGit').show();
544 $
('#lbrepositoryGit').show();
545 $
('#lbbranchGit').show();
546 $
('#branchGit').show();
550 function setCookie(c_name
, value
, exdays
)
552 var exdate
=new Date();
553 exdate
.setDate(exdate
.getDate() + exdays
);
554 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
555 document
.cookie
=c_name
+ "=" + c_value
;
558 function del_cookie(c_name
)
560 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
563 function getCookie(c_name
)
565 var c_value
= document
.cookie
;
566 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
567 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
568 if (c_start
== -1) { c_value
= null; }
571 c_start
= c_value
.indexOf("=", c_start
) + 1;
572 var c_end
= c_value
.indexOf(";", c_start
);
573 if (c_end
== -1) { c_end
= c_value
.length
; }
574 c_value
= unescape(c_value
.substring(c_start
,c_end
));
579 function getUserPass(c_name
){
580 var cookie
= base64
.decode(getCookie(c_name
));
581 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
584 function checkCookie()
586 var cookie
=getCookie("logginNitdoc");
587 if (cookie
!=null && cookie
!="")
589 cookie
= base64
.decode(cookie
);
590 userName
= cookie
.split(':')[0];
591 repoName
= cookie
.split(':')[2];
592 branchName
= cookie
.split(':')[3];
595 else { return false; }
603 base64
.PADCHAR
= '=';
604 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
605 base64
.getbyte64
= function(s
,i
) {
606 // This is oddly fast, except on Chrome/V8.
607 // Minimal or no improvement in performance by using a
608 // object with properties mapping chars to value (eg. 'A': 0)
609 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
611 throw "Cannot decode base64";
616 base64
.decode
= function(s
) {
619 var getbyte64
= base64
.getbyte64
;
627 throw "Cannot decode base64";
631 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
633 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
636 // either way, we want to ignore this last block
641 for (i
= 0; i
< imax
; i
+= 4) {
642 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
643 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
644 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
649 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
650 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
653 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
654 x
.push(String
.fromCharCode(b10
>> 16));
660 base64
.getbyte
= function(s
,i
) {
661 var x
= s
.charCodeAt(i
);
663 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
669 base64
.encode
= function(s
) {
670 if (arguments
.length
!= 1) {
671 throw "SyntaxError: Not enough arguments";
673 var padchar
= base64
.PADCHAR
;
674 var alpha
= base64
.ALPHA
;
675 var getbyte
= base64
.getbyte
;
683 var imax
= s
.length
- s
.length
% 3;
688 for (i
= 0; i
< imax
; i
+= 3) {
689 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
690 x
.push(alpha
.charAt(b10
>> 18));
691 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
692 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
693 x
.push(alpha
.charAt(b10
& 0x3f));
695 switch (s
.length
- imax
) {
697 b10
= getbyte(s
,i
) << 16;
698 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
702 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
703 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
704 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
710 $
.fn
.spin
= function(opts
) {
711 this.each(function() {
719 if (opts
!== false) {
720 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);