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, " "); $.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