// Avoid `console` errors in browsers that lack a console. (function() { var method; var noop = function () {}; var methods = [ 'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn' ]; var length = methods.length; var console = (window.console = window.console || {}); while (length--) { method = methods[length]; // Only stub undefined methods. if (!console[method]) { console[method] = noop; } } }()); var App = function(){ var init = function(){ console.log('================'); console.log('application init'); //initParallaxBackground(); initNavigation(); $(window).trigger('app_initialized'); }; var rpcCall = function(method, params, callback, silent){ silent = (!!silent); var request = { method: method, params: params, id: new Date().getTime() }; var payload = JSON.stringify(request); $.ajax({ timeout:30000, type: 'POST', url: '/rpc/', data: payload, dataType: 'json', success: function(response) { if (typeof(callback) == 'function') { callback(response); } }, error: function(response, statusText) { if(statusText == 'timeout'){ if(!silent) { alert('timeout'); } } else { if (typeof(callback) == 'function') { callback(response); } else { if(!silent){ alert('Fehler! ' + JSON.stringify(response.error)); } } } } }); }; var scrollTo = function($element, offset, speed){ offset = offset || 0; if($element.length > 0){ speed = speed || 500; $(window).scrollTo($element, speed, { offset:offset }); } }; var initNavigation = function(){ $('#navTrigger').on('click', function(e){ e.preventDefault(); $('#navList').slideToggle('fast'); }); $('#zumkontaktzeug').on('click', function(e){ //e.preventDefault(); $('#navList').slideToggle('fast'); }); }; var initParallaxBackground = function(){ var $elements = $('.parallaxBackground'); $(window).scroll(function() { $elements.each(function(){ var $el = $(this); var yPos = -($(window).scrollTop() / $el.data('speed')); $el.css({ backgroundPosition: '50% '+ yPos + 'px' }); }); }); }; return { init:init, rpcCall:rpcCall, scrollTo:scrollTo } };