1(function($) { 2 // @todo Document this. 3 $.extend($,{ placeholder: { 4 browser_supported: function() { 5 return this._supported !== undefined ? 6 this._supported : 7 ( this._supported = !!('placeholder' in $('<input type="text">')[0]) ); 8 }, 9 shim: function(opts) { 10 var config = { 11 color: '#fff', 12 cls: 'placeholder', 13 selector: 'input[placeholder], textarea[placeholder]' 14 }; 15 $.extend(config,opts); 16 return !this.browser_supported() && $(config.selector)._placeholder_shim(config); 17 } 18 }}); 19 20 $.extend($.fn,{ 21 _placeholder_shim: function(config) { 22 function calcPositionCss(target) 23 { 24 var op = $(target).offsetParent().offset(); 25 var ot = $(target).offset(); 26 27 return { 28 top: ot.top - op.top, 29 left: ot.left - op.left, 30 width: $(target).width() 31 }; 32 } 33 return this.each(function() { 34 var $this = $(this); 35 36 if( $this.is(':visible') ) { 37 38 if( $this.data('placeholder') ) { 39 var $ol = $this.data('placeholder'); 40 $ol.css(calcPositionCss($this)); 41 return true; 42 } 43 44 var possible_line_height = {}; 45 if( !$this.is('textarea') && $this.css('height') != 'auto') { 46 possible_line_height = { lineHeight: $this.css('height'), whiteSpace: 'nowrap' }; 47 } 48 49 var ol = $('<label />') 50 .text($this.attr('placeholder')) 51 .addClass(config.cls) 52 .css($.extend({ 53 position:'absolute', 54 display: 'inline', 55 float:'none', 56 overflow:'hidden', 57 textAlign: 'left', 58 color: config.color, 59 cursor: 'text', 60 paddingTop: $this.css('padding-top'), 61 paddingRight: $this.css('padding-right'), 62 paddingBottom: $this.css('padding-bottom'), 63 paddingLeft: $this.css('padding-left'), 64 fontSize: $this.css('font-size'), 65 fontFamily: $this.css('font-family'), 66 fontStyle: $this.css('font-style'), 67 fontWeight: $this.css('font-weight'), 68 textTransform: $this.css('text-transform'), 69 backgroundColor: 'transparent', 70 zIndex: 99 71 }, possible_line_height)) 72 .css(calcPositionCss(this)) 73 .attr('for', this.id) 74 .data('target',$this) 75 .click(function(){ 76 $(this).data('target').focus(); 77 }) 78 .insertBefore(this); 79 $this 80 .data('placeholder',ol) 81 .focus(function(){ 82 ol.hide(); 83 }).blur(function() { 84 ol[$this.val().length ? 'hide' : 'show'](); 85 }).triggerHandler('blur'); 86 $(window) 87 .resize(function() { 88 var $target = ol.data('target'); 89 ol.css(calcPositionCss($target)); 90 }); 91 } 92 }); 93 } 94 }); 95})(jQuery); 96 97jQuery(document).add(window).bind('ready load', function() { 98 if (jQuery.placeholder) { 99 jQuery.placeholder.shim(); 100 } 101}); 102
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.