(function($) { // @todo Document this. $.extend($,{ placeholder: { browser_supported: function() { return this._supported !== undefined ? this._supported : ( this._supported = !!('placeholder' in $('')[0]) ); }, shim: function(opts) { var config = { color: '#888', cls: 'placeholder', selector: 'input[placeholder], textarea[placeholder]' }; $.extend(config,opts); return !this.browser_supported() && $(config.selector)._placeholder_shim(config); } }}); $.extend($.fn,{ _placeholder_shim: function(config) { function calcPositionCss(target) { var op = $(target).offsetParent().offset(); var ot = $(target).offset(); return { top: ot.top - op.top, left: ot.left - op.left, width: $(target).width() }; } function adjustToResizing(label) { var $target = label.data('target'); if(typeof $target !== "undefined") { label.css(calcPositionCss($target)); $(window).one("resize", function () { adjustToResizing(label); }); } } return this.each(function() { var $this = $(this); if( $this.is(':visible') ) { if( $this.data('placeholder') ) { var $ol = $this.data('placeholder'); $ol.css(calcPositionCss($this)); return true; } var possible_line_height = {}; if( !$this.is('textarea') && $this.css('height') != 'auto') { possible_line_height = { lineHeight: $this.css('height'), whiteSpace: 'nowrap' }; } var isBorderBox = ($this.css('box-sizing') === 'border-box'); var isTextarea = $this.is('textarea'); var ol = $('