nitpicking

This commit is contained in:
Zixaphir 2014-04-08 15:01:19 -07:00
parent bc9ce0a434
commit 7658f575f3
3 changed files with 112 additions and 106 deletions

View File

@ -7952,17 +7952,19 @@
} }
thumb = this.file.thumb; thumb = this.file.thumb;
$.on(thumb.parentNode, 'click', ImageExpand.cb.toggle); $.on(thumb.parentNode, 'click', ImageExpand.cb.toggle);
if (this.isClone && $.hasClass(thumb, 'expanding')) { if (this.isClone) {
if ($.hasClass(thumb, 'expanding')) {
ImageExpand.contract(this); ImageExpand.contract(this);
return ImageExpand.expand(this); ImageExpand.expand(this);
} else if (this.isClone && this.file.isExpanded && this.file.isVideo) { } else if (this.file.isExpanded && this.file.isVideo) {
clone = this; clone = this;
ImageExpand.setupVideoControls(clone); ImageExpand.setupVideoControls(clone);
if (!clone.origin.file.fullImage.paused) { if (!clone.origin.file.fullImage.paused) {
return $.queueTask(function() { $.queueTask(function() {
return ImageExpand.startVideo(clone); return ImageExpand.startVideo(clone);
}); });
} }
}
} else if (ImageExpand.on && !this.isHidden && (Conf['Expand spoilers'] || !this.file.isSpoiler) && (Conf['Expand videos'] || !this.file.isVideo)) { } else if (ImageExpand.on && !this.isHidden && (Conf['Expand spoilers'] || !this.file.isSpoiler) && (Conf['Expand videos'] || !this.file.isVideo)) {
return ImageExpand.expand(this, null, true); return ImageExpand.expand(this, null, true);
} }
@ -8104,9 +8106,8 @@
}); });
}, },
completeExpand: function(post, disableAutoplay) { completeExpand: function(post, disableAutoplay) {
var bottom, thumb; var bottom;
thumb = post.file.thumb; if (!$.hasClass(post.file.thumb, 'expanding')) {
if (!$.hasClass(thumb, 'expanding')) {
return; return;
} }
if (!post.nodes.root.parentNode) { if (!post.nodes.root.parentNode) {
@ -8123,8 +8124,6 @@
}); });
}, },
completeExpand2: function(post, disableAutoplay) { completeExpand2: function(post, disableAutoplay) {
var thumb;
thumb = post.file.thumb;
$.addClass(post.nodes.root, 'expanded-image'); $.addClass(post.nodes.root, 'expanded-image');
$.rmClass(post.file.thumb, 'expanding'); $.rmClass(post.file.thumb, 'expanding');
post.file.isExpanded = true; post.file.isExpanded = true;
@ -8137,32 +8136,36 @@
} }
} }
}, },
videoCB: { videoCB: (function() {
click: function(e) { var mousedown;
if (this.paused && !this.controls) { mousedown = false;
this.play(); return {
return e.stopPropagation(); mouseover: function() {
} return mousedown = false;
}, },
mousedown: function(e) { mousedown: function(e) {
if (e.button === 0) { if (e.button === 0) {
return this.dataset.mousedown = 'true'; return mousedown = true;
} }
}, },
mouseup: function(e) { mouseup: function(e) {
if (e.button === 0) { if (e.button === 0) {
return this.dataset.mousedown = 'false'; return mousedown = false;
} }
}, },
mouseover: function(e) {
return this.dataset.mousedown = 'false';
},
mouseout: function(e) { mouseout: function(e) {
if (this.dataset.mousedown === 'true' && e.clientX <= this.getBoundingClientRect().left) { if (mousedown && e.clientX <= this.getBoundingClientRect().left) {
return ImageExpand.contract(Get.postFromNode(this)); return ImageExpand.contract(Get.postFromNode(this));
} }
}
}, },
click: function(e) {
if (this.paused && !this.controls) {
e.stopPropagation();
return this.play();
}
}
};
})(),
setupVideoControls: function(post) { setupVideoControls: function(post) {
var cb, contract, eventName, file, video, _ref; var cb, contract, eventName, file, video, _ref;
file = post.file; file = post.file;

View File

@ -7991,17 +7991,19 @@
} }
thumb = this.file.thumb; thumb = this.file.thumb;
$.on(thumb.parentNode, 'click', ImageExpand.cb.toggle); $.on(thumb.parentNode, 'click', ImageExpand.cb.toggle);
if (this.isClone && $.hasClass(thumb, 'expanding')) { if (this.isClone) {
if ($.hasClass(thumb, 'expanding')) {
ImageExpand.contract(this); ImageExpand.contract(this);
return ImageExpand.expand(this); ImageExpand.expand(this);
} else if (this.isClone && this.file.isExpanded && this.file.isVideo) { } else if (this.file.isExpanded && this.file.isVideo) {
clone = this; clone = this;
ImageExpand.setupVideoControls(clone); ImageExpand.setupVideoControls(clone);
if (!clone.origin.file.fullImage.paused) { if (!clone.origin.file.fullImage.paused) {
return $.queueTask(function() { $.queueTask(function() {
return ImageExpand.startVideo(clone); return ImageExpand.startVideo(clone);
}); });
} }
}
} else if (ImageExpand.on && !this.isHidden && (Conf['Expand spoilers'] || !this.file.isSpoiler) && (Conf['Expand videos'] || !this.file.isVideo)) { } else if (ImageExpand.on && !this.isHidden && (Conf['Expand spoilers'] || !this.file.isSpoiler) && (Conf['Expand videos'] || !this.file.isVideo)) {
return ImageExpand.expand(this, null, true); return ImageExpand.expand(this, null, true);
} }
@ -8143,9 +8145,8 @@
}); });
}, },
completeExpand: function(post, disableAutoplay) { completeExpand: function(post, disableAutoplay) {
var bottom, thumb; var bottom;
thumb = post.file.thumb; if (!$.hasClass(post.file.thumb, 'expanding')) {
if (!$.hasClass(thumb, 'expanding')) {
return; return;
} }
if (!post.nodes.root.parentNode) { if (!post.nodes.root.parentNode) {
@ -8162,8 +8163,6 @@
}); });
}, },
completeExpand2: function(post, disableAutoplay) { completeExpand2: function(post, disableAutoplay) {
var thumb;
thumb = post.file.thumb;
$.addClass(post.nodes.root, 'expanded-image'); $.addClass(post.nodes.root, 'expanded-image');
$.rmClass(post.file.thumb, 'expanding'); $.rmClass(post.file.thumb, 'expanding');
post.file.isExpanded = true; post.file.isExpanded = true;
@ -8176,32 +8175,36 @@
} }
} }
}, },
videoCB: { videoCB: (function() {
click: function(e) { var mousedown;
if (this.paused && !this.controls) { mousedown = false;
this.play(); return {
return e.stopPropagation(); mouseover: function() {
} return mousedown = false;
}, },
mousedown: function(e) { mousedown: function(e) {
if (e.button === 0) { if (e.button === 0) {
return this.dataset.mousedown = 'true'; return mousedown = true;
} }
}, },
mouseup: function(e) { mouseup: function(e) {
if (e.button === 0) { if (e.button === 0) {
return this.dataset.mousedown = 'false'; return mousedown = false;
} }
}, },
mouseover: function(e) {
return this.dataset.mousedown = 'false';
},
mouseout: function(e) { mouseout: function(e) {
if (this.dataset.mousedown === 'true' && e.clientX <= this.getBoundingClientRect().left) { if (mousedown && e.clientX <= this.getBoundingClientRect().left) {
return ImageExpand.contract(Get.postFromNode(this)); return ImageExpand.contract(Get.postFromNode(this));
} }
}
}, },
click: function(e) {
if (this.paused && !this.controls) {
e.stopPropagation();
return this.play();
}
}
};
})(),
setupVideoControls: function(post) { setupVideoControls: function(post) {
var cb, contract, eventName, file, video, _ref; var cb, contract, eventName, file, video, _ref;
file = post.file; file = post.file;

View File

@ -17,16 +17,20 @@ ImageExpand =
return unless @file?.isImage or @file?.isVideo return unless @file?.isImage or @file?.isVideo
{thumb} = @file {thumb} = @file
$.on thumb.parentNode, 'click', ImageExpand.cb.toggle $.on thumb.parentNode, 'click', ImageExpand.cb.toggle
if @isClone and $.hasClass thumb, 'expanding' if @isClone
if $.hasClass thumb, 'expanding'
# If we clone a post where the image is still loading, # If we clone a post where the image is still loading,
# make it loading in the clone too. # make it loading in the clone too.
ImageExpand.contract @ ImageExpand.contract @
ImageExpand.expand @ ImageExpand.expand @
else if @isClone and @file.isExpanded and @file.isVideo
else if @file.isExpanded and @file.isVideo
clone = @ clone = @
ImageExpand.setupVideoControls clone ImageExpand.setupVideoControls clone
unless clone.origin.file.fullImage.paused unless clone.origin.file.fullImage.paused
$.queueTask -> ImageExpand.startVideo clone $.queueTask -> ImageExpand.startVideo clone
return
else if ImageExpand.on and !@isHidden and else if ImageExpand.on and !@isHidden and
(Conf['Expand spoilers'] or !@file.isSpoiler) and (Conf['Expand spoilers'] or !@file.isSpoiler) and
(Conf['Expand videos'] or !@file.isVideo) (Conf['Expand videos'] or !@file.isVideo)
@ -130,8 +134,7 @@ ImageExpand =
ImageExpand.completeExpand post, disableAutoplay ImageExpand.completeExpand post, disableAutoplay
completeExpand: (post, disableAutoplay) -> completeExpand: (post, disableAutoplay) ->
{thumb} = post.file return unless $.hasClass post.file.thumb, 'expanding' # contracted before the image loaded
return unless $.hasClass thumb, 'expanding' # contracted before the image loaded
unless post.nodes.root.parentNode unless post.nodes.root.parentNode
# Image might start/finish loading before the post is inserted. # Image might start/finish loading before the post is inserted.
# Don't scroll when it's expanded in a QP for example. # Don't scroll when it's expanded in a QP for example.
@ -144,7 +147,6 @@ ImageExpand =
window.scrollBy 0, post.nodes.root.getBoundingClientRect().bottom - bottom window.scrollBy 0, post.nodes.root.getBoundingClientRect().bottom - bottom
completeExpand2: (post, disableAutoplay) -> completeExpand2: (post, disableAutoplay) ->
{thumb} = post.file
$.addClass post.nodes.root, 'expanded-image' $.addClass post.nodes.root, 'expanded-image'
$.rmClass post.file.thumb, 'expanding' $.rmClass post.file.thumb, 'expanding'
post.file.isExpanded = true post.file.isExpanded = true
@ -154,19 +156,17 @@ ImageExpand =
post.file.fullImage.controls = Conf['Show Controls'] post.file.fullImage.controls = Conf['Show Controls']
ImageExpand.startVideo post if Conf['Autoplay'] and not disableAutoplay ImageExpand.startVideo post if Conf['Autoplay'] and not disableAutoplay
videoCB: videoCB: do ->
# dragging to the left contracts the video
mousedown = false
mouseover: -> mousedown = false
mousedown: (e) -> mousedown = true if e.button is 0
mouseup: (e) -> mousedown = false if e.button is 0
mouseout: (e) -> ImageExpand.contract (Get.postFromNode @) if mousedown and e.clientX <= @getBoundingClientRect().left
click: (e) -> click: (e) ->
if @paused and not @controls if @paused and not @controls
@play()
e.stopPropagation() e.stopPropagation()
@play()
# dragging to the left contracts the video
mousedown: (e) -> @dataset.mousedown = 'true' if e.button is 0
mouseup: (e) -> @dataset.mousedown = 'false' if e.button is 0
mouseover: (e) -> @dataset.mousedown = 'false'
mouseout: (e) ->
if @dataset.mousedown is 'true' and e.clientX <= @getBoundingClientRect().left
ImageExpand.contract (Get.postFromNode @)
setupVideoControls: (post) -> setupVideoControls: (post) ->
{file} = post {file} = post