Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
feat: allow width and height to be modified
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Coe committed Jun 2, 2016
1 parent 89e95ed commit 8f535b1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion annotation.mustache
Expand Up @@ -9,7 +9,7 @@
{{#hasKey this "href"}}
<a href="{{{href}}}" style="border: none;text-decoration: none;"><img src="{{{url}}}" alt="{{text}}" {{#if fullSize}}style="height:auto;width:100%;"{{/if}} /></a>
{{else}}
<img src="{{{url}}}" alt="{{text}}" {{#if fullSize}}style="height:auto;width:100%;"{{/if}} />
<img src="{{{url}}}" alt="{{text}}" {{#if width}}style="height:{{height}};width:{{width}};"{{/if}} />
{{/hasKey}}
{{/each}}
{{/hasKey}}
Expand Down
8 changes: 4 additions & 4 deletions index.js
Expand Up @@ -10,20 +10,20 @@ function AnnotationPoller (opts) {
this.pkg = opts.pkg // what package should we load annotations for?
this.endpoint = '/api/v1/annotations/' + this.pkg
this.annotations = {}
this.template = Handlebars.templates['annotation.mustache']
this.template = global.Handlebars.templates['annotation.mustache']
this.addonSelector = '#npm-addon-box'
}

AnnotationPoller.prototype._installExtensions = function () {
Handlebars.registerHelper('hasKey', function (obj, key, options) {
global.Handlebars.registerHelper('hasKey', function (obj, key, options) {
if (typeof obj === 'object' && obj[key]) {
return options.fn(this)
} else {
return options.inverse(this)
}
})

Handlebars.registerHelper('isArray', function (obj, options) {
global.Handlebars.registerHelper('isArray', function (obj, options) {
if ($.isArray(obj)) {
return options.fn(this)
} else {
Expand Down Expand Up @@ -123,7 +123,7 @@ AnnotationPoller.prototype._applyReplacements = function (obj) {
if (!$.isArray(row.image)) {
row.image = [row.image]
}
row.image.forEach(function(img) {
row.image.forEach(function (img) {
if (img.url) img.url = _this._escape(img.url)
if (img.href) img.href = _this._escape(img.href)
})
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"build": "handlebars annotation.mustache -f annotation.js",
"pretest": "npm run build",
"pretest": "npm run build; standard",
"prepublish": "npm run build",
"test": "nyc mocha --timeout=10000 test.js",
"coverage": "nyc report --reporter=text-lcov | coveralls",
Expand Down Expand Up @@ -42,8 +42,8 @@
"handlebars": "^4.0.5",
"jquery": "^2.2.2"
},
"ignore": {
"ignore": [
"nyc": {
"exclude": [
"annotation.js"
]
},
Expand Down
29 changes: 15 additions & 14 deletions test.js
Expand Up @@ -78,7 +78,7 @@ describe('annotation-poller', function () {
$.mockjax({
url: endpoint,
status: 500,
responseText: "ENOGOOD"
responseText: 'ENOGOOD'
})

var poller = annotationPoller({pollInterval: 50, pkg: pkg})
Expand Down Expand Up @@ -266,8 +266,8 @@ describe('annotation-poller', function () {

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);
$('.addon-container:last > li > a').length.should.be.equal(0)
$('.addon-container:last > li > img').length.should.be.equal(1)
poller.stop()
return done()
})
Expand All @@ -292,8 +292,8 @@ describe('annotation-poller', function () {

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);
$('.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()
})
Expand Down Expand Up @@ -325,18 +325,18 @@ describe('annotation-poller', function () {

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);
$('.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()
})
})

it('renders fullsize images', function (done) {
it('respects width and height if provided', function (done) {
$.mockjax({
url: endpoint,
url: endpoint,
responseText: [{
id: 'test-fullsize-images',
name: 'fullsize images',
Expand All @@ -345,16 +345,17 @@ describe('annotation-poller', function () {
image: {
url: 'http://www.example.com/img1.png',
text: 'my awesome image',
fullSize: true
width: '100%',
height: 'auto'
}
}]
}]
})

var poller = annotationPoller({pollInterval: 50, pkg: pkg})
poller.start(function () {
$('.addon-container:last > li > img').length.should.be.equal(1);
$('.addon-container:last > li > img').css('width').should.be.equal('100%');
$('.addon-container:last > li > img').length.should.be.equal(1)
$('.addon-container:last > li > img').css('width').should.be.equal('100%')
poller.stop()
return done()
})
Expand Down

0 comments on commit 8f535b1

Please sign in to comment.