3 http://code.google.com/p/openid-selector/
5 This code is licenced under the New BSD License.
8 var providers_large = {
11 icon: 'http://google.com/favicon.ico',
12 url: 'https://www.google.com/accounts/o8/id'
16 icon: 'http://yahoo.com/favicon.ico',
17 url: 'http://me.yahoo.com/'
21 icon: 'wikiicons/openidlogin-bg.gif',
22 label: 'Enter your OpenID:',
26 var providers_small = {
29 icon: 'http://livejournal.com/favicon.ico',
30 label: 'Enter your Livejournal username:',
31 url: 'http://{username}.livejournal.com/'
35 icon: 'http://flickr.com/favicon.ico',
36 label: 'Enter your Flickr username:',
37 url: 'http://flickr.com/photos/{username}/'
41 icon: 'https://ddgw.s3.amazonaws.com/wordpress.org.ico',
42 label: 'Enter your Wordpress.com username:',
43 url: 'http://{username}.wordpress.com/'
47 icon: 'http://myopenid.com/favicon.ico',
48 label: 'Enter your MyOpenID username:',
49 url: 'http://{username}.myopenid.com/'
53 icon: 'http://claimid.com/favicon.ico',
54 label: 'Enter your ClaimID username:',
55 url: 'http://claimid.com/{username}'
59 icon: 'http://aol.com/favicon.ico',
60 label: 'Enter your AOL username:',
61 url: 'http://openid.aol.com/{username}'
65 icon: 'http://verisign.com/favicon.ico',
66 label: 'Enter your Verisign username:',
67 url: 'http://{username}.pip.verisignlabs.com/'
70 var providers = $.extend({}, providers_large, providers_small);
76 cookie_expires: 6*30, // 6 months.
77 cookie_name: 'openid_provider',
86 init: function(input_id, localloginurl) {
88 var openid_btns = $('#openid_btns');
90 this.input_id = input_id;
92 $('#openid_choice').show();
93 $('#openid_input_area').empty();
95 // add box for each provider
96 for (id in providers_large) {
97 openid_btns.append(this.getBoxHTML(providers_large[id], 'large'));
100 if (providers_small) {
101 openid_btns.append('<br/>');
103 for (id in providers_small) {
105 openid_btns.append(this.getBoxHTML(providers_small[id], 'small'));
108 if (localloginurl != "") {
110 '<a href="' + localloginurl + '"' +
111 ' style="background: #FFF" ' +
112 'class="openid_small_btn">' +
113 '<img alt="" width="16" height="16" src="favicon.ico" />' +
119 $('#openid_form').submit(this.submit);
121 var box_id = this.readCookie();
123 this.signin(box_id, true);
126 getBoxHTML: function(provider, box_size) {
129 if (box_size == 'large') {
130 label=' ' + provider["name"];
133 title=' title="'+provider["name"]+'"';
135 var box_id = provider["name"].toLowerCase();
136 return '<a' + title +' href="javascript: openid.signin(\''+ box_id +'\');"' +
137 ' style="background: #FFF" ' +
138 'class="' + box_id + ' openid_' + box_size + '_btn">' +
139 '<img alt="" width="16" height="16" src="' + provider["icon"] + '" />' +
144 /* Provider image click */
145 signin: function(box_id, onload) {
147 var provider = providers[box_id];
152 this.highlight(box_id);
153 this.setCookie(box_id);
155 this.provider_id = box_id;
156 this.provider_url = provider['url'];
158 // prompt user for input?
159 if (provider['label']) {
160 this.useInputBox(provider);
162 $('#openid_input_area').empty();
164 $('#openid_form').submit();
168 /* Sign-in button click */
171 var url = openid.provider_url;
173 url = url.replace('{username}', $('#openid_username').val());
174 openid.setOpenIdUrl(url);
176 if(openid.ajaxHandler) {
177 openid.ajaxHandler(openid.provider_id, document.getElementById(openid.input_id).value);
181 alert("In client demo mode. Normally would have submitted OpenID:\r\n" + document.getElementById(openid.input_id).value);
186 setOpenIdUrl: function (url) {
188 var hidden = $('#'+this.input_id);
189 if (hidden.length > 0) {
192 $('#openid_form').append('<input style="display:none" id="' + this.input_id + '" name="' + this.input_id + '" value="'+url+'"/>');
195 highlight: function (box_id) {
197 // remove previous highlight.
198 var highlight = $('#openid_highlight');
200 highlight.replaceWith($('#openid_highlight a')[0]);
202 // add new highlight.
203 $('.'+box_id).wrap('<div id="openid_highlight"></div>');
205 setCookie: function (value) {
207 var date = new Date();
208 date.setTime(date.getTime()+(this.cookie_expires*24*60*60*1000));
209 var expires = "; expires="+date.toGMTString();
211 document.cookie = this.cookie_name+"="+value+expires+"; path=" + this.cookie_path;
213 readCookie: function () {
214 var nameEQ = this.cookie_name + "=";
215 var ca = document.cookie.split(';');
216 for(var i=0;i < ca.length;i++) {
218 while (c.charAt(0)==' ') c = c.substring(1,c.length);
219 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
223 useInputBox: function (provider) {
225 var input_area = $('#openid_input_area');
228 var id = 'openid_username';
230 var label = provider['label'];
234 html = '<p>' + label + '</p>';
236 if (provider['name'] == 'OpenID') {
239 style = 'background:#FFF url(wikiicons/openidlogin-bg.gif) no-repeat scroll 0 50%; padding-left:18px;';
241 html += '<input id="'+id+'" type="text" style="'+style+'" name="'+id+'" value="'+value+'" />' +
242 '<input id="openid_submit" type="submit" value="Login"/>';
245 input_area.append(html);
249 setDemoMode: function (demoMode) {
250 this.demo = demoMode;
252 setAjaxHandler: function (ajaxFunction) {
253 this.ajaxHandler = ajaxFunction;