|
28 | 28 |
|
29 | 29 | } else {
|
30 | 30 |
|
31 |
| - placeholder = $.fn.placeholder = function() { |
| 31 | + var settings = {}; |
| 32 | + |
| 33 | + placeholder = $.fn.placeholder = function(options) { |
| 34 | + |
| 35 | + var defaults = {customClass: 'placeholder'}; |
| 36 | + settings = $.extend({}, defaults, options); |
| 37 | + |
32 | 38 | var $this = this;
|
33 | 39 | $this
|
34 | 40 | .filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]')
|
35 |
| - .not('.placeholder') |
| 41 | + .not('.'+settings.customClass) |
36 | 42 | .bind({
|
37 | 43 | 'focus.placeholder': clearPlaceholder,
|
38 | 44 | 'blur.placeholder': setPlaceholder
|
|
74 | 80 | // We can't use `triggerHandler` here because of dummy text/password inputs :(
|
75 | 81 | setPlaceholder.call(element);
|
76 | 82 | }
|
77 |
| - } else if ($element.hasClass('placeholder')) { |
| 83 | + } else if ($element.hasClass(settings.customClass)) { |
78 | 84 | clearPlaceholder.call(element, true, value) || (element.value = value);
|
79 | 85 | } else {
|
80 | 86 | element.value = value;
|
|
97 | 103 | // Look for forms
|
98 | 104 | $(document).delegate('form', 'submit.placeholder', function() {
|
99 | 105 | // Clear the placeholder values so they don't get submitted
|
100 |
| - var $inputs = $('.placeholder', this).each(clearPlaceholder); |
| 106 | + var $inputs = $('.'+settings.customClass, this).each(clearPlaceholder); |
101 | 107 | setTimeout(function() {
|
102 | 108 | $inputs.each(setPlaceholder);
|
103 | 109 | }, 10);
|
|
106 | 112 |
|
107 | 113 | // Clear placeholder values upon page reload
|
108 | 114 | $(window).bind('beforeunload.placeholder', function() {
|
109 |
| - $('.placeholder').each(function() { |
| 115 | + $('.'+settings.customClass).each(function() { |
110 | 116 | this.value = '';
|
111 | 117 | });
|
112 | 118 | });
|
|
128 | 134 | function clearPlaceholder(event, value) {
|
129 | 135 | var input = this;
|
130 | 136 | var $input = $(input);
|
131 |
| - if (input.value == $input.attr('placeholder') && $input.hasClass('placeholder')) { |
| 137 | + if (input.value == $input.attr('placeholder') && $input.hasClass(settings.customClass)) { |
132 | 138 | if ($input.data('placeholder-password')) {
|
133 | 139 | $input = $input.hide().nextAll('input[type="password"]:first').show().attr('id', $input.removeAttr('id').data('placeholder-id'));
|
134 | 140 | // If `clearPlaceholder` was called from `$.valHooks.input.set`
|
|
138 | 144 | $input.focus();
|
139 | 145 | } else {
|
140 | 146 | input.value = '';
|
141 |
| - $input.removeClass('placeholder'); |
| 147 | + $input.removeClass(settings.customClass); |
142 | 148 | input == safeActiveElement() && input.select();
|
143 | 149 | }
|
144 | 150 | }
|
|
174 | 180 | $input = $input.removeAttr('id').hide().prevAll('input[type="text"]:first').attr('id', id).show();
|
175 | 181 | // Note: `$input[0] != input` now!
|
176 | 182 | }
|
177 |
| - $input.addClass('placeholder'); |
| 183 | + $input.addClass(settings.customClass); |
178 | 184 | $input[0].value = $input.attr('placeholder');
|
179 | 185 | } else {
|
180 |
| - $input.removeClass('placeholder'); |
| 186 | + $input.removeClass(settings.customClass); |
181 | 187 | }
|
182 | 188 | }
|
183 | 189 |
|
|
0 commit comments