summaryrefslogtreecommitdiffstats
path: root/templates/content/jquery-openid/jquery.openid.js
blob: 8d1cd2047d244ea725577978cf700e121f80f955 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//jQuery OpenID Plugin 1.1 Copyright 2009 Jarrett Vance http://jvance.com/pages/jQueryOpenIdPlugin.xhtml
$.fn.openid = function() {
  var $this = $(this);

  //name input value - needed for name based OpenID
  var $usr = $this.find('input[name=openid_username]');

  //final url input value
  var $id = $this.find('input[name=openid_url]');

  //beginning and end of name OpenID url (name being the middle)
  var $front = $this.find('p:has(input[name=openid_username])>span:eq(0)');
  var $end = $this.find('p:has(input[name=openid_username])>span:eq(1)');

  //needed for special effects only
  var $localfs = $this.find('fieldset:has(input[name=username])');
  var $usrfs = $this.find('fieldset:has(input[name=openid_username])');
  var $idfs = $this.find('fieldset:has(input[name=openid_url])');

  var submitusr = function() {
    if ($usr.val().length < 1) {
      $usr.focus();
      return false;
    }
    $id.val($front.text() + $usr.val() + $end.text());
    return true;
  };

  var submitid = function() {
    if ($id.val().length < 1) {
      $id.focus();
      return false;
    }
    return true;

  };
  var local = function() {
    var $li = $(this);
    $('#openid_form .providers li').removeClass('highlight');
    $li.addClass('highlight');
    $usrfs.hide();
    $idfs.hide();
    $localfs.show();
    $this.unbind('submit').submit(submitid);
    return false;
  };

  var direct = function() {
    var $li = $(this);
    $('#openid_form .providers li').removeClass('highlight');
    $li.addClass('highlight');
    $usrfs.fadeOut('slow');
    $localfs.fadeOut('slow');
    $idfs.fadeOut('slow');
    $id.val($this.find("li.highlight span").text());
    setTimeout(function(){$('#bsignin').click();},1000);
    return false;
  };

  var openid = function() {
    var $li = $(this);
    $('#openid_form .providers li').removeClass('highlight');
    $li.addClass('highlight');
    $usrfs.hide();
    $localfs.hide();
    $idfs.show();
    $id.focus();
    $this.unbind('submit').submit(submitid);
    return false;
  };

  var username = function() {
    var $li = $(this);
    $('#openid_form .providers li').removeClass('highlight');
    $li.addClass('highlight');
    $idfs.hide();
    $localfs.hide();
    $usrfs.show();
    $this.find('#enter_your_what').text($li.attr("title"));
    $front.text($li.find("span").text().split("username")[0]);
    $end.text("").text($li.find("span").text().split("username")[1]);
    $id.focus();
    $this.unbind('submit').submit(submitusr);
    return false;
  };

  $this.find('li.local').click(local);
  $this.find('li.direct').click(direct);
  $this.find('li.openid').click(openid);
  $this.find('li.username').click(username);
  $id.keypress(function(e) {
    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
      return submitid();
    }
  });
  $usr.keypress(function(e) {
    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
      return submitusr();
    }
  });
  $this.find('li span').hide();
  $this.find('li').css('line-height', 0).css('cursor', 'pointer');
  $usrfs.hide();
  $idfs.hide();
  $localfs.hide();
  $this.find('li:eq(0)').click();

  return this;
};
// submitting next=%2F&openid_username=&openid_url=http%3A%2F%2Fyahoo.com%2F
// submitting next=%2F&openid_username=&openid_url=http%3A%2F%2Fyahoo.com%2F