3 http://code.google.com/p/openid-selector/
5 This code is licenced under the New BSD License.
8 var providers_large = {
11 url: 'https://www.google.com/accounts/o8/id'
15 url: 'http://yahoo.com/'
19 label: 'Enter your AOL screenname.',
20 url: 'http://openid.aol.com/{username}'
24 label: 'Your Verisign username',
25 url: 'http://{username}.pip.verisignlabs.com/'
29 label: 'Enter your OpenID.',
33 var providers_small = {
36 label: 'Enter your MyOpenID username.',
37 url: 'http://{username}.myopenid.com/'
41 label: 'Enter your Livejournal username.',
42 url: 'http://{username}.livejournal.com/'
46 label: 'Enter your Flickr username.',
47 url: 'http://flickr.com/{username}/'
51 label: 'Enter your Technorati username.',
52 url: 'http://technorati.com/people/technorati/{username}/'
56 label: 'Enter your Wordpress.com username.',
57 url: 'http://{username}.wordpress.com/'
61 label: 'Your Blogger account',
62 url: 'http://{username}.blogspot.com/'
66 label: 'Your Vidoop username',
67 url: 'http://{username}.myvidoop.com/'
71 label: 'Your ClaimID username',
72 url: 'http://claimid.com/{username}'
75 var providers = $.extend({}, providers_large, providers_small);
81 cookie_expires: 6*30, // 6 months.
82 cookie_name: 'openid_provider',
91 init: function(input_id) {
93 var openid_btns = $('#openid_btns');
95 this.input_id = input_id;
97 $('#openid_choice').show();
98 $('#openid_input_area').empty();
100 // add box for each provider
101 for (id in providers_large) {
103 openid_btns.append(this.getBoxHTML(providers_large[id], 'large', '.gif'));
105 if (providers_small) {
106 openid_btns.append('<br/>');
108 for (id in providers_small) {
110 openid_btns.append(this.getBoxHTML(providers_small[id], 'small', '.ico'));
114 $('#openid_form').submit(this.submit);
116 var box_id = this.readCookie();
118 this.signin(box_id, true);
121 getBoxHTML: function(provider, box_size, image_ext) {
123 var box_id = provider["name"].toLowerCase();
124 return '<a title="'+provider["name"]+'" href="javascript: openid.signin(\''+ box_id +'\');"' +
125 ' style="background: #FFF url(' + this.img_path + box_id + image_ext+') no-repeat center center" ' +
126 'class="' + box_id + ' openid_' + box_size + '_btn"></a>';
129 /* Provider image click */
130 signin: function(box_id, onload) {
132 var provider = providers[box_id];
137 this.highlight(box_id);
138 this.setCookie(box_id);
140 this.provider_id = box_id;
141 this.provider_url = provider['url'];
143 // prompt user for input?
144 if (provider['label']) {
145 this.useInputBox(provider);
147 $('#openid_input_area').empty();
149 $('#openid_form').submit();
153 /* Sign-in button click */
156 var url = openid.provider_url;
158 url = url.replace('{username}', $('#openid_username').val());
159 openid.setOpenIdUrl(url);
161 if(openid.ajaxHandler) {
162 openid.ajaxHandler(openid.provider_id, document.getElementById(openid.input_id).value);
166 alert("In client demo mode. Normally would have submitted OpenID:\r\n" + document.getElementById(openid.input_id).value);
171 setOpenIdUrl: function (url) {
173 var hidden = document.getElementById(this.input_id);
174 if (hidden != null) {
177 $('#openid_form').append('<input type="hidden" id="' + this.input_id + '" name="' + this.input_id + '" value="'+url+'"/>');
180 highlight: function (box_id) {
182 // remove previous highlight.
183 var highlight = $('#openid_highlight');
185 highlight.replaceWith($('#openid_highlight a')[0]);
187 // add new highlight.
188 $('.'+box_id).wrap('<div id="openid_highlight"></div>');
190 setCookie: function (value) {
192 var date = new Date();
193 date.setTime(date.getTime()+(this.cookie_expires*24*60*60*1000));
194 var expires = "; expires="+date.toGMTString();
196 document.cookie = this.cookie_name+"="+value+expires+"; path=" + this.cookie_path;
198 readCookie: function () {
199 var nameEQ = this.cookie_name + "=";
200 var ca = document.cookie.split(';');
201 for(var i=0;i < ca.length;i++) {
203 while (c.charAt(0)==' ') c = c.substring(1,c.length);
204 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
208 useInputBox: function (provider) {
210 var input_area = $('#openid_input_area');
213 var id = 'openid_username';
215 var label = provider['label'];
219 html = '<p>' + label + '</p>';
221 if (provider['name'] == 'OpenID') {
224 style = 'background:#FFF url('+this.img_path+'openid-inputicon.gif) no-repeat scroll 0 50%; padding-left:18px;';
226 html += '<input id="'+id+'" type="text" style="'+style+'" name="'+id+'" value="'+value+'" />' +
227 '<input id="openid_submit" type="submit" value="Sign-In"/>';
230 input_area.append(html);
234 setDemoMode: function (demoMode) {
235 this.demo = demoMode;
237 setAjaxHandler: function (ajaxFunction) {
238 this.ajaxHandler = ajaxFunction;