2012-03-14 04:41:56 -04:00
|
|
|
/*
|
|
|
|
* quick-reply.js
|
2012-03-30 20:13:11 -04:00
|
|
|
* https://github.com/savetheinternet/Tinyboard/blob/master/js/quick-reply.js
|
2012-03-14 04:41:56 -04:00
|
|
|
*
|
|
|
|
* Released under the MIT license
|
2013-09-14 17:17:02 -04:00
|
|
|
* Copyright (c) 2013 Michael Save <savetheinternet@tinyboard.org>
|
2012-03-14 04:41:56 -04:00
|
|
|
*
|
|
|
|
* Usage:
|
2012-03-15 01:19:26 -04:00
|
|
|
* $config['additional_javascript'][] = 'js/jquery.min.js';
|
|
|
|
* $config['additional_javascript'][] = 'js/quick-reply.js';
|
2012-03-14 04:41:56 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-09-14 17:17:02 -04:00
|
|
|
var show_quick_reply = function(){
|
|
|
|
if($('div.banner').length == 0)
|
2013-09-14 17:31:05 -04:00
|
|
|
return;
|
|
|
|
if($('#quick-reply').length != 0)
|
|
|
|
return;
|
2013-09-14 17:17:02 -04:00
|
|
|
|
|
|
|
$('<style type="text/css">\
|
|
|
|
#quick-reply {\
|
|
|
|
position: fixed;\
|
|
|
|
right: 0;\
|
|
|
|
top: 10%;\
|
|
|
|
float: right;\
|
|
|
|
background: #D6DAF0;\
|
|
|
|
display: block;\
|
|
|
|
padding: 0 0 0 0;\
|
|
|
|
width: 350px;\
|
|
|
|
}\
|
|
|
|
#quick-reply table {\
|
|
|
|
border-collapse: collapse;\
|
|
|
|
margin: 0;\
|
|
|
|
width: 100%;\
|
|
|
|
}\
|
|
|
|
#quick-reply th, #quick-reply td {\
|
|
|
|
margin: 0;\
|
|
|
|
padding: 0;\
|
|
|
|
}\
|
|
|
|
#quick-reply th {\
|
|
|
|
text-align: center;\
|
|
|
|
padding: 2px 0;\
|
|
|
|
border: 1px solid #222;\
|
|
|
|
}\
|
|
|
|
#quick-reply input[type="text"] {\
|
|
|
|
width: 100%;\
|
|
|
|
padding: 2px;\
|
|
|
|
margin: 0 0 1px 0;\
|
|
|
|
font-size: 10pt;\
|
|
|
|
box-sizing: border-box;\
|
|
|
|
-webkit-box-sizing:border-box;\
|
|
|
|
-moz-box-sizing: border-box;\
|
|
|
|
}\
|
|
|
|
#quick-reply textarea {\
|
|
|
|
width: 100%;\
|
|
|
|
box-sizing: border-box;\
|
|
|
|
-webkit-box-sizing:border-box;\
|
|
|
|
-moz-box-sizing: border-box;\
|
|
|
|
font-size: 10pt;\
|
|
|
|
}\
|
|
|
|
#quick-reply input[type="file"] {\
|
|
|
|
padding: 5px 0;\
|
|
|
|
}\
|
|
|
|
#quick-reply .nonsense {\
|
|
|
|
display: none;\
|
|
|
|
}\
|
|
|
|
#quick-reply td.submit {\
|
|
|
|
width: 1%;\
|
|
|
|
}\
|
|
|
|
</style>').appendTo($('head'));
|
|
|
|
|
|
|
|
var $postForm = $('form[name="post"]').clone();
|
|
|
|
|
|
|
|
$postForm.clone();
|
2012-03-14 04:41:56 -04:00
|
|
|
|
2013-09-14 17:17:02 -04:00
|
|
|
$dummyStuff = $('<div class="nonsense"></div>').appendTo($postForm);
|
|
|
|
|
|
|
|
$postForm.find('table tr').each(function() {
|
|
|
|
var $th = $(this).children('th');
|
|
|
|
var $td = $(this).children('td');
|
|
|
|
if ($th.length && $td.length) {
|
|
|
|
$td.attr('colspan', 2);
|
|
|
|
|
|
|
|
if ($td.find('input[type="text"]').length) {
|
|
|
|
// Replace <th> with input placeholders
|
|
|
|
$td.find('input[type="text"]')
|
|
|
|
.removeAttr('size')
|
|
|
|
.attr('placeholder', $th.clone().children().remove().end().text());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move anti-spam nonsense and remove <th>
|
|
|
|
$th.contents().appendTo($dummyStuff);
|
|
|
|
$th.remove();
|
|
|
|
|
|
|
|
if ($td.find('input[name="password"]').length) {
|
|
|
|
// Hide password field
|
|
|
|
$(this).hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fix submit button
|
|
|
|
if ($td.find('input[type="submit"]').length) {
|
|
|
|
$td.removeAttr('colspan');
|
|
|
|
$('<td class="submit"></td>').append($td.find('input[type="submit"]')).insertAfter($td);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($td.find('input[type="file"]').length) {
|
|
|
|
if ($td.find('input[name="file_url"]').length) {
|
|
|
|
$file_url = $td.find('input[name="file_url"]');
|
|
|
|
|
|
|
|
// Make a new row for it
|
|
|
|
$newRow = $('<tr><td colspan="2"></td></tr>');
|
|
|
|
|
|
|
|
$file_url.clone().attr('placeholder', _('Upload URL')).appendTo($newRow.find('td'));
|
|
|
|
$file_url.parent().remove();
|
|
|
|
|
|
|
|
$newRow.insertBefore(this);
|
|
|
|
|
|
|
|
$td.find('label').remove();
|
|
|
|
$td.contents().filter(function() {
|
|
|
|
return this.nodeType == 3; // Node.TEXT_NODE
|
|
|
|
}).remove();
|
|
|
|
$td.find('input[name="file_url"]').removeAttr('id');
|
|
|
|
}
|
|
|
|
}
|
2013-09-14 17:49:14 -04:00
|
|
|
|
|
|
|
// Remove mod controls, because it looks shit.
|
|
|
|
if ($td.find('input[type="checkbox"]').length) {
|
|
|
|
$(this).remove();
|
|
|
|
}
|
2013-09-14 17:17:02 -04:00
|
|
|
}
|
2012-03-14 04:41:56 -04:00
|
|
|
});
|
2013-09-14 17:17:02 -04:00
|
|
|
|
|
|
|
$postForm.find('textarea[name="body"]').removeAttr('id').removeAttr('cols').attr('placeholder', _('Comment'));
|
|
|
|
|
|
|
|
$postForm.find('br').remove();
|
|
|
|
$postForm.find('table').prepend('<tr><th colspan="2">' + _('Quick Reply') + '</th></tr>');
|
|
|
|
|
|
|
|
$postForm.attr('id', 'quick-reply');
|
|
|
|
|
|
|
|
$postForm.appendTo($('body'));
|
|
|
|
|
|
|
|
// Synchronise body text with original post form
|
|
|
|
$('#body').bind('change input propertychange', function() {
|
|
|
|
$postForm.find('textarea[name="body"]').val($(this).val());
|
|
|
|
});
|
|
|
|
$postForm.find('textarea[name="body"]').bind('change input propertychange', function() {
|
|
|
|
$('#body').val($(this).val());
|
|
|
|
});
|
|
|
|
// Synchronise other inputs
|
2013-09-14 18:00:02 -04:00
|
|
|
$('form[name="post"]:first input[type="text"],select').bind('change input propertychange', function() {
|
2013-09-14 17:40:49 -04:00
|
|
|
$postForm.find('[name="' + $(this).attr('name') + '"]').val($(this).val());
|
2013-09-14 17:17:02 -04:00
|
|
|
});
|
2013-09-14 17:37:57 -04:00
|
|
|
$postForm.find('input[type="text"],select').bind('change input propertychange', function() {
|
2013-09-14 18:00:02 -04:00
|
|
|
$('form[name="post"]:first [name="' + $(this).attr('name') + '"]').val($(this).val());
|
|
|
|
});
|
|
|
|
|
|
|
|
$origPostForm = $('form[name="post"]');
|
|
|
|
|
|
|
|
$(window).scroll(function() {
|
|
|
|
if ($(this).scrollTop() < $origPostForm.offset().top + $origPostForm.height() - 100)
|
|
|
|
$postForm.fadeOut(100);
|
|
|
|
else
|
|
|
|
$postForm.fadeIn(100);
|
2013-09-14 17:17:02 -04:00
|
|
|
});
|
|
|
|
};
|
2012-03-14 04:41:56 -04:00
|
|
|
|
2013-09-14 17:31:05 -04:00
|
|
|
$(window).on('cite', function(e, id, with_link) {
|
2013-09-14 17:17:02 -04:00
|
|
|
show_quick_reply();
|
|
|
|
$('#quick-reply textarea').focus();
|
2013-09-14 17:31:05 -04:00
|
|
|
if (with_link) {
|
|
|
|
console.log(id, with_link);
|
|
|
|
setTimeout(function() {
|
|
|
|
highlightReply(id);
|
|
|
|
$(window).scrollTop($('#' + id).offset().top);
|
|
|
|
}, 10);
|
|
|
|
}
|
2013-09-14 17:17:02 -04:00
|
|
|
});
|