Sha256: 5b51d0d57affed5b65d8f26a4247b1dcc4157abf3769db41924d3a6e57224bf8

Contents?: true

Size: 1.37 KB

Versions: 49

Compression:

Stored size: 1.37 KB

Contents

'use strict';

/**
 * Append or prepend placeholders to certain inputs
 */

exports.init = function () {
  $('.js-prepend-placeholder[placeholder], .js-append-placeholder[placeholder]').each(function () {
    var $this = $(this);
    replace_input_with_group($this, $this.attr('placeholder'), $this.hasClass('js-append-placeholder'));
  });
}

/**
 * Replace an <input> element with an appended/prepended placeholder
 * @param  {jQuery}          $input
 * @param  {string}          placeholder
 * @param  {optional} {bool} reverse - false: prepend, true: append (default false)
 * @return {jQuery}          The new input group
 */
function replace_input_with_group ($input, placeholder, reverse) {
    var placeholder  = placeholder || '',
        reverse      = (typeof reverse === 'undefined') ? false : reverse,
        span_class   = !!reverse ? 'input-append' : 'input-prepend',
        $clone       = $input.clone(),
        $input_group = $('<div class="input-group"></div>'),
        $prepend     = $('<span class="' + span_class + '">' + placeholder + '</span>');

    $prepend.prependTo($input_group);
    $clone.attr('placeholder', '')
          .appendTo($input_group);
    $input.replaceWith($input_group);
    $clone.css(!!reverse ? 'padding-right' : 'padding-left', (parseInt($clone.css('padding-right'), 10) + parseInt($prepend.outerWidth(), 10)) + 'px');

    return $input_group;
}

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
lalala-4.1.0.dev.425 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.1.0.dev.420 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.1.0.dev.419 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.1.0.dev.418 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.1.0.dev.417 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.0.0.dev.416 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.1.0.dev.415 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.1.0.dev.414 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.1.0.dev.413 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.1.0.dev.412 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.1.0.dev.411 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.1.0.dev.410 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.1.0.dev.409 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.0.0.dev.407 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.1.0.dev.408 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.1.0.dev.398 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.1.0.dev.397 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.0.0.dev.396 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.0.0.dev.395 app/assets/javascripts/lalala/modules/input_group.module.js
lalala-4.1.0.dev.394 app/assets/javascripts/lalala/modules/input_group.module.js