Sha256: e8fdf05ebaad6995db16048a665cf26cc284e97fe253eda45a069225a6fbb398

Contents?: true

Size: 1.5 KB

Versions: 62

Compression:

Stored size: 1.5 KB

Contents

/**
 * @namespace WORKAREA.autocompleteFields
 */
WORKAREA.registerModule('autocompleteFields', (function () {
    'use strict';

    var addPlaceholder = function ($field) {
            var placeholder = $field.prop('placeholder') ||
                I18n.t('workarea.admin.js.autocomplete_fields.placeholder');

            $field.prop('placeholder', placeholder);
        },

        getSource = function (url) {
            return function (request, response) {
                $.getJSON(url, { q: request.term }, function (data) {
                    response(data.results);
                });
            };
        },

        initAutocomplete = function ($field) {
            var url = $field.data('autocompleteField');

            return $field.autocomplete({
                minLength: 2,
                source: getSource(url),
                position: {
                    my: 'center top',
                    at: 'center bottom',
                    collision: 'none'
                }
            });
        },

        defineInjectionPoint = function (index, field) {
            $(field).parent().addClass('ui-front');
            return $(field);
        },

        setup = _.flow(defineInjectionPoint, initAutocomplete, addPlaceholder),

        /**
         * @method
         * @name init
         * @memberof WORKAREA.autocompleteFields
         */
        init = function ($scope) {
            $('[data-autocomplete-field]', $scope).each(setup);
        };

    return {
        init: init
    };
}()));

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.5.26 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.45 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.5.25 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.5.23 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.44 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.5.22 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.43 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.5.21 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.42 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.5.20 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.41 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.5.19 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.40 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.5.18 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.39 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.5.17 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.38 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.5.16 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.37 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js