This repository was archived by the owner on Oct 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbrowserid.min.js
1 lines (1 loc) · 4.77 KB
/
browserid.min.js
1
/*jshint browser: true*//*global browserid_common, jQuery*/(function(){"use strict";function a(e){return e||"login"}function f(e){t=e;var n={siteName:browserid_common.siteName||"",siteLogo:browserid_common.siteLogo||"",backgroundColor:browserid_common.backgroundColor||"",termsOfService:browserid_common.termsOfService||"",privacyPolicy:browserid_common.privacyPolicy||""};t==="comment"?n.returnTo=w("#submit_comment"):t==="register"&&(n.returnTo=w("#submit_registration")),navigator.id.request(n)}function l(t){var n=document.getElementById("rememberme");n!==null&&(n=n.checked);var r=document.createElement("form");r.setAttribute("style","display: none;"),r.method="POST",r.action=browserid_common.urlLoginSubmit;var i={browserid_assertion:t,rememberme:n};browserid_common.urlLoginRedirect!==null&&(i.redirect_to=browserid_common.urlLoginRedirect),E(r,i),e("body").append(r),r.submit()}function c(){r=!0,p(),f("comment")}function h(t){var i=d();if(!i&&!n)return v();var o=e("#commentform"),u=e("#comment_post_ID").val();E(o,{browserid_comment:u,browserid_assertion:t}),localStorage.removeItem("comment_hash"),sessionStorage.setItem("submitting_comment","true"),browserid_common.loggedInUser||(r=!0,navigator.id.logout()),s=!0,e("#submit").click()}function p(){var t={author:e("#author").val(),url:e("#url").val(),comment:e("#comment").val(),comment_parent:e("#comment_parent").val()};localStorage.setItem("comment_state",JSON.stringify(t))}function d(){var t=localStorage.getItem("comment_state");return t&&(t=JSON.parse(t),e("#author").val(t.author),e("#url").val(t.url),e("#comment").val(t.comment),e("#comment_parent").val(t.comment_parent),localStorage.removeItem("comment_state")),t}function v(){var e=localStorage.getItem("comment_hash");e?(localStorage.removeItem("comment_hash"),document.location.hash=e,document.location.reload(!0)):setTimeout(v,100)}function m(t){var r=y();if(!r&&!n)return b();sessionStorage.setItem("submitting_registration","true"),e("#browserid_assertion").val(t),i=!0,e("#wp-submit").click()}function g(){var t={user_login:e("#user_login").val()};localStorage.setItem("registration_state",JSON.stringify(t))}function y(){var t=localStorage.getItem("registration_state");return t&&(t=JSON.parse(t),e("#user_login").val(t.user_login),localStorage.removeItem("registration_state")),t}function b(){var e=localStorage.getItem("registration_complete");e?(localStorage.removeItem("registration_complete"),document.location=browserid_common.urlRegistrationRedirect):setTimeout(b,100)}function w(e){return document.location.href.replace(/http(s)?:\/\//,"").replace(document.location.host,"").replace(/#.*$/,"")+e}function E(t,n){t=e(t);for(var r in n){var i=document.createElement("input");i.type="hidden",i.name=r,i.value=n[r],t.append(i)}}function S(){var t=e("<div class='persona__submit'><div class='persona__submit_spinner'></div></div>");e("body").append(t)}function x(t,n){function r(){var r=e(t).val();r&&r.trim().length?e(n).removeClass("disabled"):e(n).addClass("disabled")}e(n).addClass("disabled"),e(t).keyup(r),e(t).change(r)}function T(t,n,r){e("body")[typeof e.fn.on=="function"?"on":"delegate"](n,t,r)}var e=jQuery,t,n,r=!1,i=!1,s=browserid_common.loggedInUser||!1,o;e(".js-persona__login").click(function(e){e.preventDefault(),r=!1,f("login")}),T(".js-persona__logout","click",function(e){r=!1,navigator.id.logout()}),browserid_common.isPersonaUsedWithComments&&(e("body").addClass("persona--comments"),e(".js-persona__submit-comment").click(function(t){t.preventDefault(),e("#commentform").submit()}),e("#commentform").submit(function(t){if(e("#comment").hasClass("disabled")){t.preventDefault();return}s||(t.preventDefault(),c())})),browserid_common.isPersonaOnlyAuth&&(e("body").addClass("persona--persona-only-auth"),x("#user_login",".js-persona__register"),e(".js-persona__register").click(function(t){t.preventDefault();if(e(t.target).hasClass("disabled"))return;r=!1,g(),f("register")}),e("#registerform").submit(function(t){if(i)return;t.preventDefault();if(e("#user_login").val().length===0)return;r=!1,g(),f("register")}));if(document.location.hash==="#submit_comment"){r=!0,S(),o=d();if(!o)return v();t="comment",n=!0}else if(document.location.hash==="#submit_registration"){r=!0,S(),o=y();if(!o)return b();t="register",n=!0}else document.location.href===browserid_common.urlRegistrationRedirect&&sessionStorage.getItem("submitting_registration")?localStorage.setItem("registration_complete","true"):sessionStorage.getItem("submitting_comment")&&(r=!0,sessionStorage.removeItem("submitting_comment"),localStorage.setItem("comment_hash",document.location.hash));if(browserid_common.msgError||e("#login_error").length)r=!0,navigator.id.logout();var u={login:l,register:m,comment:h};navigator.id.watch({loggedInUser:browserid_common.loggedInUser||null,onlogin:function(e){t=a(t);var n=u[t];n&&n(e)},onlogout:function(){if(r)return}})})();