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;
26 lines
: 11, // The number of lines to draw
27 length
: 7, // The length of each line
28 width
: 4, // The line thickness
29 radius
: 10, // The radius of the inner circle
30 corners
: 1, // Corner roundness (0..1)
31 rotate
: 0, // The rotation offset
32 color
: '#FFF', // #rgb or #rrggbb
33 speed
: 1, // Rounds per second
34 trail
: 60, // Afterglow percentage
35 shadow
: false, // Whether to render a shadow
36 hwaccel
: false, // Whether to use hardware acceleration
37 className
: 'spinner', // The CSS class to assign to the spinner
38 zIndex
: 99999, // The z-index (defaults to 2000000000)
39 top
: '300', // Top position relative to parent in px
40 left
: 'auto' // Left position relative to parent in px
42 var targetSpinner
= document
.getElementById('waitCommit');
43 var spinner
= new Spinner(opts
).spin(targetSpinner
);
46 * JQuery Case Insensitive :icontains selector
48 $
.expr
[':'].icontains
= function(obj
, index
, meta
, stack
){
49 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;
53 * Quick Search global vars
56 // Current search results preview table
57 var currentTable
= null;
59 //Hightlighted index in search result preview table
60 var currentIndex
= -1;
62 // Check if a comment is editing
63 window
.onbeforeunload
= function() {
65 return 'Are you sure you want to leave this page?';
70 * Add folding and filtering facilities to class description page.
72 $
(document
).ready(function() {
76 $
('a[id=commitBtn]').hide();
77 $
('a[id=cancelBtn]').hide();
78 // Hide Authenfication form
83 * Highlight the spoted element
85 highlightBlock(currentAnchor());
94 $
(document
.createElement("a"))
98 .css("cursor", "pointer")
100 if($
(this).find("a.fold").html() == "+") {
101 $
(this).find("a.fold").html("-");
103 $
(this).find("a.fold").html("+");
105 $
(this).nextAll().toggle();
108 // Insert search field
111 $
(document
.createElement("li"))
113 $
(document
.createElement("form"))
115 $
(document
.createElement("input"))
120 value
: "quick search..."
128 // Select previous result on "Up"
130 // If already on first result, focus search input
131 if(currentIndex
== 0) {
132 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
133 $
("#search").focus();
134 // Else select previous result
135 } else if(currentIndex
> 0) {
136 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
138 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
139 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
140 $
("#search").focus();
144 // Select next result on "Down"
146 if(currentIndex
< currentTable
.find("tr").length
- 1) {
147 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
149 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
150 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
151 $
("#search").focus();
154 // Go to url on "Enter"
156 if(currentIndex
> -1) {
157 window
.location
= $
(currentTable
.find("tr")[currentIndex]).data("searchDetails").url
;
160 if($
("#search").val().length
== 0)
163 window
.location
= "full-index.html#q=" + $
("#search").val();
164 if(window
.location
.href
.indexOf("full-index.html") > -1) {
170 // Hide results preview on "Escape"
173 if(currentTable
!= null) {
174 currentTable
.remove();
180 if($
("#search").val().length
== 0) {
184 // Remove previous table
185 if(currentTable
!= null) {
186 currentTable
.remove();
189 // Build results table
191 currentTable
= $
(document
.createElement("table"));
193 // Escape regexp related characters in query
194 var query
= $
("#search").val();
195 query
= query
.replace(/\
[/gi
, "\\[");
196 query
= query
.replace(/\|
/gi
, "\\|");
197 query
= query
.replace(/\*/gi
, "\\*");
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
, "\\)");
205 var regexp
= new RegExp("^" + query
, "i");
206 for(var entry
in entries
) {
210 var result
= entry
.match(regexp
);
211 if(result
!= null && result
.toString().toUpperCase() == $
("#search").val().toUpperCase()) {
212 for(var i
= 0; i
< entries
[entry].length
; i
++) {
217 $
(document
.createElement("tr"))
218 .data("searchDetails", {name
: entry
, url
: entries
[entry][i]["url"]})
219 .data("index", index
)
220 .append($
(document
.createElement("td")).html(entry
))
222 $
(document
.createElement("td"))
223 .addClass("entryInfo")
224 .html(entries
[entry][i]["txt"] + " »"))
225 .mouseover( function() {
226 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
227 $
(this).addClass("activeSearchResult");
228 currentIndex
= $
(this).data("index");
230 .mouseout( function() {
231 $
(this).removeClass("activeSearchResult");
234 window
.location
= $
(this).data("searchDetails")["url"];
242 // Initialize table properties
243 currentTable
.attr("id", "searchTable");
244 currentTable
.css("position", "absolute");
245 currentTable
.width($
("#search").outerWidth());
246 $
("header").append(currentTable
);
247 currentTable
.offset({left
: $
("#search").offset().left
+ ($
("#search").outerWidth() - currentTable
.outerWidth()), top
: $
("#search").offset().top
+ $
("#search").outerHeight()});
249 // Preselect first entry
250 if(currentTable
.find("tr").length
> 0) {
252 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
253 $
("#search").focus();
258 .focusout(function() {
259 if($
(this).val() == "") {
260 $
(this).addClass("notUsed");
261 $
(this).val("quick search...");
264 .focusin(function() {
265 if($
(this).val() == "quick search...") {
266 $
(this).removeClass("notUsed");
271 .submit( function() {
277 // Close quicksearch list on click
278 $
(document
).click(function(e
) {
279 if(e
.target
!= $
("#search")[0] && e
.target
!= $
("#searchTable")[0]) {
280 if(currentTable
!= null) {
281 currentTable
.remove();
287 // Insert filter field
288 $
("article.filterable h2, nav.filterable h3")
290 $
(document
.createElement("div"))
293 $
(document
.createElement("input"))
300 $
(this).parent().parent().find("ul li:not(:icontains('" + $
(this).val() + "'))").addClass("hide");
301 $
(this).parent().parent().find("ul li:icontains('" + $
(this).val() + "')").removeClass("hide");
303 .focusout(function() {
304 if($
(this).val() == "") {
305 $
(this).addClass("notUsed");
306 $
(this).val("filter...");
309 .focusin(function() {
310 if($
(this).val() == "filter...") {
311 $
(this).removeClass("notUsed");
318 // Filter toggle between H I R in nav porperties list
319 $
("nav.properties.filterable .filter")
321 $
(document
.createElement("a"))
324 title
: "hide inherited properties"
327 if($
(this).hasClass("hidden")) {
328 $
(this).parent().parent().find("li.inherit").show();
330 $
(this).parent().parent().find("li.inherit").hide();
333 $
(this).toggleClass("hidden");
337 $
(document
.createElement("a"))
340 title
: "hide redefined properties"
343 if($
(this).hasClass("hidden")) {
344 $
(this).parent().parent().find("li.redef").show();
346 $
(this).parent().parent().find("li.redef").hide();
349 $
(this).toggleClass("hidden");
353 $
(document
.createElement("a"))
356 title
: "hide introduced properties"
359 if($
(this).hasClass("hidden")) {
360 $
(this).parent().parent().find("li.intro").show();
362 $
(this).parent().parent().find("li.intro").hide();
365 $
(this).toggleClass("hidden");
369 // Filter toggle between I R in
370 $
("article.properties.filterable .filter, article.classes.filterable .filter")
372 $
(document
.createElement("a"))
375 title
: "hide introduced properties"
378 if($
(this).hasClass("hidden")) {
379 $
(this).parent().parent().find("li.intro").show();
381 $
(this).parent().parent().find("li.intro").hide();
384 $
(this).toggleClass("hidden");
388 $
(document
.createElement("a"))
391 title
: "hide redefined properties"
394 if($
(this).hasClass("hidden")) {
395 $
(this).parent().parent().find("li.redef").show();
397 $
(this).parent().parent().find("li.redef").hide();
400 $
(this).toggleClass("hidden");
407 $
("a[href*='#']").click( function() {
408 highlightBlock($
(this).attr("href").split(/#
/)[1]);
411 //Preload filter fields with query string
413 // Hide Authenfication form
414 $
(".popover").hide();
415 // Display Login modal
416 $
("#logGitHub").click(function(){ displayLogginModal(); });
419 // If cookie existing the session is opened
420 if(sessionStarted
){ userB64
= "Basic " + getUserPass("logginNitdoc"); }
422 // Sign In an github user or Log out him
423 $
("#signIn").click(function(){
425 if($
('#loginGit').val() == "" || $
('#passwordGit').val() == ""){ displayMessage('Please informed login/password field!', 40, 45); }
428 userName
= $
('#loginGit').val();
429 password
= $
('#passwordGit').val();
430 githubRepo
= $
('#repositoryGit').val();
431 branchName
= $
('#branchGit').val();
432 userB64
= "Basic " + base64
.encode(userName
+':'+password
);
434 // Check if repo exist
437 $
.when(isBranchExisting()).done(function(){
440 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+githubRepo
+':'+branchName
), 1);
441 $
('#loginGit').val("");
442 $
('#passwordGit').val("");
452 // Delete cookie and reset settings
453 del_cookie("logginNitdoc");
454 closeAllCommentInEdtiting();
456 displayLogginModal();
459 // Activate edit mode
460 $
('pre[class=text_label]').click(function(){
461 // the customer is loggued ?
462 if(!sessionStarted || userName
== ""){
463 // No => nothing happen
467 var arrayNew
= $
(this).text().split('\n');
468 var lNew
= arrayNew
.length
- 1;
471 for (var i
= 0; i
< lNew
; i
++) {
472 adapt
+= arrayNew
[i];
473 if(i
< lNew
-1){ adapt
+= "\n"; }
479 $
(this).next().show();
480 // Show cancel button
481 $
(this).next().next().show();
482 // Show commit button
483 $
(this).next().next().next().show();
484 // Add text in edit box
485 if($
(this).next().val() == "" || $
(this).next().val() != adapt
){ $
(this).next().val(adapt
); }
487 $
(this).next().height($
(this).next().prop("scrollHeight"));
489 $
(this).next().select();
490 preElement
= $
(this);
494 // Disable the edit mode
495 $
('a[id=cancelBtn]').click(function(){
496 closeEditing($
(this));
499 // Display commit form
500 $
('a[id=commitBtn]').click(function(){
501 updateComment
= $
(this).prev().prev().val();
502 commentType
= $
(this).prev().prev().prev().attr('type');
504 if(updateComment
== ""){ displayMessage('The comment field is empty!', 40, 45); }
507 displayMessage("You need to be loggued before commit something", 45, 40);
508 displayLogginModal();
512 // Create the commit message
513 var commitMessage
= 'Wikidoc: modified comment in ' + $
(this).parent().prev().html().split(' ')[1];
514 $
('#commitMessage').val(commitMessage
);
515 pathFile
= $
(this).prev().prev().prev().attr('tag');
516 $
('#modal').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btn_close" title="Close" alt="Close" /></a>');
517 $
('body').append('<div id="fade"></div>');
518 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
523 $
('.btn_close').click(function(){
525 $
(this).next().hide();
526 if(editComment
> 0){ editComment
-= 1; }
529 //Close Popups and Fade Layer
530 $
('body').on('click', 'a.close, #fade', function() {
531 if(editComment
> 0){ editComment
-= 1; }
532 $
('#fade , #modal').fadeOut(function() {
533 $
('#fade, a.close').remove();
535 $
('#modalQuestion').hide();
538 $
('#loginAction').click(function(){
542 // Look if the customer is logged
544 displayMessage("You need to be loggued before commit something", 100, 40);
545 $
('.popover').show();
548 else{ userB64
= "Basic " + getUserPass("logginNitdoc"); }
549 // Check if repo exist
555 commitMessage
= $
('#commitMessage').val();
556 if(commitMessage
== ""){ commitMessage
= "New commit";}
558 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
561 startCommitProcess();
564 $
('#modal, #modalQuestion').fadeOut(function() {
566 $
('#password').val("");
567 $
('textarea').hide();
568 $
('textarea').prev().show();
570 $
('a[id=cancelBtn]').hide();
571 $
('a[id=commitBtn]').hide();
572 // Re-load all comment
576 else{ editComment
-= 1; }
579 // Cancel creating branch
580 $
('#btnCancelBranch').click(function(){
582 $
('#modalQuestion').hide();
583 $
('#fade , #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
587 // Create new branch and continu
588 $
('#btnCreateBranch').click(function(){
589 $
('#modalQuestion').hide();
590 if($
('#btnCreateBranch').text() != 'Ok'){
593 commitMessage
= $
('#commitMessage').val();
594 if(commitMessage
== ""){ commitMessage
= "New commit"; }
597 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+githubRepo
+':'+branchName
), 1);
598 $
('#loginGit').val("");
599 $
('#passwordGit').val("");
600 loginProcess
= false;
601 displayLogginModal();
604 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
605 else{ startCommitProcess(); }
611 $
('#fade , #modalQuestion, #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
615 $
('a[class=newComment]').click(function(){
616 addNewComment
= true;
621 $
(this).next().show();
622 // Show cancel button
623 $
(this).next().next().show();
624 // Show commit button
625 $
(this).next().next().next().show();
627 $
(this).next().height($
(this).next().prop("scrollHeight"));
629 $
(this).next().select();
630 preElement
= $
(this);
633 $
("#dropBranches").change(function () {
634 $
("#dropBranches option:selected").each(function () {
635 if(branchName
!= $
(this).text()){
636 branchName
= $
(this).text();
639 $
.when(updateCookie(userName
, password
, githubRepo
, branchName
)).done(function(){
640 closeAllCommentInEdtiting();
647 if(sessionStarted
== true){
648 $
(this).css({'cursor' : 'hand'});
651 $
(this).css({'cursor' : ''});
655 if(sessionStarted
== true){
656 $
(this).css({'cursor' : 'pointer'});
659 $
(this).css({'cursor' : ''});
665 /* Parse current URL and return anchor name */
666 function currentAnchor() {
667 var index
= document
.location
.hash
.indexOf("#");
669 return document
.location
.hash
.substring(index
+ 1);
674 /* Prealod filters field using search query */
675 function preloadFilters() {
676 // Parse URL and get query string
677 var search
= currentAnchor();
679 if(search
== null || search
.indexOf("q=") == -1)
682 search
= search
.substring(2, search
.length
);
684 if(search
== "" || search
== "undefined")
687 $
(":text").val(search
);
689 .removeClass("notUsed")
694 /* Hightlight the spoted block */
695 function highlightBlock(a
) {
700 $
(".highlighted").removeClass("highlighted");
702 var target
= $
("#" + a
);
704 if(target
.is("article")) {
705 target
.parent().addClass("highlighted");
708 target
.addClass("highlighted");
712 // Init process to commit the new comment
713 function startCommitProcess()
715 var numL
= preElement
.attr("title");
716 commentLineStart
= numL
.split('-')[0] - 1;
717 if(addNewComment
) { commentLineStart
++; }
718 commentLineEnd
= (commentLineStart
+ preElement
.text().split('\n').length
) - 1;
720 replaceComment(updateComment
, currentfileContent
);
726 function displayLogginModal(){
727 if ($
('.popover').is(':hidden')) {
728 if(sessionStarted
){ getListBranches(); }
729 $
('.popover').show();
731 else { $
('.popover').hide(); }
735 function updateDisplaying(){
738 userB64
= "Basic " + getUserPass("logginNitdoc");
739 $
('#loginGit').hide();
740 $
('#passwordGit').hide();
741 $
('#lbpasswordGit').hide();
742 $
('#lbloginGit').hide();
743 $
('#repositoryGit').hide();
744 $
('#lbrepositoryGit').hide();
745 $
('#lbbranchGit').hide();
746 $
('#branchGit').hide();
747 $
('#listBranches').show();
748 $
("#liGitHub").attr("class", "current");
749 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
750 $
('#nickName').text(userName
);
751 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
752 $
('#logginMessage').css({'display' : 'block'});
753 $
('#logginMessage').css({'text-align' : 'center'});
754 $
('.popover').css({'height' : '160px'});
755 $
('#signIn').text("Sign out");
756 sessionStarted
= true;
761 sessionStarted
= false;
762 $
('#logginMessage').css({'display' : 'none'});
763 $
("#liGitHub").attr("class", "");
764 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
765 $
('#loginGit').val("");
766 $
('#passwordGit').val("");
767 $
('#nickName').text("");
768 $
('.popover').css({'height' : '325px'});
769 $
('#logginMessage').css({'display' : 'none'});
770 $
('#repositoryGit').val($
('#repoName').attr('name'));
771 $
('#branchGit').val('wikidoc');
772 $
('#signIn').text("Sign In");
773 $
('#loginGit').show();
774 $
('#passwordGit').show();
775 $
('#lbpasswordGit').show();
776 $
('#lbloginGit').show();
777 $
('#repositoryGit').show();
778 $
('#lbrepositoryGit').show();
779 $
('#lbbranchGit').show();
780 $
('#branchGit').show();
781 $
('#listBranches').hide();
785 function setCookie(c_name
, value
, exdays
)
787 var exdate
=new Date();
788 exdate
.setDate(exdate
.getDate() + exdays
);
789 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
790 document
.cookie
=c_name
+ "=" + c_value
;
793 function del_cookie(c_name
)
795 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
798 function updateCookie(user
, pwd
, repo
, branch
){
801 setCookie("logginNitdoc", base64
.encode(user
+':'+pwd
+':'+repo
+':'+branch
), 1);
805 function getCookie(c_name
)
807 var c_value
= document
.cookie
;
808 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
809 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
810 if (c_start
== -1) { c_value
= null; }
813 c_start
= c_value
.indexOf("=", c_start
) + 1;
814 var c_end
= c_value
.indexOf(";", c_start
);
815 if (c_end
== -1) { c_end
= c_value
.length
; }
816 c_value
= unescape(c_value
.substring(c_start
,c_end
));
821 function getUserPass(c_name
){
822 var cookie
= base64
.decode(getCookie(c_name
));
823 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
826 function checkCookie()
828 var cookie
=getCookie("logginNitdoc");
829 if (cookie
!=null && cookie
!="")
831 cookie
= base64
.decode(cookie
);
832 userName
= cookie
.split(':')[0];
833 password
= cookie
.split(':')[1];
834 githubRepo
= cookie
.split(':')[2];
835 branchName
= cookie
.split(':')[3];
838 else { return false; }
846 base64
.PADCHAR
= '=';
847 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
848 base64
.getbyte64
= function(s
,i
) {
849 // This is oddly fast, except on Chrome/V8.
850 // Minimal or no improvement in performance by using a
851 // object with properties mapping chars to value (eg. 'A': 0)
852 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
854 throw "Cannot decode base64";
859 base64
.decode
= function(s
) {
862 var getbyte64
= base64
.getbyte64
;
870 throw "Cannot decode base64";
874 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
876 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
879 // either way, we want to ignore this last block
884 for (i
= 0; i
< imax
; i
+= 4) {
885 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
886 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
887 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
892 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
893 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
896 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
897 x
.push(String
.fromCharCode(b10
>> 16));
903 base64
.getbyte
= function(s
,i
) {
904 var x
= s
.charCodeAt(i
);
906 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
912 base64
.encode
= function(s
) {
913 if (arguments
.length
!= 1) {
914 throw "SyntaxError: Not enough arguments";
916 var padchar
= base64
.PADCHAR
;
917 var alpha
= base64
.ALPHA
;
918 var getbyte
= base64
.getbyte
;
926 var imax
= s
.length
- s
.length
% 3;
931 for (i
= 0; i
< imax
; i
+= 3) {
932 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
933 x
.push(alpha
.charAt(b10
>> 18));
934 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
935 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
936 x
.push(alpha
.charAt(b10
& 0x3f));
938 switch (s
.length
- imax
) {
940 b10
= getbyte(s
,i
) << 16;
941 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
945 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
946 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
947 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
955 function getLastCommit()
958 if(sessionStarted
){ urlHead
= "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
;}
960 // TODO: get url of the original repo.
965 beforeSend
: function (xhr
) {
966 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
972 success
: function(success
)
974 shaLastCommit
= success
.object
.sha
;
979 function getBaseTree()
982 beforeSend
: function (xhr
) {
983 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
986 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits/" + shaLastCommit
,
989 success
: function(success
)
991 shaBaseTree
= success
.tree
.sha
;
992 if (state
){ setBlob(); }
1001 function setNewTree()
1004 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1006 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/trees",
1008 data
:'{ "base_tree" : "'+shaBaseTree
+'", '+
1010 '"path":"'+ pathFile
+'",'+
1013 '"sha": "'+ shaBlob
+'"'+
1016 success
: function(success
)
1017 { // si l'appel a bien fonctionné
1018 shaNewTree
= JSON
.parse(success
).sha
;
1027 function setNewCommit()
1030 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1032 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits",
1034 data
:'{ "message" : "'+ commitMessage
+'", '+
1035 '"parents" :"'+shaLastCommit
+'",'+
1036 '"tree": "'+shaNewTree
+'"'+
1038 success
: function(success
)
1040 shaNewCommit
= JSON
.parse(success
).sha
;
1053 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1055 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1056 data
:'{ "sha" : "'+shaNewCommit
+'", '+
1059 success
: function(success
) { displayMessage('Commit created successfully', 40, 40); },
1060 error
:function(error
){ displayMessage('Error ' + JSON
.parse(error
).object
.message
, 40, 40); }
1068 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1070 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/blobs",
1072 data
:'{ "content" : "'+text
.replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"')+'", '+
1073 '"encoding" :"utf-8"'+
1075 success
: function(success
)
1077 shaBlob
= JSON
.parse(success
).sha
;
1080 error
:function(error
){
1081 displayMessage('Error : Problem parsing JSON', 40, 40);
1087 // Display file content
1088 function getFileContent(urlFile
, newComment
)
1091 beforeSend
: function (xhr
) {
1092 xhr
.setRequestHeader ("Accept", "application/vnd.github-blob.raw");
1093 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1098 success
: function(success
)
1101 replaceComment(newComment
, success
);
1106 function replaceComment(newComment
, fileContent
){
1107 var arrayNew
= newComment
.split('\n');
1108 var lNew
= arrayNew
.length
;
1110 var lines
= fileContent
.split("\n");
1111 for (var i
= 0; i
< lines
.length
; i
++) {
1112 if(i
== commentLineStart
){
1114 for(var indexLine
=0; indexLine
< lines
[i
+1].length
; indexxLine
++){
1115 if(lines
[i
+1].substr(indexLine
,1) == "\t" || lines
[i
+1].substr(indexLine
,1) == "#"){ text
+= lines
[i
+1].substr(indexLine
,1); }
1118 text
+= lines
[i] + "\n";
1120 // We change the comment
1121 for(var j
= 0; j
< lNew
; j
++){
1122 if(commentType
== 1){ text
+= "\t# " + arrayNew
[j] + "\n"; }
1124 if(arrayNew
[j] == ""){ text
+= "#"+"\n"; }
1125 else{ text
+= "# " + arrayNew
[j] + "\n"; }
1129 else if(i
< commentLineStart || i
>= commentLineEnd
){
1130 if(i
== lines
.length
-1){ text
+= lines
[i]; }
1131 else{ text
+= lines
[i] + "\n"; }
1135 addNewComment
= false;
1139 function getCommentLastCommit(path
){
1142 if(shaLastCommit
!= ""){
1143 if (checkCookie()) {
1144 urlRaw
="https://rawgithub.com/"+ userName
+"/"+ githubRepo
+"/" + shaLastCommit
+ "/" + path
;
1149 success
: function(success
)
1151 currentfileContent
= success
;
1158 function displayMessage(msg
, widthDiv
, margModal
){
1161 $
('#txtQuestion').text(msg
);
1162 $
('#btnCreateBranch').text("Ok");
1163 $
('#btnCancelBranch').hide();
1164 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1165 var xModal
= $
('#modalQuestion').css('width').split('px')[0];
1166 var yModal
= $
('#modalQuestion').css('height').split('px')[0];
1167 var x
= $
(document
).width
/2 - xModal
/2;
1168 var y
= $
(document
).height
/2 - yModal
/2;
1169 var xBtnBranch
= $
('#btnCreateBranch').css('width').split('px')[0];
1170 $
('#modalQuestion').css({'left' : x
, 'top' : y
});
1171 $
('#modalQuestion').show();
1172 $
('#btnCreateBranch').css('margin-left', xModal
/2 - xBtnBranch
);
1173 $
('body').append('<div id="fade"></div>');
1174 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1177 function displaySpinner(){
1178 spinner
.spin(targetSpinner
);
1179 $
("#waitCommit").show();
1182 // Check if the repo already exist
1183 function isRepoExisting(){
1185 beforeSend
: function (xhr
) {
1186 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1189 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1192 success
: function(){ repoExist
= true; },
1195 displayMessage('Repo not found !', 35, 45);
1201 // Check if the branch already exist
1202 function isBranchExisting(){
1204 beforeSend
: function (xhr
) {
1205 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1208 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1211 success
: function(){ branchExist
= true; },
1214 branchExist
= false;
1217 $
('#txtQuestion').text("Are you sure you want to create that branch ?");
1218 $
('#btnCancelBranch').show();
1219 $
('#btnCreateBranch').text("Yes");
1220 $
('#modalQuestion').show();
1221 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1222 $
('body').append('<div id="fade"></div>');
1223 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1228 function getMasterSha()
1231 beforeSend
: function (xhr
) {
1232 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1235 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/master",
1238 success
: function(success
) { shaMaster
= success
.object
.sha
; }
1242 function createBranch(){
1247 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1249 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs",
1250 data
:'{ "ref" : "refs/heads/'+branchName
+'",'+
1251 '"sha" : "'+shaMaster
+'"'+
1253 success
: function(){ return; },
1256 displayMessage('Impossible to create the new branch : ' + branchName
, 40, 40);
1261 $
.fn
.spin
= function(opts
) {
1262 this.each(function() {
1263 var $
this = $
(this),
1264 data
= $
this.data();
1267 data
.spinner
.stop();
1268 delete data
.spinner
;
1270 if (opts
!== false) {
1271 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);
1277 function reloadComment(){
1278 $
.when(getCommentLastCommit($
('pre[class=text_label]').attr('tag'))).done(function(){
1279 $
('pre[class=text_label]').each(function(){ getCommentOfFunction($
(this)); });
1283 function getCommentOfFunction(element
){
1285 var numL
= element
.attr("title");
1287 commentLineStart
= numL
.split('-')[0] - 1;
1288 commentLineEnd
= (commentLineStart
+ element
.text().split('\n').length
) - 1;
1289 var lines
= currentfileContent
.split("\n");
1290 for (var i
= 0; i
< lines
.length
; i
++) {
1291 if(i
>= commentLineStart
-1 && i
<= commentLineEnd
){
1292 if (lines
[i].substr(1,1) == "#"){ textC
+= lines
[i].substr(3,lines
[i].length
) + "\n";}
1293 else if(lines
[i].substr(0,1) == '#'){ textC
+= lines
[i].substr(2,lines
[i].length
) + "\n"; }
1296 if (textC
!= ""){ element
.text(textC
); }
1300 // Get list of branches
1301 function getListBranches()
1303 cleanListBranches();
1305 beforeSend
: function (xhr
) {
1306 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1309 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/branches",
1312 success
: function(success
)
1314 for(var branch
in success
) {
1316 if(branchName
== success
[branch].name
){
1317 selected
= 'selected';
1319 $
('#dropBranches').append('<option value="" '+ selected
+'>' + success
[branch].name
+ '</option>');
1325 // Delete all option in the list
1326 function cleanListBranches(){
1327 $
('#dropBranches').children("option").remove();
1330 function closeAllCommentInEdtiting(){
1331 $
('a[id=cancelBtn]').each(function(){
1332 closeEditing($
(this));
1336 function closeEditing(tag
){
1337 if(editComment
> 0){ editComment
-= 1; }
1345 tag
.prev().prev().show();
1348 function checkSignIn(){
1349 var response
= false;
1351 beforeSend
: function (xhr
) {
1352 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1355 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1358 success
: function(success
)
1360 displayMessage('You are now logged in');
1365 displayMessage('Error : Wrong username or password');