$("document").ready(function(){ //Initialisieren Loadinganimation.init(); }); var Loadinganimation = { imgSrc: '/path/to/ajax_load_big.gif', init: function(){ //Anwenden auf alle Links außer JS-Links, interne Links und solche mit der Klasse ".noLoadingAnimation" $("a[href]").not("a[href=javascript:;]").not("a[href=#]").not(".noLoadingAnimation").each(function(i, element){ //Nur Elemente, die keine JS-Events haben (TODO: Nur click-events beachten) if(typeof $(element).data("events") == 'undefined' || $(element).data("events").length==0){ $(element).click(function(eventObject){ //Nicht bei Öffnen in neuem Tab (Strg+Klick) if (!eventObject.ctrlKey) { Loadinganimation.show(); } }); } }); //Bei Formularversand auch ausfuehren, wenn keine anderen Events registriert sind. $("form").submit(function(){ console.log($(this).data("events")); if(typeof $(this).data("events") == 'undefined' || $(this).data("events").length==0){ Loadinganimation.show(); } }); //Bei Klick auf die Animation ausblenden $("div#loadinganimation").click(function(){ Loadinganimation.hide(); }); //Bei ESC wieder ausblenden document.onkeydown = function(e){ if (e == null) { // ie keycode = event.keyCode; } else { // mozilla keycode = e.which; } if(keycode == 27){ // escape, close box Loadinganimation.hide(); } }; }, /** * Zeigt die Ladegrafik als Layer über der Seite. */ show: function(){ //Nur einblenden, wenn nicht bereits eingeblendet! if($("div#loadinganimation").length==0){ $("body").append( '
'+Drupal.t('Loading')+'...'+Drupal.t('Loading')+'...'+Drupal.t('Loading')+'...
'+Drupal.t('Loading')+'...
' ); } }, /** * Versteckt die Ladegrafik über der Seite. */ hide: function(){ $("div#loadinganimation").remove(); } }