1/* 2 * In-Field Label jQuery Plugin + å°ãã«ã¹ã¿ãã¤ãº 3 * http://fuelyourcoding.com/scripts/infield.html 4 * 5 * Copyright (c) 2009 Doug Neiner 6 * Dual licensed under the MIT and GPL licenses. 7 * Uses the same license as jQuery, see: 8 * http://docs.jquery.com/License 9 * 10 * @version 0.1 11 */ 12(function($){ 13 14 $.InFieldLabels = function(label,field, options){ 15 // To avoid scope issues, use 'base' instead of 'this' 16 // to reference this class from internal events and functions. 17 var base = this; 18 19 // Access to jQuery and DOM versions of each element 20 base.$label = $(label); 21 base.label = label; 22 23 base.$field = $(field); 24 base.field = field; 25 26 base.$label.data("InFieldLabels", base); 27 base.showing = true; 28 29 base.init = function(){ 30 // Merge supplied options with default options 31 base.options = $.extend({},$.InFieldLabels.defaultOptions, options); 32 33 // Check if the field is already filled in 34 if(base.$field.val() != ""){ 35 base.$label.hide(); 36 base.showing = false; 37 }; 38 39 base.$field.focus(function(){ 40 base.fadeOnFocus(); 41 }).blur(function(){ 42 base.checkForEmpty(true); 43 }).bind('keydown.infieldlabel',function(e){ 44 // Use of a namespace (.infieldlabel) allows us to 45 // unbind just this method later 46 base.hideOnChange(e); 47 }).change(function(e){ 48 base.checkForEmpty(); 49 }).bind('onPropertyChange', function(){ 50 base.checkForEmpty(); 51 }); 52 }; 53 54 // If the label is currently showing 55 // then fade it down to the amount 56 // specified in the settings 57 base.fadeOnFocus = function(){ 58 if(base.showing){ 59 base.setOpacity(base.options.fadeOpacity); 60 }; 61 }; 62 63 base.setOpacity = function(opacity){ 64 base.$label.stop().animate({ opacity: opacity }, base.options.fadeDuration); 65 base.showing = (opacity > 0.0); 66 }; 67 68 // Checks for empty as a fail safe 69 // set blur to true when passing from 70 // the blur event 71 base.checkForEmpty = function(blur){ 72 if(base.$field.val() == ""){ 73 base.prepForShow(); 74 base.setOpacity( blur ? 1.0 : base.options.fadeOpacity ); 75 } else { 76 base.setOpacity(0.0); 77 }; 78 }; 79 80 base.prepForShow = function(e){ 81 if(!base.showing) { 82 // Prepare for a animate in... 83 base.$label.css({opacity: 0.0}).show(); 84 85 // Reattach the keydown event 86 base.$field.bind('keydown.infieldlabel',function(e){ 87 base.hideOnChange(e); 88 }); 89 }; 90 }; 91 92 base.hideOnChange = function(e){ 93 if( 94 (e.keyCode == 16) || // Skip Shift 95 (e.keyCode == 9) // Skip Tab 96 ) return; 97 98 if(base.showing){ 99 base.$label.hide(); 100 base.showing = false; 101 }; 102 103 // Remove keydown event to save on CPU processing 104 base.$field.unbind('keydown.infieldlabel'); 105 }; 106 107 // Run the initialization method 108 base.init(); 109 }; 110 111 $.InFieldLabels.defaultOptions = { 112 fadeOpacity: 0.5, // Once a field has focus, how transparent should the label be 113 fadeDuration: 300 // How long should it take to animate from 1.0 opacity to the fadeOpacity 114 }; 115 116 117 $.fn.inFieldLabels = function(options){ 118 return this.each(function(){ 119 // Find input or textarea based on for= attribute 120 // The for attribute on the label must contain the ID 121 // of the input or textarea element 122 var for_attr = $(this).attr('for'); 123 if( !for_attr ) return; // Nothing to attach, since the for field wasn't used 124 125 126 // Find the referenced input or textarea element 127 // ããã«inputã®emailã«ã対å¿ãããããã«è¿½å ãã¾ãã 128 var $field = $( 129 "input#" + for_attr + "[type='text']," + 130 "input#" + for_attr + "[type='password']," + 131 "input#" + for_attr + "[type='email']," + 132 "textarea#" + for_attr 133 ); 134 135 if( $field.length == 0) return; // Again, nothing to attach 136 137 // Only create object for input[text], input[password], or textarea 138 (new $.InFieldLabels(this, $field[0], options)); 139 }); 140 }; 141 142})(jQuery);
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.