5 var sessionStarted
= false;
7 var currentfileContent
= '';
8 var addNewComment
= false;
13 var shaLastCommit
= "";
19 var repoExist
= false;
20 var branchExist
= false;
25 lines
: 11, // The number of lines to draw
26 length
: 7, // The length of each line
27 width
: 4, // The line thickness
28 radius
: 10, // The radius of the inner circle
29 corners
: 1, // Corner roundness (0..1)
30 rotate
: 0, // The rotation offset
31 color
: '#FFF', // #rgb or #rrggbb
32 speed
: 1, // Rounds per second
33 trail
: 60, // Afterglow percentage
34 shadow
: false, // Whether to render a shadow
35 hwaccel
: false, // Whether to use hardware acceleration
36 className
: 'spinner', // The CSS class to assign to the spinner
37 zIndex
: 99999, // The z-index (defaults to 2000000000)
38 top
: '300', // Top position relative to parent in px
39 left
: 'auto' // Left position relative to parent in px
41 var targetSpinner
= document
.getElementById('waitCommit');
42 var spinner
= new Spinner(opts
).spin(targetSpinner
);
45 * JQuery Case Insensitive :icontains selector
47 $
.expr
[':'].icontains
= function(obj
, index
, meta
, stack
){
48 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;
52 * Quick Search global vars
55 // Current search results preview table
56 var currentTable
= null;
58 //Hightlighted index in search result preview table
59 var currentIndex
= -1;
61 // Check if a comment is editing
62 window
.onbeforeunload
= function() {
64 return 'Are you sure you want to leave this page?';
69 * Add folding and filtering facilities to class description page.
71 $
(document
).ready(function() {
75 $
('a[id=commitBtn]').hide();
76 $
('a[id=cancelBtn]').hide();
77 // Hide Authenfication form
79 githubRepo
= $
('#repoName').attr('name');
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 repoName
= $
('#repositoryGit').val();
431 branchName
= $
('#branchGit').val();
432 userB64
= "Basic " + base64
.encode(userName
+':'+password
);
433 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+repoName
+':'+branchName
), 1);
434 $
('#loginGit').val("");
435 $
('#passwordGit').val("");
441 // Delete cookie and reset settings
442 del_cookie("logginNitdoc");
444 displayLogginModal();
447 // Activate edit mode
448 $
('pre[class=text_label]').click(function(){
449 // the customer is loggued ?
450 if(!sessionStarted || userName
== ""){
451 // No => nothing happen
455 var arrayNew
= $
(this).text().split('\n');
456 var lNew
= arrayNew
.length
- 1;
459 for (var i
= 0; i
< lNew
; i
++) {
460 adapt
+= arrayNew
[i];
461 if(i
< lNew
-1){ adapt
+= "\n"; }
467 $
(this).next().show();
468 // Show cancel button
469 $
(this).next().next().show();
470 // Show commit button
471 $
(this).next().next().next().show();
472 // Add text in edit box
473 if($
(this).next().val() == "" || $
(this).next().val() != adapt
){ $
(this).next().val(adapt
); }
475 $
(this).next().height($
(this).next().prop("scrollHeight"));
477 $
(this).next().select();
478 preElement
= $
(this);
482 // Disable the edit mode
483 $
('a[id=cancelBtn]').click(function(){
484 if(editComment
> 0){ editComment
-= 1; }
488 $
(this).next().hide();
490 $
(this).prev().hide();
492 $
(this).prev().prev().show();
495 // Display commit form
496 $
('a[id=commitBtn]').click(function(){
497 updateComment
= $
(this).prev().prev().val();
498 commentType
= $
(this).prev().prev().prev().attr('type');
500 if(updateComment
== ""){ displayMessage('The comment field is empty!', 40, 45); }
503 displayMessage("You need to be loggued before commit something", 45, 40);
504 displayLogginModal();
507 $
('#commitMessage').val('New commit');
508 pathFile
= $
(this).prev().prev().prev().attr('tag');
509 $
('#modal').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btn_close" title="Close" alt="Close" /></a>');
510 $
('body').append('<div id="fade"></div>');
511 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
516 $
('.btn_close').click(function(){
518 $
(this).next().hide();
519 if(editComment
> 0){ editComment
-= 1; }
522 //Close Popups and Fade Layer
523 $
('body').on('click', 'a.close, #fade', function() {
524 if(editComment
> 0){ editComment
-= 1; }
525 $
('#fade , #modal').fadeOut(function() {
526 $
('#fade, a.close').remove();
528 $
('#modalQuestion').hide();
531 $
('#loginAction').click(function(){
535 // Look if the customer is logged
537 displayMessage("You need to be loggued before commit something", 100, 40);
538 $
('.popover').show();
541 else{ userB64
= "Basic " + getUserPass("logginNitdoc"); }
542 githubRepo
= repoName
;
543 // Check if repo exist
549 commitMessage
= $
('#commitMessage').val();
550 if(commitMessage
== ""){ commitMessage
= "New commit";}
552 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
555 startCommitProcess();
558 $
('#modal, #modalQuestion').fadeOut(function() {
560 $
('#password').val("");
561 $
('textarea').hide();
562 $
('textarea').prev().show();
564 $
('a[id=cancelBtn]').hide();
565 $
('a[id=commitBtn]').hide();
566 // Re-load all comment
570 else{ editComment
-= 1; }
573 // Cancel creating branch
574 $
('#btnCancelBranch').click(function(){
576 $
('#modalQuestion').hide();
577 $
('#fade , #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
581 // Create new branch and continu
582 $
('#btnCreateBranch').click(function(){
583 $
('#modalQuestion').hide();
584 if($
('#btnCreateBranch').text() != 'Ok'){
587 commitMessage
= $
('#commitMessage').val();
588 if(commitMessage
== ""){ commitMessage
= "New commit"; }
590 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
591 else{ startCommitProcess(); }
596 $
('#fade , #modalQuestion, #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
600 $
('a[class=newComment]').click(function(){
601 addNewComment
= true;
606 $
(this).next().show();
607 // Show cancel button
608 $
(this).next().next().show();
609 // Show commit button
610 $
(this).next().next().next().show();
612 $
(this).next().height($
(this).next().prop("scrollHeight"));
614 $
(this).next().select();
615 preElement
= $
(this);
618 $
("#dropBranches").change(function () {
619 $
("#dropBranches option:selected").each(function () {
620 if(branchName
!= $
(this).text()){
621 branchName
= $
(this).text();
624 $
.when(updateCookie(userName
, password
, repoName
, branchName
)).done(function(){
630 /* Parse current URL and return anchor name */
631 function currentAnchor() {
632 var index
= document
.location
.hash
.indexOf("#");
634 return document
.location
.hash
.substring(index
+ 1);
639 /* Prealod filters field using search query */
640 function preloadFilters() {
641 // Parse URL and get query string
642 var search
= currentAnchor();
644 if(search
== null || search
.indexOf("q=") == -1)
647 search
= search
.substring(2, search
.length
);
649 if(search
== "" || search
== "undefined")
652 $
(":text").val(search
);
654 .removeClass("notUsed")
659 /* Hightlight the spoted block */
660 function highlightBlock(a
) {
665 $
(".highlighted").removeClass("highlighted");
667 var target
= $
("#" + a
);
669 if(target
.is("article")) {
670 target
.parent().addClass("highlighted");
673 target
.addClass("highlighted");
677 // Init process to commit the new comment
678 function startCommitProcess()
680 var numL
= preElement
.attr("title");
681 commentLineStart
= numL
.split('-')[0] - 1;
682 if(addNewComment
) { commentLineStart
++; }
683 commentLineEnd
= (commentLineStart
+ preElement
.text().split('\n').length
) - 1;
685 replaceComment(updateComment
, currentfileContent
);
691 function displayLogginModal(){
692 if ($
('.popover').is(':hidden')) {
693 if(sessionStarted
){ getListBranches(); }
694 $
('.popover').show();
696 else { $
('.popover').hide(); }
700 function updateDisplaying(){
703 userB64
= "Basic " + getUserPass("logginNitdoc");
704 $
('#loginGit').hide();
705 $
('#passwordGit').hide();
706 $
('#lbpasswordGit').hide();
707 $
('#lbloginGit').hide();
708 $
('#repositoryGit').hide();
709 $
('#lbrepositoryGit').hide();
710 $
('#lbbranchGit').hide();
711 $
('#branchGit').hide();
712 $
('#listBranches').show();
713 $
("#liGitHub").attr("class", "current");
714 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
715 $
('#nickName').text(userName
);
716 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
717 $
('#logginMessage').css({'display' : 'block'});
718 $
('#logginMessage').css({'text-align' : 'center'});
719 $
('.popover').css({'height' : '120px'});
720 $
('#signIn').text("Sign out");
721 sessionStarted
= true;
726 sessionStarted
= false;
727 $
('#logginMessage').css({'display' : 'none'});
728 $
("#liGitHub").attr("class", "");
729 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
730 $
('#loginGit').val("");
731 $
('#passwordGit').val("");
732 $
('#nickName').text("");
733 $
('.popover').css({'height' : '280px'});
734 $
('#logginMessage').css({'display' : 'none'});
735 $
('#repositoryGit').val($
('#repoName').attr('name'));
736 $
('#branchGit').val('wikidoc');
737 $
('#signIn').text("Sign In");
738 $
('#loginGit').show();
739 $
('#passwordGit').show();
740 $
('#lbpasswordGit').show();
741 $
('#lbloginGit').show();
742 $
('#repositoryGit').show();
743 $
('#lbrepositoryGit').show();
744 $
('#lbbranchGit').show();
745 $
('#branchGit').show();
746 $
('#listBranches').hide();
750 function setCookie(c_name
, value
, exdays
)
752 var exdate
=new Date();
753 exdate
.setDate(exdate
.getDate() + exdays
);
754 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
755 document
.cookie
=c_name
+ "=" + c_value
;
758 function del_cookie(c_name
)
760 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
763 function updateCookie(user
, pwd
, repo
, branch
){
766 setCookie("logginNitdoc", base64
.encode(user
+':'+pwd
+':'+repo
+':'+branch
), 1);
770 function getCookie(c_name
)
772 var c_value
= document
.cookie
;
773 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
774 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
775 if (c_start
== -1) { c_value
= null; }
778 c_start
= c_value
.indexOf("=", c_start
) + 1;
779 var c_end
= c_value
.indexOf(";", c_start
);
780 if (c_end
== -1) { c_end
= c_value
.length
; }
781 c_value
= unescape(c_value
.substring(c_start
,c_end
));
786 function getUserPass(c_name
){
787 var cookie
= base64
.decode(getCookie(c_name
));
788 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
791 function checkCookie()
793 var cookie
=getCookie("logginNitdoc");
794 if (cookie
!=null && cookie
!="")
796 cookie
= base64
.decode(cookie
);
797 userName
= cookie
.split(':')[0];
798 password
= cookie
.split(':')[1];
799 repoName
= cookie
.split(':')[2];
800 branchName
= cookie
.split(':')[3];
803 else { return false; }
811 base64
.PADCHAR
= '=';
812 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
813 base64
.getbyte64
= function(s
,i
) {
814 // This is oddly fast, except on Chrome/V8.
815 // Minimal or no improvement in performance by using a
816 // object with properties mapping chars to value (eg. 'A': 0)
817 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
819 throw "Cannot decode base64";
824 base64
.decode
= function(s
) {
827 var getbyte64
= base64
.getbyte64
;
835 throw "Cannot decode base64";
839 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
841 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
844 // either way, we want to ignore this last block
849 for (i
= 0; i
< imax
; i
+= 4) {
850 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
851 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
852 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
857 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
858 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
861 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
862 x
.push(String
.fromCharCode(b10
>> 16));
868 base64
.getbyte
= function(s
,i
) {
869 var x
= s
.charCodeAt(i
);
871 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
877 base64
.encode
= function(s
) {
878 if (arguments
.length
!= 1) {
879 throw "SyntaxError: Not enough arguments";
881 var padchar
= base64
.PADCHAR
;
882 var alpha
= base64
.ALPHA
;
883 var getbyte
= base64
.getbyte
;
891 var imax
= s
.length
- s
.length
% 3;
896 for (i
= 0; i
< imax
; i
+= 3) {
897 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
898 x
.push(alpha
.charAt(b10
>> 18));
899 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
900 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
901 x
.push(alpha
.charAt(b10
& 0x3f));
903 switch (s
.length
- imax
) {
905 b10
= getbyte(s
,i
) << 16;
906 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
910 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
911 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
912 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
920 function getLastCommit()
923 if(sessionStarted
){ urlHead
= "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
;}
925 // TODO: get url of the original repo.
930 beforeSend
: function (xhr
) {
931 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
937 success
: function(success
)
939 shaLastCommit
= success
.object
.sha
;
944 function getBaseTree()
947 beforeSend
: function (xhr
) {
948 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
951 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits/" + shaLastCommit
,
954 success
: function(success
)
956 shaBaseTree
= success
.tree
.sha
;
957 if (state
){ setBlob(); }
966 function setNewTree()
969 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
971 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/trees",
973 data
:'{ "base_tree" : "'+shaBaseTree
+'", '+
975 '"path":"'+ pathFile
+'",'+
978 '"sha": "'+ shaBlob
+'"'+
981 success
: function(success
)
982 { // si l'appel a bien fonctionné
983 shaNewTree
= JSON
.parse(success
).sha
;
992 function setNewCommit()
995 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
997 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits",
999 data
:'{ "message" : "'+ commitMessage
+'", '+
1000 '"parents" :"'+shaLastCommit
+'",'+
1001 '"tree": "'+shaNewTree
+'"'+
1003 success
: function(success
)
1005 shaNewCommit
= JSON
.parse(success
).sha
;
1018 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1020 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1021 data
:'{ "sha" : "'+shaNewCommit
+'", '+
1024 success
: function(success
) { displayMessage('Commit created successfully', 40, 40); },
1025 error
:function(error
){ displayMessage('Error ' + JSON
.parse(error
).object
.message
, 40, 40); }
1033 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1035 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/blobs",
1037 data
:'{ "content" : "'+text
.replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"')+'", '+
1038 '"encoding" :"utf-8"'+
1040 success
: function(success
)
1042 shaBlob
= JSON
.parse(success
).sha
;
1045 error
:function(error
){
1046 displayMessage('Error : Problem parsing JSON', 40, 40);
1052 // Display file content
1053 function getFileContent(urlFile
, newComment
)
1056 beforeSend
: function (xhr
) {
1057 xhr
.setRequestHeader ("Accept", "application/vnd.github-blob.raw");
1058 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1063 success
: function(success
)
1066 replaceComment(newComment
, success
);
1071 function replaceComment(newComment
, fileContent
){
1072 var arrayNew
= newComment
.split('\n');
1073 var lNew
= arrayNew
.length
;
1075 var lines
= fileContent
.split("\n");
1076 for (var i
= 0; i
< lines
.length
; i
++) {
1077 if(i
== commentLineStart
){
1079 for(var indexLine
=0; indexLine
< lines
[i
+1].length
; indexxLine
++){
1080 if(lines
[i
+1].substr(indexLine
,1) == "\t" || lines
[i
+1].substr(indexLine
,1) == "#"){ text
+= lines
[i
+1].substr(indexLine
,1); }
1083 text
+= lines
[i] + "\n";
1085 // We change the comment
1086 for(var j
= 0; j
< lNew
; j
++){
1087 if(commentType
== 1){ text
+= "\t# " + arrayNew
[j] + "\n"; }
1089 if(arrayNew
[j] == ""){ text
+= "#"+"\n"; }
1090 else{ text
+= "# " + arrayNew
[j] + "\n"; }
1094 else if(i
< commentLineStart || i
>= commentLineEnd
){
1095 if(i
== lines
.length
-1){ text
+= lines
[i]; }
1096 else{ text
+= lines
[i] + "\n"; }
1100 addNewComment
= false;
1104 function getCommentLastCommit(path
){
1107 if(shaLastCommit
!= ""){
1108 if (checkCookie()) { urlRaw
="https://rawgithub.com/"+ userName
+"/"+ repoName
+"/" + shaLastCommit
+ "/" + path
; }
1109 else{ urlRaw
="https://rawgithub.com/StefanLage/"+ $
('#repoName').attr('name') +"/" + shaLastCommit
+ "/" + path
; }
1115 success
: function(success
)
1117 currentfileContent
= success
;
1123 function displayMessage(msg
, widthDiv
, margModal
){
1126 $
('#btnCreateBranch').css('margin-left',widthDiv
+ '%');
1127 $
('#txtQuestion').text(msg
);
1128 $
('#btnCreateBranch').text("Ok");
1129 $
('#btnCancelBranch').hide();
1130 $
('#modalQuestion').css({'left' : margModal
+ '%'})
1131 $
('#modalQuestion').show();
1132 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1133 $
('body').append('<div id="fade"></div>');
1134 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1137 function displaySpinner(){
1138 spinner
.spin(targetSpinner
);
1139 $
("#waitCommit").show();
1142 // Check if the repo already exist
1143 function isRepoExisting(){
1145 beforeSend
: function (xhr
) {
1146 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1149 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1152 success
: function(){ repoExist
= true; },
1155 displayMessage('Repo not found !', 35, 45);
1161 // Check if the branch already exist
1162 function isBranchExisting(){
1164 beforeSend
: function (xhr
) {
1165 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1168 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1171 success
: function(){ branchExist
= true; },
1174 branchExist
= false;
1177 $
('#txtQuestion').text("Are you sure you want to create that branch ?");
1178 $
('#btnCancelBranch').show();
1179 $
('#btnCreateBranch').text("Yes");
1180 $
('#modalQuestion').show();
1181 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1182 $
('body').append('<div id="fade"></div>');
1183 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1188 function getMasterSha()
1191 beforeSend
: function (xhr
) {
1192 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1195 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/master",
1198 success
: function(success
) { shaMaster
= success
.object
.sha
; }
1202 function createBranch(){
1207 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1209 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs",
1210 data
:'{ "ref" : "refs/heads/'+branchName
+'",'+
1211 '"sha" : "'+shaMaster
+'"'+
1213 success
: function(){ return; },
1216 displayMessage('Impossible to create the new branch : ' + branchName
, 40, 40);
1221 $
.fn
.spin
= function(opts
) {
1222 this.each(function() {
1223 var $
this = $
(this),
1224 data
= $
this.data();
1227 data
.spinner
.stop();
1228 delete data
.spinner
;
1230 if (opts
!== false) {
1231 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);
1237 function reloadComment(){
1238 $
.when(getCommentLastCommit($
('pre[class=text_label]').attr('tag'))).done(function(){
1239 $
('pre[class=text_label]').each(function(){ getCommentOfFunction($
(this)); });
1243 function getCommentOfFunction(element
){
1245 var numL
= element
.attr("title");
1247 commentLineStart
= numL
.split('-')[0] - 1;
1248 commentLineEnd
= (commentLineStart
+ element
.text().split('\n').length
) - 1;
1249 var lines
= currentfileContent
.split("\n");
1250 for (var i
= 0; i
< lines
.length
; i
++) {
1251 if(i
>= commentLineStart
-1 && i
<= commentLineEnd
){
1252 if (lines
[i].substr(1,1) == "#"){ textC
+= lines
[i].substr(3,lines
[i].length
) + "\n";}
1253 else if(lines
[i].substr(0,1) == '#'){ textC
+= lines
[i].substr(2,lines
[i].length
) + "\n"; }
1256 if (textC
!= ""){ element
.text(textC
); }
1260 // Get list of branches
1261 function getListBranches()
1263 cleanListBranches();
1265 beforeSend
: function (xhr
) {
1266 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1269 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/branches",
1272 success
: function(success
)
1274 for(var branch
in success
) {
1276 if(branchName
== success
[branch].name
){
1277 selected
= 'selected';
1279 $
('#dropBranches').append('<option value="" '+ selected
+'>' + success
[branch].name
+ '</option>');
1285 // Delete all option in the list
1286 function cleanListBranches(){
1287 $
('#dropBranches').children("option").remove();