1/** 2 * Displays default text in the input field when its value is empty. 3 * If the browser supports placeholder input attributes (HTML5), then 4 * we skip this component. 5 * 6 * Usage: 7 * <pre> 8 * <input placeholder="Some default text"> 9 * </pre> 10 * 11 * Events thrown: reset.placeholder 12 */ 13define('confluence/placeholder', [ 14 'jquery', 15 'document' 16], function( 17 $, 18 document 19) { 20 'use strict'; 21 22 /** 23 * @exports confluence/placeholder 24 */ 25 return function(scope) { 26 scope = scope || document.body; 27 28 var ignoredClasses = ['autocomplete-multiuser', 'select2-input']; 29 // browser supports placeholder, no need to do anything 30 var temp = document.createElement('input'); 31 if ('placeholder' in temp) { 32 return; 33 } 34 35 // support old attributes default-text, cause it was introduced in 3.3. 36 $('textarea[placeholder][data-placeholder-bound!="true"],' 37 + 'input[placeholder][data-placeholder-bound!="true"],' 38 + 'input.default-text[data-placeholder-bound!="true"]', scope).each(function() { 39 var $this = $(this).attr('data-placeholder-bound', 'true'); 40 41 // HACK: Ignore fields that don't actually need the placeholder behaviour 42 for (var i = 0, numIgnoredClasses = ignoredClasses.length; i < numIgnoredClasses; ++i) { 43 if ($this.hasClass(ignoredClasses[i])) { 44 return; 45 } 46 } 47 48 // Since we insert the placeholder as value for browsers that do not support the tag we need to remove it 49 // before submitting or or it will be treated as the value for that field 50 $this.bind('reset.placeholder', function(e, data) { 51 var form = data.element.closest('form'); 52 form.bind('submit', function() { 53 if (data.element.hasClass('placeholded')) { 54 data.element.val(''); 55 } 56 }); 57 }); 58 59 60 var applyDefaultText = function() { 61 if ($.trim($this.val()).length) { 62 return; 63 } 64 var defaultText = $this.attr('placeholder') || $this.attr('data-default-text'); 65 $this.val(defaultText) 66 .addClass('placeholded') 67 .trigger('reset.placeholder', { element: $this, defaultText: defaultText }); 68 $this.trigger('reset.default-text'); 69 }; 70 var clearDefaultText = function() { 71 if (!$this.hasClass('placeholded')) { 72 return; 73 } 74 $this.val(''); 75 $this.removeClass('placeholded'); 76 }; 77 78 applyDefaultText(); 79 $this.blur(applyDefaultText).focus(clearDefaultText) 80 // Needed because IE does not fire a focus event when clicking on this field from a Select2 field. 81 // It also doesn't fire a blur event when moving focus from this field to a Select2 field, but that's not 82 // easily fixable :( 83 .mousedown(clearDefaultText); 84 }); 85 }; 86}); 87 88require('confluence/module-exporter').safeRequire('confluence/placeholder', function(placeholder) { 89 'use strict'; 90 91 var AJS = require('ajs'); 92 var Confluence = require('confluence/legacy'); 93 94 AJS.Confluence.Binder.placeholder = placeholder; 95 // for backwards compatibility 96 Confluence.Binder.inputDefaultText = placeholder; 97});
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.