Files
grzanieplus.pl/web/jQueryTools/prevue/js/jquery.prevue.min.js
2025-03-12 17:06:23 +01:00

14 lines
2.0 KiB
JavaScript

/*
* Prevue.js jQuery Password Previewer v1.0.2
* http://jaunesarmiento.me/prevuejs
*
* Copyright 2013, Jaune Sarmiento
* Released under the MIT license
* http://www.opensource.org/licenses/mit-license.php
*
* Date: Wed Jan 29, 2014
*/
(function($){window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){console.log(Array.prototype.slice.call(arguments))}};$.fn.prevue=function(settings){var defaults={fontIconClassNameOff:'prevue-icon-eye',fontIconClassNameOn:'prevue-icon-eye-off',fontSize:'16',color:'#999',offsetX:5,offsetY:0};if(settings){$.extend(defaults,settings)}
return this.each(function(){var $o=$(this);var node=this.nodeName.toLowerCase();if(node=="input"&&this.type=="password"){var $input=$o,$previewIcon=$('<i>').css({'font-size':defaults.fontSize+'px'}).addClass('prevue-icon').addClass(defaults.fontIconClassNameOff),paddingTop=$o.css('padding-top'),paddingBottom=$o.css('padding-bottom'),height=parseInt($o.height())+parseInt(paddingTop.substring(0,paddingTop.length-2))+parseInt(paddingBottom.substring(0,paddingBottom.length-2)),$previewBtn=$('<a>').attr('href','javascript: void(0);').addClass('prevue-btn').css({'text-decoration':'none','position':'absolute','right':parseInt(0+defaults.offsetX)+'px','height':parseInt(height+defaults.offsetY)+'px','line-height':(height+defaults.offsetY)+'px','color':defaults.color}),$wrapper=$('<span>').addClass('prevue-wrapper').css({'position':'relative'});$previewBtn.append($previewIcon);$o.replaceWith($wrapper);$wrapper.append($input);$wrapper.append($previewBtn);$previewBtn.on('click',function(e){var $el=$(this).prev(),$icon=$(this).children().eq(0);if($el.attr('type')=='password'){$el.attr('type','text');$icon.removeClass(defaults.fontIconClassNameOff).addClass(defaults.fontIconClassNameOn);}
else{$el.attr('type','password');$icon.removeClass(defaults.fontIconClassNameOn).addClass(defaults.fontIconClassNameOff);}});}else{console.log('Prevue.js only works on <input type="password"> elements, while you have used it on a <'+node+'> element.');return false;}});};})(jQuery);