5 var sessionStarted
= false;
7 var currentfileContent
= '';
8 var addNewComment
= false;
13 var shaLastCommit
= "";
19 var repoExist
= false;
20 var branchExist
= false;
25 lines
: 11, // The number of lines to draw
26 length
: 7, // The length of each line
27 width
: 4, // The line thickness
28 radius
: 10, // The radius of the inner circle
29 corners
: 1, // Corner roundness (0..1)
30 rotate
: 0, // The rotation offset
31 color
: '#FFF', // #rgb or #rrggbb
32 speed
: 1, // Rounds per second
33 trail
: 60, // Afterglow percentage
34 shadow
: false, // Whether to render a shadow
35 hwaccel
: false, // Whether to use hardware acceleration
36 className
: 'spinner', // The CSS class to assign to the spinner
37 zIndex
: 99999, // The z-index (defaults to 2000000000)
38 top
: '300', // Top position relative to parent in px
39 left
: 'auto' // Left position relative to parent in px
41 var targetSpinner
= document
.getElementById('waitCommit');
42 var spinner
= new Spinner(opts
).spin(targetSpinner
);
45 * JQuery Case Insensitive :icontains selector
47 $
.expr
[':'].icontains
= function(obj
, index
, meta
, stack
){
48 return (obj
.textContent
.replace(/\
[[0-9]+\
]/g
, "") || obj
.innerText
.replace(/\
[[0-9]+\
]/g
, "") ||
jQuery(obj
).text().replace(/\
[[0-9]+\
]/g
, "") ||
'').toLowerCase().indexOf(meta
[3].toLowerCase()) >= 0;
52 * Quick Search global vars
55 // Current search results preview table
56 var currentTable
= null;
58 //Hightlighted index in search result preview table
59 var currentIndex
= -1;
61 // Check if a comment is editing
62 window
.onbeforeunload
= function() {
64 return 'Are you sure you want to leave this page?';
69 * Add folding and filtering facilities to class description page.
71 $
(document
).ready(function() {
75 $
('a[id=commitBtn]').hide();
76 $
('a[id=cancelBtn]').hide();
77 // Hide Authenfication form
79 githubRepo
= $
('#repoName').attr('name');
83 * Highlight the spoted element
85 highlightBlock(currentAnchor());
94 $
(document
.createElement("a"))
98 .css("cursor", "pointer")
100 if($
(this).find("a.fold").html() == "+") {
101 $
(this).find("a.fold").html("-");
103 $
(this).find("a.fold").html("+");
105 $
(this).nextAll().toggle();
108 // Insert search field
111 $
(document
.createElement("li"))
113 $
(document
.createElement("form"))
115 $
(document
.createElement("input"))
120 value
: "quick search..."
128 // Select previous result on "Up"
130 // If already on first result, focus search input
131 if(currentIndex
== 0) {
132 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
133 $
("#search").focus();
134 // Else select previous result
135 } else if(currentIndex
> 0) {
136 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
138 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
139 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
140 $
("#search").focus();
144 // Select next result on "Down"
146 if(currentIndex
< currentTable
.find("tr").length
- 1) {
147 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
149 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
150 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
151 $
("#search").focus();
154 // Go to url on "Enter"
156 if(currentIndex
> -1) {
157 window
.location
= $
(currentTable
.find("tr")[currentIndex]).data("searchDetails").url
;
160 if($
("#search").val().length
== 0)
163 window
.location
= "full-index.html#q=" + $
("#search").val();
164 if(window
.location
.href
.indexOf("full-index.html") > -1) {
170 // Hide results preview on "Escape"
173 if(currentTable
!= null) {
174 currentTable
.remove();
180 if($
("#search").val().length
== 0) {
184 // Remove previous table
185 if(currentTable
!= null) {
186 currentTable
.remove();
189 // Build results table
191 currentTable
= $
(document
.createElement("table"));
193 // Escape regexp related characters in query
194 var query
= $
("#search").val();
195 query
= query
.replace(/\
[/gi
, "\\[");
196 query
= query
.replace(/\|
/gi
, "\\|");
197 query
= query
.replace(/\*/gi
, "\\*");
198 query
= query
.replace(/\
+/gi
, "\\+");
199 query
= query
.replace(/\\/gi
, "\\\\");
200 query
= query
.replace(/\?/gi
, "\\?");
201 query
= query
.replace(/\
(/gi
, "\\(");
202 query
= query
.replace(/\
)/gi
, "\\)");
205 var regexp
= new RegExp("^" + query
, "i");
206 for(var entry
in entries
) {
210 var result
= entry
.match(regexp
);
211 if(result
!= null && result
.toString().toUpperCase() == $
("#search").val().toUpperCase()) {
212 for(var i
= 0; i
< entries
[entry].length
; i
++) {
217 $
(document
.createElement("tr"))
218 .data("searchDetails", {name
: entry
, url
: entries
[entry][i]["url"]})
219 .data("index", index
)
220 .append($
(document
.createElement("td")).html(entry
))
222 $
(document
.createElement("td"))
223 .addClass("entryInfo")
224 .html(entries
[entry][i]["txt"] + " »"))
225 .mouseover( function() {
226 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
227 $
(this).addClass("activeSearchResult");
228 currentIndex
= $
(this).data("index");
230 .mouseout( function() {
231 $
(this).removeClass("activeSearchResult");
234 window
.location
= $
(this).data("searchDetails")["url"];
242 // Initialize table properties
243 currentTable
.attr("id", "searchTable");
244 currentTable
.css("position", "absolute");
245 currentTable
.width($
("#search").outerWidth());
246 $
("header").append(currentTable
);
247 currentTable
.offset({left
: $
("#search").offset().left
+ ($
("#search").outerWidth() - currentTable
.outerWidth()), top
: $
("#search").offset().top
+ $
("#search").outerHeight()});
249 // Preselect first entry
250 if(currentTable
.find("tr").length
> 0) {
252 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
253 $
("#search").focus();
258 .focusout(function() {
259 if($
(this).val() == "") {
260 $
(this).addClass("notUsed");
261 $
(this).val("quick search...");
264 .focusin(function() {
265 if($
(this).val() == "quick search...") {
266 $
(this).removeClass("notUsed");
271 .submit( function() {
277 // Close quicksearch list on click
278 $
(document
).click(function(e
) {
279 if(e
.target
!= $
("#search")[0] && e
.target
!= $
("#searchTable")[0]) {
280 if(currentTable
!= null) {
281 currentTable
.remove();
287 // Insert filter field
288 $
("article.filterable h2, nav.filterable h3")
290 $
(document
.createElement("div"))
293 $
(document
.createElement("input"))
300 $
(this).parent().parent().find("ul li:not(:icontains('" + $
(this).val() + "'))").addClass("hide");
301 $
(this).parent().parent().find("ul li:icontains('" + $
(this).val() + "')").removeClass("hide");
303 .focusout(function() {
304 if($
(this).val() == "") {
305 $
(this).addClass("notUsed");
306 $
(this).val("filter...");
309 .focusin(function() {
310 if($
(this).val() == "filter...") {
311 $
(this).removeClass("notUsed");
318 // Filter toggle between H I R in nav porperties list
319 $
("nav.properties.filterable .filter")
321 $
(document
.createElement("a"))
324 title
: "hide inherited properties"
327 if($
(this).hasClass("hidden")) {
328 $
(this).parent().parent().find("li.inherit").show();
330 $
(this).parent().parent().find("li.inherit").hide();
333 $
(this).toggleClass("hidden");
337 $
(document
.createElement("a"))
340 title
: "hide redefined properties"
343 if($
(this).hasClass("hidden")) {
344 $
(this).parent().parent().find("li.redef").show();
346 $
(this).parent().parent().find("li.redef").hide();
349 $
(this).toggleClass("hidden");
353 $
(document
.createElement("a"))
356 title
: "hide introduced properties"
359 if($
(this).hasClass("hidden")) {
360 $
(this).parent().parent().find("li.intro").show();
362 $
(this).parent().parent().find("li.intro").hide();
365 $
(this).toggleClass("hidden");
369 // Filter toggle between I R in
370 $
("article.properties.filterable .filter, article.classes.filterable .filter")
372 $
(document
.createElement("a"))
375 title
: "hide introduced properties"
378 if($
(this).hasClass("hidden")) {
379 $
(this).parent().parent().find("li.intro").show();
381 $
(this).parent().parent().find("li.intro").hide();
384 $
(this).toggleClass("hidden");
388 $
(document
.createElement("a"))
391 title
: "hide redefined properties"
394 if($
(this).hasClass("hidden")) {
395 $
(this).parent().parent().find("li.redef").show();
397 $
(this).parent().parent().find("li.redef").hide();
400 $
(this).toggleClass("hidden");
407 $
("a[href*='#']").click( function() {
408 highlightBlock($
(this).attr("href").split(/#
/)[1]);
411 //Preload filter fields with query string
413 // Hide Authenfication form
414 $
(".popover").hide();
415 // Display Login modal
416 $
("#logGitHub").click(function(){ displayLogginModal(); });
419 // If cookie existing the session is opened
420 if(sessionStarted
){ userB64
= "Basic " + getUserPass("logginNitdoc"); }
422 // Sign In an github user or Log out him
423 $
("#signIn").click(function(){
425 if($
('#loginGit').val() == "" || $
('#passwordGit').val() == ""){ displayMessage('The comment field is empty!', 40, 45); }
428 userName
= $
('#loginGit').val();
429 password
= $
('#passwordGit').val();
430 repoName
= $
('#repositoryGit').val();
431 branchName
= $
('#branchGit').val();
432 userB64
= "Basic " + base64
.encode(userName
+':'+password
);
433 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+repoName
+':'+branchName
), 1);
434 $
('#loginGit').val("");
435 $
('#passwordGit').val("");
441 // Delete cookie and reset settings
442 del_cookie("logginNitdoc");
443 closeAllCommentInEdtiting();
445 displayLogginModal();
448 // Activate edit mode
449 $
('pre[class=text_label]').click(function(){
450 // the customer is loggued ?
451 if(!sessionStarted || userName
== ""){
452 // No => nothing happen
456 var arrayNew
= $
(this).text().split('\n');
457 var lNew
= arrayNew
.length
- 1;
460 for (var i
= 0; i
< lNew
; i
++) {
461 adapt
+= arrayNew
[i];
462 if(i
< lNew
-1){ adapt
+= "\n"; }
468 $
(this).next().show();
469 // Show cancel button
470 $
(this).next().next().show();
471 // Show commit button
472 $
(this).next().next().next().show();
473 // Add text in edit box
474 if($
(this).next().val() == "" || $
(this).next().val() != adapt
){ $
(this).next().val(adapt
); }
476 $
(this).next().height($
(this).next().prop("scrollHeight"));
478 $
(this).next().select();
479 preElement
= $
(this);
483 // Disable the edit mode
484 $
('a[id=cancelBtn]').click(function(){
485 closeEditing($
(this));
488 // Display commit form
489 $
('a[id=commitBtn]').click(function(){
490 updateComment
= $
(this).prev().prev().val();
491 commentType
= $
(this).prev().prev().prev().attr('type');
493 if(updateComment
== ""){ displayMessage('The comment field is empty!', 40, 45); }
496 displayMessage("You need to be loggued before commit something", 45, 40);
497 displayLogginModal();
500 $
('#commitMessage').val('New commit');
501 pathFile
= $
(this).prev().prev().prev().attr('tag');
502 $
('#modal').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btn_close" title="Close" alt="Close" /></a>');
503 $
('body').append('<div id="fade"></div>');
504 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
509 $
('.btn_close').click(function(){
511 $
(this).next().hide();
512 if(editComment
> 0){ editComment
-= 1; }
515 //Close Popups and Fade Layer
516 $
('body').on('click', 'a.close, #fade', function() {
517 if(editComment
> 0){ editComment
-= 1; }
518 $
('#fade , #modal').fadeOut(function() {
519 $
('#fade, a.close').remove();
521 $
('#modalQuestion').hide();
524 $
('#loginAction').click(function(){
528 // Look if the customer is logged
530 displayMessage("You need to be loggued before commit something", 100, 40);
531 $
('.popover').show();
534 else{ userB64
= "Basic " + getUserPass("logginNitdoc"); }
535 githubRepo
= repoName
;
536 // Check if repo exist
542 commitMessage
= $
('#commitMessage').val();
543 if(commitMessage
== ""){ commitMessage
= "New commit";}
545 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
548 startCommitProcess();
551 $
('#modal, #modalQuestion').fadeOut(function() {
553 $
('#password').val("");
554 $
('textarea').hide();
555 $
('textarea').prev().show();
557 $
('a[id=cancelBtn]').hide();
558 $
('a[id=commitBtn]').hide();
559 // Re-load all comment
563 else{ editComment
-= 1; }
566 // Cancel creating branch
567 $
('#btnCancelBranch').click(function(){
569 $
('#modalQuestion').hide();
570 $
('#fade , #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
574 // Create new branch and continu
575 $
('#btnCreateBranch').click(function(){
576 $
('#modalQuestion').hide();
577 if($
('#btnCreateBranch').text() != 'Ok'){
580 commitMessage
= $
('#commitMessage').val();
581 if(commitMessage
== ""){ commitMessage
= "New commit"; }
583 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
584 else{ startCommitProcess(); }
589 $
('#fade , #modalQuestion, #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
593 $
('a[class=newComment]').click(function(){
594 addNewComment
= true;
599 $
(this).next().show();
600 // Show cancel button
601 $
(this).next().next().show();
602 // Show commit button
603 $
(this).next().next().next().show();
605 $
(this).next().height($
(this).next().prop("scrollHeight"));
607 $
(this).next().select();
608 preElement
= $
(this);
611 $
("#dropBranches").change(function () {
612 $
("#dropBranches option:selected").each(function () {
613 if(branchName
!= $
(this).text()){
614 branchName
= $
(this).text();
617 $
.when(updateCookie(userName
, password
, repoName
, branchName
)).done(function(){
618 closeAllCommentInEdtiting();
624 /* Parse current URL and return anchor name */
625 function currentAnchor() {
626 var index
= document
.location
.hash
.indexOf("#");
628 return document
.location
.hash
.substring(index
+ 1);
633 /* Prealod filters field using search query */
634 function preloadFilters() {
635 // Parse URL and get query string
636 var search
= currentAnchor();
638 if(search
== null || search
.indexOf("q=") == -1)
641 search
= search
.substring(2, search
.length
);
643 if(search
== "" || search
== "undefined")
646 $
(":text").val(search
);
648 .removeClass("notUsed")
653 /* Hightlight the spoted block */
654 function highlightBlock(a
) {
659 $
(".highlighted").removeClass("highlighted");
661 var target
= $
("#" + a
);
663 if(target
.is("article")) {
664 target
.parent().addClass("highlighted");
667 target
.addClass("highlighted");
671 // Init process to commit the new comment
672 function startCommitProcess()
674 var numL
= preElement
.attr("title");
675 commentLineStart
= numL
.split('-')[0] - 1;
676 if(addNewComment
) { commentLineStart
++; }
677 commentLineEnd
= (commentLineStart
+ preElement
.text().split('\n').length
) - 1;
679 replaceComment(updateComment
, currentfileContent
);
685 function displayLogginModal(){
686 if ($
('.popover').is(':hidden')) {
687 if(sessionStarted
){ getListBranches(); }
688 $
('.popover').show();
690 else { $
('.popover').hide(); }
694 function updateDisplaying(){
697 userB64
= "Basic " + getUserPass("logginNitdoc");
698 $
('#loginGit').hide();
699 $
('#passwordGit').hide();
700 $
('#lbpasswordGit').hide();
701 $
('#lbloginGit').hide();
702 $
('#repositoryGit').hide();
703 $
('#lbrepositoryGit').hide();
704 $
('#lbbranchGit').hide();
705 $
('#branchGit').hide();
706 $
('#listBranches').show();
707 $
("#liGitHub").attr("class", "current");
708 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
709 $
('#nickName').text(userName
);
710 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
711 $
('#logginMessage').css({'display' : 'block'});
712 $
('#logginMessage').css({'text-align' : 'center'});
713 $
('.popover').css({'height' : '120px'});
714 $
('#signIn').text("Sign out");
715 sessionStarted
= true;
720 sessionStarted
= false;
721 $
('#logginMessage').css({'display' : 'none'});
722 $
("#liGitHub").attr("class", "");
723 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
724 $
('#loginGit').val("");
725 $
('#passwordGit').val("");
726 $
('#nickName').text("");
727 $
('.popover').css({'height' : '280px'});
728 $
('#logginMessage').css({'display' : 'none'});
729 $
('#repositoryGit').val($
('#repoName').attr('name'));
730 $
('#branchGit').val('wikidoc');
731 $
('#signIn').text("Sign In");
732 $
('#loginGit').show();
733 $
('#passwordGit').show();
734 $
('#lbpasswordGit').show();
735 $
('#lbloginGit').show();
736 $
('#repositoryGit').show();
737 $
('#lbrepositoryGit').show();
738 $
('#lbbranchGit').show();
739 $
('#branchGit').show();
740 $
('#listBranches').hide();
744 function setCookie(c_name
, value
, exdays
)
746 var exdate
=new Date();
747 exdate
.setDate(exdate
.getDate() + exdays
);
748 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
749 document
.cookie
=c_name
+ "=" + c_value
;
752 function del_cookie(c_name
)
754 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
757 function updateCookie(user
, pwd
, repo
, branch
){
760 setCookie("logginNitdoc", base64
.encode(user
+':'+pwd
+':'+repo
+':'+branch
), 1);
764 function getCookie(c_name
)
766 var c_value
= document
.cookie
;
767 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
768 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
769 if (c_start
== -1) { c_value
= null; }
772 c_start
= c_value
.indexOf("=", c_start
) + 1;
773 var c_end
= c_value
.indexOf(";", c_start
);
774 if (c_end
== -1) { c_end
= c_value
.length
; }
775 c_value
= unescape(c_value
.substring(c_start
,c_end
));
780 function getUserPass(c_name
){
781 var cookie
= base64
.decode(getCookie(c_name
));
782 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
785 function checkCookie()
787 var cookie
=getCookie("logginNitdoc");
788 if (cookie
!=null && cookie
!="")
790 cookie
= base64
.decode(cookie
);
791 userName
= cookie
.split(':')[0];
792 password
= cookie
.split(':')[1];
793 repoName
= cookie
.split(':')[2];
794 branchName
= cookie
.split(':')[3];
797 else { return false; }
805 base64
.PADCHAR
= '=';
806 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
807 base64
.getbyte64
= function(s
,i
) {
808 // This is oddly fast, except on Chrome/V8.
809 // Minimal or no improvement in performance by using a
810 // object with properties mapping chars to value (eg. 'A': 0)
811 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
813 throw "Cannot decode base64";
818 base64
.decode
= function(s
) {
821 var getbyte64
= base64
.getbyte64
;
829 throw "Cannot decode base64";
833 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
835 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
838 // either way, we want to ignore this last block
843 for (i
= 0; i
< imax
; i
+= 4) {
844 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
845 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
846 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
851 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
852 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
855 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
856 x
.push(String
.fromCharCode(b10
>> 16));
862 base64
.getbyte
= function(s
,i
) {
863 var x
= s
.charCodeAt(i
);
865 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
871 base64
.encode
= function(s
) {
872 if (arguments
.length
!= 1) {
873 throw "SyntaxError: Not enough arguments";
875 var padchar
= base64
.PADCHAR
;
876 var alpha
= base64
.ALPHA
;
877 var getbyte
= base64
.getbyte
;
885 var imax
= s
.length
- s
.length
% 3;
890 for (i
= 0; i
< imax
; i
+= 3) {
891 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
892 x
.push(alpha
.charAt(b10
>> 18));
893 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
894 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
895 x
.push(alpha
.charAt(b10
& 0x3f));
897 switch (s
.length
- imax
) {
899 b10
= getbyte(s
,i
) << 16;
900 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
904 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
905 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
906 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
914 function getLastCommit()
917 if(sessionStarted
){ urlHead
= "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
;}
919 // TODO: get url of the original repo.
924 beforeSend
: function (xhr
) {
925 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
931 success
: function(success
)
933 shaLastCommit
= success
.object
.sha
;
938 function getBaseTree()
941 beforeSend
: function (xhr
) {
942 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
945 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits/" + shaLastCommit
,
948 success
: function(success
)
950 shaBaseTree
= success
.tree
.sha
;
951 if (state
){ setBlob(); }
960 function setNewTree()
963 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
965 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/trees",
967 data
:'{ "base_tree" : "'+shaBaseTree
+'", '+
969 '"path":"'+ pathFile
+'",'+
972 '"sha": "'+ shaBlob
+'"'+
975 success
: function(success
)
976 { // si l'appel a bien fonctionné
977 shaNewTree
= JSON
.parse(success
).sha
;
986 function setNewCommit()
989 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
991 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits",
993 data
:'{ "message" : "'+ commitMessage
+'", '+
994 '"parents" :"'+shaLastCommit
+'",'+
995 '"tree": "'+shaNewTree
+'"'+
997 success
: function(success
)
999 shaNewCommit
= JSON
.parse(success
).sha
;
1012 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1014 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1015 data
:'{ "sha" : "'+shaNewCommit
+'", '+
1018 success
: function(success
) { displayMessage('Commit created successfully', 40, 40); },
1019 error
:function(error
){ displayMessage('Error ' + JSON
.parse(error
).object
.message
, 40, 40); }
1027 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1029 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/blobs",
1031 data
:'{ "content" : "'+text
.replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"')+'", '+
1032 '"encoding" :"utf-8"'+
1034 success
: function(success
)
1036 shaBlob
= JSON
.parse(success
).sha
;
1039 error
:function(error
){
1040 displayMessage('Error : Problem parsing JSON', 40, 40);
1046 // Display file content
1047 function getFileContent(urlFile
, newComment
)
1050 beforeSend
: function (xhr
) {
1051 xhr
.setRequestHeader ("Accept", "application/vnd.github-blob.raw");
1052 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1057 success
: function(success
)
1060 replaceComment(newComment
, success
);
1065 function replaceComment(newComment
, fileContent
){
1066 var arrayNew
= newComment
.split('\n');
1067 var lNew
= arrayNew
.length
;
1069 var lines
= fileContent
.split("\n");
1070 for (var i
= 0; i
< lines
.length
; i
++) {
1071 if(i
== commentLineStart
){
1073 for(var indexLine
=0; indexLine
< lines
[i
+1].length
; indexxLine
++){
1074 if(lines
[i
+1].substr(indexLine
,1) == "\t" || lines
[i
+1].substr(indexLine
,1) == "#"){ text
+= lines
[i
+1].substr(indexLine
,1); }
1077 text
+= lines
[i] + "\n";
1079 // We change the comment
1080 for(var j
= 0; j
< lNew
; j
++){
1081 if(commentType
== 1){ text
+= "\t# " + arrayNew
[j] + "\n"; }
1083 if(arrayNew
[j] == ""){ text
+= "#"+"\n"; }
1084 else{ text
+= "# " + arrayNew
[j] + "\n"; }
1088 else if(i
< commentLineStart || i
>= commentLineEnd
){
1089 if(i
== lines
.length
-1){ text
+= lines
[i]; }
1090 else{ text
+= lines
[i] + "\n"; }
1094 addNewComment
= false;
1098 function getCommentLastCommit(path
){
1101 if(shaLastCommit
!= ""){
1102 if (checkCookie()) { urlRaw
="https://rawgithub.com/"+ userName
+"/"+ repoName
+"/" + shaLastCommit
+ "/" + path
; }
1103 else{ urlRaw
="https://rawgithub.com/StefanLage/"+ $
('#repoName').attr('name') +"/" + shaLastCommit
+ "/" + path
; }
1109 success
: function(success
)
1111 currentfileContent
= success
;
1117 function displayMessage(msg
, widthDiv
, margModal
){
1120 $
('#btnCreateBranch').css('margin-left',widthDiv
+ '%');
1121 $
('#txtQuestion').text(msg
);
1122 $
('#btnCreateBranch').text("Ok");
1123 $
('#btnCancelBranch').hide();
1124 $
('#modalQuestion').css({'left' : margModal
+ '%'})
1125 $
('#modalQuestion').show();
1126 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1127 $
('body').append('<div id="fade"></div>');
1128 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1131 function displaySpinner(){
1132 spinner
.spin(targetSpinner
);
1133 $
("#waitCommit").show();
1136 // Check if the repo already exist
1137 function isRepoExisting(){
1139 beforeSend
: function (xhr
) {
1140 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1143 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1146 success
: function(){ repoExist
= true; },
1149 displayMessage('Repo not found !', 35, 45);
1155 // Check if the branch already exist
1156 function isBranchExisting(){
1158 beforeSend
: function (xhr
) {
1159 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1162 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1165 success
: function(){ branchExist
= true; },
1168 branchExist
= false;
1171 $
('#txtQuestion').text("Are you sure you want to create that branch ?");
1172 $
('#btnCancelBranch').show();
1173 $
('#btnCreateBranch').text("Yes");
1174 $
('#modalQuestion').show();
1175 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1176 $
('body').append('<div id="fade"></div>');
1177 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1182 function getMasterSha()
1185 beforeSend
: function (xhr
) {
1186 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1189 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/master",
1192 success
: function(success
) { shaMaster
= success
.object
.sha
; }
1196 function createBranch(){
1201 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1203 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs",
1204 data
:'{ "ref" : "refs/heads/'+branchName
+'",'+
1205 '"sha" : "'+shaMaster
+'"'+
1207 success
: function(){ return; },
1210 displayMessage('Impossible to create the new branch : ' + branchName
, 40, 40);
1215 $
.fn
.spin
= function(opts
) {
1216 this.each(function() {
1217 var $
this = $
(this),
1218 data
= $
this.data();
1221 data
.spinner
.stop();
1222 delete data
.spinner
;
1224 if (opts
!== false) {
1225 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);
1231 function reloadComment(){
1232 $
.when(getCommentLastCommit($
('pre[class=text_label]').attr('tag'))).done(function(){
1233 $
('pre[class=text_label]').each(function(){ getCommentOfFunction($
(this)); });
1237 function getCommentOfFunction(element
){
1239 var numL
= element
.attr("title");
1241 commentLineStart
= numL
.split('-')[0] - 1;
1242 commentLineEnd
= (commentLineStart
+ element
.text().split('\n').length
) - 1;
1243 var lines
= currentfileContent
.split("\n");
1244 for (var i
= 0; i
< lines
.length
; i
++) {
1245 if(i
>= commentLineStart
-1 && i
<= commentLineEnd
){
1246 if (lines
[i].substr(1,1) == "#"){ textC
+= lines
[i].substr(3,lines
[i].length
) + "\n";}
1247 else if(lines
[i].substr(0,1) == '#'){ textC
+= lines
[i].substr(2,lines
[i].length
) + "\n"; }
1250 if (textC
!= ""){ element
.text(textC
); }
1254 // Get list of branches
1255 function getListBranches()
1257 cleanListBranches();
1259 beforeSend
: function (xhr
) {
1260 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1263 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/branches",
1266 success
: function(success
)
1268 for(var branch
in success
) {
1270 if(branchName
== success
[branch].name
){
1271 selected
= 'selected';
1273 $
('#dropBranches').append('<option value="" '+ selected
+'>' + success
[branch].name
+ '</option>');
1279 // Delete all option in the list
1280 function cleanListBranches(){
1281 $
('#dropBranches').children("option").remove();
1284 function closeAllCommentInEdtiting(){
1285 $
('a[id=cancelBtn]').each(function(){
1286 closeEditing($
(this));
1290 function closeEditing(tag
){
1291 if(editComment
> 0){ editComment
-= 1; }
1299 tag
.prev().prev().show();