(function($) { var App = App || { // Initialization. init: function () { App.initGlobal(); App.initBlog(); }, //------------------------------------------------------------------------------------------------------------------ // Global //------------------------------------------------------------------------------------------------------------------ initGlobal: function () { App.globalContactForm(); }, globalContactForm: function() { $(document).on('click', '.cf-submitted', function(e) { e.preventDefault(); var form = $(this).closest('form'); App.globalReloadContent(form, '.ajaxify'); }); }, //------------------------------------------------------------------------------------------------------------------ // Blog //------------------------------------------------------------------------------------------------------------------ blogCurentPage: 1, blogPostPerPage: 4, initBlog: function () { App.blogPaging(); }, blogPaging: function() { $(document).on("click", "#more_posts", function() { // When btn is pressed. $(".section-blog-more-block").remove(); //$("#more_posts").attr("disabled",true); // Disable the button, temp. $.post(ajaxurl, { action:"more_blog_items_ajax", offset: (App.blogCurentPage * App.blogPostPerPage), ppp: App.blogPostPerPage }).success(function(posts){ App.blogCurentPage++; $(".ajaxify").append(posts); //$("#more_posts").attr("disabled",false); }); }); }, /** * Perform ajax request. * * @param {String} target * @param {String} content * @param {integer} scroll Scrooll to location? * @param {String} renderPartial Custom renderPartial parameter for request. * @param {String} callback Callback to execute after ajax is done. * @param {bool} async Perform asynchronious request? * @returns {boolean} */ globalReloadContent: function(target, content, scroll, renderPartial, callback, async) { var type = "POST"; var url = ajaxurl; var data = ""; if (typeof target != 'string') { data = target.serialize(); type = "POST"; } else { url = ajaxurl; } $('.form-success', target).hide(); $('.form-input', target).hide(); $('.form-error', target).hide(); jQuery.ajax( { type: type, url: url, data: data, async: (async != undefined ? async : true), success: function (r) { if (async !== false) { if (r == 'success') { $('.form-success', target).show(); } else if (r == 'input') { $('.form-input', target).show(); } else { $('.form-error', target).show(); } } } } ); return false; }, }; // Document ready trigger. $(document).ready(function() { // Run main application initialization. App.init(); }); })(jQuery);