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: '#888', 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 function adjustToResizing(label) { 34 var $target = label.data('target'); 35 if(typeof $target !== "undefined") { 36 label.css(calcPositionCss($target)); 37 $(window).one("resize", function () { adjustToResizing(label); }); 38 } 39 } 40 return this.each(function() { 41 var $this = $(this); 42 43 if( $this.is(':visible') ) { 44 45 if( $this.data('placeholder') ) { 46 var $ol = $this.data('placeholder'); 47 $ol.css(calcPositionCss($this)); 48 return true; 49 } 50 51 var possible_line_height = {}; 52 if( !$this.is('textarea') && $this.css('height') != 'auto') { 53 possible_line_height = { lineHeight: $this.css('height'), whiteSpace: 'nowrap' }; 54 } 55 56 var isBorderBox = ($this.css('box-sizing') === 'border-box'); 57 var isTextarea = $this.is('textarea'); 58 59 var ol = $('<label />') 60 .text($this.attr('placeholder')) 61 .addClass(config.cls) 62 .css($.extend({ 63 position:'absolute', 64 display: 'inline', 65 'float':'none', 66 overflow:'hidden', 67 textAlign: 'left', 68 color: config.color, 69 cursor: 'text', 70 paddingTop: !isTextarea && isBorderBox ? '0' : $this.css('padding-top'), 71 paddingRight: $this.css('padding-right'), 72 paddingBottom: !isTextarea && isBorderBox ? '0' : $this.css('padding-bottom'), 73 paddingLeft: $this.css('padding-left'), 74 fontSize: $this.css('font-size'), 75 fontFamily: $this.css('font-family'), 76 fontStyle: $this.css('font-style'), 77 fontWeight: $this.css('font-weight'), 78 textTransform: $this.css('text-transform'), 79 backgroundColor: 'transparent', 80 zIndex: 99 81 }, possible_line_height)) 82 .css(calcPositionCss(this)) 83 .attr('for', this.id) 84 .data('target',$this) 85 .click(function(){ 86 if (!$(this).data('target').is(':disabled')) { 87 $(this).data('target').focus(); 88 } 89 }) 90 .insertBefore(this); 91 $this 92 .data('placeholder', ol) 93 .on('keydown', function () { 94 ol.hide(); 95 }) 96 .on('blur change', function () { 97 ol[$this.val().length ? 'hide' : 'show'](); 98 }) 99 .triggerHandler('blur'); 100 $(window).one("resize", function () { adjustToResizing(ol); }); 101 } 102 }); 103 } 104 }); 105})(jQuery); 106 107jQuery(document).add(window).bind('ready load', function() { 108 if (jQuery.placeholder) { 109 jQuery.placeholder.shim(); 110 } 111}); 112
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.