ImageHover.coffee
This commit is contained in:
parent
4089d56720
commit
1c1ec16eef
@ -11286,6 +11286,10 @@
|
|||||||
|
|
||||||
ImageHover = {
|
ImageHover = {
|
||||||
init: function() {
|
init: function() {
|
||||||
|
var _ref;
|
||||||
|
if ((_ref = g.VIEW) !== 'index' && _ref !== 'thread') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Conf['Image Hover']) {
|
if (Conf['Image Hover']) {
|
||||||
Post.callbacks.push({
|
Post.callbacks.push({
|
||||||
name: 'Image Hover',
|
name: 'Image Hover',
|
||||||
@ -11300,113 +11304,85 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
node: function() {
|
node: function() {
|
||||||
var _ref, _ref1;
|
if (!(this.file && (this.file.isImage || this.file.isVideo))) {
|
||||||
if (!(((_ref = this.file) != null ? _ref.isImage : void 0) || ((_ref1 = this.file) != null ? _ref1.isVideo : void 0))) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return $.on(this.file.thumb, 'mouseover', ImageHover.mouseover);
|
return $.on(this.file.thumb, 'mouseover', ImageHover.mouseover);
|
||||||
},
|
},
|
||||||
catalogNode: function() {
|
catalogNode: function() {
|
||||||
var file;
|
var file;
|
||||||
if (!((file = this.thread.OP.file) && (file.isImage || file.isVideo))) {
|
file = this.thread.OP.file;
|
||||||
|
if (!(file && (file.isImage || file.isVideo))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return $.on(this.nodes.thumb, 'mouseover', ImageHover.mouseover);
|
return $.on(this.nodes.thumb, 'mouseover', ImageHover.mouseover);
|
||||||
},
|
},
|
||||||
mouseover: function(e) {
|
mouseover: function(e) {
|
||||||
var el, isVideo, post, thumb;
|
var el, error, file, isVideo, maxHeight, maxWidth, post, scale, _ref;
|
||||||
post = $.hasClass(this, 'thumb') ? g.posts[this.parentNode.dataset.fullID] : Get.postFromNode(this);
|
post = $.hasClass(this, 'thumb') ? g.posts[this.parentNode.dataset.fullID] : Get.postFromNode(this);
|
||||||
isVideo = post.file.isVideo;
|
file = post.file;
|
||||||
el = $.el((isVideo ? 'video' : 'img'), {
|
isVideo = file.isVideo;
|
||||||
src: post.file.URL
|
if (file.isExpanding || file.isExpanded) {
|
||||||
});
|
return;
|
||||||
thumb = post.file.thumb;
|
}
|
||||||
if (d.body.contains(thumb)) {
|
error = ImageHover.error(post);
|
||||||
if (el !== thumb.nextSibling) {
|
if (((_ref = ImageCommon.cache) != null ? _ref.dataset.fullID : void 0) === post.fullID) {
|
||||||
$.after(thumb, el);
|
el = ImageCommon.popCache();
|
||||||
}
|
$.on(el, 'error', error);
|
||||||
} else {
|
} else {
|
||||||
if (el.parentNode !== Header.hover) {
|
el = $.el((isVideo ? 'video' : 'img'));
|
||||||
$.add(Header.hover, el);
|
el.dataset.fullID = post.fullID;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
el.id = 'ihover';
|
el.id = 'ihover';
|
||||||
el.dataset.fullID = post.fullID;
|
$.add(Header.hover, el);
|
||||||
if (isVideo) {
|
if (isVideo) {
|
||||||
el.loop = true;
|
el.loop = true;
|
||||||
el.controls = false;
|
el.controls = false;
|
||||||
el.muted = !Conf['Allow Sound'];
|
|
||||||
if (Conf['Autoplay']) {
|
if (Conf['Autoplay']) {
|
||||||
el.play();
|
el.play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UI.hover({
|
maxWidth = Math.max(left, doc.clientWidth - right);
|
||||||
|
maxHeight = doc.clientHeight - 16;
|
||||||
|
scale = Math.min(1, maxWidth / width, maxHeight / height);
|
||||||
|
el.style.maxWidth = "" + (scale * width) + "px";
|
||||||
|
el.style.maxHeight = "" + (scale * height) + "px";
|
||||||
|
return UI.hover({
|
||||||
root: this,
|
root: this,
|
||||||
el: el,
|
el: el,
|
||||||
latestEvent: e,
|
latestEvent: e,
|
||||||
endEvents: 'mouseout click',
|
endEvents: 'mouseout click',
|
||||||
asapTest: post.file.isImage ? function() {
|
asapTest: function() {
|
||||||
return el.naturalHeight;
|
return true;
|
||||||
} : function() {
|
|
||||||
return el.readyState >= el.HAVE_CURRENT_DATA;
|
|
||||||
},
|
},
|
||||||
|
height: scale * height + padding,
|
||||||
|
noRemove: true,
|
||||||
cb: function() {
|
cb: function() {
|
||||||
|
$.off(el, 'error', error);
|
||||||
|
ImageCommon.pushCache(el);
|
||||||
if (isVideo) {
|
if (isVideo) {
|
||||||
el.pause();
|
el.pause();
|
||||||
TrashQueue.add(el, post);
|
|
||||||
}
|
}
|
||||||
return el.removeAttribute('id');
|
$.rm(el);
|
||||||
|
return el.removeAttribute('style');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return $.on(el, 'error', ImageHover.error);
|
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function(post) {
|
||||||
var URL, post, src, timeoutID;
|
return function() {
|
||||||
if (!doc.contains(this)) {
|
if (ImageCommon.decodeError(this, post)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
post = g.posts[this.dataset.fullID];
|
|
||||||
src = this.src.split('/');
|
|
||||||
if (src[2] === 'i.4cdn.org') {
|
|
||||||
URL = Redirect.to('file', {
|
|
||||||
boardID: src[3],
|
|
||||||
filename: src[4].replace(/\?.+$/, '')
|
|
||||||
});
|
|
||||||
if (URL) {
|
|
||||||
this.src = URL;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (g.DEAD || post.isDead || post.file.isDead) {
|
return ImageCommon.error(this, post, 3 * $.SECOND, (function(_this) {
|
||||||
return;
|
return function(URL) {
|
||||||
}
|
if (URL) {
|
||||||
}
|
return _this.src = URL + (_this.src === URL ? '?' + Date.now() : '');
|
||||||
timeoutID = setTimeout(((function(_this) {
|
} else {
|
||||||
return function() {
|
return $.rm(_this);
|
||||||
return _this.src = post.file.URL + '?' + Date.now();
|
|
||||||
};
|
|
||||||
})(this)), 3000);
|
|
||||||
return $.ajax("//a.4cdn.org/" + post.board + "/thread/" + post.thread + ".json", {
|
|
||||||
onload: function() {
|
|
||||||
var postObj, _i, _len, _ref;
|
|
||||||
if (this.status !== 200) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_ref = this.response.posts;
|
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
||||||
postObj = _ref[_i];
|
|
||||||
if (postObj.no === post.ID) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
if (postObj.no !== post.ID) {
|
})(this));
|
||||||
clearTimeout(timeoutID);
|
};
|
||||||
return post.kill();
|
|
||||||
} else if (postObj.filedeleted) {
|
|
||||||
clearTimeout(timeoutID);
|
|
||||||
return post.kill(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -11308,6 +11308,10 @@
|
|||||||
|
|
||||||
ImageHover = {
|
ImageHover = {
|
||||||
init: function() {
|
init: function() {
|
||||||
|
var _ref;
|
||||||
|
if ((_ref = g.VIEW) !== 'index' && _ref !== 'thread') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Conf['Image Hover']) {
|
if (Conf['Image Hover']) {
|
||||||
Post.callbacks.push({
|
Post.callbacks.push({
|
||||||
name: 'Image Hover',
|
name: 'Image Hover',
|
||||||
@ -11322,102 +11326,85 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
node: function() {
|
node: function() {
|
||||||
var _ref, _ref1;
|
if (!(this.file && (this.file.isImage || this.file.isVideo))) {
|
||||||
if (!(((_ref = this.file) != null ? _ref.isImage : void 0) || ((_ref1 = this.file) != null ? _ref1.isVideo : void 0))) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return $.on(this.file.thumb, 'mouseover', ImageHover.mouseover);
|
return $.on(this.file.thumb, 'mouseover', ImageHover.mouseover);
|
||||||
},
|
},
|
||||||
catalogNode: function() {
|
catalogNode: function() {
|
||||||
var file;
|
var file;
|
||||||
if (!((file = this.thread.OP.file) && (file.isImage || file.isVideo))) {
|
file = this.thread.OP.file;
|
||||||
|
if (!(file && (file.isImage || file.isVideo))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return $.on(this.nodes.thumb, 'mouseover', ImageHover.mouseover);
|
return $.on(this.nodes.thumb, 'mouseover', ImageHover.mouseover);
|
||||||
},
|
},
|
||||||
mouseover: function(e) {
|
mouseover: function(e) {
|
||||||
var el, isVideo, post, thumb;
|
var el, error, file, isVideo, maxHeight, maxWidth, post, scale, _ref;
|
||||||
post = $.hasClass(this, 'thumb') ? g.posts[this.parentNode.dataset.fullID] : Get.postFromNode(this);
|
post = $.hasClass(this, 'thumb') ? g.posts[this.parentNode.dataset.fullID] : Get.postFromNode(this);
|
||||||
isVideo = post.file.isVideo;
|
file = post.file;
|
||||||
el = $.el((isVideo ? 'video' : 'img'), {
|
isVideo = file.isVideo;
|
||||||
src: post.file.URL
|
if (file.isExpanding || file.isExpanded) {
|
||||||
});
|
return;
|
||||||
thumb = post.file.thumb;
|
}
|
||||||
if (d.body.contains(thumb)) {
|
error = ImageHover.error(post);
|
||||||
if (el !== thumb.nextSibling) {
|
if (((_ref = ImageCommon.cache) != null ? _ref.dataset.fullID : void 0) === post.fullID) {
|
||||||
$.after(thumb, el);
|
el = ImageCommon.popCache();
|
||||||
}
|
$.on(el, 'error', error);
|
||||||
} else {
|
} else {
|
||||||
if (el.parentNode !== Header.hover) {
|
el = $.el((isVideo ? 'video' : 'img'));
|
||||||
$.add(Header.hover, el);
|
el.dataset.fullID = post.fullID;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
el.id = 'ihover';
|
el.id = 'ihover';
|
||||||
el.dataset.fullID = post.fullID;
|
$.add(Header.hover, el);
|
||||||
if (isVideo) {
|
if (isVideo) {
|
||||||
el.loop = true;
|
el.loop = true;
|
||||||
el.controls = false;
|
el.controls = false;
|
||||||
el.muted = !Conf['Allow Sound'];
|
|
||||||
if (Conf['Autoplay']) {
|
if (Conf['Autoplay']) {
|
||||||
el.play();
|
el.play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UI.hover({
|
maxWidth = Math.max(left, doc.clientWidth - right);
|
||||||
|
maxHeight = doc.clientHeight - 16;
|
||||||
|
scale = Math.min(1, maxWidth / width, maxHeight / height);
|
||||||
|
el.style.maxWidth = "" + (scale * width) + "px";
|
||||||
|
el.style.maxHeight = "" + (scale * height) + "px";
|
||||||
|
return UI.hover({
|
||||||
root: this,
|
root: this,
|
||||||
el: el,
|
el: el,
|
||||||
latestEvent: e,
|
latestEvent: e,
|
||||||
endEvents: 'mouseout click',
|
endEvents: 'mouseout click',
|
||||||
asapTest: post.file.isImage ? function() {
|
asapTest: function() {
|
||||||
return el.naturalHeight;
|
return true;
|
||||||
} : function() {
|
|
||||||
return el.readyState >= el.HAVE_CURRENT_DATA;
|
|
||||||
},
|
},
|
||||||
|
height: scale * height + padding,
|
||||||
|
noRemove: true,
|
||||||
cb: function() {
|
cb: function() {
|
||||||
|
$.off(el, 'error', error);
|
||||||
|
ImageCommon.pushCache(el);
|
||||||
if (isVideo) {
|
if (isVideo) {
|
||||||
el.pause();
|
el.pause();
|
||||||
TrashQueue.add(el, post);
|
|
||||||
}
|
}
|
||||||
return el.removeAttribute('id');
|
$.rm(el);
|
||||||
|
return el.removeAttribute('style');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return $.on(el, 'error', ImageHover.error);
|
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function(post) {
|
||||||
var URL, post, src, timeoutID;
|
return function() {
|
||||||
if (!doc.contains(this)) {
|
if (ImageCommon.decodeError(this, post)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
post = g.posts[this.dataset.fullID];
|
|
||||||
src = this.src.split('/');
|
|
||||||
if (src[2] === 'i.4cdn.org') {
|
|
||||||
URL = Redirect.to('file', {
|
|
||||||
boardID: src[3],
|
|
||||||
filename: src[4].replace(/\?.+$/, '')
|
|
||||||
});
|
|
||||||
if (URL) {
|
|
||||||
this.src = URL;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (g.DEAD || post.isDead || post.file.isDead) {
|
return ImageCommon.error(this, post, 3 * $.SECOND, (function(_this) {
|
||||||
return;
|
return function(URL) {
|
||||||
}
|
if (URL) {
|
||||||
}
|
return _this.src = URL + (_this.src === URL ? '?' + Date.now() : '');
|
||||||
timeoutID = setTimeout(((function(_this) {
|
} else {
|
||||||
return function() {
|
return $.rm(_this);
|
||||||
return _this.src = post.file.URL + '?' + Date.now();
|
}
|
||||||
};
|
};
|
||||||
})(this)), 3000);
|
})(this));
|
||||||
return $.ajax(post.file.URL, {
|
};
|
||||||
onloadend: function() {
|
|
||||||
if (this.status !== 404) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
clearTimeout(timeoutID);
|
|
||||||
return post.kill(true);
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
type: 'head'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
ImageHover =
|
ImageHover =
|
||||||
init: ->
|
init: ->
|
||||||
|
return if g.VIEW not in ['index', 'thread']
|
||||||
if Conf['Image Hover']
|
if Conf['Image Hover']
|
||||||
Post.callbacks.push
|
Post.callbacks.push
|
||||||
name: 'Image Hover'
|
name: 'Image Hover'
|
||||||
@ -8,82 +9,62 @@ ImageHover =
|
|||||||
CatalogThread.callbacks.push
|
CatalogThread.callbacks.push
|
||||||
name: 'Image Hover'
|
name: 'Image Hover'
|
||||||
cb: @catalogNode
|
cb: @catalogNode
|
||||||
|
|
||||||
node: ->
|
node: ->
|
||||||
return unless @file?.isImage or @file?.isVideo
|
return unless @file and (@file.isImage or @file.isVideo)
|
||||||
$.on @file.thumb, 'mouseover', ImageHover.mouseover
|
$.on @file.thumb, 'mouseover', ImageHover.mouseover
|
||||||
|
|
||||||
catalogNode: ->
|
catalogNode: ->
|
||||||
return unless (file = @thread.OP.file) and (file.isImage or file.isVideo)
|
{file} = @thread.OP
|
||||||
|
return unless file and (file.isImage or file.isVideo)
|
||||||
$.on @nodes.thumb, 'mouseover', ImageHover.mouseover
|
$.on @nodes.thumb, 'mouseover', ImageHover.mouseover
|
||||||
|
|
||||||
mouseover: (e) ->
|
mouseover: (e) ->
|
||||||
post = if $.hasClass @, 'thumb'
|
post = if $.hasClass @, 'thumb'
|
||||||
g.posts[@parentNode.dataset.fullID]
|
g.posts[@parentNode.dataset.fullID]
|
||||||
else
|
else
|
||||||
Get.postFromNode @
|
Get.postFromNode @
|
||||||
{isVideo} = post.file
|
{file} = post
|
||||||
el = $.el (if isVideo then 'video' else 'img'),
|
{isVideo} = file
|
||||||
src: post.file.URL
|
return if file.isExpanding or file.isExpanded
|
||||||
{thumb} = post.file
|
error = ImageHover.error post
|
||||||
|
if ImageCommon.cache?.dataset.fullID is post.fullID
|
||||||
if d.body.contains thumb
|
el = ImageCommon.popCache()
|
||||||
$.after thumb, el unless el is thumb.nextSibling
|
$.on el, 'error', error
|
||||||
else
|
else
|
||||||
$.add Header.hover, el if el.parentNode isnt Header.hover
|
el = $.el (if isVideo then 'video' else 'img')
|
||||||
|
el.dataset.fullID = post.fullID
|
||||||
|
|
||||||
el.id = 'ihover'
|
el.id = 'ihover'
|
||||||
el.dataset.fullID = post.fullID
|
$.add Header.hover, el
|
||||||
if isVideo
|
if isVideo
|
||||||
el.loop = true
|
el.loop = true
|
||||||
el.controls = false
|
el.controls = false
|
||||||
el.muted = not Conf['Allow Sound']
|
|
||||||
el.play() if Conf['Autoplay']
|
el.play() if Conf['Autoplay']
|
||||||
|
maxWidth = Math.max left, doc.clientWidth - right
|
||||||
|
maxHeight = doc.clientHeight - 16
|
||||||
|
scale = Math.min 1, maxWidth / width, maxHeight / height
|
||||||
|
el.style.maxWidth = "#{scale * width}px"
|
||||||
|
el.style.maxHeight = "#{scale * height}px"
|
||||||
UI.hover
|
UI.hover
|
||||||
root: @
|
root: @
|
||||||
el: el
|
el: el
|
||||||
latestEvent: e
|
latestEvent: e
|
||||||
endEvents: 'mouseout click'
|
endEvents: 'mouseout click'
|
||||||
asapTest: if post.file.isImage
|
asapTest: -> true
|
||||||
-> el.naturalHeight
|
height: scale * height + padding
|
||||||
else
|
noRemove: true
|
||||||
-> el.readyState >= el.HAVE_CURRENT_DATA
|
|
||||||
cb: ->
|
cb: ->
|
||||||
if isVideo
|
$.off el, 'error', error
|
||||||
el.pause()
|
ImageCommon.pushCache el
|
||||||
TrashQueue.add el, post
|
el.pause() if isVideo
|
||||||
el.removeAttribute 'id'
|
$.rm el
|
||||||
$.on el, 'error', ImageHover.error
|
el.removeAttribute 'style'
|
||||||
error: ->
|
|
||||||
return unless doc.contains @
|
|
||||||
post = g.posts[@dataset.fullID]
|
|
||||||
|
|
||||||
src = @src.split '/'
|
error: (post) -> ->
|
||||||
if src[2] is 'i.4cdn.org'
|
return if ImageCommon.decodeError @, post
|
||||||
URL = Redirect.to 'file',
|
ImageCommon.error @, post, 3 * $.SECOND, (URL) =>
|
||||||
boardID: src[3]
|
|
||||||
filename: src[4].replace /\?.+$/, ''
|
|
||||||
if URL
|
if URL
|
||||||
@src = URL
|
@src = URL + if @src is URL then '?' + Date.now() else ''
|
||||||
return
|
else
|
||||||
if g.DEAD or post.isDead or post.file.isDead
|
$.rm @
|
||||||
return
|
|
||||||
|
|
||||||
timeoutID = setTimeout (=> @src = post.file.URL + '?' + Date.now()), 3000
|
|
||||||
<% if (type === 'crx') { %>
|
|
||||||
$.ajax post.file.URL,
|
|
||||||
onloadend: ->
|
|
||||||
return if @status isnt 404
|
|
||||||
clearTimeout timeoutID
|
|
||||||
post.kill true
|
|
||||||
,
|
|
||||||
type: 'head'
|
|
||||||
<% } else { %>
|
|
||||||
# XXX CORS for i.4cdn.org WHEN?
|
|
||||||
$.ajax "//a.4cdn.org/#{post.board}/thread/#{post.thread}.json", onload: ->
|
|
||||||
return if @status isnt 200
|
|
||||||
for postObj in @response.posts
|
|
||||||
break if postObj.no is post.ID
|
|
||||||
if postObj.no isnt post.ID
|
|
||||||
clearTimeout timeoutID
|
|
||||||
post.kill()
|
|
||||||
else if postObj.filedeleted
|
|
||||||
clearTimeout timeoutID
|
|
||||||
post.kill true
|
|
||||||
<% } %>
|
|
||||||
Loading…
x
Reference in New Issue
Block a user