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.4.27 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.5.4 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.26 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.5.3 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.25 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.5.2 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.24 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.5.1 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.23 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.22 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.5.0 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.21 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.5.0.beta.1 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.20 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.19 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.18 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.17 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.16 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.15 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js
workarea-admin-3.4.14 app/assets/javascripts/workarea/admin/modules/autocomplete_fields.js