Sha256: 3c6ca184ff2e28431f821b0337a7af6432054be9288d33f763e7ff907804e2db
Contents?: true
Size: 1.32 KB
Versions: 3
Compression:
Stored size: 1.32 KB
Contents
// Implements the jQuery load div pattern // See effective_reports admin screen $(document).on('change', "[data-load-ajax-url][data-load-ajax-div]", function(event) { let $input = $(event.currentTarget); let url = $input.data('load-ajax-url'); let div = $input.data('load-ajax-div'); let $container = $input.closest('form').find(div); if(div.length == 0) { console.error("Unable to find load ajax div " + div); return; } let name = ($input.attr('name').split(/\[|\]/)[1] || ''); if(name.length == 0) { console.error("Unable to parse load ajax input name " + $input.attr('name')); return; } let value = ($input.val() || ''); if(value.length == 0) { $container.html(''); return; } let joiner = (url.indexOf('?') == -1 ? '?' : '&'); let input = {} input[name] = value; url = (url + joiner + $.param(input)); $container.html("<div class='load-ajax-loading'><p>Loading...</p></div>"); let $content = $('<div></div>'); $content.load(url + ' ' + div, function(response, status, xhr) { if(status == 'error') { $container.append("<div class='load-ajax-error'><p>Error: please refresh the page and try again.</p></div>"); } else { $container.replaceWith($content.children(div)); EffectiveBootstrap.initialize(); $(document).trigger('effective-datatables:initialize'); } }); });
Version data entries
3 entries across 3 versions & 1 rubygems