-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
69 lines (58 loc) · 1.82 KB
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
jQuery(document).ready(function($){
'use strict';
(function($) {
$.fn.phAnim = function( options ) {
// Set default option
var settings = $.extend({}, options),
label,
ph;
// get label elem
function getLabel(input) {
return $(input).parent().find('label');
}
// generate an id
function makeid() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
return this.each( function() {
// check if the input has id or create one
if( $(this).attr('id') == undefined ) {
$(this).attr('id', makeid());
}
// check if elem has label or create one
if( getLabel($(this)).length == 0 ) {
// check if elem has placeholder
if( $(this).attr('placeholder') != undefined ) {
ph = $(this).attr('placeholder');
$(this).attr('placeholder', '');
// create a label with placeholder text
$(this).parent().prepend('<label for='+ $(this).attr('id') +'>'+ ph +'</label>');
}
} else {
// if elem has label remove placeholder
$(this).attr('placeholder', '');
// check label for attr or set it
if(getLabel($(this)).attr('for') == undefined ) {
getLabel($(this)).attr('for', $(this).attr('id'));
}
}
$(this).on('focus', function() {
label = getLabel($(this));
label.addClass('active focusIn');
}).on('focusout', function() {
if( $(this).val() == '' ) {
label.removeClass('active');
}
label.removeClass('focusIn');
});
});
};
}(jQuery));
$(document).ready(function() {
$('.custom-input input').phAnim();
});
});