* snippet now in a separate JS file - compiled and uglified with the other assets * popup gets centered in opening browser window * publisher gets pre-filled with markdown-styled content
45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later
|
|
|
|
var bookmarklet = function(url, width, height, opts) {
|
|
// calculate popup dimensions & placement
|
|
var dim = function() {
|
|
var w = window,
|
|
winTop = (w.screenTop ? w.screenTop : w.screenY),
|
|
winLeft = (w.screenLeft ? w.screenLeft : w.screenX),
|
|
top = (winTop + (w.innerHeight / 2) - (height / 2)),
|
|
left = (winLeft + (w.innerWidth / 2) - (width / 2));
|
|
return "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left;
|
|
};
|
|
|
|
// prepare url parameters
|
|
var params = function() {
|
|
var w = window,
|
|
d = document,
|
|
href = w.location.href,
|
|
title = d.title,
|
|
sel = w.getSelection ? w.getSelection() :
|
|
d.getSelection ? d.getSelection() :
|
|
d.selection.createRange().text,
|
|
notes = sel.toString();
|
|
return "url=" + encodeURIComponent(href) +
|
|
"&title=" + encodeURIComponent(title) +
|
|
"¬es=" + encodeURIComponent(notes);
|
|
};
|
|
|
|
// popup (or redirect) action
|
|
var act = function() {
|
|
var popupOpts = (opts || "location=yes,links=no,scrollbars=yes,toolbar=no"),
|
|
jumpUrl = url + "?jump=yes";
|
|
|
|
(window.open(url + "?" + params(), "diaspora_bookmarklet", popupOpts + "," + dim()) ||
|
|
(window.location.href = jumpUrl + "&" + params()));
|
|
};
|
|
|
|
if( /Firefox/.test(navigator.userAgent) ) {
|
|
setTimeout(act, 0);
|
|
} else {
|
|
act();
|
|
}
|
|
};
|
|
|
|
// @license-end
|