Skip to content

Instantly share code, notes, and snippets.

@gagarine
Created September 6, 2011 21:06
Show Gist options
  • Save gagarine/1198968 to your computer and use it in GitHub Desktop.
Save gagarine/1198968 to your computer and use it in GitHub Desktop.
bookmarklet for sankore
if (typeof jQuery == 'undefined') {
var jQ = document.createElement('script');
jQ.type = 'text/javascript';
jQ.onload = runthis;
jQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
document.body.appendChild(jQ);
} else {
runthis();
}
function runthis() {
var iframeSrc = 'http://planete.sankore.org/xwiki/bin/view/Main/AddResources?xpage=popup&url=';
var url = location.href;
var title = ((document.title) ? document.title : document.location.host);
var error = false;
if ($("#frame").length === 0) {
if (url === "") {
alert("URL invalide");
error = true;
}
if (!error) {
$("body").append("\
<div id='bookmarklet'>\
<div id='frame_veil' style=''>\
<p>Loading...</p>\
</div>\
<iframe src='" + iframeSrc + url + "' onload=\"$('#bookmarklet iframe').fadeIn(300);\">Enable iFrames.</iframe>\
<style type='text/css'>\
#bookmarklet { display:none; position: fixed; width: 100%; height: 100%; top: 0; left: 0; background-color: rgba(255,255,255,.7); cursor: pointer; z-index: 900; }\
#frame_veil p { color: #666; font: bold 20px/20px Helvetica, sans-serif; position: absolute; top: 50%; left: 50%; width: 10em; margin: -10px auto 0 -5em; text-align: center; }\
#bookmarklet iframe { display: none; position: fixed; top: 10%; left: 10%; width: 760px; height: 90%; z-index: 999; border: 10px solid rgba(0,0,0,.5); margin:0 auto }\
</style>\
</div>");
$("#bookmarklet").fadeIn(100);
}
} else {
$("#bookmarklet").fadeOut(300);
setTimeout("$('#bookmarklet').remove()", 400);
}
$("#bookmarklet").click(function(event) {
$("#bookmarklet").fadeOut(300);
setTimeout("$('#bookmarklet').remove()", 400);
});
}
function getSelText() {
var s = '';
if (window.getSelection) {
s = window.getSelection();
} else if (document.getSelection) {
s = document.getSelection();
} else if (document.selection) {
s = document.selection.createRange().text;
}
return s;
}
<html>
<head>
<body>
<h1>Drag and drop this link</h1>
<a href="javascript:(function(){document.body.appendChild(document.createElement('script')).src='http://foo.bar/bookmarklet-planete.js';})();">Sankore bookmarklet</a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment