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();
402 // Activate edit mode
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 // Disable the edit mode
438 $
('a[id=cancelBtn]').click(function(){
439 if(editComment
> 0){ editComment
-= 1; }
443 $
(this).next().hide();
445 $
(this).prev().hide();
447 $
(this).prev().prev().show();
450 // Display commit form
451 $
('a[id=commitBtn]').click(function(){
452 updateComment
= $
(this).prev().prev().val();
453 commentType
= $
(this).prev().prev().prev().attr('type');
455 if(updateComment
== ""){ displayMessage('The comment field is empty!', 40, 45); }
458 displayMessage("You need to be loggued before commit something", 45, 40);
459 displayLogginModal();
462 $
('#commitMessage').val('New commit');
463 pathFile
= $
(this).prev().prev().prev().attr('tag');
464 $
('#modal').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btn_close" title="Close" alt="Close" /></a>');
465 $
('body').append('<div id="fade"></div>');
466 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
471 $
('.btn_close').click(function(){
473 $
(this).next().hide();
474 if(editComment
> 0){ editComment
-= 1; }
477 //Close Popups and Fade Layer
478 $
('body').on('click', 'a.close, #fade', function() {
479 if(editComment
> 0){ editComment
-= 1; }
480 $
('#fade , #modal').fadeOut(function() {
481 $
('#fade, a.close').remove();
483 $
('#modalQuestion').hide();
488 /* Parse current URL and return anchor name */
489 function currentAnchor() {
490 var index
= document
.location
.hash
.indexOf("#");
492 return document
.location
.hash
.substring(index
+ 1);
497 /* Prealod filters field using search query */
498 function preloadFilters() {
499 // Parse URL and get query string
500 var search
= currentAnchor();
502 if(search
== null || search
.indexOf("q=") == -1)
505 search
= search
.substring(2, search
.length
);
507 if(search
== "" || search
== "undefined")
510 $
(":text").val(search
);
512 .removeClass("notUsed")
517 /* Hightlight the spoted block */
518 function highlightBlock(a
) {
523 $
(".highlighted").removeClass("highlighted");
525 var target
= $
("#" + a
);
527 if(target
.is("article")) {
528 target
.parent().addClass("highlighted");
531 target
.addClass("highlighted");
535 function displayLogginModal(){
536 if ($
('.popover').is(':hidden')) { $
('.popover').show(); }
537 else { $
('.popover').hide(); }
541 function updateDisplaying(){
544 $
('#loginGit').hide();
545 $
('#passwordGit').hide();
546 $
('#lbpasswordGit').hide();
547 $
('#lbloginGit').hide();
548 $
('#repositoryGit').hide();
549 $
('#lbrepositoryGit').hide();
550 $
('#lbbranchGit').hide();
551 $
('#branchGit').hide();
552 $
("#liGitHub").attr("class", "current");
553 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
554 $
('#nickName').text(userName
);
555 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
556 $
('#logginMessage').css({'display' : 'block'});
557 $
('#logginMessage').css({'text-align' : 'center'});
558 $
('.popover').css({'height' : '80px'});
559 $
('#signIn').text("Sign out");
560 sessionStarted
= true;
564 sessionStarted
= false;
565 $
('#logginMessage').css({'display' : 'none'});
566 $
("#liGitHub").attr("class", "");
567 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
568 $
('#loginGit').val("");
569 $
('#passwordGit').val("");
570 $
('#nickName').text("");
571 $
('.popover').css({'height' : '280px'});
572 $
('#logginMessage').css({'display' : 'none'});
573 $
('#repositoryGit').val($
('#repoName').attr('name'));
574 $
('#branchGit').val('wikidoc');
575 $
('#signIn').text("Sign In");
576 $
('#loginGit').show();
577 $
('#passwordGit').show();
578 $
('#lbpasswordGit').show();
579 $
('#lbloginGit').show();
580 $
('#repositoryGit').show();
581 $
('#lbrepositoryGit').show();
582 $
('#lbbranchGit').show();
583 $
('#branchGit').show();
587 function setCookie(c_name
, value
, exdays
)
589 var exdate
=new Date();
590 exdate
.setDate(exdate
.getDate() + exdays
);
591 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
592 document
.cookie
=c_name
+ "=" + c_value
;
595 function del_cookie(c_name
)
597 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
600 function getCookie(c_name
)
602 var c_value
= document
.cookie
;
603 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
604 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
605 if (c_start
== -1) { c_value
= null; }
608 c_start
= c_value
.indexOf("=", c_start
) + 1;
609 var c_end
= c_value
.indexOf(";", c_start
);
610 if (c_end
== -1) { c_end
= c_value
.length
; }
611 c_value
= unescape(c_value
.substring(c_start
,c_end
));
616 function getUserPass(c_name
){
617 var cookie
= base64
.decode(getCookie(c_name
));
618 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
621 function checkCookie()
623 var cookie
=getCookie("logginNitdoc");
624 if (cookie
!=null && cookie
!="")
626 cookie
= base64
.decode(cookie
);
627 userName
= cookie
.split(':')[0];
628 repoName
= cookie
.split(':')[2];
629 branchName
= cookie
.split(':')[3];
632 else { return false; }
640 base64
.PADCHAR
= '=';
641 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
642 base64
.getbyte64
= function(s
,i
) {
643 // This is oddly fast, except on Chrome/V8.
644 // Minimal or no improvement in performance by using a
645 // object with properties mapping chars to value (eg. 'A': 0)
646 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
648 throw "Cannot decode base64";
653 base64
.decode
= function(s
) {
656 var getbyte64
= base64
.getbyte64
;
664 throw "Cannot decode base64";
668 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
670 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
673 // either way, we want to ignore this last block
678 for (i
= 0; i
< imax
; i
+= 4) {
679 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
680 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
681 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
686 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
687 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
690 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
691 x
.push(String
.fromCharCode(b10
>> 16));
697 base64
.getbyte
= function(s
,i
) {
698 var x
= s
.charCodeAt(i
);
700 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
706 base64
.encode
= function(s
) {
707 if (arguments
.length
!= 1) {
708 throw "SyntaxError: Not enough arguments";
710 var padchar
= base64
.PADCHAR
;
711 var alpha
= base64
.ALPHA
;
712 var getbyte
= base64
.getbyte
;
720 var imax
= s
.length
- s
.length
% 3;
725 for (i
= 0; i
< imax
; i
+= 3) {
726 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
727 x
.push(alpha
.charAt(b10
>> 18));
728 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
729 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
730 x
.push(alpha
.charAt(b10
& 0x3f));
732 switch (s
.length
- imax
) {
734 b10
= getbyte(s
,i
) << 16;
735 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
739 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
740 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
741 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
747 $
.fn
.spin
= function(opts
) {
748 this.each(function() {
756 if (opts
!== false) {
757 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);