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

1 line
6.0 KiB
JavaScript

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