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="lichess_widgets.css" />
<link rel="stylesheet" href="dark.css" /> <link rel="stylesheet" href="dark.css" />
<link rel="stylesheet" href="light.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> <script src="lichess_widgets.js"></script>
<style> <style>
html, body { html, body {
@ -67,7 +66,6 @@
<blockcode> <blockcode>
&lt;link rel="stylesheet" href="http://rubenwardy.github.io/lichess_widgets/lichess_widgets.css" /&gt;<br /> &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;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 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; &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() { var lichess_widgets = (function() {
function make_online(id) { var callback_serials = 0;
$(id).addClass("lichess_online"); function fetchJson(url, callback) {
$(id + " > img").attr("src", "http://rubenwardy.github.io/lichess_widgets/lichess_online.png"); 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) { function capitalize(inp) {
return inp.charAt(0).toUpperCase() + inp.slice(1); return inp.charAt(0).toUpperCase() + inp.slice(1);
} }
var serial = 0; var serial = 0;
return { return {
callbacks: {},
profile: function(theme, author, text) { profile: function(theme, author, text) {
serial++; serial++;
var id = 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 += "<img src=\"http://lichess1.org/assets/images/favicon-32-white.png\" alt=\"lichess\" />"
tmp += "<span>" + text + "</span></a>"; tmp += "<span>" + text + "</span></a>";
document.write(tmp); document.write(tmp);
$.ajax({ fetchJson("http://en.lichess.org/api/user/" + author,function(data) {
url: "http://en.lichess.org/api/user/" + author, if (data.online)
dataType: "jsonp", make_online("lichess_widget_" + id);
jsonp: "callback",
success: function(data) {
if (data.online)
make_online("#lichess_widget_" + id);
}
}); });
}, },
profile_scores: function(theme, author, text) { 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 += "<img src=\"http://lichess1.org/assets/images/favicon-32-white.png\" alt=\"lichess\" />"
tmp += "<span>" + text + "</span></a>"; tmp += "<span>" + text + "</span></a>";
document.write(tmp); document.write(tmp);
$.ajax({ fetchJson("http://en.lichess.org/api/user/" + author, function(data) {
url: "http://en.lichess.org/api/user/" + author, if (data.online)
dataType: "jsonp", make_online("lichess_widget_" + id);
jsonp: "callback",
success: function(data) {
if (data.online)
make_online("#lichess_widget_" + id);
if (text && text != "") if (text && text != "")
text = text + " | "; text = text + " | ";
$("#lichess_widget_" + id + " > span").html(text + "Classical <b>" + data.perfs.classical.rating + "</b> | Bullet <b>" + data.perfs.bullet.rating + "</b>");
} 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) { profile_big: function(theme, author, text) {
@ -57,28 +64,24 @@ var lichess_widgets = (function() {
var id = serial; var id = serial;
if (text == undefined) if (text == undefined)
text = author + " on Lichess"; 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 += "<img src=\"http://lichess1.org/assets/images/favicon-32-white.png\" alt=\"lichess\" />" + text + "<hr />"
tmp += "<span></span></a>"; tmp += "<span></span></a>";
document.write(tmp); document.write(tmp);
$.ajax({ fetchJson("http://en.lichess.org/api/user/" + author, function(data) {
url: "http://en.lichess.org/api/user/" + author, if (data.online)
dataType: "jsonp", make_online("lichess_widget_" + id);
jsonp: "callback",
success: function(data) {
if (data.online)
make_online("#lichess_widget_" + id);
var res = ""; var res = "";
for (var key in data.perfs) { for (var key in data.perfs) {
if (data.perfs.hasOwnProperty(key) && data.perfs[key].games > 0) { if (data.perfs.hasOwnProperty(key) && data.perfs[key].games > 0) {
if (res!="") if (res!="")
res += "<br />"; res += "<br />";
res += capitalize(key) + " <b>" + data.perfs[key].rating + "</b> / " + data.perfs[key].games + " Games"; 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;
}); });
} }
} }