WordPress/wp-admin/js/user-profile.min.js

1 line
5.5 KiB
JavaScript

!function(a){function b(){return"function"!=typeof zxcvbn?void setTimeout(b,50):(j.val()?(g(),h()):(j.val(j.data("pw")),j.trigger("pwupdate"),h()),1!==parseInt(n.data("start-masked"),10)?j.attr("type","text"):n.trigger("click"),void a("#pw-weak-text-label").html(userProfileL10n.warnWeak))}function c(){q=j.val(),1===parseInt(j.data("reveal"),10)&&b(),j.on("input pwupdate",function(){j.val()!==q&&(q=j.val(),j.removeClass("short bad good strong"),h())})}function d(a){n.attr({"aria-label":a?userProfileL10n.ariaShow:userProfileL10n.ariaHide}).find(".text").text(a?userProfileL10n.show:userProfileL10n.hide).end().find(".dashicons").removeClass(a?"dashicons-hidden":"dashicons-visibility").addClass(a?"dashicons-visibility":"dashicons-hidden")}function e(){n=i.find(".wp-hide-pw"),n.show().on("click",function(){"password"===j.attr("type")?(j.attr("type","text"),d(!1)):(j.attr("type","password"),d(!0)),j.focus(),_.isUndefined(j[0].setSelectionRange)||j[0].setSelectionRange(0,100)})}function f(){var f,g,h;i=a(".user-pass1-wrap, .user-pass-wrap"),a(".user-pass2-wrap").hide(),p=a("#submit, #wp-submit").on("click",function(){r=!1}),o=p.add(" #createusersub"),l=a(".pw-weak"),m=l.find(".pw-checkbox"),m.change(function(){o.prop("disabled",!m.prop("checked"))}),j=a("#pass1"),j.length?c():j=a("#user_pass"),k=a("#pass2").on("input",function(){k.val().length>0&&(j.val(k.val()),k.val(""),q="",j.trigger("pwupdate"))}),j.is(":hidden")&&(j.prop("disabled",!0),k.prop("disabled",!0)),f=i.find(".wp-pwd"),g=i.find("button.wp-generate-pw"),e(),g.length&&f.hide(),g.show(),g.on("click",function(){r=!0,g.hide(),f.show(),j.attr("disabled",!1),k.attr("disabled",!1),0===j.val().length&&b()}),h=i.find("button.wp-cancel-pw"),h.on("click",function(){r=!1,j.val(""),wp.ajax.post("generate-password").done(function(a){j.data("pw",a)}),g.show().focus(),f.hide(),l.hide(0,function(){m.removeProp("checked")}),j.prop("disabled",!0),k.prop("disabled",!0),d(!1),i.closest("form").is("#your-profile")&&(j.val("").trigger("pwupdate"),o.prop("disabled",!1))}),i.closest("form").on("submit",function(){r=!1,j.prop("disabled",!1),k.prop("disabled",!1),k.val(j.val())})}function g(){var b,c=a("#pass1").val();if(a("#pass-strength-result").removeClass("short bad good strong empty"),!c)return void a("#pass-strength-result").addClass("empty").html("&nbsp;");switch(b=wp.passwordStrength.meter(c,wp.passwordStrength.userInputBlacklist(),c)){case-1:a("#pass-strength-result").addClass("bad").html(pwsL10n.unknown);break;case 2:a("#pass-strength-result").addClass("bad").html(pwsL10n.bad);break;case 3:a("#pass-strength-result").addClass("good").html(pwsL10n.good);break;case 4:a("#pass-strength-result").addClass("strong").html(pwsL10n.strong);break;case 5:a("#pass-strength-result").addClass("short").html(pwsL10n.mismatch);break;default:a("#pass-strength-result").addClass("short").html(pwsL10n["short"])}}function h(){var b=a("#pass-strength-result")[0];b.className&&(j.addClass(b.className),a(b).is(".short, .bad")?(m.prop("checked")||o.prop("disabled",!0),l.show()):(a(b).is(".empty")?(o.prop("disabled",!0),m.prop("checked",!1)):o.prop("disabled",!1),l.hide()))}var i,j,k,l,m,n,o,p,q,r=!1;a(document).ready(function(){var b,c,d,e,h=a("#display_name"),i=h.val(),j=a("#wp-admin-bar-my-account").find(".display-name");a("#pass1").val("").on("input pwupdate",g),a("#pass-strength-result").show(),a(".color-palette").click(function(){a(this).siblings('input[name="admin_color"]').prop("checked",!0)}),h.length&&(a("#first_name, #last_name, #nickname").bind("blur.user_profile",function(){var b=[],c={display_nickname:a("#nickname").val()||"",display_username:a("#user_login").val()||"",display_firstname:a("#first_name").val()||"",display_lastname:a("#last_name").val()||""};c.display_firstname&&c.display_lastname&&(c.display_firstlast=c.display_firstname+" "+c.display_lastname,c.display_lastfirst=c.display_lastname+" "+c.display_firstname),a.each(a("option",h),function(a,c){b.push(c.value)}),a.each(c,function(d,e){if(e){var f=e.replace(/<\/?[a-z][^>]*>/gi,"");c[d].length&&a.inArray(f,b)===-1&&(b.push(f),a("<option />",{text:f}).appendTo(h))}})}),h.on("change",function(){if(d===e){var b=a.trim(this.value)||i;j.text(b)}})),b=a("#color-picker"),c=a("#colors-css"),d=a("input#user_id").val(),e=a('input[name="checkuser_id"]').val(),b.on("click.colorpicker",".color-option",function(){var b,f=a(this);if(!f.hasClass("selected")&&(f.siblings(".selected").removeClass("selected"),f.addClass("selected").find('input[type="radio"]').prop("checked",!0),d===e)){if(0===c.length&&(c=a('<link rel="stylesheet" />').appendTo("head")),c.attr("href",f.children(".css_url").val()),"undefined"!=typeof wp&&wp.svgPainter){try{b=a.parseJSON(f.children(".icon_colors").val())}catch(g){}b&&(wp.svgPainter.setColors(b),wp.svgPainter.paint())}a.post(ajaxurl,{action:"save-user-color-scheme",color_scheme:f.children('input[name="admin_color"]').val(),nonce:a("#color-nonce").val()}).done(function(b){b.success&&a("body").removeClass(b.data.previousScheme).addClass(b.data.currentScheme)})}}),f()}),a("#destroy-sessions").on("click",function(b){var c=a(this);wp.ajax.post("destroy-sessions",{nonce:a("#_wpnonce").val(),user_id:a("#user_id").val()}).done(function(a){c.prop("disabled",!0),c.siblings(".notice").remove(),c.before('<div class="notice notice-success inline"><p>'+a.message+"</p></div>")}).fail(function(a){c.siblings(".notice").remove(),c.before('<div class="notice notice-error inline"><p>'+a.message+"</p></div>")}),b.preventDefault()}),window.generatePassword=b,a(window).on("beforeunload",function(){if(!0===r)return userProfileL10n.warn})}(jQuery);