Projekt

Allgemein

Profil

GX-Bug #66671 » placeholder.js

src/gambio_installer/javascript/placeholder.js - Moritz Bunjes, 27.04.2020 17:12

 
1
/* --------------------------------------------------------------
2
  initiate_jquery_placeholder.js 2020-04-27
3
  Gambio GmbH
4
  http://www.gambio.de
5
  Copyright (c) 2020 Gambio GmbH
6
  Released under the GNU General Public License (Version 2)
7
  [http://www.gnu.org/licenses/gpl-2.0.html]
8
  --------------------------------------------------------------*/
9

    
10
$(document).ready(function() {
11
	
12
	$('input[type="text"], input[type="password"]').each(function() {
13
		
14
		const POSITION_ADJUSTMENTS = {
15
			'FTP_HOST': 11, 'FTP_PASSWORD': 11, 'FTP_PORT': 11, 'FTP_USER' : 11
16
		};
17
		
18
		let $this = $(this),
19
			name = $this.attr('name'),
20
			placeholder = $this.attr('placeholder');
21
		
22
		if (placeholder !== undefined) {
23
			
24
			if ($this.attr('id') === undefined) {
25
				
26
				$this.attr('id', name);
27
			}
28
			
29
			$this.after('<label for="' + $this.attr('id') + '" class="placeholder">' + placeholder + '</label>');
30
			
31
			let $label = $('label[for="' + $this.attr('id') + '"]');
32
			
33
			if ($this.val() === '') {
34
				
35
				$label.addClass('hidden');
36
			}
37
			
38
			if (POSITION_ADJUSTMENTS[$this.attr('id')] !== undefined) {
39
				
40
				$label.css('top', ($this.position().top + POSITION_ADJUSTMENTS[$this.attr('id')] ) + 'px');
41
			}
42
			
43
			$this.on('keyup', function() {
44
				
45
				if (POSITION_ADJUSTMENTS[$this.attr('id')] !== undefined) {
46
					
47
					$label.css('top', ($this.position().top + POSITION_ADJUSTMENTS[$this.attr('id')] ) + 'px');
48
				}
49
				
50
				if ($this.val() === '') {
51
					
52
					$label.addClass('hidden');
53
				} else {
54
					
55
					$label.removeClass('hidden');
56
				}
57
			});
58
		}
59
	});
60
});
(2-2/2)