Add Reveal Spoilers.

This commit is contained in:
Nicolas Stepien 2012-09-10 22:56:03 +02:00
parent 3bb93e73c7
commit 6c9d745a84
2 changed files with 51 additions and 3 deletions

View File

@ -74,7 +74,7 @@
*/
(function() {
var $, $$, Board, Build, Clone, Conf, Config, FileInfo, Get, Main, Post, QuoteBacklink, QuoteInline, QuotePreview, Quotify, Redirect, Sauce, Thread, Time, UI, d, g,
var $, $$, Board, Build, Clone, Conf, Config, FileInfo, Get, Main, Post, QuoteBacklink, QuoteInline, QuotePreview, Quotify, Redirect, RevealSpoilers, Sauce, Thread, Time, UI, d, g,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
@ -985,6 +985,13 @@
$.log(err, 'Sauce');
}
}
if (Conf['Reveal Spoilers']) {
try {
RevealSpoilers.init();
} catch (err) {
$.log(err, 'Reveal Spoilers');
}
}
return $.ready(Main.initFeaturesReady);
},
initFeaturesReady: function() {
@ -1996,7 +2003,7 @@
},
p: function() {
if (this.file.isSpoiler) {
return 'Spoiler';
return 'Spoiler, ';
} else {
return '';
}
@ -2089,6 +2096,26 @@
}
};
RevealSpoilers = {
init: function() {
return Post.prototype.callbacks.push({
name: 'Reveal Spoilers',
cb: this.node
});
},
node: function() {
var style, thumb, _ref;
if (this.isClone || !((_ref = this.file) != null ? _ref.isSpoiler : void 0)) {
return;
}
thumb = this.file.thumb;
thumb.removeAttribute('style');
style = thumb.style;
style.maxHeight = style.maxWidth = this.isReply ? '125px' : '250px';
return thumb.src = this.file.thumbURL;
}
};
Main.init();
}).call(this);

View File

@ -790,6 +790,13 @@ Main =
# XXX handle error
$.log err, 'Sauce'
if Conf['Reveal Spoilers']
try
RevealSpoilers.init()
catch err
# XXX handle error
$.log err, 'Reveal Spoilers'
$.ready Main.initFeaturesReady
initFeaturesReady: ->
if d.title is '4chan - 404 Not Found'
@ -1726,7 +1733,7 @@ FileInfo =
else
"<span class=fntrunc>#{FileInfo.escape shortname}</span><span class=fnfull>#{FileInfo.escape fullname}</span>"
N: -> FileInfo.escape @file.name
p: -> if @file.isSpoiler then 'Spoiler' else ''
p: -> if @file.isSpoiler then 'Spoiler, ' else ''
s: -> $.bytesToString @file.size
B: -> FileInfo.convertUnit @file.size, 'B'
K: -> FileInfo.convertUnit @file.size, 'KB'
@ -1776,6 +1783,20 @@ Sauce =
nodes.push $.tn('\u00A0'), link @
$.add @file.info, nodes
RevealSpoilers =
init: ->
Post::callbacks.push
name: 'Reveal Spoilers'
cb: @node
node: ->
return if @isClone or !@file?.isSpoiler
{thumb} = @file
# revealed spoilers do not have height/width set, this fixes auto-gifs dimensions.
thumb.removeAttribute 'style'
{style} = thumb
style.maxHeight = style.maxWidth = if @isReply then '125px' else '250px'
thumb.src = @file.thumbURL
Main.init()