Sha256: 7adb2f7a055eb9954a9015ca41f1028b1ffa44d0a8f5ddb9b7e193c599810f42

Contents?: true

Size: 1.27 KB

Versions: 15

Compression:

Stored size: 1.27 KB

Contents

$(function() {
  "use strict";

  var $input = $(".search__input");
  var activeSuffix = "--active";
  var timeout;

  $.fn.textWidth = function(text, font) {
    if (!$.fn.textWidth.fakeEl) {
      $.fn.textWidth.fakeEl = $('<span style="display: none;">')
                              .appendTo(document.body);
    }

    var htmlText = text || this.val() || this.text();
    htmlText = $.fn.textWidth.fakeEl.text(htmlText).html();
    htmlText = htmlText.replace(/\s/g, "&nbsp;");
    $.fn.textWidth.fakeEl.html(htmlText).css("font", font || this.css("font"));
    return $.fn.textWidth.fakeEl.width();
  };

  var activate = function(className) {
    $("." + className).addClass(className + activeSuffix);
  };

  var deactivate = function(className) {
    $("." + className).removeClass(className + activeSuffix);
  };

  $input.on("focus",   function() { activate("search__icon"); });
  $input.on("blur",    function() { deactivate("search__icon"); });
  $input.on("keydown", function() { deactivate("search__hint"); });

  var showHint = function() { activate("search__hint"); };

  $input.on("keyup", function() {
    clearTimeout(timeout);

    if($input.val().length) {
      $(".search__hint").css("left", $input.textWidth() + 75);
      timeout = setTimeout(showHint, 250);
    }
  });
});

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
administrate-0.7.0 app/assets/javascripts/administrate/components/_search.js
administrate-0.6.0 app/assets/javascripts/administrate/components/_search.js
administrate-0.5.0 app/assets/javascripts/administrate/components/_search.js
administrate-0.4.0 app/assets/javascripts/administrate/components/_search.js
administrate-0.3.0 app/assets/javascripts/administrate/components/_search.js
administrate-0.2.2 app/assets/javascripts/administrate/components/_search.js
administrate-0.2.1 app/assets/javascripts/administrate/components/_search.js
administrate-0.2.0 app/assets/javascripts/administrate/components/_search.js
administrate-0.2.0.rc1 app/assets/javascripts/administrate/components/_search.js
administrate-0.1.5 app/assets/javascripts/administrate/components/_search.js
administrate-0.1.4 app/assets/javascripts/administrate/components/_search.js
administrate-0.1.3 app/assets/javascripts/administrate/components/_search.js
administrate-0.1.2 app/assets/javascripts/administrate/components/_search.js
administrate-0.1.1 app/assets/javascripts/administrate/components/_search.js
administrate-0.1.0 app/assets/javascripts/administrate/components/_search.js