diff --git a/annotation.mustache b/annotation.mustache index 26af736..1630e9f 100644 --- a/annotation.mustache +++ b/annotation.mustache @@ -4,16 +4,23 @@ {{#each rows}}
  • {{#each this}} - {{#isArray this}} + {{#hasKey this "_image"}} {{#each this}} - {{text}}{{#unless @last}},{{/unless}} + {{#hasKey this "href"}} + {{text}} + {{else}} + {{text}} + {{/hasKey}} {{/each}} - {{/isArray}} - {{#hasKey this "_image"}} - {{text}} {{/hasKey}} {{#hasKey this "_link"}} - {{text}} + {{#isArray this}} + {{#each this}} + {{text}}{{#unless @last}},{{/unless}} + {{/each}} + {{else}} + {{text}} + {{/isArray}} {{/hasKey}} {{#hasKey this "_text"}} {{{text}}} diff --git a/index.js b/index.js index 682285d..511e156 100644 --- a/index.js +++ b/index.js @@ -120,7 +120,13 @@ AnnotationPoller.prototype._applyReplacements = function (obj) { // escape any HTML in image links. if (row.image) { - if (row.image.url) row.image.url = _this._escape(row.image.url) + if (!$.isArray(row.image)) { + row.image = [row.image] + } + row.image.forEach(function(img) { + if (img.url) img.url = _this._escape(img.url) + if (img.href) img.href = _this._escape(img.href) + }) } // flatten the row object into an ordered diff --git a/test.js b/test.js index 18df599..bcfefd6 100644 --- a/test.js +++ b/test.js @@ -247,4 +247,90 @@ describe('annotation-poller', function () { }, 1000) }) }) + + it('renders non-linked images', function (done) { + $.mockjax({ + url: endpoint, + responseText: [{ + id: 'test-image-render', + name: 'image render test integration', + fingerprint: 'tir', + rows: [{ + image: { + url: 'http://www.example.com/img.png', + text: 'my awesome image link' + } + }] + }] + }) + + var poller = annotationPoller({pollInterval: 50, pkg: pkg}) + poller.start(function () { + $('.addon-container:last > li > a').length.should.be.equal(0); + $('.addon-container:last > li > img').length.should.be.equal(1); + poller.stop() + return done() + }) + }) + + it('renders image links', function (done) { + $.mockjax({ + url: endpoint, + responseText: [{ + id: 'test-image-link', + name: 'image link test integration', + fingerprint: 'til', + rows: [{ + image: { + url: 'http://www.example.com/img.png', + text: 'my awesome image link', + href: 'http://www.example.com/link' + } + }] + }] + }) + + var poller = annotationPoller({pollInterval: 50, pkg: pkg}) + poller.start(function () { + $('.addon-container:last > li > a').length.should.be.equal(1); + $('.addon-container:last > li > a > img').length.should.be.equal(1); + poller.stop() + return done() + }) + }) + + it('renders multiple images and image links', function (done) { + $.mockjax({ + url: endpoint, + responseText: [{ + id: 'test-multi-mixed-image-links', + name: 'mixed multi image links', + fingerprint: 'tmmil', + rows: [{ + image: [{ + url: 'http://www.example.com/img1.png', + text: 'my awesome image link', + href: 'http://www.example.com/link1' + }, { + url: 'http://www.example.com/img2.png', + text: 'my awesome image link' + }, { + url: 'http://www.example.com/img3.png', + text: 'my awesome image link', + href: 'http://www.example.com/link3' + }] + }] + }] + }) + + var poller = annotationPoller({pollInterval: 50, pkg: pkg}) + poller.start(function () { + $('.addon-container:last > li > a').length.should.be.equal(2); + $('.addon-container:last > li > a > img').length.should.be.equal(2); + $('.addon-container:last > li > img').length.should.be.equal(1); + $('.addon-container:last > li img').length.should.be.equal(3); + poller.stop() + return done() + }) + }) })