From 10c200bf456ff07927cf7b809683a50569f00928 Mon Sep 17 00:00:00 2001 From: Mika Majakorpi Date: Tue, 24 Feb 2015 18:43:41 +0200 Subject: [PATCH 1/4] Fix placeholder positioning to happen more reliably on window resize and to position vertically in the middle of input element. --- src/placeholder_polyfill.jquery.js | 37 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/placeholder_polyfill.jquery.js b/src/placeholder_polyfill.jquery.js index 2c3f48f..d8a1b99 100644 --- a/src/placeholder_polyfill.jquery.js +++ b/src/placeholder_polyfill.jquery.js @@ -27,25 +27,24 @@ } function positionPlaceholder(placeholder,input){ var ta = input.is('textarea'); - var pt = parseFloat(input.css('padding-top')); - var pl = parseFloat(input.css('padding-left')); - - // Determine if we need to shift the header down more. - var offset = input.offset(); - if (pt) { - offset.top += pt; - } - if (pl) { - offset.left += pl; - } placeholder.css({ width : input.innerWidth()-(ta ? 20 : 4), - height : input.innerHeight()-6, lineHeight : input.css('line-height'), whiteSpace : ta ? 'normal' : 'nowrap', overflow : 'hidden' - }).offset(offset); + }) + + var top = parseInt((input.outerHeight() / 2) - (placeholder.outerHeight() / 2)); + var left = parseFloat(input.css('padding-left')); + var offset = input.offset(); + if (top) { + offset.top += top; + } + if (left) { + offset.left += left; + } + placeholder.offset(offset); } function startFilledCheckChange(input,options){ var val = input.val(); @@ -157,18 +156,18 @@ showPlaceholderIfEmpty(input,o.options); // reformat on window resize and optional reformat on font resize - requires: http://www.tomdeater.com/jquery/onfontresize/ - $(document).bind("fontresize resize", function(){ + $(window).bind("fontresize resize", function(){ positionPlaceholder(placeholder,input); }); // optional reformat when a textarea is being resized - requires http://benalman.com/projects/jquery-resize-plugin/ if($.event.special.resize){ $("textarea").bind("resize", function(event){ - if ($(this).is(":visible")) { - positionPlaceholder(placeholder,input); - } - event.stopPropagation(); - event.preventDefault(); + if ($(this).is(":visible")) { + positionPlaceholder(placeholder,input); + } + event.stopPropagation(); + event.preventDefault(); }); }else{ // we simply disable the resizeablilty of textareas when we can't react on them resizing From af42d6d1e4e84d479bd4f85927b42f6b5765c3e2 Mon Sep 17 00:00:00 2001 From: Mika Majakorpi Date: Tue, 24 Feb 2015 19:01:13 +0200 Subject: [PATCH 2/4] Fix placeholder vertical positioning for text areas by setting height only for text area placeholders. --- src/placeholder_polyfill.jquery.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/placeholder_polyfill.jquery.js b/src/placeholder_polyfill.jquery.js index d8a1b99..e629dae 100644 --- a/src/placeholder_polyfill.jquery.js +++ b/src/placeholder_polyfill.jquery.js @@ -30,6 +30,7 @@ placeholder.css({ width : input.innerWidth()-(ta ? 20 : 4), + height : ta ? input.innerHeight() - 6 : 'auto', lineHeight : input.css('line-height'), whiteSpace : ta ? 'normal' : 'nowrap', overflow : 'hidden' From f0891ef24e5cf8fe5cffa1610d9d49743cc175cd Mon Sep 17 00:00:00 2001 From: Mika Majakorpi Date: Tue, 24 Feb 2015 20:54:42 +0200 Subject: [PATCH 3/4] Added .DS_Store (OS X) to .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3561942..9262f57 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules -/npm-debug.log \ No newline at end of file +/npm-debug.log +.DS_Store \ No newline at end of file From fd45e84f69e92fa0cfb2daa09f3278c6e1ad3a65 Mon Sep 17 00:00:00 2001 From: Mika Majakorpi Date: Tue, 24 Feb 2015 20:57:30 +0200 Subject: [PATCH 4/4] Revert fontresize event handler binding to document object. --- src/placeholder_polyfill.jquery.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/placeholder_polyfill.jquery.js b/src/placeholder_polyfill.jquery.js index e629dae..dea73d2 100644 --- a/src/placeholder_polyfill.jquery.js +++ b/src/placeholder_polyfill.jquery.js @@ -155,9 +155,11 @@ showPlaceholderIfEmpty($(this),o.options); }); showPlaceholderIfEmpty(input,o.options); - - // reformat on window resize and optional reformat on font resize - requires: http://www.tomdeater.com/jquery/onfontresize/ - $(window).bind("fontresize resize", function(){ + $(window).bind("resize", function(){ + positionPlaceholder(placeholder,input); + }); + //optional reformat on font resize - requires: http://www.tomdeater.com/jquery/onfontresize/ + $(document).bind("fontresize", function(){ positionPlaceholder(placeholder,input); });