1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-03 06:55:03 +03:00
ifhub.club/application/frontend/common/js/topic.js
Denis Shakhov d6029b1b12 Доработки и исправления
* Оптимизировано добавление\удаление из избранного
* Документирование
* Мелкие доработки и исправления
2013-08-29 16:30:04 +07:00

105 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Топик
*
* @module ls/topic
*
* @license GNU General Public License, version 2
* @copyright 2013 OOO "ЛС-СОФТ" {@link http://livestreetcms.com}
* @author Denis Shakhov <denis.shakhov@gmail.com>
*/
var ls = ls || {};
ls.topic = (function ($) {
"use strict";
/**
* Дефолтные опции
*/
var defaults = {
// Роутеры
oRouters: {
preview: aRouter['ajax'] + 'preview/topic/'
},
// Селекторы
selectors: {
previewImage: '.js-topic-preview-image',
previewImageLoader: '.js-topic-preview-loader',
previewTopicTextButton: '.js-topic-preview-text-button',
previewTopicTextHideButton: '.js-topic-preview-text-hide-button',
addTopicTitle: '.js-topic-add-title'
}
};
/**
* Инициализация
*
* @param {Object} options Опции
*/
this.init = function(options) {
var self = this;
this.options = $.extend({}, defaults, options);
// Подгрузка избражений-превью
$(this.options.selectors.previewImage).each(function () {
$(this).imagesLoaded(function () {
var $this = $(this),
$preview = $this.closest(self.options.selectors.previewImageLoader).removeClass('loading');
$this.height() < $preview.height() && $this.css('top', ($preview.height() - $this.height()) / 2 );
});
});
// Превью текста
$(this.options.selectors.previewTopicTextButton).on('click', function (e) {
self.showPreviewText('form-topic-add', 'topic-text-preview');
});
// Закрытие превью текста
$(document).on('click', this.options.selectors.previewTopicTextHideButton, function (e) {
self.hidePreviewText();
});
// Подгрузка информации о выбранном блоге при создании топика
$(this.options.selectors.addTopicTitle).on('change', function (e) {
ls.blog.loadInfo($(this).val());
});
};
/**
* Превью текста
*
* @param {String} sFormId ID формы
* @param {String} sPreviewId ID блока превью
*/
this.showPreviewText = function(sFormId, sPreviewId) {
var oForm = $('#' + sFormId);
var oPreview = $('#' + sPreviewId);
var oButton = oForm.find(this.options.selectors.previewTopicTextButton);
ls.hook.marker('previewBefore');
ls.ajaxSubmit(this.options.oRouters.preview, oForm, function(result) {
if (result.bStateError) {
ls.msg.error(null, result.sMsg);
} else {
oPreview.show().html(result.sText);
ls.hook.run('ls_topic_preview_after', [oForm, oPreview, result]);
}
}, {
submitButton: oButton
});
};
/**
* Закрытие превью
*/
this.hidePreviewText = function() {
$('#topic-text-preview').hide();
};
return this;
}).call(ls.topic || {}, jQuery);