Skip to content

Commit

Permalink
image: a11y-attributes + content + examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mishanga committed Dec 12, 2014
1 parent 5012c0a commit d4a34b4
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 36 deletions.
29 changes: 18 additions & 11 deletions common.blocks/image/image.bemhtml
@@ -1,13 +1,20 @@
block('image')(
tag()('img'),
attrs()(function() {
var ctx = this.ctx;
return {
src : ctx.url,
width : ctx.width,
height : ctx.height,
alt : ctx.alt,
title : ctx.title
};
})
attrs()({ role : 'img' }),

tag()('span'),

match(function() { return typeof this.ctx.content === 'undefined'; })(
tag()('img'),
attrs()(function() {
var ctx = this.ctx;
return this.extend(applyNext(),
{
src : ctx.url,
width : ctx.width,
height : ctx.height,
alt : ctx.alt,
title : ctx.title
});
})
)
);
24 changes: 15 additions & 9 deletions common.blocks/image/image.bh.js
@@ -1,13 +1,19 @@
module.exports = function(bh) {
bh.match('image', function(ctx, json) {
ctx
.tag('img')
.attrs({
src : json.url,
width : json.width,
height : json.height,
alt : json.alt,
title : json.title
});
ctx.attr('role', 'img');

if(typeof json.content !== 'undefined') {
ctx.tag('span');
} else {
ctx
.tag('img')
.attrs({
src : json.url,
width : json.width,
height : json.height,
alt : json.alt,
title : json.title
});
}
});
};
46 changes: 31 additions & 15 deletions common.blocks/image/image.tests/simple.bemjson.js
Expand Up @@ -9,25 +9,41 @@
{ tag : 'h2', content : 'image' },
{
block : 'test',
content : {
block : 'image',
url : '../../../test.blocks/icon/_action/download.svg',
alt : 'Download',
title : 'Download image'
}
content : [
'Source: ',
{
block : 'image',
url : '../../../test.blocks/image/github.svg',
alt : 'Download',
title : 'Download image'
}
]
},
{ tag : 'br' },
{ tag : 'h3', content : 'with specified size' },
{
block : 'test',
content : {
block : 'image',
url : '../../../test.blocks/icon/_action/download.svg',
width : 50,
height : 50,
alt : 'Download',
title : 'Download image'
}
content : [
'Specified size: ',
{
block : 'image',
url : '../../../test.blocks/image/github.svg',
width : 53,
height : 24,
alt : 'GitHub',
title : 'GitHub logo'
}
]
},
{ tag : 'br' },
{
block : 'test',
content : [
'Inline content: ',
{
block : 'image',
content : '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path d="M1 13v2h14v-2h-14zm13-7h-3v-5h-6v5.031l-3-.031 6 6 6-6z"/></svg>'
}
]
}
]
});
2 changes: 1 addition & 1 deletion common.blocks/image/image.tmpl-specs/10-simple.html
@@ -1 +1 @@
<img class="image" src="#" width="16" height="16" alt="Download" title="Download image"/>
<img class="image" role="img" src="#" width="16" height="16" alt="Download" title="Download image"/>
6 changes: 6 additions & 0 deletions common.blocks/image/image.tmpl-specs/20-content.bemjson.js
@@ -0,0 +1,6 @@
({
block : 'image',
width : '16',
height : '16',
content : '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"></svg>'
})
1 change: 1 addition & 0 deletions common.blocks/image/image.tmpl-specs/20-content.html
@@ -0,0 +1 @@
<div class="image" role="img"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"></svg></div>
1 change: 1 addition & 0 deletions test.blocks/image/github.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d4a34b4

Please sign in to comment.