jquery-placeholder-rails 2.0.7 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c98350a2a4e127c82b99e0d38136b3e0c9872f6
4
- data.tar.gz: 6cadd17d9843f8c27c7620b18c923fe7108438f7
3
+ metadata.gz: fc43a228cf81ad7714e7667e39ce9a15f316ca9d
4
+ data.tar.gz: d47edb1dcaf700f96ff4c2ca32f16c12533ef4bd
5
5
  SHA512:
6
- metadata.gz: 33520bc41e3437a303349dbf994fc8e0c887e8e2d3617dec66e515c3dfe6b2e58ca8f6a1cfac4ab9c27edfb82eabeeb7bcbf3249144b7a45baf515546be4c0e3
7
- data.tar.gz: e3e7423e70d1c422c01c3195553cd9dcb7d0488c1ec5c13fe99f79ec3b0e9788c2dd67703ab3d4ac6eac93cd1ea61ca8103f2493ee691c86b50fc12d223bdb52
6
+ metadata.gz: 795770998c968efe8f0512e6bd74069089827154f22ee9d03c97d7a35a1117c4e76cafcd2fd6a4cd2dcd8b1c8525be58bc17cbb225dc69e5a7fc1c7bef98ff0f
7
+ data.tar.gz: d05069709af725aa85e0a39aed3c11bf1e778f7caf336632108db604ff985d80570a50e020043d239121c08d311657ab46145b288250a33770d1befc36588670
@@ -1,7 +1,7 @@
1
1
  module JQuery
2
2
  module Placeholder
3
3
  module Rails
4
- VERSION = '2.0.7'
4
+ VERSION = '2.1.2'
5
5
  end
6
6
  end
7
7
  end
