4 var providers_large = {
7 url: 'https://www.google.com/accounts/o8/id'
11 url: 'http://me.yahoo.com/'
15 label: 'Enter your AOL screenname.',
16 url: 'http://openid.aol.com/{username}'
20 label: 'Enter your OpenID.',
24 var providers_small = {
27 label: 'Enter your MyOpenID username.',
28 url: 'http://{username}.myopenid.com/'
32 label: 'Enter your Livejournal username.',
33 url: 'http://{username}.livejournal.com/'
37 label: 'Enter your Flickr username.',
38 url: 'http://flickr.com/{username}/'
42 label: 'Enter your Technorati username.',
43 url: 'http://technorati.com/people/technorati/{username}/'
47 label: 'Enter your Wordpress.com username.',
48 url: 'http://{username}.wordpress.com/'
52 label: 'Your Blogger account',
53 url: 'http://{username}.blogspot.com/'
57 label: 'Your Verisign username',
58 url: 'http://{username}.pip.verisignlabs.com/'
62 label: 'Your Verisign username',
63 url: 'http://{username}.pip.verisignlabs.com/'
67 label: 'Your ClaimID username',
68 url: 'http://claimid.com/{username}'
71 var providers = $.extend({}, providers_large, providers_small);
75 cookie_expires: 6*30, // 6 months.
76 cookie_name: 'openid_provider',
79 img_path: '/media/images/openid/',
84 init: function(input_id) {
86 var openid_btns = $('#openid_btns');
87 this.input_id = input_id;
89 $('#openid_choice').show();
90 //$('#openid_input_area').empty();
92 // add box for each provider
93 for (id in providers_large) {
94 openid_btns.append(this.getBoxHTML(providers_large[id], 'large', '.gif'));
96 if (providers_small) {
97 openid_btns.append('<br/>');
98 for (id in providers_small) {
99 openid_btns.append(this.getBoxHTML(providers_small[id], 'small', '.png'));
103 var box_id = this.readCookie();
105 this.signin(box_id, true);
108 getBoxHTML: function(provider, box_size, image_ext) {
110 var box_id = provider["name"].toLowerCase();
111 return '<a title="'+provider["name"]+'" href="javascript: openid.signin(\''+ box_id +'\');"' +
112 ' style="background: #FFF url(' + this.img_path + box_id + image_ext+') no-repeat center center" ' + 'class="' + box_id + ' openid_' + box_size + '_btn"></a>';
115 /* Provider image click */
116 signin: function(box_id, onload) {
117 var provider = providers[box_id];
121 this.highlight(box_id);
122 this.setCookie(box_id);
124 $('#'+this.input_id).val(provider['url']);
125 var input = $('#'+this.input_id);
126 if(document.selection){
127 var r = document.all.openid_url.createTextRange();
128 var res = r.findText("{username}");
134 var text = input.val();
135 var searchText = "{username}";
136 var posStart = text.indexOf(searchText);
139 document.getElementById(this.input_id).setSelectionRange(posStart, posStart + searchText.length);
144 highlight: function (box_id) {
145 // remove previous highlight.
146 var highlight = $('#openid_highlight');
148 highlight.replaceWith($('#openid_highlight a')[0]);
150 // add new highlight.
151 $('.'+box_id).wrap('<div id="openid_highlight"></div>');
154 setCookie: function (value) {
155 var date = new Date();
156 date.setTime(date.getTime()+(this.cookie_expires*24*60*60*1000));
157 var expires = "; expires="+date.toGMTString();
158 document.cookie = this.cookie_name+"="+value+expires+"; path=" + this.cookie_path;
161 readCookie: function () {
162 var nameEQ = this.cookie_name + "=";
163 var ca = document.cookie.split(';');
164 for(var i=0;i < ca.length;i++) {
166 while (c.charAt(0)==' ') c = c.substring(1,c.length);
167 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);