UNPKG

840 BJavaScriptView Raw
1import $ from '../jquery';
2import skate from '../internal/skate';
3
4(function () {
5 if ('placeholder' in document.createElement('input')) {
6 return;
7 }
8
9 function applyDefaultText (input) {
10 var value = String(input.value).trim();
11 if (!value.length) {
12 input.value = input.getAttribute('placeholder');
13 $(input).addClass('aui-placeholder-shown');
14 }
15 }
16
17 skate('placeholder', {
18 type: skate.type.ATTRIBUTE,
19 events: {
20 blur: applyDefaultText,
21 focus: function (input) {
22 if (input.value === input.getAttribute('placeholder')) {
23 input.value = '';
24 $(input).removeClass('aui-placeholder-shown');
25 }
26 }
27 },
28 created: applyDefaultText
29 });
30}());