3 var sessionStarted
= false;
5 var currentfileContent
= '';
6 var addNewComment
= false;
11 var shaLastCommit
= "";
17 var repoExist
= false;
18 var branchExist
= false;
23 lines
: 11, // The number of lines to draw
24 length
: 7, // The length of each line
25 width
: 4, // The line thickness
26 radius
: 10, // The radius of the inner circle
27 corners
: 1, // Corner roundness (0..1)
28 rotate
: 0, // The rotation offset
29 color
: '#FFF', // #rgb or #rrggbb
30 speed
: 1, // Rounds per second
31 trail
: 60, // Afterglow percentage
32 shadow
: false, // Whether to render a shadow
33 hwaccel
: false, // Whether to use hardware acceleration
34 className
: 'spinner', // The CSS class to assign to the spinner
35 zIndex
: 99999, // The z-index (defaults to 2000000000)
36 top
: '300', // Top position relative to parent in px
37 left
: 'auto' // Left position relative to parent in px
39 var targetSpinner
= document
.getElementById('waitCommit');
40 var spinner
= new Spinner(opts
).spin(targetSpinner
);
43 * JQuery Case Insensitive :icontains selector
45 $
.expr
[':'].icontains
= function(obj
, index
, meta
, stack
){
46 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;
50 * Quick Search global vars
53 // Current search results preview table
54 var currentTable
= null;
56 //Hightlighted index in search result preview table
57 var currentIndex
= -1;
59 // Check if a comment is editing
60 window
.onbeforeunload
= function() {
62 return 'Are you sure you want to leave this page?';
67 * Add folding and filtering facilities to class description page.
69 $
(document
).ready(function() {
73 $
('a[id=commitBtn]').hide();
74 $
('a[id=cancelBtn]').hide();
75 // Hide Authenfication form
77 githubRepo
= $
('#repoName').attr('name');
81 * Highlight the spoted element
83 highlightBlock(currentAnchor());
92 $
(document
.createElement("a"))
96 .css("cursor", "pointer")
98 if($
(this).find("a.fold").html() == "+") {
99 $
(this).find("a.fold").html("-");
101 $
(this).find("a.fold").html("+");
103 $
(this).nextAll().toggle();
106 // Insert search field
109 $
(document
.createElement("li"))
111 $
(document
.createElement("form"))
113 $
(document
.createElement("input"))
118 value
: "quick search..."
126 // Select previous result on "Up"
128 // If already on first result, focus search input
129 if(currentIndex
== 0) {
130 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
131 $
("#search").focus();
132 // Else select previous result
133 } else if(currentIndex
> 0) {
134 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
136 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
137 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
138 $
("#search").focus();
142 // Select next result on "Down"
144 if(currentIndex
< currentTable
.find("tr").length
- 1) {
145 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
147 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
148 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
149 $
("#search").focus();
152 // Go to url on "Enter"
154 if(currentIndex
> -1) {
155 window
.location
= $
(currentTable
.find("tr")[currentIndex]).data("searchDetails").url
;
158 if($
("#search").val().length
== 0)
161 window
.location
= "full-index.html#q=" + $
("#search").val();
162 if(window
.location
.href
.indexOf("full-index.html") > -1) {
168 // Hide results preview on "Escape"
171 if(currentTable
!= null) {
172 currentTable
.remove();
178 if($
("#search").val().length
== 0) {
182 // Remove previous table
183 if(currentTable
!= null) {
184 currentTable
.remove();
187 // Build results table
189 currentTable
= $
(document
.createElement("table"));
191 // Escape regexp related characters in query
192 var query
= $
("#search").val();
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
, "\\(");
200 query
= query
.replace(/\
)/gi
, "\\)");
203 var regexp
= new RegExp("^" + query
, "i");
204 for(var entry
in entries
) {
208 var result
= entry
.match(regexp
);
209 if(result
!= null && result
.toString().toUpperCase() == $
("#search").val().toUpperCase()) {
210 for(var i
= 0; i
< entries
[entry].length
; i
++) {
215 $
(document
.createElement("tr"))
216 .data("searchDetails", {name
: entry
, url
: entries
[entry][i]["url"]})
217 .data("index", index
)
218 .append($
(document
.createElement("td")).html(entry
))
220 $
(document
.createElement("td"))
221 .addClass("entryInfo")
222 .html(entries
[entry][i]["txt"] + " »"))
223 .mouseover( function() {
224 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
225 $
(this).addClass("activeSearchResult");
226 currentIndex
= $
(this).data("index");
228 .mouseout( function() {
229 $
(this).removeClass("activeSearchResult");
232 window
.location
= $
(this).data("searchDetails")["url"];
240 // Initialize table properties
241 currentTable
.attr("id", "searchTable");
242 currentTable
.css("position", "absolute");
243 currentTable
.width($
("#search").outerWidth());
244 $
("header").append(currentTable
);
245 currentTable
.offset({left
: $
("#search").offset().left
+ ($
("#search").outerWidth() - currentTable
.outerWidth()), top
: $
("#search").offset().top
+ $
("#search").outerHeight()});
247 // Preselect first entry
248 if(currentTable
.find("tr").length
> 0) {
250 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
251 $
("#search").focus();
256 .focusout(function() {
257 if($
(this).val() == "") {
258 $
(this).addClass("notUsed");
259 $
(this).val("quick search...");
262 .focusin(function() {
263 if($
(this).val() == "quick search...") {
264 $
(this).removeClass("notUsed");
269 .submit( function() {
275 // Close quicksearch list on click
276 $
(document
).click(function(e
) {
277 if(e
.target
!= $
("#search")[0] && e
.target
!= $
("#searchTable")[0]) {
278 if(currentTable
!= null) {
279 currentTable
.remove();
285 // Insert filter field
286 $
("article.filterable h2, nav.filterable h3")
288 $
(document
.createElement("div"))
291 $
(document
.createElement("input"))
298 $
(this).parent().parent().find("ul li:not(:icontains('" + $
(this).val() + "'))").addClass("hide");
299 $
(this).parent().parent().find("ul li:icontains('" + $
(this).val() + "')").removeClass("hide");
301 .focusout(function() {
302 if($
(this).val() == "") {
303 $
(this).addClass("notUsed");
304 $
(this).val("filter...");
307 .focusin(function() {
308 if($
(this).val() == "filter...") {
309 $
(this).removeClass("notUsed");
316 // Filter toggle between H I R in nav porperties list
317 $
("nav.properties.filterable .filter")
319 $
(document
.createElement("a"))
322 title
: "hide inherited properties"
325 if($
(this).hasClass("hidden")) {
326 $
(this).parent().parent().find("li.inherit").show();
328 $
(this).parent().parent().find("li.inherit").hide();
331 $
(this).toggleClass("hidden");
335 $
(document
.createElement("a"))
338 title
: "hide redefined properties"
341 if($
(this).hasClass("hidden")) {
342 $
(this).parent().parent().find("li.redef").show();
344 $
(this).parent().parent().find("li.redef").hide();
347 $
(this).toggleClass("hidden");
351 $
(document
.createElement("a"))
354 title
: "hide introduced properties"
357 if($
(this).hasClass("hidden")) {
358 $
(this).parent().parent().find("li.intro").show();
360 $
(this).parent().parent().find("li.intro").hide();
363 $
(this).toggleClass("hidden");
367 // Filter toggle between I R in
368 $
("article.properties.filterable .filter, article.classes.filterable .filter")
370 $
(document
.createElement("a"))
373 title
: "hide introduced properties"
376 if($
(this).hasClass("hidden")) {
377 $
(this).parent().parent().find("li.intro").show();
379 $
(this).parent().parent().find("li.intro").hide();
382 $
(this).toggleClass("hidden");
386 $
(document
.createElement("a"))
389 title
: "hide redefined properties"
392 if($
(this).hasClass("hidden")) {
393 $
(this).parent().parent().find("li.redef").show();
395 $
(this).parent().parent().find("li.redef").hide();
398 $
(this).toggleClass("hidden");
405 $
("a[href*='#']").click( function() {
406 highlightBlock($
(this).attr("href").split(/#
/)[1]);
409 //Preload filter fields with query string
411 // Hide Authenfication form
412 $
(".popover").hide();
413 // Display Login modal
414 $
("#logGitHub").click(function(){ displayLogginModal(); });
417 // If cookie existing the session is opened
418 if(sessionStarted
){ userB64
= "Basic " + getUserPass("logginNitdoc"); }
420 // Sign In an github user or Log out him
421 $
("#signIn").click(function(){
423 if($
('#loginGit').val() == "" || $
('#passwordGit').val() == ""){ displayMessage('The comment field is empty!', 40, 45); }
426 userName
= $
('#loginGit').val();
427 password
= $
('#passwordGit').val();
428 repoName
= $
('#repositoryGit').val();
429 branchName
= $
('#branchGit').val();
430 userB64
= "Basic " + base64
.encode(userName
+':'+password
);
431 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+repoName
+':'+branchName
), 1);
432 $
('#loginGit').val("");
433 $
('#passwordGit').val("");
438 // Delete cookie and reset settings
439 del_cookie("logginNitdoc");
441 displayLogginModal();
444 // Activate edit mode
445 $
('pre[class=text_label]').click(function(){
446 // the customer is loggued ?
447 if(!sessionStarted || userName
== ""){
448 // No => nothing happen
452 var arrayNew
= $
(this).text().split('\n');
453 var lNew
= arrayNew
.length
- 1;
456 for (var i
= 0; i
< lNew
; i
++) {
457 adapt
+= arrayNew
[i];
458 if(i
< lNew
-1){ adapt
+= "\n"; }
464 $
(this).next().show();
465 // Show cancel button
466 $
(this).next().next().show();
467 // Show commit button
468 $
(this).next().next().next().show();
469 // Add text in edit box
470 if($
(this).next().val() == ""){ $
(this).next().val(adapt
); }
472 $
(this).next().height($
(this).next().prop("scrollHeight"));
474 $
(this).next().select();
475 preElement
= $
(this);
479 // Disable the edit mode
480 $
('a[id=cancelBtn]').click(function(){
481 if(editComment
> 0){ editComment
-= 1; }
485 $
(this).next().hide();
487 $
(this).prev().hide();
489 $
(this).prev().prev().show();
492 // Display commit form
493 $
('a[id=commitBtn]').click(function(){
494 updateComment
= $
(this).prev().prev().val();
495 commentType
= $
(this).prev().prev().prev().attr('type');
497 if(updateComment
== ""){ displayMessage('The comment field is empty!', 40, 45); }
500 displayMessage("You need to be loggued before commit something", 45, 40);
501 displayLogginModal();
504 $
('#commitMessage').val('New commit');
505 pathFile
= $
(this).prev().prev().prev().attr('tag');
506 $
('#modal').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btn_close" title="Close" alt="Close" /></a>');
507 $
('body').append('<div id="fade"></div>');
508 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
513 $
('.btn_close').click(function(){
515 $
(this).next().hide();
516 if(editComment
> 0){ editComment
-= 1; }
519 //Close Popups and Fade Layer
520 $
('body').on('click', 'a.close, #fade', function() {
521 if(editComment
> 0){ editComment
-= 1; }
522 $
('#fade , #modal').fadeOut(function() {
523 $
('#fade, a.close').remove();
525 $
('#modalQuestion').hide();
528 $
('#loginAction').click(function(){
532 // Look if the customer is logged
534 displayMessage("You need to be loggued before commit something", 100, 40);
535 $
('.popover').show();
538 else{ userB64
= "Basic " + getUserPass("logginNitdoc"); }
539 githubRepo
= repoName
;
540 // Check if repo exist
546 commitMessage
= $
('#commitMessage').val();
547 if(commitMessage
== ""){ commitMessage
= "New commit";}
549 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
552 startCommitProcess();
555 $
('#modal, #modalQuestion').fadeOut(function() {
557 $
('#password').val("");
558 $
('textarea').hide();
559 $
('textarea').prev().show();
561 $
('a[id=cancelBtn]').hide();
562 $
('a[id=commitBtn]').hide();
563 // Re-load all comment
567 else{ editComment
-= 1; }
570 // Cancel creating branch
571 $
('#btnCancelBranch').click(function(){
573 $
('#modalQuestion').hide();
574 $
('#fade , #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
578 // Create new branch and continu
579 $
('#btnCreateBranch').click(function(){
580 $
('#modalQuestion').hide();
581 if($
('#btnCreateBranch').text() != 'Ok'){
584 commitMessage
= $
('#commitMessage').val();
585 if(commitMessage
== ""){ commitMessage
= "New commit"; }
587 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
588 else{ startCommitProcess(); }
593 $
('#fade , #modalQuestion, #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
597 $
('a[class=newComment]').click(function(){
598 addNewComment
= true;
603 $
(this).next().show();
604 // Show cancel button
605 $
(this).next().next().show();
606 // Show commit button
607 $
(this).next().next().next().show();
609 $
(this).next().height($
(this).next().prop("scrollHeight"));
611 $
(this).next().select();
612 preElement
= $
(this);
617 /* Parse current URL and return anchor name */
618 function currentAnchor() {
619 var index
= document
.location
.hash
.indexOf("#");
621 return document
.location
.hash
.substring(index
+ 1);
626 /* Prealod filters field using search query */
627 function preloadFilters() {
628 // Parse URL and get query string
629 var search
= currentAnchor();
631 if(search
== null || search
.indexOf("q=") == -1)
634 search
= search
.substring(2, search
.length
);
636 if(search
== "" || search
== "undefined")
639 $
(":text").val(search
);
641 .removeClass("notUsed")
646 /* Hightlight the spoted block */
647 function highlightBlock(a
) {
652 $
(".highlighted").removeClass("highlighted");
654 var target
= $
("#" + a
);
656 if(target
.is("article")) {
657 target
.parent().addClass("highlighted");
660 target
.addClass("highlighted");
664 // Init process to commit the new comment
665 function startCommitProcess()
667 var numL
= preElement
.attr("title");
668 commentLineStart
= numL
.split('-')[0] - 1;
669 if(addNewComment
) { commentLineStart
++; }
670 commentLineEnd
= (commentLineStart
+ preElement
.text().split('\n').length
) - 1;
672 replaceComment(updateComment
, currentfileContent
);
678 function displayLogginModal(){
679 if ($
('.popover').is(':hidden')) { $
('.popover').show(); }
680 else { $
('.popover').hide(); }
684 function updateDisplaying(){
687 userB64
= "Basic " + getUserPass("logginNitdoc");
688 $
('#loginGit').hide();
689 $
('#passwordGit').hide();
690 $
('#lbpasswordGit').hide();
691 $
('#lbloginGit').hide();
692 $
('#repositoryGit').hide();
693 $
('#lbrepositoryGit').hide();
694 $
('#lbbranchGit').hide();
695 $
('#branchGit').hide();
696 $
("#liGitHub").attr("class", "current");
697 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
698 $
('#nickName').text(userName
);
699 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
700 $
('#logginMessage').css({'display' : 'block'});
701 $
('#logginMessage').css({'text-align' : 'center'});
702 $
('.popover').css({'height' : '80px'});
703 $
('#signIn').text("Sign out");
704 sessionStarted
= true;
709 sessionStarted
= false;
710 $
('#logginMessage').css({'display' : 'none'});
711 $
("#liGitHub").attr("class", "");
712 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
713 $
('#loginGit').val("");
714 $
('#passwordGit').val("");
715 $
('#nickName').text("");
716 $
('.popover').css({'height' : '280px'});
717 $
('#logginMessage').css({'display' : 'none'});
718 $
('#repositoryGit').val($
('#repoName').attr('name'));
719 $
('#branchGit').val('wikidoc');
720 $
('#signIn').text("Sign In");
721 $
('#loginGit').show();
722 $
('#passwordGit').show();
723 $
('#lbpasswordGit').show();
724 $
('#lbloginGit').show();
725 $
('#repositoryGit').show();
726 $
('#lbrepositoryGit').show();
727 $
('#lbbranchGit').show();
728 $
('#branchGit').show();
732 function setCookie(c_name
, value
, exdays
)
734 var exdate
=new Date();
735 exdate
.setDate(exdate
.getDate() + exdays
);
736 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
737 document
.cookie
=c_name
+ "=" + c_value
;
740 function del_cookie(c_name
)
742 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
745 function getCookie(c_name
)
747 var c_value
= document
.cookie
;
748 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
749 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
750 if (c_start
== -1) { c_value
= null; }
753 c_start
= c_value
.indexOf("=", c_start
) + 1;
754 var c_end
= c_value
.indexOf(";", c_start
);
755 if (c_end
== -1) { c_end
= c_value
.length
; }
756 c_value
= unescape(c_value
.substring(c_start
,c_end
));
761 function getUserPass(c_name
){
762 var cookie
= base64
.decode(getCookie(c_name
));
763 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
766 function checkCookie()
768 var cookie
=getCookie("logginNitdoc");
769 if (cookie
!=null && cookie
!="")
771 cookie
= base64
.decode(cookie
);
772 userName
= cookie
.split(':')[0];
773 repoName
= cookie
.split(':')[2];
774 branchName
= cookie
.split(':')[3];
777 else { return false; }
785 base64
.PADCHAR
= '=';
786 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
787 base64
.getbyte64
= function(s
,i
) {
788 // This is oddly fast, except on Chrome/V8.
789 // Minimal or no improvement in performance by using a
790 // object with properties mapping chars to value (eg. 'A': 0)
791 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
793 throw "Cannot decode base64";
798 base64
.decode
= function(s
) {
801 var getbyte64
= base64
.getbyte64
;
809 throw "Cannot decode base64";
813 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
815 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
818 // either way, we want to ignore this last block
823 for (i
= 0; i
< imax
; i
+= 4) {
824 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
825 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
826 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
831 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
832 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
835 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
836 x
.push(String
.fromCharCode(b10
>> 16));
842 base64
.getbyte
= function(s
,i
) {
843 var x
= s
.charCodeAt(i
);
845 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
851 base64
.encode
= function(s
) {
852 if (arguments
.length
!= 1) {
853 throw "SyntaxError: Not enough arguments";
855 var padchar
= base64
.PADCHAR
;
856 var alpha
= base64
.ALPHA
;
857 var getbyte
= base64
.getbyte
;
865 var imax
= s
.length
- s
.length
% 3;
870 for (i
= 0; i
< imax
; i
+= 3) {
871 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
872 x
.push(alpha
.charAt(b10
>> 18));
873 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
874 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
875 x
.push(alpha
.charAt(b10
& 0x3f));
877 switch (s
.length
- imax
) {
879 b10
= getbyte(s
,i
) << 16;
880 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
884 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
885 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
886 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
894 function getLastCommit()
897 if(sessionStarted
){ urlHead
= "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
;}
899 // TODO: get url of the original repo.
904 beforeSend
: function (xhr
) {
905 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
911 success
: function(success
)
913 shaLastCommit
= success
.object
.sha
;
918 function getBaseTree()
921 beforeSend
: function (xhr
) {
922 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
925 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits/" + shaLastCommit
,
928 success
: function(success
)
930 shaBaseTree
= success
.tree
.sha
;
931 if (state
){ setBlob(); }
940 function setNewTree()
943 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
945 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/trees",
947 data
:'{ "base_tree" : "'+shaBaseTree
+'", '+
949 '"path":"'+ pathFile
+'",'+
952 '"sha": "'+ shaBlob
+'"'+
955 success
: function(success
)
956 { // si l'appel a bien fonctionné
957 shaNewTree
= JSON
.parse(success
).sha
;
966 function setNewCommit()
969 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
971 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits",
973 data
:'{ "message" : "'+ commitMessage
+'", '+
974 '"parents" :"'+shaLastCommit
+'",'+
975 '"tree": "'+shaNewTree
+'"'+
977 success
: function(success
)
979 shaNewCommit
= JSON
.parse(success
).sha
;
992 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
994 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
995 data
:'{ "sha" : "'+shaNewCommit
+'", '+
998 success
: function(success
) { displayMessage('Commit created successfully', 40, 40); },
999 error
:function(error
){ displayMessage('Error ' + JSON
.parse(error
).object
.message
, 40, 40); }
1007 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1009 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/blobs",
1011 data
:'{ "content" : "'+text
.replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"')+'", '+
1012 '"encoding" :"utf-8"'+
1014 success
: function(success
)
1016 shaBlob
= JSON
.parse(success
).sha
;
1019 error
:function(error
){
1020 displayMessage('Error : Problem parsing JSON', 40, 40);
1026 // Display file content
1027 function getFileContent(urlFile
, newComment
)
1030 beforeSend
: function (xhr
) {
1031 xhr
.setRequestHeader ("Accept", "application/vnd.github-blob.raw");
1032 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1037 success
: function(success
)
1040 replaceComment(newComment
, success
);
1045 function replaceComment(newComment
, fileContent
){
1046 var arrayNew
= newComment
.split('\n');
1047 var lNew
= arrayNew
.length
;
1049 var lines
= fileContent
.split("\n");
1050 for (var i
= 0; i
< lines
.length
; i
++) {
1051 if(i
== commentLineStart
){
1053 for(var indexLine
=0; indexLine
< lines
[i
+1].length
; indexxLine
++){
1054 if(lines
[i
+1].substr(indexLine
,1) == "\t" || lines
[i
+1].substr(indexLine
,1) == "#"){ text
+= lines
[i
+1].substr(indexLine
,1); }
1057 text
+= lines
[i] + "\n";
1059 // We change the comment
1060 for(var j
= 0; j
< lNew
; j
++){
1061 if(commentType
== 1){ text
+= "\t# " + arrayNew
[j] + "\n"; }
1063 if(arrayNew
[j] == ""){ text
+= "#"+"\n"; }
1064 else{ text
+= "# " + arrayNew
[j] + "\n"; }
1068 else if(i
< commentLineStart || i
>= commentLineEnd
){
1069 if(i
== lines
.length
-1){ text
+= lines
[i]; }
1070 else{ text
+= lines
[i] + "\n"; }
1074 addNewComment
= false;
1078 function getCommentLastCommit(path
){
1081 if(shaLastCommit
!= ""){
1082 if (checkCookie()) { urlRaw
="https://rawgithub.com/"+ userName
+"/"+ repoName
+"/" + shaLastCommit
+ "/" + path
; }
1083 else{ urlRaw
="https://rawgithub.com/StefanLage/"+ $
('#repoName').attr('name') +"/" + shaLastCommit
+ "/" + path
; }
1089 success
: function(success
)
1091 currentfileContent
= success
;
1097 function displayMessage(msg
, widthDiv
, margModal
){
1100 $
('#btnCreateBranch').css('margin-left',widthDiv
+ '%');
1101 $
('#txtQuestion').text(msg
);
1102 $
('#btnCreateBranch').text("Ok");
1103 $
('#btnCancelBranch').hide();
1104 $
('#modalQuestion').css({'left' : margModal
+ '%'})
1105 $
('#modalQuestion').show();
1106 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1107 $
('body').append('<div id="fade"></div>');
1108 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1111 function displaySpinner(){
1112 spinner
.spin(targetSpinner
);
1113 $
("#waitCommit").show();
1116 // Check if the repo already exist
1117 function isRepoExisting(){
1119 beforeSend
: function (xhr
) {
1120 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1123 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1126 success
: function(){ repoExist
= true; },
1129 displayMessage('Repo not found !', 35, 45);
1135 // Check if the branch already exist
1136 function isBranchExisting(){
1138 beforeSend
: function (xhr
) {
1139 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1142 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1145 success
: function(){ branchExist
= true; },
1148 branchExist
= false;
1151 $
('#txtQuestion').text("Are you sure you want to create that branch ?");
1152 $
('#btnCancelBranch').show();
1153 $
('#btnCreateBranch').text("Yes");
1154 $
('#modalQuestion').show();
1155 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1156 $
('body').append('<div id="fade"></div>');
1157 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1162 function getMasterSha()
1165 beforeSend
: function (xhr
) {
1166 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1169 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/master",
1172 success
: function(success
) { shaMaster
= success
.object
.sha
; }
1176 function createBranch(){
1181 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1183 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs",
1184 data
:'{ "ref" : "refs/heads/'+branchName
+'",'+
1185 '"sha" : "'+shaMaster
+'"'+
1187 success
: function(){ return; },
1190 displayMessage('Impossible to create the new branch : ' + branchName
, 40, 40);
1195 $
.fn
.spin
= function(opts
) {
1196 this.each(function() {
1197 var $
this = $
(this),
1198 data
= $
this.data();
1201 data
.spinner
.stop();
1202 delete data
.spinner
;
1204 if (opts
!== false) {
1205 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);
1211 function reloadComment(){
1212 $
.when(getCommentLastCommit($
('pre[class=text_label]').attr('tag'))).done(function(){
1213 $
('pre[class=text_label]').each(function(){ getCommentOfFunction($
(this)); });
1217 function getCommentOfFunction(element
){
1219 var numL
= element
.attr("title");
1221 commentLineStart
= numL
.split('-')[0] - 1;
1222 commentLineEnd
= (commentLineStart
+ element
.text().split('\n').length
) - 1;
1223 var lines
= currentfileContent
.split("\n");
1224 for (var i
= 0; i
< lines
.length
; i
++) {
1225 if(i
>= commentLineStart
-1 && i
<= commentLineEnd
){
1226 if (lines
[i].substr(1,1) == "#"){ textC
+= lines
[i].substr(3,lines
[i].length
) + "\n";}
1227 else if(lines
[i].substr(0,1) == '#'){ textC
+= lines
[i].substr(2,lines
[i].length
) + "\n"; }
1230 if (textC
!= ""){ element
.text(textC
); }