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;
56 // Check if a comment is editing
57 window
.onbeforeunload
= function() {
59 return 'Are you sure you want to leave this page?';
64 * Add folding and filtering facilities to class description page.
66 $
(document
).ready(function() {
70 $
('a[id=commitBtn]').hide();
71 $
('a[id=cancelBtn]').hide();
72 // Hide Authenfication form
76 githubRepo
= $
('#repoName').attr('name');
77 // Load comment from the original repo
80 * Highlight the spoted element
82 highlightBlock(currentAnchor());
91 $
(document
.createElement("a"))
95 .css("cursor", "pointer")
97 if($
(this).find("a.fold").html() == "+") {
98 $
(this).find("a.fold").html("-");
100 $
(this).find("a.fold").html("+");
102 $
(this).nextAll().toggle();
105 // Insert search field
108 $
(document
.createElement("li"))
110 $
(document
.createElement("form"))
112 $
(document
.createElement("input"))
117 value
: "quick search..."
125 // Select previous result on "Up"
127 // If already on first result, focus search input
128 if(currentIndex
== 0) {
129 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
130 $
("#search").focus();
131 // Else select previous result
132 } else if(currentIndex
> 0) {
133 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
135 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
136 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
137 $
("#search").focus();
141 // Select next result on "Down"
143 if(currentIndex
< currentTable
.find("tr").length
- 1) {
144 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
146 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
147 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
148 $
("#search").focus();
151 // Go to url on "Enter"
153 if(currentIndex
> -1) {
154 window
.location
= $
(currentTable
.find("tr")[currentIndex]).data("searchDetails").url
;
157 if($
("#search").val().length
== 0)
160 window
.location
= "full-index.html#q=" + $
("#search").val();
161 if(window
.location
.href
.indexOf("full-index.html") > -1) {
167 // Hide results preview on "Escape"
170 if(currentTable
!= null) {
171 currentTable
.remove();
177 if($
("#search").val().length
== 0) {
181 // Remove previous table
182 if(currentTable
!= null) {
183 currentTable
.remove();
186 // Build results table
188 currentTable
= $
(document
.createElement("table"));
190 // Escape regexp related characters in query
191 var query
= $
("#search").val();
192 query
= query
.replace(/\
[/gi
, "\\[");
193 query
= query
.replace(/\|
/gi
, "\\|");
194 query
= query
.replace(/\*/gi
, "\\*");
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
, "\\)");
202 var regexp
= new RegExp("^" + query
, "i");
203 for(var entry
in entries
) {
207 var result
= entry
.match(regexp
);
208 if(result
!= null && result
.toString().toUpperCase() == $
("#search").val().toUpperCase()) {
209 for(var i
= 0; i
< entries
[entry].length
; i
++) {
214 $
(document
.createElement("tr"))
215 .data("searchDetails", {name
: entry
, url
: entries
[entry][i]["url"]})
216 .data("index", index
)
217 .append($
(document
.createElement("td")).html(entry
))
219 $
(document
.createElement("td"))
220 .addClass("entryInfo")
221 .html(entries
[entry][i]["txt"] + " »"))
222 .mouseover( function() {
223 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
224 $
(this).addClass("activeSearchResult");
225 currentIndex
= $
(this).data("index");
227 .mouseout( function() {
228 $
(this).removeClass("activeSearchResult");
231 window
.location
= $
(this).data("searchDetails")["url"];
239 // Initialize table properties
240 currentTable
.attr("id", "searchTable");
241 currentTable
.css("position", "absolute");
242 currentTable
.width($
("#search").outerWidth());
243 $
("header").append(currentTable
);
244 currentTable
.offset({left
: $
("#search").offset().left
+ ($
("#search").outerWidth() - currentTable
.outerWidth()), top
: $
("#search").offset().top
+ $
("#search").outerHeight()});
246 // Preselect first entry
247 if(currentTable
.find("tr").length
> 0) {
249 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
250 $
("#search").focus();
255 .focusout(function() {
256 if($
(this).val() == "") {
257 $
(this).addClass("notUsed");
258 $
(this).val("quick search...");
261 .focusin(function() {
262 if($
(this).val() == "quick search...") {
263 $
(this).removeClass("notUsed");
268 .submit( function() {
274 // Close quicksearch list on click
275 $
(document
).click(function(e
) {
276 if(e
.target
!= $
("#search")[0] && e
.target
!= $
("#searchTable")[0]) {
277 if(currentTable
!= null) {
278 currentTable
.remove();
284 // Insert filter field
285 $
("article.filterable h2, nav.filterable h3")
287 $
(document
.createElement("div"))
290 $
(document
.createElement("input"))
297 $
(this).parent().parent().find("ul li:not(:icontains('" + $
(this).val() + "'))").addClass("hide");
298 $
(this).parent().parent().find("ul li:icontains('" + $
(this).val() + "')").removeClass("hide");
300 .focusout(function() {
301 if($
(this).val() == "") {
302 $
(this).addClass("notUsed");
303 $
(this).val("filter...");
306 .focusin(function() {
307 if($
(this).val() == "filter...") {
308 $
(this).removeClass("notUsed");
315 // Filter toggle between H I R in nav porperties list
316 $
("nav.properties.filterable .filter")
318 $
(document
.createElement("a"))
321 title
: "hide inherited properties"
324 if($
(this).hasClass("hidden")) {
325 $
(this).parent().parent().find("li.inherit").show();
327 $
(this).parent().parent().find("li.inherit").hide();
330 $
(this).toggleClass("hidden");
334 $
(document
.createElement("a"))
337 title
: "hide redefined properties"
340 if($
(this).hasClass("hidden")) {
341 $
(this).parent().parent().find("li.redef").show();
343 $
(this).parent().parent().find("li.redef").hide();
346 $
(this).toggleClass("hidden");
350 $
(document
.createElement("a"))
353 title
: "hide introduced properties"
356 if($
(this).hasClass("hidden")) {
357 $
(this).parent().parent().find("li.intro").show();
359 $
(this).parent().parent().find("li.intro").hide();
362 $
(this).toggleClass("hidden");
366 // Filter toggle between I R in
367 $
("article.properties.filterable .filter, article.classes.filterable .filter")
369 $
(document
.createElement("a"))
372 title
: "hide introduced properties"
375 if($
(this).hasClass("hidden")) {
376 $
(this).parent().parent().find("li.intro").show();
378 $
(this).parent().parent().find("li.intro").hide();
381 $
(this).toggleClass("hidden");
385 $
(document
.createElement("a"))
388 title
: "hide redefined properties"
391 if($
(this).hasClass("hidden")) {
392 $
(this).parent().parent().find("li.redef").show();
394 $
(this).parent().parent().find("li.redef").hide();
397 $
(this).toggleClass("hidden");
404 $
("a[href*='#']").click( function() {
405 highlightBlock($
(this).attr("href").split(/#
/)[1]);
408 //Preload filter fields with query string
410 // Hide Authenfication form
411 $
(".popover").hide();
412 // Display Login modal
413 $
("#logGitHub").click(function(){ displayLogginModal(); });
416 // If cookie existing the session is opened
417 if(sessionStarted
){ userB64
= "Basic " + getUserPass("logginNitdoc"); }
419 // Sign In an github user or Log out him
420 $
("#signIn").click(function(){
422 if($
('#loginGit').val() == "" || $
('#passwordGit').val() == ""){ displayMessage('The comment field is empty!', 40, 45); }
425 userName
= $
('#loginGit').val();
426 password
= $
('#passwordGit').val();
427 repoName
= $
('#repositoryGit').val();
428 branchName
= $
('#branchGit').val();
429 userB64
= "Basic " + base64
.encode(userName
+':'+password
);
430 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+repoName
+':'+branchName
), 1);
431 $
('#loginGit').val("");
432 $
('#passwordGit').val("");
437 // Delete cookie and reset settings
438 del_cookie("logginNitdoc");
440 displayLogginModal();
443 // Activate edit mode
444 $
('pre[class=text_label]').click(function(){
445 // the customer is loggued ?
446 if(!sessionStarted || userName
== ""){
447 // No => nothing happen
451 var arrayNew
= $
(this).text().split('\n');
452 var lNew
= arrayNew
.length
- 1;
455 for (var i
= 0; i
< lNew
; i
++) {
456 adapt
+= arrayNew
[i];
457 if(i
< lNew
-1){ adapt
+= "\n"; }
463 $
(this).next().show();
464 // Show cancel button
465 $
(this).next().next().show();
466 // Show commit button
467 $
(this).next().next().next().show();
468 // Add text in edit box
469 if($
(this).next().val() == ""){ $
(this).next().val(adapt
); }
471 $
(this).next().height($
(this).next().prop("scrollHeight"));
473 $
(this).next().select();
474 preElement
= $
(this);
478 // Disable the edit mode
479 $
('a[id=cancelBtn]').click(function(){
480 if(editComment
> 0){ editComment
-= 1; }
484 $
(this).next().hide();
486 $
(this).prev().hide();
488 $
(this).prev().prev().show();
491 // Display commit form
492 $
('a[id=commitBtn]').click(function(){
493 updateComment
= $
(this).prev().prev().val();
494 commentType
= $
(this).prev().prev().prev().attr('type');
496 if(updateComment
== ""){ displayMessage('The comment field is empty!', 40, 45); }
499 displayMessage("You need to be loggued before commit something", 45, 40);
500 displayLogginModal();
503 $
('#commitMessage').val('New commit');
504 pathFile
= $
(this).prev().prev().prev().attr('tag');
505 $
('#modal').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btn_close" title="Close" alt="Close" /></a>');
506 $
('body').append('<div id="fade"></div>');
507 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
512 $
('.btn_close').click(function(){
514 $
(this).next().hide();
515 if(editComment
> 0){ editComment
-= 1; }
518 //Close Popups and Fade Layer
519 $
('body').on('click', 'a.close, #fade', function() {
520 if(editComment
> 0){ editComment
-= 1; }
521 $
('#fade , #modal').fadeOut(function() {
522 $
('#fade, a.close').remove();
524 $
('#modalQuestion').hide();
527 $
('#loginAction').click(function(){
531 // Look if the customer is logged
533 displayMessage("You need to be loggued before commit something", 100, 40);
534 $
('.popover').show();
537 else{ userB64
= "Basic " + getUserPass("logginNitdoc"); }
538 githubRepo
= repoName
;
539 // Check if repo exist
545 commitMessage
= $
('#commitMessage').val();
546 if(commitMessage
== ""){ commitMessage
= "New commit";}
548 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
551 startCommitProcess();
554 $
('#modal, #modalQuestion').fadeOut(function() {
556 $
('#password').val("");
557 $
('textarea').hide();
558 $
('textarea').prev().show();
560 $
('a[id=cancelBtn]').hide();
561 $
('a[id=commitBtn]').hide();
562 // Re-load all comment
566 else{ editComment
-= 1; }
569 // Cancel creating branch
570 $
('#btnCancelBranch').click(function(){
572 $
('#modalQuestion').hide();
573 $
('#fade , #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
577 // Create new branch and continu
578 $
('#btnCreateBranch').click(function(){
579 $
('#modalQuestion').hide();
580 if($
('#btnCreateBranch').text() != 'Ok'){
583 commitMessage
= $
('#commitMessage').val();
584 if(commitMessage
== ""){ commitMessage
= "New commit"; }
586 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
587 else{ startCommitProcess(); }
592 $
('#fade , #modalQuestion, #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
598 /* Parse current URL and return anchor name */
599 function currentAnchor() {
600 var index
= document
.location
.hash
.indexOf("#");
602 return document
.location
.hash
.substring(index
+ 1);
607 /* Prealod filters field using search query */
608 function preloadFilters() {
609 // Parse URL and get query string
610 var search
= currentAnchor();
612 if(search
== null || search
.indexOf("q=") == -1)
615 search
= search
.substring(2, search
.length
);
617 if(search
== "" || search
== "undefined")
620 $
(":text").val(search
);
622 .removeClass("notUsed")
627 /* Hightlight the spoted block */
628 function highlightBlock(a
) {
633 $
(".highlighted").removeClass("highlighted");
635 var target
= $
("#" + a
);
637 if(target
.is("article")) {
638 target
.parent().addClass("highlighted");
641 target
.addClass("highlighted");
645 // Init process to commit the new comment
646 function startCommitProcess()
648 var numL
= preElement
.attr("title");
649 commentLineStart
= numL
.split('-')[0] - 1;
650 commentLineEnd
= (commentLineStart
+ preElement
.text().split('\n').length
) - 1;
652 replaceComment(updateComment
, currentfileContent
);
658 function displayLogginModal(){
659 if ($
('.popover').is(':hidden')) { $
('.popover').show(); }
660 else { $
('.popover').hide(); }
664 function updateDisplaying(){
667 $
('#loginGit').hide();
668 $
('#passwordGit').hide();
669 $
('#lbpasswordGit').hide();
670 $
('#lbloginGit').hide();
671 $
('#repositoryGit').hide();
672 $
('#lbrepositoryGit').hide();
673 $
('#lbbranchGit').hide();
674 $
('#branchGit').hide();
675 $
("#liGitHub").attr("class", "current");
676 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
677 $
('#nickName').text(userName
);
678 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
679 $
('#logginMessage').css({'display' : 'block'});
680 $
('#logginMessage').css({'text-align' : 'center'});
681 $
('.popover').css({'height' : '80px'});
682 $
('#signIn').text("Sign out");
683 sessionStarted
= true;
687 sessionStarted
= false;
688 $
('#logginMessage').css({'display' : 'none'});
689 $
("#liGitHub").attr("class", "");
690 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
691 $
('#loginGit').val("");
692 $
('#passwordGit').val("");
693 $
('#nickName').text("");
694 $
('.popover').css({'height' : '280px'});
695 $
('#logginMessage').css({'display' : 'none'});
696 $
('#repositoryGit').val($
('#repoName').attr('name'));
697 $
('#branchGit').val('wikidoc');
698 $
('#signIn').text("Sign In");
699 $
('#loginGit').show();
700 $
('#passwordGit').show();
701 $
('#lbpasswordGit').show();
702 $
('#lbloginGit').show();
703 $
('#repositoryGit').show();
704 $
('#lbrepositoryGit').show();
705 $
('#lbbranchGit').show();
706 $
('#branchGit').show();
710 function setCookie(c_name
, value
, exdays
)
712 var exdate
=new Date();
713 exdate
.setDate(exdate
.getDate() + exdays
);
714 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
715 document
.cookie
=c_name
+ "=" + c_value
;
718 function del_cookie(c_name
)
720 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
723 function getCookie(c_name
)
725 var c_value
= document
.cookie
;
726 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
727 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
728 if (c_start
== -1) { c_value
= null; }
731 c_start
= c_value
.indexOf("=", c_start
) + 1;
732 var c_end
= c_value
.indexOf(";", c_start
);
733 if (c_end
== -1) { c_end
= c_value
.length
; }
734 c_value
= unescape(c_value
.substring(c_start
,c_end
));
739 function getUserPass(c_name
){
740 var cookie
= base64
.decode(getCookie(c_name
));
741 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
744 function checkCookie()
746 var cookie
=getCookie("logginNitdoc");
747 if (cookie
!=null && cookie
!="")
749 cookie
= base64
.decode(cookie
);
750 userName
= cookie
.split(':')[0];
751 repoName
= cookie
.split(':')[2];
752 branchName
= cookie
.split(':')[3];
755 else { return false; }
763 base64
.PADCHAR
= '=';
764 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
765 base64
.getbyte64
= function(s
,i
) {
766 // This is oddly fast, except on Chrome/V8.
767 // Minimal or no improvement in performance by using a
768 // object with properties mapping chars to value (eg. 'A': 0)
769 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
771 throw "Cannot decode base64";
776 base64
.decode
= function(s
) {
779 var getbyte64
= base64
.getbyte64
;
787 throw "Cannot decode base64";
791 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
793 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
796 // either way, we want to ignore this last block
801 for (i
= 0; i
< imax
; i
+= 4) {
802 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
803 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
804 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
809 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
810 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
813 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
814 x
.push(String
.fromCharCode(b10
>> 16));
820 base64
.getbyte
= function(s
,i
) {
821 var x
= s
.charCodeAt(i
);
823 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
829 base64
.encode
= function(s
) {
830 if (arguments
.length
!= 1) {
831 throw "SyntaxError: Not enough arguments";
833 var padchar
= base64
.PADCHAR
;
834 var alpha
= base64
.ALPHA
;
835 var getbyte
= base64
.getbyte
;
843 var imax
= s
.length
- s
.length
% 3;
848 for (i
= 0; i
< imax
; i
+= 3) {
849 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
850 x
.push(alpha
.charAt(b10
>> 18));
851 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
852 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
853 x
.push(alpha
.charAt(b10
& 0x3f));
855 switch (s
.length
- imax
) {
857 b10
= getbyte(s
,i
) << 16;
858 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
862 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
863 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
864 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
872 function getLastCommit()
875 if(sessionStarted
){ urlHead
= "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
;}
877 // TODO: get url of the original repo.
882 beforeSend
: function (xhr
) {
883 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
889 success
: function(success
)
891 shaLastCommit
= success
.object
.sha
;
896 function getBaseTree()
899 beforeSend
: function (xhr
) {
900 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
903 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits/" + shaLastCommit
,
906 success
: function(success
)
908 shaBaseTree
= success
.tree
.sha
;
909 if (state
){ setBlob(); }
918 function setNewTree()
921 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
923 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/trees",
925 data
:'{ "base_tree" : "'+shaBaseTree
+'", '+
927 '"path":"'+ pathFile
+'",'+
930 '"sha": "'+ shaBlob
+'"'+
933 success
: function(success
)
934 { // si l'appel a bien fonctionné
935 shaNewTree
= JSON
.parse(success
).sha
;
944 function setNewCommit()
947 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
949 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits",
951 data
:'{ "message" : "'+ commitMessage
+'", '+
952 '"parents" :"'+shaLastCommit
+'",'+
953 '"tree": "'+shaNewTree
+'"'+
955 success
: function(success
)
957 shaNewCommit
= JSON
.parse(success
).sha
;
970 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
972 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
973 data
:'{ "sha" : "'+shaNewCommit
+'", '+
976 success
: function(success
) { displayMessage('Commit created successfully', 40, 40); },
977 error
:function(error
){ displayMessage('Error ' + JSON
.parse(error
).object
.message
, 40, 40); }
985 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
987 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/blobs",
989 data
:'{ "content" : "'+text
.replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"')+'", '+
990 '"encoding" :"utf-8"'+
992 success
: function(success
)
994 shaBlob
= JSON
.parse(success
).sha
;
997 error
:function(error
){
998 displayMessage('Error : Problem parsing JSON', 40, 40);
1004 // Display file content
1005 function getFileContent(urlFile
, newComment
)
1008 beforeSend
: function (xhr
) {
1009 xhr
.setRequestHeader ("Accept", "application/vnd.github-blob.raw");
1010 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1015 success
: function(success
)
1018 replaceComment(newComment
, success
);
1023 function replaceComment(newComment
, fileContent
){
1024 var arrayNew
= newComment
.split('\n');
1025 var lNew
= arrayNew
.length
;
1027 var lines
= fileContent
.split("\n");
1028 for (var i
= 0; i
< lines
.length
; i
++) {
1029 if(i
== commentLineStart
){
1030 // We change the comment
1031 for(var j
= 0; j
< lNew
; j
++){
1032 if(commentType
== 1){ text
+= "\t# " + arrayNew
[j] + "\n"; }
1034 if(arrayNew
[j] == ""){ text
+= "#"+"\n"; }
1035 else{ text
+= "# " + arrayNew
[j] + "\n"; }
1039 else if(i
< commentLineStart || i
>= commentLineEnd
){
1040 if(i
== lines
.length
-1){ text
+= lines
[i]; }
1041 else{ text
+= lines
[i] + "\n"; }
1046 function getCommentLastCommit(path
){
1049 if(shaLastCommit
!= ""){
1050 if (checkCookie()) { urlRaw
="https://rawgithub.com/"+ userName
+"/"+ repoName
+"/" + shaLastCommit
+ "/" + path
; }
1051 else{ urlRaw
="https://rawgithub.com/StefanLage/"+ $
('#repoName').attr('name') +"/" + shaLastCommit
+ "/" + path
; }
1057 success
: function(success
)
1059 currentfileContent
= success
;
1065 function displayMessage(msg
, widthDiv
, margModal
){
1068 $
('#btnCreateBranch').css('margin-left',widthDiv
+ '%');
1069 $
('#txtQuestion').text(msg
);
1070 $
('#btnCreateBranch').text("Ok");
1071 $
('#btnCancelBranch').hide();
1072 $
('#modalQuestion').css({'left' : margModal
+ '%'})
1073 $
('#modalQuestion').show();
1074 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1075 $
('body').append('<div id="fade"></div>');
1076 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1079 function displaySpinner(){
1080 spinner
.spin(targetSpinner
);
1081 $
("#waitCommit").show();
1084 // Check if the repo already exist
1085 function isRepoExisting(){
1087 beforeSend
: function (xhr
) {
1088 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1091 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1094 success
: function(){ repoExist
= true; },
1097 displayMessage('Repo not found !', 35, 45);
1103 // Check if the branch already exist
1104 function isBranchExisting(){
1106 beforeSend
: function (xhr
) {
1107 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1110 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1113 success
: function(){ branchExist
= true; },
1116 branchExist
= false;
1119 $
('#txtQuestion').text("Are you sure you want to create that branch ?");
1120 $
('#btnCancelBranch').show();
1121 $
('#btnCreateBranch').text("Yes");
1122 $
('#modalQuestion').show();
1123 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1124 $
('body').append('<div id="fade"></div>');
1125 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1130 function getMasterSha()
1133 beforeSend
: function (xhr
) {
1134 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1137 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/master",
1140 success
: function(success
) { shaMaster
= success
.object
.sha
; }
1144 function createBranch(){
1149 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1151 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs",
1152 data
:'{ "ref" : "refs/heads/'+branchName
+'",'+
1153 '"sha" : "'+shaMaster
+'"'+
1155 success
: function(){ return; },
1158 displayMessage('Impossible to create the new branch : ' + branchName
, 40, 40);
1163 $
.fn
.spin
= function(opts
) {
1164 this.each(function() {
1165 var $
this = $
(this),
1166 data
= $
this.data();
1169 data
.spinner
.stop();
1170 delete data
.spinner
;
1172 if (opts
!== false) {
1173 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);
1179 function reloadComment(){
1180 $
.when(getCommentLastCommit($
('pre[class=text_label]').attr('tag'))).done(function(){
1181 $
('pre[class=text_label]').each(function(){ getCommentOfFunction($
(this)); });
1185 function getCommentOfFunction(element
){
1187 var numL
= element
.attr("title");
1189 commentLineStart
= numL
.split('-')[0] - 1;
1190 commentLineEnd
= (commentLineStart
+ element
.text().split('\n').length
) - 1;
1191 var lines
= currentfileContent
.split("\n");
1192 for (var i
= 0; i
< lines
.length
; i
++) {
1193 if(i
>= commentLineStart
-1 && i
<= commentLineEnd
){
1194 if (lines
[i].substr(1,1) == "#"){ textC
+= lines
[i].substr(3,lines
[i].length
) + "\n";}
1195 else if(lines
[i].substr(0,1) == '#'){ textC
+= lines
[i].substr(2,lines
[i].length
) + "\n"; }
1198 if (textC
!= ""){ element
.text(textC
); }