2013-07-27 01:39:11 +02:00
|
|
|
/*
|
|
|
|
* toggle-images.js
|
|
|
|
*
|
|
|
|
* Released under the MIT license
|
|
|
|
* Copyright (c) 2012 Michael Save <savetheinternet@tinyboard.org>
|
2014-01-19 14:27:24 +01:00
|
|
|
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
|
2013-07-27 01:39:11 +02:00
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
2014-09-20 22:10:44 +02:00
|
|
|
* //$config['additional_javascript'][] = 'js/options.js';
|
|
|
|
* //$config['additional_javascript'][] = 'js/style-select.js';
|
|
|
|
* //$config['additional_javascript'][] = 'js/options/general.js';
|
2013-07-27 01:39:11 +02:00
|
|
|
* $config['additional_javascript'][] = 'js/toggle-images.js';
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
$(document).ready(function(){
|
|
|
|
var hide_images = localStorage['hideimages'] ? true : false;
|
|
|
|
|
|
|
|
$('<style type="text/css"> img.hidden{ opacity: 0.1; background: grey; border: 1px solid #000; } </style>').appendTo($('head'));
|
|
|
|
|
|
|
|
var hideImage = function() {
|
2013-07-27 06:14:43 +02:00
|
|
|
if ($(this).parent()[0].dataset.expanded == 'true') {
|
|
|
|
$(this).parent().click();
|
|
|
|
}
|
2013-07-27 01:39:11 +02:00
|
|
|
$(this)
|
|
|
|
.attr('data-orig', this.src)
|
|
|
|
.attr('src', 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==')
|
|
|
|
.addClass('hidden');
|
|
|
|
};
|
|
|
|
|
|
|
|
var restoreImage = function() {
|
|
|
|
$(this)
|
|
|
|
.attr('src', $(this).attr('data-orig'))
|
|
|
|
.removeClass('hidden');
|
|
|
|
};
|
|
|
|
|
2013-07-27 06:14:43 +02:00
|
|
|
// Fix for hide-images.js
|
|
|
|
var show_hide_hide_images_buttons = function() {
|
|
|
|
if (hide_images) {
|
|
|
|
$('a.hide-image-link').each(function() {
|
|
|
|
if ($(this).next().hasClass('show-image-link')) {
|
|
|
|
$(this).next().hide();
|
|
|
|
}
|
2013-07-27 07:16:12 +02:00
|
|
|
$(this).hide().after('<span class="toggle-images-placeholder">'+_('hidden')+'</span>');
|
2013-07-27 06:14:43 +02:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$('span.toggle-images-placeholder').remove();
|
|
|
|
$('a.hide-image-link').each(function() {
|
|
|
|
if ($(this).next().hasClass('show-image-link')) {
|
|
|
|
$(this).next().show();
|
|
|
|
} else {
|
|
|
|
$(this).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-20 22:10:44 +02:00
|
|
|
var selector, event;
|
|
|
|
if (window.Options && Options.get_tab('general')) {
|
|
|
|
selector = '#toggle-images>input';
|
|
|
|
event = 'change';
|
|
|
|
Options.extend_tab("general", "<label id='toggle-images'><input type='checkbox' /> "+_('Hide images')+"</label>");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
selector = '#toggle-images a';
|
|
|
|
event = 'click';
|
|
|
|
$('hr:first').before('<div id="toggle-images" style="text-align:right"><a class="unimportant" href="javascript:void(0)">-</a></div>');
|
|
|
|
$('div#toggle-images a')
|
|
|
|
.text(hide_images ? _('Show images') : _('Hide images'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$(selector)
|
|
|
|
.on(event, function() {
|
2013-07-27 01:39:11 +02:00
|
|
|
hide_images = !hide_images;
|
|
|
|
if (hide_images) {
|
2014-01-19 14:27:24 +01:00
|
|
|
$('img.post-image, .theme-catalog .thread>a>img').each(hideImage);
|
2013-07-27 01:39:11 +02:00
|
|
|
localStorage.hideimages = true;
|
|
|
|
} else {
|
2014-01-19 14:27:24 +01:00
|
|
|
$('img.post-image, .theme-catalog .thread>a>img').each(restoreImage);
|
2013-07-27 01:39:11 +02:00
|
|
|
delete localStorage.hideimages;
|
|
|
|
}
|
2013-07-27 06:14:43 +02:00
|
|
|
|
|
|
|
show_hide_hide_images_buttons();
|
|
|
|
|
2013-07-27 07:16:12 +02:00
|
|
|
$(this).text(hide_images ? _('Show images') : _('Hide images'))
|
2013-07-27 01:39:11 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (hide_images) {
|
2014-01-19 14:27:24 +01:00
|
|
|
$('img.post-image, .theme-catalog .thread>a>img').each(hideImage);
|
2013-07-27 06:14:43 +02:00
|
|
|
show_hide_hide_images_buttons();
|
2014-09-20 22:10:44 +02:00
|
|
|
|
|
|
|
if (window.Options && Options.get_tab('general')) {
|
|
|
|
$('#toggle-images>input').prop('checked', true);
|
|
|
|
}
|
2013-07-27 01:39:11 +02:00
|
|
|
}
|
2013-08-16 15:49:57 +02:00
|
|
|
|
2014-01-21 19:25:11 +01:00
|
|
|
$(document).on('new_post', function(e, post) {
|
2013-08-16 15:49:57 +02:00
|
|
|
if (hide_images) {
|
|
|
|
$(post).find('img.post-image').each(hideImage);
|
|
|
|
}
|
|
|
|
});
|
2013-07-27 01:39:11 +02:00
|
|
|
});
|