// source --> https://sindroms.ru/wp-content/plugins/wpdiscuz/assets/js/wpdiscuz.js?ver=4.1.4
jQuery(document).ready(function ($) {
$('body').addClass('wpdiscuz_' + wpdiscuzAjaxObj.wpdiscuz_options.version);
var isUserLoggedIn = wpdiscuzAjaxObj.wpdiscuz_options.is_user_logged_in;
var isShowCaptchaForGuests = wpdiscuzAjaxObj.wpdiscuz_options.wc_captcha_show_for_guest == 1 && !isUserLoggedIn;
var isShowCaptchaForMembers = wpdiscuzAjaxObj.wpdiscuz_options.wc_captcha_show_for_members == 1 && isUserLoggedIn;
var isCaptchaInSession = wpdiscuzAjaxObj.wpdiscuz_options.isCaptchaInSession;
var wpdiscuzRecaptcha = wpdiscuzAjaxObj.wpdiscuz_options.wpDiscuzReCaptcha;
var isGoodbyeCaptchaActive = wpdiscuzAjaxObj.wpdiscuz_options.isGoodbyeCaptchaActive;
var commentListLoadType = wpdiscuzAjaxObj.wpdiscuz_options.commentListLoadType;
var lazyLoadOnPageLoad = wpdiscuzAjaxObj.wpdiscuz_options.lazyLoadOnPageLoad;
var wordpressIsPaginate = wpdiscuzAjaxObj.wpdiscuz_options.wordpressIsPaginate;
var wpdiscuzPostId = wpdiscuzAjaxObj.wpdiscuz_options.wc_post_id;
var commentListUpdateType = wpdiscuzAjaxObj.wpdiscuz_options.commentListUpdateType;
var commentListUpdateTimer = wpdiscuzAjaxObj.wpdiscuz_options.commentListUpdateTimer;
var disableGuestsLiveUpdate = wpdiscuzAjaxObj.wpdiscuz_options.liveUpdateGuests;
var loadLastCommentId = wpdiscuzAjaxObj.wpdiscuz_options.loadLastCommentId;
var wpdiscuzCommentOrder = wpdiscuzAjaxObj.wpdiscuz_options.wordpress_comment_order;
var commentsVoteOrder = wpdiscuzAjaxObj.wpdiscuz_options.commentsVoteOrder;
var storeCommenterData = wpdiscuzAjaxObj.wpdiscuz_options.storeCommenterData;
var wpdiscuzLoadCount = commentListLoadType == 2 && !lazyLoadOnPageLoad ? 0 : 1;
var wpdiscuzCommentOrderBy = 'comment_date_gmt';
var wpdiscuzReplyArray = [];
var wpdiscuzCommentArray = [];
var wpdiscuzUploader = wpdiscuzAjaxObj.wpdiscuz_options.uploader;
var commentTextMaxLength = wpdiscuzAjaxObj.wpdiscuz_options.commentTextMaxLength;
var wpdGoogleRecaptchaValid = true;
var wpdiscuzReplyButton = '';
var wpdiscuzCookiehash = wpdiscuzAjaxObj.wpdiscuz_options.cookiehash;
var isLoadOnlyParentComments = wpdiscuzAjaxObj.wpdiscuz_options.isLoadOnlyParentComments;
loginButtonsClone();
if (!wpdiscuzAjaxObj.wpdiscuz_options.wordpressIsPaginate) {
var wpdiscuzLastVisitKey = wpdiscuzAjaxObj.wpdiscuz_options.lastVisitKey;
var wpdiscuzLastVisit = wpdiscuzAjaxObj.wpdiscuz_options.lastVisitCookie;
var wpdiscuzLastVisitExpires = wpdiscuzAjaxObj.wpdiscuz_options.lastVisitExpires;
Cookies.set(wpdiscuzLastVisitKey, (JSON.stringify(wpdiscuzLastVisit)), {expires: wpdiscuzLastVisitExpires, path: window.location});
}
if (commentsVoteOrder) {
$('.wpdiscuz-vote-sort-up').addClass('wpdiscuz-sort-button-active');
wpdiscuzCommentOrderBy = 'by_vote';
} else {
$('.wpdiscuz-date-sort-' + wpdiscuzCommentOrder).addClass('wpdiscuz-sort-button-active');
}
$('#wc_unsubscribe_message').delay(4000).fadeOut(1500, function () {
$(this).remove();
location.href = location.href.substring(0, location.href.indexOf('subscribeAnchor') - 1);
});
if ($('.wc_main_comm_form').length) {
setCookieInForm();
wpdiscuzReplaceValidationUI($('.wc_main_comm_form')[0]);
}
$(document).delegate('.wc-reply-button', 'click', function () {
wpdiscuzReplyButton = $(this);
if ($(this).hasClass('wpdiscuz-clonned')) {
$('#wc-secondary-form-wrapper-' + getUniqueID($(this), 0)).slideToggle(700);
} else {
cloneSecondaryForm($(this));
}
$(this).toggleClass('wc-cta-active');
setCookieInForm();
});
$(document).delegate('.wc-comment-img-link', 'click', function () {
$(this).parents('.wc-comment-img-link-wrap').find('span').toggleClass('wc-comment-img-link-show');
});
$(document).delegate('textarea.wc_comment', 'focus', function () {
var parent = $(this).parents('.wc-form-wrapper');
$('.commentTextMaxLength', parent).show();
$('.wc-form-footer', parent).slideDown(700);
});
$(document).delegate('#wpcomm textarea', 'focus', function () {
if (!($(this).next('.autogrow-textarea-mirror').length)) {
$(this).autoGrow();
}
});
$(document).delegate('textarea.wc_comment', 'blur', function () {
var parent = $(this).parents('.wc-form-wrapper');
$('.commentTextMaxLength', parent).hide();
});
$(document).delegate('textarea.wc_comment', 'keyup', function () {
setTextareaCharCount($(this), commentTextMaxLength);
});
$.each($('textarea.wc_comment'), function () {
setTextareaCharCount($(this), commentTextMaxLength);
});
$(document).delegate('.wc-share-link', 'click', function () {
var parent = $(this).parents('.wc-comment-right');
$(this).toggleClass('wc-cta-active');
if ($(this).hasClass('wc-cta-active')) {
$('.share_buttons_box', parent).show();
} else {
$('.share_buttons_box', parent).hide();
}
});
$(document).delegate('.wpdiscuz-nofollow,.wc_captcha_refresh_img,.wc-toggle,.wc-load-more-link', 'click', function (e) {
e.preventDefault();
});
$(document).delegate('.wc-toggle', 'click', function () {
var uniqueID = getUniqueID($(this), 0);
var toggle = $(this);
var icon = $('.fa', toggle);
if (icon.hasClass('wpdiscuz-show-replies') && isLoadOnlyParentComments) {
wpdiscuzShowReplies(uniqueID);
} else {
$('#wc-comm-' + uniqueID + '> .wc-reply').slideToggle(700, function () {
if ($(this).is(':hidden')) {
icon.removeClass('fa-chevron-up');
icon.addClass('fa-chevron-down');
icon.attr('title', wpdiscuzAjaxObj.wpdiscuz_options.wc_show_replies_text);
} else {
icon.removeClass('fa-chevron-down');
icon.addClass('fa-chevron-up');
icon.attr('title', wpdiscuzAjaxObj.wpdiscuz_options.wc_hide_replies_text);
}
});
$('.wpdiscuz-children', toggle).toggleClass('wpdiscuz-hidden');
if ($('.wpdiscuz-children-count', toggle).length) {
var replies = $('#wc-comm-' + uniqueID + ' .wc-reply');
$('.wpdiscuz-children-count', toggle).html(replies.length);
}
}
});
$(document).delegate('.wc-new-loaded-comment', 'mouseenter', function () {
if ($(this).hasClass('wc-reply')) {
$('>.wc-comment-right', this).css('backgroundColor', wpdiscuzAjaxObj.wpdiscuz_options.wc_reply_bg_color);
} else {
$('>.wc-comment-right', this).css('backgroundColor', wpdiscuzAjaxObj.wpdiscuz_options.wc_comment_bg_color);
}
});
//============================== CAPTCHA ============================== //
$(document).delegate('.wc_captcha_refresh_img', 'click', function () {
changeCaptchaImage($(this));
});
function changeCaptchaImage(reloadImage) {
if (!wpdiscuzRecaptcha && !isGoodbyeCaptchaActive && (isShowCaptchaForGuests || isShowCaptchaForMembers)) {
var form = reloadImage.parents('.wc-form-wrapper');
var keyField = $('.wpdiscuz-cnonce', form);
if (isCaptchaInSession) {
var uuId = getUUID();
var captchaImg = $(reloadImage).prev().children('.wc_captcha_img');
var src = captchaImg.attr('src');
var fileUrl = src.substring(0, src.indexOf('=') + 1);
captchaImg.attr('src', fileUrl + uuId + '&r=' + Math.random());
keyField.attr('id', uuId);
keyField.attr('value', uuId);
} else {
var data = new FormData();
data.append('action', 'generateCaptcha');
var isMain = form.hasClass('wc-secondary-form-wrapper') ? 0 : 1;
var uniqueId = getUniqueID(reloadImage, isMain);
data.append('wpdiscuz_unique_id', uniqueId);
var ajaxObject = getAjaxObj(data);
ajaxObject.done(function (response) {
try {
var obj = $.parseJSON(response);
if (obj.code == 1) {
var captchaImg = $(reloadImage).prev().children('.wc_captcha_img');
var src = captchaImg.attr('src');
var lastSlashIndex = src.lastIndexOf('/') + 1;
var newSrc = src.substring(0, lastSlashIndex) + obj.message;
captchaImg.attr('src', newSrc);
keyField.attr('id', obj.key);
keyField.attr('value', obj.key);
}
} catch (e) {
console.log(e);
}
$('.wpdiscuz-loading-bar').hide();
});
}
}
}
function getUUID() {
var chars = '123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var uuId = 'c';
for (i = 0; i < 13; i++) {
uuId += chars[Math.floor(Math.random() * (chars.length - 1) + 1)];
}
return uuId;
}
//============================== CAPTCHA ============================== //
//============================== ADD COMMENT FUNCTION ============================== //
$(document).delegate('.wc_comm_submit.wc_not_clicked', 'click', function () {
var currentSubmitBtn = $(this);
var depth = 1;
var wcForm = $(this).parents('form');
if (!wcForm.hasClass('wc_main_comm_form')) {
depth = getCommentDepth($(this).parents('.wc-comment'));
}
if (!wpdiscuzAjaxObj.wpdiscuz_options.is_email_field_required && $('.wc_email', wcForm).val()) {
$('.wc_email', wcForm).attr('required', 'required');
}
if (!wpdiscuzAjaxObj.wpdiscuz_options.is_email_field_required && !($('.wc_email', wcForm).val())) {
$('.wc_email', wcForm).removeAttr('required');
}
wpdGoogleRecaptchaValid = true;
wpdValidateFieldRequired(wcForm);
wcForm.submit(function (event) {
event.preventDefault();
});
if (wcForm[0].checkValidity() && wpdGoogleRecaptchaValid) {
$(currentSubmitBtn).removeClass('wc_not_clicked');
var data = new FormData();
data.append('action', 'addComment');
var inputs = $(":input", wcForm);
inputs.each(function () {
if (this.name != '' && this.type != 'checkbox' && this.type != 'radio') {
data.append(this.name + '', $(this).val());
}
if (this.type == 'checkbox' || this.type == 'radio') {
if ($(this).is(':checked')) {
data.append(this.name + '', $(this).val());
}
}
});
data.append('wc_comment_depth', depth);
if (wpdiscuzUploader == 1) {
var images = $(wcForm).find('input.wmu-image');
var videos = $(wcForm).find('input.wmu-video');
var files = $(wcForm).find('input.wmu-file');
if (images.length > 0) {
$.each($(images), function (i, imageFile) {
if (imageFile.files.length > 0) {
$.each(imageFile.files, function (j, imageObj) {
data.append('wmu_images[' + i + ']', imageObj);
});
}
});
}
if (videos.length > 0) {
$.each($(videos), function (i, videoFile) {
if (videoFile.files.length > 0) {
$.each(videoFile.files, function (j, videoObj) {
data.append('wmu_videos[' + i + ']', videoObj);
});
}
});
}
if (files.length > 0) {
$.each($(files), function (i, file) {
if (file.files.length > 0) {
$.each(file.files, function (j, fileObj) {
data.append('wmu_files[' + i + ']', fileObj);
});
}
});
}
}
if (!wpdiscuzRecaptcha && !isGoodbyeCaptchaActive && (isShowCaptchaForGuests || isShowCaptchaForMembers) && !isCaptchaInSession) {
var image = $('.wc_captcha_img', wcForm);
var src = image.attr('src');
var lastIndex = src.lastIndexOf('/') + 1;
var fileName = src.substring(lastIndex);
data.append('fileName', fileName);
}
if (Cookies.get('comment_author_' + wpdiscuzCookiehash) && !$('.wc_name', wcForm).val()) {
data.append('wc_name', Cookies.get('comment_author_' + wpdiscuzCookiehash));
}
if (Cookies.get('comment_author_email_' + wpdiscuzCookiehash) && !$('.wc_email', wcForm).val()) {
data.append('wc_email', Cookies.get('comment_author_email_' + wpdiscuzCookiehash));
}
if (wpdiscuzAjaxObj.wpdiscuz_options.wpdiscuz_zs) {
data.append('wpdiscuz_zs', wpdiscuzAjaxObj.wpdiscuz_options.wpdiscuz_zs);
}
getAjaxObj(data).done(function (response) {
$(currentSubmitBtn).addClass('wc_not_clicked');
var messageKey = '';
var message = '';
try {
var obj = $.parseJSON(response);
messageKey = obj.code;
if (parseInt(messageKey) >= 0) {
var isMain = obj.is_main;
message = obj.message;
$('.wc_header_text_count').html(obj.wc_all_comments_count_new);
if (isMain) {
$('.wc-thread-wrapper').prepend(message);
} else {
$('#wc-secondary-form-wrapper-' + messageKey).slideToggle(700);
if (obj.is_in_same_container == 1) {
$('#wc-secondary-form-wrapper-' + messageKey).after(message);
} else {
$('#wc-secondary-form-wrapper-' + messageKey).after(message.replace('wc-reply', 'wc-reply wc-no-left-margin'));
}
}
if (obj.held_moderate == 1) {
var moderateCommentTime = 30 * 24 * 60 * 60;
var moderateComments = '';
if (Cookies.get('wc_moderate_comments_' + wpdiscuzPostId)) {
moderateComments = Cookies.get('wc_moderate_comments_' + wpdiscuzPostId);
}
moderateComments += obj.new_comment_id + ',';
Cookies.set('wc_moderate_comments_' + wpdiscuzPostId, moderateComments, {expires: moderateCommentTime, path: '/'});
}
notifySubscribers(obj);
wpdiscuzRedirect(obj);
addCookie(wcForm, obj);
wcForm.get(0).reset();
setCookieInForm();
var currTArea = $('.wc_comment', wcForm);
currTArea.css('height', '72px');
setTextareaCharCount(currTArea, commentTextMaxLength);
$('.wmu-preview-wrap', wcForm).remove();
if (wpdiscuzReplyButton.length) {
wpdiscuzReplyButton.removeClass('wc-cta-active');
}
} else {
message = wpdiscuzAjaxObj.wpdiscuz_options[messageKey];
if (obj.typeError != 'undefined' && obj.typeError != null) {
message += ' ' + obj.typeError;
}
wpdiscuzAjaxObj.setCommentMessage(wcForm, messageKey, message, true);
}
if (obj.callbackFunctions != null && obj.callbackFunctions != 'undefined' && obj.callbackFunctions.length) {
$.each(obj.callbackFunctions, function (i) {
if (typeof wpdiscuzAjaxObj[obj.callbackFunctions[i]] === "function") {
wpdiscuzAjaxObj[obj.callbackFunctions[i]](messageKey, wcForm);
} else {
console.log(obj.callbackFunctions[i] + " is not a function");
}
});
}
} catch (e) {
if (response.indexOf('<') >= 0 && response.indexOf('>') >= 0) {
message = e;
} else {
message = response;
}
wpdiscuzAjaxObj.setCommentMessage(wcForm, 'wc_invalid_field', message, true);
}
$('.wpdiscuz-loading-bar').hide();
});
}
changeCaptchaImage($('.wc_captcha_refresh_img', wcForm));
wpdiscuzReset();
});
function notifySubscribers(obj) {
if (!obj.held_moderate) {
var data = new FormData();
data.append('action', 'checkNotificationType');
data.append('comment_id', obj.new_comment_id);
data.append('email', obj.user_email);
data.append('isParent', obj.is_main);
var ajaxObject = getAjaxObj(data);
ajaxObject.done(function (response) {
try {
obj = $.parseJSON(response);
} catch (e) {
console.log(e);
}
});
}
}
function wpdiscuzRedirect(obj) {
if (obj.redirect > 0 && obj.new_comment_id) {
var data = new FormData();
data.append('action', 'redirect');
data.append('commentId', obj.new_comment_id);
var ajaxObject = getAjaxObj(data);
ajaxObject.done(function (response) {
obj = $.parseJSON(response);
if (obj.code == 1) {
setTimeout(function () {
window.location.href = obj.redirect_to;
}, 5000);
}
});
}
}
function setCookieInForm() {
if (Cookies.get('comment_author_' + wpdiscuzCookiehash) && Cookies.get('comment_author_' + wpdiscuzCookiehash).indexOf('Anonymous') < 0) {
$('.wc_comm_form .wc_name').val(Cookies.get('comment_author_' + wpdiscuzCookiehash));
}
if (Cookies.get('comment_author_email_' + wpdiscuzCookiehash) && Cookies.get('comment_author_email_' + wpdiscuzCookiehash).indexOf('@example.com') < 0) {
$('.wc_comm_form .wc_email').val(Cookies.get('comment_author_email_' + wpdiscuzCookiehash));
}
if (Cookies.get('comment_author_url_' + wpdiscuzCookiehash)) {
$('.wc_comm_form .wc_website').val(Cookies.get('comment_author_url_' + wpdiscuzCookiehash));
}
}
function addCookie(wcForm, obj) {
var email = '';
var name = '';
if ($('.wc_email', wcForm).val()) {
email = $('.wc_email', wcForm).val();
} else {
email = obj.user_email;
}
if ($('.wc_name', wcForm).val()) {
name = $('.wc_name', wcForm).val();
} else {
name = obj.user_name;
}
if (storeCommenterData == null) {
Cookies.set('comment_author_email_' + wpdiscuzCookiehash, email);
Cookies.set('comment_author_' + wpdiscuzCookiehash, name);
if ($('.wc_website', wcForm).length) {
Cookies.set('comment_author_url_' + wpdiscuzCookiehash, $('.wc_website', wcForm).val());
}
} else {
storeCommenterData = parseInt(storeCommenterData);
Cookies.set('comment_author_email_' + wpdiscuzCookiehash, email, {expires: storeCommenterData, path: '/'});
Cookies.set('comment_author_' + wpdiscuzCookiehash, name, {expires: storeCommenterData, path: '/'});
if ($('.wc_website', wcForm).length) {
Cookies.set('comment_author_url_' + wpdiscuzCookiehash, $('.wc_website', wcForm).val(), {expires: storeCommenterData, path: '/'});
}
}
}
//============================== ADD COMMENT FUNCTION ============================== //
//============================== EDIT COMMENT FUNCTION ============================== //
var wcCommentTextBeforeEditing;
$(document).delegate('.wc_editable_comment', 'click', function () {
var uniqueID = getUniqueID($(this), 0);
var commentID = getCommentID(uniqueID);
var editButton = $(this);
var data = new FormData();
data.append('action', 'editComment');
data.append('commentId', commentID);
var wcCommentTextBeforeEditingTop = $('#wc-comm-' + uniqueID + ' .wpd-top-custom-fields');
var wcCommentTextBeforeEditingBottom = $('#wc-comm-' + uniqueID + ' .wpd-bottom-custom-fields');
wcCommentTextBeforeEditing = wcCommentTextBeforeEditingTop.length ? '
' + wcCommentTextBeforeEditingTop.html() + '
' : '';
wcCommentTextBeforeEditing += '';
wcCommentTextBeforeEditing += wcCommentTextBeforeEditingBottom.length ? '' + $('#wc-comm-' + uniqueID + ' .wpd-bottom-custom-fields').html() + '
' : '';
getAjaxObj(data).done(function (response) {
try {
var obj = $.parseJSON(response);
var message = '';
var messageKey = obj.code;
if (parseInt(messageKey) >= 0) {
$('#wc-comm-' + uniqueID + ' .wpd-top-custom-fields').remove();
$('#wc-comm-' + uniqueID + ' .wpd-bottom-custom-fields').remove();
$('#wc-comm-' + uniqueID + ' > .wc-comment-right .wc-comment-text').replaceWith(obj.message);
$('#wc-comm-' + uniqueID + ' > .wc-comment-right .wc-comment-footer .wc_editable_comment').hide();
$('#wc-comm-' + uniqueID + ' > .wc-comment-right .wc-comment-footer .wc_cancel_edit').css('display', 'inline-block');
var editForm = $('#wc-comm-' + uniqueID + ' > .wc-comment-right #wpdiscuz-edit-form');
wpdiscuzReplaceValidationUI(editForm[0]);
} else {
message = wpdiscuzAjaxObj.wpdiscuz_options[messageKey];
wpdiscuzAjaxObj.setCommentMessage(editButton, messageKey, message, false);
}
} catch (e) {
console.log(e);
}
$('.wpdiscuz-loading-bar').hide();
});
});
$(document).delegate('.wc_save_edited_comment', 'click', function () {
var uniqueID = getUniqueID($(this));
var commentID = getCommentID(uniqueID);
var editCommentForm = $('#wc-comm-' + uniqueID + ' #wpdiscuz-edit-form');
var saveButton = $(this);
wpdValidateFieldRequired(editCommentForm);
editCommentForm.submit(function (event) {
event.preventDefault();
});
if (editCommentForm[0].checkValidity()) {
var data = new FormData();
data.append('action', 'saveEditedComment');
data.append('wpdiscuz_unique_id', uniqueID);
data.append('commentId', commentID);
var inputs = $(":input", editCommentForm);
inputs.each(function () {
if ($(this).is(':visible') && this.name != '' && this.type != 'checkbox' && this.type != 'radio') {
data.append(this.name + '', $(this).val());
}
if (this.type == 'checkbox' || this.type == 'radio') {
if ($(this).is(':checked')) {
data.append(this.name + '', $(this).val());
}
}
});
getAjaxObj(data).done(function (response) {
try {
var obj = $.parseJSON(response);
var messageKey = obj.code;
var message = '';
if (parseInt(messageKey) >= 0) {
wcCancelOrSave(uniqueID, obj.message);
} else {
message = wpdiscuzAjaxObj.wpdiscuz_options[messageKey];
wpdiscuzAjaxObj.setCommentMessage(saveButton, messageKey, message, false);
}
if (obj.callbackFunctions != null && obj.callbackFunctions != 'undefined' && obj.callbackFunctions.length) {
$.each(obj.callbackFunctions, function (i) {
if (typeof wpdiscuzAjaxObj[obj.callbackFunctions[i]] === "function") {
wpdiscuzAjaxObj[obj.callbackFunctions[i]](messageKey, commentID, commentContent);
} else {
console.log(obj.callbackFunctions[i] + " is not a function");
}
});
}
} catch (e) {
if (response.indexOf('<') >= 0 && response.indexOf('>') >= 0) {
message = e;
} else {
message = response;
}
wpdiscuzAjaxObj.setCommentMessage(saveButton, 'wc_invalid_field', message, false);
}
$('.wpdiscuz-loading-bar').hide();
});
}
});
$(document).delegate('.wc_cancel_edit', 'click', function () {
var uniqueID = getUniqueID($(this));
wcCancelOrSave(uniqueID, wcCommentTextBeforeEditing);
});
function wcCancelOrSave(uniqueID, content) {
$('#wc-comm-' + uniqueID + ' > .wc-comment-right .wc-comment-footer .wc_editable_comment').show();
$('#wc-comm-' + uniqueID + ' > .wc-comment-right .wc-comment-footer .wc_cancel_edit').hide();
$('#wc-comm-' + uniqueID + ' #wpdiscuz-edit-form').replaceWith(content);
}
function nl2br(str, is_xhtml) {
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '
' : '
';
var string = (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
return string.replace('
', '
');
}
//============================== EDIT COMMENT FUNCTION ============================== //
//============================== LOAD MORE ============================== //
$(document).delegate('.wc-load-more-submit', 'click', function () {
var loadButton = $(this);
var loaded = 'wc-loaded';
var loading = 'wc-loading';
if (loadButton.hasClass(loaded)) {
wpdiscuzLoadComments(loadButton, loaded, loading);
}
});
var isRun = false;
if (commentListLoadType == 2 && !wordpressIsPaginate) {
$('.wc-load-more-submit').parents('.wpdiscuz-comment-pagination').hide();
wpdiscuzScrollEvents();
$(window).scroll(function () {
wpdiscuzScrollEvents();
});
}
function wpdiscuzScrollEvents() {
var wpdiscuzHasMoreComments = $('#wpdiscuzHasMoreComments').val();
var scrollHeight = $(document).height();
var scrollPosition = $(window).height() + $(window).scrollTop();
if (scrollHeight && scrollPosition) {
var scrollPercent = scrollPosition * 100 / scrollHeight;
if (scrollPercent >= 80 && isRun === false && wpdiscuzHasMoreComments == 1) {
isRun = true;
wpdiscuzLoadComments($('.wc-load-more-submit'));
}
}
}
function wpdiscuzLoadComments(loadButton, loaded, loading) {
loadButton.toggleClass(loaded);
loadButton.toggleClass(loading);
var data = new FormData();
data.append('action', 'loadMoreComments');
data.append('offset', wpdiscuzLoadCount);
data.append('orderBy', wpdiscuzCommentOrderBy);
data.append('order', wpdiscuzCommentOrder);
data.append('lastParentId', getLastParentID());
data.append(wpdiscuzLastVisitKey, Cookies.get(wpdiscuzLastVisitKey));
wpdiscuzLoadCount++;
getAjaxObj(data).done(function (response) {
try {
var obj = $.parseJSON(response);
$('.wpdiscuz-comment-pagination').before(obj.comment_list);
setLoadMoreVisibility(obj);
$('.wpdiscuz_single').remove();
isRun = false;
loadLastCommentId = obj.loadLastCommentId;
} catch (e) {
console.log(e);
}
$('.wpdiscuz-loading-bar').hide();
$('.wc-load-more-submit').blur();
loadButton.toggleClass(loaded);
loadButton.toggleClass(loading);
});
}
function setLoadMoreVisibility(obj) {
if (obj.is_show_load_more == false) {
$('#wpdiscuzHasMoreComments').val(0);
$('.wc-load-more-submit').parents('.wpdiscuz-comment-pagination').hide();
} else {
setLastParentID(obj.last_parent_id);
$('#wpdiscuzHasMoreComments').val(1);
}
if (obj.callbackFunctions != null && obj.callbackFunctions != 'undefined' && obj.callbackFunctions.length) {
$.each(obj.callbackFunctions, function (i) {
if (typeof wpdiscuzAjaxObj[obj.callbackFunctions[i]] === "function") {
wpdiscuzAjaxObj[obj.callbackFunctions[i]]();
} else {
console.log(obj.callbackFunctions[i] + " is not a function");
}
});
}
}
//============================== LOAD MORE ============================== //
//============================== VOTE ============================== //
$(document).delegate('.wc_vote.wc_not_clicked', 'click', function () {
var currentVoteBtn = $(this);
$(currentVoteBtn).removeClass('wc_not_clicked');
var messageKey = '';
var message = '';
var commentID = $(this).parents('.wc-comment-right').attr('id');
commentID = commentID.substring(commentID.lastIndexOf('-') + 1);
var voteType;
if ($(this).hasClass('wc-up')) {
voteType = 1;
} else {
voteType = -1;
}
var data = new FormData();
data.append('action', 'voteOnComment');
data.append('commentId', commentID);
data.append('voteType', voteType);
getAjaxObj(data).done(function (response) {
$(currentVoteBtn).addClass('wc_not_clicked');
try {
var obj = $.parseJSON(response);
messageKey = obj.code;
if (parseInt(messageKey) >= 0) {
if (obj.buttonsStyle == 'total') {
var voteCountDiv = $('.wc-comment-footer .wc-vote-result', $('#comment-' + commentID));
voteCountDiv.text(parseInt(voteCountDiv.text()) + voteType);
} else {
var likeCountDiv = $('.wc-comment-footer .wc-vote-result-like', $('#comment-' + commentID));
var dislikeCountDiv = $('.wc-comment-footer .wc-vote-result-dislike', $('#comment-' + commentID));
likeCountDiv.text(obj.likeCount);
dislikeCountDiv.text(obj.dislikeCount);
parseInt(obj.likeCount) > 0 ? likeCountDiv.addClass('wc-positive') : likeCountDiv.removeClass('wc-positive');
parseInt(obj.dislikeCount) < 0 ? dislikeCountDiv.addClass('wc-negative') : dislikeCountDiv.removeClass('wc-negative');
}
} else {
message = wpdiscuzAjaxObj.wpdiscuz_options[messageKey];
wpdiscuzAjaxObj.setCommentMessage(currentVoteBtn, messageKey, message, false);
}
if (obj.callbackFunctions != null && obj.callbackFunctions != 'undefined' && obj.callbackFunctions.length) {
$.each(obj.callbackFunctions, function (i) {
if (typeof wpdiscuzAjaxObj[obj.callbackFunctions[i]] === "function") {
wpdiscuzAjaxObj[obj.callbackFunctions[i]](messageKey, commentID, voteType);
} else {
console.log(obj.callbackFunctions[i] + " is not a function");
}
});
}
} catch (e) {
console.log(e);
}
$('.wpdiscuz-loading-bar').hide();
});
});
//============================== VOTE ============================== //
//============================== SORTING ============================== //
$(document).delegate('.wpdiscuz-sort-button', 'click', function () {
if (!($(this).hasClass('wpdiscuz-sort-button-active'))) {
var clickedBtn = $(this);
if ($(this).hasClass('wpdiscuz-vote-sort-up')) {
wpdiscuzCommentOrderBy = 'by_vote';
wpdiscuzCommentOrder = 'desc';
} else {
wpdiscuzCommentOrderBy = 'comment_date_gmt';
wpdiscuzCommentOrder = $(this).hasClass('wpdiscuz-date-sort-desc') ? 'desc' : 'asc';
}
var data = new FormData();
data.append('action', 'wpdiscuzSorting');
data.append('orderBy', wpdiscuzCommentOrderBy);
data.append('order', wpdiscuzCommentOrder);
var messageKey = '';
var message = '';
getAjaxObj(data).done(function (response) {
try {
var obj = $.parseJSON(response);
messageKey = obj.code;
message = obj.message;
if (parseInt(messageKey) > 0) {
$('#wpcomm .wc-thread-wrapper .wc-comment').each(function () {
$(this).remove();
});
$('#wpcomm .wc-thread-wrapper').prepend(message);
wpdiscuzLoadCount = parseInt(obj.loadCount);
} else {
}
setActiveButton(clickedBtn);
setLoadMoreVisibility(obj);
} catch (e) {
console.log(e);
}
$('.wpdiscuz-loading-bar').hide();
});
}
});
function setActiveButton(clickedBtn) {
$('.wpdiscuz-sort-buttons .wpdiscuz-sort-button').each(function () {
$(this).removeClass('wpdiscuz-sort-button-active');
});
clickedBtn.addClass('wpdiscuz-sort-button-active');
}
//============================== SORTING ============================== //
//============================== SINGLE COMMENT ============================== //
function getSingleComment() {
var loc = location.href;
var matches = loc.match(/#comment\-(\d+)/);
if (matches !== null) {
var commentId = matches[1];
if (!$('#comment-' + commentId).length) {
var data = new FormData();
data.append('action', 'getSingleComment');
data.append('commentId', commentId);
var ajaxObject = getAjaxObj(data);
ajaxObject.done(function (response) {
try {
var obj = $.parseJSON(response);
$('.wc-thread-wrapper').prepend(obj.message);
$('html, body').animate({
scrollTop: $(".wc-thread-wrapper").offset().top
}, 1000);
} catch (e) {
console.log(e);
}
$('.wpdiscuz-loading-bar').hide();
});
}
}
}
getSingleComment();
//============================== SINGLE COMMENT ============================== //
//============================== LIVE UPDATE ============================== //
if (commentListUpdateType && loadLastCommentId && (isUserLoggedIn || (!isUserLoggedIn && !disableGuestsLiveUpdate))) {
setInterval(liveUpdate, parseInt(commentListUpdateTimer) * 1000);
}
function liveUpdate() {
var visibleCommentIds = getVisibleCommentIds();
var email = (Cookies.get('comment_author_email_' + wpdiscuzCookiehash) != undefined && Cookies.get('comment_author_email_' + wpdiscuzCookiehash) != '') ? Cookies.get('comment_author_email_' + wpdiscuzCookiehash) : '';
var data = new FormData();
data.append('action', 'updateAutomatically');
data.append('loadLastCommentId', loadLastCommentId);
data.append('visibleCommentIds', visibleCommentIds);
data.append('email', email);
var ajaxObject = getAjaxObj(data);
ajaxObject.done(function (response) {
try {
var obj = $.parseJSON(response);
if (obj.code == 1) {
if (commentListUpdateType == 1) {
liveUpdateImmediately(obj);
} else {
wpdiscuzCommentArray = wpdiscuzCommentArray.concat(obj.message.comments);
wpdiscuzReplyArray = wpdiscuzReplyArray.concat(obj.message.author_replies);
var newCommentArrayLength = wpdiscuzCommentArray.length;
var newRepliesArrayLength = wpdiscuzReplyArray.length;
if (newCommentArrayLength > 0) {
var newCommentText = newCommentArrayLength + ' ';
newCommentText += newCommentArrayLength > 1 ? wpdiscuzAjaxObj.wpdiscuz_options.wc_new_comments_button_text : wpdiscuzAjaxObj.wpdiscuz_options.wc_new_comment_button_text;
$('.wc_new_comment').html(newCommentText).show();
} else {
$('.wc_new_comment').hide();
}
if (newRepliesArrayLength > 0) {
var newReplyText = newRepliesArrayLength + ' ';
newReplyText += newRepliesArrayLength > 1 ? wpdiscuzAjaxObj.wpdiscuz_options.wc_new_replies_button_text : wpdiscuzAjaxObj.wpdiscuz_options.wc_new_reply_button_text;
$('.wc_new_reply').html(newReplyText).show();
} else {
$('.wc_new_reply').hide();
}
}
$('.wc_header_text_count').html(obj.wc_all_comments_count_new);
loadLastCommentId = obj.loadLastCommentId;
}
} catch (e) {
console.log(e);
}
$('.wpdiscuz-loading-bar').hide();
});
}
function liveUpdateImmediately(obj) {
if (obj.message !== undefined) {
var commentObject;
var message = obj.message;
for (var i = 0; i < message.length; i++) {
commentObject = message[i];
addCommentToTree(commentObject.comment_parent, commentObject.comment_html);
}
}
}
$(document).delegate('.wc-update-on-click', 'click', function () {
var data = new FormData();
data.append('action', 'updateOnClick');
var clickedButton = $(this);
if (clickedButton.hasClass('wc_new_comment')) {
data.append('newCommentIds', wpdiscuzCommentArray.join());
} else {
data.append('newCommentIds', wpdiscuzReplyArray.join());
}
getAjaxObj(data).done(function (response) {
try {
var obj = $.parseJSON(response);
liveUpdateImmediately(obj);
if (clickedButton.hasClass('wc_new_comment')) {
wpdiscuzCommentArray = [];
$('.wc_new_comment').hide();
} else {
wpdiscuzReplyArray = [];
$('.wc_new_reply').hide();
}
} catch (e) {
console.log(e);
}
$('.wpdiscuz-loading-bar').hide();
});
});
//============================== LIVE UPDATE ============================== //
//============================== READ MORE ============================== //
$(document).delegate('.wpdiscuz-readmore', 'click', function () {
var uniqueId = getUniqueID($(this));
var commentId = getCommentID(uniqueId);
var data = new FormData();
data.append('action', 'readMore');
data.append('commentId', commentId);
getAjaxObj(data).done(function (response) {
try {
var obj = $.parseJSON(response);
if (obj.code) {
$('#comment-' + commentId + ' .wc-comment-text').html(' ' + obj.message);
$('#wpdiscuz-readmore-' + uniqueId).remove();
}
} catch (e) {
console.log(e);
}
$('.wpdiscuz-loading-bar').hide();
});
});
//============================== READ MORE ============================== //
//============================== FUNCTIONS ============================== //
/**
* field - the clicked element
* messagekey - the key for adding class on message container
* message - the message to add
* isformerror - whether the error is form or not
*/
wpdiscuzAjaxObj.setCommentMessage = function (field, messageKey, message, isFormError) {
var msgContainer;
var parentContainer;
if (isFormError) {
parentContainer = field.parents('.wc-form-wrapper');
} else {
parentContainer = field.closest('.wc-comment');
}
msgContainer = parentContainer.children('.wpdiscuz-comment-message');
msgContainer.removeClass();
msgContainer.addClass('wpdiscuz-comment-message');
msgContainer.addClass(messageKey);
msgContainer.html(message);
msgContainer.show().delay(4000).fadeOut(1000, function () {
msgContainer.removeClass();
msgContainer.addClass('wpdiscuz-comment-message');
msgContainer.html('');
});
}
function cloneSecondaryForm(field) {
var uniqueId = getUniqueID(field, 0);
$('#wpdiscuz_form_anchor-' + uniqueId).before(replaceUniqueId(uniqueId));
var secondaryFormWrapper = $('#wc-secondary-form-wrapper-' + uniqueId);
wpdiscuzReplaceValidationUI($('.wc_comm_form', secondaryFormWrapper)[0]);
secondaryFormWrapper.slideToggle(700, function () {
field.addClass('wpdiscuz-clonned');
});
changeCaptchaImage($('.wc_captcha_refresh_img', secondaryFormWrapper));
}
function replaceUniqueId(uniqueId) {
var secondaryForm = $('#wpdiscuz_hidden_secondary_form').html();
return secondaryForm.replace(/wpdiscuzuniqueid/g, uniqueId);
}
function getUniqueID(field, isMain) {
var fieldID = '';
if (isMain) {
fieldID = field.parents('.wc-main-form-wrapper').attr('id');
} else {
fieldID = field.parents('.wc-comment').attr('id');
}
var uniqueID = fieldID.substring(fieldID.lastIndexOf('-') + 1);
return uniqueID;
}
function getCommentID(uniqueID) {
return uniqueID.substring(0, uniqueID.indexOf('_'));
}
function getLastParentID() {
var url = $('.wc-load-more-link').attr("href");
return url.substring(url.lastIndexOf('=') + 1);
}
function setLastParentID(lastParentID) {
var url = $('.wc-load-more-link').attr("href");
$('.wc-load-more-link').attr("href", url.replace(/[\d]+$/m, lastParentID));
if (commentListLoadType != 2) {
$('.wpdiscuz-comment-pagination').show();
}
}
function getCommentDepth(field) {
var fieldClasses = field.attr('class');
var classesArray = fieldClasses.split(' ');
var depth = '';
$.each(classesArray, function (index, value) {
if ('wc_comment_level' === getParentDepth(value, false)) {
depth = getParentDepth(value, true);
}
});
return parseInt(depth) + 1;
}
function getParentDepth(depthValue, isNumberPart) {
var depth = '';
if (isNumberPart) {
depth = depthValue.substring(depthValue.indexOf('-') + 1);
} else {
depth = depthValue.substring(0, depthValue.indexOf('-'));
}
return depth;
}
function addCommentToTree(parentId, comment) {
if (parentId == 0) {
$('.wc-thread-wrapper').prepend(comment);
} else {
var parentUniqueId = getUniqueID($('#comment-' + parentId), 0);
$('#wpdiscuz_form_anchor-' + parentUniqueId).after(comment);
}
}
function getVisibleCommentIds() {
var uniqueId;
var commentId;
var visibleCommentIds = '';
$('.wc-comment-right').each(function () {
uniqueId = getUniqueID($(this), 0);
commentId = getCommentID(uniqueId);
visibleCommentIds += commentId + ',';
});
return visibleCommentIds;
}
function loginButtonsClone() {
if ($('.wc_social_plugin_wrapper .wp-social-login-provider-list').length) {
$('.wc_social_plugin_wrapper .wp-social-login-provider-list').clone().prependTo('#wpdiscuz_hidden_secondary_form > .wc-form-wrapper > .wc-secondary-forms-social-content');
} else if ($('.wc_social_plugin_wrapper .the_champ_login_container').length) {
$('.wc_social_plugin_wrapper .the_champ_login_container').clone().prependTo('#wpdiscuz_hidden_secondary_form > .wc-form-wrapper > .wc-secondary-forms-social-content');
} else if ($('.wc_social_plugin_wrapper .social_connect_form').length) {
$('.wc_social_plugin_wrapper .social_connect_form').clone().prependTo('#wpdiscuz_hidden_secondary_form > .wc-form-wrapper > .wc-secondary-forms-social-content');
} else if ($('.wc_social_plugin_wrapper .oneall_social_login_providers').length) {
$('.wc_social_plugin_wrapper .oneall_social_login .oneall_social_login_providers').clone().prependTo('#wpdiscuz_hidden_secondary_form > .wc-form-wrapper > .wc-secondary-forms-social-content');
}
}
function displayShowHideReplies() {
$('#wcThreadWrapper .wc-comment').each(function (i) {
if ($('> .wc-reply', this).length || $(this).hasClass('wpdiscuz-root-comment')) {
var toggle = $('> .wc-comment-right .wc-comment-footer .wc-toggle', this);
toggle.removeClass('wpdiscuz-hidden');
}
});
}
function wpdiscuzReset() {
$('.wpdiscuz_reset').val("");
}
function setTextareaCharCount(elem, count) {
if (commentTextMaxLength != null) {
var currLength = elem.val().length;
var textareaWrap = elem.parents('.wc_comm_form');
var charCountDiv = $('.commentTextMaxLength', textareaWrap);
var left = commentTextMaxLength - currLength;
if (left <= 10) {
charCountDiv.addClass('left10');
} else {
charCountDiv.removeClass('left10');
}
charCountDiv.html(left);
}
}
function wpdValidateFieldRequired(form) {
var fieldsGroup = form.find('.wpd-required-group');
$.each(fieldsGroup, function () {
$('input', this).removeAttr('required');
var checkedFields = $('input:checked', this);
if (checkedFields.length === 0) {
$('input', $(this)).attr('required', 'required');
} else {
$('.wpd-field-invalid', this).remove();
}
});
if (wpdiscuzRecaptcha && $('input[name=wpdiscuz_recaptcha]', form).length && !$('input[name=wpdiscuz_recaptcha]', form).val().length) {
wpdGoogleRecaptchaValid = false;
$('.wpdiscuz-recaptcha', form).css('border', '1px solid red');
} else if (wpdiscuzRecaptcha) {
$('.wpdiscuz-recaptcha', form).css('border', 'none');
}
}
//============================== FUNCTIONS ============================== //
//=================== FORM VALIDATION ================================//
function wpdiscuzReplaceValidationUI(form) {
form.addEventListener("invalid", function (event) {
event.preventDefault();
}, true);
form.addEventListener("submit", function (event) {
if (!this.checkValidity()) {
event.preventDefault();
}
});
}
$(document).delegate('.wc_comm_submit, .wc_save_edited_comment', 'click', function () {
var curentForm = $(this).parents('form');
var invalidFields = $(':invalid', curentForm),
errorMessages = $('.error-message', curentForm),
parent;
for (var i = 0; i < errorMessages.length; i++) {
errorMessages[ i ].parentNode.removeChild(errorMessages[ i ]);
}
for (var i = 0; i < invalidFields.length; i++) {
parent = invalidFields[ i ].parentNode;
var oldMsg = parent.querySelector('.wpd-field-invalid');
if (oldMsg) {
parent.removeChild(oldMsg);
}
if (invalidFields[ i ].validationMessage !== '') {
parent.insertAdjacentHTML("beforeend", "" +
invalidFields[ i ].validationMessage +
"
");
}
}
});
function wpdiscuzRemoveError(field) {
var wpdiscuzErrorDiv = $(field).parents('div.wpdiscuz-item').find('.wpd-field-invalid');
if (wpdiscuzErrorDiv) {
wpdiscuzErrorDiv.remove();
}
}
$(document).delegate('.wpdiscuz-item input,.wpdiscuz-item textarea,.wpdiscuz-item select', 'click', function () {
wpdiscuzRemoveError($(this));
});
$(document).delegate('.wpdiscuz-item input,.wpdiscuz-item textarea,.wpdiscuz-item select', 'focus', function () {
wpdiscuzRemoveError($(this));
});
$(document).delegate('.wpd-required-group', 'change', function () {
if ($('input:checked', this).length !== 0) {
$('.wpd-field-invalid', this).remove();
$('input', $(this)).removeAttr('required');
} else {
$('input', $(this)).attr('required', 'required');
}
});
/* SPOILER */
$(document).delegate('.wpdiscuz-spoiler', 'click', function () {
$(this).next().slideToggle();
if ($(this).hasClass('wpdiscuz-spoiler-closed')) {
$(this).parents('.wpdiscuz-spoiler-wrap').find('.fa-plus').removeClass('fa-plus').addClass('fa-minus');
} else {
$(this).parents('.wpdiscuz-spoiler-wrap').find('.fa-minus').removeClass('fa-minus').addClass('fa-plus');
}
$(this).toggleClass('wpdiscuz-spoiler-closed');
});
function wpdiscuzShowReplies(uniqueId) {
var commentId = getCommentID(uniqueId);
var data = new FormData();
data.append('action', 'wpdiscuzShowReplies');
data.append('commentId', commentId);
var ajax = getAjaxObj(data);
ajax.done(function (response) {
try {
var resp = $.parseJSON(response);
if (resp.code == 1) {
$('#wc-comm-' + uniqueId).replaceWith(resp.data);
$('#wc-comm-' + uniqueId + ' .wc-toggle .fa').removeClass('fa-chevron-down').addClass('fa-chevron-up').removeClass('wpdiscuz-show-replies');
} else {
console.log('Unknown error occured');
}
} catch (e) {
console.log(e);
}
$('.wpdiscuz-loading-bar').hide();
});
}
/**
* @param {type} action the action key
* @param {type} data the request properties
* @returns {jqXHR}
*/
function getAjaxObj(data) {
if (data.action !== 'liveUpdate') {
$('.wpdiscuz-loading-bar').show();
}
data.append('postId', wpdiscuzPostId);
return $.ajax({
type: 'POST',
url: wpdiscuzAjaxObj.url,
data: data,
contentType: false,
processData: false,
});
}
});
// source --> https://sindroms.ru/wp-content/plugins/fancybox-for-wordpress/fancybox/jquery.fancybox.js?ver=1.3.8
/*
* FancyBox - jQuery Plugin
* Simple and fancy lightbox alternative
*
* Examples and documentation at: http://fancybox.net
*
* Copyright (c) 2008 - 2010 Janis Skarnelis
* That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
*
* Version: 1.3.8
* Requires: jQuery v1.7+
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
!function(a){var b,c,d,e,f,g,h,i,j,k,w,A,B,l=0,m={},n=[],o=0,p={},q=[],r=null,s=new Image,t=/\.(jpg|gif|png|bmp|jpeg|webp)(.*)?$/i,u=/[^\.]\.(swf)\s*$/i,v=/[^\.]\.(svg)\s*$/i,x=1,y=0,z="",C=!1,D=a.extend(a("")[0],{prop:0}),E=navigator.userAgent.match(/msie [6]/i)&&!window.XMLHttpRequest,F=void 0!==document.createTouch,G=function(){c.hide(),s.onerror=s.onload=null,r&&r.abort(),b.empty()},H=function(){return!1===m.onError(n,l,m)?(c.hide(),void(C=!1)):(m.titleShow=!1,m.width="auto",m.height="auto",b.html('The requested content cannot be loaded.
Please try again later.
'),void J())},I=function(){var e,f,h,i,j,k,d=n[l];if(G(),m=a.extend({},a.fn.fancybox.defaults,"undefined"==typeof a(d).data("fancybox")?m:a(d).data("fancybox")),k=m.onStart(n,l,m),k===!1)return void(C=!1);if("object"==typeof k&&(m=a.extend(m,k)),h=m.title||(d.nodeName?a(d).attr("title"):d.title)||"",d.nodeName&&!m.orig&&(m.orig=a(d).children("img:first").length?a(d).children("img:first"):a(d)),""===h&&m.orig&&(h=m.titleFromAlt?m.orig.attr("alt"):m.orig.attr("title")),e=m.href||(d.nodeName?a(d).attr("href"):d.href)||null,(/^(?:javascript)/i.test(e)||"#"==e)&&(e=null),m.type?(f=m.type,e||(e=m.content)):m.content?f="html":e&&(f=e.match(t)||a(d).hasClass("image")?"image":e.match(u)?"swf":e.match(v)?"svg":a(d).hasClass("iframe")?"iframe":0===e.indexOf("#")?"inline":"ajax"),!f)return void H();switch("inline"==f&&(d=e.substr(e.indexOf("#")),f=a(d).length>0?"inline":"ajax"),m.type=f,m.href=e,m.title=h,m.autoDimensions&&("html"==m.type||"inline"==m.type||"ajax"==m.type?(m.width="auto",m.height="auto"):m.autoDimensions=!1),m.modal&&(m.overlayShow=!0,m.hideOnOverlayClick=!1,m.hideOnContentClick=!1,m.enableEscapeButton=!1,m.showCloseButton=!1),m.padding=parseInt(m.padding,10),m.margin=parseInt(m.margin,10),b.css("padding",m.padding+m.margin),a(".fancybox-inline-tmp").off("fancybox-cancel").on("fancybox-change",function(){a(this).replaceWith(g.children())}),f){case"html":b.html(m.content),J();break;case"inline":if(a(d).parent().is("#fancybox-content")===!0)return void(C=!1);a('').hide().insertBefore(a(d)).on("fancybox-cleanup",function(){a(this).replaceWith(g.children())}).on("fancybox-cancel",function(){a(this).replaceWith(b.children())}),a(d).appendTo(b),J();break;case"image":C=!1,a.fancybox.showActivity(),s=new Image,s.onerror=function(){H()},s.onload=function(){C=!0,s.onerror=s.onload=null,K()},s.src=e;break;case"swf":m.scrolling="no",i='",b.html(i),J();break;case"svg":m.scrolling="no",i='',b.html(i),J();break;case"ajax":C=!1,a.fancybox.showActivity(),m.ajax.win=m.ajax.success,r=a.ajax(a.extend({},m.ajax,{url:e,data:m.ajax.data||{},error:function(a,b,c){a.status>0&&H()},success:function(a,d,f){var g="object"==typeof f?f:r;if(200==g.status){if("function"==typeof m.ajax.win){if(k=m.ajax.win(e,a,d,f),k===!1)return void c.hide();"string"!=typeof k&&"object"!=typeof k||(a=k)}b.html(a),J()}}}));break;case"iframe":L()}},J=function(){var c=m.width,d=m.height,e=0==a(window).width()?window.innerWidth:a(window).width(),f=0==a(window).height()?window.innerHeight:a(window).height();c=c.toString().indexOf("%")>-1?parseInt((e-2*m.margin)*parseFloat(c)/100,10)+"px":"auto"==c?"auto":c+"px",d=d.toString().indexOf("%")>-1?parseInt((f-2*m.margin)*parseFloat(d)/100,10)+"px":"auto"==d?"auto":d+"px",b.wrapInner(''),m.width=b.width(),m.height=b.height(),L()},K=function(){m.width=s.width,m.height=s.height,a("").attr({id:"fancybox-img",src:s.src,alt:m.title}).appendTo(b),L()},L=function(){var f,r;return c.hide(),e.is(":visible")&&!1===p.onCleanup(q,o,p)?(a(".fancybox-inline-tmp").trigger("fancybox-cancel"),void(C=!1)):(C=!0,a(g.add(d)).off(),a(window).off("resize.fb scroll.fb"),a(document).off("keydown.fb"),e.is(":visible")&&"outside"!==p.titlePosition&&e.css("height",e.height()),q=n,o=l,p=m,p.overlayShow?(d.css({"background-color":p.overlayColor,opacity:p.overlayOpacity,cursor:p.hideOnOverlayClick?"pointer":"auto",height:a(document).height()}),d.is(":visible")||(E&&a("select:not(#fancybox-tmp select)").filter(function(){return"hidden"!==this.style.visibility}).css({visibility:"hidden"}).one("fancybox-cleanup",function(){this.style.visibility="inherit"}),d.show())):d.hide(),B=T(),N(),e.is(":visible")?(a(h.add(j).add(k)).hide(),f=e.position(),A={top:f.top,left:f.left,width:e.width(),height:e.height()},r=A.width==B.width&&A.height==B.height,void g.fadeTo(p.changeFade,.3,function(){var c=function(){g.html(b.contents()).fadeTo(p.changeFade,1,P)};a(".fancybox-inline-tmp").trigger("fancybox-change"),g.empty().removeAttr("filter").css({"border-width":p.padding,width:B.width-2*p.padding,height:m.autoDimensions?"auto":B.height-y-2*p.padding}),r?c():(D.prop=0,a(D).animate({prop:1},{duration:p.changeSpeed,easing:p.easingChange,step:R,complete:c}))})):(e.removeAttr("style"),g.css("border-width",p.padding),"elastic"==p.transitionIn?(A=V(),g.html(b.contents()),e.show(),p.opacity&&(B.opacity=0),D.prop=0,void a(D).animate({prop:1},{duration:p.speedIn,easing:p.easingIn,step:R,complete:P})):("inside"==p.titlePosition&&y>0&&i.show(),g.css({width:B.width-2*p.padding,height:m.autoDimensions?"auto":B.height-y-2*p.padding}).html(b.contents()),void e.css(B).fadeIn("none"==p.transitionIn?0:p.speedIn,P))))},M=function(a){return!(!a||!a.length)&&("float"==p.titlePosition?'':''+a+"
")},N=function(){if(z=p.title||"",y=0,i.empty().removeAttr("style").removeClass(),p.titleShow===!1)return void i.hide();if(z=a.isFunction(p.titleFormat)?p.titleFormat(z,q,o,p):M(z),!z||""===z)return void i.hide();switch(i.addClass("fancybox-title-"+p.titlePosition).html(z).appendTo("body").show(),p.titlePosition){case"inside":i.css({width:B.width-2*p.padding,marginLeft:p.padding,marginRight:p.padding}),y=i.outerHeight(!0),i.appendTo(f),B.height+=y;break;case"over":i.css({marginLeft:p.padding,width:B.width-2*p.padding,bottom:p.padding}).appendTo(f);break;case"float":i.css("left",parseInt((i.width()-B.width-40)/2,10)*-1).appendTo(e);break;default:i.css({width:B.width-2*p.padding,paddingLeft:p.padding,paddingRight:p.padding}).appendTo(e)}i.hide()},O=function(){return(p.enableEscapeButton||p.enableKeyboardNav)&&a(document).on("keydown.fb",function(b){27==b.keyCode&&p.enableEscapeButton?(b.preventDefault(),a.fancybox.close()):37!=b.keyCode&&39!=b.keyCode||!p.enableKeyboardNav||"INPUT"===b.target.tagName||"TEXTAREA"===b.target.tagName||"SELECT"===b.target.tagName||(b.preventDefault(),a.fancybox[37==b.keyCode?"prev":"next"]())}),p.showNavArrows?((p.cyclic&&q.length>1||0!==o)&&j.show(),void((p.cyclic&&q.length>1||o!=q.length-1)&&k.show())):(j.hide(),void k.hide())},P=function(){a.support.opacity||(g.get(0).style.removeAttribute("filter"),e.get(0).style.removeAttribute("filter")),m.autoDimensions&&g.css("height","auto"),e.css("height","auto"),z&&z.length&&i.show(),p.showCloseButton&&h.show(),O(),p.hideOnContentClick&&g.on("click",a.fancybox.close),p.hideOnOverlayClick&&d.on("click",a.fancybox.close),p.autoResize&&a(window).on("resize.fb",a.fancybox.resize),p.centerOnScroll&&a(window).on("scroll.fb",a.fancybox.center),a.fn.mousewheel&&e.on("mousewheel.fb",function(b,c){C?b.preventDefault():"image"!=p.type||0!=a(b.target).get(0).clientHeight&&a(b.target).get(0).scrollHeight!==a(b.target).get(0).clientHeight||(b.preventDefault(),a.fancybox[c>0?"prev":"next"]())}),"iframe"==p.type&&a('").appendTo(g),e.show(),C=!1,a.fancybox.center(),p.onComplete(q,o,p),Q()},Q=function(){var b,c;q.length-1>o&&(b=q[o+1].href,"undefined"!=typeof b&&(b.match(t)||a(obj).hasClass("image"))&&(c=new Image,c.src=b)),o>0&&(b=q[o-1].href,"undefined"!=typeof b&&(b.match(t)||a(obj).hasClass("image"))&&(c=new Image,c.src=b))},R=function(a){var b={width:parseInt(A.width+(B.width-A.width)*a,10),height:parseInt(A.height+(B.height-A.height)*a,10),top:parseInt(A.top+(B.top-A.top)*a,10),left:parseInt(A.left+(B.left-A.left)*a,10)};"undefined"!=typeof B.opacity&&(b.opacity=a<.5?.5:a),e.css(b),g.css({width:b.width-2*p.padding,height:b.height-y*a-2*p.padding})},S=function(){return[0==a(window).width()?window.innerWidth:a(window).width()-2*p.margin,0==a(window).height()?window.innerHeight:a(window).height()-2*p.margin,a(document).scrollLeft()+p.margin,a(document).scrollTop()+p.margin]},T=function(){var e,a=S(),b={},c=p.autoScale,d=2*p.padding;return p.width.toString().indexOf("%")>-1?b.width=parseInt(a[0]*parseFloat(p.width)/100,10):b.width=p.width+d,p.height.toString().indexOf("%")>-1?b.height=parseInt(a[1]*parseFloat(p.height)/100,10):b.height=p.height+d,c&&(b.width>a[0]||b.height>a[1])&&("image"==m.type||"svg"==m.type||"swf"==m.type?(e=p.width/p.height,b.width>a[0]&&(b.width=a[0],b.height=parseInt((b.width-d)/e+d,10)),b.height>a[1]&&(b.height=a[1],b.width=parseInt((b.height-d)*e+d,10))):(b.width=Math.min(b.width,a[0]),b.height=Math.min(b.height,a[1]))),b.top=parseInt(Math.max(a[3]-20,a[3]+.5*(a[1]-b.height-40)),10),b.left=parseInt(Math.max(a[2]-20,a[2]+.5*(a[0]-b.width-40)),10),b},U=function(a){var b=a.offset();return b.top+=parseInt(a.css("paddingTop"),10)||0,b.left+=parseInt(a.css("paddingLeft"),10)||0,b.top+=parseInt(a.css("border-top-width"),10)||0,b.left+=parseInt(a.css("border-left-width"),10)||0,b.width=a.width(),b.height=a.height(),b},V=function(){var d,e,b=!!m.orig&&a(m.orig),c={};return b&&b.length?(d=U(b),c={width:d.width+2*p.padding,height:d.height+2*p.padding,top:d.top-p.padding-20,left:d.left-p.padding-20}):(e=S(),c={width:2*p.padding,height:2*p.padding,top:parseInt(e[3]+.5*e[1],10),left:parseInt(e[2]+.5*e[0],10)}),c},W=function(){return c.is(":visible")?(a("div",c).css("top",x*-40+"px"),void(x=(x+1)%12)):void clearInterval(w)};a.fn.fancybox=function(b){return a(this).length?(a(this).data("fancybox",a.extend({},b,a.metadata?a(this).metadata():{})).off("click.fb").on("click.fb",function(b){if(b.preventDefault(),!C){C=!0,a(this).blur(),n=[],l=0;var c=a(this).attr("rel")||"";c&&""!=c&&"nofollow"!==c?(n=a('a[rel="'+c+'"], area[rel="'+c+'"]'),l=n.index(this)):n.push(this),I()}}),this):this},a.fancybox=function(b){var c;if(!C){if(C=!0,c="undefined"!=typeof arguments[1]?arguments[1]:{},n=[],l=parseInt(c.index,10)||0,a.isArray(b)){for(var d=0,e=b.length;dn.length||l<0)&&(l=0),I()}},a.fancybox.showActivity=function(){clearInterval(w),c.show(),w=setInterval(W,66)},a.fancybox.hideActivity=function(){c.hide()},a.fancybox.next=function(){return a.fancybox.pos(o+1)},a.fancybox.prev=function(){return a.fancybox.pos(o-1)},a.fancybox.pos=function(a){C||(a=parseInt(a),n=q,a>-1&&a1&&(l=a>=q.length?0:q.length-1,I()))},a.fancybox.cancel=function(){C||(C=!0,a(".fancybox-inline-tmp").trigger("fancybox-cancel"),G(),m.onCancel(n,l,m),C=!1)},a.fancybox.close=function(){function b(){d.fadeOut("fast"),i.empty().hide(),e.hide(),a(".fancybox-inline-tmp").trigger("fancybox-cleanup"),g.empty(),p.onClosed(q,o,p),q=m=[],o=l=0,p=m={},C=!1}if(!C&&!e.is(":hidden")){if(C=!0,p&&!1===p.onCleanup(q,o,p))return void(C=!1);if(G(),a(h.add(j).add(k)).hide(),a(g.add(d)).off(),a(window).off("resize.fb scroll.fb mousewheel.fb"),a(document).off("keydown.fb"),g.find("iframe#fancybox-frame").attr("src",E&&/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank"),"inside"!==p.titlePosition&&i.empty(),e.stop(),"elastic"==p.transitionOut){A=V();var c=e.position();B={top:c.top,left:c.left,width:e.width(),height:e.height()},p.opacity&&(B.opacity=1),i.empty().hide(),D.prop=1,a(D).animate({prop:0},{duration:p.speedOut,easing:p.easingOut,step:R,complete:b})}else e.fadeOut("none"==p.transitionOut?0:p.speedOut,b)}},a.fancybox.resize=function(){d.is(":visible")&&d.css("height",a(document).height()),a.fancybox.center(!0)},a.fancybox.center=function(){var a,b;C||(b=arguments[0]===!0?1:0,a=S(),!b&&(e.width()>a[0]||e.height()>a[1])||e.stop().animate({top:parseInt(Math.max(a[3]-20,a[3]+.5*(a[1]-g.height()-40)-p.padding)),left:parseInt(Math.max(a[2]-20,a[2]+.5*(a[0]-g.width()-40)-p.padding))},"number"==typeof arguments[0]?arguments[0]:200))},a.fancybox.init=function(){a("#fancybox-wrap").length||(a("body").append(b=a(''),c=a(''),d=a(''),e=a('')),f=a('').append('').appendTo(e),f.append(g=a(''),h=a(''),i=a(''),j=a(''),k=a('')),h.click(a.fancybox.close),c.click(a.fancybox.cancel),j.click(function(b){b.preventDefault(),a.fancybox.prev()}),k.click(function(b){b.preventDefault(),a.fancybox.next()}),a.support.opacity||e.addClass("fancybox-ie"),E&&(c.addClass("fancybox-ie6"),e.addClass("fancybox-ie6"),a('').prependTo(f)))},a.fn.fancybox.defaults={padding:10,margin:40,opacity:!1,modal:!1,cyclic:!1,allowfullscreen:!1,scrolling:"auto",width:560,height:340,autoScale:!0,autoDimensions:!0,centerOnScroll:!F,autoResize:!0,ajax:{},swf:{wmode:"transparent"},svg:{wmode:"transparent"},hideOnOverlayClick:!0,hideOnContentClick:!1,overlayShow:!0,overlayOpacity:.7,overlayColor:"#777",titleShow:!0,titlePosition:"float",titleFormat:null,titleFromAlt:!1,transitionIn:"fade",transitionOut:"fade",speedIn:300,speedOut:300,changeSpeed:300,changeFade:"fast",easingIn:"swing",easingOut:"swing",showCloseButton:!0,showNavArrows:!0,enableEscapeButton:!0,enableKeyboardNav:!0,onStart:function(){},onCancel:function(){},onComplete:function(){},onCleanup:function(){},onClosed:function(){},onError:function(){}},a(document).ready(function(){a.fancybox.init()})}(jQuery);