3 var sessionStarted
= false;
5 var currentfileContent
= '';
8 var shaLastCommit
= "";
14 var repoExist
= false;
15 var branchExist
= false;
20 lines
: 11, // The number of lines to draw
21 length
: 7, // The length of each line
22 width
: 4, // The line thickness
23 radius
: 10, // The radius of the inner circle
24 corners
: 1, // Corner roundness (0..1)
25 rotate
: 0, // The rotation offset
26 color
: '#FFF', // #rgb or #rrggbb
27 speed
: 1, // Rounds per second
28 trail
: 60, // Afterglow percentage
29 shadow
: false, // Whether to render a shadow
30 hwaccel
: false, // Whether to use hardware acceleration
31 className
: 'spinner', // The CSS class to assign to the spinner
32 zIndex
: 99999, // The z-index (defaults to 2000000000)
33 top
: '300', // Top position relative to parent in px
34 left
: 'auto' // Left position relative to parent in px
36 var targetSpinner
= document
.getElementById('waitCommit');
37 var spinner
= new Spinner(opts
).spin(targetSpinner
);
40 * JQuery Case Insensitive :icontains selector
42 $
.expr
[':'].icontains
= function(obj
, index
, meta
, stack
){
43 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;
47 * Quick Search global vars
50 // Current search results preview table
51 var currentTable
= null;
53 //Hightlighted index in search result preview table
54 var currentIndex
= -1;
58 * Add folding and filtering facilities to class description page.
60 $
(document
).ready(function() {
64 $
('a[id=commitBtn]').hide();
65 $
('a[id=cancelBtn]').hide();
66 // Hide Authenfication form
70 githubRepo
= $
('#repoName').attr('name');
71 // Load comment from the original repo
74 * Highlight the spoted element
76 highlightBlock(currentAnchor());
85 $
(document
.createElement("a"))
89 .css("cursor", "pointer")
91 if($
(this).find("a.fold").html() == "+") {
92 $
(this).find("a.fold").html("-");
94 $
(this).find("a.fold").html("+");
96 $
(this).nextAll().toggle();
99 // Insert search field
102 $
(document
.createElement("li"))
104 $
(document
.createElement("form"))
106 $
(document
.createElement("input"))
111 value
: "quick search..."
119 // Select previous result on "Up"
121 // If already on first result, focus search input
122 if(currentIndex
== 0) {
123 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
124 $
("#search").focus();
125 // Else select previous result
126 } else if(currentIndex
> 0) {
127 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
129 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
130 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
131 $
("#search").focus();
135 // Select next result on "Down"
137 if(currentIndex
< currentTable
.find("tr").length
- 1) {
138 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
140 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
141 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
142 $
("#search").focus();
145 // Go to url on "Enter"
147 if(currentIndex
> -1) {
148 window
.location
= $
(currentTable
.find("tr")[currentIndex]).data("searchDetails").url
;
151 if($
("#search").val().length
== 0)
154 window
.location
= "full-index.html#q=" + $
("#search").val();
155 if(window
.location
.href
.indexOf("full-index.html") > -1) {
161 // Hide results preview on "Escape"
164 if(currentTable
!= null) {
165 currentTable
.remove();
171 if($
("#search").val().length
== 0) {
175 // Remove previous table
176 if(currentTable
!= null) {
177 currentTable
.remove();
180 // Build results table
182 currentTable
= $
(document
.createElement("table"));
184 // Escape regexp related characters in query
185 var query
= $
("#search").val();
186 query
= query
.replace(/\
[/gi
, "\\[");
187 query
= query
.replace(/\|
/gi
, "\\|");
188 query
= query
.replace(/\*/gi
, "\\*");
189 query
= query
.replace(/\
+/gi
, "\\+");
190 query
= query
.replace(/\\/gi
, "\\\\");
191 query
= query
.replace(/\?/gi
, "\\?");
192 query
= query
.replace(/\
(/gi
, "\\(");
193 query
= query
.replace(/\
)/gi
, "\\)");
196 var regexp
= new RegExp("^" + query
, "i");
197 for(var entry
in entries
) {
201 var result
= entry
.match(regexp
);
202 if(result
!= null && result
.toString().toUpperCase() == $
("#search").val().toUpperCase()) {
203 for(var i
= 0; i
< entries
[entry].length
; i
++) {
208 $
(document
.createElement("tr"))
209 .data("searchDetails", {name
: entry
, url
: entries
[entry][i]["url"]})
210 .data("index", index
)
211 .append($
(document
.createElement("td")).html(entry
))
213 $
(document
.createElement("td"))
214 .addClass("entryInfo")
215 .html(entries
[entry][i]["txt"] + " »"))
216 .mouseover( function() {
217 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
218 $
(this).addClass("activeSearchResult");
219 currentIndex
= $
(this).data("index");
221 .mouseout( function() {
222 $
(this).removeClass("activeSearchResult");
225 window
.location
= $
(this).data("searchDetails")["url"];
233 // Initialize table properties
234 currentTable
.attr("id", "searchTable");
235 currentTable
.css("position", "absolute");
236 currentTable
.width($
("#search").outerWidth());
237 $
("header").append(currentTable
);
238 currentTable
.offset({left
: $
("#search").offset().left
+ ($
("#search").outerWidth() - currentTable
.outerWidth()), top
: $
("#search").offset().top
+ $
("#search").outerHeight()});
240 // Preselect first entry
241 if(currentTable
.find("tr").length
> 0) {
243 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
244 $
("#search").focus();
249 .focusout(function() {
250 if($
(this).val() == "") {
251 $
(this).addClass("notUsed");
252 $
(this).val("quick search...");
255 .focusin(function() {
256 if($
(this).val() == "quick search...") {
257 $
(this).removeClass("notUsed");
262 .submit( function() {
268 // Close quicksearch list on click
269 $
(document
).click(function(e
) {
270 if(e
.target
!= $
("#search")[0] && e
.target
!= $
("#searchTable")[0]) {
271 if(currentTable
!= null) {
272 currentTable
.remove();
278 // Insert filter field
279 $
("article.filterable h2, nav.filterable h3")
281 $
(document
.createElement("div"))
284 $
(document
.createElement("input"))
291 $
(this).parent().parent().find("ul li:not(:icontains('" + $
(this).val() + "'))").addClass("hide");
292 $
(this).parent().parent().find("ul li:icontains('" + $
(this).val() + "')").removeClass("hide");
294 .focusout(function() {
295 if($
(this).val() == "") {
296 $
(this).addClass("notUsed");
297 $
(this).val("filter...");
300 .focusin(function() {
301 if($
(this).val() == "filter...") {
302 $
(this).removeClass("notUsed");
309 // Filter toggle between H I R in nav porperties list
310 $
("nav.properties.filterable .filter")
312 $
(document
.createElement("a"))
315 title
: "hide inherited properties"
318 if($
(this).hasClass("hidden")) {
319 $
(this).parent().parent().find("li.inherit").show();
321 $
(this).parent().parent().find("li.inherit").hide();
324 $
(this).toggleClass("hidden");
328 $
(document
.createElement("a"))
331 title
: "hide redefined properties"
334 if($
(this).hasClass("hidden")) {
335 $
(this).parent().parent().find("li.redef").show();
337 $
(this).parent().parent().find("li.redef").hide();
340 $
(this).toggleClass("hidden");
344 $
(document
.createElement("a"))
347 title
: "hide introduced properties"
350 if($
(this).hasClass("hidden")) {
351 $
(this).parent().parent().find("li.intro").show();
353 $
(this).parent().parent().find("li.intro").hide();
356 $
(this).toggleClass("hidden");
360 // Filter toggle between I R in
361 $
("article.properties.filterable .filter, article.classes.filterable .filter")
363 $
(document
.createElement("a"))
366 title
: "hide introduced properties"
369 if($
(this).hasClass("hidden")) {
370 $
(this).parent().parent().find("li.intro").show();
372 $
(this).parent().parent().find("li.intro").hide();
375 $
(this).toggleClass("hidden");
379 $
(document
.createElement("a"))
382 title
: "hide redefined properties"
385 if($
(this).hasClass("hidden")) {
386 $
(this).parent().parent().find("li.redef").show();
388 $
(this).parent().parent().find("li.redef").hide();
391 $
(this).toggleClass("hidden");
398 $
("a[href*='#']").click( function() {
399 highlightBlock($
(this).attr("href").split(/#
/)[1]);
402 //Preload filter fields with query string
404 // Hide Authenfication form
405 $
(".popover").hide();
406 // Display Login modal
407 $
("#logGitHub").click(function(){ displayLogginModal(); });
410 // If cookie existing the session is opened
411 if(sessionStarted
){ userB64
= "Basic " + getUserPass("logginNitdoc"); }
413 // Sign In an github user or Log out him
414 $
("#signIn").click(function(){
416 if($
('#loginGit').val() == "" || $
('#passwordGit').val() == ""){ displayMessage('The comment field is empty!', 40, 45); }
419 userName
= $
('#loginGit').val();
420 password
= $
('#passwordGit').val();
421 repoName
= $
('#repositoryGit').val();
422 branchName
= $
('#branchGit').val();
423 userB64
= "Basic " + base64
.encode(userName
+':'+password
);
424 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+repoName
+':'+branchName
), 1);
425 $
('#loginGit').val("");
426 $
('#passwordGit').val("");
431 // Delete cookie and reset settings
432 del_cookie("logginNitdoc");
434 displayLogginModal();
437 // Activate edit mode
438 $
('pre[class=text_label]').click(function(){
439 // the customer is loggued ?
440 if(!sessionStarted || userName
== ""){
441 // No => nothing happen
445 var arrayNew
= $
(this).text().split('\n');
446 var lNew
= arrayNew
.length
- 1;
449 for (var i
= 0; i
< lNew
; i
++) {
450 adapt
+= arrayNew
[i];
451 if(i
< lNew
-1){ adapt
+= "\n"; }
457 $
(this).next().show();
458 // Show cancel button
459 $
(this).next().next().show();
460 // Show commit button
461 $
(this).next().next().next().show();
462 // Add text in edit box
463 if($
(this).next().val() == ""){ $
(this).next().val(adapt
); }
465 $
(this).next().height($
(this).next().prop("scrollHeight"));
467 $
(this).next().select();
468 preElement
= $
(this);
472 // Disable the edit mode
473 $
('a[id=cancelBtn]').click(function(){
474 if(editComment
> 0){ editComment
-= 1; }
478 $
(this).next().hide();
480 $
(this).prev().hide();
482 $
(this).prev().prev().show();
485 // Display commit form
486 $
('a[id=commitBtn]').click(function(){
487 updateComment
= $
(this).prev().prev().val();
488 commentType
= $
(this).prev().prev().prev().attr('type');
490 if(updateComment
== ""){ displayMessage('The comment field is empty!', 40, 45); }
493 displayMessage("You need to be loggued before commit something", 45, 40);
494 displayLogginModal();
497 $
('#commitMessage').val('New commit');
498 pathFile
= $
(this).prev().prev().prev().attr('tag');
499 $
('#modal').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btn_close" title="Close" alt="Close" /></a>');
500 $
('body').append('<div id="fade"></div>');
501 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
506 $
('.btn_close').click(function(){
508 $
(this).next().hide();
509 if(editComment
> 0){ editComment
-= 1; }
512 //Close Popups and Fade Layer
513 $
('body').on('click', 'a.close, #fade', function() {
514 if(editComment
> 0){ editComment
-= 1; }
515 $
('#fade , #modal').fadeOut(function() {
516 $
('#fade, a.close').remove();
518 $
('#modalQuestion').hide();
521 $
('#loginAction').click(function(){
525 // Look if the customer is logged
527 displayMessage("You need to be loggued before commit something", 100, 40);
528 $
('.popover').show();
531 else{ userB64
= "Basic " + getUserPass("logginNitdoc"); }
532 githubRepo
= repoName
;
533 // Check if repo exist
539 commitMessage
= $
('#commitMessage').val();
540 if(commitMessage
== ""){ commitMessage
= "New commit";}
542 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
545 startCommitProcess();
548 $
('#modal, #modalQuestion').fadeOut(function() {
550 $
('#password').val("");
551 $
('textarea').hide();
552 $
('textarea').prev().show();
554 $
('a[id=cancelBtn]').hide();
555 $
('a[id=commitBtn]').hide();
556 // Re-load all comment
560 else{ editComment
-= 1; }
563 // Cancel creating branch
564 $
('#btnCancelBranch').click(function(){
566 $
('#modalQuestion').hide();
567 $
('#fade , #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
571 // Create new branch and continu
572 $
('#btnCreateBranch').click(function(){
573 $
('#modalQuestion').hide();
574 if($
('#btnCreateBranch').text() != 'Ok'){
577 commitMessage
= $
('#commitMessage').val();
578 if(commitMessage
== ""){ commitMessage
= "New commit"; }
580 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
581 else{ startCommitProcess(); }
586 $
('#fade , #modalQuestion, #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
592 /* Parse current URL and return anchor name */
593 function currentAnchor() {
594 var index
= document
.location
.hash
.indexOf("#");
596 return document
.location
.hash
.substring(index
+ 1);
601 /* Prealod filters field using search query */
602 function preloadFilters() {
603 // Parse URL and get query string
604 var search
= currentAnchor();
606 if(search
== null || search
.indexOf("q=") == -1)
609 search
= search
.substring(2, search
.length
);
611 if(search
== "" || search
== "undefined")
614 $
(":text").val(search
);
616 .removeClass("notUsed")
621 /* Hightlight the spoted block */
622 function highlightBlock(a
) {
627 $
(".highlighted").removeClass("highlighted");
629 var target
= $
("#" + a
);
631 if(target
.is("article")) {
632 target
.parent().addClass("highlighted");
635 target
.addClass("highlighted");
639 // Init process to commit the new comment
640 function startCommitProcess()
642 var numL
= preElement
.attr("title");
643 commentLineStart
= numL
.split('-')[0] - 1;
644 commentLineEnd
= (commentLineStart
+ preElement
.text().split('\n').length
) - 1;
646 replaceComment(updateComment
, currentfileContent
);
652 function displayLogginModal(){
653 if ($
('.popover').is(':hidden')) { $
('.popover').show(); }
654 else { $
('.popover').hide(); }
658 function updateDisplaying(){
661 $
('#loginGit').hide();
662 $
('#passwordGit').hide();
663 $
('#lbpasswordGit').hide();
664 $
('#lbloginGit').hide();
665 $
('#repositoryGit').hide();
666 $
('#lbrepositoryGit').hide();
667 $
('#lbbranchGit').hide();
668 $
('#branchGit').hide();
669 $
("#liGitHub").attr("class", "current");
670 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
671 $
('#nickName').text(userName
);
672 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
673 $
('#logginMessage').css({'display' : 'block'});
674 $
('#logginMessage').css({'text-align' : 'center'});
675 $
('.popover').css({'height' : '80px'});
676 $
('#signIn').text("Sign out");
677 sessionStarted
= true;
681 sessionStarted
= false;
682 $
('#logginMessage').css({'display' : 'none'});
683 $
("#liGitHub").attr("class", "");
684 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
685 $
('#loginGit').val("");
686 $
('#passwordGit').val("");
687 $
('#nickName').text("");
688 $
('.popover').css({'height' : '280px'});
689 $
('#logginMessage').css({'display' : 'none'});
690 $
('#repositoryGit').val($
('#repoName').attr('name'));
691 $
('#branchGit').val('wikidoc');
692 $
('#signIn').text("Sign In");
693 $
('#loginGit').show();
694 $
('#passwordGit').show();
695 $
('#lbpasswordGit').show();
696 $
('#lbloginGit').show();
697 $
('#repositoryGit').show();
698 $
('#lbrepositoryGit').show();
699 $
('#lbbranchGit').show();
700 $
('#branchGit').show();
704 function setCookie(c_name
, value
, exdays
)
706 var exdate
=new Date();
707 exdate
.setDate(exdate
.getDate() + exdays
);
708 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
709 document
.cookie
=c_name
+ "=" + c_value
;
712 function del_cookie(c_name
)
714 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
717 function getCookie(c_name
)
719 var c_value
= document
.cookie
;
720 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
721 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
722 if (c_start
== -1) { c_value
= null; }
725 c_start
= c_value
.indexOf("=", c_start
) + 1;
726 var c_end
= c_value
.indexOf(";", c_start
);
727 if (c_end
== -1) { c_end
= c_value
.length
; }
728 c_value
= unescape(c_value
.substring(c_start
,c_end
));
733 function getUserPass(c_name
){
734 var cookie
= base64
.decode(getCookie(c_name
));
735 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
738 function checkCookie()
740 var cookie
=getCookie("logginNitdoc");
741 if (cookie
!=null && cookie
!="")
743 cookie
= base64
.decode(cookie
);
744 userName
= cookie
.split(':')[0];
745 repoName
= cookie
.split(':')[2];
746 branchName
= cookie
.split(':')[3];
749 else { return false; }
757 base64
.PADCHAR
= '=';
758 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
759 base64
.getbyte64
= function(s
,i
) {
760 // This is oddly fast, except on Chrome/V8.
761 // Minimal or no improvement in performance by using a
762 // object with properties mapping chars to value (eg. 'A': 0)
763 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
765 throw "Cannot decode base64";
770 base64
.decode
= function(s
) {
773 var getbyte64
= base64
.getbyte64
;
781 throw "Cannot decode base64";
785 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
787 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
790 // either way, we want to ignore this last block
795 for (i
= 0; i
< imax
; i
+= 4) {
796 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
797 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
798 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
803 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
804 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
807 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
808 x
.push(String
.fromCharCode(b10
>> 16));
814 base64
.getbyte
= function(s
,i
) {
815 var x
= s
.charCodeAt(i
);
817 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
823 base64
.encode
= function(s
) {
824 if (arguments
.length
!= 1) {
825 throw "SyntaxError: Not enough arguments";
827 var padchar
= base64
.PADCHAR
;
828 var alpha
= base64
.ALPHA
;
829 var getbyte
= base64
.getbyte
;
837 var imax
= s
.length
- s
.length
% 3;
842 for (i
= 0; i
< imax
; i
+= 3) {
843 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
844 x
.push(alpha
.charAt(b10
>> 18));
845 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
846 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
847 x
.push(alpha
.charAt(b10
& 0x3f));
849 switch (s
.length
- imax
) {
851 b10
= getbyte(s
,i
) << 16;
852 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
856 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
857 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
858 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
866 function getLastCommit()
869 if(sessionStarted
){ urlHead
= "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
;}
871 // TODO: get url of the original repo.
876 beforeSend
: function (xhr
) {
877 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
883 success
: function(success
)
885 shaLastCommit
= success
.object
.sha
;
890 function getBaseTree()
893 beforeSend
: function (xhr
) {
894 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
897 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits/" + shaLastCommit
,
900 success
: function(success
)
902 shaBaseTree
= success
.tree
.sha
;
903 if (state
){ setBlob(); }
912 function setNewTree()
915 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
917 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/trees",
919 data
:'{ "base_tree" : "'+shaBaseTree
+'", '+
921 '"path":"'+ pathFile
+'",'+
924 '"sha": "'+ shaBlob
+'"'+
927 success
: function(success
)
928 { // si l'appel a bien fonctionné
929 shaNewTree
= JSON
.parse(success
).sha
;
938 function setNewCommit()
941 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
943 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits",
945 data
:'{ "message" : "'+ commitMessage
+'", '+
946 '"parents" :"'+shaLastCommit
+'",'+
947 '"tree": "'+shaNewTree
+'"'+
949 success
: function(success
)
951 shaNewCommit
= JSON
.parse(success
).sha
;
964 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
966 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
967 data
:'{ "sha" : "'+shaNewCommit
+'", '+
970 success
: function(success
) { displayMessage('Commit created successfully', 40, 40); },
971 error
:function(error
){ displayMessage('Error ' + JSON
.parse(error
).object
.message
, 40, 40); }
979 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
981 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/blobs",
983 data
:'{ "content" : "'+text
.replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"')+'", '+
984 '"encoding" :"utf-8"'+
986 success
: function(success
)
988 shaBlob
= JSON
.parse(success
).sha
;
991 error
:function(error
){
992 displayMessage('Error : Problem parsing JSON', 40, 40);
998 // Display file content
999 function getFileContent(urlFile
, newComment
)
1002 beforeSend
: function (xhr
) {
1003 xhr
.setRequestHeader ("Accept", "application/vnd.github-blob.raw");
1004 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1009 success
: function(success
)
1012 replaceComment(newComment
, success
);
1017 function replaceComment(newComment
, fileContent
){
1018 var arrayNew
= newComment
.split('\n');
1019 var lNew
= arrayNew
.length
;
1021 var lines
= fileContent
.split("\n");
1022 for (var i
= 0; i
< lines
.length
; i
++) {
1023 if(i
== commentLineStart
){
1024 // We change the comment
1025 for(var j
= 0; j
< lNew
; j
++){
1026 if(commentType
== 1){ text
+= "\t# " + arrayNew
[j] + "\n"; }
1028 if(arrayNew
[j] == ""){ text
+= "#"+"\n"; }
1029 else{ text
+= "# " + arrayNew
[j] + "\n"; }
1033 else if(i
< commentLineStart || i
>= commentLineEnd
){
1034 if(i
== lines
.length
-1){ text
+= lines
[i]; }
1035 else{ text
+= lines
[i] + "\n"; }
1040 function getCommentLastCommit(path
){
1043 if(shaLastCommit
!= ""){
1044 if (checkCookie()) { urlRaw
="https://rawgithub.com/"+ userName
+"/"+ repoName
+"/" + shaLastCommit
+ "/" + path
; }
1045 else{ urlRaw
="https://rawgithub.com/StefanLage/"+ $
('#repoName').attr('name') +"/" + shaLastCommit
+ "/" + path
; }
1051 success
: function(success
)
1053 currentfileContent
= success
;
1059 function displayMessage(msg
, widthDiv
, margModal
){
1062 $
('#btnCreateBranch').css('margin-left',widthDiv
+ '%');
1063 $
('#txtQuestion').text(msg
);
1064 $
('#btnCreateBranch').text("Ok");
1065 $
('#btnCancelBranch').hide();
1066 $
('#modalQuestion').css({'left' : margModal
+ '%'})
1067 $
('#modalQuestion').show();
1068 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1069 $
('body').append('<div id="fade"></div>');
1070 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1073 function displaySpinner(){
1074 spinner
.spin(targetSpinner
);
1075 $
("#waitCommit").show();
1078 // Check if the repo already exist
1079 function isRepoExisting(){
1081 beforeSend
: function (xhr
) {
1082 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1085 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1088 success
: function(){ repoExist
= true; },
1091 displayMessage('Repo not found !', 35, 45);
1097 // Check if the branch already exist
1098 function isBranchExisting(){
1100 beforeSend
: function (xhr
) {
1101 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1104 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1107 success
: function(){ branchExist
= true; },
1110 branchExist
= false;
1113 $
('#txtQuestion').text("Are you sure you want to create that branch ?");
1114 $
('#btnCancelBranch').show();
1115 $
('#btnCreateBranch').text("Yes");
1116 $
('#modalQuestion').show();
1117 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1118 $
('body').append('<div id="fade"></div>');
1119 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1124 function getMasterSha()
1127 beforeSend
: function (xhr
) {
1128 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1131 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/master",
1134 success
: function(success
) { shaMaster
= success
.object
.sha
; }
1138 function createBranch(){
1143 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1145 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs",
1146 data
:'{ "ref" : "refs/heads/'+branchName
+'",'+
1147 '"sha" : "'+shaMaster
+'"'+
1149 success
: function(){ return; },
1152 displayMessage('Impossible to create the new branch : ' + branchName
, 40, 40);
1157 $
.fn
.spin
= function(opts
) {
1158 this.each(function() {
1159 var $
this = $
(this),
1160 data
= $
this.data();
1163 data
.spinner
.stop();
1164 delete data
.spinner
;
1166 if (opts
!== false) {
1167 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);
1173 function reloadComment(){
1174 $
.when(getCommentLastCommit($
('pre[class=text_label]').attr('tag'))).done(function(){
1175 $
('pre[class=text_label]').each(function(){ getCommentOfFunction($
(this)); });
1179 function getCommentOfFunction(element
){
1181 var numL
= element
.attr("title");
1183 commentLineStart
= numL
.split('-')[0] - 1;
1184 commentLineEnd
= (commentLineStart
+ element
.text().split('\n').length
) - 1;
1185 var lines
= currentfileContent
.split("\n");
1186 for (var i
= 0; i
< lines
.length
; i
++) {
1187 if(i
>= commentLineStart
-1 && i
<= commentLineEnd
){
1188 if (lines
[i].substr(1,1) == "#"){ textC
+= lines
[i].substr(3,lines
[i].length
) + "\n";}
1189 else if(lines
[i].substr(0,1) == '#'){ textC
+= lines
[i].substr(2,lines
[i].length
) + "\n"; }
1192 if (textC
!= ""){ element
.text(textC
); }