Project

General

Profile

1
/*! UIkit 2.27.5 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
2
(function(addon) {
3

    
4
    var component;
5

    
6
    if (window.UIkit2) {
7
        component = addon(UIkit2);
8
    }
9

    
10
    if (typeof define == 'function' && define.amd) {
11
        define('uikit-form-password', ['uikit'], function(){
12
            return component || addon(UIkit2);
13
        });
14
    }
15

    
16
})(function(UI){
17

    
18
    "use strict";
19

    
20
    UI.component('formPassword', {
21

    
22
        defaults: {
23
            lblShow: 'Show',
24
            lblHide: 'Hide'
25
        },
26

    
27
        boot: function() {
28
            // init code
29
            UI.$html.on('click.formpassword.uikit', '[data-uk-form-password]', function(e) {
30

    
31
                var ele = UI.$(this);
32

    
33
                if (!ele.data('formPassword')) {
34

    
35
                    e.preventDefault();
36

    
37
                    UI.formPassword(ele, UI.Utils.options(ele.attr('data-uk-form-password')));
38
                    ele.trigger('click');
39
                }
40
            });
41
        },
42

    
43
        init: function() {
44

    
45
            var $this = this;
46

    
47
            this.on('click', function(e) {
48

    
49
                e.preventDefault();
50

    
51
                if($this.input.length) {
52
                    var type = $this.input.attr('type');
53
                    $this.input.attr('type', type=='text' ? 'password':'text');
54
                    $this.element.html($this.options[type=='text' ? 'lblShow':'lblHide']);
55
                }
56
            });
57

    
58
            this.input = this.element.next('input').length ? this.element.next('input') : this.element.prev('input');
59
            this.element.html(this.options[this.input.is('[type="password"]') ? 'lblShow':'lblHide']);
60

    
61

    
62
            this.element.data('formPassword', this);
63
        }
64
    });
65

    
66
    return UI.formPassword;
67
});
(7-7/46)