floatlabels 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 32f08a1de1dd64bd1426963f84cc78c572601c2b
4
+ data.tar.gz: 701649ffd871be71e492ef0b76476a671252a675
5
+ SHA512:
6
+ metadata.gz: bdd44c255f613ea1cc0979beeb3eb4c8dcfe2b99fd9519078a4075bda2497b3b1add9c052ced31b9a134c1dbe2798acd4933d31516c502a9554d6878dfff7cbe
7
+ data.tar.gz: 7be6b9b2fd6bf8596ec21ffedcc78028e52cbd8b853e447adc639ca918fd59a9be92c86964635276e79ffd6707f1b55406dc26789f3455e69266900f134ec5b0
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in floatlabels.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Matt Cameron
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,92 @@
1
+ # Floatlabels
2
+
3
+ Sick of boring old labels that take up space and clog up your beautiful websites?
4
+
5
+ Floatlabels uses floated labels to make your forms look cleaner and smarter. Once a user begins typing, your placeholders automagically turn into labels so the user still has context.
6
+
7
+ ![Demo](demo.gif)
8
+
9
+ ## Installation
10
+
11
+ Add floatlabels to your application's Gemfile:
12
+
13
+ gem 'jquery-rails' # requires jQuery
14
+ gem 'floatlabels'
15
+
16
+ Require floatlabels inside your application.js file, after jQuery.
17
+
18
+ //= require jquery
19
+ //= require floatlabels
20
+
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+
27
+ ## Usage
28
+
29
+ Add the class to the inputs you want to float the labels on
30
+
31
+ <%= f.text_field :example, placeholder: 'Example Label', class: 'floatlabel' %>
32
+
33
+ Initialise floatlabels
34
+
35
+ $('.floatlabel').floatlabel();
36
+
37
+ and hey presto, you've got floated labels!
38
+
39
+ ### Options
40
+
41
+ You can override any of the following default options on initialisation:
42
+
43
+ $('.floatlabel').floatlabel({
44
+ type : 'inside', // ('inside' or 'outside')
45
+ slideInput : true,
46
+ labelHiddenTop : '5px',
47
+ labelShownTop : '0px',
48
+ paddingOffset : '10px',
49
+ transitionDuration : 0.1,
50
+ transitionEasing : 'ease-in-out',
51
+ labelClass : '',
52
+ typeMatches : /text|password|email|number|search|url|tel/,
53
+ focusColor : '#2996cc',
54
+ blurColor : '#9D9D9D',
55
+ fontWeight : 'bold',
56
+ fontSize : '9px'
57
+ });
58
+
59
+
60
+ You can also use `data-label="Example Label"` to set the label text.
61
+
62
+ <%= f.text_field :pirate_name, data: {label: 'Pirate Name'}, class: 'floatlabel form-control' %>
63
+
64
+
65
+ #### Types
66
+
67
+ I added a quick option to switch between labels inside your text input, and labels above the input.
68
+
69
+ Using `type: 'outside'` automatically sets the following:
70
+
71
+ slideInput : false,
72
+ labelShownTop : '-20px',
73
+ paddingOffset : '0px'
74
+
75
+ This will overwrite any custom options you have set for these values with the above.
76
+
77
+ #### More info
78
+ *More documentation can be found at [http://clubdesign.github.io/floatlabels.js](http://clubdesign.github.io/floatlabels.js).*
79
+
80
+ ## Credit
81
+ All credit goes to Marcus Poherely. This is simply a gemified version of his code with some slightly different defaults.
82
+
83
+ - URL: http://clubdesign.github.io/floatlabels.js/
84
+ - Author: Marcus Pohorely ( http://www.clubdesign.at )
85
+ - Copyright: Copyright 2013 / 2014 http://www.clubdesign.at
86
+ - Adapted for bootstrap projects by Michael Levin 2/20/14
87
+ - Slightly modified and gemified by Matt Cameron 15-Mar-2016
88
+
89
+
90
+ ## License
91
+
92
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "floatlabels"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
Binary file
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'floatlabels/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "floatlabels"
8
+ spec.version = Floatlabels::VERSION
9
+ spec.authors = ["Matt Cameron"]
10
+ spec.email = ["mattlbcameron@gmail.com"]
11
+
12
+ spec.summary = "Easily use floating labels on text inputs."
13
+ spec.description = "Automatically use placeholders as a floating label to save space and add context to your forms. Follows the famous Float Label Pattern. Built on jQuery."
14
+ spec.homepage = "https://github.com/mattcameron/floatlabels"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,6 @@
1
+ require "floatlabels/version"
2
+
3
+ module Floatlabels
4
+ class Engine < ::Rails::Engine; end
5
+
6
+ end
@@ -0,0 +1,3 @@
1
+ module Floatlabels
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,186 @@
1
+ /**
2
+ * FloatLabels
3
+ * URL: http://clubdesign.github.io/floatlabels.js/
4
+ * Author: Marcus Pohorely ( http://www.clubdesign.at )
5
+ * Copyright: Copyright 2013 / 2014 http://www.clubdesign.at
6
+ *
7
+ * Adapted for bootstrap projects by Michael Levin 2/20/14
8
+ *
9
+ * Slightly modified and gemified by Matt Cameron 15-Mar-2016
10
+ */
11
+
12
+ ;(function ( $, window, document, undefined ) {
13
+ var defaults = {
14
+ type : 'inside',
15
+ slideInput : true,
16
+ labelHiddenTop : '5px',
17
+ labelShownTop : '0px',
18
+ paddingOffset : '10px',
19
+ transitionDuration : 0.1,
20
+ transitionEasing : 'ease-in-out',
21
+ labelClass : '',
22
+ typeMatches : /text|password|email|number|search|url|tel/,
23
+ focusColor : '#2996cc',
24
+ blurColor : '#9D9D9D',
25
+ fontWeight : 'bold',
26
+ fontSize : '9px'
27
+ };
28
+
29
+ function FloatLabel ( element, options ) {
30
+ this.$element = $(element);
31
+ this.settings = configureSettings(options);
32
+ this.init();
33
+ }
34
+
35
+ function configureSettings(options) {
36
+ settings = $.extend( {}, defaults, options );
37
+
38
+ // Overwrite some settings for easy switch to labels above input
39
+ if (settings.type ==='outside') {
40
+ settings.slideInput = false;
41
+ settings.labelShownTop = '-20px';
42
+ settings.paddingOffset = '0px';
43
+ }
44
+
45
+ return settings;
46
+ }
47
+
48
+ FloatLabel.prototype = {
49
+ init: function () {
50
+ var self = this,
51
+ settings = this.settings,
52
+ thisElement = this.$element,
53
+ transDuration = settings.transitionDuration,
54
+ transEasing = settings.transitionEasing,
55
+ transFull = 'all ' + transDuration + 's ' + transEasing,
56
+ animationCss = {
57
+ '-webkit-transition': transFull,
58
+ '-moz-transition' : transFull,
59
+ '-o-transition' : transFull,
60
+ '-ms-transition' : transFull,
61
+ 'transition' : transFull
62
+ };
63
+
64
+ // Only proceed if element is either an input or textatrea
65
+ if( thisElement.prop('tagName').toUpperCase() != 'INPUT' &&
66
+ thisElement.prop('tagName').toUpperCase() != 'TEXTAREA') { return; }
67
+
68
+ // Make sure the type is allowed (in options)
69
+ if( thisElement.prop('tagName').toUpperCase() === 'INPUT' && !settings.typeMatches.test( thisElement.attr('type') ) ) { return; }
70
+
71
+ // Get element ID or randomly create one (for label)
72
+ var elementID = thisElement.attr('id');
73
+ if( !elementID ) {
74
+ elementID = Math.floor( Math.random() * 100 ) + 1;
75
+ thisElement.attr('id', elementID);
76
+ }
77
+
78
+ var placeholderText = thisElement.attr('placeholder'),
79
+ floatingText = thisElement.data('label'),
80
+ extraClasses = thisElement.data('class');
81
+
82
+ if( !extraClasses ) { extraClasses = ''; }
83
+
84
+ // Friendly reminder
85
+ if( !placeholderText || placeholderText === '' ) { placeholderText = "You forgot to add placeholder attribute!"; }
86
+
87
+ // Use the data attribute if it has been set, otherwise use placeholder
88
+ if( !floatingText || floatingText === '' ) { floatingText = placeholderText; }
89
+
90
+ thisElement.wrap('<div class="floatlabel-wrapper" style="position:relative"></div>');
91
+ thisElement.before('<label for="' + elementID + '" class="label-floatlabel ' + settings.labelClass + ' ' + extraClasses + '">' + floatingText + '</label>');
92
+ this.$label = thisElement.prev('label');
93
+ this.$label.css({
94
+ 'position' : 'absolute',
95
+ 'top' : settings.labelHiddenTop,
96
+ 'left' : '8px',
97
+ 'display' : 'none',
98
+ '-moz-opacity' : '0',
99
+ '-khtml-opacity' : '0',
100
+ '-webkit-opacity': '0',
101
+ 'opacity' : '0',
102
+ 'font-size' : self.settings.fontSize,
103
+ 'font-weight' : self.settings.fontWeight,
104
+ 'color' : self.settings.blurColor
105
+ });
106
+
107
+ this.inputPaddingTop = parseFloat( thisElement.css('padding-top') ) + parseFloat(settings.paddingOffset);
108
+
109
+ if( !settings.slideInput ) {
110
+ thisElement.css('padding-top', this.inputPaddingTop);
111
+ }
112
+
113
+ // Event Handlers
114
+ thisElement.on('keyup blur change', function( e ) {
115
+ self.checkValue( e );
116
+ });
117
+ thisElement.on('blur', function() { thisElement.prev('label').css({ 'color' : self.settings.blurColor }); });
118
+ thisElement.on('focus', function() { thisElement.prev('label').css({ 'color' : self.settings.focusColor }); });
119
+
120
+ window.setTimeout( function() {
121
+ self.$label.css( animationCss );
122
+ self.$element.css( animationCss );
123
+ }, 100);
124
+ this.checkValue();
125
+ },
126
+ checkValue: function( e ) {
127
+ if( e ) {
128
+ var keyCode = e.keyCode || e.which;
129
+ if( keyCode === 9 ) { return; }
130
+ }
131
+ var thisElement = this.$element,
132
+ currentFlout = thisElement.data('flout');
133
+ if( thisElement.val() !== "" ) { thisElement.data('flout', '1'); }
134
+ if( thisElement.val() === "" ) { thisElement.data('flout', '0'); }
135
+ if( thisElement.data('flout') === '1' && currentFlout !== '1' ) {
136
+ this.showLabel();
137
+ }
138
+ if( thisElement.data('flout') === '0' && currentFlout !== '0' ) {
139
+ this.hideLabel();
140
+ }
141
+ },
142
+ showLabel: function() {
143
+ var self = this;
144
+ self.$label.css({ 'display' : 'block' });
145
+ window.setTimeout(function() {
146
+ self.$label.css({
147
+ 'top' : self.settings.labelShownTop,
148
+ '-moz-opacity' : '1',
149
+ '-khtml-opacity' : '1',
150
+ '-webkit-opacity': '1',
151
+ 'opacity' : '1'
152
+ });
153
+ if( self.settings.slideInput ) {
154
+ self.$element.css({ 'padding-top' : self.inputPaddingTop });
155
+ }
156
+ self.$element.addClass('active-floatlabel');
157
+ }, 50);
158
+ },
159
+ hideLabel: function() {
160
+ var self = this;
161
+ self.$label.css({
162
+ 'top' : self.settings.labelHiddenTop,
163
+ '-moz-opacity' : '0',
164
+ '-khtml-opacity' : '0',
165
+ '-webkit-opacity': '0',
166
+ 'opacity' : '0'
167
+ });
168
+ if( self.settings.slideInput ) {
169
+ var paddingTop = parseFloat( self.inputPaddingTop ) - parseFloat(this.settings.paddingOffset);
170
+ self.$element.css({ 'padding-top' : paddingTop });
171
+ }
172
+ self.$element.removeClass('active-floatlabel');
173
+ window.setTimeout(function() {
174
+ self.$label.css({ 'display' : 'none' });
175
+ }, self.settings.transitionDuration * 1000);
176
+ }
177
+ };
178
+
179
+ $.fn.floatlabel = function ( options ) {
180
+ return this.each(function() {
181
+ if ( !$.data( this, "plugin_floatlabel" ) ) {
182
+ $.data( this, "plugin_floatlabel", new FloatLabel( this, options ) );
183
+ }
184
+ });
185
+ };
186
+ })( jQuery, window, document );
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: floatlabels
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Cameron
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Automatically use placeholders as a floating label to save space and
42
+ add context to your forms. Follows the famous Float Label Pattern. Built on jQuery.
43
+ email:
44
+ - mattlbcameron@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - demo.gif
57
+ - floatlabels.gemspec
58
+ - lib/floatlabels.rb
59
+ - lib/floatlabels/version.rb
60
+ - vendor/assets/javascripts/floatlabels.js
61
+ homepage: https://github.com/mattcameron/floatlabels
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.4.8
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Easily use floating labels on text inputs.
85
+ test_files: []