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();
510 // Create the commit message
511 var commitMessage
= 'Wikidoc: modified comment in ' + $
(this).parent().prev().html().split(' ')[1];
512 $
('#commitMessage').val(commitMessage
);
513 pathFile
= $
(this).prev().prev().prev().attr('tag');
514 $
('#modal').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btn_close" title="Close" alt="Close" /></a>');
515 $
('body').append('<div id="fade"></div>');
516 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
521 $
('.btn_close').click(function(){
523 $
(this).next().hide();
524 if(editComment
> 0){ editComment
-= 1; }
527 //Close Popups and Fade Layer
528 $
('body').on('click', 'a.close, #fade', function() {
529 if(editComment
> 0){ editComment
-= 1; }
530 $
('#fade , #modal').fadeOut(function() {
531 $
('#fade, a.close').remove();
533 $
('#modalQuestion').hide();
536 $
('#loginAction').click(function(){
540 // Look if the customer is logged
542 displayMessage("You need to be loggued before commit something", 100, 40);
543 $
('.popover').show();
546 else{ userB64
= "Basic " + getUserPass("logginNitdoc"); }
547 // Check if repo exist
553 commitMessage
= $
('#commitMessage').val();
554 if(commitMessage
== ""){ commitMessage
= "New commit";}
556 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
559 startCommitProcess();
562 $
('#modal, #modalQuestion').fadeOut(function() {
564 $
('#password').val("");
565 $
('textarea').hide();
566 $
('textarea').prev().show();
568 $
('a[id=cancelBtn]').hide();
569 $
('a[id=commitBtn]').hide();
570 // Re-load all comment
574 else{ editComment
-= 1; }
577 // Cancel creating branch
578 $
('#btnCancelBranch').click(function(){
580 $
('#modalQuestion').hide();
581 $
('#fade , #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
585 // Create new branch and continu
586 $
('#btnCreateBranch').click(function(){
587 $
('#modalQuestion').hide();
588 if($
('#btnCreateBranch').text() != 'Ok'){
591 commitMessage
= $
('#commitMessage').val();
592 if(commitMessage
== ""){ commitMessage
= "New commit"; }
595 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+githubRepo
+':'+branchName
), 1);
596 $
('#loginGit').val("");
597 $
('#passwordGit').val("");
598 loginProcess
= false;
599 displayLogginModal();
602 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
603 else{ startCommitProcess(); }
609 $
('#fade , #modalQuestion, #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
613 $
('a[class=newComment]').click(function(){
614 addNewComment
= true;
619 $
(this).next().show();
620 // Show cancel button
621 $
(this).next().next().show();
622 // Show commit button
623 $
(this).next().next().next().show();
625 $
(this).next().height($
(this).next().prop("scrollHeight"));
627 $
(this).next().select();
628 preElement
= $
(this);
631 $
("#dropBranches").change(function () {
632 $
("#dropBranches option:selected").each(function () {
633 if(branchName
!= $
(this).text()){
634 branchName
= $
(this).text();
637 $
.when(updateCookie(userName
, password
, githubRepo
, branchName
)).done(function(){
638 closeAllCommentInEdtiting();
645 if(sessionStarted
== true){
646 $
(this).css({'cursor' : 'hand'});
649 $
(this).css({'cursor' : ''});
653 if(sessionStarted
== true){
654 $
(this).css({'cursor' : 'pointer'});
657 $
(this).css({'cursor' : ''});
663 /* Parse current URL and return anchor name */
664 function currentAnchor() {
665 var index
= document
.location
.hash
.indexOf("#");
667 return document
.location
.hash
.substring(index
+ 1);
672 /* Prealod filters field using search query */
673 function preloadFilters() {
674 // Parse URL and get query string
675 var search
= currentAnchor();
677 if(search
== null || search
.indexOf("q=") == -1)
680 search
= search
.substring(2, search
.length
);
682 if(search
== "" || search
== "undefined")
685 $
(":text").val(search
);
687 .removeClass("notUsed")
692 /* Hightlight the spoted block */
693 function highlightBlock(a
) {
698 $
(".highlighted").removeClass("highlighted");
700 var target
= $
("#" + a
);
702 if(target
.is("article")) {
703 target
.parent().addClass("highlighted");
706 target
.addClass("highlighted");
710 // Init process to commit the new comment
711 function startCommitProcess()
713 var numL
= preElement
.attr("title");
714 commentLineStart
= numL
.split('-')[0] - 1;
715 if(addNewComment
) { commentLineStart
++; }
716 commentLineEnd
= (commentLineStart
+ preElement
.text().split('\n').length
) - 1;
718 replaceComment(updateComment
, currentfileContent
);
724 function displayLogginModal(){
725 if ($
('.popover').is(':hidden')) {
726 if(sessionStarted
){ getListBranches(); }
727 $
('.popover').show();
729 else { $
('.popover').hide(); }
733 function updateDisplaying(){
736 userB64
= "Basic " + getUserPass("logginNitdoc");
737 $
('#loginGit').hide();
738 $
('#passwordGit').hide();
739 $
('#lbpasswordGit').hide();
740 $
('#lbloginGit').hide();
741 $
('#repositoryGit').hide();
742 $
('#lbrepositoryGit').hide();
743 $
('#lbbranchGit').hide();
744 $
('#branchGit').hide();
745 $
('#listBranches').show();
746 $
("#liGitHub").attr("class", "current");
747 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
748 $
('#nickName').text(userName
);
749 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
750 $
('#logginMessage').css({'display' : 'block'});
751 $
('#logginMessage').css({'text-align' : 'center'});
752 $
('.popover').css({'height' : '120px'});
753 $
('#signIn').text("Sign out");
754 sessionStarted
= true;
759 sessionStarted
= false;
760 $
('#logginMessage').css({'display' : 'none'});
761 $
("#liGitHub").attr("class", "");
762 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
763 $
('#loginGit').val("");
764 $
('#passwordGit').val("");
765 $
('#nickName').text("");
766 $
('.popover').css({'height' : '280px'});
767 $
('#logginMessage').css({'display' : 'none'});
768 $
('#repositoryGit').val($
('#repoName').attr('name'));
769 $
('#branchGit').val('wikidoc');
770 $
('#signIn').text("Sign In");
771 $
('#loginGit').show();
772 $
('#passwordGit').show();
773 $
('#lbpasswordGit').show();
774 $
('#lbloginGit').show();
775 $
('#repositoryGit').show();
776 $
('#lbrepositoryGit').show();
777 $
('#lbbranchGit').show();
778 $
('#branchGit').show();
779 $
('#listBranches').hide();
783 function setCookie(c_name
, value
, exdays
)
785 var exdate
=new Date();
786 exdate
.setDate(exdate
.getDate() + exdays
);
787 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
788 document
.cookie
=c_name
+ "=" + c_value
;
791 function del_cookie(c_name
)
793 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
796 function updateCookie(user
, pwd
, repo
, branch
){
799 setCookie("logginNitdoc", base64
.encode(user
+':'+pwd
+':'+repo
+':'+branch
), 1);
803 function getCookie(c_name
)
805 var c_value
= document
.cookie
;
806 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
807 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
808 if (c_start
== -1) { c_value
= null; }
811 c_start
= c_value
.indexOf("=", c_start
) + 1;
812 var c_end
= c_value
.indexOf(";", c_start
);
813 if (c_end
== -1) { c_end
= c_value
.length
; }
814 c_value
= unescape(c_value
.substring(c_start
,c_end
));
819 function getUserPass(c_name
){
820 var cookie
= base64
.decode(getCookie(c_name
));
821 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
824 function checkCookie()
826 var cookie
=getCookie("logginNitdoc");
827 if (cookie
!=null && cookie
!="")
829 cookie
= base64
.decode(cookie
);
830 userName
= cookie
.split(':')[0];
831 password
= cookie
.split(':')[1];
832 githubRepo
= cookie
.split(':')[2];
833 branchName
= cookie
.split(':')[3];
836 else { return false; }
844 base64
.PADCHAR
= '=';
845 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
846 base64
.getbyte64
= function(s
,i
) {
847 // This is oddly fast, except on Chrome/V8.
848 // Minimal or no improvement in performance by using a
849 // object with properties mapping chars to value (eg. 'A': 0)
850 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
852 throw "Cannot decode base64";
857 base64
.decode
= function(s
) {
860 var getbyte64
= base64
.getbyte64
;
868 throw "Cannot decode base64";
872 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
874 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
877 // either way, we want to ignore this last block
882 for (i
= 0; i
< imax
; i
+= 4) {
883 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
884 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
885 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
890 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
891 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
894 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
895 x
.push(String
.fromCharCode(b10
>> 16));
901 base64
.getbyte
= function(s
,i
) {
902 var x
= s
.charCodeAt(i
);
904 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
910 base64
.encode
= function(s
) {
911 if (arguments
.length
!= 1) {
912 throw "SyntaxError: Not enough arguments";
914 var padchar
= base64
.PADCHAR
;
915 var alpha
= base64
.ALPHA
;
916 var getbyte
= base64
.getbyte
;
924 var imax
= s
.length
- s
.length
% 3;
929 for (i
= 0; i
< imax
; i
+= 3) {
930 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
931 x
.push(alpha
.charAt(b10
>> 18));
932 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
933 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
934 x
.push(alpha
.charAt(b10
& 0x3f));
936 switch (s
.length
- imax
) {
938 b10
= getbyte(s
,i
) << 16;
939 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
943 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
944 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
945 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
953 function getLastCommit()
956 if(sessionStarted
){ urlHead
= "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
;}
958 // TODO: get url of the original repo.
963 beforeSend
: function (xhr
) {
964 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
970 success
: function(success
)
972 shaLastCommit
= success
.object
.sha
;
977 function getBaseTree()
980 beforeSend
: function (xhr
) {
981 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
984 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits/" + shaLastCommit
,
987 success
: function(success
)
989 shaBaseTree
= success
.tree
.sha
;
990 if (state
){ setBlob(); }
999 function setNewTree()
1002 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1004 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/trees",
1006 data
:'{ "base_tree" : "'+shaBaseTree
+'", '+
1008 '"path":"'+ pathFile
+'",'+
1011 '"sha": "'+ shaBlob
+'"'+
1014 success
: function(success
)
1015 { // si l'appel a bien fonctionné
1016 shaNewTree
= JSON
.parse(success
).sha
;
1025 function setNewCommit()
1028 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1030 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits",
1032 data
:'{ "message" : "'+ commitMessage
+'", '+
1033 '"parents" :"'+shaLastCommit
+'",'+
1034 '"tree": "'+shaNewTree
+'"'+
1036 success
: function(success
)
1038 shaNewCommit
= JSON
.parse(success
).sha
;
1051 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1053 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1054 data
:'{ "sha" : "'+shaNewCommit
+'", '+
1057 success
: function(success
) { displayMessage('Commit created successfully', 40, 40); },
1058 error
:function(error
){ displayMessage('Error ' + JSON
.parse(error
).object
.message
, 40, 40); }
1066 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1068 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/blobs",
1070 data
:'{ "content" : "'+text
.replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"')+'", '+
1071 '"encoding" :"utf-8"'+
1073 success
: function(success
)
1075 shaBlob
= JSON
.parse(success
).sha
;
1078 error
:function(error
){
1079 displayMessage('Error : Problem parsing JSON', 40, 40);
1085 // Display file content
1086 function getFileContent(urlFile
, newComment
)
1089 beforeSend
: function (xhr
) {
1090 xhr
.setRequestHeader ("Accept", "application/vnd.github-blob.raw");
1091 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1096 success
: function(success
)
1099 replaceComment(newComment
, success
);
1104 function replaceComment(newComment
, fileContent
){
1105 var arrayNew
= newComment
.split('\n');
1106 var lNew
= arrayNew
.length
;
1108 var lines
= fileContent
.split("\n");
1109 for (var i
= 0; i
< lines
.length
; i
++) {
1110 if(i
== commentLineStart
){
1112 for(var indexLine
=0; indexLine
< lines
[i
+1].length
; indexxLine
++){
1113 if(lines
[i
+1].substr(indexLine
,1) == "\t" || lines
[i
+1].substr(indexLine
,1) == "#"){ text
+= lines
[i
+1].substr(indexLine
,1); }
1116 text
+= lines
[i] + "\n";
1118 // We change the comment
1119 for(var j
= 0; j
< lNew
; j
++){
1120 if(commentType
== 1){ text
+= "\t# " + arrayNew
[j] + "\n"; }
1122 if(arrayNew
[j] == ""){ text
+= "#"+"\n"; }
1123 else{ text
+= "# " + arrayNew
[j] + "\n"; }
1127 else if(i
< commentLineStart || i
>= commentLineEnd
){
1128 if(i
== lines
.length
-1){ text
+= lines
[i]; }
1129 else{ text
+= lines
[i] + "\n"; }
1133 addNewComment
= false;
1137 function getCommentLastCommit(path
){
1140 if(shaLastCommit
!= ""){
1141 if (checkCookie()) {
1142 urlRaw
="https://rawgithub.com/"+ userName
+"/"+ githubRepo
+"/" + shaLastCommit
+ "/" + path
;
1147 success
: function(success
)
1149 currentfileContent
= success
;
1156 function displayMessage(msg
, widthDiv
, margModal
){
1159 $
('#btnCreateBranch').css('margin-left',widthDiv
+ '%');
1160 $
('#txtQuestion').text(msg
);
1161 $
('#btnCreateBranch').text("Ok");
1162 $
('#btnCancelBranch').hide();
1163 $
('#modalQuestion').css({'left' : margModal
+ '%'})
1164 $
('#modalQuestion').show();
1165 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1166 $
('body').append('<div id="fade"></div>');
1167 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1170 function displaySpinner(){
1171 spinner
.spin(targetSpinner
);
1172 $
("#waitCommit").show();
1175 // Check if the repo already exist
1176 function isRepoExisting(){
1178 beforeSend
: function (xhr
) {
1179 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1182 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1185 success
: function(){ repoExist
= true; },
1188 displayMessage('Repo not found !', 35, 45);
1194 // Check if the branch already exist
1195 function isBranchExisting(){
1197 beforeSend
: function (xhr
) {
1198 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1201 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1204 success
: function(){ branchExist
= true; },
1207 branchExist
= false;
1210 $
('#txtQuestion').text("Are you sure you want to create that branch ?");
1211 $
('#btnCancelBranch').show();
1212 $
('#btnCreateBranch').text("Yes");
1213 $
('#modalQuestion').show();
1214 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1215 $
('body').append('<div id="fade"></div>');
1216 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1221 function getMasterSha()
1224 beforeSend
: function (xhr
) {
1225 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1228 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/master",
1231 success
: function(success
) { shaMaster
= success
.object
.sha
; }
1235 function createBranch(){
1240 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1242 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs",
1243 data
:'{ "ref" : "refs/heads/'+branchName
+'",'+
1244 '"sha" : "'+shaMaster
+'"'+
1246 success
: function(){ return; },
1249 displayMessage('Impossible to create the new branch : ' + branchName
, 40, 40);
1254 $
.fn
.spin
= function(opts
) {
1255 this.each(function() {
1256 var $
this = $
(this),
1257 data
= $
this.data();
1260 data
.spinner
.stop();
1261 delete data
.spinner
;
1263 if (opts
!== false) {
1264 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);
1270 function reloadComment(){
1271 $
.when(getCommentLastCommit($
('pre[class=text_label]').attr('tag'))).done(function(){
1272 $
('pre[class=text_label]').each(function(){ getCommentOfFunction($
(this)); });
1276 function getCommentOfFunction(element
){
1278 var numL
= element
.attr("title");
1280 commentLineStart
= numL
.split('-')[0] - 1;
1281 commentLineEnd
= (commentLineStart
+ element
.text().split('\n').length
) - 1;
1282 var lines
= currentfileContent
.split("\n");
1283 for (var i
= 0; i
< lines
.length
; i
++) {
1284 if(i
>= commentLineStart
-1 && i
<= commentLineEnd
){
1285 if (lines
[i].substr(1,1) == "#"){ textC
+= lines
[i].substr(3,lines
[i].length
) + "\n";}
1286 else if(lines
[i].substr(0,1) == '#'){ textC
+= lines
[i].substr(2,lines
[i].length
) + "\n"; }
1289 if (textC
!= ""){ element
.text(textC
); }
1293 // Get list of branches
1294 function getListBranches()
1296 cleanListBranches();
1298 beforeSend
: function (xhr
) {
1299 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1302 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/branches",
1305 success
: function(success
)
1307 for(var branch
in success
) {
1309 if(branchName
== success
[branch].name
){
1310 selected
= 'selected';
1312 $
('#dropBranches').append('<option value="" '+ selected
+'>' + success
[branch].name
+ '</option>');
1318 // Delete all option in the list
1319 function cleanListBranches(){
1320 $
('#dropBranches').children("option").remove();
1323 function closeAllCommentInEdtiting(){
1324 $
('a[id=cancelBtn]').each(function(){
1325 closeEditing($
(this));
1329 function closeEditing(tag
){
1330 if(editComment
> 0){ editComment
-= 1; }
1338 tag
.prev().prev().show();