Skip to content

Instantly share code, notes, and snippets.

@kaineer
Forked from Luardi/picture-element.js
Last active September 14, 2016 04:29
Show Gist options
  • Save kaineer/3e49c32fd79b6339787130c56f6caec4 to your computer and use it in GitHub Desktop.
Save kaineer/3e49c32fd79b6339787130c56f6caec4 to your computer and use it in GitHub Desktop.
'use strict';
var template = document.querySelector('template');
var templateContainer = 'content' in template ? template.content : template;
var newGallery = require('./gallery');
var IMAGE_LOAD_TIMEOUT = 10000;
var Picture = module.exports = function(picture, i) {
this.data = picture;
this.index = i;
this.createPictureElement();
};
Picture.prototype.createPictureElement = function() {
this.element = templateContainer.querySelector('.picture').cloneNode(true);
this.comments = this.element.querySelector('.picture-comments');
this.comments.textContent = this.data.comments;
// ...
this.image = new Image(182, 182);
// ...
this.image.onclick = this.onImageClick.bind(this);
};
Picture.prototype.onImageClick = function(event) {
event.preventDefault();
newGallery.show(this.index);
};
Picture.prototype.remove = function() {
this.image.onclick = null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment