3 var sessionStarted
= false;
5 var currentfileContent
= '';
8 var shaLastCommit
= "";
14 var repoExist
= false;
15 var branchExist
= false;
19 lines
: 11, // The number of lines to draw
20 length
: 7, // The length of each line
21 width
: 4, // The line thickness
22 radius
: 10, // The radius of the inner circle
23 corners
: 1, // Corner roundness (0..1)
24 rotate
: 0, // The rotation offset
25 color
: '#FFF', // #rgb or #rrggbb
26 speed
: 1, // Rounds per second
27 trail
: 60, // Afterglow percentage
28 shadow
: false, // Whether to render a shadow
29 hwaccel
: false, // Whether to use hardware acceleration
30 className
: 'spinner', // The CSS class to assign to the spinner
31 zIndex
: 99999, // The z-index (defaults to 2000000000)
32 top
: '300', // Top position relative to parent in px
33 left
: 'auto' // Left position relative to parent in px
35 var targetSpinner
= document
.getElementById('waitCommit');
36 var spinner
= new Spinner(opts
).spin(targetSpinner
);
39 * JQuery Case Insensitive :icontains selector
41 $
.expr
[':'].icontains
= function(obj
, index
, meta
, stack
){
42 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;
46 * Quick Search global vars
49 // Current search results preview table
50 var currentTable
= null;
52 //Hightlighted index in search result preview table
53 var currentIndex
= -1;
57 * Add folding and filtering facilities to class description page.
59 $
(document
).ready(function() {
63 $
('a[id=commitBtn]').hide();
64 $
('a[id=cancelBtn]').hide();
65 // Hide Authenfication form
71 * Highlight the spoted element
73 highlightBlock(currentAnchor());
82 $
(document
.createElement("a"))
86 .css("cursor", "pointer")
88 if($
(this).find("a.fold").html() == "+") {
89 $
(this).find("a.fold").html("-");
91 $
(this).find("a.fold").html("+");
93 $
(this).nextAll().toggle();
96 // Insert search field
99 $
(document
.createElement("li"))
101 $
(document
.createElement("form"))
103 $
(document
.createElement("input"))
108 value
: "quick search..."
116 // Select previous result on "Up"
118 // If already on first result, focus search input
119 if(currentIndex
== 0) {
120 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
121 $
("#search").focus();
122 // Else select previous result
123 } else if(currentIndex
> 0) {
124 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
126 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
127 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
128 $
("#search").focus();
132 // Select next result on "Down"
134 if(currentIndex
< currentTable
.find("tr").length
- 1) {
135 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
137 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
138 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
139 $
("#search").focus();
142 // Go to url on "Enter"
144 if(currentIndex
> -1) {
145 window
.location
= $
(currentTable
.find("tr")[currentIndex]).data("searchDetails").url
;
148 if($
("#search").val().length
== 0)
151 window
.location
= "full-index.html#q=" + $
("#search").val();
152 if(window
.location
.href
.indexOf("full-index.html") > -1) {
158 // Hide results preview on "Escape"
161 if(currentTable
!= null) {
162 currentTable
.remove();
168 if($
("#search").val().length
== 0) {
172 // Remove previous table
173 if(currentTable
!= null) {
174 currentTable
.remove();
177 // Build results table
179 currentTable
= $
(document
.createElement("table"));
181 // Escape regexp related characters in query
182 var query
= $
("#search").val();
183 query
= query
.replace(/\
[/gi
, "\\[");
184 query
= query
.replace(/\|
/gi
, "\\|");
185 query
= query
.replace(/\*/gi
, "\\*");
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
, "\\)");
193 var regexp
= new RegExp("^" + query
, "i");
194 for(var entry
in entries
) {
198 var result
= entry
.match(regexp
);
199 if(result
!= null && result
.toString().toUpperCase() == $
("#search").val().toUpperCase()) {
200 for(var i
= 0; i
< entries
[entry].length
; i
++) {
205 $
(document
.createElement("tr"))
206 .data("searchDetails", {name
: entry
, url
: entries
[entry][i]["url"]})
207 .data("index", index
)
208 .append($
(document
.createElement("td")).html(entry
))
210 $
(document
.createElement("td"))
211 .addClass("entryInfo")
212 .html(entries
[entry][i]["txt"] + " »"))
213 .mouseover( function() {
214 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
215 $
(this).addClass("activeSearchResult");
216 currentIndex
= $
(this).data("index");
218 .mouseout( function() {
219 $
(this).removeClass("activeSearchResult");
222 window
.location
= $
(this).data("searchDetails")["url"];
230 // Initialize table properties
231 currentTable
.attr("id", "searchTable");
232 currentTable
.css("position", "absolute");
233 currentTable
.width($
("#search").outerWidth());
234 $
("header").append(currentTable
);
235 currentTable
.offset({left
: $
("#search").offset().left
+ ($
("#search").outerWidth() - currentTable
.outerWidth()), top
: $
("#search").offset().top
+ $
("#search").outerHeight()});
237 // Preselect first entry
238 if(currentTable
.find("tr").length
> 0) {
240 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
241 $
("#search").focus();
246 .focusout(function() {
247 if($
(this).val() == "") {
248 $
(this).addClass("notUsed");
249 $
(this).val("quick search...");
252 .focusin(function() {
253 if($
(this).val() == "quick search...") {
254 $
(this).removeClass("notUsed");
259 .submit( function() {
265 // Close quicksearch list on click
266 $
(document
).click(function(e
) {
267 if(e
.target
!= $
("#search")[0] && e
.target
!= $
("#searchTable")[0]) {
268 if(currentTable
!= null) {
269 currentTable
.remove();
275 // Insert filter field
276 $
("article.filterable h2, nav.filterable h3")
278 $
(document
.createElement("div"))
281 $
(document
.createElement("input"))
288 $
(this).parent().parent().find("ul li:not(:icontains('" + $
(this).val() + "'))").addClass("hide");
289 $
(this).parent().parent().find("ul li:icontains('" + $
(this).val() + "')").removeClass("hide");
291 .focusout(function() {
292 if($
(this).val() == "") {
293 $
(this).addClass("notUsed");
294 $
(this).val("filter...");
297 .focusin(function() {
298 if($
(this).val() == "filter...") {
299 $
(this).removeClass("notUsed");
306 // Filter toggle between H I R in nav porperties list
307 $
("nav.properties.filterable .filter")
309 $
(document
.createElement("a"))
312 title
: "hide inherited properties"
315 if($
(this).hasClass("hidden")) {
316 $
(this).parent().parent().find("li.inherit").show();
318 $
(this).parent().parent().find("li.inherit").hide();
321 $
(this).toggleClass("hidden");
325 $
(document
.createElement("a"))
328 title
: "hide redefined properties"
331 if($
(this).hasClass("hidden")) {
332 $
(this).parent().parent().find("li.redef").show();
334 $
(this).parent().parent().find("li.redef").hide();
337 $
(this).toggleClass("hidden");
341 $
(document
.createElement("a"))
344 title
: "hide introduced properties"
347 if($
(this).hasClass("hidden")) {
348 $
(this).parent().parent().find("li.intro").show();
350 $
(this).parent().parent().find("li.intro").hide();
353 $
(this).toggleClass("hidden");
357 // Filter toggle between I R in
358 $
("article.properties.filterable .filter, article.classes.filterable .filter")
360 $
(document
.createElement("a"))
363 title
: "hide introduced properties"
366 if($
(this).hasClass("hidden")) {
367 $
(this).parent().parent().find("li.intro").show();
369 $
(this).parent().parent().find("li.intro").hide();
372 $
(this).toggleClass("hidden");
376 $
(document
.createElement("a"))
379 title
: "hide redefined properties"
382 if($
(this).hasClass("hidden")) {
383 $
(this).parent().parent().find("li.redef").show();
385 $
(this).parent().parent().find("li.redef").hide();
388 $
(this).toggleClass("hidden");
395 $
("a[href*='#']").click( function() {
396 highlightBlock($
(this).attr("href").split(/#
/)[1]);
399 //Preload filter fields with query string
401 // Hide Authenfication form
402 $
(".popover").hide();
403 // Display Login modal
404 $
("#logGitHub").click(function(){ displayLogginModal(); });
407 // If cookie existing the session is opened
408 if(sessionStarted
){ userB64
= "Basic " + getUserPass("logginNitdoc"); }
410 // Sign In an github user or Log out him
411 $
("#signIn").click(function(){
413 if($
('#loginGit').val() == "" || $
('#passwordGit').val() == ""){ displayMessage('The comment field is empty!', 40, 45); }
416 userName
= $
('#loginGit').val();
417 password
= $
('#passwordGit').val();
418 repoName
= $
('#repositoryGit').val();
419 branchName
= $
('#branchGit').val();
420 userB64
= "Basic " + base64
.encode(userName
+':'+password
);
421 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+repoName
+':'+branchName
), 1);
422 $
('#loginGit').val("");
423 $
('#passwordGit').val("");
428 // Delete cookie and reset settings
429 del_cookie("logginNitdoc");
431 displayLogginModal();
434 // Activate edit mode
435 $
('pre[class=text_label]').click(function(){
436 // the customer is loggued ?
437 if(!sessionStarted || userName
== ""){
438 // No => nothing happen
442 var arrayNew
= $
(this).text().split('\n');
443 var lNew
= arrayNew
.length
- 1;
446 for (var i
= 0; i
< lNew
; i
++) {
447 adapt
+= arrayNew
[i];
448 if(i
< lNew
-1){ adapt
+= "\n"; }
454 $
(this).next().show();
455 // Show cancel button
456 $
(this).next().next().show();
457 // Show commit button
458 $
(this).next().next().next().show();
459 // Add text in edit box
460 if($
(this).next().val() == ""){ $
(this).next().val(adapt
); }
462 $
(this).next().height($
(this).next().prop("scrollHeight"));
464 $
(this).next().select();
465 preElement
= $
(this);
469 // Disable the edit mode
470 $
('a[id=cancelBtn]').click(function(){
471 if(editComment
> 0){ editComment
-= 1; }
475 $
(this).next().hide();
477 $
(this).prev().hide();
479 $
(this).prev().prev().show();
482 // Display commit form
483 $
('a[id=commitBtn]').click(function(){
484 updateComment
= $
(this).prev().prev().val();
485 commentType
= $
(this).prev().prev().prev().attr('type');
487 if(updateComment
== ""){ displayMessage('The comment field is empty!', 40, 45); }
490 displayMessage("You need to be loggued before commit something", 45, 40);
491 displayLogginModal();
494 $
('#commitMessage').val('New commit');
495 pathFile
= $
(this).prev().prev().prev().attr('tag');
496 $
('#modal').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btn_close" title="Close" alt="Close" /></a>');
497 $
('body').append('<div id="fade"></div>');
498 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
503 $
('.btn_close').click(function(){
505 $
(this).next().hide();
506 if(editComment
> 0){ editComment
-= 1; }
509 //Close Popups and Fade Layer
510 $
('body').on('click', 'a.close, #fade', function() {
511 if(editComment
> 0){ editComment
-= 1; }
512 $
('#fade , #modal').fadeOut(function() {
513 $
('#fade, a.close').remove();
515 $
('#modalQuestion').hide();
518 $
('#loginAction').click(function(){
522 // Look if the customer is logged
524 displayMessage("You need to be loggued before commit something", 100, 40);
525 $
('.popover').show();
528 else{ userB64
= "Basic " + getUserPass("logginNitdoc"); }
529 githubRepo
= repoName
;
530 // Check if repo exist
536 commitMessage
= $
('#commitMessage').val();
537 if(commitMessage
== ""){ commitMessage
= "New commit";}
539 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
542 startCommitProcess();
545 $
('#modal, #modalQuestion').fadeOut(function() {
547 $
('#password').val("");
548 $
('textarea').hide();
549 $
('textarea').prev().show();
551 $
('a[id=cancelBtn]').hide();
552 $
('a[id=commitBtn]').hide();
555 else{ editComment
-= 1; }
558 // Cancel creating branch
559 $
('#btnCancelBranch').click(function(){
561 $
('#modalQuestion').hide();
562 $
('#fade , #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
566 // Create new branch and continu
567 $
('#btnCreateBranch').click(function(){
568 $
('#modalQuestion').hide();
569 if($
('#btnCreateBranch').text() != 'Ok'){
572 commitMessage
= $
('#commitMessage').val();
573 if(commitMessage
== ""){ commitMessage
= "New commit"; }
575 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
576 else{ startCommitProcess(); }
581 $
('#fade , #modalQuestion, #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
587 /* Parse current URL and return anchor name */
588 function currentAnchor() {
589 var index
= document
.location
.hash
.indexOf("#");
591 return document
.location
.hash
.substring(index
+ 1);
596 /* Prealod filters field using search query */
597 function preloadFilters() {
598 // Parse URL and get query string
599 var search
= currentAnchor();
601 if(search
== null || search
.indexOf("q=") == -1)
604 search
= search
.substring(2, search
.length
);
606 if(search
== "" || search
== "undefined")
609 $
(":text").val(search
);
611 .removeClass("notUsed")
616 /* Hightlight the spoted block */
617 function highlightBlock(a
) {
622 $
(".highlighted").removeClass("highlighted");
624 var target
= $
("#" + a
);
626 if(target
.is("article")) {
627 target
.parent().addClass("highlighted");
630 target
.addClass("highlighted");
634 // Init process to commit the new comment
635 function startCommitProcess()
637 var numL
= preElement
.attr("title");
638 commentLineStart
= numL
.split('-')[0] - 1;
639 commentLineEnd
= (commentLineStart
+ preElement
.text().split('\n').length
) - 1;
641 replaceComment(updateComment
, currentfileContent
);
647 function displayLogginModal(){
648 if ($
('.popover').is(':hidden')) { $
('.popover').show(); }
649 else { $
('.popover').hide(); }
653 function updateDisplaying(){
656 $
('#loginGit').hide();
657 $
('#passwordGit').hide();
658 $
('#lbpasswordGit').hide();
659 $
('#lbloginGit').hide();
660 $
('#repositoryGit').hide();
661 $
('#lbrepositoryGit').hide();
662 $
('#lbbranchGit').hide();
663 $
('#branchGit').hide();
664 $
("#liGitHub").attr("class", "current");
665 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
666 $
('#nickName').text(userName
);
667 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
668 $
('#logginMessage').css({'display' : 'block'});
669 $
('#logginMessage').css({'text-align' : 'center'});
670 $
('.popover').css({'height' : '80px'});
671 $
('#signIn').text("Sign out");
672 sessionStarted
= true;
676 sessionStarted
= false;
677 $
('#logginMessage').css({'display' : 'none'});
678 $
("#liGitHub").attr("class", "");
679 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
680 $
('#loginGit').val("");
681 $
('#passwordGit').val("");
682 $
('#nickName').text("");
683 $
('.popover').css({'height' : '280px'});
684 $
('#logginMessage').css({'display' : 'none'});
685 $
('#repositoryGit').val($
('#repoName').attr('name'));
686 $
('#branchGit').val('wikidoc');
687 $
('#signIn').text("Sign In");
688 $
('#loginGit').show();
689 $
('#passwordGit').show();
690 $
('#lbpasswordGit').show();
691 $
('#lbloginGit').show();
692 $
('#repositoryGit').show();
693 $
('#lbrepositoryGit').show();
694 $
('#lbbranchGit').show();
695 $
('#branchGit').show();
699 function setCookie(c_name
, value
, exdays
)
701 var exdate
=new Date();
702 exdate
.setDate(exdate
.getDate() + exdays
);
703 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
704 document
.cookie
=c_name
+ "=" + c_value
;
707 function del_cookie(c_name
)
709 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
712 function getCookie(c_name
)
714 var c_value
= document
.cookie
;
715 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
716 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
717 if (c_start
== -1) { c_value
= null; }
720 c_start
= c_value
.indexOf("=", c_start
) + 1;
721 var c_end
= c_value
.indexOf(";", c_start
);
722 if (c_end
== -1) { c_end
= c_value
.length
; }
723 c_value
= unescape(c_value
.substring(c_start
,c_end
));
728 function getUserPass(c_name
){
729 var cookie
= base64
.decode(getCookie(c_name
));
730 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
733 function checkCookie()
735 var cookie
=getCookie("logginNitdoc");
736 if (cookie
!=null && cookie
!="")
738 cookie
= base64
.decode(cookie
);
739 userName
= cookie
.split(':')[0];
740 repoName
= cookie
.split(':')[2];
741 branchName
= cookie
.split(':')[3];
744 else { return false; }
752 base64
.PADCHAR
= '=';
753 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
754 base64
.getbyte64
= function(s
,i
) {
755 // This is oddly fast, except on Chrome/V8.
756 // Minimal or no improvement in performance by using a
757 // object with properties mapping chars to value (eg. 'A': 0)
758 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
760 throw "Cannot decode base64";
765 base64
.decode
= function(s
) {
768 var getbyte64
= base64
.getbyte64
;
776 throw "Cannot decode base64";
780 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
782 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
785 // either way, we want to ignore this last block
790 for (i
= 0; i
< imax
; i
+= 4) {
791 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
792 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
793 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
798 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
799 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
802 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
803 x
.push(String
.fromCharCode(b10
>> 16));
809 base64
.getbyte
= function(s
,i
) {
810 var x
= s
.charCodeAt(i
);
812 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
818 base64
.encode
= function(s
) {
819 if (arguments
.length
!= 1) {
820 throw "SyntaxError: Not enough arguments";
822 var padchar
= base64
.PADCHAR
;
823 var alpha
= base64
.ALPHA
;
824 var getbyte
= base64
.getbyte
;
832 var imax
= s
.length
- s
.length
% 3;
837 for (i
= 0; i
< imax
; i
+= 3) {
838 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
839 x
.push(alpha
.charAt(b10
>> 18));
840 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
841 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
842 x
.push(alpha
.charAt(b10
& 0x3f));
844 switch (s
.length
- imax
) {
846 b10
= getbyte(s
,i
) << 16;
847 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
851 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
852 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
853 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
861 function getLastCommit()
864 if(sessionStarted
){ urlHead
= "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
;}
866 // TODO: get url of the original repo.
871 beforeSend
: function (xhr
) {
872 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
878 success
: function(success
)
880 shaLastCommit
= success
.object
.sha
;
885 function getBaseTree()
888 beforeSend
: function (xhr
) {
889 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
892 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits/" + shaLastCommit
,
895 success
: function(success
)
897 shaBaseTree
= success
.tree
.sha
;
898 if (state
){ setBlob(); }
907 function setNewTree()
910 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
912 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/trees",
914 data
:'{ "base_tree" : "'+shaBaseTree
+'", '+
916 '"path":"'+ pathFile
+'",'+
919 '"sha": "'+ shaBlob
+'"'+
922 success
: function(success
)
923 { // si l'appel a bien fonctionné
924 shaNewTree
= JSON
.parse(success
).sha
;
933 function setNewCommit()
936 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
938 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits",
940 data
:'{ "message" : "'+ commitMessage
+'", '+
941 '"parents" :"'+shaLastCommit
+'",'+
942 '"tree": "'+shaNewTree
+'"'+
944 success
: function(success
)
946 shaNewCommit
= JSON
.parse(success
).sha
;
959 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
961 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
962 data
:'{ "sha" : "'+shaNewCommit
+'", '+
965 success
: function(success
) { displayMessage('Commit created successfully', 40, 40); },
966 error
:function(error
){ displayMessage('Error ' + JSON
.parse(error
).object
.message
, 40, 40); }
974 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
976 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/blobs",
978 data
:'{ "content" : "'+text
.replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"')+'", '+
979 '"encoding" :"utf-8"'+
981 success
: function(success
)
983 shaBlob
= JSON
.parse(success
).sha
;
986 error
:function(error
){
987 displayMessage('Error : Problem parsing JSON', 40, 40);
993 // Display file content
994 function getFileContent(urlFile
, newComment
)
997 beforeSend
: function (xhr
) {
998 xhr
.setRequestHeader ("Accept", "application/vnd.github-blob.raw");
999 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1004 success
: function(success
)
1007 replaceComment(newComment
, success
);
1012 function replaceComment(newComment
, fileContent
){
1013 var arrayNew
= newComment
.split('\n');
1014 var lNew
= arrayNew
.length
;
1016 var lines
= fileContent
.split("\n");
1017 for (var i
= 0; i
< lines
.length
; i
++) {
1018 if(i
== commentLineStart
){
1019 // We change the comment
1020 for(var j
= 0; j
< lNew
; j
++){
1021 if(commentType
== 1){ text
+= "\t# " + arrayNew
[j] + "\n"; }
1023 if(arrayNew
[j] == ""){ text
+= "#"+"\n"; }
1024 else{ text
+= "# " + arrayNew
[j] + "\n"; }
1028 else if(i
< commentLineStart || i
>= commentLineEnd
){
1029 if(i
== lines
.length
-1){ text
+= lines
[i]; }
1030 else{ text
+= lines
[i] + "\n"; }
1035 function getCommentLastCommit(path
){
1038 if(shaLastCommit
!= ""){
1039 if (checkCookie()) { urlRaw
="https://rawgithub.com/"+ userName
+"/"+ repoName
+"/" + shaLastCommit
+ "/" + path
; }
1040 else{ urlRaw
="https://rawgithub.com/StefanLage/"+ $
('#repoName').attr('name') +"/" + shaLastCommit
+ "/" + path
; }
1046 success
: function(success
)
1048 currentfileContent
= success
;
1054 function displayMessage(msg
, widthDiv
, margModal
){
1057 $
('#btnCreateBranch').css('margin-left',widthDiv
+ '%');
1058 $
('#txtQuestion').text(msg
);
1059 $
('#btnCreateBranch').text("Ok");
1060 $
('#btnCancelBranch').hide();
1061 $
('#modalQuestion').css({'left' : margModal
+ '%'})
1062 $
('#modalQuestion').show();
1063 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1064 $
('body').append('<div id="fade"></div>');
1065 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1068 function displaySpinner(){
1069 spinner
.spin(targetSpinner
);
1070 $
("#waitCommit").show();
1073 // Check if the repo already exist
1074 function isRepoExisting(){
1076 beforeSend
: function (xhr
) {
1077 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1080 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1083 success
: function(){ repoExist
= true; },
1086 displayMessage('Repo not found !', 35, 45);
1092 // Check if the branch already exist
1093 function isBranchExisting(){
1095 beforeSend
: function (xhr
) {
1096 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1099 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1102 success
: function(){ branchExist
= true; },
1105 branchExist
= false;
1108 $
('#txtQuestion').text("Are you sure you want to create that branch ?");
1109 $
('#btnCancelBranch').show();
1110 $
('#btnCreateBranch').text("Yes");
1111 $
('#modalQuestion').show();
1112 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1113 $
('body').append('<div id="fade"></div>');
1114 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1119 function getMasterSha()
1122 beforeSend
: function (xhr
) {
1123 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1126 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/master",
1129 success
: function(success
) { shaMaster
= success
.object
.sha
; }
1133 function createBranch(){
1138 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1140 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs",
1141 data
:'{ "ref" : "refs/heads/'+branchName
+'",'+
1142 '"sha" : "'+shaMaster
+'"'+
1144 success
: function(){ return; },
1147 displayMessage('Impossible to create the new branch : ' + branchName
, 40, 40);
1152 $
.fn
.spin
= function(opts
) {
1153 this.each(function() {
1154 var $
this = $
(this),
1155 data
= $
this.data();
1158 data
.spinner
.stop();
1159 delete data
.spinner
;
1161 if (opts
!== false) {
1162 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);