Skip to content
This repository was archived by the owner on Feb 20, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions bootstrapForm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="./floatlabels.js"></script>
<!--<link rel="stylesheet" href="./floatlabels.css">-->

<title>Floating labels</title>
</head>

<body>
<div class="container">
<h1>Bootstrap floating labels</h1>

<form role="form">
<div class="row">
<div class="form-group col-xs-12">
<input class="form-control floatlabel" type="text" name="title" placeholder="Title" value="test">
</div>
</div>
<div class="row">
<div class="form-group col-xs-6">
<input class="form-control floatlabel" type="text" name="price" placeholder="Price">
</div>
<div class="form-group col-xs-6">
<select class="form-control floatlabel" placeholder="Specific location (optional)">
<option></option><option selected>Ontario</option><option>Quebec</option><option>Other</option>
</select>
</div>
</div>
<div class="row">
<div class="form-group col-xs-12">
<textarea placeholder="Description" class="form-control floatlabel" rows="5"></textarea>
</div>
</div>
</form>
</div>
</body>
</html>

<script type="text/javascript">
$(document).ready(function () {
//$('.floatlabel').floatlabel({ labelStartTop: '-5px', paddingOffset : '3px', backgroundColor: 'white' });
$('.floatlabel').floatlabel();
});
</script>
71 changes: 52 additions & 19 deletions floatlabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
transitionDuration : 0.1,
transitionEasing : 'ease-in-out',
labelClass : '',
backgroundColor : 'transparent',
typeMatches : /text|password|email|number|search|url/
};
function Plugin ( element, options ) {
Expand All @@ -38,8 +39,11 @@
'-ms-transition' : 'all ' + transDuration + 's ' + transEasing,
'transition' : 'all ' + transDuration + 's ' + transEasing
};
if( thisElement.prop('tagName').toUpperCase() !== 'INPUT' ) { return; }
if( !settings.typeMatches.test( thisElement.attr('type') ) ) { return; }
if( thisElement.prop('tagName').toUpperCase() !== 'INPUT' &&
thisElement.prop('tagName').toUpperCase() !== 'TEXTAREA' &&
thisElement.prop('tagName').toUpperCase() !== 'SELECT') { return; }
if( thisElement.prop('tagName').toUpperCase() == 'INPUT' &&
!settings.typeMatches.test( thisElement.attr('type') ) ) { return; }
var elementID = thisElement.attr('id');
if( !elementID ) {
elementID = Math.floor( Math.random() * 100 ) + 1;
Expand All @@ -55,19 +59,42 @@
thisElement.wrap('<div class="floatlabel-wrapper" style="position:relative"></div>');
thisElement.before('<label for="' + elementID + '" class="label-floatlabel ' + settings.labelClass + ' ' + extraClasses + '">' + floatingText + '</label>');
this.$label = thisElement.prev('label');
this.$label.css({
'position' : 'absolute',
'top' : settings.labelStartTop,
'left' : '8px', //thisElement.css('padding-left'),
'display' : 'none',
'-moz-opacity' : '0',
'-khtml-opacity' : '0',
'-webkit-opacity' : '0',
'opacity' : '0',
'font-size' : '11px',
'font-weight' : 'bold',
'color' : '#838780'
});
//this.$label.css({ 'top' : settings.labelStartTop });
if (thisElement.prop('tagName').toUpperCase() == 'SELECT') {
this.$label.css({
'position' : 'absolute',
'top' : settings.labelStartTop,
'left' : '8px', //thisElement.css('padding-left'),
'font-size' : '11px',
'font-weight' : 'bold',
'color' : '#838780',
'background-color' : settings.backgroundColor,
'padding-left' : '5px',
'padding-right' : '5px',
'display' : 'block',
'-moz-opacity' : '1',
'-khtml-opacity' : '1',
'-webkit-opacity' : '1',
'opacity' : '1'
});
} else {
this.$label.css({
'position' : 'absolute',
'top' : settings.labelStartTop,
'left' : '8px', //thisElement.css('padding-left'),
'font-size' : '11px',
'font-weight' : 'bold',
'color' : '#838780',
'background-color' : settings.backgroundColor,
'padding-left' : '5px',
'padding-right' : '5px',
'display' : 'none',
'-moz-opacity' : '0',
'-khtml-opacity' : '0',
'-webkit-opacity' : '0',
'opacity' : '0',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An extra , here.

});
}
if( !settings.slideInput ) {
thisElement.css({ 'padding-top' : this.inputPaddingTop });
}
Expand All @@ -94,23 +121,29 @@
if( thisElement.data('flout') === '1' && currentFlout !== '1' ) {
this.showLabel();
}
if( thisElement.data('flout') === '0' && currentFlout !== '0' ) {
this.hideLabel();
if (thisElement.prop('tagName').toUpperCase() !== 'SELECT') {
if( thisElement.data('flout') === '0' && currentFlout !== '0' ) {
this.hideLabel();
}
}
},
showLabel: function() {
var self = this;
self.$label.css({ 'display' : 'block' });
window.setTimeout(function() {
self.$label.css({
'top' : self.settings.labelEndTop,
'top' : self.settings.labelStartTop,
'-moz-opacity' : '1',
'-khtml-opacity' : '1',
'-webkit-opacity' : '1',
'opacity' : '1'
});
if( self.settings.slideInput ) {
self.$element.css({ 'padding-top' : self.inputPaddingTop });
if (self.$element.prop('tagName').toUpperCase() !== 'SELECT') {
self.$element.css({ 'padding-top' : self.inputPaddingTop });
} else {
self.$element.css({ 'padding-top' : self.inputPaddingTop - parseFloat(self.settings.labelStartTop) - 6 });
}
}
self.$element.addClass('active-floatlabel');
}, 50);
Expand Down
2 changes: 1 addition & 1 deletion floatlabels.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.