aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/generators/rails/app/templates/public/javascripts/jquery.compat.js
blob: 6f5427fbce15132f85a0e5901ea0a42a195f1463 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
jQuery(function ($) {
    function evalAttribute(element, attribute) {
        var el = $(element); 
        var attr = el.attr('data-' + attribute);
        if(attr) {
            eval(attr);
        }
    }

    $('form[data-remote="true"],a[data-remote="true"],input[data-remote="true"]')
        .live('before', function (e) {
            evalAttribute(this, 'onbefore'); 
        })
        .live('after', function (e, xhr) {
            evalAttribute(this, 'onafter'); 
        })
        .live('loading', function (e, xhr) {
            evalAttribute(this, 'onloading'); 
        })
        .live('loaded', function (e, xhr) {
            evalAttribute(this, 'onloaded'); 
        })
        .live('complete', function (e, xhr) {
            evalAttribute(this, 'oncomplete'); 
            evalAttribute(this, 'on' + xhr.status); 
        })
        .live('success', function (e, data, status, xhr) {
            evalAttribute(this, 'onsuccess'); 
        })
        .live('failure', function (e, xhr, status, error) {
            evalAttribute(this, 'onfailure'); 
        });
});