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
, "\\)");
211 var regexp
= new RegExp("^" + query
, "i");
212 for(var entry
in entries
) {
216 var result
= entry
.match(regexp
);
217 if(result
!= null && result
.toString().toUpperCase() == $
("#search").val().toUpperCase()) {
218 for(var i
= 0; i
< entries
[entry].length
; i
++) {
223 $
(document
.createElement("tr"))
224 .data("searchDetails", {name
: entry
, url
: entries
[entry][i]["url"]})
225 .data("index", index
)
226 .append($
(document
.createElement("td")).html(entry
))
228 $
(document
.createElement("td"))
229 .addClass("entryInfo")
230 .html(entries
[entry][i]["txt"] + " »"))
231 .mouseover( function() {
232 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
233 $
(this).addClass("activeSearchResult");
234 currentIndex
= $
(this).data("index");
236 .mouseout( function() {
237 $
(this).removeClass("activeSearchResult");
240 window
.location
= $
(this).data("searchDetails")["url"];
248 // Initialize table properties
249 currentTable
.attr("id", "searchTable");
250 currentTable
.css("position", "absolute");
251 currentTable
.width($
("#search").outerWidth());
252 $
("header").append(currentTable
);
253 currentTable
.offset({left
: $
("#search").offset().left
+ ($
("#search").outerWidth() - currentTable
.outerWidth()), top
: $
("#search").offset().top
+ $
("#search").outerHeight()});
255 // Preselect first entry
256 if(currentTable
.find("tr").length
> 0) {
258 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
259 $
("#search").focus();
264 .focusout(function() {
265 if($
(this).val() == "") {
266 $
(this).addClass("notUsed");
267 $
(this).val("quick search...");
270 .focusin(function() {
271 if($
(this).val() == "quick search...") {
272 $
(this).removeClass("notUsed");
277 .submit( function() {
283 // Close quicksearch list on click
284 $
(document
).click(function(e
) {
285 if(e
.target
!= $
("#search")[0] && e
.target
!= $
("#searchTable")[0]) {
286 if(currentTable
!= null) {
287 currentTable
.remove();
293 // Insert filter field
294 $
("article.filterable h2, nav.filterable h3")
296 $
(document
.createElement("div"))
299 $
(document
.createElement("input"))
306 $
(this).parent().parent().find("ul li:not(:icontains('" + $
(this).val() + "'))").addClass("hide");
307 $
(this).parent().parent().find("ul li:icontains('" + $
(this).val() + "')").removeClass("hide");
309 .focusout(function() {
310 if($
(this).val() == "") {
311 $
(this).addClass("notUsed");
312 $
(this).val("filter...");
315 .focusin(function() {
316 if($
(this).val() == "filter...") {
317 $
(this).removeClass("notUsed");
324 // Filter toggle between H I R in nav porperties list
325 $
("nav.properties.filterable .filter")
327 $
(document
.createElement("a"))
330 title
: "hide inherited properties"
333 if($
(this).hasClass("hidden")) {
334 $
(this).parent().parent().find("li.inherit").show();
336 $
(this).parent().parent().find("li.inherit").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");
359 $
(document
.createElement("a"))
362 title
: "hide introduced properties"
365 if($
(this).hasClass("hidden")) {
366 $
(this).parent().parent().find("li.intro").show();
368 $
(this).parent().parent().find("li.intro").hide();
371 $
(this).toggleClass("hidden");
375 // Filter toggle between I R in
376 $
("article.properties.filterable .filter, article.classes.filterable .filter")
378 $
(document
.createElement("a"))
381 title
: "hide introduced properties"
384 if($
(this).hasClass("hidden")) {
385 $
(this).parent().parent().find("li.intro").show();
387 $
(this).parent().parent().find("li.intro").hide();
390 $
(this).toggleClass("hidden");
394 $
(document
.createElement("a"))
397 title
: "hide redefined properties"
400 if($
(this).hasClass("hidden")) {
401 $
(this).parent().parent().find("li.redef").show();
403 $
(this).parent().parent().find("li.redef").hide();
406 $
(this).toggleClass("hidden");
413 $
("a[href*='#']").click( function() {
414 highlightBlock($
(this).attr("href").split(/#
/)[1]);
417 //Preload filter fields with query string
419 // Hide Authenfication form
420 $
(".popover").hide();
421 // Display Login modal
422 $
("#logGitHub").click(function(){ displayLogginModal(); });
425 // If cookie existing the session is opened
426 if(sessionStarted
){ userB64
= "Basic " + getUserPass("logginNitdoc"); }
428 // Sign In an github user or Log out him
429 $
("#signIn").click(function(){
431 if($
('#loginGit').val() == "" || $
('#passwordGit').val() == ""){ displayMessage('Please informed login/password field!', 40, 45); }
434 userName
= $
('#loginGit').val();
435 password
= $
('#passwordGit').val();
436 githubRepo
= $
('#repositoryGit').val();
437 branchName
= $
('#branchGit').val();
438 userB64
= "Basic " + base64
.encode(userName
+':'+password
);
440 // Check if repo exist
443 $
.when(isBranchExisting()).done(function(){
446 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+githubRepo
+':'+branchName
), 1);
447 $
('#loginGit').val("");
448 $
('#passwordGit').val("");
458 // Delete cookie and reset settings
459 del_cookie("logginNitdoc");
460 closeAllCommentInEdtiting();
462 displayLogginModal();
465 // Activate edit mode
466 $
('pre[class=text_label]').click(function(){
467 // the customer is loggued ?
468 if(!sessionStarted || userName
== ""){
469 // No => nothing happen
473 numComment
= $
(this).attr('title');
474 var arrayNew
= $
(this).text().split('\n');
475 var lNew
= arrayNew
.length
- 1;
478 for (var i
= 0; i
< lNew
; i
++) {
479 adapt
+= arrayNew
[i];
480 if(i
< lNew
-1){ adapt
+= "\n"; }
483 getCommentOfFunction($
(this));
487 $
(this).next().show();
488 // Show cancel button
489 $
(this).next().next().show();
490 // Show commit button
491 $
(this).next().next().next().show();
492 // Add text in edit box
493 if($
(this).next().val() == "" || $
(this).next().val() != adapt
){ $
(this).next().val(adapt
); }
495 $
(this).next().height($
(this).next().prop("scrollHeight"));
496 resizeTextarea($
(this).next());
498 $
(this).next().select();
499 preElement
= $
(this);
503 // Disable the edit mode
504 $
('a[id=cancelBtn]').click(function(){
505 $
(this).parent().prev().children('#lblDiffCommit').text("");
507 closeEditing($
(this));
510 // Display commit form
511 $
('a[id=commitBtn]').click(function(){
512 updateComment
= $
(this).prev().prev().val();
513 commentType
= $
(this).prev().prev().prev().attr('type');
515 if(updateComment
== ""){ displayMessage('The comment field is empty!', 40, 45); }
518 displayMessage("You need to be loggued before commit something", 45, 40);
519 displayLogginModal();
523 // Create the commit message
524 commitMessage
= 'Wikidoc: modified comment in ' + $
(this).parent().prev().html().split(' ')[1];
525 $
('#commitMessage').text(commitMessage
);
526 $
('#commitMessage').css({'display': 'block'});
527 pathFile
= $
(this).prev().prev().prev().attr('tag');
528 $
('#modal').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btn_close" title="Close" alt="Close" /></a>');
529 $
('body').append('<div id="fade"></div>');
530 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
535 $
('.btn_close').click(function(){
537 $
(this).next().hide();
538 if(editComment
> 0){ editComment
-= 1; }
539 $
('#chkSignedOff').attr('checked', false);
543 //Close Popups and Fade Layer
544 $
('body').on('click', 'a.close, #fade', function() {
545 if(editComment
> 0){ editComment
-= 1; }
546 $
('#fade , #modal').fadeOut(function() {
547 $
('#fade, a.close').remove();
549 $
('#modalQuestion').hide();
550 $
('#chkSignedOff').attr('checked', false);
554 $
('#loginAction').click(function(){
558 // Look if the customer is logged
560 displayMessage("You need to be loggued before commit something", 100, 40);
561 $
('.popover').show();
564 else{ userB64
= "Basic " + getUserPass("logginNitdoc"); }
565 // Check if repo exist
571 commitMessage
= $
('#commitMessage').val().replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"');
572 if(commitMessage
== ""){ commitMessage
= "New commit";}
574 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
577 startCommitProcess();
580 $
('#modal, #modalQuestion').fadeOut(function() {
582 $
('#password').val("");
583 $
('textarea').hide();
584 $
('textarea').prev().show();
586 $
('a[id=cancelBtn]').hide();
587 $
('a[id=commitBtn]').hide();
588 $
('a[id=lblDiffCommit]').text("");
590 // Re-load all comment
594 else{ editComment
-= 1; }
595 $
('#chkSignedOff').attr('checked', false);
598 // Cancel creating branch
599 $
('#btnCancelBranch').click(function(){
601 $
('#modalQuestion').hide();
602 $
('#fade , #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
606 // Create new branch and continu
607 $
('#btnCreateBranch').click(function(){
608 $
('#modalQuestion').hide();
609 if($
('#btnCreateBranch').text() != 'Ok'){
612 commitMessage
= $
('#commitMessage').val().replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"');
613 if(commitMessage
== ""){ commitMessage
= "New commit"; }
616 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+githubRepo
+':'+branchName
), 1);
617 $
('#loginGit').val("");
618 $
('#passwordGit').val("");
619 loginProcess
= false;
620 displayLogginModal();
623 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
624 else{ startCommitProcess(); }
630 $
('#fade , #modalQuestion, #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
634 $
('a[class=newComment]').click(function(){
635 addNewComment
= true;
640 $
(this).next().show();
641 // Show cancel button
642 $
(this).next().next().show();
643 // Show commit button
644 $
(this).next().next().next().show();
646 $
(this).next().height($
(this).next().prop("scrollHeight"));
647 resizeTextarea($
(this).next());
649 $
(this).next().select();
650 preElement
= $
(this);
653 $
("#dropBranches").change(function () {
654 $
("#dropBranches option:selected").each(function () {
655 if(branchName
!= $
(this).text()){
656 branchName
= $
(this).text();
659 $
.when(updateCookie(userName
, password
, githubRepo
, branchName
)).done(function(){
660 closeAllCommentInEdtiting();
667 if(sessionStarted
== true){
668 $
(this).css({'cursor' : 'hand'});
671 $
(this).css({'cursor' : ''});
675 if(sessionStarted
== true){
676 $
(this).css({'cursor' : 'pointer'});
679 $
(this).css({'cursor' : ''});
684 $
('#chkSignedOff').click(function(){
685 if($
(this).is(':checked')){ addSignedOff(); }
686 else{ removeSignedOff(); }
689 $
('a[id=lblDiffCommit]').click(function(){
690 showComment($
(this));
694 /* Parse current URL and return anchor name */
695 function currentAnchor() {
696 var index
= document
.location
.hash
.indexOf("#");
698 return document
.location
.hash
.substring(index
+ 1);
703 /* Prealod filters field using search query */
704 function preloadFilters() {
705 // Parse URL and get query string
706 var search
= currentAnchor();
708 if(search
== null || search
.indexOf("q=") == -1)
711 search
= search
.substring(2, search
.length
);
713 if(search
== "" || search
== "undefined")
716 $
(":text").val(search
);
718 .removeClass("notUsed")
723 /* Hightlight the spoted block */
724 function highlightBlock(a
) {
729 $
(".highlighted").removeClass("highlighted");
731 var target
= $
("#" + a
);
733 if(target
.is("article")) {
734 target
.parent().addClass("highlighted");
737 target
.addClass("highlighted");
741 // Init process to commit the new comment
742 function startCommitProcess()
744 if($
('#chkSignedOff').is(':checked')){
745 var numL
= preElement
.attr("title");
746 commentLineStart
= numL
.split('-')[0] - 1;
747 if(addNewComment
) { commentLineStart
++; }
748 commentLineEnd
= (commentLineStart
+ preElement
.text().split('\n').length
) - 1;
750 replaceComment(updateComment
, currentfileContent
);
756 displayMessage('Please sign this commit', 40, 40);
760 function displayLogginModal(){
761 if ($
('.popover').is(':hidden')) {
762 if(sessionStarted
){ getListBranches(); }
763 $
('.popover').show();
765 else { $
('.popover').hide(); }
769 function updateDisplaying(){
772 userB64
= "Basic " + getUserPass("logginNitdoc");
773 $
('#loginGit').hide();
774 $
('#passwordGit').hide();
775 $
('#lbpasswordGit').hide();
776 $
('#lbloginGit').hide();
777 $
('#repositoryGit').hide();
778 $
('#lbrepositoryGit').hide();
779 $
('#lbbranchGit').hide();
780 $
('#branchGit').hide();
781 $
('#listBranches').show();
782 $
('#divGitHubRepoDisplay').show();
783 $
("#liGitHub").attr("class", "current");
784 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
785 $
('#nickName').text(userName
);
786 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
787 $
('#logginMessage').css({'display' : 'block'});
788 $
('#logginMessage').css({'text-align' : 'center'});
789 $
('.popover').css({'height' : '190px'});
790 $
('#signIn').text("Sign out");
791 $
('#githubRepoDisplay').text(githubRepo
);
792 sessionStarted
= true;
797 sessionStarted
= false;
798 $
('#logginMessage').css({'display' : 'none'});
799 $
("#liGitHub").attr("class", "");
800 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
801 $
('#loginGit').val("");
802 $
('#passwordGit').val("");
803 $
('#nickName').text("");
804 $
('.popover').css({'height' : '325px'});
805 $
('#logginMessage').css({'display' : 'none'});
806 $
('#repositoryGit').val($
('#repoName').attr('name'));
807 $
('#branchGit').val('wikidoc');
808 $
('#signIn').text("Sign In");
809 $
('#loginGit').show();
810 $
('#passwordGit').show();
811 $
('#lbpasswordGit').show();
812 $
('#lbloginGit').show();
813 $
('#repositoryGit').show();
814 $
('#lbrepositoryGit').show();
815 $
('#lbbranchGit').show();
816 $
('#branchGit').show();
817 $
('#listBranches').hide();
818 $
('#divGitHubRepoDisplay').hide();
822 function setCookie(c_name
, value
, exdays
)
824 var exdate
=new Date();
825 exdate
.setDate(exdate
.getDate() + exdays
);
826 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
827 document
.cookie
=c_name
+ "=" + c_value
;
830 function del_cookie(c_name
)
832 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
835 function updateCookie(user
, pwd
, repo
, branch
){
838 setCookie("logginNitdoc", base64
.encode(user
+':'+pwd
+':'+repo
+':'+branch
), 1);
842 function getCookie(c_name
)
844 var c_value
= document
.cookie
;
845 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
846 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
847 if (c_start
== -1) { c_value
= null; }
850 c_start
= c_value
.indexOf("=", c_start
) + 1;
851 var c_end
= c_value
.indexOf(";", c_start
);
852 if (c_end
== -1) { c_end
= c_value
.length
; }
853 c_value
= unescape(c_value
.substring(c_start
,c_end
));
858 function getUserPass(c_name
){
859 var cookie
= base64
.decode(getCookie(c_name
));
860 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
863 function checkCookie()
865 var cookie
=getCookie("logginNitdoc");
866 if (cookie
!=null && cookie
!="")
868 cookie
= base64
.decode(cookie
);
869 userName
= cookie
.split(':')[0];
870 password
= cookie
.split(':')[1];
871 githubRepo
= cookie
.split(':')[2];
872 branchName
= cookie
.split(':')[3];
875 else { return false; }
883 base64
.PADCHAR
= '=';
884 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
885 base64
.getbyte64
= function(s
,i
) {
886 // This is oddly fast, except on Chrome/V8.
887 // Minimal or no improvement in performance by using a
888 // object with properties mapping chars to value (eg. 'A': 0)
889 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
891 throw "Cannot decode base64";
896 base64
.decode
= function(s
) {
899 var getbyte64
= base64
.getbyte64
;
907 throw "Cannot decode base64";
911 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
913 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
916 // either way, we want to ignore this last block
921 for (i
= 0; i
< imax
; i
+= 4) {
922 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
923 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
924 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
929 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
930 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
933 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
934 x
.push(String
.fromCharCode(b10
>> 16));
940 base64
.getbyte
= function(s
,i
) {
941 var x
= s
.charCodeAt(i
);
943 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
949 base64
.encode
= function(s
) {
950 if (arguments
.length
!= 1) {
951 throw "SyntaxError: Not enough arguments";
953 var padchar
= base64
.PADCHAR
;
954 var alpha
= base64
.ALPHA
;
955 var getbyte
= base64
.getbyte
;
963 var imax
= s
.length
- s
.length
% 3;
968 for (i
= 0; i
< imax
; i
+= 3) {
969 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
970 x
.push(alpha
.charAt(b10
>> 18));
971 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
972 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
973 x
.push(alpha
.charAt(b10
& 0x3f));
975 switch (s
.length
- imax
) {
977 b10
= getbyte(s
,i
) << 16;
978 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
982 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
983 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
984 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
992 function getLastCommit()
995 if(sessionStarted
){ urlHead
= "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
;}
997 // TODO: get url of the original repo.
1002 beforeSend
: function (xhr
) {
1003 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1009 success
: function(success
)
1011 shaLastCommit
= success
.object
.sha
;
1016 function getBaseTree()
1019 beforeSend
: function (xhr
) {
1020 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1023 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits/" + shaLastCommit
,
1026 success
: function(success
)
1028 shaBaseTree
= success
.tree
.sha
;
1029 if (state
){ setBlob(); }
1038 function setNewTree()
1041 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1043 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/trees",
1046 data
:'{ "base_tree" : "'+shaBaseTree
+'", '+
1048 '"path":"'+ pathFile
+'",'+
1051 '"sha": "'+ shaBlob
+'"'+
1054 success
: function(success
)
1055 { // si l'appel a bien fonctionné
1056 shaNewTree
= success
.sha
;
1065 function setNewCommit()
1069 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1071 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits",
1074 data
:'{ "message" : "'+ commitMessage
+'", '+
1075 '"parents" :"'+shaLastCommit
+'",'+
1076 '"tree": "'+shaNewTree
+'"'+
1078 success
: function(success
)
1080 shaNewCommit
= success
.sha
;
1093 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1095 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1097 data
:'{ "sha" : "'+shaNewCommit
+'", '+
1100 success
: function(success
) { displayMessage('Commit created successfully', 40, 40); },
1101 error
:function(error
){ displayMessage('Error ' + error
.object
.message
, 40, 40); }
1109 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1111 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/blobs",
1114 data
:'{ "content" : "'+text
.replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"')+'", '+
1115 '"encoding" :"utf-8"'+
1117 success
: function(success
)
1119 shaBlob
= success
.sha
;
1122 error
:function(error
){
1123 displayMessage('Error : Problem parsing JSON', 40, 40);
1129 // Display file content
1130 function getFileContent(urlFile
, newComment
)
1133 beforeSend
: function (xhr
) {
1134 xhr
.setRequestHeader ("Accept", "application/vnd.github-blob.raw");
1135 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1140 success
: function(success
)
1143 replaceComment(newComment
, success
);
1148 function replaceComment(newComment
, fileContent
){
1149 var arrayNew
= newComment
.split('\n');
1150 var lNew
= arrayNew
.length
;
1152 var lines
= fileContent
.split("\n");
1153 for (var i
= 0; i
< lines
.length
; i
++) {
1154 if(i
== commentLineStart
){
1156 for(var indexLine
=0; indexLine
< lines
[i
+1].length
; indexxLine
++){
1157 if(lines
[i
+1].substr(indexLine
,1) == "\t" || lines
[i
+1].substr(indexLine
,1) == "#"){ text
+= lines
[i
+1].substr(indexLine
,1); }
1160 text
+= lines
[i] + "\n";
1162 // We change the comment
1163 for(var j
= 0; j
< lNew
; j
++){
1164 if(commentType
== 1){ text
+= "\t# " + arrayNew
[j] + "\n"; }
1166 if(arrayNew
[j] == ""){ text
+= "#"+"\n"; }
1167 else{ text
+= "# " + arrayNew
[j] + "\n"; }
1171 else if(i
< commentLineStart || i
>= commentLineEnd
){
1172 if(i
== lines
.length
-1){ text
+= lines
[i]; }
1173 else{ text
+= lines
[i] + "\n"; }
1177 addNewComment
= false;
1181 function getCommentLastCommit(path
, origin
){
1184 if(origin
){// We want to get the original file
1185 bkBranch
= branchName
;
1186 branchName
= "master";
1189 if(shaLastCommit
!= ""){
1190 if (checkCookie()) {
1191 urlRaw
="https://rawgithub.com/"+ userName
+"/"+ githubRepo
+"/" + shaLastCommit
+ "/" + path
;
1196 success
: function(success
)
1198 if(origin
){ originalFileContent
= success
; }
1199 else{ currentfileContent
= success
; }
1204 if(origin
){ branchName
= bkBranch
; }
1207 function displayMessage(msg
, widthDiv
, margModal
){
1210 $
('#btnCancelBranch').hide();
1211 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1212 $
('#txtQuestion').text(msg
);
1213 $
('#btnCreateBranch').text("Ok");
1214 var xModal
= $
('#modalQuestion').css('width').split('px')[0];
1215 var yModal
= $
('#modalQuestion').css('height').split('px')[0];
1216 var x
= $
(document
).width
/2 - xModal
/2;
1217 var y
= $
(document
).height
/2 - yModal
/2;
1218 var xBtnBranch
= $
('#btnCreateBranch').css('width').split('px')[0];
1219 $
('#modalQuestion').css({'left' : x
, 'top' : y
});
1220 $
('#modalQuestion').show();
1221 $
('#btnCreateBranch').css('margin-left', xModal
/2 - xBtnBranch
);
1222 $
('body').append('<div id="fade"></div>');
1223 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1226 function displaySpinner(){
1227 spinner
.spin(targetSpinner
);
1228 $
("#waitCommit").show();
1231 // Check if the repo already exist
1232 function isRepoExisting(){
1234 beforeSend
: function (xhr
) {
1235 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1238 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1241 success
: function(){ repoExist
= true; },
1244 displayMessage('Repo not found !', 35, 45);
1250 // Check if the branch already exist
1251 function isBranchExisting(){
1253 beforeSend
: function (xhr
) {
1254 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1257 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1260 success
: function(){ branchExist
= true; },
1263 branchExist
= false;
1266 $
('#txtQuestion').text("Are you sure you want to create that branch ?");
1267 $
('#btnCancelBranch').show();
1268 $
('#btnCreateBranch').text("Yes");
1269 $
('#modalQuestion').show();
1270 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1271 $
('body').append('<div id="fade"></div>');
1272 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1277 function getMasterSha()
1280 beforeSend
: function (xhr
) {
1281 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1284 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/master",
1287 success
: function(success
) { shaMaster
= success
.object
.sha
; }
1291 function createBranch(){
1296 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1298 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs",
1299 data
:'{ "ref" : "refs/heads/'+branchName
+'",'+
1300 '"sha" : "'+shaMaster
+'"'+
1302 success
: function(){ return; },
1305 displayMessage('Impossible to create the new branch : ' + branchName
, 40, 40);
1310 $
.fn
.spin
= function(opts
) {
1311 this.each(function() {
1312 var $
this = $
(this),
1313 data
= $
this.data();
1316 data
.spinner
.stop();
1317 delete data
.spinner
;
1319 if (opts
!== false) {
1320 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);
1326 function reloadComment(){
1327 var path
= $
('pre[class=text_label]').attr('tag');
1328 $
.when(getCommentLastCommit(path
, false)).done(function(){
1329 if(sessionStarted
){ getCommentLastCommit(path
, true); }
1330 $
('pre[class=text_label]').each(function(){ getCommentOfFunction($
(this)); });
1334 function getCommentOfFunction(element
){
1336 var numL
= element
.attr("title");
1338 commentLineStart
= numL
-1;
1339 commentLineEnd
= element
.attr('name').split(numL
)[1].split('-')[1]-1;
1340 var lines
= currentfileContent
.split("\n");
1341 for (var i
= 0; i
< lines
.length
; i
++) {
1342 if(i
>= commentLineStart
-1 && i
<= commentLineEnd
+1){
1343 if (lines
[i].substr(1,1) == "#"){ textC
+= lines
[i].substr(3,lines
[i].length
) + "\n";}
1344 else if(lines
[i].substr(0,1) == '#'){ textC
+= lines
[i].substr(2,lines
[i].length
) + "\n"; }
1347 if(textC
!= element
.text
){element
.text(textC
);}
1348 if (textC
!= "" && editComment
> 0){
1349 var originContent
= originalFileContent
.split("\n");
1351 var lblDiff
= element
.parent().prev().children('#lblDiffCommit');
1352 var preSave
= element
.parent().children('#preSave');
1353 for (var i
= 0; i
< originContent
.length
; i
++) {
1354 if(i
>= commentLineStart
-1 && i
<= commentLineEnd
+1){
1355 if (originContent
[i].substr(1,1) == "#"){ origin
+= originContent
[i].substr(3,originContent
[i].length
) + "\n";}
1356 else if(originContent
[i].substr(0,1) == '#'){ origin
+= originContent
[i].substr(2,originContent
[i].length
) + "\n"; }
1359 if(textC
!= origin
&& numL
== numComment
){
1360 // The comment is different compare to the original
1361 if(showcomment
== false){ lblDiff
.text("Show original comment"); }
1362 preSave
.text(origin
);
1364 else if (numL
== numComment
){ lblDiff
.text(""); }
1369 // Get list of branches
1370 function getListBranches()
1372 cleanListBranches();
1374 beforeSend
: function (xhr
) {
1375 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1378 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/branches",
1381 success
: function(success
)
1383 for(var branch
in success
) {
1385 if(branchName
== success
[branch].name
){
1386 selected
= 'selected';
1388 $
('#dropBranches').append('<option value="" '+ selected
+'>' + success
[branch].name
+ '</option>');
1394 // Delete all option in the list
1395 function cleanListBranches(){
1396 $
('#dropBranches').children("option").remove();
1399 function closeAllCommentInEdtiting(){
1400 $
('a[id=cancelBtn]').each(function(){
1401 closeEditing($
(this));
1405 function closeEditing(tag
){
1406 if(editComment
> 0){ editComment
-= 1; }
1414 tag
.prev().prev().show();
1417 function checkSignIn(){
1418 var response
= false;
1420 beforeSend
: function (xhr
) {
1421 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1424 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1427 success
: function(success
)
1431 displayMessage('You are now logged in');
1435 displayMessage('Error : Wrong username or password');
1442 function getUserInfo(){
1444 beforeSend
: function (xhr
) {
1445 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1448 url
: "https://api.github.com/user/emails",
1451 success
: function(success
)
1453 userEmail
= success
;
1458 function getSignedOff(){
1460 beforeSend
: function (xhr
) {
1461 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1464 url
: "https://api.github.com/users/"+userName
,
1467 success
: function(success
)
1469 signedOff
= success
.name
;
1474 function addSignedOff(){
1475 $
.when(getUserInfo()).done(function(){
1476 $
.when(getSignedOff()).done(function(){
1477 $
('#commitMessage').val($
('#commitMessage').val() + "\n\nSigned-off-by: "+signedOff
+" <"+userEmail
+">");
1480 resizeTextarea($
('#commitMessage'));
1483 function removeSignedOff(){
1484 $
('#commitMessage').val(commitMessage
);
1485 resizeTextarea($
('#commitMessage'));
1488 function resizeTextarea(element
){
1489 var nLines
= element
.val().split('\n').length
+ 1;
1490 element
.attr('rows', nLines
);
1493 function showComment(element
){
1494 // Display the original comment
1495 if (showcomment
== true){
1496 showcomment
= false;
1497 element
.text("Show original comment");
1500 // Show the comment updated in user's repo
1502 element
.text("Comment changed in "+githubRepo
+" / "+branchName
);
1504 var parent
= element
.parent().next(".description");
1505 var textarea
= parent
.children('#fileContent');
1506 var text
= textarea
.val();
1507 var preSave
= parent
.children('#preSave');
1508 textarea
.val(preSave
.text());
1511 textarea
.height(textarea
.prop("scrollHeight"));
1512 resizeTextarea(textarea
);