5 var sessionStarted
= false;
7 var currentfileContent
= '';
8 var addNewComment
= false;
13 var shaLastCommit
= "";
19 var repoExist
= false;
20 var branchExist
= false;
22 var loginProcess
= false;
25 var commitMessage
= '';
29 lines
: 11, // The number of lines to draw
30 length
: 7, // The length of each line
31 width
: 4, // The line thickness
32 radius
: 10, // The radius of the inner circle
33 corners
: 1, // Corner roundness (0..1)
34 rotate
: 0, // The rotation offset
35 color
: '#FFF', // #rgb or #rrggbb
36 speed
: 1, // Rounds per second
37 trail
: 60, // Afterglow percentage
38 shadow
: false, // Whether to render a shadow
39 hwaccel
: false, // Whether to use hardware acceleration
40 className
: 'spinner', // The CSS class to assign to the spinner
41 zIndex
: 99999, // The z-index (defaults to 2000000000)
42 top
: '300', // Top position relative to parent in px
43 left
: 'auto' // Left position relative to parent in px
45 var targetSpinner
= document
.getElementById('waitCommit');
46 var spinner
= new Spinner(opts
).spin(targetSpinner
);
49 * JQuery Case Insensitive :icontains selector
51 $
.expr
[':'].icontains
= function(obj
, index
, meta
, stack
){
52 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;
56 * Quick Search global vars
59 // Current search results preview table
60 var currentTable
= null;
62 //Hightlighted index in search result preview table
63 var currentIndex
= -1;
65 // Check if a comment is editing
66 window
.onbeforeunload
= function() {
68 return 'Are you sure you want to leave this page?';
73 * Add folding and filtering facilities to class description page.
75 $
(document
).ready(function() {
79 $
('a[id=commitBtn]').hide();
80 $
('a[id=cancelBtn]').hide();
81 // Hide Authenfication form
86 * Highlight the spoted element
88 highlightBlock(currentAnchor());
97 $
(document
.createElement("a"))
101 .css("cursor", "pointer")
103 if($
(this).find("a.fold").html() == "+") {
104 $
(this).find("a.fold").html("-");
106 $
(this).find("a.fold").html("+");
108 $
(this).nextAll().toggle();
111 // Insert search field
114 $
(document
.createElement("li"))
116 $
(document
.createElement("form"))
118 $
(document
.createElement("input"))
123 value
: "quick search..."
131 // Select previous result on "Up"
133 // If already on first result, focus search input
134 if(currentIndex
== 0) {
135 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
136 $
("#search").focus();
137 // Else select previous result
138 } else if(currentIndex
> 0) {
139 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
141 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
142 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
143 $
("#search").focus();
147 // Select next result on "Down"
149 if(currentIndex
< currentTable
.find("tr").length
- 1) {
150 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
152 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
153 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
154 $
("#search").focus();
157 // Go to url on "Enter"
159 if(currentIndex
> -1) {
160 window
.location
= $
(currentTable
.find("tr")[currentIndex]).data("searchDetails").url
;
163 if($
("#search").val().length
== 0)
166 window
.location
= "full-index.html#q=" + $
("#search").val();
167 if(window
.location
.href
.indexOf("full-index.html") > -1) {
173 // Hide results preview on "Escape"
176 if(currentTable
!= null) {
177 currentTable
.remove();
183 if($
("#search").val().length
== 0) {
187 // Remove previous table
188 if(currentTable
!= null) {
189 currentTable
.remove();
192 // Build results table
194 currentTable
= $
(document
.createElement("table"));
196 // Escape regexp related characters in query
197 var query
= $
("#search").val();
198 query
= query
.replace(/\
[/gi
, "\\[");
199 query
= query
.replace(/\|
/gi
, "\\|");
200 query
= query
.replace(/\*/gi
, "\\*");
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
, "\\)");
208 var regexp
= new RegExp("^" + query
, "i");
209 for(var entry
in entries
) {
213 var result
= entry
.match(regexp
);
214 if(result
!= null && result
.toString().toUpperCase() == $
("#search").val().toUpperCase()) {
215 for(var i
= 0; i
< entries
[entry].length
; i
++) {
220 $
(document
.createElement("tr"))
221 .data("searchDetails", {name
: entry
, url
: entries
[entry][i]["url"]})
222 .data("index", index
)
223 .append($
(document
.createElement("td")).html(entry
))
225 $
(document
.createElement("td"))
226 .addClass("entryInfo")
227 .html(entries
[entry][i]["txt"] + " »"))
228 .mouseover( function() {
229 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
230 $
(this).addClass("activeSearchResult");
231 currentIndex
= $
(this).data("index");
233 .mouseout( function() {
234 $
(this).removeClass("activeSearchResult");
237 window
.location
= $
(this).data("searchDetails")["url"];
245 // Initialize table properties
246 currentTable
.attr("id", "searchTable");
247 currentTable
.css("position", "absolute");
248 currentTable
.width($
("#search").outerWidth());
249 $
("header").append(currentTable
);
250 currentTable
.offset({left
: $
("#search").offset().left
+ ($
("#search").outerWidth() - currentTable
.outerWidth()), top
: $
("#search").offset().top
+ $
("#search").outerHeight()});
252 // Preselect first entry
253 if(currentTable
.find("tr").length
> 0) {
255 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
256 $
("#search").focus();
261 .focusout(function() {
262 if($
(this).val() == "") {
263 $
(this).addClass("notUsed");
264 $
(this).val("quick search...");
267 .focusin(function() {
268 if($
(this).val() == "quick search...") {
269 $
(this).removeClass("notUsed");
274 .submit( function() {
280 // Close quicksearch list on click
281 $
(document
).click(function(e
) {
282 if(e
.target
!= $
("#search")[0] && e
.target
!= $
("#searchTable")[0]) {
283 if(currentTable
!= null) {
284 currentTable
.remove();
290 // Insert filter field
291 $
("article.filterable h2, nav.filterable h3")
293 $
(document
.createElement("div"))
296 $
(document
.createElement("input"))
303 $
(this).parent().parent().find("ul li:not(:icontains('" + $
(this).val() + "'))").addClass("hide");
304 $
(this).parent().parent().find("ul li:icontains('" + $
(this).val() + "')").removeClass("hide");
306 .focusout(function() {
307 if($
(this).val() == "") {
308 $
(this).addClass("notUsed");
309 $
(this).val("filter...");
312 .focusin(function() {
313 if($
(this).val() == "filter...") {
314 $
(this).removeClass("notUsed");
321 // Filter toggle between H I R in nav porperties list
322 $
("nav.properties.filterable .filter")
324 $
(document
.createElement("a"))
327 title
: "hide inherited properties"
330 if($
(this).hasClass("hidden")) {
331 $
(this).parent().parent().find("li.inherit").show();
333 $
(this).parent().parent().find("li.inherit").hide();
336 $
(this).toggleClass("hidden");
340 $
(document
.createElement("a"))
343 title
: "hide redefined properties"
346 if($
(this).hasClass("hidden")) {
347 $
(this).parent().parent().find("li.redef").show();
349 $
(this).parent().parent().find("li.redef").hide();
352 $
(this).toggleClass("hidden");
356 $
(document
.createElement("a"))
359 title
: "hide introduced properties"
362 if($
(this).hasClass("hidden")) {
363 $
(this).parent().parent().find("li.intro").show();
365 $
(this).parent().parent().find("li.intro").hide();
368 $
(this).toggleClass("hidden");
372 // Filter toggle between I R in
373 $
("article.properties.filterable .filter, article.classes.filterable .filter")
375 $
(document
.createElement("a"))
378 title
: "hide introduced properties"
381 if($
(this).hasClass("hidden")) {
382 $
(this).parent().parent().find("li.intro").show();
384 $
(this).parent().parent().find("li.intro").hide();
387 $
(this).toggleClass("hidden");
391 $
(document
.createElement("a"))
394 title
: "hide redefined properties"
397 if($
(this).hasClass("hidden")) {
398 $
(this).parent().parent().find("li.redef").show();
400 $
(this).parent().parent().find("li.redef").hide();
403 $
(this).toggleClass("hidden");
410 $
("a[href*='#']").click( function() {
411 highlightBlock($
(this).attr("href").split(/#
/)[1]);
414 //Preload filter fields with query string
416 // Hide Authenfication form
417 $
(".popover").hide();
418 // Display Login modal
419 $
("#logGitHub").click(function(){ displayLogginModal(); });
422 // If cookie existing the session is opened
423 if(sessionStarted
){ userB64
= "Basic " + getUserPass("logginNitdoc"); }
425 // Sign In an github user or Log out him
426 $
("#signIn").click(function(){
428 if($
('#loginGit').val() == "" || $
('#passwordGit').val() == ""){ displayMessage('Please informed login/password field!', 40, 45); }
431 userName
= $
('#loginGit').val();
432 password
= $
('#passwordGit').val();
433 githubRepo
= $
('#repositoryGit').val();
434 branchName
= $
('#branchGit').val();
435 userB64
= "Basic " + base64
.encode(userName
+':'+password
);
437 // Check if repo exist
440 $
.when(isBranchExisting()).done(function(){
443 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+githubRepo
+':'+branchName
), 1);
444 $
('#loginGit').val("");
445 $
('#passwordGit').val("");
455 // Delete cookie and reset settings
456 del_cookie("logginNitdoc");
457 closeAllCommentInEdtiting();
459 displayLogginModal();
462 // Activate edit mode
463 $
('pre[class=text_label]').click(function(){
464 // the customer is loggued ?
465 if(!sessionStarted || userName
== ""){
466 // No => nothing happen
470 var arrayNew
= $
(this).text().split('\n');
471 var lNew
= arrayNew
.length
- 1;
474 for (var i
= 0; i
< lNew
; i
++) {
475 adapt
+= arrayNew
[i];
476 if(i
< lNew
-1){ adapt
+= "\n"; }
482 $
(this).next().show();
483 // Show cancel button
484 $
(this).next().next().show();
485 // Show commit button
486 $
(this).next().next().next().show();
487 // Add text in edit box
488 if($
(this).next().val() == "" || $
(this).next().val() != adapt
){ $
(this).next().val(adapt
); }
490 $
(this).next().height($
(this).next().prop("scrollHeight"));
491 resizeTextarea($
(this).next());
493 $
(this).next().select();
494 preElement
= $
(this);
498 // Disable the edit mode
499 $
('a[id=cancelBtn]').click(function(){
500 closeEditing($
(this));
503 // Display commit form
504 $
('a[id=commitBtn]').click(function(){
505 $
(this).parent().prev().children('#lblDiffCommit').text("");
507 updateComment
= $
(this).prev().prev().val();
508 commentType
= $
(this).prev().prev().prev().attr('type');
510 if(updateComment
== ""){ displayMessage('The comment field is empty!', 40, 45); }
513 displayMessage("You need to be loggued before commit something", 45, 40);
514 displayLogginModal();
518 // Create the commit message
519 commitMessage
= 'Wikidoc: modified comment in ' + $
(this).parent().prev().html().split(' ')[1];
520 $
('#commitMessage').text(commitMessage
);
521 $
('#commitMessage').css({'display': 'block'});
522 pathFile
= $
(this).prev().prev().prev().attr('tag');
523 $
('#modal').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btn_close" title="Close" alt="Close" /></a>');
524 $
('body').append('<div id="fade"></div>');
525 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
530 $
('.btn_close').click(function(){
532 $
(this).next().hide();
533 if(editComment
> 0){ editComment
-= 1; }
534 $
('#chkSignedOff').attr('checked', false);
538 //Close Popups and Fade Layer
539 $
('body').on('click', 'a.close, #fade', function() {
540 if(editComment
> 0){ editComment
-= 1; }
541 $
('#fade , #modal').fadeOut(function() {
542 $
('#fade, a.close').remove();
544 $
('#modalQuestion').hide();
545 $
('#chkSignedOff').attr('checked', false);
549 $
('#loginAction').click(function(){
553 // Look if the customer is logged
555 displayMessage("You need to be loggued before commit something", 100, 40);
556 $
('.popover').show();
559 else{ userB64
= "Basic " + getUserPass("logginNitdoc"); }
560 // Check if repo exist
566 commitMessage
= $
('#commitMessage').val().replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"');
567 if(commitMessage
== ""){ commitMessage
= "New commit";}
569 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
572 startCommitProcess();
575 $
('#modal, #modalQuestion').fadeOut(function() {
577 $
('#password').val("");
578 $
('textarea').hide();
579 $
('textarea').prev().show();
581 $
('a[id=cancelBtn]').hide();
582 $
('a[id=commitBtn]').hide();
583 // Re-load all comment
587 else{ editComment
-= 1; }
588 $
('#chkSignedOff').attr('checked', false);
591 // Cancel creating branch
592 $
('#btnCancelBranch').click(function(){
594 $
('#modalQuestion').hide();
595 $
('#fade , #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
599 // Create new branch and continu
600 $
('#btnCreateBranch').click(function(){
601 $
('#modalQuestion').hide();
602 if($
('#btnCreateBranch').text() != 'Ok'){
605 commitMessage
= $
('#commitMessage').val().replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"');
606 if(commitMessage
== ""){ commitMessage
= "New commit"; }
609 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+githubRepo
+':'+branchName
), 1);
610 $
('#loginGit').val("");
611 $
('#passwordGit').val("");
612 loginProcess
= false;
613 displayLogginModal();
616 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
617 else{ startCommitProcess(); }
623 $
('#fade , #modalQuestion, #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
627 $
('a[class=newComment]').click(function(){
628 addNewComment
= true;
633 $
(this).next().show();
634 // Show cancel button
635 $
(this).next().next().show();
636 // Show commit button
637 $
(this).next().next().next().show();
639 $
(this).next().height($
(this).next().prop("scrollHeight"));
640 resizeTextarea($
(this).next());
642 $
(this).next().select();
643 preElement
= $
(this);
646 $
("#dropBranches").change(function () {
647 $
("#dropBranches option:selected").each(function () {
648 if(branchName
!= $
(this).text()){
649 branchName
= $
(this).text();
652 $
.when(updateCookie(userName
, password
, githubRepo
, branchName
)).done(function(){
653 closeAllCommentInEdtiting();
660 if(sessionStarted
== true){
661 $
(this).css({'cursor' : 'hand'});
664 $
(this).css({'cursor' : ''});
668 if(sessionStarted
== true){
669 $
(this).css({'cursor' : 'pointer'});
672 $
(this).css({'cursor' : ''});
677 $
('#chkSignedOff').click(function(){
678 if($
(this).is(':checked')){ addSignedOff(); }
679 else{ removeSignedOff(); }
683 /* Parse current URL and return anchor name */
684 function currentAnchor() {
685 var index
= document
.location
.hash
.indexOf("#");
687 return document
.location
.hash
.substring(index
+ 1);
692 /* Prealod filters field using search query */
693 function preloadFilters() {
694 // Parse URL and get query string
695 var search
= currentAnchor();
697 if(search
== null || search
.indexOf("q=") == -1)
700 search
= search
.substring(2, search
.length
);
702 if(search
== "" || search
== "undefined")
705 $
(":text").val(search
);
707 .removeClass("notUsed")
712 /* Hightlight the spoted block */
713 function highlightBlock(a
) {
718 $
(".highlighted").removeClass("highlighted");
720 var target
= $
("#" + a
);
722 if(target
.is("article")) {
723 target
.parent().addClass("highlighted");
726 target
.addClass("highlighted");
730 // Init process to commit the new comment
731 function startCommitProcess()
733 if($
('#chkSignedOff').is(':checked')){
734 var numL
= preElement
.attr("title");
735 commentLineStart
= numL
.split('-')[0] - 1;
736 if(addNewComment
) { commentLineStart
++; }
737 commentLineEnd
= (commentLineStart
+ preElement
.text().split('\n').length
) - 1;
739 replaceComment(updateComment
, currentfileContent
);
745 displayMessage('Please sign this commit', 40, 40);
749 function displayLogginModal(){
750 if ($
('.popover').is(':hidden')) {
751 if(sessionStarted
){ getListBranches(); }
752 $
('.popover').show();
754 else { $
('.popover').hide(); }
758 function updateDisplaying(){
761 userB64
= "Basic " + getUserPass("logginNitdoc");
762 $
('#loginGit').hide();
763 $
('#passwordGit').hide();
764 $
('#lbpasswordGit').hide();
765 $
('#lbloginGit').hide();
766 $
('#repositoryGit').hide();
767 $
('#lbrepositoryGit').hide();
768 $
('#lbbranchGit').hide();
769 $
('#branchGit').hide();
770 $
('#listBranches').show();
771 $
('#divGitHubRepoDisplay').show();
772 $
("#liGitHub").attr("class", "current");
773 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
774 $
('#nickName').text(userName
);
775 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
776 $
('#logginMessage').css({'display' : 'block'});
777 $
('#logginMessage').css({'text-align' : 'center'});
778 $
('.popover').css({'height' : '190px'});
779 $
('#signIn').text("Sign out");
780 $
('#githubRepoDisplay').text(githubRepo
);
781 sessionStarted
= true;
786 sessionStarted
= false;
787 $
('#logginMessage').css({'display' : 'none'});
788 $
("#liGitHub").attr("class", "");
789 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
790 $
('#loginGit').val("");
791 $
('#passwordGit').val("");
792 $
('#nickName').text("");
793 $
('.popover').css({'height' : '325px'});
794 $
('#logginMessage').css({'display' : 'none'});
795 $
('#repositoryGit').val($
('#repoName').attr('name'));
796 $
('#branchGit').val('wikidoc');
797 $
('#signIn').text("Sign In");
798 $
('#loginGit').show();
799 $
('#passwordGit').show();
800 $
('#lbpasswordGit').show();
801 $
('#lbloginGit').show();
802 $
('#repositoryGit').show();
803 $
('#lbrepositoryGit').show();
804 $
('#lbbranchGit').show();
805 $
('#branchGit').show();
806 $
('#listBranches').hide();
807 $
('#divGitHubRepoDisplay').hide();
811 function setCookie(c_name
, value
, exdays
)
813 var exdate
=new Date();
814 exdate
.setDate(exdate
.getDate() + exdays
);
815 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
816 document
.cookie
=c_name
+ "=" + c_value
;
819 function del_cookie(c_name
)
821 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
824 function updateCookie(user
, pwd
, repo
, branch
){
827 setCookie("logginNitdoc", base64
.encode(user
+':'+pwd
+':'+repo
+':'+branch
), 1);
831 function getCookie(c_name
)
833 var c_value
= document
.cookie
;
834 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
835 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
836 if (c_start
== -1) { c_value
= null; }
839 c_start
= c_value
.indexOf("=", c_start
) + 1;
840 var c_end
= c_value
.indexOf(";", c_start
);
841 if (c_end
== -1) { c_end
= c_value
.length
; }
842 c_value
= unescape(c_value
.substring(c_start
,c_end
));
847 function getUserPass(c_name
){
848 var cookie
= base64
.decode(getCookie(c_name
));
849 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
852 function checkCookie()
854 var cookie
=getCookie("logginNitdoc");
855 if (cookie
!=null && cookie
!="")
857 cookie
= base64
.decode(cookie
);
858 userName
= cookie
.split(':')[0];
859 password
= cookie
.split(':')[1];
860 githubRepo
= cookie
.split(':')[2];
861 branchName
= cookie
.split(':')[3];
864 else { return false; }
872 base64
.PADCHAR
= '=';
873 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
874 base64
.getbyte64
= function(s
,i
) {
875 // This is oddly fast, except on Chrome/V8.
876 // Minimal or no improvement in performance by using a
877 // object with properties mapping chars to value (eg. 'A': 0)
878 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
880 throw "Cannot decode base64";
885 base64
.decode
= function(s
) {
888 var getbyte64
= base64
.getbyte64
;
896 throw "Cannot decode base64";
900 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
902 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
905 // either way, we want to ignore this last block
910 for (i
= 0; i
< imax
; i
+= 4) {
911 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
912 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
913 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
918 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
919 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
922 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
923 x
.push(String
.fromCharCode(b10
>> 16));
929 base64
.getbyte
= function(s
,i
) {
930 var x
= s
.charCodeAt(i
);
932 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
938 base64
.encode
= function(s
) {
939 if (arguments
.length
!= 1) {
940 throw "SyntaxError: Not enough arguments";
942 var padchar
= base64
.PADCHAR
;
943 var alpha
= base64
.ALPHA
;
944 var getbyte
= base64
.getbyte
;
952 var imax
= s
.length
- s
.length
% 3;
957 for (i
= 0; i
< imax
; i
+= 3) {
958 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
959 x
.push(alpha
.charAt(b10
>> 18));
960 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
961 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
962 x
.push(alpha
.charAt(b10
& 0x3f));
964 switch (s
.length
- imax
) {
966 b10
= getbyte(s
,i
) << 16;
967 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
971 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
972 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
973 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
981 function getLastCommit()
984 if(sessionStarted
){ urlHead
= "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
;}
986 // TODO: get url of the original repo.
991 beforeSend
: function (xhr
) {
992 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
998 success
: function(success
)
1000 shaLastCommit
= success
.object
.sha
;
1005 function getBaseTree()
1008 beforeSend
: function (xhr
) {
1009 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1012 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits/" + shaLastCommit
,
1015 success
: function(success
)
1017 shaBaseTree
= success
.tree
.sha
;
1018 if (state
){ setBlob(); }
1027 function setNewTree()
1030 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1032 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/trees",
1035 data
:'{ "base_tree" : "'+shaBaseTree
+'", '+
1037 '"path":"'+ pathFile
+'",'+
1040 '"sha": "'+ shaBlob
+'"'+
1043 success
: function(success
)
1044 { // si l'appel a bien fonctionné
1045 shaNewTree
= success
.sha
;
1054 function setNewCommit()
1058 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1060 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits",
1063 data
:'{ "message" : "'+ commitMessage
+'", '+
1064 '"parents" :"'+shaLastCommit
+'",'+
1065 '"tree": "'+shaNewTree
+'"'+
1067 success
: function(success
)
1069 shaNewCommit
= success
.sha
;
1082 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1084 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1086 data
:'{ "sha" : "'+shaNewCommit
+'", '+
1089 success
: function(success
) { displayMessage('Commit created successfully', 40, 40); },
1090 error
:function(error
){ displayMessage('Error ' + error
.object
.message
, 40, 40); }
1098 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1100 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/blobs",
1103 data
:'{ "content" : "'+text
.replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"')+'", '+
1104 '"encoding" :"utf-8"'+
1106 success
: function(success
)
1108 shaBlob
= success
.sha
;
1111 error
:function(error
){
1112 displayMessage('Error : Problem parsing JSON', 40, 40);
1118 // Display file content
1119 function getFileContent(urlFile
, newComment
)
1122 beforeSend
: function (xhr
) {
1123 xhr
.setRequestHeader ("Accept", "application/vnd.github-blob.raw");
1124 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1129 success
: function(success
)
1132 replaceComment(newComment
, success
);
1137 function replaceComment(newComment
, fileContent
){
1138 var arrayNew
= newComment
.split('\n');
1139 var lNew
= arrayNew
.length
;
1141 var lines
= fileContent
.split("\n");
1142 for (var i
= 0; i
< lines
.length
; i
++) {
1143 if(i
== commentLineStart
){
1145 for(var indexLine
=0; indexLine
< lines
[i
+1].length
; indexxLine
++){
1146 if(lines
[i
+1].substr(indexLine
,1) == "\t" || lines
[i
+1].substr(indexLine
,1) == "#"){ text
+= lines
[i
+1].substr(indexLine
,1); }
1149 text
+= lines
[i] + "\n";
1151 // We change the comment
1152 for(var j
= 0; j
< lNew
; j
++){
1153 if(commentType
== 1){ text
+= "\t# " + arrayNew
[j] + "\n"; }
1155 if(arrayNew
[j] == ""){ text
+= "#"+"\n"; }
1156 else{ text
+= "# " + arrayNew
[j] + "\n"; }
1160 else if(i
< commentLineStart || i
>= commentLineEnd
){
1161 if(i
== lines
.length
-1){ text
+= lines
[i]; }
1162 else{ text
+= lines
[i] + "\n"; }
1166 addNewComment
= false;
1170 function getCommentLastCommit(path
){
1173 if(shaLastCommit
!= ""){
1174 if (checkCookie()) {
1175 urlRaw
="https://rawgithub.com/"+ userName
+"/"+ githubRepo
+"/" + shaLastCommit
+ "/" + path
;
1180 success
: function(success
)
1182 currentfileContent
= success
;
1189 function displayMessage(msg
, widthDiv
, margModal
){
1192 $
('#btnCancelBranch').hide();
1193 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1194 $
('#txtQuestion').text(msg
);
1195 $
('#btnCreateBranch').text("Ok");
1196 var xModal
= $
('#modalQuestion').css('width').split('px')[0];
1197 var yModal
= $
('#modalQuestion').css('height').split('px')[0];
1198 var x
= $
(document
).width
/2 - xModal
/2;
1199 var y
= $
(document
).height
/2 - yModal
/2;
1200 var xBtnBranch
= $
('#btnCreateBranch').css('width').split('px')[0];
1201 $
('#modalQuestion').css({'left' : x
, 'top' : y
});
1202 $
('#modalQuestion').show();
1203 $
('#btnCreateBranch').css('margin-left', xModal
/2 - xBtnBranch
);
1204 $
('body').append('<div id="fade"></div>');
1205 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1208 function displaySpinner(){
1209 spinner
.spin(targetSpinner
);
1210 $
("#waitCommit").show();
1213 // Check if the repo already exist
1214 function isRepoExisting(){
1216 beforeSend
: function (xhr
) {
1217 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1220 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1223 success
: function(){ repoExist
= true; },
1226 displayMessage('Repo not found !', 35, 45);
1232 // Check if the branch already exist
1233 function isBranchExisting(){
1235 beforeSend
: function (xhr
) {
1236 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1239 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1242 success
: function(){ branchExist
= true; },
1245 branchExist
= false;
1248 $
('#txtQuestion').text("Are you sure you want to create that branch ?");
1249 $
('#btnCancelBranch').show();
1250 $
('#btnCreateBranch').text("Yes");
1251 $
('#modalQuestion').show();
1252 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1253 $
('body').append('<div id="fade"></div>');
1254 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1259 function getMasterSha()
1262 beforeSend
: function (xhr
) {
1263 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1266 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/master",
1269 success
: function(success
) { shaMaster
= success
.object
.sha
; }
1273 function createBranch(){
1278 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1280 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs",
1281 data
:'{ "ref" : "refs/heads/'+branchName
+'",'+
1282 '"sha" : "'+shaMaster
+'"'+
1284 success
: function(){ return; },
1287 displayMessage('Impossible to create the new branch : ' + branchName
, 40, 40);
1292 $
.fn
.spin
= function(opts
) {
1293 this.each(function() {
1294 var $
this = $
(this),
1295 data
= $
this.data();
1298 data
.spinner
.stop();
1299 delete data
.spinner
;
1301 if (opts
!== false) {
1302 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);
1308 function reloadComment(){
1309 $
.when(getCommentLastCommit($
('pre[class=text_label]').attr('tag'))).done(function(){
1310 $
('pre[class=text_label]').each(function(){ getCommentOfFunction($
(this)); });
1314 function getCommentOfFunction(element
){
1316 var numL
= element
.attr("title");
1318 commentLineStart
= numL
.split('-')[0] - 1;
1319 commentLineEnd
= (commentLineStart
+ element
.text().split('\n').length
) - 1;
1320 var lines
= currentfileContent
.split("\n");
1321 for (var i
= 0; i
< lines
.length
; i
++) {
1322 if(i
>= commentLineStart
-1 && i
<= commentLineEnd
){
1323 if (lines
[i].substr(1,1) == "#"){ textC
+= lines
[i].substr(3,lines
[i].length
) + "\n";}
1324 else if(lines
[i].substr(0,1) == '#'){ textC
+= lines
[i].substr(2,lines
[i].length
) + "\n"; }
1327 if (textC
!= ""){ element
.text(textC
); }
1331 // Get list of branches
1332 function getListBranches()
1334 cleanListBranches();
1336 beforeSend
: function (xhr
) {
1337 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1340 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/branches",
1343 success
: function(success
)
1345 for(var branch
in success
) {
1347 if(branchName
== success
[branch].name
){
1348 selected
= 'selected';
1350 $
('#dropBranches').append('<option value="" '+ selected
+'>' + success
[branch].name
+ '</option>');
1356 // Delete all option in the list
1357 function cleanListBranches(){
1358 $
('#dropBranches').children("option").remove();
1361 function closeAllCommentInEdtiting(){
1362 $
('a[id=cancelBtn]').each(function(){
1363 closeEditing($
(this));
1367 function closeEditing(tag
){
1368 if(editComment
> 0){ editComment
-= 1; }
1376 tag
.prev().prev().show();
1379 function checkSignIn(){
1380 var response
= false;
1382 beforeSend
: function (xhr
) {
1383 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1386 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1389 success
: function(success
)
1393 displayMessage('You are now logged in');
1397 displayMessage('Error : Wrong username or password');
1404 function getUserInfo(){
1406 beforeSend
: function (xhr
) {
1407 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1410 url
: "https://api.github.com/user/emails",
1413 success
: function(success
)
1415 userEmail
= success
;
1420 function getSignedOff(){
1422 beforeSend
: function (xhr
) {
1423 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1426 url
: "https://api.github.com/users/"+userName
,
1429 success
: function(success
)
1431 signedOff
= success
.name
;
1436 function addSignedOff(){
1437 $
.when(getUserInfo()).done(function(){
1438 $
.when(getSignedOff()).done(function(){
1439 $
('#commitMessage').val($
('#commitMessage').val() + "\n\nSigned-off-by: "+signedOff
+" <"+userEmail
+">");
1442 resizeTextarea($
('#commitMessage'));
1445 function removeSignedOff(){
1446 $
('#commitMessage').val(commitMessage
);
1447 resizeTextarea($
('#commitMessage'));
1450 function resizeTextarea(element
){
1451 var nLines
= element
.val().split('\n').length
+ 1;
1452 element
.attr('rows', nLines
);