@@ -1,16 +1,28 @@
1
- /*! http://mths.be/placeholder v2.0.7 by @mathias */
2
- ;(function(window, document, $) {
1
+ /*! http://mths.be/placeholder v2.1.2 by @mathias */
2
+ (function(factory) {
3
+ if (typeof define === 'function' && define.amd) {
4
+ // AMD
5
+ define(['jquery'], factory);
6
+ } else if (typeof module === 'object' && module.exports) {
7
+ factory(require('jquery'));
8
+ } else {
9
+ // Browser globals
10
+ factory(jQuery);
11
+ }
12
+ }(function($) {
3
13
 
4
- var isInputSupported = 'placeholder' in document.createElement('input'),
5
- isTextareaSupported = 'placeholder' in document.createElement('textarea'),
6
- prototype = $.fn,
7
- valHooks = $.valHooks,
8
- hooks,
9
- placeholder;
14
+ // Opera Mini v7 doesn't support placeholder although its DOM seems to indicate so
15
+ var isOperaMini = Object.prototype.toString.call(window.operamini) == '[object OperaMini]';
16
+ var isInputSupported = 'placeholder' in document.createElement('input') && !isOperaMini;
17
+ var isTextareaSupported = 'placeholder' in document.createElement('textarea') && !isOperaMini;
18
+ var valHooks = $.valHooks;
19
+ var propHooks = $.propHooks;
20
+ var hooks;
21
+ var placeholder;
10
22
 
11
23
  if (isInputSupported && isTextareaSupported) {
12
24
 
13
- placeholder = prototype.placeholder = function() {
25
+ placeholder = $.fn.placeholder = function() {
14
26
  return this;
15
27
  };
16
28
 
@@ -18,11 +30,17 @@
18
30
 
19
31
  } else {
20
32
 
21
- placeholder = prototype.placeholder = function() {
33
+ var settings = {};
34
+
35
+ placeholder = $.fn.placeholder = function(options) {
36
+
37
+ var defaults = {customClass: 'placeholder'};
38
+ settings = $.extend({}, defaults, options);
39
+
22
40
  var $this = this;
23
41
  $this
24
42
  .filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]')
25
- .not('.placeholder')
43
+ .not('.'+settings.customClass)
26
44
  .bind({
27
45
  'focus.placeholder': clearPlaceholder,
28
46
  'blur.placeholder': setPlaceholder
@@ -38,21 +56,33 @@
38
56
  hooks = {
39
57
  'get': function(element) {
40
58
  var $element = $(element);
41
- return $element.data('placeholder-enabled') && $element.hasClass('placeholder') ? '' : element.value;
59
+
60
+ var $passwordInput = $element.data('placeholder-password');
61
+ if ($passwordInput) {
62
+ return $passwordInput[0].value;
63
+ }
64
+
65
+ return $element.data('placeholder-enabled') && $element.hasClass(settings.customClass) ? '' : element.value;
42
66
  },
43
67
  'set': function(element, value) {
44
68
  var $element = $(element);
69
+
70
+ var $passwordInput = $element.data('placeholder-password');
71
+ if ($passwordInput) {
72
+ return $passwordInput[0].value = value;
73
+ }
74
+
45
75
  if (!$element.data('placeholder-enabled')) {
46
76
  return element.value = value;
47
77
  }
48
- if (value == '') {
78
+ if (value === '') {
49
79
  element.value = value;
50
80
  // Issue #56: Setting the placeholder causes problems if the element continues to have focus.
51
- if (element != document.activeElement) {
81
+ if (element != safeActiveElement()) {
52
82
  // We can't use `triggerHandler` here because of dummy text/password inputs :(
53
83
  setPlaceholder.call(element);
54
84
  }
55
- } else if ($element.hasClass('placeholder')) {
85
+ } else if ($element.hasClass(settings.customClass)) {
56
86
  clearPlaceholder.call(element, true, value) || (element.value = value);
57
87
  } else {
58
88
  element.value = value;
@@ -62,14 +92,20 @@
62
92
  }
63
93
  };
64
94
 
65
- isInputSupported || (valHooks.input = hooks);
66
- isTextareaSupported || (valHooks.textarea = hooks);
95
+ if (!isInputSupported) {
96
+ valHooks.input = hooks;
97
+ propHooks.value = hooks;
98
+ }
99
+ if (!isTextareaSupported) {
100
+ valHooks.textarea = hooks;
101
+ propHooks.value = hooks;
102
+ }
67
103
 
68
104
  $(function() {
69
105
  // Look for forms
70
106
  $(document).delegate('form', 'submit.placeholder', function() {
71
107
  // Clear the placeholder values so they don't get submitted
72
- var $inputs = $('.placeholder', this).each(clearPlaceholder);
108
+ var $inputs = $('.'+settings.customClass, this).each(clearPlaceholder);
73
109
  setTimeout(function() {
74
110
  $inputs.each(setPlaceholder);
75
111
  }, 10);
@@ -78,7 +114,7 @@
78
114
 
79
115
  // Clear placeholder values upon page reload
80
116
  $(window).bind('beforeunload.placeholder', function() {
81
- $('.placeholder').each(function() {
117
+ $('.'+settings.customClass).each(function() {
82
118
  this.value = '';
83
119
  });
84
120
  });
@@ -87,8 +123,8 @@
87
123
 
88
124
  function args(elem) {
89
125
  // Return an object of element attributes
90
- var newAttrs = {},
91
- rinlinejQuery = /^jQuery\d+$/;
126
+ var newAttrs = {};
127
+ var rinlinejQuery = /^jQuery\d+$/;
92
128
  $.each(elem.attributes, function(i, attr) {
93
129
  if (attr.specified && !rinlinejQuery.test(attr.name)) {
94
130
  newAttrs[attr.name] = attr.value;
@@ -98,11 +134,11 @@
98
134
  }
99
135
 
100
136
  function clearPlaceholder(event, value) {
101
- var input = this,
102
- $input = $(input);
103
- if (input.value == $input.attr('placeholder') && $input.hasClass('placeholder')) {
137
+ var input = this;
138
+ var $input = $(input);
139
+ if (input.value == $input.attr('placeholder') && $input.hasClass(settings.customClass)) {
104
140
  if ($input.data('placeholder-password')) {
105
- $input = $input.hide().next().show().attr('id', $input.removeAttr('id').data('placeholder-id'));
141
+ $input = $input.hide().nextAll('input[type="password"]:first').show().attr('id', $input.removeAttr('id').data('placeholder-id'));
106
142
  // If `clearPlaceholder` was called from `$.valHooks.input.set`
107
143
  if (event === true) {
108
144
  return $input[0].value = value;
@@ -110,30 +146,29 @@
110
146
  $input.focus();
111
147
  } else {
112
148
  input.value = '';
113
- $input.removeClass('placeholder');
114
- input == document.activeElement && input.select();
149
+ $input.removeClass(settings.customClass);
150
+ input == safeActiveElement() && input.select();
115
151
  }
116
152
  }
117
153
  }
118
154
 
119
155
  function setPlaceholder() {
120
- var $replacement,
121
- input = this,
122
- $input = $(input),
123
- $origInput = $input,
124
- id = this.id;
125
- if (input.value == '') {
126
- if (input.type == 'password') {
156
+ var $replacement;
157
+ var input = this;
158
+ var $input = $(input);
159
+ var id = this.id;
160
+ if (input.value === '') {
161
+ if (input.type === 'password') {
127
162
  if (!$input.data('placeholder-textinput')) {
128
163
  try {
129
- $replacement = $input.clone().attr({ 'type': 'text' });
164
+ $replacement = $input.clone().prop({ 'type': 'text' });
130
165
  } catch(e) {
131
166
  $replacement = $('<input>').attr($.extend(args(this), { 'type': 'text' }));
132
167
  }
133
168
  $replacement
134
169
  .removeAttr('name')
135
170
  .data({
136
- 'placeholder-password': true,
171
+ 'placeholder-password': $input,
137
172
  'placeholder-id': id
138
173
  })
139
174
  .bind('focus.placeholder', clearPlaceholder);
@@ -144,14 +179,22 @@
144
179
  })
145
180
  .before($replacement);
146
181
  }
147
- $input = $input.removeAttr('id').hide().prev().attr('id', id).show();
182
+ $input = $input.removeAttr('id').hide().prevAll('input[type="text"]:first').attr('id', id).show();
148
183
  // Note: `$input[0] != input` now!
149
184
  }
150
- $input.addClass('placeholder');
185
+ $input.addClass(settings.customClass);
151
186
  $input[0].value = $input.attr('placeholder');
152
187
  } else {
153
- $input.removeClass('placeholder');
188
+ $input.removeClass(settings.customClass);
154
189
  }
155
190
  }
156
191
 
157
- }(this, document, jQuery));
192
+ function safeActiveElement() {
193
+ // Avoid IE9 `document.activeElement` of death
194
+ // https://github.com/mathiasbynens/jquery-placeholder/pull/99
195
+ try {
196
+ return document.activeElement;
197
+ } catch (exception) {}
198
+ }
199
+
200
+ }));
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-placeholder-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Navin Peiris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-11 00:00:00.000000000 Z
11
+ date: 2015-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: jQuery Placeholder for the Rails asset pipeline
@@ -45,7 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - .gitignore
48
+ - ".gitignore"
49
49
  - Gemfile
50
50
  - LICENSE.txt
51
51
  - README.md
@@ -67,17 +67,17 @@ require_paths:
67
67
  - lib
68
68
  required_ruby_version: !ruby/object:Gem::Requirement
69
69
  requirements:
70
- - - '>='
70
+ - - ">="
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - '>='
75
+ - - ">="
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []
79
79
  rubyforge_project:
80
- rubygems_version: 2.0.4
80
+ rubygems_version: 2.4.5
81
81
  signing_key:
82
82
  specification_version: 4
83
83
  summary: jQuery Placeholder is a utility used to enable HTML5 placeholder text in