HosipLan

Untitled

May 6th, 2011
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(function(){
  2.  
  3.     // vhodně nastylovaný div vložím po načtení stránky
  4.     $('<div id="ajax-spinner"></div>').appendTo("body").ajaxStop(function () {
  5.         // a při události ajaxStop spinner schovám a nastavím mu původní pozici
  6.         $(this).hide().css({
  7.             position: "fixed",
  8.             left: "50%",
  9.             top: "50%"
  10.         });
  11.     }).hide();
  12.  
  13.     // zajaxovatění odkazů
  14.     $("a.ajax").live("click", function (event) {
  15.         event.preventDefault();
  16.  
  17.         $.get(this.href, $.nette.success);
  18.  
  19.         // zobrazení spinneru a nastavení jeho pozice
  20.         $("#ajax-spinner").show();
  21.     });
  22.  
  23.     // ajaxové formuláře
  24.     $(function () {
  25.         // odeslání na formulářích
  26.         $('body').delegate("form.ajax", "submit", function (e) {
  27.             if (!Nette.validateForm(this)) {
  28.                 return false;
  29.             }
  30.  
  31.             $(this).ajaxSubmit(e, {
  32.                 success : $.nette.success
  33.             });
  34.  
  35.         }).delegate("form.ajax :submit", "click", function (e) {
  36.             e = e || event;
  37.             var target = e.target || e.srcElement;
  38.             this['nette-submittedBy'] = (target.type in {submit:1, image:1}) ? target : null;
  39.  
  40.             if (!Nette.validateForm(this.form)) {
  41.                 return false;
  42.             }
  43.  
  44.             $(this).ajaxSubmit(e, {
  45.                 success : $.nette.success
  46.             });
  47.         });
  48.     });
  49.  
  50. });
Advertisement
Add Comment
Please, Sign In to add comment