5 var sessionStarted
= false;
7 var currentfileContent
= '';
8 var originalFileContent
= '';
9 var addNewComment
= false;
14 var shaLastCommit
= "";
20 var repoExist
= false;
21 var branchExist
= false;
23 var loginProcess
= false;
26 var commitMessage
= '';
28 var showcomment
= false;
32 lines
: 11, // The number of lines to draw
33 length
: 7, // The length of each line
34 width
: 4, // The line thickness
35 radius
: 10, // The radius of the inner circle
36 corners
: 1, // Corner roundness (0..1)
37 rotate
: 0, // The rotation offset
38 color
: '#FFF', // #rgb or #rrggbb
39 speed
: 1, // Rounds per second
40 trail
: 60, // Afterglow percentage
41 shadow
: false, // Whether to render a shadow
42 hwaccel
: false, // Whether to use hardware acceleration
43 className
: 'spinner', // The CSS class to assign to the spinner
44 zIndex
: 99999, // The z-index (defaults to 2000000000)
45 top
: '300', // Top position relative to parent in px
46 left
: 'auto' // Left position relative to parent in px
48 var targetSpinner
= document
.getElementById('waitCommit');
49 var spinner
= new Spinner(opts
).spin(targetSpinner
);
52 * JQuery Case Insensitive :icontains selector
54 $
.expr
[':'].icontains
= function(obj
, index
, meta
, stack
){
55 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;
59 * Quick Search global vars
62 // Current search results preview table
63 var currentTable
= null;
65 //Hightlighted index in search result preview table
66 var currentIndex
= -1;
68 // Check if a comment is editing
69 window
.onbeforeunload
= function() {
71 return 'Are you sure you want to leave this page?';
76 * Add folding and filtering facilities to class description page.
78 $
(document
).ready(function() {
82 $
('a[id=commitBtn]').hide();
83 $
('a[id=cancelBtn]').hide();
84 // Hide Authenfication form
89 * Highlight the spoted element
91 highlightBlock(currentAnchor());
100 $
(document
.createElement("a"))
104 .css("cursor", "pointer")
106 if($
(this).find("a.fold").html() == "+") {
107 $
(this).find("a.fold").html("-");
109 $
(this).find("a.fold").html("+");
111 $
(this).nextAll().toggle();
114 // Insert search field
117 $
(document
.createElement("li"))
119 $
(document
.createElement("form"))
121 $
(document
.createElement("input"))
126 value
: "quick search..."
134 // Select previous result on "Up"
136 // If already on first result, focus search input
137 if(currentIndex
== 0) {
138 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
139 $
("#search").focus();
140 // Else select previous result
141 } else if(currentIndex
> 0) {
142 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
144 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
145 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
146 $
("#search").focus();
150 // Select next result on "Down"
152 if(currentIndex
< currentTable
.find("tr").length
- 1) {
153 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
155 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
156 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
157 $
("#search").focus();
160 // Go to url on "Enter"
162 if(currentIndex
> -1) {
163 window
.location
= $
(currentTable
.find("tr")[currentIndex]).data("searchDetails").url
;
166 if($
("#search").val().length
== 0)
169 window
.location
= "full-index.html#q=" + $
("#search").val();
170 if(window
.location
.href
.indexOf("full-index.html") > -1) {
176 // Hide results preview on "Escape"
179 if(currentTable
!= null) {
180 currentTable
.remove();
186 if($
("#search").val().length
== 0) {
190 // Remove previous table
191 if(currentTable
!= null) {
192 currentTable
.remove();
195 // Build results table
197 currentTable
= $
(document
.createElement("table"));
199 // Escape regexp related characters in query
200 var query
= $
("#search").val();
201 query
= query
.replace(/\\/gi
, "\\\\");
202 query
= query
.replace(/\
[/gi
, "\\[");
203 query
= query
.replace(/\|
/gi
, "\\|");
204 query
= query
.replace(/\*/gi
, "\\*");
205 query
= query
.replace(/\
+/gi
, "\\+");
206 query
= query
.replace(/\?/gi
, "\\?");
207 query
= query
.replace(/\
(/gi
, "\\(");
208 query
= query
.replace(/\
)/gi
, "\\)");
209 query
= query
.replace(/&/gi
, "&&");
210 query
= query
.replace(/>/gi
, ">");
211 query
= query
.replace(/</gi
, "<");
214 var regexp
= new RegExp("^" + query
, "i");
215 for(var entry
in entries
) {
219 var result
= entry
.match(regexp
);
221 for(var i
= 0; i
< entries
[entry].length
; i
++) {
226 $
(document
.createElement("tr"))
227 .data("searchDetails", {name
: entry
, url
: entries
[entry][i]["url"]})
228 .data("index", index
)
229 .append($
(document
.createElement("td")).html(entry
))
231 $
(document
.createElement("td"))
232 .addClass("entryInfo")
233 .html(entries
[entry][i]["txt"] + " »"))
234 .mouseover( function() {
235 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
236 $
(this).addClass("activeSearchResult");
237 currentIndex
= $
(this).data("index");
239 .mouseout( function() {
240 $
(this).removeClass("activeSearchResult");
243 window
.location
= $
(this).data("searchDetails")["url"];
251 // Initialize table properties
252 currentTable
.attr("id", "searchTable");
253 currentTable
.css("position", "absolute");
254 currentTable
.width($
("#search").outerWidth());
255 $
("header").append(currentTable
);
256 currentTable
.offset({left
: $
("#search").offset().left
+ ($
("#search").outerWidth() - currentTable
.outerWidth()), top
: $
("#search").offset().top
+ $
("#search").outerHeight()});
258 // Preselect first entry
259 if(currentTable
.find("tr").length
> 0) {
261 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
262 $
("#search").focus();
267 .focusout(function() {
268 if($
(this).val() == "") {
269 $
(this).addClass("notUsed");
270 $
(this).val("quick search...");
273 .focusin(function() {
274 if($
(this).val() == "quick search...") {
275 $
(this).removeClass("notUsed");
280 .submit( function() {
286 // Close quicksearch list on click
287 $
(document
).click(function(e
) {
288 if(e
.target
!= $
("#search")[0] && e
.target
!= $
("#searchTable")[0]) {
289 if(currentTable
!= null) {
290 currentTable
.remove();
296 // Insert filter field
297 $
("article.filterable h2, nav.filterable h3")
299 $
(document
.createElement("div"))
302 $
(document
.createElement("input"))
309 $
(this).parent().parent().find("ul li:not(:icontains('" + $
(this).val() + "'))").addClass("hide");
310 $
(this).parent().parent().find("ul li:icontains('" + $
(this).val() + "')").removeClass("hide");
312 .focusout(function() {
313 if($
(this).val() == "") {
314 $
(this).addClass("notUsed");
315 $
(this).val("filter...");
318 .focusin(function() {
319 if($
(this).val() == "filter...") {
320 $
(this).removeClass("notUsed");
327 // Filter toggle between H I R in nav porperties list
328 $
("nav.properties.filterable .filter")
330 $
(document
.createElement("a"))
333 title
: "hide inherited properties"
336 if($
(this).hasClass("hidden")) {
337 $
(this).parent().parent().find("li.inherit").show();
339 $
(this).parent().parent().find("li.inherit").hide();
342 $
(this).toggleClass("hidden");
346 $
(document
.createElement("a"))
349 title
: "hide redefined properties"
352 if($
(this).hasClass("hidden")) {
353 $
(this).parent().parent().find("li.redef").show();
355 $
(this).parent().parent().find("li.redef").hide();
358 $
(this).toggleClass("hidden");
362 $
(document
.createElement("a"))
365 title
: "hide introduced properties"
368 if($
(this).hasClass("hidden")) {
369 $
(this).parent().parent().find("li.intro").show();
371 $
(this).parent().parent().find("li.intro").hide();
374 $
(this).toggleClass("hidden");
378 // Filter toggle between I R in
379 $
("article.properties.filterable .filter, article.classes.filterable .filter")
381 $
(document
.createElement("a"))
384 title
: "hide introduced properties"
387 if($
(this).hasClass("hidden")) {
388 $
(this).parent().parent().find("li.intro").show();
390 $
(this).parent().parent().find("li.intro").hide();
393 $
(this).toggleClass("hidden");
397 $
(document
.createElement("a"))
400 title
: "hide redefined properties"
403 if($
(this).hasClass("hidden")) {
404 $
(this).parent().parent().find("li.redef").show();
406 $
(this).parent().parent().find("li.redef").hide();
409 $
(this).toggleClass("hidden");
416 $
("a[href*='#']").click( function() {
417 highlightBlock($
(this).attr("href").split(/#
/)[1]);
420 //Preload filter fields with query string
422 // Hide Authenfication form
423 $
(".popover").hide();
424 // Display Login modal
425 $
("#logGitHub").click(function(){ displayLogginModal(); });
428 // If cookie existing the session is opened
429 if(sessionStarted
){ userB64
= "Basic " + getUserPass("logginNitdoc"); }
431 // Sign In an github user or Log out him
432 $
("#signIn").click(function(){
434 if($
('#loginGit').val() == "" || $
('#passwordGit').val() == ""){ displayMessage('Please informed login/password field!', 40, 45); }
437 userName
= $
('#loginGit').val();
438 password
= $
('#passwordGit').val();
439 githubRepo
= $
('#repositoryGit').val();
440 branchName
= $
('#branchGit').val();
441 userB64
= "Basic " + base64
.encode(userName
+':'+password
);
443 // Check if repo exist
446 $
.when(isBranchExisting()).done(function(){
449 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+githubRepo
+':'+branchName
), 1);
450 $
('#loginGit').val("");
451 $
('#passwordGit').val("");
461 // Delete cookie and reset settings
462 del_cookie("logginNitdoc");
463 closeAllCommentInEdtiting();
465 displayLogginModal();
468 // Activate edit mode
469 $
('pre[class=text_label]').click(function(){
470 // the customer is loggued ?
471 if(!sessionStarted || userName
== ""){
472 // No => nothing happen
476 numComment
= $
(this).attr('title');
477 var arrayNew
= $
(this).text().split('\n');
478 var lNew
= arrayNew
.length
- 1;
481 for (var i
= 0; i
< lNew
; i
++) {
482 adapt
+= arrayNew
[i];
483 if(i
< lNew
-1){ adapt
+= "\n"; }
486 getCommentOfFunction($
(this));
490 $
(this).next().show();
491 // Show cancel button
492 $
(this).next().next().show();
493 // Show commit button
494 $
(this).next().next().next().show();
495 // Add text in edit box
496 if($
(this).next().val() == "" || $
(this).next().val() != adapt
){ $
(this).next().val(adapt
); }
498 $
(this).next().height($
(this).next().prop("scrollHeight"));
499 resizeTextarea($
(this).next());
501 $
(this).next().select();
502 preElement
= $
(this);
506 // Disable the edit mode
507 $
('a[id=cancelBtn]').click(function(){
508 $
(this).parent().prev().children('#lblDiffCommit').text("");
510 closeEditing($
(this));
513 // Display commit form
514 $
('a[id=commitBtn]').click(function(){
515 updateComment
= $
(this).prev().prev().val();
516 commentType
= $
(this).prev().prev().prev().attr('type');
518 if(updateComment
== ""){ displayMessage('The comment field is empty!', 40, 45); }
521 displayMessage("You need to be loggued before commit something", 45, 40);
522 displayLogginModal();
526 // Create the commit message
527 commitMessage
= 'Wikidoc: modified comment in ' + $
(this).parent().prev().prev().html().split(' ')[1];
528 $
('#commitMessage').text(commitMessage
);
529 $
('#commitMessage').css({'display': 'block'});
530 pathFile
= $
(this).prev().prev().prev().attr('tag');
531 $
('#modal').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btn_close" title="Close" alt="Close" /></a>');
532 $
('body').append('<div id="fade"></div>');
533 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
538 $
('.btn_close').click(function(){
540 $
(this).next().hide();
541 if(editComment
> 0){ editComment
-= 1; }
542 $
('#chkSignedOff').attr('checked', false);
546 //Close Popups and Fade Layer
547 $
('body').on('click', 'a.close, #fade', function() {
548 if(editComment
> 0){ editComment
-= 1; }
549 $
('#fade , #modal').fadeOut(function() {
550 $
('#fade, a.close').remove();
552 $
('#modalQuestion').hide();
553 $
('#chkSignedOff').attr('checked', false);
557 $
('#loginAction').click(function(){
561 // Look if the customer is logged
563 displayMessage("You need to be loggued before commit something", 100, 40);
564 $
('.popover').show();
567 else{ userB64
= "Basic " + getUserPass("logginNitdoc"); }
568 // Check if repo exist
574 commitMessage
= $
('#commitMessage').val().replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"');
575 if(commitMessage
== ""){ commitMessage
= "New commit";}
577 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
580 startCommitProcess();
583 $
('#modal, #modalQuestion').fadeOut(function() {
585 $
('#password').val("");
586 $
('textarea').hide();
587 $
('textarea').prev().show();
589 $
('a[id=cancelBtn]').hide();
590 $
('a[id=commitBtn]').hide();
591 $
('a[id=lblDiffCommit]').text("");
593 // Re-load all comment
597 else{ editComment
-= 1; }
598 $
('#chkSignedOff').attr('checked', false);
601 // Cancel creating branch
602 $
('#btnCancelBranch').click(function(){
604 $
('#modalQuestion').hide();
605 $
('#fade , #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
609 // Create new branch and continu
610 $
('#btnCreateBranch').click(function(){
611 $
('#modalQuestion').hide();
612 if($
('#btnCreateBranch').text() != 'Ok'){
615 commitMessage
= $
('#commitMessage').val().replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"');
616 if(commitMessage
== ""){ commitMessage
= "New commit"; }
619 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+githubRepo
+':'+branchName
), 1);
620 $
('#loginGit').val("");
621 $
('#passwordGit').val("");
622 loginProcess
= false;
623 displayLogginModal();
626 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
627 else{ startCommitProcess(); }
633 $
('#fade , #modalQuestion, #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
637 $
('a[class=newComment]').click(function(){
638 addNewComment
= true;
643 $
(this).next().show();
644 // Show cancel button
645 $
(this).next().next().show();
646 // Show commit button
647 $
(this).next().next().next().show();
649 $
(this).next().height($
(this).next().prop("scrollHeight"));
650 resizeTextarea($
(this).next());
652 $
(this).next().select();
653 preElement
= $
(this);
656 $
("#dropBranches").change(function () {
657 $
("#dropBranches option:selected").each(function () {
658 if(branchName
!= $
(this).text()){
659 branchName
= $
(this).text();
662 $
.when(updateCookie(userName
, password
, githubRepo
, branchName
)).done(function(){
663 closeAllCommentInEdtiting();
670 if(sessionStarted
== true){
671 $
(this).css({'cursor' : 'hand'});
674 $
(this).css({'cursor' : ''});
678 if(sessionStarted
== true){
679 $
(this).css({'cursor' : 'pointer'});
682 $
(this).css({'cursor' : ''});
687 $
('#chkSignedOff').click(function(){
688 if($
(this).is(':checked')){ addSignedOff(); }
689 else{ removeSignedOff(); }
692 $
('a[id=lblDiffCommit]').click(function(){
693 showComment($
(this));
697 /* Parse current URL and return anchor name */
698 function currentAnchor() {
699 var index
= document
.location
.hash
.indexOf("#");
701 return document
.location
.hash
.substring(index
+ 1);
706 /* Prealod filters field using search query */
707 function preloadFilters() {
708 // Parse URL and get query string
709 var search
= currentAnchor();
711 if(search
== null || search
.indexOf("q=") == -1)
714 search
= search
.substring(2, search
.length
);
716 if(search
== "" || search
== "undefined")
719 $
(":text").val(search
);
721 .removeClass("notUsed")
726 /* Hightlight the spoted block */
727 function highlightBlock(a
) {
732 $
(".highlighted").removeClass("highlighted");
734 var target
= $
("#" + a
);
736 if(target
.is("article")) {
737 target
.parent().addClass("highlighted");
740 target
.addClass("highlighted");
744 // Init process to commit the new comment
745 function startCommitProcess()
747 if($
('#chkSignedOff').is(':checked')){
748 var numL
= preElement
.attr("title");
749 commentLineStart
= numL
.split('-')[0] - 1;
750 if(addNewComment
) { commentLineStart
++; }
751 commentLineEnd
= (commentLineStart
+ preElement
.text().split('\n').length
) - 1;
753 replaceComment(updateComment
, currentfileContent
);
759 displayMessage('Please sign this commit', 40, 40);
763 function displayLogginModal(){
764 if ($
('.popover').is(':hidden')) {
765 if(sessionStarted
){ getListBranches(); }
766 $
('.popover').show();
768 else { $
('.popover').hide(); }
772 function updateDisplaying(){
775 userB64
= "Basic " + getUserPass("logginNitdoc");
776 $
('#loginGit').hide();
777 $
('#passwordGit').hide();
778 $
('#lbpasswordGit').hide();
779 $
('#lbloginGit').hide();
780 $
('#repositoryGit').hide();
781 $
('#lbrepositoryGit').hide();
782 $
('#lbbranchGit').hide();
783 $
('#branchGit').hide();
784 $
('#listBranches').show();
785 $
('#divGitHubRepoDisplay').show();
786 $
("#liGitHub").attr("class", "current");
787 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
788 $
('#nickName').text(userName
);
789 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
790 $
('#logginMessage').css({'display' : 'block'});
791 $
('#logginMessage').css({'text-align' : 'center'});
792 $
('.popover').css({'height' : '190px'});
793 $
('#signIn').text("Sign out");
794 $
('#githubRepoDisplay').text(githubRepo
);
795 sessionStarted
= true;
800 sessionStarted
= false;
801 $
('#logginMessage').css({'display' : 'none'});
802 $
("#liGitHub").attr("class", "");
803 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
804 $
('#loginGit').val("");
805 $
('#passwordGit').val("");
806 $
('#nickName').text("");
807 $
('.popover').css({'height' : '325px'});
808 $
('#logginMessage').css({'display' : 'none'});
809 $
('#repositoryGit').val($
('#repoName').attr('name'));
810 $
('#branchGit').val('wikidoc');
811 $
('#signIn').text("Sign In");
812 $
('#loginGit').show();
813 $
('#passwordGit').show();
814 $
('#lbpasswordGit').show();
815 $
('#lbloginGit').show();
816 $
('#repositoryGit').show();
817 $
('#lbrepositoryGit').show();
818 $
('#lbbranchGit').show();
819 $
('#branchGit').show();
820 $
('#listBranches').hide();
821 $
('#divGitHubRepoDisplay').hide();
825 function setCookie(c_name
, value
, exdays
)
827 var exdate
=new Date();
828 exdate
.setDate(exdate
.getDate() + exdays
);
829 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
830 document
.cookie
=c_name
+ "=" + c_value
;
833 function del_cookie(c_name
)
835 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
838 function updateCookie(user
, pwd
, repo
, branch
){
841 setCookie("logginNitdoc", base64
.encode(user
+':'+pwd
+':'+repo
+':'+branch
), 1);
845 function getCookie(c_name
)
847 var c_value
= document
.cookie
;
848 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
849 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
850 if (c_start
== -1) { c_value
= null; }
853 c_start
= c_value
.indexOf("=", c_start
) + 1;
854 var c_end
= c_value
.indexOf(";", c_start
);
855 if (c_end
== -1) { c_end
= c_value
.length
; }
856 c_value
= unescape(c_value
.substring(c_start
,c_end
));
861 function getUserPass(c_name
){
862 var cookie
= base64
.decode(getCookie(c_name
));
863 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
866 function checkCookie()
868 var cookie
=getCookie("logginNitdoc");
869 if (cookie
!=null && cookie
!="")
871 cookie
= base64
.decode(cookie
);
872 userName
= cookie
.split(':')[0];
873 password
= cookie
.split(':')[1];
874 githubRepo
= cookie
.split(':')[2];
875 branchName
= cookie
.split(':')[3];
878 else { return false; }
886 base64
.PADCHAR
= '=';
887 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
888 base64
.getbyte64
= function(s
,i
) {
889 // This is oddly fast, except on Chrome/V8.
890 // Minimal or no improvement in performance by using a
891 // object with properties mapping chars to value (eg. 'A': 0)
892 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
894 throw "Cannot decode base64";
899 base64
.decode
= function(s
) {
902 var getbyte64
= base64
.getbyte64
;
910 throw "Cannot decode base64";
914 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
916 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
919 // either way, we want to ignore this last block
924 for (i
= 0; i
< imax
; i
+= 4) {
925 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
926 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
927 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
932 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
933 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
936 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
937 x
.push(String
.fromCharCode(b10
>> 16));
943 base64
.getbyte
= function(s
,i
) {
944 var x
= s
.charCodeAt(i
);
946 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
952 base64
.encode
= function(s
) {
953 if (arguments
.length
!= 1) {
954 throw "SyntaxError: Not enough arguments";
956 var padchar
= base64
.PADCHAR
;
957 var alpha
= base64
.ALPHA
;
958 var getbyte
= base64
.getbyte
;
966 var imax
= s
.length
- s
.length
% 3;
971 for (i
= 0; i
< imax
; i
+= 3) {
972 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
973 x
.push(alpha
.charAt(b10
>> 18));
974 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
975 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
976 x
.push(alpha
.charAt(b10
& 0x3f));
978 switch (s
.length
- imax
) {
980 b10
= getbyte(s
,i
) << 16;
981 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
985 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
986 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
987 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
995 function getLastCommit()
998 if(sessionStarted
){ urlHead
= "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
;}
1000 // TODO: get url of the original repo.
1005 beforeSend
: function (xhr
) {
1006 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1012 success
: function(success
)
1014 shaLastCommit
= success
.object
.sha
;
1019 function getBaseTree()
1022 beforeSend
: function (xhr
) {
1023 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1026 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits/" + shaLastCommit
,
1029 success
: function(success
)
1031 shaBaseTree
= success
.tree
.sha
;
1032 if (state
){ setBlob(); }
1041 function setNewTree()
1044 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1046 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/trees",
1049 data
:'{ "base_tree" : "'+shaBaseTree
+'", '+
1051 '"path":"'+ pathFile
+'",'+
1054 '"sha": "'+ shaBlob
+'"'+
1057 success
: function(success
)
1058 { // si l'appel a bien fonctionné
1059 shaNewTree
= success
.sha
;
1068 function setNewCommit()
1072 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1074 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits",
1077 data
:'{ "message" : "'+ commitMessage
+'", '+
1078 '"parents" :"'+shaLastCommit
+'",'+
1079 '"tree": "'+shaNewTree
+'"'+
1081 success
: function(success
)
1083 shaNewCommit
= success
.sha
;
1096 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1098 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1100 data
:'{ "sha" : "'+shaNewCommit
+'", '+
1103 success
: function(success
) { displayMessage('Commit created successfully', 40, 40); },
1104 error
:function(error
){ displayMessage('Error ' + error
.object
.message
, 40, 40); }
1112 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1114 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/blobs",
1117 data
:'{ "content" : "'+text
.replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"')+'", '+
1118 '"encoding" :"utf-8"'+
1120 success
: function(success
)
1122 shaBlob
= success
.sha
;
1125 error
:function(error
){
1126 displayMessage('Error : Problem parsing JSON', 40, 40);
1132 // Display file content
1133 function getFileContent(urlFile
, newComment
)
1136 beforeSend
: function (xhr
) {
1137 xhr
.setRequestHeader ("Accept", "application/vnd.github-blob.raw");
1138 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1143 success
: function(success
)
1146 replaceComment(newComment
, success
);
1151 function replaceComment(newComment
, fileContent
){
1152 var arrayNew
= newComment
.split('\n');
1153 var lNew
= arrayNew
.length
;
1155 var lines
= fileContent
.split("\n");
1156 for (var i
= 0; i
< lines
.length
; i
++) {
1157 if(i
== commentLineStart
){
1159 for(var indexLine
=0; indexLine
< lines
[i
+1].length
; indexxLine
++){
1160 if(lines
[i
+1].substr(indexLine
,1) == "\t" || lines
[i
+1].substr(indexLine
,1) == "#"){ text
+= lines
[i
+1].substr(indexLine
,1); }
1163 text
+= lines
[i] + "\n";
1165 // We change the comment
1166 for(var j
= 0; j
< lNew
; j
++){
1167 if(commentType
== 1){ text
+= "\t# " + arrayNew
[j] + "\n"; }
1169 if(arrayNew
[j] == ""){ text
+= "#"+"\n"; }
1170 else{ text
+= "# " + arrayNew
[j] + "\n"; }
1174 else if(i
< commentLineStart || i
>= commentLineEnd
){
1175 if(i
== lines
.length
-1){ text
+= lines
[i]; }
1176 else{ text
+= lines
[i] + "\n"; }
1180 addNewComment
= false;
1184 function getCommentLastCommit(path
, origin
){
1187 if(origin
){// We want to get the original file
1188 bkBranch
= branchName
;
1189 branchName
= "master";
1192 if(shaLastCommit
!= ""){
1193 if (checkCookie()) {
1194 urlRaw
="https://rawgithub.com/"+ userName
+"/"+ githubRepo
+"/" + shaLastCommit
+ "/" + path
;
1199 success
: function(success
)
1201 if(origin
){ originalFileContent
= success
; }
1202 else{ currentfileContent
= success
; }
1207 if(origin
){ branchName
= bkBranch
; }
1210 function displayMessage(msg
, widthDiv
, margModal
){
1213 $
('#btnCancelBranch').hide();
1214 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1215 $
('#txtQuestion').text(msg
);
1216 $
('#btnCreateBranch').text("Ok");
1217 var xModal
= $
('#modalQuestion').css('width').split('px')[0];
1218 var yModal
= $
('#modalQuestion').css('height').split('px')[0];
1219 var x
= $
(document
).width
/2 - xModal
/2;
1220 var y
= $
(document
).height
/2 - yModal
/2;
1221 var xBtnBranch
= $
('#btnCreateBranch').css('width').split('px')[0];
1222 $
('#modalQuestion').css({'left' : x
, 'top' : y
});
1223 $
('#modalQuestion').show();
1224 $
('#btnCreateBranch').css('margin-left', xModal
/2 - xBtnBranch
);
1225 $
('body').append('<div id="fade"></div>');
1226 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1229 function displaySpinner(){
1230 spinner
.spin(targetSpinner
);
1231 $
("#waitCommit").show();
1234 // Check if the repo already exist
1235 function isRepoExisting(){
1237 beforeSend
: function (xhr
) {
1238 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1241 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1244 success
: function(){ repoExist
= true; },
1247 displayMessage('Repo not found !', 35, 45);
1253 // Check if the branch already exist
1254 function isBranchExisting(){
1256 beforeSend
: function (xhr
) {
1257 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1260 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1263 success
: function(){ branchExist
= true; },
1266 branchExist
= false;
1269 $
('#txtQuestion').text("Are you sure you want to create that branch ?");
1270 $
('#btnCancelBranch').show();
1271 $
('#btnCreateBranch').text("Yes");
1272 $
('#modalQuestion').show();
1273 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1274 $
('body').append('<div id="fade"></div>');
1275 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1280 function getMasterSha()
1283 beforeSend
: function (xhr
) {
1284 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1287 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/master",
1290 success
: function(success
) { shaMaster
= success
.object
.sha
; }
1294 function createBranch(){
1299 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1301 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs",
1302 data
:'{ "ref" : "refs/heads/'+branchName
+'",'+
1303 '"sha" : "'+shaMaster
+'"'+
1305 success
: function(){ return; },
1308 displayMessage('Impossible to create the new branch : ' + branchName
, 40, 40);
1313 $
.fn
.spin
= function(opts
) {
1314 this.each(function() {
1315 var $
this = $
(this),
1316 data
= $
this.data();
1319 data
.spinner
.stop();
1320 delete data
.spinner
;
1322 if (opts
!== false) {
1323 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);
1329 function reloadComment(){
1330 var path
= $
('pre[class=text_label]').attr('tag');
1331 $
.when(getCommentLastCommit(path
, false)).done(function(){
1332 if(sessionStarted
){ getCommentLastCommit(path
, true); }
1333 $
('pre[class=text_label]').each(function(){ getCommentOfFunction($
(this)); });
1337 function getCommentOfFunction(element
){
1339 var numL
= element
.attr("title");
1341 commentLineStart
= numL
-1;
1342 commentLineEnd
= element
.attr('name').split(numL
)[1].split('-')[1]-1;
1343 var lines
= currentfileContent
.split("\n");
1344 for (var i
= 0; i
< lines
.length
; i
++) {
1345 if(i
>= commentLineStart
-1 && i
<= commentLineEnd
+1){
1346 if (lines
[i].substr(1,1) == "#"){ textC
+= lines
[i].substr(3,lines
[i].length
) + "\n";}
1347 else if(lines
[i].substr(0,1) == '#'){ textC
+= lines
[i].substr(2,lines
[i].length
) + "\n"; }
1350 if(textC
!= element
.text
){element
.text(textC
);}
1351 if (textC
!= "" && editComment
> 0){
1352 var originContent
= originalFileContent
.split("\n");
1354 var lblDiff
= element
.parent().prev().children('#lblDiffCommit');
1355 var preSave
= element
.parent().children('#preSave');
1356 for (var i
= 0; i
< originContent
.length
; i
++) {
1357 if(i
>= commentLineStart
-1 && i
<= commentLineEnd
+1){
1358 if (originContent
[i].substr(1,1) == "#"){ origin
+= originContent
[i].substr(3,originContent
[i].length
) + "\n";}
1359 else if(originContent
[i].substr(0,1) == '#'){ origin
+= originContent
[i].substr(2,originContent
[i].length
) + "\n"; }
1362 if(textC
!= origin
&& numL
== numComment
){
1363 // The comment is different compare to the original
1364 if(showcomment
== false){ lblDiff
.text("Show original comment"); }
1365 preSave
.text(origin
);
1367 else if (numL
== numComment
){ lblDiff
.text(""); }
1372 // Get list of branches
1373 function getListBranches()
1375 cleanListBranches();
1377 beforeSend
: function (xhr
) {
1378 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1381 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/branches",
1384 success
: function(success
)
1386 for(var branch
in success
) {
1388 if(branchName
== success
[branch].name
){
1389 selected
= 'selected';
1391 $
('#dropBranches').append('<option value="" '+ selected
+'>' + success
[branch].name
+ '</option>');
1397 // Delete all option in the list
1398 function cleanListBranches(){
1399 $
('#dropBranches').children("option").remove();
1402 function closeAllCommentInEdtiting(){
1403 $
('a[id=cancelBtn]').each(function(){
1404 closeEditing($
(this));
1408 function closeEditing(tag
){
1409 if(editComment
> 0){ editComment
-= 1; }
1417 tag
.prev().prev().show();
1420 function checkSignIn(){
1421 var response
= false;
1423 beforeSend
: function (xhr
) {
1424 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1427 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1430 success
: function(success
)
1434 displayMessage('You are now logged in');
1438 displayMessage('Error : Wrong username or password');
1445 function getUserInfo(){
1447 beforeSend
: function (xhr
) {
1448 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1451 url
: "https://api.github.com/user/emails",
1454 success
: function(success
)
1456 userEmail
= success
;
1461 function getSignedOff(){
1463 beforeSend
: function (xhr
) {
1464 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1467 url
: "https://api.github.com/users/"+userName
,
1470 success
: function(success
)
1472 signedOff
= success
.name
;
1477 function addSignedOff(){
1478 $
.when(getUserInfo()).done(function(){
1479 $
.when(getSignedOff()).done(function(){
1480 $
('#commitMessage').val($
('#commitMessage').val() + "\n\nSigned-off-by: "+signedOff
+" <"+userEmail
+">");
1483 resizeTextarea($
('#commitMessage'));
1486 function removeSignedOff(){
1487 $
('#commitMessage').val(commitMessage
);
1488 resizeTextarea($
('#commitMessage'));
1491 function resizeTextarea(element
){
1492 var nLines
= element
.val().split('\n').length
+ 1;
1493 element
.attr('rows', nLines
);
1496 function showComment(element
){
1497 // Display the original comment
1498 if (showcomment
== true){
1499 showcomment
= false;
1500 element
.text("Show original comment");
1503 // Show the comment updated in user's repo
1505 element
.text("Comment changed in "+githubRepo
+" / "+branchName
);
1507 var parent
= element
.parent().next(".description");
1508 var textarea
= parent
.children('#fileContent');
1509 var text
= textarea
.val();
1510 var preSave
= parent
.children('#preSave');
1511 textarea
.val(preSave
.text());
1514 textarea
.height(textarea
.prop("scrollHeight"));
1515 resizeTextarea(textarea
);