summaryrefslogtreecommitdiff
path: root/data/js
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2015-11-01 13:46:55 +0100
committerYorhel <git@yorhel.nl>2015-11-01 13:46:55 +0100
commit9ab45fccbf8a3370ee0b8afaaae42b7b8c9ad162 (patch)
tree6fb00dee56195e34c704475819f7a60d710dfc47 /data/js
parent8c9cfe238e565088b37d256eb461a01919ef9968 (diff)
Image viewer: Use HTML5 data- attribute instead of 'rel' for data
The possible values of the rel attribute is fixed, it's not supposed to be a free-form field.
Diffstat (limited to 'data/js')
-rw-r--r--data/js/iv.js22
-rw-r--r--data/js/lib.js2
-rw-r--r--data/js/vnscr.js2
3 files changed, 13 insertions, 13 deletions
diff --git a/data/js/iv.js b/data/js/iv.js
index 75754a90..f1593d22 100644
--- a/data/js/iv.js
+++ b/data/js/iv.js
@@ -1,14 +1,14 @@
/* Simple image viewer widget. Usage:
*
- * <a href="full_image.jpg" rel="iv:{width}x{height}:{category}">..</a>
+ * <a href="full_image.jpg" data-iv="{width}x{height}:{category}">..</a>
*
* Clicking on the above link will cause the image viewer to open
* full_image.jpg. The {category} part can be empty or absent. If it is not
* empty, next/previous links will show up to point to the other images within
* the same category.
*
- * ivInit() should be called when links with "iv:" tags are dynamically added
- * or removed from the DOM.
+ * ivInit() should be called when links with "data-iv" attributes are
+ * dynamically added or removed from the DOM.
*/
// Cache of image categories and the list of associated link objects. Used to
@@ -21,10 +21,10 @@ function init() {
var l = byName('a');
for(var i=0;i<l.length;i++) {
var o = l[i];
- if(o.rel.substr(0,3) == 'iv:' && o.id != 'ivprev' && o.id != 'ivnext') {
+ if(o.getAttribute('data-iv') && o.id != 'ivprev' && o.id != 'ivnext') {
n++;
o.onclick = show;
- var cat = o.rel.split(':')[2];
+ var cat = o.getAttribute('data-iv').split(':')[1];
if(cat) {
if(!cats[cat])
cats[cat] = [];
@@ -60,23 +60,23 @@ function fixnav(lnk, cat, i, dir) {
var a = cat ? findnav(cat, i, dir) : 0;
lnk.style.visibility = a ? 'visible' : 'hidden';
lnk.href = a ? a.href : '#';
- lnk.rel = a ? a.rel : '';
lnk.iv_i = a ? a.iv_i : 0;
+ lnk.setAttribute('data-iv', a ? a.getAttribute('data-iv') : '');
}
function show() {
var u = this.href;
- var opt = this.rel.split(':');
+ var opt = this.getAttribute('data-iv').split(':');
var idx = this.iv_i;
var view = byId('iv_view');
var full = byId('ivfull');
- fixnav(byId('ivprev'), opt[2], idx, -1);
- fixnav(byId('ivnext'), opt[2], idx, 1);
+ fixnav(byId('ivprev'), opt[1], idx, -1);
+ fixnav(byId('ivnext'), opt[1], idx, 1);
// calculate dimensions
- var w = Math.floor(opt[1].split('x')[0]);
- var h = Math.floor(opt[1].split('x')[1]);
+ var w = Math.floor(opt[0].split('x')[0]);
+ var h = Math.floor(opt[0].split('x')[1]);
var ww = typeof(window.innerWidth) == 'number' ? window.innerWidth : document.documentElement.clientWidth;
var wh = typeof(window.innerHeight) == 'number' ? window.innerHeight : document.documentElement.clientHeight;
var st = typeof(window.pageYOffset) == 'number' ? window.pageYOffset : document.body && document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
diff --git a/data/js/lib.js b/data/js/lib.js
index 675f2baa..7d0f6b18 100644
--- a/data/js/lib.js
+++ b/data/js/lib.js
@@ -83,7 +83,7 @@ window.tag = function() {
continue;
if(typeof arguments[i] == 'object' && !arguments[i].appendChild) {
for(attr in arguments[i]) {
- if(attr == 'style')
+ if(attr == 'style' || attr.match(/^data-/))
el.setAttribute(attr, arguments[i][attr]);
else
el[ attr == 'class' ? 'className' : attr == 'for' ? 'htmlFor' : attr ] = arguments[i][attr];
diff --git a/data/js/vnscr.js b/data/js/vnscr.js
index acde013d..08d3ffae 100644
--- a/data/js/vnscr.js
+++ b/data/js/vnscr.js
@@ -98,7 +98,7 @@ function loaded(tr, id, width, height) {
tr.scr_loading = 0;
setContent(byName(tr, 'td')[0],
- tag('a', {href: URL(tr.scr_id, 'f'), rel:'iv:'+dim+':edit'},
+ tag('a', {href: URL(tr.scr_id, 'f'), 'data-iv':dim+':edit'},
tag('img', {src: URL(tr.scr_id, 't')})
)
);