Component-Builder-fork/admin/custom/uikit-v2/js/components/form-password.js

68 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-04-22 13:31:39 +00:00
/*! UIkit 2.27.5 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
2016-01-30 20:28:43 +00:00
(function(addon) {
var component;
2017-11-12 00:33:10 +00:00
if (window.UIkit2) {
component = addon(UIkit2);
2016-01-30 20:28:43 +00:00
}
2017-11-12 00:33:10 +00:00
if (typeof define == 'function' && define.amd) {
define('uikit-form-password', ['uikit'], function(){
return component || addon(UIkit2);
2016-01-30 20:28:43 +00:00
});
}
})(function(UI){
"use strict";
UI.component('formPassword', {
defaults: {
2017-11-12 00:33:10 +00:00
lblShow: 'Show',
lblHide: 'Hide'
2016-01-30 20:28:43 +00:00
},
boot: function() {
// init code
2017-11-12 00:33:10 +00:00
UI.$html.on('click.formpassword.uikit', '[data-uk-form-password]', function(e) {
2016-01-30 20:28:43 +00:00
var ele = UI.$(this);
2017-11-12 00:33:10 +00:00
if (!ele.data('formPassword')) {
2016-01-30 20:28:43 +00:00
e.preventDefault();
2017-11-12 00:33:10 +00:00
UI.formPassword(ele, UI.Utils.options(ele.attr('data-uk-form-password')));
ele.trigger('click');
2016-01-30 20:28:43 +00:00
}
});
},
init: function() {
var $this = this;
2017-11-12 00:33:10 +00:00
this.on('click', function(e) {
2016-01-30 20:28:43 +00:00
e.preventDefault();
if($this.input.length) {
2017-11-12 00:33:10 +00:00
var type = $this.input.attr('type');
$this.input.attr('type', type=='text' ? 'password':'text');
$this.element.html($this.options[type=='text' ? 'lblShow':'lblHide']);
2016-01-30 20:28:43 +00:00
}
});
2017-11-12 00:33:10 +00:00
this.input = this.element.next('input').length ? this.element.next('input') : this.element.prev('input');
this.element.html(this.options[this.input.is('[type="password"]') ? 'lblShow':'lblHide']);
2016-03-19 01:51:35 +00:00
2016-01-30 20:28:43 +00:00
2017-11-12 00:33:10 +00:00
this.element.data('formPassword', this);
2016-01-30 20:28:43 +00:00
}
});
return UI.formPassword;
});