// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require admin/jquery-migrate.min
//= require jquery.ui.all
//= require jquery.ui.datepicker-ru
//= require jquery-ui-timepicker-addon
//= require admin/vendor/jquery-ui-timepicker-addon-ru
//= require jquery_ujs
//= require admin/vendor/bootstrap.min
//= require jquery.remotipart
//= require admin/vendor/jquery.tokeninput.patched
//= require admin/vendor/jquery.tagsinput
//= require admin/vendor/underscore-min
//= require js-routes
//= require ckeditor/init
//= require admin/photo_uploader
//= require_self
//= require admin/custom_admin
function setupWymEditor(wrappedSet) {
var upload = wrappedSet.data('upload');
var table = wrappedSet.data('table');
var hStyles = wrappedSet.data('h');
var hideBlockquote = (wrappedSet.data('hide-blockquote') === true);
var html = wrappedSet.data('html');
var preview = wrappedSet.data('preview');
var toolsItems = [
{'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'},
{'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
{'name': 'InsertOrderedList', 'title': 'Ordered_List', 'css': 'wym_tools_ordered_list'},
{'name': 'InsertUnorderedList', 'title': 'Unordered_List', 'css': 'wym_tools_unordered_list'},
{'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
{'name': 'Paste', 'title': 'Paste_From_Word', 'css': 'wym_tools_paste'},
{'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
{'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'}
];
if (table) {
toolsItems.push({'name': 'InsertTable', 'title': 'Table', 'css': 'wym_tools_table'});
}
if (html) {
toolsItems.push({'name': 'ToggleHtml', 'title': 'HTML', 'css': 'wym_tools_html'});
}
if (preview) {
toolsItems.push({'name': 'Preview', 'title': 'Preview', 'css': 'wym_tools_preview'});
}
var wym_options = {
lang: 'ru', rmUnwantedBr: true,
jQueryPath: '/assets/jquery.js',
toolsItems: toolsItems,
logoHtml: "", classesHtml: "", statusHtml: "", containersHtml: "",
postInit: function (wym) {
if (!hideBlockquote) {
var bqClass = 'wym_tools_blockquote';
var bqHtml = buttonHtml("Цитата ", bqClass, '/wysiwyg/skins/default/icons.png');
$(wym._box).find(wym._options.toolsSelector + wym._options.toolsListSelector).prepend(bqHtml);
$(wym._box).find('li.' + bqClass + ' a').click(function () {
wym.container('BLOCKQUOTE');
return(false);
});
}
// CURRENTLY DOESNT WORK
// if (table) {
// var bqClass = 'wym_tools_th';
// var bqHtml = buttonHtml("Заголовок таблицы ", bqClass, '/wysiwyg/skins/default/icons.png');
// $(wym._box).find(wym._options.toolsSelector + wym._options.toolsListSelector).prepend(bqHtml);
// $(wym._box).find('li.' + bqClass + ' a').click(function () {
// wym.container('TH');
// return(false);
// });
// }
if (!hStyles) {
hStyles = [1, 2, 3, 4, 5, 6];
}
for (var j = hStyles.length - 1; j >= 0; j--) {
(function (c) {
var cls = 'wym_tools_heading' + c;
var html = buttonHtml("Заголовок " + c, cls, '/wysiwyg/skins/default/icons.png');
$(wym._box).find(wym._options.toolsSelector + wym._options.toolsListSelector).prepend(html);
$(wym._box).find('li.' + cls + ' a').click(function () {
wym.container('H' + c);
return(false);
});
})(hStyles[j]);
}
var cls = 'wym_tools_paragraph';
var html = buttonHtml("Абзац", cls, '/wysiwyg/skins/default/icons.png');
$(wym._box).find(wym._options.toolsSelector + wym._options.toolsListSelector).prepend(html);
$(wym._box).find('li.' + cls + ' a').click(function () {
wym.container('P');
return(false);
});
if (upload) {
wym.imageupload_init('/article_images', 'image')
}
$('.wym_buttons').addClass('btn-toolbar').find('li').addClass('btn-group').find('a').addClass('btn');
}
};
wrappedSet.wymeditor(wym_options);
function buttonHtml(title, cls, path_to_icon) {
var html = "
"
+ ""
+ title
+ "";
return html;
}
}
function injectNewSliderId(s, id) {
return s.replace(/NEW_RECORD/g, id);
}
(function ($) {
$.fn.stickyBar = function () {
if (this.length){
var $bar = this,
barOffsetTop = $bar.offset().top,
barOuterHeight = $bar.outerHeight(),
windowScrollTop = $(window).scrollTop(),
windowHeight = $(window).height();
if (barOffsetTop + barOuterHeight > windowScrollTop + windowHeight) {
$bar.addClass('__sticky');
}
$(window).scroll(function () {
windowScrollTop = $(window).scrollTop();
windowHeight = $(window).height();
if (barOffsetTop + barOuterHeight > windowScrollTop + windowHeight) {
$bar.addClass('__sticky');
} else {
$bar.removeClass('__sticky');
}
});
}
}
})(jQuery);
$(function () {
$(document).on('click', '.pictograms__button_remove', function () {
var
$this = $(this),
container = '.' + $this.data('container');
var input = $this.prev(':hidden');
if (input.size() > 0) {
$(input[0]).attr("value", "1");
$this.closest(container).hide();
} else {
$(this).closest(container).remove();
}
return false;
});
$(document).on('click', '[data-image-remove-btn]', function () {
var container = $(this).closest('.upload-img-container');
container.find('[data-image-preview]').hide();
container.find('[data-image-placeholder]').show();
container.find('[data-image-remove-flag]').val(1);
return false;
});
$('.sortable').sortable();
$('.wymeditor').each(function () {
setupWymEditor($(this));
});
function merge_datepicker_options($element) {
var options = {
dateFormat: 'yy-mm-dd',
changeMonth: true,
changeYear: true
};
var customOptions = $element.data('calendar-options');
if (customOptions) {
options = $.extend(options, customOptions);
}
return options;
}
function addDatePickers() {
$('input[data-calendar-date]').each(function () {
$this = $(this);
$this.datepicker(merge_datepicker_options($this));
});
}
addDatePickers();
function addDateTimePickers() {
$('input[data-calendar-datetime]').each(function () {
$this = $(this);
$this.datetimepicker(merge_datepicker_options($this));
});
}
addDateTimePickers();
$(document).on('click', '.close-popover-form', function () {
$('.pictograms__button_edit').popover('hide');
$('.popover').css('display', 'none');
});
$(document).on('click', '.submit-popover-form', function () {
var
$title = $(this).closest('.slide-form-group').find('input[type="text"]');
$('#' + $title.attr('id')).val($title.val());
$('.pictograms__button_edit').popover('hide');
$('.popover').css('display', 'none');
});
var $form = $('form');
$form.on('click', '.remove_field', function () {
$(this).prev('input[type=hidden]').val('1');
$(this).closest('.fields_container').hide();
return false;
});
$form.on('click', '.add_fields', function () {
var time = new Date().getTime();
var regexp = new RegExp($(this).data('id'), 'g');
$(this).before($(this).data('fields').replace(regexp, time));
window.NestedFormCallbacks = window.NestedFormCallbacks || [];
_.each(window.NestedFormCallbacks, function (callback) {
callback();
});
addDatePickers();
addDateTimePickers();
return false
});
$('[data-multi-field]').each(function () {
var options = { crossDomain: false,
preventDuplicates: true,
hintText: 'Введите строку для поиска',
noResultsText: 'Ничего не найдено',
searchingText: 'Поиск...',
theme: 'facebook',
showAllOnFocus: $(this).data('show-all-on-focus'),
useCache: $(this).data('use-cache')
};
var objectUrlName = $(this).data('object-url-name');
if (objectUrlName) {
var formatter_options = {tokenFormatter: function (item) {
return "" + item[this.propertyToSearch] + "
"
}
};
options = $.extend(options, formatter_options);
}
$(this).tokenInput($(this).data('source'), options);
});
$('.action-bar').stickyBar();
$(document).on('change', '[data-file-upload]', function () {
var filename = $(this).val().replace(/.*(\/|\\)/, '');
$(this).closest('[data-file-upload-container]').find('[data-file-upload-title]').text(filename);
});
});
CKEDITOR.config.extraPlugins = 'slideshow,mediaembed,autogrow';
CKEDITOR.config.removeButtons = 'About,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,BidiLtr,BidiRtl,Language,Scayt,Smiley,SpellChecker,Templates,Indent,CreateDiv,HorizontalRule,Flash,NewPage,PageBreak,Iframe,Styles,FontSize,Font,TextColor,BGColor,JustifyLeft,JustifyCenter,JustifyRight,JustifyBlock';
CKEDITOR.config.removePlugins = 'scayt,smiley';
CKEDITOR.config.language = 'ru';