5 var sessionStarted
= false;
7 var currentfileContent
= '';
8 var addNewComment
= false;
13 var shaLastCommit
= "";
19 var repoExist
= false;
20 var branchExist
= false;
22 var loginProcess
= false;
25 var commitMessage
= '';
29 lines
: 11, // The number of lines to draw
30 length
: 7, // The length of each line
31 width
: 4, // The line thickness
32 radius
: 10, // The radius of the inner circle
33 corners
: 1, // Corner roundness (0..1)
34 rotate
: 0, // The rotation offset
35 color
: '#FFF', // #rgb or #rrggbb
36 speed
: 1, // Rounds per second
37 trail
: 60, // Afterglow percentage
38 shadow
: false, // Whether to render a shadow
39 hwaccel
: false, // Whether to use hardware acceleration
40 className
: 'spinner', // The CSS class to assign to the spinner
41 zIndex
: 99999, // The z-index (defaults to 2000000000)
42 top
: '300', // Top position relative to parent in px
43 left
: 'auto' // Left position relative to parent in px
45 var targetSpinner
= document
.getElementById('waitCommit');
46 var spinner
= new Spinner(opts
).spin(targetSpinner
);
49 * JQuery Case Insensitive :icontains selector
51 $
.expr
[':'].icontains
= function(obj
, index
, meta
, stack
){
52 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;
56 * Quick Search global vars
59 // Current search results preview table
60 var currentTable
= null;
62 //Hightlighted index in search result preview table
63 var currentIndex
= -1;
65 // Check if a comment is editing
66 window
.onbeforeunload
= function() {
68 return 'Are you sure you want to leave this page?';
73 * Add folding and filtering facilities to class description page.
75 $
(document
).ready(function() {
79 $
('a[id=commitBtn]').hide();
80 $
('a[id=cancelBtn]').hide();
81 // Hide Authenfication form
86 * Highlight the spoted element
88 highlightBlock(currentAnchor());
97 $
(document
.createElement("a"))
101 .css("cursor", "pointer")
103 if($
(this).find("a.fold").html() == "+") {
104 $
(this).find("a.fold").html("-");
106 $
(this).find("a.fold").html("+");
108 $
(this).nextAll().toggle();
111 // Insert search field
114 $
(document
.createElement("li"))
116 $
(document
.createElement("form"))
118 $
(document
.createElement("input"))
123 value
: "quick search..."
131 // Select previous result on "Up"
133 // If already on first result, focus search input
134 if(currentIndex
== 0) {
135 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
136 $
("#search").focus();
137 // Else select previous result
138 } else if(currentIndex
> 0) {
139 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
141 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
142 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
143 $
("#search").focus();
147 // Select next result on "Down"
149 if(currentIndex
< currentTable
.find("tr").length
- 1) {
150 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
152 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
153 $
("#search").val($
(currentTable
.find("tr")[currentIndex]).data("searchDetails").name
);
154 $
("#search").focus();
157 // Go to url on "Enter"
159 if(currentIndex
> -1) {
160 window
.location
= $
(currentTable
.find("tr")[currentIndex]).data("searchDetails").url
;
163 if($
("#search").val().length
== 0)
166 window
.location
= "full-index.html#q=" + $
("#search").val();
167 if(window
.location
.href
.indexOf("full-index.html") > -1) {
173 // Hide results preview on "Escape"
176 if(currentTable
!= null) {
177 currentTable
.remove();
183 if($
("#search").val().length
== 0) {
187 // Remove previous table
188 if(currentTable
!= null) {
189 currentTable
.remove();
192 // Build results table
194 currentTable
= $
(document
.createElement("table"));
196 // Escape regexp related characters in query
197 var query
= $
("#search").val();
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
, "\\\\");
203 query
= query
.replace(/\?/gi
, "\\?");
204 query
= query
.replace(/\
(/gi
, "\\(");
205 query
= query
.replace(/\
)/gi
, "\\)");
208 var regexp
= new RegExp("^" + query
, "i");
209 for(var entry
in entries
) {
213 var result
= entry
.match(regexp
);
214 if(result
!= null && result
.toString().toUpperCase() == $
("#search").val().toUpperCase()) {
215 for(var i
= 0; i
< entries
[entry].length
; i
++) {
220 $
(document
.createElement("tr"))
221 .data("searchDetails", {name
: entry
, url
: entries
[entry][i]["url"]})
222 .data("index", index
)
223 .append($
(document
.createElement("td")).html(entry
))
225 $
(document
.createElement("td"))
226 .addClass("entryInfo")
227 .html(entries
[entry][i]["txt"] + " »"))
228 .mouseover( function() {
229 $
(currentTable
.find("tr")[currentIndex]).removeClass("activeSearchResult");
230 $
(this).addClass("activeSearchResult");
231 currentIndex
= $
(this).data("index");
233 .mouseout( function() {
234 $
(this).removeClass("activeSearchResult");
237 window
.location
= $
(this).data("searchDetails")["url"];
245 // Initialize table properties
246 currentTable
.attr("id", "searchTable");
247 currentTable
.css("position", "absolute");
248 currentTable
.width($
("#search").outerWidth());
249 $
("header").append(currentTable
);
250 currentTable
.offset({left
: $
("#search").offset().left
+ ($
("#search").outerWidth() - currentTable
.outerWidth()), top
: $
("#search").offset().top
+ $
("#search").outerHeight()});
252 // Preselect first entry
253 if(currentTable
.find("tr").length
> 0) {
255 $
(currentTable
.find("tr")[currentIndex]).addClass("activeSearchResult");
256 $
("#search").focus();
261 .focusout(function() {
262 if($
(this).val() == "") {
263 $
(this).addClass("notUsed");
264 $
(this).val("quick search...");
267 .focusin(function() {
268 if($
(this).val() == "quick search...") {
269 $
(this).removeClass("notUsed");
274 .submit( function() {
280 // Close quicksearch list on click
281 $
(document
).click(function(e
) {
282 if(e
.target
!= $
("#search")[0] && e
.target
!= $
("#searchTable")[0]) {
283 if(currentTable
!= null) {
284 currentTable
.remove();
290 // Insert filter field
291 $
("article.filterable h2, nav.filterable h3")
293 $
(document
.createElement("div"))
296 $
(document
.createElement("input"))
303 $
(this).parent().parent().find("ul li:not(:icontains('" + $
(this).val() + "'))").addClass("hide");
304 $
(this).parent().parent().find("ul li:icontains('" + $
(this).val() + "')").removeClass("hide");
306 .focusout(function() {
307 if($
(this).val() == "") {
308 $
(this).addClass("notUsed");
309 $
(this).val("filter...");
312 .focusin(function() {
313 if($
(this).val() == "filter...") {
314 $
(this).removeClass("notUsed");
321 // Filter toggle between H I R in nav porperties list
322 $
("nav.properties.filterable .filter")
324 $
(document
.createElement("a"))
327 title
: "hide inherited properties"
330 if($
(this).hasClass("hidden")) {
331 $
(this).parent().parent().find("li.inherit").show();
333 $
(this).parent().parent().find("li.inherit").hide();
336 $
(this).toggleClass("hidden");
340 $
(document
.createElement("a"))
343 title
: "hide redefined properties"
346 if($
(this).hasClass("hidden")) {
347 $
(this).parent().parent().find("li.redef").show();
349 $
(this).parent().parent().find("li.redef").hide();
352 $
(this).toggleClass("hidden");
356 $
(document
.createElement("a"))
359 title
: "hide introduced properties"
362 if($
(this).hasClass("hidden")) {
363 $
(this).parent().parent().find("li.intro").show();
365 $
(this).parent().parent().find("li.intro").hide();
368 $
(this).toggleClass("hidden");
372 // Filter toggle between I R in
373 $
("article.properties.filterable .filter, article.classes.filterable .filter")
375 $
(document
.createElement("a"))
378 title
: "hide introduced properties"
381 if($
(this).hasClass("hidden")) {
382 $
(this).parent().parent().find("li.intro").show();
384 $
(this).parent().parent().find("li.intro").hide();
387 $
(this).toggleClass("hidden");
391 $
(document
.createElement("a"))
394 title
: "hide redefined properties"
397 if($
(this).hasClass("hidden")) {
398 $
(this).parent().parent().find("li.redef").show();
400 $
(this).parent().parent().find("li.redef").hide();
403 $
(this).toggleClass("hidden");
410 $
("a[href*='#']").click( function() {
411 highlightBlock($
(this).attr("href").split(/#
/)[1]);
414 //Preload filter fields with query string
416 // Hide Authenfication form
417 $
(".popover").hide();
418 // Display Login modal
419 $
("#logGitHub").click(function(){ displayLogginModal(); });
422 // If cookie existing the session is opened
423 if(sessionStarted
){ userB64
= "Basic " + getUserPass("logginNitdoc"); }
425 // Sign In an github user or Log out him
426 $
("#signIn").click(function(){
428 if($
('#loginGit').val() == "" || $
('#passwordGit').val() == ""){ displayMessage('Please informed login/password field!', 40, 45); }
431 userName
= $
('#loginGit').val();
432 password
= $
('#passwordGit').val();
433 githubRepo
= $
('#repositoryGit').val();
434 branchName
= $
('#branchGit').val();
435 userB64
= "Basic " + base64
.encode(userName
+':'+password
);
437 // Check if repo exist
440 $
.when(isBranchExisting()).done(function(){
443 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+githubRepo
+':'+branchName
), 1);
444 $
('#loginGit').val("");
445 $
('#passwordGit').val("");
455 // Delete cookie and reset settings
456 del_cookie("logginNitdoc");
457 closeAllCommentInEdtiting();
459 displayLogginModal();
462 // Activate edit mode
463 $
('pre[class=text_label]').click(function(){
464 // the customer is loggued ?
465 if(!sessionStarted || userName
== ""){
466 // No => nothing happen
470 var arrayNew
= $
(this).text().split('\n');
471 var lNew
= arrayNew
.length
- 1;
474 for (var i
= 0; i
< lNew
; i
++) {
475 adapt
+= arrayNew
[i];
476 if(i
< lNew
-1){ adapt
+= "\n"; }
482 $
(this).next().show();
483 // Show cancel button
484 $
(this).next().next().show();
485 // Show commit button
486 $
(this).next().next().next().show();
487 // Add text in edit box
488 if($
(this).next().val() == "" || $
(this).next().val() != adapt
){ $
(this).next().val(adapt
); }
490 $
(this).next().height($
(this).next().prop("scrollHeight"));
492 $
(this).next().select();
493 preElement
= $
(this);
497 // Disable the edit mode
498 $
('a[id=cancelBtn]').click(function(){
499 closeEditing($
(this));
502 // Display commit form
503 $
('a[id=commitBtn]').click(function(){
504 $
(this).parent().prev().children('#lblDiffCommit').text("");
506 updateComment
= $
(this).prev().prev().val();
507 commentType
= $
(this).prev().prev().prev().attr('type');
509 if(updateComment
== ""){ displayMessage('The comment field is empty!', 40, 45); }
512 displayMessage("You need to be loggued before commit something", 45, 40);
513 displayLogginModal();
517 // Create the commit message
518 commitMessage
= 'Wikidoc: modified comment in ' + $
(this).parent().prev().html().split(' ')[1];
519 $
('#commitMessage').text(commitMessage
);
520 $
('#commitMessage').css({'display': 'block'});
521 pathFile
= $
(this).prev().prev().prev().attr('tag');
522 $
('#modal').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btn_close" title="Close" alt="Close" /></a>');
523 $
('body').append('<div id="fade"></div>');
524 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
529 $
('.btn_close').click(function(){
531 $
(this).next().hide();
532 if(editComment
> 0){ editComment
-= 1; }
533 $
('#chkSignedOff').attr('checked', false);
536 //Close Popups and Fade Layer
537 $
('body').on('click', 'a.close, #fade', function() {
538 if(editComment
> 0){ editComment
-= 1; }
539 $
('#fade , #modal').fadeOut(function() {
540 $
('#fade, a.close').remove();
542 $
('#modalQuestion').hide();
543 $
('#chkSignedOff').attr('checked', false);
546 $
('#loginAction').click(function(){
550 // Look if the customer is logged
552 displayMessage("You need to be loggued before commit something", 100, 40);
553 $
('.popover').show();
556 else{ userB64
= "Basic " + getUserPass("logginNitdoc"); }
557 // Check if repo exist
563 commitMessage
= $
('#commitMessage').val().replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"');
564 if(commitMessage
== ""){ commitMessage
= "New commit";}
566 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
569 startCommitProcess();
572 $
('#modal, #modalQuestion').fadeOut(function() {
574 $
('#password').val("");
575 $
('textarea').hide();
576 $
('textarea').prev().show();
578 $
('a[id=cancelBtn]').hide();
579 $
('a[id=commitBtn]').hide();
580 // Re-load all comment
584 else{ editComment
-= 1; }
585 $
('#chkSignedOff').attr('checked', false);
588 // Cancel creating branch
589 $
('#btnCancelBranch').click(function(){
591 $
('#modalQuestion').hide();
592 $
('#fade , #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
596 // Create new branch and continu
597 $
('#btnCreateBranch').click(function(){
598 $
('#modalQuestion').hide();
599 if($
('#btnCreateBranch').text() != 'Ok'){
602 commitMessage
= $
('#commitMessage').val().replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"');
603 if(commitMessage
== ""){ commitMessage
= "New commit"; }
606 setCookie("logginNitdoc", base64
.encode(userName
+':'+password
+':'+githubRepo
+':'+branchName
), 1);
607 $
('#loginGit').val("");
608 $
('#passwordGit').val("");
609 loginProcess
= false;
610 displayLogginModal();
613 if ($
.trim(updateComment
) == ''){ this.value
= (this.defaultValue ?
this.defaultValue
: ''); }
614 else{ startCommitProcess(); }
620 $
('#fade , #modalQuestion, #modal').fadeOut(function() { $
('#fade, a.close').remove(); });
624 $
('a[class=newComment]').click(function(){
625 addNewComment
= true;
630 $
(this).next().show();
631 // Show cancel button
632 $
(this).next().next().show();
633 // Show commit button
634 $
(this).next().next().next().show();
636 $
(this).next().height($
(this).next().prop("scrollHeight"));
638 $
(this).next().select();
639 preElement
= $
(this);
642 $
("#dropBranches").change(function () {
643 $
("#dropBranches option:selected").each(function () {
644 if(branchName
!= $
(this).text()){
645 branchName
= $
(this).text();
648 $
.when(updateCookie(userName
, password
, githubRepo
, branchName
)).done(function(){
649 closeAllCommentInEdtiting();
656 if(sessionStarted
== true){
657 $
(this).css({'cursor' : 'hand'});
660 $
(this).css({'cursor' : ''});
664 if(sessionStarted
== true){
665 $
(this).css({'cursor' : 'pointer'});
668 $
(this).css({'cursor' : ''});
673 $
('#chkSignedOff').click(function(){
674 if($
(this).is(':checked')){ addSignedOff(); }
675 else{ removeSignedOff(); }
679 /* Parse current URL and return anchor name */
680 function currentAnchor() {
681 var index
= document
.location
.hash
.indexOf("#");
683 return document
.location
.hash
.substring(index
+ 1);
688 /* Prealod filters field using search query */
689 function preloadFilters() {
690 // Parse URL and get query string
691 var search
= currentAnchor();
693 if(search
== null || search
.indexOf("q=") == -1)
696 search
= search
.substring(2, search
.length
);
698 if(search
== "" || search
== "undefined")
701 $
(":text").val(search
);
703 .removeClass("notUsed")
708 /* Hightlight the spoted block */
709 function highlightBlock(a
) {
714 $
(".highlighted").removeClass("highlighted");
716 var target
= $
("#" + a
);
718 if(target
.is("article")) {
719 target
.parent().addClass("highlighted");
722 target
.addClass("highlighted");
726 // Init process to commit the new comment
727 function startCommitProcess()
729 if($
('#chkSignedOff').is(':checked')){
730 var numL
= preElement
.attr("title");
731 commentLineStart
= numL
.split('-')[0] - 1;
732 if(addNewComment
) { commentLineStart
++; }
733 commentLineEnd
= (commentLineStart
+ preElement
.text().split('\n').length
) - 1;
735 replaceComment(updateComment
, currentfileContent
);
741 displayMessage('Please sign this commit', 40, 40);
745 function displayLogginModal(){
746 if ($
('.popover').is(':hidden')) {
747 if(sessionStarted
){ getListBranches(); }
748 $
('.popover').show();
750 else { $
('.popover').hide(); }
754 function updateDisplaying(){
757 userB64
= "Basic " + getUserPass("logginNitdoc");
758 $
('#loginGit').hide();
759 $
('#passwordGit').hide();
760 $
('#lbpasswordGit').hide();
761 $
('#lbloginGit').hide();
762 $
('#repositoryGit').hide();
763 $
('#lbrepositoryGit').hide();
764 $
('#lbbranchGit').hide();
765 $
('#branchGit').hide();
766 $
('#listBranches').show();
767 $
('#divGitHubRepoDisplay').show();
768 $
("#liGitHub").attr("class", "current");
769 $
("#imgGitHub").attr("src", "resources/icons/github-icon-w.png");
770 $
('#nickName').text(userName
);
771 $
('#githubAccount').attr("href", "https://github.com/"+userName
);
772 $
('#logginMessage').css({'display' : 'block'});
773 $
('#logginMessage').css({'text-align' : 'center'});
774 $
('.popover').css({'height' : '190px'});
775 $
('#signIn').text("Sign out");
776 $
('#githubRepoDisplay').text(githubRepo
);
777 sessionStarted
= true;
782 sessionStarted
= false;
783 $
('#logginMessage').css({'display' : 'none'});
784 $
("#liGitHub").attr("class", "");
785 $
("#imgGitHub").attr("src", "resources/icons/github-icon.png");
786 $
('#loginGit').val("");
787 $
('#passwordGit').val("");
788 $
('#nickName').text("");
789 $
('.popover').css({'height' : '325px'});
790 $
('#logginMessage').css({'display' : 'none'});
791 $
('#repositoryGit').val($
('#repoName').attr('name'));
792 $
('#branchGit').val('wikidoc');
793 $
('#signIn').text("Sign In");
794 $
('#loginGit').show();
795 $
('#passwordGit').show();
796 $
('#lbpasswordGit').show();
797 $
('#lbloginGit').show();
798 $
('#repositoryGit').show();
799 $
('#lbrepositoryGit').show();
800 $
('#lbbranchGit').show();
801 $
('#branchGit').show();
802 $
('#listBranches').hide();
803 $
('#divGitHubRepoDisplay').hide();
807 function setCookie(c_name
, value
, exdays
)
809 var exdate
=new Date();
810 exdate
.setDate(exdate
.getDate() + exdays
);
811 var c_value
=escape(value
) + ((exdays
==null) ?
"" : "; expires="+exdate
.toUTCString());
812 document
.cookie
=c_name
+ "=" + c_value
;
815 function del_cookie(c_name
)
817 document
.cookie
= c_name
+ '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
820 function updateCookie(user
, pwd
, repo
, branch
){
823 setCookie("logginNitdoc", base64
.encode(user
+':'+pwd
+':'+repo
+':'+branch
), 1);
827 function getCookie(c_name
)
829 var c_value
= document
.cookie
;
830 var c_start
= c_value
.indexOf(" " + c_name
+ "=");
831 if (c_start
== -1) { c_start
= c_value
.indexOf(c_name
+ "="); }
832 if (c_start
== -1) { c_value
= null; }
835 c_start
= c_value
.indexOf("=", c_start
) + 1;
836 var c_end
= c_value
.indexOf(";", c_start
);
837 if (c_end
== -1) { c_end
= c_value
.length
; }
838 c_value
= unescape(c_value
.substring(c_start
,c_end
));
843 function getUserPass(c_name
){
844 var cookie
= base64
.decode(getCookie(c_name
));
845 return base64
.encode(cookie
.split(':')[0] + ':' + cookie
.split(':')[1]);
848 function checkCookie()
850 var cookie
=getCookie("logginNitdoc");
851 if (cookie
!=null && cookie
!="")
853 cookie
= base64
.decode(cookie
);
854 userName
= cookie
.split(':')[0];
855 password
= cookie
.split(':')[1];
856 githubRepo
= cookie
.split(':')[2];
857 branchName
= cookie
.split(':')[3];
860 else { return false; }
868 base64
.PADCHAR
= '=';
869 base64
.ALPHA
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
870 base64
.getbyte64
= function(s
,i
) {
871 // This is oddly fast, except on Chrome/V8.
872 // Minimal or no improvement in performance by using a
873 // object with properties mapping chars to value (eg. 'A': 0)
874 var idx
= base64
.ALPHA
.indexOf(s
.charAt(i
));
876 throw "Cannot decode base64";
881 base64
.decode
= function(s
) {
884 var getbyte64
= base64
.getbyte64
;
892 throw "Cannot decode base64";
896 if (s
.charAt(imax
-1) == base64
.PADCHAR
) {
898 if (s
.charAt(imax
-2) == base64
.PADCHAR
) {
901 // either way, we want to ignore this last block
906 for (i
= 0; i
< imax
; i
+= 4) {
907 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
908 (getbyte64(s
,i
+2) << 6) |
getbyte64(s
,i
+3);
909 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff, b10
& 0xff));
914 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12) |
(getbyte64(s
,i
+2) << 6)
915 x
.push(String
.fromCharCode(b10
>> 16, (b10
>> 8) & 0xff));
918 b10
= (getbyte64(s
,i
) << 18) |
(getbyte64(s
,i
+1) << 12);
919 x
.push(String
.fromCharCode(b10
>> 16));
925 base64
.getbyte
= function(s
,i
) {
926 var x
= s
.charCodeAt(i
);
928 throw "INVALID_CHARACTER_ERR: DOM Exception 5";
934 base64
.encode
= function(s
) {
935 if (arguments
.length
!= 1) {
936 throw "SyntaxError: Not enough arguments";
938 var padchar
= base64
.PADCHAR
;
939 var alpha
= base64
.ALPHA
;
940 var getbyte
= base64
.getbyte
;
948 var imax
= s
.length
- s
.length
% 3;
953 for (i
= 0; i
< imax
; i
+= 3) {
954 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8) |
getbyte(s
,i
+2);
955 x
.push(alpha
.charAt(b10
>> 18));
956 x
.push(alpha
.charAt((b10
>> 12) & 0x3F));
957 x
.push(alpha
.charAt((b10
>> 6) & 0x3f));
958 x
.push(alpha
.charAt(b10
& 0x3f));
960 switch (s
.length
- imax
) {
962 b10
= getbyte(s
,i
) << 16;
963 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
967 b10
= (getbyte(s
,i
) << 16) |
(getbyte(s
,i
+1) << 8);
968 x
.push(alpha
.charAt(b10
>> 18) + alpha
.charAt((b10
>> 12) & 0x3F) +
969 alpha
.charAt((b10
>> 6) & 0x3f) + padchar
);
977 function getLastCommit()
980 if(sessionStarted
){ urlHead
= "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
;}
982 // TODO: get url of the original repo.
987 beforeSend
: function (xhr
) {
988 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
994 success
: function(success
)
996 shaLastCommit
= success
.object
.sha
;
1001 function getBaseTree()
1004 beforeSend
: function (xhr
) {
1005 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1008 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits/" + shaLastCommit
,
1011 success
: function(success
)
1013 shaBaseTree
= success
.tree
.sha
;
1014 if (state
){ setBlob(); }
1023 function setNewTree()
1026 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1028 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/trees",
1031 data
:'{ "base_tree" : "'+shaBaseTree
+'", '+
1033 '"path":"'+ pathFile
+'",'+
1036 '"sha": "'+ shaBlob
+'"'+
1039 success
: function(success
)
1040 { // si l'appel a bien fonctionné
1041 shaNewTree
= success
.sha
;
1050 function setNewCommit()
1054 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1056 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/commits",
1059 data
:'{ "message" : "'+ commitMessage
+'", '+
1060 '"parents" :"'+shaLastCommit
+'",'+
1061 '"tree": "'+shaNewTree
+'"'+
1063 success
: function(success
)
1065 shaNewCommit
= success
.sha
;
1078 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1080 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1082 data
:'{ "sha" : "'+shaNewCommit
+'", '+
1085 success
: function(success
) { displayMessage('Commit created successfully', 40, 40); },
1086 error
:function(error
){ displayMessage('Error ' + error
.object
.message
, 40, 40); }
1094 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1096 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/blobs",
1099 data
:'{ "content" : "'+text
.replace(/\r?
\n/g
, '\\n').replace(/\t/g
, '\\t').replace(/\"/g
,'\\"')+'", '+
1100 '"encoding" :"utf-8"'+
1102 success
: function(success
)
1104 shaBlob
= success
.sha
;
1107 error
:function(error
){
1108 displayMessage('Error : Problem parsing JSON', 40, 40);
1114 // Display file content
1115 function getFileContent(urlFile
, newComment
)
1118 beforeSend
: function (xhr
) {
1119 xhr
.setRequestHeader ("Accept", "application/vnd.github-blob.raw");
1120 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1125 success
: function(success
)
1128 replaceComment(newComment
, success
);
1133 function replaceComment(newComment
, fileContent
){
1134 var arrayNew
= newComment
.split('\n');
1135 var lNew
= arrayNew
.length
;
1137 var lines
= fileContent
.split("\n");
1138 for (var i
= 0; i
< lines
.length
; i
++) {
1139 if(i
== commentLineStart
){
1141 for(var indexLine
=0; indexLine
< lines
[i
+1].length
; indexxLine
++){
1142 if(lines
[i
+1].substr(indexLine
,1) == "\t" || lines
[i
+1].substr(indexLine
,1) == "#"){ text
+= lines
[i
+1].substr(indexLine
,1); }
1145 text
+= lines
[i] + "\n";
1147 // We change the comment
1148 for(var j
= 0; j
< lNew
; j
++){
1149 if(commentType
== 1){ text
+= "\t# " + arrayNew
[j] + "\n"; }
1151 if(arrayNew
[j] == ""){ text
+= "#"+"\n"; }
1152 else{ text
+= "# " + arrayNew
[j] + "\n"; }
1156 else if(i
< commentLineStart || i
>= commentLineEnd
){
1157 if(i
== lines
.length
-1){ text
+= lines
[i]; }
1158 else{ text
+= lines
[i] + "\n"; }
1162 addNewComment
= false;
1166 function getCommentLastCommit(path
){
1169 if(shaLastCommit
!= ""){
1170 if (checkCookie()) {
1171 urlRaw
="https://rawgithub.com/"+ userName
+"/"+ githubRepo
+"/" + shaLastCommit
+ "/" + path
;
1176 success
: function(success
)
1178 currentfileContent
= success
;
1185 function displayMessage(msg
, widthDiv
, margModal
){
1188 $
('#btnCancelBranch').hide();
1189 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1190 $
('#txtQuestion').text(msg
);
1191 $
('#btnCreateBranch').text("Ok");
1192 var xModal
= $
('#modalQuestion').css('width').split('px')[0];
1193 var yModal
= $
('#modalQuestion').css('height').split('px')[0];
1194 var x
= $
(document
).width
/2 - xModal
/2;
1195 var y
= $
(document
).height
/2 - yModal
/2;
1196 var xBtnBranch
= $
('#btnCreateBranch').css('width').split('px')[0];
1197 $
('#modalQuestion').css({'left' : x
, 'top' : y
});
1198 $
('#modalQuestion').show();
1199 $
('#btnCreateBranch').css('margin-left', xModal
/2 - xBtnBranch
);
1200 $
('body').append('<div id="fade"></div>');
1201 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1204 function displaySpinner(){
1205 spinner
.spin(targetSpinner
);
1206 $
("#waitCommit").show();
1209 // Check if the repo already exist
1210 function isRepoExisting(){
1212 beforeSend
: function (xhr
) {
1213 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1216 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1219 success
: function(){ repoExist
= true; },
1222 displayMessage('Repo not found !', 35, 45);
1228 // Check if the branch already exist
1229 function isBranchExisting(){
1231 beforeSend
: function (xhr
) {
1232 if (userB64
!= "") { xhr
.setRequestHeader ("Authorization", userB64
); }
1235 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/"+branchName
,
1238 success
: function(){ branchExist
= true; },
1241 branchExist
= false;
1244 $
('#txtQuestion').text("Are you sure you want to create that branch ?");
1245 $
('#btnCancelBranch').show();
1246 $
('#btnCreateBranch').text("Yes");
1247 $
('#modalQuestion').show();
1248 $
('#modalQuestion').show().prepend('<a class="close"><img src="resources/icons/close.png" class="btnCloseQuestion" title="Close" alt="Close" /></a>');
1249 $
('body').append('<div id="fade"></div>');
1250 $
('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
1255 function getMasterSha()
1258 beforeSend
: function (xhr
) {
1259 if (userB64
!= ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1262 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs/heads/master",
1265 success
: function(success
) { shaMaster
= success
.object
.sha
; }
1269 function createBranch(){
1274 beforeSend
: function (xhr
) { xhr
.setRequestHeader ("Authorization", userB64
); },
1276 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/git/refs",
1277 data
:'{ "ref" : "refs/heads/'+branchName
+'",'+
1278 '"sha" : "'+shaMaster
+'"'+
1280 success
: function(){ return; },
1283 displayMessage('Impossible to create the new branch : ' + branchName
, 40, 40);
1288 $
.fn
.spin
= function(opts
) {
1289 this.each(function() {
1290 var $
this = $
(this),
1291 data
= $
this.data();
1294 data
.spinner
.stop();
1295 delete data
.spinner
;
1297 if (opts
!== false) {
1298 data
.spinner
= new Spinner($
.extend({color
: $
this.css('color')}, opts
)).spin(this);
1304 function reloadComment(){
1305 $
.when(getCommentLastCommit($
('pre[class=text_label]').attr('tag'))).done(function(){
1306 $
('pre[class=text_label]').each(function(){ getCommentOfFunction($
(this)); });
1310 function getCommentOfFunction(element
){
1312 var numL
= element
.attr("title");
1314 commentLineStart
= numL
.split('-')[0] - 1;
1315 commentLineEnd
= (commentLineStart
+ element
.text().split('\n').length
) - 1;
1316 var lines
= currentfileContent
.split("\n");
1317 for (var i
= 0; i
< lines
.length
; i
++) {
1318 if(i
>= commentLineStart
-1 && i
<= commentLineEnd
){
1319 if (lines
[i].substr(1,1) == "#"){ textC
+= lines
[i].substr(3,lines
[i].length
) + "\n";}
1320 else if(lines
[i].substr(0,1) == '#'){ textC
+= lines
[i].substr(2,lines
[i].length
) + "\n"; }
1323 if (textC
!= ""){ element
.text(textC
); }
1327 // Get list of branches
1328 function getListBranches()
1330 cleanListBranches();
1332 beforeSend
: function (xhr
) {
1333 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1336 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
+"/branches",
1339 success
: function(success
)
1341 for(var branch
in success
) {
1343 if(branchName
== success
[branch].name
){
1344 selected
= 'selected';
1346 $
('#dropBranches').append('<option value="" '+ selected
+'>' + success
[branch].name
+ '</option>');
1352 // Delete all option in the list
1353 function cleanListBranches(){
1354 $
('#dropBranches').children("option").remove();
1357 function closeAllCommentInEdtiting(){
1358 $
('a[id=cancelBtn]').each(function(){
1359 closeEditing($
(this));
1363 function closeEditing(tag
){
1364 if(editComment
> 0){ editComment
-= 1; }
1372 tag
.prev().prev().show();
1375 function checkSignIn(){
1376 var response
= false;
1378 beforeSend
: function (xhr
) {
1379 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1382 url
: "https://api.github.com/repos/"+userName
+"/"+githubRepo
,
1385 success
: function(success
)
1389 displayMessage('You are now logged in');
1393 displayMessage('Error : Wrong username or password');
1400 function getUserInfo(){
1402 beforeSend
: function (xhr
) {
1403 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1406 url
: "https://api.github.com/user/emails",
1409 success
: function(success
)
1411 userEmail
= success
;
1416 function getSignedOff(){
1418 beforeSend
: function (xhr
) {
1419 if ($
("#login").val() != ""){ xhr
.setRequestHeader ("Authorization", userB64
); }
1422 url
: "https://api.github.com/users/"+userName
,
1425 success
: function(success
)
1427 signedOff
= success
.name
;
1432 function addSignedOff(){
1433 $
.when(getUserInfo()).done(function(){
1434 $
.when(getSignedOff()).done(function(){
1435 $
('#commitMessage').val($
('#commitMessage').val() + "\n\nSigned-off-by: "+signedOff
+" <"+userEmail
+">");
1440 function removeSignedOff(){
1441 $
('#commitMessage').val(commitMessage
);