22
22
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23
23
* IN THE SOFTWARE.
24
24
*/
25
- ! function ( a ) { "use strict" ; function b ( ) { } function c ( ) { try { return document . activeElement } catch ( a ) { } } function d ( a , b ) { for ( var c = 0 , d = a . length ; d > c ; c ++ ) if ( a [ c ] === b ) return ! 0 ; return ! 1 } function e ( a , b , c ) { return a . addEventListener ?a . addEventListener ( b , c , ! 1 ) :a . attachEvent ?a . attachEvent ( "on" + b , c ) :void 0 } function f ( a , b ) { var c ; a . createTextRange ?( c = a . createTextRange ( ) , c . move ( "character" , b ) , c . select ( ) ) :a . selectionStart && ( a . focus ( ) , a . setSelectionRange ( b , b ) ) } function g ( a , b ) { try { return a . type = b , ! 0 } catch ( c ) { return ! 1 } } function h ( a , b ) { if ( a && a . getAttribute ( B ) ) b ( a ) ; else for ( var c , d = a ?a . getElementsByTagName ( "input" ) :N , e = a ?a . getElementsByTagName ( "textarea" ) :O , f = d ?d . length :0 , g = e ?e . length :0 , h = f + g , i = 0 ; h > i ; i ++ ) c = f > i ?d [ i ] :e [ i - f ] , b ( c ) } function i ( a ) { h ( a , k ) } function j ( a ) { h ( a , l ) } function k ( a , b ) { var c = ! ! b && a . value !== b , d = a . value === a . getAttribute ( B ) ; if ( ( c || d ) && "true" === a . getAttribute ( C ) ) { a . removeAttribute ( C ) , a . value = a . value . replace ( a . getAttribute ( B ) , "" ) , a . className = a . className . replace ( A , "" ) ; var e = a . getAttribute ( I ) ; parseInt ( e , 10 ) >= 0 && ( a . setAttribute ( "maxLength" , e ) , a . removeAttribute ( I ) ) ; var f = a . getAttribute ( D ) ; return f && ( a . type = f ) , ! 0 } return ! 1 } function l ( a ) { var b = a . getAttribute ( B ) ; if ( "" === a . value && b ) { a . setAttribute ( C , "true" ) , a . value = b , a . className += " " + z ; var c = a . getAttribute ( I ) ; c || ( a . setAttribute ( I , a . maxLength ) , a . removeAttribute ( "maxLength" ) ) ; var d = a . getAttribute ( D ) ; return d ?a . type = "text" :"password" === a . type && g ( a , "text" ) && a . setAttribute ( D , "password" ) , ! 0 } return ! 1 } function m ( a ) { return function ( ) { P && a . value === a . getAttribute ( B ) && "true" === a . getAttribute ( C ) ?f ( a , 0 ) :k ( a ) } } function n ( a ) { return function ( ) { l ( a ) } } function o ( a ) { return function ( ) { i ( a ) } } function p ( a ) { return function ( b ) { return v = a . value , "true" === a . getAttribute ( C ) && v === a . getAttribute ( B ) && d ( x , b . keyCode ) ?( b . preventDefault && b . preventDefault ( ) , ! 1 ) :void 0 } } function q ( a ) { return function ( ) { k ( a , v ) , "" === a . value && ( a . blur ( ) , f ( a , 0 ) ) } } function r ( a ) { return function ( ) { a === c ( ) && a . value === a . getAttribute ( B ) && "true" === a . getAttribute ( C ) && f ( a , 0 ) } } function s ( a ) { var b = a . form ; b && "string" == typeof b && ( b = document . getElementById ( b ) , b . getAttribute ( E ) || ( e ( b , "submit" , o ( b ) ) , b . setAttribute ( E , "true" ) ) ) , e ( a , "focus" , m ( a ) ) , e ( a , "blur" , n ( a ) ) , P && ( e ( a , "keydown" , p ( a ) ) , e ( a , "keyup" , q ( a ) ) , e ( a , "click" , r ( a ) ) ) , a . setAttribute ( F , "true" ) , a . setAttribute ( B , T ) , ( P || a !== c ( ) ) && l ( a ) } var t = document . createElement ( "input" ) , u = void 0 !== t . placeholder ; if ( a . Placeholders = { nativeSupport :u , disable :u ?b :i , enable :u ?b :j } , ! u ) { var v , w = [ "text" , "search" , "url" , "tel" , "email" , "password" , "number" , "textarea" ] , x = [ 27 , 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 8 , 46 ] , y = "#ccc" , z = "placeholdersjs" , A = new RegExp ( "(?:^|\\s)" + z + "(?!\\S)" ) , B = "data-placeholder-value" , C = "data-placeholder-active" , D = "data-placeholder-type" , E = "data-placeholder-submit" , F = "data-placeholder-bound" , G = "data-placeholder-focus" , H = "data-placeholder-live" , I = "data-placeholder-maxlength" , J = 100 , K = document . getElementsByTagName ( "head" ) [ 0 ] , L = document . documentElement , M = a . Placeholders , N = document . getElementsByTagName ( "input" ) , O = document . getElementsByTagName ( "textarea" ) , P = "false" === L . getAttribute ( G ) , Q = "false" !== L . getAttribute ( H ) , R = document . createElement ( "style" ) ; R . type = "text/css" ; var S = document . createTextNode ( "." + z + " {color:" + y + ";}" ) ; R . styleSheet ?R . styleSheet . cssText = S . nodeValue :R . appendChild ( S ) , K . insertBefore ( R , K . firstChild ) ; for ( var T , U , V = 0 , W = N . length + O . length ; W > V ; V ++ ) U = V < N . length ?N [ V ] :O [ V - N . length ] , T = U . attributes . placeholder , T && ( T = T . nodeValue , T && d ( w , U . type ) && s ( U ) ) ; var X = setInterval ( function ( ) { for ( var a = 0 , b = N . length + O . length ; b > a ; a ++ ) U = a < N . length ?N [ a ] :O [ a - N . length ] , T = U . attributes . placeholder , T ?( T = T . nodeValue , T && d ( w , U . type ) && ( U . getAttribute ( F ) || s ( U ) , ( T !== U . getAttribute ( B ) || "password" === U . type && ! U . getAttribute ( D ) ) && ( "password" === U . type && ! U . getAttribute ( D ) && g ( U , "text" ) && U . setAttribute ( D , "password" ) , U . value === U . getAttribute ( B ) && ( U . value = T ) , U . setAttribute ( B , T ) ) ) ) :U . getAttribute ( C ) && ( k ( U ) , U . removeAttribute ( B ) ) ; Q || clearInterval ( X ) } , J ) ; e ( a , "beforeunload" , function ( ) { M . disable ( ) } ) } } ( this ) , function ( a , b ) { "use strict" ; var c = a . fn . val , d = a . fn . prop ; b . Placeholders . nativeSupport || ( a . fn . val = function ( a ) { var b = c . apply ( this , arguments ) , d = this . eq ( 0 ) . data ( "placeholder-value" ) ; return void 0 === a && this . eq ( 0 ) . data ( "placeholder-active" ) && b === d ?"" :b } , a . fn . prop = function ( a , b ) { return void 0 === b && this . eq ( 0 ) . data ( "placeholder-active" ) && "value" === a ?"" :d . apply ( this , arguments ) } ) } ( jQuery , this ) ;
25
+ ! function ( a ) { "use strict" ;
26
+ //
27
+ // Utility functions
28
+ //
29
+ // No-op (used in place of public methods when native support is detected).
30
+ function b ( ) { }
31
+ // Avoid IE9 activeElement of death when an iframe is used.
32
+ //
33
+ // More info:
34
+ // - http://bugs.jquery.com/ticket/13393
35
+ // - https://github.com/jquery/jquery/commit/85fc5878b3c6af73f42d61eedf73013e7faae408
36
+ function c ( ) { try { return document . activeElement } catch ( a ) { } }
37
+ // Check whether an item is in an array. We don't use Array.prototype.indexOf
38
+ // so we don't clobber any existing polyfills. This is a really simple
39
+ // alternative.
40
+ function d ( a , b ) { for ( var c = 0 , d = a . length ; c < d ; c ++ ) if ( a [ c ] === b ) return ! 0 ; return ! 1 }
41
+ // Cross-browser DOM event binding
42
+ function e ( a , b , c ) { return a . addEventListener ?a . addEventListener ( b , c , ! 1 ) :a . attachEvent ?a . attachEvent ( "on" + b , c ) :void 0 }
43
+ // Move the caret to the index position specified. Assumes that the element
44
+ // has focus.
45
+ function f ( a , b ) { var c ; a . createTextRange ?( c = a . createTextRange ( ) , c . move ( "character" , b ) , c . select ( ) ) :a . selectionStart && ( a . focus ( ) , a . setSelectionRange ( b , b ) ) }
46
+ // Attempt to change the type property of an input element.
47
+ function g ( a , b ) { try { return a . type = b , ! 0 } catch ( a ) {
48
+ // You can't change input type in IE8 and below.
49
+ return ! 1 } } function h ( a , b ) {
50
+ // Check if the passed in node is an input/textarea (in which case it can't
51
+ // have any affected descendants).
52
+ if ( a && a . getAttribute ( B ) ) b ( a ) ; else for ( var c , d = a ?a . getElementsByTagName ( "input" ) :N , e = a ?a . getElementsByTagName ( "textarea" ) :O , f = d ?d . length :0 , g = e ?e . length :0 , h = f + g , i = 0 ; i < h ; i ++ ) c = i < f ?d [ i ] :e [ i - f ] , b ( c ) }
53
+ // Return all affected elements to their normal state (remove placeholder
54
+ // value if present).
55
+ function i ( a ) { h ( a , k ) }
56
+ // Show the placeholder value on all appropriate elements.
57
+ function j ( a ) { h ( a , l ) }
58
+ // Hide the placeholder value on a single element. Returns true if the
59
+ // placeholder was hidden and false if it was not (because it wasn't visible
60
+ // in the first place).
61
+ function k ( a , b ) { var c = ! ! b && a . value !== b , d = a . value === a . getAttribute ( B ) ; if ( ( c || d ) && "true" === a . getAttribute ( C ) ) { a . removeAttribute ( C ) , a . value = a . value . replace ( a . getAttribute ( B ) , "" ) , a . className = a . className . replace ( A , "" ) ;
62
+ // Restore the maxlength value. Old FF returns -1 if attribute not set.
63
+ // See GH-56.
64
+ var e = a . getAttribute ( I ) ; parseInt ( e , 10 ) >= 0 && ( a . setAttribute ( "maxLength" , e ) , a . removeAttribute ( I ) ) ;
65
+ // If the polyfill has changed the type of the element we need to change
66
+ // it back.
67
+ var f = a . getAttribute ( D ) ; return f && ( a . type = f ) , ! 0 } return ! 1 }
68
+ // Show the placeholder value on a single element. Returns true if the
69
+ // placeholder was shown and false if it was not (because it was already
70
+ // visible).
71
+ function l ( a ) { var b = a . getAttribute ( B ) ; if ( "" === a . value && b ) { a . setAttribute ( C , "true" ) , a . value = b , a . className += " " + z ;
72
+ // Store and remove the maxlength value.
73
+ var c = a . getAttribute ( I ) ; c || ( a . setAttribute ( I , a . maxLength ) , a . removeAttribute ( "maxLength" ) ) ;
74
+ // If the type of element needs to change, change it (e.g. password
75
+ // inputs).
76
+ var d = a . getAttribute ( D ) ; return d ?a . type = "text" :"password" === a . type && g ( a , "text" ) && a . setAttribute ( D , "password" ) , ! 0 } return ! 1 }
77
+ // Returns a function that is used as a focus event handler.
78
+ function m ( a ) { return function ( ) {
79
+ // Only hide the placeholder value if the (default) hide-on-focus
80
+ // behaviour is enabled.
81
+ P && a . value === a . getAttribute ( B ) && "true" === a . getAttribute ( C ) ?
82
+ // Move the caret to the start of the input (this mimics the behaviour
83
+ // of all browsers that do not hide the placeholder on focus).
84
+ f ( a , 0 ) :
85
+ // Remove the placeholder.
86
+ k ( a ) } }
87
+ // Returns a function that is used as a blur event handler.
88
+ function n ( a ) { return function ( ) { l ( a ) } }
89
+ // Returns a function that is used as a submit event handler on form elements
90
+ // that have children affected by this polyfill.
91
+ function o ( a ) { return function ( ) {
92
+ // Turn off placeholders on all appropriate descendant elements.
93
+ i ( a ) } }
94
+ // Functions that are used as a event handlers when the hide-on-input
95
+ // behaviour has been activated - very basic implementation of the 'input'
96
+ // event.
97
+ function p ( a ) { return function ( b ) {
98
+ // Prevent the use of the arrow keys (try to keep the cursor before the
99
+ // placeholder).
100
+ if ( v = a . value , "true" === a . getAttribute ( C ) && v === a . getAttribute ( B ) && d ( x , b . keyCode ) ) return b . preventDefault && b . preventDefault ( ) , ! 1 } } function q ( a ) { return function ( ) { k ( a , v ) ,
101
+ // If the element is now empty we need to show the placeholder
102
+ "" === a . value && ( a . blur ( ) , f ( a , 0 ) ) } } function r ( a ) { return function ( ) { a === c ( ) && a . value === a . getAttribute ( B ) && "true" === a . getAttribute ( C ) && f ( a , 0 ) } }
103
+ // Bind event handlers to an element that we need to affect with the
104
+ // polyfill.
105
+ function s ( a ) {
106
+ // If the element is part of a form, make sure the placeholder string is
107
+ // not submitted as a value.
108
+ var b = a . form ; b && ( "string" == typeof b && (
109
+ // Get the real form.
110
+ b = document . getElementById ( b ) ) ,
111
+ // Set a flag on the form so we know it's been handled (forms can contain
112
+ // multiple inputs).
113
+ b . getAttribute ( E ) || ( e ( b , "submit" , o ( b ) ) , b . setAttribute ( E , "true" ) ) ) ,
114
+ // Bind event handlers to the element so we can hide/show the placeholder
115
+ // as appropriate.
116
+ e ( a , "focus" , m ( a ) ) , e ( a , "blur" , n ( a ) ) ,
117
+ // If the placeholder should hide on input rather than on focus we need
118
+ // additional event handlers
119
+ P && ( e ( a , "keydown" , p ( a ) ) , e ( a , "keyup" , q ( a ) ) , e ( a , "click" , r ( a ) ) ) ,
120
+ // Remember that we've bound event handlers to this element.
121
+ a . setAttribute ( F , "true" ) , a . setAttribute ( B , T ) ,
122
+ // If the element doesn't have a value and is not focussed, set it to the
123
+ // placeholder string.
124
+ ( P || a !== c ( ) ) && l ( a ) }
125
+ //
126
+ // Test for support. We do this as early as possible to optimise for browsers
127
+ // that have native support for the attribute.
128
+ //
129
+ var t = document . createElement ( "input" ) , u = void 0 !== t . placeholder ; if ( a . Placeholders = { nativeSupport :u , disable :u ?b :i , enable :u ?b :j } , ! u ) {
130
+ //
131
+ // If we reach this point then the browser does not have native support for
132
+ // the attribute.
133
+ //
134
+ // The list of input element types that support the placeholder attribute.
135
+ var v , w = [ "text" , "search" , "url" , "tel" , "email" , "password" , "number" , "textarea" ] , x = [
136
+ // The following keys all cause the caret to jump to the end of the input
137
+ // value.
138
+ 27 , // Escape
139
+ 33 , // Page up
140
+ 34 , // Page down
141
+ 35 , // End
142
+ 36 , // Home
143
+ // Arrow keys allow you to move the caret manually, which should be
144
+ // prevented when the placeholder is visible.
145
+ 37 , // Left
146
+ 38 , // Up
147
+ 39 , // Right
148
+ 40 , // Down
149
+ // The following keys allow you to modify the placeholder text by removing
150
+ // characters, which should be prevented when the placeholder is visible.
151
+ 8 , // Backspace
152
+ 46 ] , y = "#ccc" , z = "placeholdersjs" , A = new RegExp ( "(?:^|\\s)" + z + "(?!\\S)" ) , B = "data-placeholder-value" , C = "data-placeholder-active" , D = "data-placeholder-type" , E = "data-placeholder-submit" , F = "data-placeholder-bound" , G = "data-placeholder-focus" , H = "data-placeholder-live" , I = "data-placeholder-maxlength" , J = 100 , K = document . getElementsByTagName ( "head" ) [ 0 ] , L = document . documentElement , M = a . Placeholders , N = document . getElementsByTagName ( "input" ) , O = document . getElementsByTagName ( "textarea" ) , P = "false" === L . getAttribute ( G ) , Q = "false" !== L . getAttribute ( H ) , R = document . createElement ( "style" ) ; R . type = "text/css" ;
153
+ // Create style rules as text node.
154
+ var S = document . createTextNode ( "." + z + " {color:" + y + ";}" ) ;
155
+ // Append style rules to newly created stylesheet.
156
+ R . styleSheet ?R . styleSheet . cssText = S . nodeValue :R . appendChild ( S ) ,
157
+ // Prepend new style element to the head (before any existing stylesheets,
158
+ // so user-defined rules take precedence).
159
+ K . insertBefore ( R , K . firstChild ) ; for ( var T , U , V = 0 , W = N . length + O . length ; V < W ; V ++ )
160
+ // Find the next element. If we've already done all the inputs we move on
161
+ // to the textareas.
162
+ U = V < N . length ?N [ V ] :O [ V - N . length ] ,
163
+ // Get the value of the placeholder attribute, if any. IE10 emulating IE7
164
+ // fails with getAttribute, hence the use of the attributes node.
165
+ T = U . attributes . placeholder ,
166
+ // If the element has a placeholder attribute we need to modify it.
167
+ T && (
168
+ // IE returns an empty object instead of undefined if the attribute is
169
+ // not present.
170
+ T = T . nodeValue ,
171
+ // Only apply the polyfill if this element is of a type that supports
172
+ // placeholders and has a placeholder attribute with a non-empty value.
173
+ T && d ( w , U . type ) && s ( U ) ) ;
174
+ // If enabled, the polyfill will repeatedly check for changed/added elements
175
+ // and apply to those as well.
176
+ var X = setInterval ( function ( ) { for ( var a = 0 , b = N . length + O . length ; a < b ; a ++ ) U = a < N . length ?N [ a ] :O [ a - N . length ] ,
177
+ // Only apply the polyfill if this element is of a type that supports
178
+ // placeholders, and has a placeholder attribute with a non-empty value.
179
+ T = U . attributes . placeholder , T ?( T = T . nodeValue , T && d ( w , U . type ) && (
180
+ // If the element hasn't had event handlers bound to it then add
181
+ // them.
182
+ U . getAttribute ( F ) || s ( U ) ,
183
+ // If the placeholder value has changed or not been initialised yet
184
+ // we need to update the display.
185
+ ( T !== U . getAttribute ( B ) || "password" === U . type && ! U . getAttribute ( D ) ) && (
186
+ // Attempt to change the type of password inputs (fails in IE < 9).
187
+ "password" === U . type && ! U . getAttribute ( D ) && g ( U , "text" ) && U . setAttribute ( D , "password" ) ,
188
+ // If the placeholder value has changed and the placeholder is
189
+ // currently on display we need to change it.
190
+ U . value === U . getAttribute ( B ) && ( U . value = T ) ,
191
+ // Keep a reference to the current placeholder value in case it
192
+ // changes via another script.
193
+ U . setAttribute ( B , T ) ) ) ) :U . getAttribute ( C ) && ( k ( U ) , U . removeAttribute ( B ) ) ;
194
+ // If live updates are not enabled cancel the timer.
195
+ Q || clearInterval ( X ) } , J ) ;
196
+ // Disabling placeholders before unloading the page prevents flash of
197
+ // unstyled placeholders on load if the page was refreshed.
198
+ e ( a , "beforeunload" , function ( ) { M . disable ( ) } ) } } ( this ) , function ( a , b ) { "use strict" ; var c = a . fn . val , d = a . fn . prop ; b . Placeholders . nativeSupport || ( a . fn . val = function ( a ) { var b = c . apply ( this , arguments ) , d = this . eq ( 0 ) . data ( "placeholder-value" ) ; return void 0 === a && this . eq ( 0 ) . data ( "placeholder-active" ) && b === d ?"" :b } , a . fn . prop = function ( a , b ) { return void 0 === b && this . eq ( 0 ) . data ( "placeholder-active" ) && "value" === a ?"" :d . apply ( this , arguments ) } ) } ( jQuery , this ) ;
0 commit comments