Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rik committed Jul 5, 2011
0 parents commit ae35eb0
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
A simple add-on that adds a link to the longdesc under images that provides one.

Maybe you want to look at this other extension for longdesc https://addons.mozilla.org/en-US/firefox/addon/longdesc/

The source code lives at https://github.com/Rik/longdesk

*Disclaimer:* I have no opinion on whether the longdesc attribute should or should not exist.
I'm just tired of having to look through the source code every time I want to see a friend's explanation of a picture.
This add-on has only been tested on http://www.nota-bene.org/Mise-en-abyme-a-carreaux

Also, this is my first add-on ever so…
30 changes: 30 additions & 0 deletions data/pagemod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(function () {
var imgs = document.querySelectorAll('img[longdesc]');

if (imgs.length == 0)
return;

self.postMessage('load-styles');
self.on('message', function (data) {
if (data.styles) {
var style = document.createElement('style');
style.appendChild(document.createTextNode(data.styles));
document.head.appendChild(style);
}
})

for (var i=0, il=imgs.length; i < il; i++) {
var img = imgs[i];

var a = document.createElement('a');
a.classList.add('longdesc-addon-link');
a.href = imgs[i].getAttribute('longdesc');
a.appendChild(document.createTextNode('Description'));

var top = img.offsetTop + img.height;
a.style.top = top + "px";
a.style.left = img.offsetLeft + "px";

img.parentNode.insertBefore(a, img.nextSibling);
}
})();
8 changes: 8 additions & 0 deletions data/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.longdesc-addon-link {
position: absolute;
color: black;
background: white;
border: 1px solid black;
border-top: 0;
border-radius: 0 0 5px 5px;
}
2 changes: 2 additions & 0 deletions doc/main.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The main module is a program that creates a widget. When a user clicks on
the widget, the program loads the mozilla.org website in a new tab.
16 changes: 16 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const pageMod = require("page-mod");
const data = require("self").data;

exports.main = function() {
pageMod.PageMod({
include: ["*"],
contentScriptFile: data.url('pagemod.js'),
onAttach: function onAttach(worker) {
worker.on('message', function(message) {
if (message == 'load-styles') {
worker.postMessage({styles: data.load('style.css')});
}
});
}
});
}
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "longdesk",
"license": "WTFPL http://sam.zoy.org/wtfpl/",
"author": "Anthony Ricaud <anthony@ricaud.me",
"version": "0.1",
"fullName": "longdesk",
"id": "jid1-KN9CeRzPwYe6Rw",
"description": "A simple add-on that adds a link to the longdesc under images that provides one."
}
32 changes: 32 additions & 0 deletions test/test-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const main = require("main");

exports.test_test_run = function(test) {
test.pass("Unit test running!");
};

exports.test_id = function(test) {
test.assert(require("self").id.length > 0);
};

exports.test_url = function(test) {
require("request").Request({
url: "http://www.mozilla.org/",
onComplete: function(response) {
test.assertEqual(response.statusText, "OK");
test.done();
}
}).get();
test.waitUntilDone(20000);
};

exports.test_open_tab = function(test) {
const tabs = require("tabs");
tabs.open({
url: "http://www.mozilla.org/",
onReady: function(tab) {
test.assertEqual(tab.url, "http://www.mozilla.org/");
test.done();
}
});
test.waitUntilDone(20000);
};

0 comments on commit ae35eb0

Please sign in to comment.