diff --git a/browserid/compress.sh b/browserid/compress.sh index 72bb1271d7993b5f03eb0bdb641018da9f68ae19..3ff73d706e6158b2788f647b2dddf47ed9be3482 100755 --- a/browserid/compress.sh +++ b/browserid/compress.sh @@ -44,7 +44,7 @@ echo '' cd ../js # re-minimize everything together -cat jquery-1.6.2.min.js json2.js ../dialog/resources/underscore-min.js ../dialog/resources/storage.js ../dialog/resources/browserid-network.js ../dialog/resources/browserid-identities.js browserid.js pages/index.js pages/add_email_address.js pages/verify_email_address.js pages/manage_account.js > lib.js +cat jquery-1.6.2.min.js json2.js ../dialog/resources/underscore-min.js ../dialog/resources/storage.js ../dialog/resources/browserid-network.js ../dialog/resources/browserid-identities.js browserid.js pages/index.js pages/add_email_address.js pages/verify_email_address.js pages/manage_account.js pages/signin.js pages/signup.js > lib.js $UGLIFY < lib.js > lib.min.js cd ../css diff --git a/browserid/static/js/browserid.js b/browserid/static/js/browserid.js index d0921a36da10b2817da0b35c57665a0db8a5cd54..f6759e8d5286cc17a40a563499ba1057e37e8fae 100644 --- a/browserid/static/js/browserid.js +++ b/browserid/static/js/browserid.js @@ -58,9 +58,15 @@ $(function() { path = document.location.pathname, bid = BrowserID; - if (path === "/") { + if (!path || path === "/") { bid.index(); } + else if (path === "/signin") { + bid.signIn(); + } + else if (path === "/signup") { + bid.signUp(); + } else if (token && path === "/add_email_address") { bid.addEmailAddress(token); } diff --git a/browserid/static/js/pages/signin.js b/browserid/static/js/pages/signin.js new file mode 100644 index 0000000000000000000000000000000000000000..989c0da4ed029c67b15396a3e2095c106ef7499b --- /dev/null +++ b/browserid/static/js/pages/signin.js @@ -0,0 +1,64 @@ +/*globals BrowserID:true, BrowserIDNetwork: true, $:true*/ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla BrowserID. + * + * The Initial Developer of the Original Code is Mozilla. + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +(function() { + "use strict"; + + BrowserID.signIn = function () { + $("form input[autofocus]").focus(); + + $("#signUpForm").bind("submit", function(event) { + event.preventDefault(); + + var email = $("#email").val(), + password = $("#password").val(); + + BrowserIDNetwork.authenticate(email, password, function onSuccess(authenticated) { + if (authenticated) { + document.location = "/"; + } + else { + // bad authentication + $(".notifications .notification.doh").fadeIn(); + } + }, function onFailure() { + // Wah wah. Network error + }); + }); + }; +}()); + + diff --git a/browserid/static/js/pages/signup.js b/browserid/static/js/pages/signup.js new file mode 100644 index 0000000000000000000000000000000000000000..d4f8f9d3417740ace03ca1488a01f2ae4c40cf59 --- /dev/null +++ b/browserid/static/js/pages/signup.js @@ -0,0 +1,89 @@ +/*globals BrowserID:true, BrowserIDIdentities: true, $:true*/ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla BrowserID. + * + * The Initial Developer of the Original Code is Mozilla. + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +(function() { + "use strict"; + + BrowserID.signUp = function () { + var ANIMATION_SPEED = 250; + + function replaceWithMessage(selector) { + $('.forminputs').fadeOut(ANIMATION_SPEED, function() { + $(selector).fadeIn(ANIMATION_SPEED); + }); + } + + function showNotice(selector) { + $(selector).fadeIn(ANIMATION_SPEED); + } + + function onFailure() { + replaceWithMessage(".doh"); + } + + + $(function () { + var identities = BrowserIDIdentities; + + $("form input[autofocus]").focus(); + + $("#email").bind("keyup", function(event) { + if (event.which !== 13) { + $(".notification").fadeOut(ANIMATION_SPEED); + } + }); + + $("#signUpForm").bind("submit", function(event) { + event.preventDefault(); + + var email = $("#email").val(); + identities.emailRegistered(email, function(registered) { + if (!registered) { + identities.createUser(email, function onSuccess(keypair) { + $('#sentToEmail').html(email); + replaceWithMessage(".emailsent"); + }, onFailure); + } + else { + $('#registeredEmail').html(email); + showNotice(".alreadyRegistered"); + } + }, onFailure); + }); + + }); + }; +}()); diff --git a/browserid/views/index.ejs b/browserid/views/index.ejs index 09fb81328a80a3f6b96e831ef1950dc793e4c81f..e0495e85cc0f1755d8e0874dffec670a31a02a5c 100644 --- a/browserid/views/index.ejs +++ b/browserid/views/index.ejs @@ -38,20 +38,3 @@ </li> </script> -<script type="text/javascript"> - $(function () { - $('.granted').hover(function() { - $('#card').toggleClass('insert'); - $('#status').delay(400).toggleClass('green'); - }); - - $('.create').hover(function() { - $('#hint').addClass('signUp').removeClass('info'); - }); - - $('.info').hover(function() { - $('#hint').removeClass('signUp').addClass('info'); - }); - }); -</script> - diff --git a/browserid/views/layout.ejs b/browserid/views/layout.ejs index 2760c5567c22ec994dcc177b820571d816afc4d8..1ec6942c3cfe31cc9647e78d647c37c77d78d329 100644 --- a/browserid/views/layout.ejs +++ b/browserid/views/layout.ejs @@ -22,6 +22,8 @@ <script src="/js/pages/add_email_address.js" type="text/javascript"></script> <script src="/js/pages/verify_email_address.js" type="text/javascript"></script> <script src="/js/pages/manage_account.js" type="text/javascript"></script> + <script src="/js/pages/signin.js" type="text/javascript"></script> + <script src="/js/pages/signup.js" type="text/javascript"></script> <script src="/dialog/resources/storage.js" type="text/javascript"></script> <script src="/dialog/resources/browserid-network.js" type="text/javascript"></script> <script src="/dialog/resources/browserid-identities.js" type="text/javascript"></script> diff --git a/browserid/views/signin.ejs b/browserid/views/signin.ejs index 2edf5cd2182307e180d53c49b7b1d49b966be83f..10f279a20d053739045245e3267a73def64e40ef 100644 --- a/browserid/views/signin.ejs +++ b/browserid/views/signin.ejs @@ -37,28 +37,3 @@ </div> </div> -<script type="text/javascript"> - $(document).ready(function () { - $("form input[autofocus]").focus(); - - $("#signUpForm").bind("submit", function(event) { - event.preventDefault(); - - var email = $("#email").val(), - password = $("#password").val(); - - BrowserIDNetwork.authenticate(email, password, function onSuccess(authenticated) { - if (authenticated) { - document.location = "/"; - } - else { - // bad authentication - $(".notifications .notification.doh").fadeIn(); - } - }, function onFailure() { - // Wah wah. Network error - }); - }); - - }); -</script> diff --git a/browserid/views/signup.ejs b/browserid/views/signup.ejs index 5a0fa3122fe16ec978ae7147b7642a216deab0d5..e16483caea3370c3c8495960c9632a1a70ba2755 100644 --- a/browserid/views/signup.ejs +++ b/browserid/views/signup.ejs @@ -28,52 +28,3 @@ </div> </div> -<script type="text/javascript"> - var ANIMATION_SPEED = 250; - - function replaceWithMessage(selector) { - $('.forminputs').fadeOut(ANIMATION_SPEED, function() { - $(selector).fadeIn(ANIMATION_SPEED); - }); - } - - function showNotice(selector) { - $(selector).fadeIn(ANIMATION_SPEED); - } - - function onFailure() { - replaceWithMessage(".doh"); - } - - - $(function () { - var identities = BrowserIDIdentities; - - $("form input[autofocus]").focus(); - - $("#email").bind("keyup", function(event) { - if (event.which !== 13) { - $(".notification").fadeOut(ANIMATION_SPEED); - } - }); - - $("#signUpForm").bind("submit", function(event) { - event.preventDefault(); - - var email = $("#email").val(); - identities.emailRegistered(email, function(registered) { - if (!registered) { - identities.createUser(email, function onSuccess(keypair) { - $('#sentToEmail').html(email); - replaceWithMessage(".emailsent"); - }, onFailure); - } - else { - $('#registeredEmail').html(email); - showNotice(".alreadyRegistered"); - } - }, onFailure); - }); - - }); -</script>