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 diff --git a/src/placeholder_polyfill.jquery.js b/src/placeholder_polyfill.jquery.js index 2c3f48f..dea73d2 100644 --- a/src/placeholder_polyfill.jquery.js +++ b/src/placeholder_polyfill.jquery.js @@ -27,25 +27,25 @@ } 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, + height : ta ? input.innerHeight() - 6 : 'auto', 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(); @@ -155,20 +155,22 @@ 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/ - $(document).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); }); // 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