1/** 2 * jquery.placeholder http://matoilic.github.com/jquery.placeholder 3 * 4 * @version v0.2.4 5 * @author Mato Ilic <[email protected]> 6 * @copyright 2013 Mato Ilic 7 * 8 * Dual licensed under the MIT and GPL licenses: 9 * http://www.opensource.org/licenses/mit-license.php 10 * http://www.gnu.org/licenses/gpl.html 11 */ 12;(function($, doc, debug) { 13 var input = ('placeholder' in doc.createElement('input')), 14 textarea = ('placeholder' in doc.createElement('textarea')), 15 selector = ':input[placeholder]'; 16 17 $.placeholder = {input: input, textarea: textarea}; 18 19 //skip if there is native browser support for the placeholder attribute 20 if(!debug && input && textarea) { 21 $.fn.placeholder = function() {}; 22 return; 23 } 24 25 if(!debug && input && !textarea) { 26 selector = 'textarea[placeholder]'; 27 } 28 29 /* patch jQuery.fn.val to return an empty value if the value matches 30 * the placeholder 31 */ 32 $.fn.realVal = $.fn.val; 33 $.fn.val = function() { 34 var $element = $(this), val, placeholder; 35 if(arguments.length > 0) return $element.realVal.apply(this, arguments); 36 37 val = $element.realVal(); 38 placeholder = $element.attr('placeholder'); 39 40 return ((val == placeholder) ? '' : val); 41 }; 42 43 function clearForm() { 44 $(this).find(selector).each(removePlaceholder); 45 } 46 47 function extractAttributes(elem) { 48 var attr = elem.attributes, copy = {}, skip = /^jQuery\d+/; 49 for(var i = 0; i < attr.length; i++) { 50 if(attr[i].specified && !skip.test(attr[i].name)) { 51 copy[attr[i].name] = attr[i].value; 52 } 53 } 54 return copy; 55 } 56 57 function removePlaceholder() { 58 var $target = $(this), $clone, $orig; 59 60 if($target.is(':password')) return; 61 62 if($target.data('password')) { 63 $orig = $target.next().show().focus(); 64 $('label[for=' + $target.attr('id') + ']').attr('for', $orig.attr('id')); 65 $target.remove(); 66 } else if($target.realVal() == $target.attr('placeholder')) { 67 $target.val(''); 68 $target.removeClass('placeholder'); 69 } 70 } 71 72 function setPlaceholder() { 73 var $target = $(this), $clone, plceholder, hasVal, cid; 74 placeholder = $target.attr('placeholder'); 75 76 if($.trim($target.val()).length > 0) return; 77 78 if($target.is(':password')) { 79 cid = $target.attr('id') + '-clone'; 80 $clone = $('<input/>') 81 .attr($.extend(extractAttributes(this), {type: 'text', value: placeholder, 'data-password': 1, id: cid})) 82 .addClass('placeholder'); 83 84 $target.before($clone).hide(); 85 $('label[for=' + $target.attr('id') + ']').attr('for', cid); 86 } else { 87 $target.val(placeholder); 88 $target.addClass('placeholder'); 89 } 90 } 91 92 $.fn.placeholder = function() { 93 this.filter(selector).each(setPlaceholder); 94 return this; 95 }; 96 97 $(function($) { 98 var $doc = $(doc); 99 $doc.on('submit', 'form', clearForm); 100 $doc.on('focus', selector, removePlaceholder); 101 $doc.on('blur', selector, setPlaceholder); 102 $(selector).placeholder(); 103 }); 104})(jQuery, document, window.debug);
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.