var App = App || {}; App.fancybox = { _formatTitle: function(el) { var $link = $(el.element); var title = el.title; var copy = $link.attr('data-copyright'); var descr = $link.attr('data-description'); return '
\n\
' + title + '
\n' + (copy !== undefined && copy.length > 0 ? '
© ' + copy + '
\n' : '') + (descr !== undefined && descr.length > 0 ? '
' + descr + '
' : '') + '
'; }, init: function() { var that = this; $('.wysiwyg-content a[href]').filter(function() { return /(jpg|gif|png)$/i.test($(this).attr('href')) }).addClass('gallery'); $('a.fancybox-ajax').fancybox({ type: 'ajax', minWidth: 320 }); $("a.gallery").fancybox({ cyclic: true, helpers: { title: { type: 'inside' // 'float', 'inside', 'outside' or 'over' } }, afterLoad: function() { this.title = that._formatTitle(this); } }); } }; App.slideshow = { element: $('#slideshow'), init: function() { if (jQuery().cycle) { this.element.cycle({ fx: 'fade', timeout: 5000, speed: 1500, slides: '.slide', next: '.slideshow-button.next', prev: '.slideshow-button.prev' }); } } }; App.tabs = { element: $('.tabs'), init: function() { var self = this; this.element.find('.tabs-nav a').click(function(e){ e.preventDefault(); self.element.find('.tab').removeClass('active'); self.element.find($(this).attr('href')).addClass('active'); self.element.find('.tabs-nav li').removeClass('active'); $(this).parent().addClass('active'); setProp('lastEstateTab', $(this).attr('href')); }); var hash = window.location.hash; if (hash) { this.element.find('.tabs-nav a[href=' + hash + ']').trigger('click'); } else if (getProp('lastEstateTab')) { this.element.find('.tabs-nav a[href=' + getProp('lastEstateTab') + ']').trigger('click'); } // pokud nejsou taby, tak se vymaze udaj o poslednim aktivnim tabu: if (this.element.find('.tabs-nav').length === 0) { setProp('lastEstateTab', false); } } }; App.emails = { element: $('a.esec'), init: function() { this.element.each(function() { var e = $(this).html(); e = e.replace(/\[ZAVINÁČ\]/g, '@'); e = e.replace(/\[TEČKA\]/g, '.'); $(this).html(e); $(this).attr("href", "mailto:" + e); }); } }; App.captcha = { element: $('form [name=my_captcha]'), init: function() { if (this.element.length > 0) { var self = this; $('body').mouseover(function(){ self.element.val('fuck spam'); }); } } }; App.forms = { errors: $('ul.error'), showErrors: function() { if (this.errors.length > 0) { var html = $('
').append(this.errors.clone()).remove().html(); this.errors.remove(); App.flashMessage.show(html); } }, init: function() { this.showErrors(); $('.submit-on-change').find('input,select').change(function(){ $(this).parents('form').submit(); }); } }; App.flashMessage = { show: function(text) { $.fancybox(text, { padding: 40, minHeight: 0, minWidth: 360, scrolling: "no", maxWidth: 700 }); } }; App.netteAjax = { init: function() { // potvrzeni requestu $.nette.ext('confirm', { load: function (rh) { $('.ajax-confirm').off('click.nette', rh).on('click.nette', rh); }, before: function (a, b, c) { if (!b || !b.nette || !b.nette.el) return; var el = b.nette.el; if (!el.is('.ajax-confirm')) return; return confirm(b.nette.el.attr('data-confirm')); } }); /*$.nette.ext('history', { load: function (rh) { $('.ajax-history').off('click.nette', rh).on('click.nette', rh); }, before: function (a, b, c) { history.replaceState(null, null, b.url); } });*/ // pokud se to ma odkomentovat, musi se opravit referenced-select-box (respektive history se vola i kdyz nema) // spiner $.nette.ext('spinner', { start: function (success) { $('[id^=snippet--]').animate({ 'opacity': 0.4 }, 500); $('#ajax-spinner').show(); }, complete: function (callback) { $('[id^=snippet--]').animate({ 'opacity': 1 }, 500); $('#ajax-spinner').hide(); } }); $.nette.ext('ajaxPageContent', { success: function (payload) { if (payload.snippets) { for (i in payload.snippets) { if (i == 'snippet--ajaxPageContent') { $.fancybox({ content: payload.snippets[i] }); } } } } }); // history.pushState $.nette.ext('push', { prepare: function(settings) { var url = settings.nette.el.attr('data-ajax-push'); if (url) { history.pushState({}, window.title, url); } } }); // pridavani polozek misto prepisovani $.nette.ext('append', { prepare: function(settings) { this.isActive = settings.nette.el.attr('data-ajax-append'); if (this.isActive) { settings.off = ['snippets']; } }, success: function(payload) { if (this.isActive) { for (var i in payload.snippets) { var $el = $('#' + i); var html = payload.snippets[i]; if (i == this.isActive) { var cnt = $el.children().length; $el.append(html); var first = $($el.children().get(cnt)); $('body').animate({ scrollTop: first.offset().top },500); } else { var snippets = this.ext('snippets'); snippets.updateSnippet($el, html); } } } }, complete: function() { this.isActive = false; //sameHeight(); $.nette.load(); } }, { isActive: false }); // init $.nette.init(); } } $(function() { App.fancybox.init(); App.slideshow.init(); App.tabs.init(); App.emails.init(); App.forms.init(); App.netteAjax.init(); $('body').on('click', '.menu-switcher', function(event) { $("header nav").toggleClass("open"); }); $('body').on('click', '.confirm', function(event) { if ($(this).data('confirm')) { return confirm($(this).data('confirm')); } return confirm('Are you sure?'); }); $('body').on('click', '[data-info]', function(event) { event.stopPropagation(); event.preventDefault(); App.flashMessage.show($(this).attr('data-info')); }); $('body').on('click', '[data-toggle]', function(event) { var $this = $(this); var $el = $($this.attr('data-toggle')); $el.toggle(); if ($el.is(':visible')) { $this.addClass('toggle-open'); $el.find('img').trigger("unveil"); } else { $this.removeClass('toggle-open'); } if ($this.is('.hide-siblings')) { $this.siblings('[data-toggle]:visible').each(function(){ $($(this).attr('data-toggle')).hide(); }); } }); $('body').on('click', '[data-toggle-class]', function(event) { event.preventDefault(); $($(this).attr('data-toggle-class')).toggleClass('toggle-class-active'); }); $('body').on('click', '.scroll-to', function(event) { event.preventDefault(); var minus = 56; $('html, body').animate({ scrollTop: $($(this).attr('href')).offset().top - minus }, 500); }); $(".wysiwyg-content img").on('load', function() { if ($(this).get(0).naturalWidth) { $(this).css('max-width', $(this).get(0).naturalWidth + 'px'); $(this).css('width', '100%'); $(this).css('height', 'auto'); } }).each(function () { if (this.complete) $(this).load(); }); }); function getProp(key) { if (typeof (Storage) !== "undefined" && typeof (sessionStorage[key]) !== "undefined") { return sessionStorage[key]; } return null; } function clearProp(key) { if (typeof (Storage) !== "undefined") { return sessionStorage.removeItem(key); } return null; } function setProp(key, value) { if (typeof (Storage) !== "undefined") { sessionStorage[key] = value; } return null; } //--------------------------------------------- // //--------------------------------------------- $.fn.checkInputs = function() { return this.each(function() { var el = $(this); var label = $('label[for=' + el.attr('id') + ']'); var cls = 'input-checked'; if (label.length === 0) label = el.parent('label'); label.addClass('check-inputs-label'); if (label.length) { el.addClass('check-inputs-input'); el.data('label', label); if (el.is('[type=radio]')) { label.addClass('radio'); } else if (el.is('[type=checkbox]')) { label.addClass('checkbox'); } el.change(function(){ if ($(this).is(':checked')) { el.parents('form').find('[name="' + el.attr('name') + '"]').each(function(){ $(this).data('label').removeClass(cls); }); label.addClass(cls); } else label.removeClass(cls); }); if (el.is(':disabled')) { label.addClass('input-disabled'); } if (el.is(':checked')) { label.addClass(cls); } else { label.removeClass(cls); } } }); };