PageSourceSearch

https://txdzw.com/Content/_Common/Assets/Scripts/bootstrap-show-pa…MNh2aN8aMGwfM0F-9yp3uKyADo0XOT0UhG9Pi53SD1k

js txdzw.com collected 2026-10-04 05:19:07 UTC 4,736 bytes, 165 lines download raw bytes

1/**
2 * @author zhixin wen <[email protected]>
3 * https://github.com/wenzhixin/bootstrap-show-password
4 * version: 1.0.3
5 */
6
7!function ($) {
8
9    'use strict';
10
11    // TOOLS DEFINITION
12    // ======================
13
14    // it only does '%s', and return '' when arguments are undefined
15    var sprintf = function(str) {
16        var args = arguments,
17            flag = true,
18            i = 1;
19
20        str = str.replace(/%s/g, function () {
21            var arg = args[i++];
22
23            if (typeof arg === 'undefined') {
24                flag = false;
25                return '';
26            }
27            return arg;
28        });
29        if (flag) {
30            return str;
31        }
32        return '';
33    };
34
35    // PASSWORD CLASS DEFINITION
36    // ======================
37
38    var Password = function(element, options) {
39        this.options   = options;
40        this.$element  = $(element);
41        this.isShown = false;
42
43        this.init();
44    };
45
46    Password.DEFAULTS = {
47        placement: 'after', // 'before' or 'after'
48        white: false, // v2
49        message: 'Click here to show/hide password',
50        eyeClass: 'glyphicon',
51        eyeOpenClass: 'glyphicon-eye-open',
52        eyeCloseClass: 'glyphicon-eye-close'
53    };
54
55    Password.prototype.init = function() {
56        var placementFuc,
57            inputClass; // v2 class
58
59        if (this.options.placement === 'before') {
60            placementFuc = 'insertBefore';
61            inputClass = 'input-prepend';
62        } else {
63            this.options.placement = 'after'; // default to after
64            placementFuc = 'insertAfter';
65            inputClass = 'input-append';
66        }
67
68        // Create the text, icon and assign
69        this.$element.wrap(sprintf('<div class="%s input-group" />', inputClass));
70        this.$icon = $([
71            '<span tabindex="100" title="' + this.options.message + '" class="add-on input-group-addon">',
72            '<i class="icon-eye-open' + (this.options.white ? ' icon-white' : '') +
73                ' ' + this.options.eyeClass + ' ' + this.options.eyeOpenClass + '"></i>',
74            '</span>'
75        ].join(''))[placementFuc](this.$element).css('cursor', 'pointer');
76
77        this.$icon.off('click').on('click', $.proxy(function () {
78
79            this.$element.prop('type', this.isShown ? 'password' : 'text');
80            this.toggle();
81        }, this));
82    };
83
84    Password.prototype.toggle = function(_relatedTarget) {
85        this[!this.isShown ? 'show' : 'hide'](_relatedTarget);
86    };
87
88    Password.prototype.show = function(_relatedTarget) {
89        var e = $.Event('show.bs.password', {relatedTarget: _relatedTarget});
90        this.$element.trigger(e);
91
92        this.isShown = true;
93        this.$icon.find('i')
94            .removeClass('icon-eye-open ' + this.options.eyeOpenClass)
95            .addClass('icon-eye-close ' + this.options.eyeCloseClass);
96
97    };
98
99    Password.prototype.hide = function(_relatedTarget) {
100        var e = $.Event('hide.bs.password', {relatedTarget: _relatedTarget});
101        this.$element.trigger(e);
102
103        this.isShown = false;
104
105        this.$icon.find('i')
106            .removeClass('icon-eye-close ' + this.options.eyeCloseClass)
107            .addClass('icon-eye-open ' + this.options.eyeOpenClass);
108    };
109
110    Password.prototype.val = function (value) {
111        return this.$element.val();
112    };
113
114
115    // PASSWORD PLUGIN DEFINITION
116    // =======================
117
118    var old = $.fn.password;
119
120    $.fn.password = function() {
121        var option = arguments[0],
122            args = arguments,
123
124            value,
125            allowedMethods = ['show', 'hide', 'toggle', 'val']; // public function
126
127        this.each(function() {
128            var $this = $(this),
129                data = $this.data('bs.password'),
130                options = $.extend({}, Password.DEFAULTS, $this.data(), typeof option === 'object' && option);
131
132            if (typeof option === 'string') {
133                if ($.inArray(option, allowedMethods) < 0) {
134                    throw "Unknown method: " + option;
135                }
136                value = data[option](args[1]);
137            } else {
138                if (!data) {
139                    data = new Password($this, options);
140                    $this.data('bs.password', data);
141                } else {
142                    data.init(options);
143                }
144            }
145        });
146
147        return value ? value : this;
148    };
149
150    $.fn.password.Constructor = Password;
151
152
153    // PASSWORD NO CONFLICT
154    // =================
155
156    $.fn.password.noConflict = function() {
157        $.fn.password = old;
158        return this;
159    };
160
161    $(function () {
162        $('[data-toggle="password"]').password();
163    });
164
165}(window.jQuery);

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.