Last active
August 29, 2015 13:57
-
-
Save Juribiyan/9776282 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Вставить это в $(document).ready(funciton() {}) */ | |
//Вешаем обработчкик на кнопки быстрого ответа | |
$('body').on('click', '.qrl', quickreply); | |
//Клонируем форму, присваиваем ей ID #postclone, добавляем проверку введенной капчи (функцию checkcaptcha нужно будет модифицировать, см. ниже), добавляем классы для придания стиля, убираем из формы .rules | |
$('#postform').clone().attr({'id': 'postclone', 'onsubmit': "return checkcaptcha('postclone');"}).appendTo('body').hide().addClass('reflinkpreview content-background qreplyform').find('.rules').remove(); | |
//Меняем id инпутов и сответствующих лейблов в клоне формы (для того, чтобы по клике по лейблу кликались чекбоксы) | |
$('#postclone label').each(function() { | |
var newid = $(this).attr('for')+'_clone'; | |
$(this).attr('for', newid); | |
$(this).find('input').attr('id', newid); | |
}); | |
//Делаем форму перетаскиваемой с помощью jQuery плагина (см. ниже). Все инпуты внутри формы не должны реагировать на перетаскивание. | |
$('input, textarea, select, label').hover(function() { | |
$('#postclone').dragsOff(); | |
}, function() { | |
$('#postclone').drags(); | |
}); | |
//Добавляем кнопку закрытия | |
$('<span class="extrabtns postboxcontrol">' | |
+'<a href="#" onclick="javascript:$(\'#postclone\').hide();return false;" title="Закрыть">' | |
+'<img src="'+ku_boardspath+'/css/icons/blank.gif" border="0" class="closebox spritebtn"></a>' | |
+'</span>').appendTo('#postclone'); | |
//jQuery плагин для таскания | |
(function($) { | |
$.fn.drags = function(opt) { | |
opt = $.extend({handle:"",cursor:"move"}, opt); | |
if(opt.handle === "") { | |
var $el = this; | |
} else { | |
var $el = this.find(opt.handle); | |
} | |
return $el.css('cursor', opt.cursor).on("mousedown", function(e) { | |
if(opt.handle === "") { | |
var $drag = $(this).addClass('draggable'); | |
} else { | |
var $drag = $(this).addClass('active-handle').parent().addClass('draggable'); | |
} | |
var z_idx = $drag.css('z-index'), | |
drg_h = $drag.outerHeight(), | |
drg_w = $drag.outerWidth(), | |
pos_y = $drag.offset().top + drg_h - e.pageY, | |
pos_x = $drag.offset().left + drg_w - e.pageX; | |
$drag.css('z-index', 1000).parents().on("mousemove", function(e) { | |
$('.draggable').offset({ | |
top:e.pageY + pos_y - drg_h, | |
left:e.pageX + pos_x - drg_w | |
}).on("mouseup", function() { | |
$(this).removeClass('draggable').css('z-index', z_idx); | |
}); | |
}); | |
e.preventDefault(); // disable selection | |
}).on("mouseup", function() { | |
if(opt.handle === "") { | |
$(this).removeClass('draggable'); | |
} else { | |
$(this).removeClass('active-handle').parent().removeClass('draggable'); | |
} | |
}); | |
} | |
$.fn.dragsOff = function(opt) { | |
opt = $.extend({handle:"",cursor:"default"}, opt); | |
if(opt.handle === "") { | |
var $el = this; | |
$(this).removeClass('draggable'); | |
} else { | |
var $el = this.find(opt.handle); | |
$(this).removeClass('active-handle') | |
.parent() | |
.removeClass('draggable'); | |
} | |
return $el.css('cursor', "default") | |
.off("mousedown") | |
.off("mouseup") | |
.off("mousemove"); | |
} | |
})(jQuery); | |
//Функция quickreply | |
function quickreply(ev) { | |
// Если кликнули по превью поста с другой доски, отвечать нужно в соответствующую доску (редкий случай) | |
var externalBoard = $(this).data('boardname'); | |
if(externalBoard === this_board_dir) externalBoard = false; | |
var parent = $(this).data('parent'), current = $(this).data('postnum') || parent; | |
// Проверяем, отображается ли форма уже | |
var appearsNew = ($('#postclone').css('display') === 'none'); | |
$('#postclone').show(); | |
// Если форма не была отображена. когда кликнули по .qrl, нужно ее спозиционировать | |
if(appearsNew) { | |
$('#postclone').css({ | |
top: $(this).offset().top + $(this).height() - $(document).scrollTop(), | |
left: Math.round(($(window).width() / 2) - ($('#postclone').width() / 2)), | |
position: 'fixed' | |
}); | |
} | |
// Вводим значения форм | |
$('#postclone input[name="replythread"]').val(parent); | |
if(externalBoard) { | |
$('#postclone input[name="board"]').val(externalBoard); | |
$('#postclone #posttypeindicator').html('<a href="../'+externalBoard+'/res/'+parent+'.html?i#'+current+'"> >>/'+externalBoard+'/'+parent+'</a>'); | |
} | |
else { | |
$('#postclone #posttypeindicator').html('<a class="xlink" href="#'+current+'"> >>'+parent+'</a>'); | |
} | |
//Добавляем '>>' | |
insert('>>'+current+'\n'); | |
return false; | |
} | |
//Функция checkcaptcha (если у тебя такая была (на нульчах есть)) | |
function checkcaptcha(formid) { | |
if($('input[name=captcha]').length > 0) { | |
if ($('#'+formid+'input[name=captcha]').val() =='') { | |
popupMessage(_.enterCaptcha); | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment