forked from weso/YASHE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
74 lines (68 loc) · 2.92 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var $ = jQuery = require("jquery");
require("../node_modules/bootstrap-sass/assets/javascripts/bootstrap/affix.js");
require("../node_modules/bootstrap-sass/assets/javascripts/bootstrap/scrollspy.js");
$(document).ready(function() {
//get the latest hosted version
if ($("#cdnDownload").length > 0) {
var name = "yashe";
//only draw when we've got some place to print this info (might not be on all pages where we include this js file)
$.get("https://data.jsdelivr.com/v1/package/npm/" + name, function(data) {
var version = data.tags.latest;
if (version) {
$("#" + name + "Css").text(
"<link href='//cdn.jsdelivr.net/npm/" +
name +
"@" +
version +
"/dist/" +
name +
".min.css' rel='stylesheet' type='text/css'/>"
);
$("#" + name + "JsBundled").text(
"<script src='//cdn.jsdelivr.net/npm/" + name + "@" + version + "/dist/" + name + ".bundled.min.js'></script" + ">"
);
} else {
console.log("failed accessing jsdelivr api");
$("#cdnDownload").hide();
}
}).fail(function() {
console.log("failed accessing jsdelivr api");
$("#cdnDownload").hide();
});
}
var gistContainer = $("#gistContainer");
if (gistContainer.length > 0) {
$.get("https://api.github.com/users/mistermboy/gists", function(data) {
var processLabel = function(origLabel) {
var label = origLabel.replace("#YASHE", "YASHE");
var splitted = label.split(" ");
if (splitted.length > 0) {
if ((splitted[0].indexOf("YASHE") == 0 || splitted[0].indexOf("YASR") == 0) && splitted[0].slice(-1) == ":") {
//we want to change "#YASQE: some gist" into "some gist". So, remove the first item
return splitted.splice(1).join(" ");
} else {
return splitted.join(" ");
}
} else {
return label;
}
};
data.forEach(function(gist) {
if (gist.description.indexOf("#YASHE") >= 0) {
var gistDiv = $("<div>").addClass("gist").addClass("well").appendTo(gistContainer);
$("<h4>").text(processLabel(gist.description)).appendTo(gistDiv);
var description = $("<p>").appendTo(gistDiv);
$.get(gist.url, function(gistFile) {
description.text(gistFile.files["YASHE.md"].content);
});
var buttonContainer = $("<p>").appendTo(gistDiv);
$(
"<a style='margin-left: 4px;' target='_blank' class='btn btn-default btn-sm' href='#' role='button'>Code <img class='pull-right gistIcon' src='imgs/blacktocat_black.png'></a>"
)
.attr("href", gist["html_url"])
.appendTo(buttonContainer);
}
});
});
}
});