Created
January 3, 2012 10:04
-
-
Save byroot/1554322 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From 84ac611267f44d8b0bd1fdec2cf92b24cebd4907 Mon Sep 17 00:00:00 2001 | |
| From: Jean Boussier <jean.boussier@tigerlilyapps.com> | |
| Date: Tue, 3 Jan 2012 10:55:46 +0100 | |
| Subject: [PATCH] Fix jquery.placeholder to avoid absolute positions | |
| --- | |
| vendor/assets/javascripts/jquery.placeholder.js | 14 +++++++------- | |
| 1 files changed, 7 insertions(+), 7 deletions(-) | |
| diff --git a/vendor/assets/javascripts/jquery.placeholder.js b/vendor/assets/javascripts/jquery.placeholder.js | |
| index 384712e..97801e1 100644 | |
| --- a/vendor/assets/javascripts/jquery.placeholder.js | |
| +++ b/vendor/assets/javascripts/jquery.placeholder.js | |
| @@ -61,7 +61,7 @@ Thanks to... | |
| labelClass: 'placeholder' | |
| }; | |
| - //check for native support for placeholder attribute, if so stub methods and return | |
| + // check for native support for placeholder attribute, if so stub methods and return | |
| var input = document.createElement("input"); | |
| if ('placeholder' in input) { | |
| $.fn.placeholder = $.fn.unplaceholder = function(){}; //empty function | |
| @@ -73,22 +73,26 @@ Thanks to... | |
| //bind to resize to fix placeholders when the page resizes (fields are hidden/displayed, which can change positioning). | |
| $(window).resize(checkResize); | |
| - | |
| $.fn.placeholder = function(options) { | |
| + console.log('placeholder'); | |
| bindEvents(); | |
| var opts = $.extend(default_options, options) | |
| this.each(function(){ | |
| var rnd=Math.random().toString(32).replace(/\./,'') | |
| + ,wrapper=$('<div>').addClass('placeholder-wrapper').css({'position': 'relative', 'border': '0', 'margin': '0', 'padding': '0'}) | |
| ,input=$(this) | |
| - ,label=$('<label style="position:absolute;display:none;top:0;left:0;"></label>'); | |
| + ,label=$('<label>').css({'position': 'absolute', 'display': 'none', 'top': '0', 'left': '0'}); | |
| if (!input.attr('placeholder') || input.data(ph) === ph) return; //already watermarked | |
| //make sure the input tag has an ID assigned, if not, assign one. | |
| if (!input.attr('id')) input.attr('id', 'input_' + rnd); | |
| + wrapper.insertBefore(input); | |
| + input.remove().appendTo(wrapper); | |
| + | |
| label .attr('id',input.attr('id') + "_placeholder") | |
| .data(ph, '#' + input.attr('id')) //reference to the input tag | |
| .attr('for',input.attr('id')) | |
| @@ -184,11 +188,7 @@ Thanks to... | |
| if ((forced || label.css('display') == 'none') && !input.val()) | |
| label | |
| .text(input.attr('placeholder')) | |
| - .css('top', input.position().top + 'px') | |
| - .css('left', input.position().left + 'px') | |
| .css('display', 'block'); | |
| - | |
| - //console.dir({ 'input': { 'id':input.attr('id'), 'pos': input.position() }}); | |
| } | |
| var cr; | |
| -- | |
| 1.7.4.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment