3 http://code.google.com/p/openid-selector/
5 This code is licenced under the New BSD License.
8 var providers_large = {
11 icon: 'ikiwiki/openid/goa-account-google.png',
12 url: 'https://www.google.com/accounts/o8/id'
16 icon: 'ikiwiki/openid/goa-account-yahoo.png',
17 url: 'http://me.yahoo.com/'
21 icon: 'wikiicons/openidlogin-bg.gif',
22 label: 'Enter your OpenID:',
26 var providers_small = {
29 icon: 'ikiwiki/openid/livejournal.png',
30 label: 'Enter your Livejournal username:',
31 url: 'http://{username}.livejournal.com/'
35 icon: 'ikiwiki/openid/goa-account-flickr.png',
36 label: 'Enter your Flickr username:',
37 url: 'http://flickr.com/photos/{username}/'
41 icon: 'ikiwiki/openid/wordpress.png',
42 label: 'Enter your Wordpress.com username:',
43 url: 'http://{username}.wordpress.com/'
47 icon: 'ikiwiki/openid/aol.png',
48 label: 'Enter your AOL username:',
49 url: 'http://openid.aol.com/{username}'
53 icon: 'ikiwiki/openid/verisign.png',
54 label: 'Enter your Verisign username:',
55 url: 'http://{username}.pip.verisignlabs.com/'
58 var providers = $.extend({}, providers_large, providers_small);
64 cookie_expires: 6*30, // 6 months.
65 cookie_name: 'openid_provider',
75 init: function(input_id, localsignin_id) {
77 var openid_btns = $('#openid_btns');
79 this.input_id = input_id;
81 $('#openid_choice').show();
82 $('#openid_input_area').empty();
84 // add box for each provider
85 for (id in providers_large) {
86 openid_btns.append(this.getBoxHTML(providers_large[id], 'large'));
89 if (providers_small) {
90 openid_btns.append('<br/>');
92 for (id in providers_small) {
94 openid_btns.append(this.getBoxHTML(providers_small[id], 'small'));
97 if (localsignin_id != "") {
98 this.localsignin_id=localsignin_id;
100 '<a href="javascript: openid.signin(\'localsignin\');"' +
101 ' style="background: #FFF" ' +
102 'class="localsignin openid_small_btn">' +
103 '<img alt="" width="16" height="16" src="favicon.ico" />' +
107 $('#'+this.localsignin_id).hide();
110 $('#openid_form').submit(this.submit);
112 var box_id = this.readCookie();
114 this.signin(box_id, true);
117 getBoxHTML: function(provider, box_size) {
120 if (box_size == 'large') {
121 label=' ' + provider["name"];
124 title=' title="'+provider["name"]+'"';
126 var box_id = provider["name"].toLowerCase();
127 return '<a' + title +' href="javascript: openid.signin(\''+ box_id +'\');"' +
128 ' style="background: #FFF" ' +
129 'class="' + box_id + ' openid_' + box_size + '_btn">' +
130 '<img alt="" width="16" height="16" src="' + provider["icon"] + '" />' +
135 /* Provider image click */
136 signin: function(box_id, onload) {
138 if (box_id == 'localsignin') {
139 this.highlight(box_id);
140 $('#openid_input_area').empty();
141 $('#'+this.localsignin_id).show();
142 this.setCookie(box_id);
146 if (this.localsignin_id) {
147 $('#'+this.localsignin_id).hide();
151 var provider = providers[box_id];
156 this.highlight(box_id);
158 this.provider_id = box_id;
159 this.provider_url = provider['url'];
161 // prompt user for input?
162 if (provider['label']) {
163 this.setCookie(box_id);
164 this.useInputBox(provider);
167 $('#openid_input_area').empty();
169 $('#openid_form').submit();
173 /* Sign-in button click */
176 var url = openid.provider_url;
178 url = url.replace('{username}', $('#openid_username').val());
179 openid.setOpenIdUrl(url);
181 if(openid.ajaxHandler) {
182 openid.ajaxHandler(openid.provider_id, document.getElementById(openid.input_id).value);
186 alert("In client demo mode. Normally would have submitted OpenID:\r\n" + document.getElementById(openid.input_id).value);
191 setOpenIdUrl: function (url) {
193 var hidden = $('#'+this.input_id);
194 if (hidden.length > 0) {
197 $('#openid_form').append('<input style="display:none" id="' + this.input_id + '" name="' + this.input_id + '" value="'+url+'"/>');
200 highlight: function (box_id) {
202 // remove previous highlight.
203 var highlight = $('#openid_highlight');
205 highlight.replaceWith($('#openid_highlight a')[0]);
207 // add new highlight.
208 $('.'+box_id).wrap('<div id="openid_highlight"></div>');
210 setCookie: function (value) {
212 var date = new Date();
213 date.setTime(date.getTime()+(this.cookie_expires*24*60*60*1000));
214 var expires = "; expires="+date.toGMTString();
216 document.cookie = this.cookie_name+"="+value+expires+"; path=" + this.cookie_path;
218 readCookie: function () {
219 var nameEQ = this.cookie_name + "=";
220 var ca = document.cookie.split(';');
221 for(var i=0;i < ca.length;i++) {
223 while (c.charAt(0)==' ') c = c.substring(1,c.length);
224 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
228 useInputBox: function (provider) {
230 var input_area = $('#openid_input_area');
233 var id = 'openid_username';
235 var label = provider['label'];
238 if (provider['name'] == 'OpenID') {
241 style = 'background:#FFF url(wikiicons/openidlogin-bg.gif) no-repeat scroll 0 50%; padding-left:18px;';
244 html = '<label for="'+ id +'" class="block">' + label + '</label>';
246 html += '<input id="'+id+'" type="text" style="'+style+'" name="'+id+'" value="'+value+'" />' +
247 '<input id="openid_submit" type="submit" value="Login"/>';
250 input_area.append(html);
254 setDemoMode: function (demoMode) {
255 this.demo = demoMode;
257 setAjaxHandler: function (ajaxFunction) {
258 this.ajaxHandler = ajaxFunction;