Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
Submit
</button>
</form>
<form class="navbar-form navbar-right" role="search">
<select id="language" name="language" class="form-control"></select>
</form>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's mixed whitespace (spaces/tabs) in these lines as well.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me like someone should:

  1. Close this PR
  2. Open a new PR completely normalizing the whitespace in all files
  3. After that is merged, open a new version of this PR

<!-- <ul class="nav navbar-nav navbar-right">
<li>
<a href="#">Link</a>
Expand Down
214 changes: 118 additions & 96 deletions js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,110 @@ var OS_LIST = [];
var cmdList = [];
var OS_ARRAY_WITH_DATA = {};
CMD_PAGES_URL = "https://api.github.com/repos/tldr-pages/tldr/contents/pages/";

$(document).ready(function() {

CMD_PAGES_URL_BASE = "https://api.github.com/repos/tldr-pages/tldr/contents/pages/";
CMD_PAGES_LANGUAGE = "https://api.github.com/repos/tldr-pages/tldr/contents/";

function getCommands(ln = "en") {
OS_LIST.length = 0;
if (ln != "en") {
CMD_PAGES_URL = CMD_PAGES_URL_BASE.replace("/pages/", "/pages." + ln + "/");
} else {
CMD_PAGES_URL = CMD_PAGES_URL_BASE;
}
$("#osSection .jumbotron").remove();
$.ajax({
url: CMD_PAGES_URL,
success: function (data) {

jQuery.each( data, function( i, val ) {

jQuery.each(data, function (i, val) {
//console.log(OS_LIST[i].type);
if (val.type == "dir"){
//console.log(val.name);
OS_LIST.push(val);
if (val.type == "dir") {
//console.log(val.name);
OS_LIST.push(val);
}
//alert(data[i].name);
});
//alert(data[i].name);
});

//console.log(OS_LIST);


for (i = 0; i < OS_LIST.length; i++){
for (i = 0; i < OS_LIST.length; i++) {
os_name = OS_LIST[i].name;
template = "<div class='jumbotron'> <p id='osname_" + i + "'></p> <p id='osnameTags_" + i +"'></p> </div>"

template = "<div class='jumbotron'> <p id='osname_" + i + "'></p> <p id='osnameTags_" + i + "'></p> </div>";
$("#osSection").append(template);
$("#osname_" + i).html(os_name);
//console.log(os_name);
$.ajax({
url: CMD_PAGES_URL + os_name,
async: false,
success: function (data) {

tempHtml = "<div id='selector' class=''>";
temparr = [];
jQuery.each( data, function( j, val ) {
temparr.push(val.name);
tempHtml = tempHtml + "<button type=\"button\" class=\"btn active badge\" id=\"" + val.name + "\" onclick=\"javascript:SearchButtonClicked('" + val.name + "');\">" + val.name + "</button>"
jQuery.each(data, function (j, val) {
temparr.push(val.name);
tempHtml = tempHtml + '<button type="button" class="btn active badge" id="' + val.name + '" onclick="javascript:SearchButtonClicked(\'' + val.name + "');\">" + val.name + "</button>";
});

tempHtml = tempHtml + "</div>"
tempHtml = tempHtml + "</div>";

//$.sessionStorage(os_name, JSON.stringify(temparr));
OS_ARRAY_WITH_DATA[os_name] = temparr;
$("#osnameTags_" + i ).html(tempHtml);
$("#osnameTags_" + i).html(tempHtml);
tempHtml = "";
//alert(os_name + "----" + temparr);
//cmdList.splice(0, cmdList.length);
}
},
});
}
},
error: function (data) {
if( data.message ){
if (data.message) {
console.log(data.message);
}

// ajax error callback
},
}); // The function returns the product of p1 and p2
}

$(document).ready(function () {
getCommands("en");
var languageSelect = document.getElementById("language");
var languageOption = document.createElement("option");
languageOption.text = "en";
languageSelect.add(languageOption);
$.ajax({
url: CMD_PAGES_LANGUAGE,
success: function (data) {
jQuery.each(data, function (i, val) {
//console.log(OS_LIST[i].type);
if (val.type == "dir") {
if (val.name.split("pages.")[1]) {
var languageSelect = document.getElementById("language");
var languageOption = document.createElement("option");
languageOption.text = val.name.split("pages.")[1];
languageSelect.add(languageOption);
}
}
//alert(data[i].name);
});

//console.log(OS_LIST);
},
error: function (data) {
if (data.message) {
console.log(data.message);
}

// ajax error callback
},
});

SearchButtonClicked=function(cmdName) {
SearchButtonClicked = function (cmdName) {
//alert(cmdName);
$('#searchBox').val(cmdName.substring(0,cmdName.lastIndexOf('.')));
$('#searchButton').click();

}
$("#searchBox").val(cmdName.substring(0, cmdName.lastIndexOf(".")));
$("#searchButton").click();
};

Check=function(arr, str){
Check = function (arr, str) {
var i, j;
var totalmatches = 0;
for (i = 0; i < arr.length; i++) {
Expand All @@ -83,59 +119,62 @@ $(document).ready(function() {
} else {
return false;
}
}

};
});


$("#language").on("change", function (e) {
var languageSelect = document.getElementById("language");
getCommands(languageSelect.value);
});

$('#searchButton').on('click', function(e){
$("#searchButton").on("click", function (e) {
$("#cmdDetails").html("");

BASE_TLDR_API_URL = "https://api.github.com/repos/tldr-pages/tldr/contents/pages";
BASE_TLDR_API_URL = "https://api.github.com/repos/tldr-pages/tldr/contents/pages";
var languageSelect = document.getElementById("language");

e.preventDefault(); // prevent the default click action
//alert("hi");
cmdToSearch = $('#searchBox').val();
//alert(cmdName);
//console.log(OS_LIST);
cmdToSearch = $("#searchBox").val();
//alert(cmdName);
//console.log(OS_LIST);

// $.each(OS_ARRAY_WITH_DATA, function (index, value) {
// alert( index + ' : ' + value );
// });


for (i = 0; i < OS_LIST.length; i++){
if(Check(OS_ARRAY_WITH_DATA[OS_LIST[i].name], cmdToSearch +'.md')){
for (i = 0; i < OS_LIST.length; i++) {
if (Check(OS_ARRAY_WITH_DATA[OS_LIST[i].name], cmdToSearch + ".md")) {
//console.log(exitfromloop);
url = OS_LIST[i].url;
url = OS_LIST[i].url;
os_name = OS_LIST[i].name;

$.ajax({
url: (url).split('?')[0] + "/" + cmdToSearch +'.md',
success: function (data) {
//alert('response received');
console.log(Base64.decode(data.content));
$("#cmdDetails").html(markdown.toHTML(Base64.decode(data.content)));
if (languageSelect.value != "en") {
url = url.replace("/pages/", "/pages." + languageSelect.value + "/");
}
$.ajax({
url: url.split("?")[0] + "/" + cmdToSearch + ".md",
success: function (data) {
//alert('response received');
console.log(Base64.decode(data.content));
$("#cmdDetails").html(markdown.toHTML(Base64.decode(data.content)));
exitfromloop = true;
$("body").animate({ scrollTop: 0 }, "slow");
// ajax success callback
},
error: function (data) {
console.log('Command not found in -->' + os_name);
$("body").animate({scrollTop: 0}, "slow");
// ajax success callback
},
error: function (data) {
console.log("Command not found in -->" + os_name);
$("#cmdDetails").html(data.message);
$("body").animate({ scrollTop: 0 }, "slow");
// ajax error callback
}
});
}
else{
$("body").animate({scrollTop: 0}, "slow");
// ajax error callback
},
});
} else {
$("#cmdDetails").html("Command help not found... Please select from the tags below.");
$("body").animate({ scrollTop: 0 }, "slow");
$("body").animate({scrollTop: 0}, "slow");
}
}
});


/**
*
* Base64 encode / decode
Expand All @@ -144,20 +183,18 @@ $('#searchButton').on('click', function(e){
**/

var Base64 = {

// private property
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

// public method for encoding
encode : function (input) {
encode: function (input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;

input = Base64._utf8_encode(input);

while (i < input.length) {

chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
Expand All @@ -173,17 +210,14 @@ var Base64 = {
enc4 = 64;
}

output = output +
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
}

return output;
},

// public method for decoding
decode : function (input) {
decode: function (input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
Expand All @@ -192,7 +226,6 @@ var Base64 = {
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

while (i < input.length) {

enc1 = this._keyStr.indexOf(input.charAt(i++));
enc2 = this._keyStr.indexOf(input.charAt(i++));
enc3 = this._keyStr.indexOf(input.charAt(i++));
Expand All @@ -210,71 +243,60 @@ var Base64 = {
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}

}

output = Base64._utf8_decode(output);

return output;

},

// private method for UTF-8 encoding
_utf8_encode : function (string) {
string = string.replace(/\r\n/g,"\n");
_utf8_encode: function (string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";

for (var n = 0; n < string.length; n++) {

var c = string.charCodeAt(n);

if (c < 128) {
utftext += String.fromCharCode(c);
}
else if((c > 127) && (c < 2048)) {
} else if (c > 127 && c < 2048) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
} else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}

}

return utftext;
},

// private method for UTF-8 decoding
_utf8_decode : function (utftext) {
_utf8_decode: function (utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;

while ( i < utftext.length ) {
var c = (c1 = c2 = 0);

while (i < utftext.length) {
c = utftext.charCodeAt(i);

if (c < 128) {
string += String.fromCharCode(c);
i++;
}
else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1);
} else if (c > 191 && c < 224) {
c2 = utftext.charCodeAt(i + 1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
}
else {
c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2);
} else {
c2 = utftext.charCodeAt(i + 1);
c3 = utftext.charCodeAt(i + 2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}

}

return string;
}

}
},
};