Sha256: 54e7fd1bf9c651bd6ea6a5d958442ef02198db461dad3dde3cd51b2dba7bd0c3

Contents?: true

Size: 999 Bytes

Versions: 11

Compression:

Stored size: 999 Bytes

Contents

/**
 * Add data-insert to an element. When that element is also data-remote, the
 * server's response will be appended into the element matching the value of
 * the data-insert attribute. (with WORKAREA modules initialized). If that
 * element is also insert-before or insert-after, the response will instead
 * be inserted before or after, respectively, the matching element.
 */

$(document).on('ajax:success', function (event, response) {
    var $element = $(event.target),
        targetSelector = $element.data('insert'),
        $target,
        $content;

    if (! $element.is('[data-insert]')) { return; }
    if (_.isEmpty(targetSelector)) { return; }

    $target = $(targetSelector);
    $content = $(response);

    if ($element.is('[data-insert-after]')) {
        $content.insertAfter($target);
    } else if ($element.is('[data-insert-before]')) {
        $content.insertBefore($target);
    } else {
        $target.append($content);
    }

    WORKAREA.initModules($content);
});

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/assets/javascripts/jquery_ujs/insert.js
workarea-admin-3.5.26 app/assets/javascripts/jquery_ujs/insert.js
workarea-admin-3.5.25 app/assets/javascripts/jquery_ujs/insert.js
workarea-admin-3.5.23 app/assets/javascripts/jquery_ujs/insert.js
workarea-admin-3.5.22 app/assets/javascripts/jquery_ujs/insert.js
workarea-admin-3.5.21 app/assets/javascripts/jquery_ujs/insert.js
workarea-admin-3.5.20 app/assets/javascripts/jquery_ujs/insert.js
workarea-admin-3.5.19 app/assets/javascripts/jquery_ujs/insert.js
workarea-admin-3.5.18 app/assets/javascripts/jquery_ujs/insert.js
workarea-admin-3.5.17 app/assets/javascripts/jquery_ujs/insert.js
workarea-admin-3.5.16 app/assets/javascripts/jquery_ujs/insert.js