Remove jQuery

master
rubenwardy 2014-11-28 17:24:28 +00:00
parent b4e42855f4
commit ffa4778847
2 changed files with 41 additions and 40 deletions

View File

@ -6,7 +6,6 @@
<link rel="stylesheet" href="lichess_widgets.css" />
<link rel="stylesheet" href="dark.css" />
<link rel="stylesheet" href="light.css" />
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="lichess_widgets.js"></script>
<style>
html, body {
@ -67,7 +66,6 @@
<blockcode>
&lt;link rel="stylesheet" href="http://rubenwardy.github.io/lichess_widgets/lichess_widgets.css" /&gt;<br />
&lt;script src="http://code.jquery.com/jquery-1.11.0.min.js"&gt;&lt;/script&gt;<br />
&lt;script src="http://rubenwardy.github.io/lichess_widgets/lichess_widgets.js"&gt;&lt;/script&gt;<br />
&lt;!-- For the light theme --&gt; &lt;link rel="stylesheet" href="http://rubenwardy.github.io/lichess_widgets/light.css" /&gt; <br />
&lt;!-- For the dark theme --&gt; &lt;link rel="stylesheet" href="http://rubenwardy.github.io/lichess_widgets/dark.css" /&gt;

View File

@ -1,13 +1,26 @@
var lichess_widgets = (function() {
function make_online(id) {
$(id).addClass("lichess_online");
$(id + " > img").attr("src", "http://rubenwardy.github.io/lichess_widgets/lichess_online.png");
var callback_serials = 0;
function fetchJson(url, callback) {
callback_serials++;
var script = document.createElement('script');
lichess_widgets.callbacks["cb" + callback_serials] = callback;
script.src = url + "?callback=lichess_widgets.callbacks.cb" + callback_serials;
document.body.appendChild(script);
}
function make_online(id) {
var ele = document.getElementById(id);
ele.className = ele.className + " lichess_online";
ele.getElementsByTagName('img')[0].src = "http://rubenwardy.github.io/lichess_widgets/lichess_online.png";
}
function capitalize(inp) {
return inp.charAt(0).toUpperCase() + inp.slice(1);
}
var serial = 0;
return {
callbacks: {},
profile: function(theme, author, text) {
serial++;
var id = serial;
@ -18,14 +31,9 @@ var lichess_widgets = (function() {
tmp += "<img src=\"http://lichess1.org/assets/images/favicon-32-white.png\" alt=\"lichess\" />"
tmp += "<span>" + text + "</span></a>";
document.write(tmp);
$.ajax({
url: "http://en.lichess.org/api/user/" + author,
dataType: "jsonp",
jsonp: "callback",
success: function(data) {
if (data.online)
make_online("#lichess_widget_" + id);
}
fetchJson("http://en.lichess.org/api/user/" + author,function(data) {
if (data.online)
make_online("lichess_widget_" + id);
});
},
profile_scores: function(theme, author, text) {
@ -38,18 +46,17 @@ var lichess_widgets = (function() {
tmp += "<img src=\"http://lichess1.org/assets/images/favicon-32-white.png\" alt=\"lichess\" />"
tmp += "<span>" + text + "</span></a>";
document.write(tmp);
$.ajax({
url: "http://en.lichess.org/api/user/" + author,
dataType: "jsonp",
jsonp: "callback",
success: function(data) {
if (data.online)
make_online("#lichess_widget_" + id);
fetchJson("http://en.lichess.org/api/user/" + author, function(data) {
if (data.online)
make_online("lichess_widget_" + id);
if (text && text != "")
text = text + " | ";
$("#lichess_widget_" + id + " > span").html(text + "Classical <b>" + data.perfs.classical.rating + "</b> | Bullet <b>" + data.perfs.bullet.rating + "</b>");
}
if (text && text != "")
text = text + " | ";
var res = text + "Classical <b>" + data.perfs.classical.rating;
res += "</b> | Bullet <b>" + data.perfs.bullet.rating + "</b>";
document.getElementById("lichess_widget_" + id).getElementsByTagName('span')[0].innerHTML = res;
});
},
profile_big: function(theme, author, text) {
@ -57,28 +64,24 @@ var lichess_widgets = (function() {
var id = serial;
if (text == undefined)
text = author + " on Lichess";
var tmp = "<a id=\"lichess_widget_" + id + "\" class=\"lichess_widget lichess_theme_" + theme + " lichess_long\" href=\"http://lichess.org/@/" + author + "\">";
var tmp = "<a id=\"lichess_widget_" + id + "\" class=\"lichess_widget lichess_theme_" + theme;
tmp += " lichess_long\" href=\"http://lichess.org/@/" + author + "\">";
tmp += "<img src=\"http://lichess1.org/assets/images/favicon-32-white.png\" alt=\"lichess\" />" + text + "<hr />"
tmp += "<span></span></a>";
document.write(tmp);
$.ajax({
url: "http://en.lichess.org/api/user/" + author,
dataType: "jsonp",
jsonp: "callback",
success: function(data) {
if (data.online)
make_online("#lichess_widget_" + id);
fetchJson("http://en.lichess.org/api/user/" + author, function(data) {
if (data.online)
make_online("lichess_widget_" + id);
var res = "";
for (var key in data.perfs) {
if (data.perfs.hasOwnProperty(key) && data.perfs[key].games > 0) {
if (res!="")
res += "<br />";
res += capitalize(key) + " <b>" + data.perfs[key].rating + "</b> / " + data.perfs[key].games + " Games";
}
var res = "";
for (var key in data.perfs) {
if (data.perfs.hasOwnProperty(key) && data.perfs[key].games > 0) {
if (res!="")
res += "<br />";
res += capitalize(key) + " <b>" + data.perfs[key].rating + "</b> / " + data.perfs[key].games + " Games";
}
$("#lichess_widget_" + id + " > span").html(res);
}
document.getElementById("lichess_widget_" + id).getElementsByTagName('span')[0].innerHTML = res;
});
}
}