contract thumbnails in hover preview

... and don't clone the video element
This commit is contained in:
ccd0 2014-04-07 15:48:56 -07:00
parent e69d6b2e7c
commit deeba623a0
5 changed files with 87 additions and 17 deletions

View File

@ -1214,8 +1214,8 @@
return this.board.posts.rm(this);
};
Post.prototype.addClone = function(context) {
return new Clone(this, context);
Post.prototype.addClone = function(context, contractThumb) {
return new Clone(this, context, contractThumb);
};
Post.prototype.rmClone = function(index) {
@ -1235,8 +1235,8 @@
Clone = (function(_super) {
__extends(Clone, _super);
function Clone(origin, context) {
var file, info, inline, inlined, key, nodes, post, root, val, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3;
function Clone(origin, context, contractThumb) {
var file, info, inline, inlined, key, nodes, post, root, val, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3, _ref4;
this.origin = origin;
this.context = context;
_ref = ['ID', 'fullID', 'board', 'thread', 'info', 'quotes', 'isReply'];
@ -1245,7 +1245,7 @@
this[key] = origin[key];
}
nodes = origin.nodes;
root = nodes.root.cloneNode(true);
root = contractThumb ? this.cloneWithoutVideo(nodes.root) : nodes.root.cloneNode(true);
post = $('.post', root);
info = $('.postInfo', post);
this.nodes = {
@ -1305,6 +1305,13 @@
this.file.text = file.firstElementChild;
this.file.thumb = $('img[data-md5]', file);
this.file.fullImage = $('.full-image', file);
if (contractThumb) {
$.rmClass(this.nodes.root, 'expanded-image');
$.rmClass(this.file.thumb, 'expanding');
}
if ((_ref4 = this.file.fullImage) != null) {
_ref4.removeAttribute('id');
}
}
if (origin.isDead) {
this.isDead = true;
@ -1313,6 +1320,23 @@
root.dataset.clone = origin.clones.push(this) - 1;
}
Clone.prototype.cloneWithoutVideo = function(node) {
var child, clone, _i, _len, _ref;
if (node.tagName === 'VIDEO') {
return [];
} else if (node.nodeType === Node.ELEMENT_NODE && $('video', node)) {
clone = node.cloneNode(false);
_ref = node.childNodes;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
child = _ref[_i];
$.add(clone, this.cloneWithoutVideo(child));
}
return clone;
} else {
return node.cloneNode(true);
}
};
return Clone;
})(Post);
@ -3325,7 +3349,7 @@
if (!root.parentNode) {
return;
}
clone = post.addClone(context);
clone = post.addClone(context, $.hasClass(root, 'dialog'));
Main.callbackNodes(Clone, [clone]);
nodes = clone.nodes;
$.rmAll(nodes.root);

View File

@ -1251,8 +1251,8 @@
return this.board.posts.rm(this);
};
Post.prototype.addClone = function(context) {
return new Clone(this, context);
Post.prototype.addClone = function(context, contractThumb) {
return new Clone(this, context, contractThumb);
};
Post.prototype.rmClone = function(index) {
@ -1272,8 +1272,8 @@
Clone = (function(_super) {
__extends(Clone, _super);
function Clone(origin, context) {
var file, info, inline, inlined, key, nodes, post, root, val, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3;
function Clone(origin, context, contractThumb) {
var file, info, inline, inlined, key, nodes, post, root, val, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3, _ref4;
this.origin = origin;
this.context = context;
_ref = ['ID', 'fullID', 'board', 'thread', 'info', 'quotes', 'isReply'];
@ -1282,7 +1282,7 @@
this[key] = origin[key];
}
nodes = origin.nodes;
root = nodes.root.cloneNode(true);
root = contractThumb ? this.cloneWithoutVideo(nodes.root) : nodes.root.cloneNode(true);
post = $('.post', root);
info = $('.postInfo', post);
this.nodes = {
@ -1342,6 +1342,13 @@
this.file.text = file.firstElementChild;
this.file.thumb = $('img[data-md5]', file);
this.file.fullImage = $('.full-image', file);
if (contractThumb) {
$.rmClass(this.nodes.root, 'expanded-image');
$.rmClass(this.file.thumb, 'expanding');
}
if ((_ref4 = this.file.fullImage) != null) {
_ref4.removeAttribute('id');
}
}
if (origin.isDead) {
this.isDead = true;
@ -1350,6 +1357,23 @@
root.dataset.clone = origin.clones.push(this) - 1;
}
Clone.prototype.cloneWithoutVideo = function(node) {
var child, clone, _i, _len, _ref;
if (node.tagName === 'VIDEO') {
return [];
} else if (node.nodeType === Node.ELEMENT_NODE && $('video', node)) {
clone = node.cloneNode(false);
_ref = node.childNodes;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
child = _ref[_i];
$.add(clone, this.cloneWithoutVideo(child));
}
return clone;
} else {
return node.cloneNode(true);
}
};
return Clone;
})(Post);
@ -3366,7 +3390,7 @@
if (!root.parentNode) {
return;
}
clone = post.addClone(context);
clone = post.addClone(context, $.hasClass(root, 'dialog'));
Main.callbackNodes(Clone, [clone]);
nodes = clone.nodes;
$.rmAll(nodes.root);

View File

@ -85,7 +85,7 @@ Get =
insert: (post, root, context) ->
# Stop here if the container has been removed while loading.
return unless root.parentNode
clone = post.addClone context
clone = post.addClone context, ($.hasClass root, 'dialog')
Main.callbackNodes Clone, [clone]
# Get rid of the side arrows.

View File

@ -1,11 +1,14 @@
class Clone extends Post
constructor: (@origin, @context) ->
constructor: (@origin, @context, contractThumb) ->
for key in ['ID', 'fullID', 'board', 'thread', 'info', 'quotes', 'isReply']
# Copy or point to the origin's key value.
@[key] = origin[key]
{nodes} = origin
root = nodes.root.cloneNode true
root = if contractThumb
@cloneWithoutVideo nodes.root
else
nodes.root.cloneNode true
post = $ '.post', root
info = $ '.postInfo', post
@nodes =
@ -56,6 +59,25 @@ class Clone extends Post
@file.thumb = $ 'img[data-md5]', file
@file.fullImage = $ '.full-image', file
# Contract thumbnails in quote preview
if contractThumb
$.rmClass @nodes.root, 'expanded-image'
$.rmClass @file.thumb, 'expanding'
# Remove any #ihover ID
@file.fullImage?.removeAttribute 'id'
@isDead = true if origin.isDead
@isClone = true
root.dataset.clone = origin.clones.push(@) - 1
cloneWithoutVideo: (node) ->
if node.tagName is 'VIDEO'
[]
else if node.nodeType is Node.ELEMENT_NODE and $ 'video', node
clone = node.cloneNode false
$.add clone, @cloneWithoutVideo child for child in node.childNodes
clone
else
node.cloneNode true

View File

@ -214,8 +214,8 @@ class Post
@thread.posts.rm @
@board.posts.rm @
addClone: (context) ->
new Clone @, context
addClone: (context, contractThumb) ->
new Clone @, context, contractThumb
rmClone: (index) ->
@clones.splice index, 1