Mercurial > boosterpack
view logintets/login_presentation.js @ 5:e91d6f908222 boosterpack
[svn r7] finished!
author | robert |
---|---|
date | Tue, 08 Sep 2009 06:55:23 -0400 |
parents | 477258d09353 |
children |
line wrap: on
line source
1 var showingLoggedIn = false;2 var messageElement = false;3 var messageP = false;5 // focusField method: called when username and password gain focus6 function focusField()7 {8 try {9 if (messageElement != false)10 {11 document.getElementById('message').removeChild(messageElement);12 }13 getSeed();14 }15 catch (e)16 { } // do nothing... hides an apparent firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=23679117 }19 // blurField method: called when username and password are blurred20 function blurField()21 {22 try {23 validateLogin();24 }25 catch (e)26 { } // hide bug https://bugzilla.mozilla.org/show_bug.cgi?id=23679127 }29 // showLogin method: displays if necessariy that we are logged in30 function showLogin() {31 if (messageElement != false)32 {33 try {34 document.getElementById('message').removeChild(messageElement);35 }36 catch (e) { }37 }38 if (loggedIn)39 {40 showingLoggedIn = true;42 loginPanel = document.getElementById('login');43 p = document.createElement('p');44 pre = document.createTextNode('Logged in as ');45 strong = document.createElement('strong');46 strong_text = document.createTextNode(fullname);47 strong.appendChild(strong_text);48 mid = document.createTextNode(' [');49 a = document.createElement('a');50 a.href='javascript:logout();';51 a_text = document.createTextNode('logout');52 a.appendChild(a_text);53 post = document.createTextNode(']');55 p.appendChild(pre);56 p.appendChild(strong);57 p.appendChild(mid);58 p.appendChild(a);59 p.appendChild(post);61 messageP = document.getElementById('message');62 loginPanel.removeChild(messageP);63 loginPanel.appendChild(p);65 messageElement = p;67 document.getElementById('username').disabled = 'disabled';68 document.getElementById('password').disabled = 'disabled';70 document.getElementById('comments').focus();71 }72 else73 {74 messageElement = document.createElement('strong');75 messageElement.appendChild(document.createTextNode(' ' + messages));76 messageElement.style.color = '#ff0000';77 document.getElementById('message').appendChild(messageElement);78 }79 }81 // logout method: prepares for a new login82 function logout()83 {84 resetLogin();85 username = document.getElementById('username');86 password = document.getElementById('password');87 loginPanel = document.getElementById('login');88 username.value = '';89 password.value = '';90 username.disabled = null;91 password.disabled = null;93 loginPanel.removeChild(messageElement);94 loginPanel.appendChild(messageP);96 messageElement = false;97 showingLoggedIn = false;99 username.focus();100 }102 // setupLogin method: to be called on page load, sets up the login script103 function setupLogin()104 {105 username = document.getElementById('username');106 password = document.getElementById('password');107 addEvent(username, 'focus', focusField);108 addEvent(username, 'blur', blurField);109 addEvent(password, 'focus', focusField);110 addEvent(password, 'blur', blurField);111 }114 // function to add events to the page in a cross-browser manner115 function addEvent(objObject, strEventName, fnHandler) {116 // DOM-compliant way to add an event listener117 if (objObject.addEventListener) {118 objObject.addEventListener(strEventName, fnHandler, false);119 }120 // IE/windows way to add an event listener121 else if (objObject.attachEvent) {122 objObject.attachEvent('on' + strEventName, fnHandler);123 }124 }126 addEvent(window,'load',setupLogin);