PageSourceSearch

https://repair4laptop.org/wp-content/themes/hestia/assets/js/material.js?ver=1.0.1

js repair4laptop.org collected 2026-09-26 05:10:22 UTC 13,037 bytes, 409 lines download raw bytes

1/**
2 *  Credits: https://github.com/FezVrasta/bootstrap-material-design
3 *
4 *  @package Hestia
5 */
6
7jQuery( document ).ready(
8	function($) {
9		// Selector to select only not already processed elements
10		$.expr[':'].notmdproc = function(obj) {
11			if ($( obj ).data( 'mdproc' )) {
12				return false;
13			} else {
14				return true;
15			}
16		};
17
18		function _isChar(evt) {
19			if (typeof evt.which === 'undefined') {
20				return true;
21			} else if (typeof evt.which === 'number' && evt.which > 0) {
22				return ( ! evt.ctrlKey &&
23				! evt.metaKey &&
24				! evt.altKey &&
25				evt.which !== 8 && // backspace
26				evt.which !== 9 && // tab
27				evt.which !== 13 && // enter
28				evt.which !== 16 && // shift
29				evt.which !== 17 && // ctrl
30				evt.which !== 20 && // caps lock
31				evt.which !== 27 // escape
32				);
33			}
34			return false;
35		}
36
37		function _addFormGroupFocus(element) {
38			var $element = $( element );
39			if ( ! $element.prop( 'disabled' )) { // this is showing as undefined on chrome but works fine on firefox??
40				$element.closest( '.form-group' ).addClass( 'is-focused' );
41			}
42		}
43
44		function _toggleDisabledState($element, state) {
45			var $target;
46			if ($element.hasClass( 'checkbox-inline' ) || $element.hasClass( 'radio-inline' )) {
47				$target = $element;
48			} else {
49				$target = $element.closest( '.checkbox' ).length ? $element.closest( '.checkbox' ) : $element.closest( '.radio' );
50			}
51			return $target.toggleClass( 'disabled', state );
52		}
53
54		function _toggleTypeFocus($input) {
55			var disabledToggleType = false;
56			if ($input.is( $.material.options.checkboxElements ) || $input.is( $.material.options.radioElements )) {
57				disabledToggleType = true;
58			}
59			$input.closest( 'label' ).hover(
60				function() {
61					var $i         = $( this ).find( 'input' );
62					var isDisabled = $i.prop( 'disabled' ); // hack because the _addFormGroupFocus() wasn't identifying the property on chrome
63					if (disabledToggleType) {
64						_toggleDisabledState( $( this ), isDisabled );
65					}
66					if ( ! isDisabled) {
67						_addFormGroupFocus( $i ); // need to find the input so we can check disablement
68					}
69				},
70				function() {
71					_removeFormGroupFocus( $( this ).find( 'input' ) );
72				}
73			);
74		}
75
76		function _removeFormGroupFocus(element) {
77			$( element ).closest( '.form-group' ).removeClass( 'is-focused' ); // remove class from form-group
78		}
79
80		$.material = {
81			'options': {
82				// These options set what will be started by $.material.init()
83				'validate': true,
84				'input': true,
85				'ripples': true,
86				'checkbox': true,
87				'togglebutton': true,
88				'radio': true,
89				'arrive': true,
90				'autofill': false,
91
92				'withRipples': [
93				'.btn:not(.btn-link)',
94				'.card-image',
95				'.navbar a:not(.withoutripple)',
96				'.dropdown-menu a',
97				'.nav-tabs a:not(.withoutripple)',
98				'.withripple',
99				'.pagination li:not(.active):not(.disabled) a:not(.withoutripple)'
100				].join( ',' ),
101				'inputElements': 'input.form-control, textarea.form-control, select.form-control',
102				'checkboxElements': '.checkbox > label > input[type=checkbox], label.checkbox-inline > input[type=checkbox]',
103				'togglebuttonElements': '.togglebutton > label > input[type=checkbox]',
104				'radioElements': '.radio > label > input[type=radio], label.radio-inline > input[type=radio]'
105			},
106			'checkbox': function(selector) {
107				// Add fake-checkbox to material checkboxes
108				var $input = $( (selector) ? selector : this.options.checkboxElements )
109				.filter( ':notmdproc' )
110				.data( 'mdproc', true )
111				.after( '<span class="checkbox-material"><span class="check"></span></span>' );
112
113				_toggleTypeFocus( $input );
114			},
115			'togglebutton': function(selector) {
116				// Add fake-checkbox to material checkboxes
117				var $input = $( (selector) ? selector : this.options.togglebuttonElements )
118				.filter( ':notmdproc' )
119				.data( 'mdproc', true )
120				.after( '<span class="toggle"></span>' );
121
122				_toggleTypeFocus( $input );
123			},
124			'radio': function(selector) {
125				// Add fake-radio to material radios
126				var $input = $( (selector) ? selector : this.options.radioElements )
127				.filter( ':notmdproc' )
128				.data( 'mdproc', true )
129				.after( '<span class="circle"></span><span class="check"></span>' );
130
131				_toggleTypeFocus( $input );
132			},
133			'input': function(selector) {
134				$( (selector) ? selector : this.options.inputElements )
135				.filter( ':notmdproc' )
136				.data( 'mdproc', true )
137				.each(
138					function() {
139						var $input = $( this );
140
141						// Requires form-group standard markup (will add it if necessary)
142							var $formGroup = $input.closest( '.form-group' ); // note that form-group may be grandparent in the case of an input-group
143						if ($formGroup.length === 0 && $input.attr( 'type' ) !== 'hidden' && ! $input.attr( 'hidden' ) && ! $input.parents( '.pirate_forms' ).length ) {
144							$input.wrap( '<div class="form-group"></div>' );
145							$formGroup = $input.closest( '.form-group' ); // find node after attached (otherwise additional attachments don't work)
146						}
147
148						// Pirate Forms compatibility
149						if ($formGroup.length === 0 && $input.attr( 'type' ) !== 'hidden' && ! $input.attr( 'hidden' ) && $input.parents( '.pirate_forms' ).length ) {
150							var $labelControl = $input.prev();
151							if( $input.attr('type') === 'checkbox' ) {
152								$labelControl = $input.next();
153							}
154							$input.add( $labelControl ).wrapAll( '<div class="form-group label-floating"></div>' );
155							$formGroup = $input.closest( '.form-group' );
156						}
157
158						// Legacy - Add hint label if using the old shorthand data-hint attribute on the input
159						if ($input.attr( 'data-hint' )) {
160							$input.after( '<p class="help-block">' + $input.attr( 'data-hint' ) + '</p>' );
161							$input.removeAttr( 'data-hint' );
162						}
163
164						// Legacy - Change input-sm/lg to form-group-sm/lg instead (preferred standard and simpler css/less variants)
165						var legacySizes = {
166							'input-lg': 'form-group-lg',
167							'input-sm': 'form-group-sm'
168						};
169						$.each(
170							legacySizes, function(legacySize, standardSize) {
171								if ($input.hasClass( legacySize )) {
172									$input.removeClass( legacySize );
173									$formGroup.addClass( standardSize );
174								}
175							}
176						);
177
178						// Legacy - Add label-floating if using old shorthand <input class="floating-label" placeholder="foo">
179						if ($input.hasClass( 'floating-label' )) {
180							var placeholder = $input.attr( 'placeholder' );
181							$input.attr( 'placeholder', null ).removeClass( 'floating-label' );
182							var id           = $input.attr( 'id' );
183							var forAttribute = '';
184							if (id) {
185								forAttribute = 'for="' + id + '"';
186							}
187							$formGroup.addClass( 'label-floating' );
188							$input.after( '<label ' + forAttribute + 'class="control-label">' + placeholder + '</label>' );
189						}
190
191						// Set as empty if is empty (damn I must improve this...)
192						if ($input.val() === null || $input.val() === 'undefined' || $input.val() === '') {
193							$formGroup.addClass( 'is-empty' );
194						}
195
196						// Support for file input
197						if ($formGroup.find( 'input[type=file]' ).length > 0) {
198							$formGroup.addClass( 'is-fileinput' );
199						}
200					}
201				);
202			},
203			'attachInputEventHandlers': function() {
204				var validate = this.options.validate;
205
206				$( document )
207				.on(
208					'keydown paste', '.form-control', function(e) {
209						if (_isChar( e )) {
210							$( this ).closest( '.form-group' ).removeClass( 'is-empty' );
211						}
212					}
213				)
214				.on(
215					'keyup change', '.form-control', function() {
216						var $input     = $( this );
217						var $formGroup = $input.closest( '.form-group' );
218						var isValid    = (typeof $input[0].checkValidity === 'undefined' || $input[0].checkValidity());
219
220						if ($input.val() === '') {
221							$formGroup.addClass( 'is-empty' );
222						} else {
223							$formGroup.removeClass( 'is-empty' );
224						}
225
226						// Validation events do not bubble, so they must be attached directly to the input: http://jsfiddle.net/PEpRM/1/
227						// Further, even the bind method is being caught, but since we are already calling #checkValidity here, just alter
228						// the form-group on change.
229						//
230						// NOTE: I'm not sure we should be intervening regarding validation, this seems better as a README and snippet of code.
231						// BUT, I've left it here for backwards compatibility.
232						if (validate) {
233							if (isValid) {
234								$formGroup.removeClass( 'has-error' );
235							} else {
236								$formGroup.addClass( 'has-error' );
237							}
238						}
239					}
240				)
241				.on(
242					'focus', '.form-control, .form-group.is-fileinput', function() {
243						_addFormGroupFocus( this );
244					}
245				)
246				.on(
247					'blur', '.form-control, .form-group.is-fileinput', function() {
248						_removeFormGroupFocus( this );
249					}
250				)
251				// make sure empty is added back when there is a programmatic value change.
252				// NOTE: programmatic changing of value using $.val() must trigger the change event i.e. $.val('x').trigger('change')
253				.on(
254					'change', '.form-group input', function() {
255						var $input = $( this );
256						if ($input.attr( 'type' ) === 'file') {
257							return;
258						}
259
260						var $formGroup = $input.closest( '.form-group' );
261						var value      = $input.val();
262						if (value) {
263							$formGroup.removeClass( 'is-empty' );
264						} else {
265							$formGroup.addClass( 'is-empty' );
266						}
267					}
268				)
269				// set the fileinput readonly field with the name of the file
270				.on(
271					'change', '.form-group.is-fileinput input[type="file"]', function() {
272						var $input     = $( this );
273						var $formGroup = $input.closest( '.form-group' );
274						var value      = '';
275						$.each(
276							this.files, function(i, file) {
277								value += file.name + ', ';
278							}
279						);
280						value = value.substring( 0, value.length - 2 );
281						if (value) {
282							$formGroup.removeClass( 'is-empty' );
283						} else {
284							$formGroup.addClass( 'is-empty' );
285						}
286						$formGroup.find( 'input.form-control[readonly]' ).val( value );
287					}
288				);
289			},
290			'ripples': function(selector) {
291				$( (selector) ? selector : this.options.withRipples ).ripples();
292			},
293			'autofill': function() {
294				// This part of code will detect autofill when the page is loading (username and password inputs for example)
295				var loading = setInterval(
296					function() {
297						$( 'input[type!=checkbox]' ).each(
298							function() {
299								var $this = $( this );
300								if ($this.val() && $this.val() !== $this.attr( 'value' )) {
301									$this.trigger( 'change' );
302								}
303							}
304						);
305					}, 100
306				);
307
308				// After 10 seconds we are quite sure all the needed inputs are autofilled then we can stop checking them
309				setTimeout(
310					function() {
311						clearInterval( loading );
312					}, 10000
313				);
314			},
315			'attachAutofillEventHandlers': function() {
316				// Listen on inputs of the focused form (because user can select from the autofill dropdown only when the input has focus)
317				var focused;
318				$( document )
319				.on(
320					'focus', 'input', function() {
321						var $inputs = $( this ).parents( 'form' ).find( 'input' ).not( '[type=file]' );
322						focused     = setInterval(
323							function() {
324								$inputs.each(
325									function() {
326										var $this = $( this );
327										if ($this.val() !== $this.attr( 'value' )) {
328											$this.trigger( 'change' );
329										}
330									}
331								);
332							}, 100
333						);
334					}
335				)
336				.on(
337					'blur', '.form-group input', function() {
338						clearInterval( focused );
339					}
340				);
341			},
342			'init': function(options) {
343				this.options  = $.extend( {}, this.options, options );
344				var $document = $( document );
345
346				if ($.fn.ripples && this.options.ripples) {
347					this.ripples();
348				}
349				if (this.options.input) {
350					this.input();
351					this.attachInputEventHandlers();
352				}
353				if (this.options.checkbox) {
354					this.checkbox();
355				}
356				if (this.options.togglebutton) {
357					this.togglebutton();
358				}
359				if (this.options.radio) {
360					this.radio();
361				}
362				if (this.options.autofill) {
363					this.autofill();
364					this.attachAutofillEventHandlers();
365				}
366
367				if (document.arrive && this.options.arrive) {
368					if ($.fn.ripples && this.options.ripples) {
369						$document.arrive(
370							this.options.withRipples, function() {
371								$.material.ripples( $( this ) );
372							}
373						);
374					}
375					if (this.options.input) {
376						$document.arrive(
377							this.options.inputElements, function() {
378								$.material.input( $( this ) );
379							}
380						);
381					}
382					if (this.options.checkbox) {
383						$document.arrive(
384							this.options.checkboxElements, function() {
385								$.material.checkbox( $( this ) );
386							}
387						);
388					}
389					if (this.options.radio) {
390						$document.arrive(
391							this.options.radioElements, function() {
392								$.material.radio( $( this ) );
393							}
394						);
395					}
396					if (this.options.togglebutton) {
397						$document.arrive(
398							this.options.togglebuttonElements, function() {
399								$.material.togglebutton( $( this ) );
400							}
401						);
402					}
403
404				}
405			}
406		};
407
408	}
409);

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.