forked from leftypol/leftypol
quick-reply.js: format
This commit is contained in:
parent
50bb090952
commit
81f5c70681
1 changed files with 51 additions and 51 deletions
|
@ -15,10 +15,10 @@
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var settings = new script_settings('quick-reply');
|
var settings = new script_settings('quick-reply');
|
||||||
|
|
||||||
var do_css = function() {
|
var do_css = function() {
|
||||||
$('#quick-reply-css').remove();
|
$('#quick-reply-css').remove();
|
||||||
|
|
||||||
// Find background of reply posts
|
// Find background of reply posts
|
||||||
var dummy_reply = $('<div class="post reply"></div>').appendTo($('body'));
|
var dummy_reply = $('<div class="post reply"></div>').appendTo($('body'));
|
||||||
var reply_background = dummy_reply.css('backgroundColor');
|
var reply_background = dummy_reply.css('backgroundColor');
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
var reply_border_color = dummy_reply.css('borderColor');
|
var reply_border_color = dummy_reply.css('borderColor');
|
||||||
var reply_border_width = dummy_reply.css('borderWidth');
|
var reply_border_width = dummy_reply.css('borderWidth');
|
||||||
dummy_reply.remove();
|
dummy_reply.remove();
|
||||||
|
|
||||||
$('<style type="text/css" id="quick-reply-css">\
|
$('<style type="text/css" id="quick-reply-css">\
|
||||||
#quick-reply {\
|
#quick-reply {\
|
||||||
position: fixed;\
|
position: fixed;\
|
||||||
|
@ -120,57 +120,57 @@
|
||||||
}\
|
}\
|
||||||
</style>').appendTo($('head'));
|
</style>').appendTo($('head'));
|
||||||
};
|
};
|
||||||
|
|
||||||
var show_quick_reply = function(){
|
var show_quick_reply = function(){
|
||||||
if($('div.banner').length == 0)
|
if($('div.banner').length == 0)
|
||||||
return;
|
return;
|
||||||
if($('#quick-reply').length != 0)
|
if($('#quick-reply').length != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
do_css();
|
do_css();
|
||||||
|
|
||||||
var $postForm = $('form[name="post"]').clone();
|
var $postForm = $('form[name="post"]').clone();
|
||||||
|
|
||||||
$postForm.clone();
|
$postForm.clone();
|
||||||
|
|
||||||
$dummyStuff = $('<div class="nonsense"></div>').appendTo($postForm);
|
$dummyStuff = $('<div class="nonsense"></div>').appendTo($postForm);
|
||||||
|
|
||||||
$postForm.find('table tr').each(function() {
|
$postForm.find('table tr').each(function() {
|
||||||
var $th = $(this).children('th:first');
|
var $th = $(this).children('th:first');
|
||||||
var $td = $(this).children('td:first');
|
var $td = $(this).children('td:first');
|
||||||
if ($th.length && $td.length) {
|
if ($th.length && $td.length) {
|
||||||
$td.attr('colspan', 2);
|
$td.attr('colspan', 2);
|
||||||
|
|
||||||
if ($td.find('input[type="text"]').length) {
|
if ($td.find('input[type="text"]').length) {
|
||||||
// Replace <th> with input placeholders
|
// Replace <th> with input placeholders
|
||||||
$td.find('input[type="text"]')
|
$td.find('input[type="text"]')
|
||||||
.removeAttr('size')
|
.removeAttr('size')
|
||||||
.attr('placeholder', $th.clone().children().remove().end().text());
|
.attr('placeholder', $th.clone().children().remove().end().text());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move anti-spam nonsense and remove <th>
|
// Move anti-spam nonsense and remove <th>
|
||||||
$th.contents().filter(function() {
|
$th.contents().filter(function() {
|
||||||
return this.nodeType == 3; // Node.TEXT_NODE
|
return this.nodeType == 3; // Node.TEXT_NODE
|
||||||
}).remove();
|
}).remove();
|
||||||
$th.contents().appendTo($dummyStuff);
|
$th.contents().appendTo($dummyStuff);
|
||||||
$th.remove();
|
$th.remove();
|
||||||
|
|
||||||
if ($td.find('input[name="password"]').length) {
|
if ($td.find('input[name="password"]').length) {
|
||||||
// Hide password field
|
// Hide password field
|
||||||
$(this).hide();
|
$(this).hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix submit button
|
// Fix submit button
|
||||||
if ($td.find('input[type="submit"]').length) {
|
if ($td.find('input[type="submit"]').length) {
|
||||||
$td.removeAttr('colspan');
|
$td.removeAttr('colspan');
|
||||||
$('<td class="submit"></td>').append($td.find('input[type="submit"]')).insertAfter($td);
|
$('<td class="submit"></td>').append($td.find('input[type="submit"]')).insertAfter($td);
|
||||||
}
|
}
|
||||||
|
|
||||||
// reCAPTCHA
|
// reCAPTCHA
|
||||||
if ($td.find('#recaptcha_widget_div').length) {
|
if ($td.find('#recaptcha_widget_div').length) {
|
||||||
// Just show the image, and have it interact with the real form.
|
// Just show the image, and have it interact with the real form.
|
||||||
var $captchaimg = $td.find('#recaptcha_image img');
|
var $captchaimg = $td.find('#recaptcha_image img');
|
||||||
|
|
||||||
$captchaimg
|
$captchaimg
|
||||||
.removeAttr('id')
|
.removeAttr('id')
|
||||||
.removeAttr('style')
|
.removeAttr('style')
|
||||||
|
@ -178,7 +178,7 @@
|
||||||
.click(function() {
|
.click(function() {
|
||||||
$('#recaptcha_reload').click();
|
$('#recaptcha_reload').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
// When we get a new captcha...
|
// When we get a new captcha...
|
||||||
$('#recaptcha_response_field').focus(function() {
|
$('#recaptcha_response_field').focus(function() {
|
||||||
if ($captchaimg.attr('src') != $('#recaptcha_image img').attr('src')) {
|
if ($captchaimg.attr('src') != $('#recaptcha_image img').attr('src')) {
|
||||||
|
@ -187,13 +187,13 @@
|
||||||
$postForm.find('input[name="recaptcha_response_field"]').val('').focus();
|
$postForm.find('input[name="recaptcha_response_field"]').val('').focus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$postForm.submit(function() {
|
$postForm.submit(function() {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
$('#recaptcha_reload').click();
|
$('#recaptcha_reload').click();
|
||||||
}, 200);
|
}, 200);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Make a new row for the response text
|
// Make a new row for the response text
|
||||||
var $newRow = $('<tr><td class="recaptcha-response" colspan="2"></td></tr>');
|
var $newRow = $('<tr><td class="recaptcha-response" colspan="2"></td></tr>');
|
||||||
$newRow.children().first().append(
|
$newRow.children().first().append(
|
||||||
|
@ -203,37 +203,37 @@
|
||||||
.removeAttr('id')
|
.removeAttr('id')
|
||||||
.addClass('recaptcha_response_field')
|
.addClass('recaptcha_response_field')
|
||||||
.attr('placeholder', $('#recaptcha_response_field').attr('placeholder'));
|
.attr('placeholder', $('#recaptcha_response_field').attr('placeholder'));
|
||||||
|
|
||||||
$('#recaptcha_response_field').addClass('recaptcha_response_field')
|
$('#recaptcha_response_field').addClass('recaptcha_response_field')
|
||||||
|
|
||||||
$td.replaceWith($('<td class="recaptcha" colspan="2"></td>').append($('<span></span>').append($captchaimg)));
|
$td.replaceWith($('<td class="recaptcha" colspan="2"></td>').append($('<span></span>').append($captchaimg)));
|
||||||
|
|
||||||
$newRow.insertAfter(this);
|
$newRow.insertAfter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upload section
|
// Upload section
|
||||||
if ($td.find('input[type="file"]').length) {
|
if ($td.find('input[type="file"]').length) {
|
||||||
if ($td.find('input[name="file_url"]').length) {
|
if ($td.find('input[name="file_url"]').length) {
|
||||||
$file_url = $td.find('input[name="file_url"]');
|
$file_url = $td.find('input[name="file_url"]');
|
||||||
|
|
||||||
if (settings.get('show_remote', false)) {
|
if (settings.get('show_remote', false)) {
|
||||||
// Make a new row for it
|
// Make a new row for it
|
||||||
var $newRow = $('<tr><td colspan="2"></td></tr>');
|
var $newRow = $('<tr><td colspan="2"></td></tr>');
|
||||||
|
|
||||||
$file_url.clone().attr('placeholder', _('Upload URL')).appendTo($newRow.find('td'));
|
$file_url.clone().attr('placeholder', _('Upload URL')).appendTo($newRow.find('td'));
|
||||||
|
|
||||||
$newRow.insertBefore(this);
|
$newRow.insertBefore(this);
|
||||||
}
|
}
|
||||||
$file_url.parent().remove();
|
$file_url.parent().remove();
|
||||||
|
|
||||||
|
|
||||||
$td.find('label').remove();
|
$td.find('label').remove();
|
||||||
$td.contents().filter(function() {
|
$td.contents().filter(function() {
|
||||||
return this.nodeType == 3; // Node.TEXT_NODE
|
return this.nodeType == 3; // Node.TEXT_NODE
|
||||||
}).remove();
|
}).remove();
|
||||||
$td.find('input[name="file_url"]').removeAttr('id');
|
$td.find('input[name="file_url"]').removeAttr('id');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($(this).find('input[name="spoiler"]').length) {
|
if ($(this).find('input[name="spoiler"]').length) {
|
||||||
$td.removeAttr('colspan');
|
$td.removeAttr('colspan');
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@
|
||||||
if ($td.is('#upload_selection')) {
|
if ($td.is('#upload_selection')) {
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove mod controls, because it looks shit.
|
// Remove mod controls, because it looks shit.
|
||||||
if ($td.find('input[type="checkbox"]').length) {
|
if ($td.find('input[type="checkbox"]').length) {
|
||||||
var tr = this;
|
var tr = this;
|
||||||
|
@ -271,15 +271,15 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$td.find('small').hide();
|
$td.find('small').hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$postForm.find('textarea[name="body"]').removeAttr('id').removeAttr('cols').attr('placeholder', _('Comment'));
|
$postForm.find('textarea[name="body"]').removeAttr('id').removeAttr('cols').attr('placeholder', _('Comment'));
|
||||||
|
|
||||||
$postForm.find('textarea:not([name="body"]),input[type="hidden"]').removeAttr('id').appendTo($dummyStuff);
|
$postForm.find('textarea:not([name="body"]),input[type="hidden"]').removeAttr('id').appendTo($dummyStuff);
|
||||||
|
|
||||||
$postForm.find('br').remove();
|
$postForm.find('br').remove();
|
||||||
$postForm.find('table').prepend('<tr><th colspan="2">\
|
$postForm.find('table').prepend('<tr><th colspan="2">\
|
||||||
<span class="handle">\
|
<span class="handle">\
|
||||||
|
@ -287,12 +287,12 @@
|
||||||
' + _('Quick Reply') + '\
|
' + _('Quick Reply') + '\
|
||||||
</span>\
|
</span>\
|
||||||
</th></tr>');
|
</th></tr>');
|
||||||
|
|
||||||
$postForm.attr('id', 'quick-reply');
|
$postForm.attr('id', 'quick-reply');
|
||||||
|
|
||||||
$postForm.appendTo($('body')).hide();
|
$postForm.appendTo($('body')).hide();
|
||||||
$origPostForm = $('form[name="post"]:first');
|
$origPostForm = $('form[name="post"]:first');
|
||||||
|
|
||||||
// Synchronise body text with original post form
|
// Synchronise body text with original post form
|
||||||
$origPostForm.find('textarea[name="body"]').on('change input propertychange', function() {
|
$origPostForm.find('textarea[name="body"]').on('change input propertychange', function() {
|
||||||
$postForm.find('textarea[name="body"]').val($(this).val());
|
$postForm.find('textarea[name="body"]').val($(this).val());
|
||||||
|
@ -316,7 +316,7 @@
|
||||||
$origPostForm.find('[name="' + $(this).attr('name') + '"]').val($(this).val());
|
$origPostForm.find('[name="' + $(this).attr('name') + '"]').val($(this).val());
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof $postForm.draggable != 'undefined') {
|
if (typeof $postForm.draggable != 'undefined') {
|
||||||
if (localStorage.quickReplyPosition) {
|
if (localStorage.quickReplyPosition) {
|
||||||
var offset = JSON.parse(localStorage.quickReplyPosition);
|
var offset = JSON.parse(localStorage.quickReplyPosition);
|
||||||
if (offset.top < 0)
|
if (offset.top < 0)
|
||||||
|
@ -338,26 +338,26 @@
|
||||||
right: $(window).width() - $(this).offset().left - $(this).width(),
|
right: $(window).width() - $(this).offset().left - $(this).width(),
|
||||||
};
|
};
|
||||||
localStorage.quickReplyPosition = JSON.stringify(offset);
|
localStorage.quickReplyPosition = JSON.stringify(offset);
|
||||||
|
|
||||||
$postForm.css('right', offset.right).css('top', offset.top).css('left', 'auto');
|
$postForm.css('right', offset.right).css('top', offset.top).css('left', 'auto');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$postForm.find('th .handle').css('cursor', 'move');
|
$postForm.find('th .handle').css('cursor', 'move');
|
||||||
}
|
}
|
||||||
|
|
||||||
$postForm.find('th .close-btn').click(function() {
|
$postForm.find('th .close-btn').click(function() {
|
||||||
$origPostForm.find('textarea[name="body"]').attr('id', 'body');
|
$origPostForm.find('textarea[name="body"]').attr('id', 'body');
|
||||||
$postForm.remove();
|
$postForm.remove();
|
||||||
floating_link();
|
floating_link();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fix bug when table gets too big for form. Shouldn't exist, but crappy CSS etc.
|
// Fix bug when table gets too big for form. Shouldn't exist, but crappy CSS etc.
|
||||||
$postForm.show();
|
$postForm.show();
|
||||||
$postForm.width($postForm.find('table').width());
|
$postForm.width($postForm.find('table').width());
|
||||||
$postForm.hide();
|
$postForm.hide();
|
||||||
|
|
||||||
$(window).trigger('quick-reply');
|
$(window).trigger('quick-reply');
|
||||||
|
|
||||||
$(window).ready(function() {
|
$(window).ready(function() {
|
||||||
if (settings.get('hide_at_top', true)) {
|
if (settings.get('hide_at_top', true)) {
|
||||||
$(window).scroll(function() {
|
$(window).scroll(function() {
|
||||||
|
@ -371,7 +371,7 @@
|
||||||
} else {
|
} else {
|
||||||
$postForm.show();
|
$postForm.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
$(window).on('stylesheet', function() {
|
$(window).on('stylesheet', function() {
|
||||||
do_css();
|
do_css();
|
||||||
if ($('link#stylesheet').attr('href')) {
|
if ($('link#stylesheet').attr('href')) {
|
||||||
|
@ -380,7 +380,7 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$(window).on('cite', function(e, id, with_link) {
|
$(window).on('cite', function(e, id, with_link) {
|
||||||
if ($(this).width() <= 400)
|
if ($(this).width() <= 400)
|
||||||
return;
|
return;
|
||||||
|
@ -391,7 +391,7 @@
|
||||||
highlightReply(id);
|
highlightReply(id);
|
||||||
$(document).scrollTop($('#' + id).offset().top);
|
$(document).scrollTop($('#' + id).offset().top);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Honestly, I'm not sure why we need setTimeout() here, but it seems to work.
|
// Honestly, I'm not sure why we need setTimeout() here, but it seems to work.
|
||||||
// Same for the "tmp" variable stuff you see inside here:
|
// Same for the "tmp" variable stuff you see inside here:
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
@ -401,7 +401,7 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var floating_link = function() {
|
var floating_link = function() {
|
||||||
if (!settings.get('floating_link', false))
|
if (!settings.get('floating_link', false))
|
||||||
return;
|
return;
|
||||||
|
@ -410,12 +410,12 @@
|
||||||
show_quick_reply();
|
show_quick_reply();
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
}).appendTo($('body'));
|
}).appendTo($('body'));
|
||||||
|
|
||||||
$(window).on('quick-reply', function() {
|
$(window).on('quick-reply', function() {
|
||||||
$('.quick-reply-btn').remove();
|
$('.quick-reply-btn').remove();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (settings.get('floating_link', false)) {
|
if (settings.get('floating_link', false)) {
|
||||||
$(window).ready(function() {
|
$(window).ready(function() {
|
||||||
if($('div.banner').length == 0)
|
if($('div.banner').length == 0)
|
||||||
|
@ -430,12 +430,12 @@
|
||||||
text-decoration: none;\
|
text-decoration: none;\
|
||||||
}\
|
}\
|
||||||
</style>').appendTo($('head'));
|
</style>').appendTo($('head'));
|
||||||
|
|
||||||
floating_link();
|
floating_link();
|
||||||
|
|
||||||
if (settings.get('hide_at_top', true)) {
|
if (settings.get('hide_at_top', true)) {
|
||||||
$('.quick-reply-btn').hide();
|
$('.quick-reply-btn').hide();
|
||||||
|
|
||||||
$(window).scroll(function() {
|
$(window).scroll(function() {
|
||||||
if ($(this).width() <= 400)
|
if ($(this).width() <= 400)
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue