/// /// var SpecFilter; (function (SpecFilter_1) { var SpecFilter = (function () { function SpecFilter($selector) { this.selected = {}; this.strings = ['специализация', 'специализации', 'специализаций']; this.typeName = 'специализации'; this.$selector = $selector; this.endpointUrl = $selector.data('enpoint-url'); var strings = $selector.data('strings'); var typeName = $selector.data('type-name'); if (strings !== undefined) { this.strings = eval(strings); } if (typeName !== undefined) { this.typeName = typeName; } $.ajax({ url: this.endpointUrl }).done((function (data) { this.content = data; }).bind(this)); this.$selector.click(this.onSelectorClick.bind(this)); this.loadSelected(); } SpecFilter.prototype.onSelectorClick = function (event) { event.preventDefault(); var context = this; var options = { content: this.content, type: 'html', height: 799, width: $('.centerbar').outerWidth(), padding: 0, autoSize: false, afterClose: function () { }, afterShow: function () { context.bindEvents(); context.loadSelected(); } }; $.fancybox(options); }; SpecFilter.prototype.loadSelected = function () { var $fancy = $('.specializations__listBlock--check').parent(); var count = 0; $(this.$selector.data('field')).find(':selected').each(function () { count++; $fancy.find('input[value=' + $(this).val() + ']').prop('checked', 'checked'); }); this.setCount(count); }; SpecFilter.declOfNum = function (number, titles) { var cases = [2, 0, 1, 1, 1, 2]; return titles[(number % 100 > 4 && number % 100 < 20) ? 2 : cases[(number % 10 < 5) ? number % 10 : 5]]; }; SpecFilter.prototype.bindEvents = function () { var context = this; var $fancy = $('.specializations__listBlock--check').parent(); $fancy.find('.btn-primary').click(function () { $(context.$selector.data('field')).find('option').removeAttr('selected'); var count = 0; var all = $fancy.find('input[value=all]').is(':checked'); $fancy.find('.fancycheckbox__checkbox:checked').each(function () { if (all) return null; console.dir($(context.$selector.data('field')) .find('[value=' + $(this).attr('value') + ']')); $(context.$selector.data('field')) .find('[value=' + $(this).attr('value') + ']') .prop('selected', 'selected'); if ($(this).attr('value') !== 'all') count++; }); context.setCount(count); $(context.$selector.data('field')).trigger('change'); $.fancybox.close(); }); $fancy.find('.fancycheckbox__selectGroup').click(function () { var checked = $(this).prop('checked'); $(this).parents('.specializations__listLetter').next().find('.fancycheckbox__checkbox').each(function () { $(this).prop('checked', checked); }); }); $fancy.find('.fancycheckbox__checkbox').click(function () { if ($(this).parents('ul').find('.fancycheckbox__checkbox').length == $(this).parents('ul').find('.fancycheckbox__checkbox:checked').length) { $(this).parents('.specializations__listRow').find('.fancycheckbox__selectGroup').prop('checked', true); } if (!$(this).is(':checked')) { $(this).parents('.specializations__listRow').find('.fancycheckbox__selectGroup').prop('checked', false); } }); $fancy.find('.specializations__listRegionMore').click(function () { var $link = $(this); var $list = $link.prev(); $list.animate({ 'max-height': $list[0].scrollHeight }, 200, function () { $link.remove(); }); }); }; SpecFilter.prototype.checkChecked = function (id) { return this.selected.hasOwnProperty(id); }; SpecFilter.prototype.setCount = function (count) { if (count === void 0) { count = 0; } this.$selector.html('Все ' + this.typeName); if (count > 0) { this.$selector.html(count + ' ' + SpecFilter.declOfNum(count, this.strings)); } }; return SpecFilter; }()); SpecFilter_1.SpecFilter = SpecFilter; })(SpecFilter || (SpecFilter = {}));