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('The comment field is empty!', 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
);
433 // Check if repo exist
436 $
.when(isBranchExisting()).done(function(){
439 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+githubRepo
+':'+branchName
), 1);
440 $
('#loginGit').val("");
441 $
('#passwordGit').val("");
450 // Delete cookie and reset settings
451 del_cookie("logginNitdoc");
452 closeAllCommentInEdtiting();
454 displayLogginModal();
457 // Activate edit mode
458 $
('pre[class=text_label]').click(function(){
459 // the customer is loggued ?
460 if(!sessionStarted || userName
== ""){
461 // No => nothing happen
465 var arrayNew
= $
(this).text().split('\n');
466 var lNew
= arrayNew
.length
- 1;
469 for (var i
= 0; i
< lNew
; i
++) {
470 adapt
+= arrayNew
[i];
471 if(i
< lNew
-1){ adapt
+= "\n"; }
477 $
(this).next().show();
478 // Show cancel button
479 $
(this).next().next().show();
480 // Show commit button
481 $
(this).next().next().next().show();
482 // Add text in edit box
483 if($
(this).next().val() == "" || $
(this).next().val() != adapt
){ $
(this).next().val(adapt
); }
485 $
(this).next().height($
(this).next().prop("scrollHeight"));
487 $
(this).next().select();
488 preElement
= $
(this);
492 // Disable the edit mode
493 $
('a[id=cancelBtn]').click(function(){
494 closeEditing($
(this));
497 // Display commit form
498 $
('a[id=commitBtn]').click(function(){
499 updateComment
= $
(this).prev().prev().val();
500 commentType
= $
(this).prev().prev().prev().attr('type');
502 if(updateComment
== ""){ displayMessage('The comment field is empty!', 40, 45); }
505 displayMessage("You need to be loggued before commit something", 45, 40);
506 displayLogginModal();
509 $
('#commitMessage').val('New commit');
510 pathFile
= $
(this).prev().prev().prev().attr('tag');
511 $
('#modal').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btn_close" title="Close" alt="Close" /></a>');
512 $
('body').append('<div id="fade"></div>');
513 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
518 $
('.btn_close').click(function(){
520 $
(this).next().hide();
521 if(editComment
> 0){ editComment
-= 1; }
524 //Close Popups and Fade Layer
525 $
('body').on('click', 'a.close, #fade', function() {
526 if(editComment
> 0){ editComment
-= 1; }
527 $
('#fade , #modal').fadeOut(function() {
528 $
('#fade, a.close').remove();
530 $
('#modalQuestion').hide();
533 $
('#loginAction').click(function(){
537 // Look if the customer is logged
539 displayMessage("You need to be loggued before commit something", 100, 40);
540 $
('.popover').show();
543 else{ userB64
= "Basic " + getUserPass("logginNitdoc"); }
544 // Check if repo exist
550 commitMessage
= $
('#commitMessage').val();
551 if(commitMessage
== ""){ commitMessage
= "New commit";}
553 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
556 startCommitProcess();
559 $
('#modal, #modalQuestion').fadeOut(function() {
561 $
('#password').val("");
562 $
('textarea').hide();
563 $
('textarea').prev().show();
565 $
('a[id=cancelBtn]').hide();
566 $
('a[id=commitBtn]').hide();
567 // Re-load all comment
571 else{ editComment
-= 1; }
574 // Cancel creating branch
575 $
('#btnCancelBranch').click(function(){
577 $
('#modalQuestion').hide();
578 $
('#fade , #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
582 // Create new branch and continu
583 $
('#btnCreateBranch').click(function(){
584 $
('#modalQuestion').hide();
585 if($
('#btnCreateBranch').text() != 'Ok'){
588 commitMessage
= $
('#commitMessage').val();
589 if(commitMessage
== ""){ commitMessage
= "New commit"; }
592 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+githubRepo
+':'+branchName
), 1);
593 $
('#loginGit').val("");
594 $
('#passwordGit').val("");
595 loginProcess
= false;
596 displayLogginModal();
599 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
600 else{ startCommitProcess(); }
606 $
('#fade , #modalQuestion, #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
610 $
('a[class=newComment]').click(function(){
611 addNewComment
= true;
616 $
(this).next().show();
617 // Show cancel button
618 $
(this).next().next().show();
619 // Show commit button
620 $
(this).next().next().next().show();
622 $
(this).next().height($
(this).next().prop("scrollHeight"));
624 $
(this).next().select();
625 preElement
= $
(this);
628 $
("#dropBranches").change(function () {
629 $
("#dropBranches option:selected").each(function () {
630 if(branchName
!= $
(this).text()){
631 branchName
= $
(this).text();
634 $
.when(updateCookie(userName
, password
, githubRepo
, branchName
)).done(function(){
635 closeAllCommentInEdtiting();
642 $
(this).css({'cursor' : 'hand'});
645 $
(this).css({'cursor' : 'pointer'});
650 /* Parse current URL and return anchor name */
651 function currentAnchor() {
652 var index
= document
.location
.hash
.indexOf("#");
654 return document
.location
.hash
.substring(index
+ 1);
659 /* Prealod filters field using search query */
660 function preloadFilters() {
661 // Parse URL and get query string
662 var search
= currentAnchor();
664 if(search
== null || search
.indexOf("q=") == -1)
667 search
= search
.substring(2, search
.length
);
669 if(search
== "" || search
== "undefined")
672 $
(":text").val(search
);
674 .removeClass("notUsed")
679 /* Hightlight the spoted block */
680 function highlightBlock(a
) {
685 $
(".highlighted").removeClass("highlighted");
687 var target
= $
("#" + a
);
689 if(target
.is("article")) {
690 target
.parent().addClass("highlighted");
693 target
.addClass("highlighted");
697 // Init process to commit the new comment
698 function startCommitProcess()
700 var numL
= preElement
.attr("title");
701 commentLineStart
= numL
.split('-')[0] - 1;
702 if(addNewComment
) { commentLineStart
++; }
703 commentLineEnd
= (commentLineStart
+ preElement
.text().split('\n').length
) - 1;
705 replaceComment(updateComment
, currentfileContent
);
711 function displayLogginModal(){
712 if ($
('.popover').is(':hidden')) {
713 if(sessionStarted
){ getListBranches(); }
714 $
('.popover').show();
716 else { $
('.popover').hide(); }
720 function updateDisplaying(){
723 userB64
= "Basic " + getUserPass("logginNitdoc");
724 $
('#loginGit').hide();
725 $
('#passwordGit').hide();
726 $
('#lbpasswordGit').hide();
727 $
('#lbloginGit').hide();
728 $
('#repositoryGit').hide();
729 $
('#lbrepositoryGit').hide();
730 $
('#lbbranchGit').hide();
731 $
('#branchGit').hide();
732 $
('#listBranches').show();
733 $
("#liGitHub").attr("class", "current");
734 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
735 $
('#nickName').text(userName
);
736 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
737 $
('#logginMessage').css({'display' : 'block'});
738 $
('#logginMessage').css({'text-align' : 'center'});
739 $
('.popover').css({'height' : '120px'});
740 $
('#signIn').text("Sign out");
741 sessionStarted
= true;
746 sessionStarted
= false;
747 $
('#logginMessage').css({'display' : 'none'});
748 $
("#liGitHub").attr("class", "");
749 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
750 $
('#loginGit').val("");
751 $
('#passwordGit').val("");
752 $
('#nickName').text("");
753 $
('.popover').css({'height' : '280px'});
754 $
('#logginMessage').css({'display' : 'none'});
755 $
('#repositoryGit').val($
('#repoName').attr('name'));
756 $
('#branchGit').val('wikidoc');
757 $
('#signIn').text("Sign In");
758 $
('#loginGit').show();
759 $
('#passwordGit').show();
760 $
('#lbpasswordGit').show();
761 $
('#lbloginGit').show();
762 $
('#repositoryGit').show();
763 $
('#lbrepositoryGit').show();
764 $
('#lbbranchGit').show();
765 $
('#branchGit').show();
766 $
('#listBranches').hide();
770 function setCookie(c_name
, value
, exdays
)
772 var exdate
=new Date();
773 exdate
.setDate(exdate
.getDate() + exdays
);
774 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
775 document
.cookie
=c_name
+ "=" + c_value
;
778 function del_cookie(c_name
)
780 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
783 function updateCookie(user
, pwd
, repo
, branch
){
786 setCookie("logginNitdoc", base64
.encode(user
+':'+pwd
+':'+repo
+':'+branch
), 1);
790 function getCookie(c_name
)
792 var c_value
= document
.cookie
;
793 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
794 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
795 if (c_start
== -1) { c_value
= null; }
798 c_start
= c_value
.indexOf("=", c_start
) + 1;
799 var c_end
= c_value
.indexOf(";", c_start
);
800 if (c_end
== -1) { c_end
= c_value
.length
; }
801 c_value
= unescape(c_value
.substring(c_start
,c_end
));
806 function getUserPass(c_name
){
807 var cookie
= base64
.decode(getCookie(c_name
));
808 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
811 function checkCookie()
813 var cookie
=getCookie("logginNitdoc");
814 if (cookie
!=null && cookie
!="")
816 cookie
= base64
.decode(cookie
);
817 userName
= cookie
.split(':')[0];
818 password
= cookie
.split(':')[1];
819 githubRepo
= cookie
.split(':')[2];
820 branchName
= cookie
.split(':')[3];
823 else { return false; }
831 base64
.PADCHAR
= '=';
832 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
833 base64
.getbyte64
= function(s
,i
) {
834 // This is oddly fast, except on Chrome/V8.
835 // Minimal or no improvement in performance by using a
836 // object with properties mapping chars to value (eg. 'A': 0)
837 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
839 throw "Cannot decode base64";
844 base64
.decode
= function(s
) {
847 var getbyte64
= base64
.getbyte64
;
855 throw "Cannot decode base64";
859 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
861 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
864 // either way, we want to ignore this last block
869 for (i
= 0; i
< imax
; i
+= 4) {
870 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
871 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
872 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
877 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
878 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
881 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
882 x
.push(String
.fromCharCode(b10
>> 16));
888 base64
.getbyte
= function(s
,i
) {
889 var x
= s
.charCodeAt(i
);
891 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
897 base64
.encode
= function(s
) {
898 if (arguments
.length
!= 1) {
899 throw "SyntaxError: Not enough arguments";
901 var padchar
= base64
.PADCHAR
;
902 var alpha
= base64
.ALPHA
;
903 var getbyte
= base64
.getbyte
;
911 var imax
= s
.length
- s
.length
% 3;
916 for (i
= 0; i
< imax
; i
+= 3) {
917 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
918 x
.push(alpha
.charAt(b10
>> 18));
919 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
920 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
921 x
.push(alpha
.charAt(b10
& 0x3f));
923 switch (s
.length
- imax
) {
925 b10
= getbyte(s
,i
) << 16;
926 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
930 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
931 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
932 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
940 function getLastCommit()
943 if(sessionStarted
){ urlHead
= "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
;}
945 // TODO: get url of the original repo.
950 beforeSend
: function (xhr
) {
951 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
957 success
: function(success
)
959 shaLastCommit
= success
.object
.sha
;
964 function getBaseTree()
967 beforeSend
: function (xhr
) {
968 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
971 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits/" + shaLastCommit
,
974 success
: function(success
)
976 shaBaseTree
= success
.tree
.sha
;
977 if (state
){ setBlob(); }
986 function setNewTree()
989 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
991 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/trees",
993 data
:'{ "base_tree" : "'+shaBaseTree
+'", '+
995 '"path":"'+ pathFile
+'",'+
998 '"sha": "'+ shaBlob
+'"'+
1001 success
: function(success
)
1002 { // si l'appel a bien fonctionné
1003 shaNewTree
= JSON
.parse(success
).sha
;
1012 function setNewCommit()
1015 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1017 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits",
1019 data
:'{ "message" : "'+ commitMessage
+'", '+
1020 '"parents" :"'+shaLastCommit
+'",'+
1021 '"tree": "'+shaNewTree
+'"'+
1023 success
: function(success
)
1025 shaNewCommit
= JSON
.parse(success
).sha
;
1038 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1040 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1041 data
:'{ "sha" : "'+shaNewCommit
+'", '+
1044 success
: function(success
) { displayMessage('Commit created successfully', 40, 40); },
1045 error
:function(error
){ displayMessage('Error ' + JSON
.parse(error
).object
.message
, 40, 40); }
1053 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1055 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/blobs",
1057 data
:'{ "content" : "'+text
.replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"')+'", '+
1058 '"encoding" :"utf-8"'+
1060 success
: function(success
)
1062 shaBlob
= JSON
.parse(success
).sha
;
1065 error
:function(error
){
1066 displayMessage('Error : Problem parsing JSON', 40, 40);
1072 // Display file content
1073 function getFileContent(urlFile
, newComment
)
1076 beforeSend
: function (xhr
) {
1077 xhr
.setRequestHeader ("Accept", "application/vnd.github-blob.raw");
1078 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1083 success
: function(success
)
1086 replaceComment(newComment
, success
);
1091 function replaceComment(newComment
, fileContent
){
1092 var arrayNew
= newComment
.split('\n');
1093 var lNew
= arrayNew
.length
;
1095 var lines
= fileContent
.split("\n");
1096 for (var i
= 0; i
< lines
.length
; i
++) {
1097 if(i
== commentLineStart
){
1099 for(var indexLine
=0; indexLine
< lines
[i
+1].length
; indexxLine
++){
1100 if(lines
[i
+1].substr(indexLine
,1) == "\t" || lines
[i
+1].substr(indexLine
,1) == "#"){ text
+= lines
[i
+1].substr(indexLine
,1); }
1103 text
+= lines
[i] + "\n";
1105 // We change the comment
1106 for(var j
= 0; j
< lNew
; j
++){
1107 if(commentType
== 1){ text
+= "\t# " + arrayNew
[j] + "\n"; }
1109 if(arrayNew
[j] == ""){ text
+= "#"+"\n"; }
1110 else{ text
+= "# " + arrayNew
[j] + "\n"; }
1114 else if(i
< commentLineStart || i
>= commentLineEnd
){
1115 if(i
== lines
.length
-1){ text
+= lines
[i]; }
1116 else{ text
+= lines
[i] + "\n"; }
1120 addNewComment
= false;
1124 function getCommentLastCommit(path
){
1127 if(shaLastCommit
!= ""){
1128 if (checkCookie()) {
1129 urlRaw
="https://rawgithub.com/"+ userName
+"/"+ githubRepo
+"/" + shaLastCommit
+ "/" + path
;
1134 success
: function(success
)
1136 currentfileContent
= success
;
1143 function displayMessage(msg
, widthDiv
, margModal
){
1146 $
('#btnCreateBranch').css('margin-left',widthDiv
+ '%');
1147 $
('#txtQuestion').text(msg
);
1148 $
('#btnCreateBranch').text("Ok");
1149 $
('#btnCancelBranch').hide();
1150 $
('#modalQuestion').css({'left' : margModal
+ '%'})
1151 $
('#modalQuestion').show();
1152 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1153 $
('body').append('<div id="fade"></div>');
1154 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1157 function displaySpinner(){
1158 spinner
.spin(targetSpinner
);
1159 $
("#waitCommit").show();
1162 // Check if the repo already exist
1163 function isRepoExisting(){
1165 beforeSend
: function (xhr
) {
1166 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1169 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1172 success
: function(){ repoExist
= true; },
1175 displayMessage('Repo not found !', 35, 45);
1181 // Check if the branch already exist
1182 function isBranchExisting(){
1184 beforeSend
: function (xhr
) {
1185 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1188 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1191 success
: function(){ branchExist
= true; },
1194 branchExist
= false;
1197 $
('#txtQuestion').text("Are you sure you want to create that branch ?");
1198 $
('#btnCancelBranch').show();
1199 $
('#btnCreateBranch').text("Yes");
1200 $
('#modalQuestion').show();
1201 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1202 $
('body').append('<div id="fade"></div>');
1203 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1208 function getMasterSha()
1211 beforeSend
: function (xhr
) {
1212 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1215 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/master",
1218 success
: function(success
) { shaMaster
= success
.object
.sha
; }
1222 function createBranch(){
1227 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1229 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs",
1230 data
:'{ "ref" : "refs/heads/'+branchName
+'",'+
1231 '"sha" : "'+shaMaster
+'"'+
1233 success
: function(){ return; },
1236 displayMessage('Impossible to create the new branch : ' + branchName
, 40, 40);
1241 $
.fn
.spin
= function(opts
) {
1242 this.each(function() {
1243 var $
this = $
(this),
1244 data
= $
this.data();
1247 data
.spinner
.stop();
1248 delete data
.spinner
;
1250 if (opts
!== false) {
1251 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);
1257 function reloadComment(){
1258 $
.when(getCommentLastCommit($
('pre[class=text_label]').attr('tag'))).done(function(){
1259 $
('pre[class=text_label]').each(function(){ getCommentOfFunction($
(this)); });
1263 function getCommentOfFunction(element
){
1265 var numL
= element
.attr("title");
1267 commentLineStart
= numL
.split('-')[0] - 1;
1268 commentLineEnd
= (commentLineStart
+ element
.text().split('\n').length
) - 1;
1269 var lines
= currentfileContent
.split("\n");
1270 for (var i
= 0; i
< lines
.length
; i
++) {
1271 if(i
>= commentLineStart
-1 && i
<= commentLineEnd
){
1272 if (lines
[i].substr(1,1) == "#"){ textC
+= lines
[i].substr(3,lines
[i].length
) + "\n";}
1273 else if(lines
[i].substr(0,1) == '#'){ textC
+= lines
[i].substr(2,lines
[i].length
) + "\n"; }
1276 if (textC
!= ""){ element
.text(textC
); }
1280 // Get list of branches
1281 function getListBranches()
1283 cleanListBranches();
1285 beforeSend
: function (xhr
) {
1286 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1289 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/branches",
1292 success
: function(success
)
1294 for(var branch
in success
) {
1296 if(branchName
== success
[branch].name
){
1297 selected
= 'selected';
1299 $
('#dropBranches').append('<option value="" '+ selected
+'>' + success
[branch].name
+ '</option>');
1305 // Delete all option in the list
1306 function cleanListBranches(){
1307 $
('#dropBranches').children("option").remove();
1310 function closeAllCommentInEdtiting(){
1311 $
('a[id=cancelBtn]').each(function(){
1312 closeEditing($
(this));
1316 function closeEditing(tag
){
1317 if(editComment
> 0){ editComment
-= 1; }
1325 tag
.prev().prev().show();