YaWK  24.1
Yet another WebKit
loginbox.ajax.js
Go to the documentation of this file.
1 $(document).ready(function(){
2  // RUN AJAX TIMER
3  initTimer();
4  // set a timeout so that ajax calls will be delayed
5  function initTimer(){
6  var myTimer = 0;
7  $("#loginForm").on('keydown', function() {
8  // cancel any previously-set timer
9  if (myTimer) {
10  clearTimeout(myTimer);
11  }
12  // set timeout function
13  myTimer = setTimeout(function() {
14  // call validation settings
15  checkForm();
16  }, 300); //delay time in milliseconds
17  });
18  }
19 
20  // check form function
21  function checkForm(){
22  // console.log('check form called');
23  // initialize form validation plugin
24  $('#loginForm').validate({
25  // set placement of error messages
26  errorPlacement: function(error, element) {
27  error.insertBefore(element);
28  },
29  rules: {
30  user: {
31  required: true,
32  minlength: 4,
33  maxlength: 48
34  },
35  password: {
36  required: true,
37  minlength: 4,
38  maxlength: 48
39  }
40  }
41  });
42  }
43 
44  var loginForm = $("#loginForm");
45 
46  // send the form when enter is pressed
47  $(loginForm).keypress(function(event){
48  var keycode = (event.keyCode ? event.keyCode : event.which);
49  if(keycode === '13'){
50  // invoke submit
51  $('#submit').click();
52  }
53  });
54 
55  // on submit
56  $(loginForm).submit(function(e)
57  { //
58  e.preventDefault();
59  // get username value from form
60  var user = $('#user').val();
61  // get password from form
62  var password = $('#password').val();
63  // get greeting from form
64  var loginboxGreeting = $('#loginboxGreeting').val();
65  var loginboxGreetingText = $('#loginboxGreetingText').val();
66  var loginboxGreetingTextType = $('#loginboxGreetingTextType').val();
67  var loginboxGreetingTextClass = $('#loginboxGreetingTextClass').val();
68  var loginboxGreetingSubtext = $('#loginboxGreetingSubtext').val();
69  var loginboxGreetingShowName = $('#loginboxGreetingShowName').val();
70  var loginboxLogoutBtnText = $('#loginboxLogoutBtnText').val();
71  var loginboxLogoutBtnClass = $('#loginboxLogoutBtnClass').val();
72  var loginboxRedirect = $('#loginboxRedirect').val();
73  var loginboxRedirectTime = $('#loginboxRedirectTime').val();
74 
75  // the logout button
76  var logoutBtn = '<a href="logout" id="logoutBtn" class="'+loginboxLogoutBtnClass+'" target="_self">'+loginboxLogoutBtnText+'</a>';
77 
78  // shake form function
79  function shakeForm()
80  { // if user/pass is wrong or not set pay attention with this animation
81  $(loginForm).effect( "shake", {times:3}, 820 );
82  }
83  // if password or user is not set
84  if (!password.trim() || (!user.trim())) {
85  // shake the form elements to get users attention
86  shakeForm();
87  return false;
88  }
89 
90  // run ajax form
91  $.ajax({
92  // PHP file to process within this request
93  url:'system/widgets/loginbox/js/loginbox.ajax.php',
94  // form method (get or post)
95  type:'POST',
96  // allow cross origin requests
97  crossOrigin: true,
98  // set async to false if you experience double calls
99  async: true,
100  // data string
101  data: {user: user, password: password},
102  // data:'user='+user+'&password='+password,
103  // check if request was successful
104  success:function(data){
105  // if no data is set
106  if(!data){
107  // draw error message and return false
108  console.log('ajax error during login: no data was sent');
109  alert('ERROR: ajax processing failed: no data was sent');
110  return false;
111  }
112  else
113  { // ajax was succesful, check php return
114  if (data.status === true)
115  { // login successful
116  // console.log('login true');
117  // hide login form
118  $("#heading").hide();
119  $("#loginForm").hide();
120 
121  // check if redirect url is set
122  if (loginboxRedirect)
123  { // check if redirect time is set
124  if (loginboxRedirectTime)
125  { // use delay before redirecting
126  setTimeout(function () {
127  window.location.href = ""+loginboxRedirect+"";
128  }, loginboxRedirectTime);
129  }
130  else
131  { // redirect instant w/o delay
132  window.location.replace(""+loginboxRedirect+"");
133  }
134  }
135 
136  // if greeting text type is set to globaltext
137  if (loginboxGreetingTextType === "GLOBALTEXT")
138  { // use html paragraph
139  loginboxGreetingTextType = 'p';
140  }
141 
142  // only add class if it is not empty
143  if (loginboxGreetingTextClass)
144  { // set text class markup
145  var loginboxGreetingTextClassMarkup = ' class="'+loginboxGreetingTextClass+'"';
146  }
147  else
148  { // no markup needed
149  loginboxGreetingTextClassMarkup = '';
150  }
151 
152  // maximum greeting
153  if (loginboxGreeting === "greeting-max")
154  { // do a personal greeting with username
155  $("#thankYouMessage").append('<'+loginboxGreetingTextType+''+loginboxGreetingTextClassMarkup+'>'+loginboxGreetingText+' '+user+' <small>'+loginboxGreetingSubtext+'</small></'+loginboxGreetingTextType+'>'+logoutBtn+'');
156  }
157 
158  // minimal greeting
159  if (loginboxGreeting === "greeting-min")
160  {
161  // welcome message without name
162  $("#thankYouMessage").append('<'+loginboxGreetingTextType+''+loginboxGreetingTextClassMarkup+'>'+loginboxGreetingText+' <small>'+loginboxGreetingSubtext+'</small></'+loginboxGreetingTextType+'>'+logoutBtn+'');
163  }
164 
165  // no greeting, just a logout button
166  if (loginboxGreeting === "greeting-button")
167  {
168  // display logout button
169  $("#thankYouMessage").append(''+logoutBtn+'');
170  }
171 
172  // no greeting, silent login mode
173  if (loginboxGreeting === "greeting-none")
174  {
175  // no welcome message
176  $("#thankYouMessage").hide();
177  }
178  }
179  else
180  { // login failed
181  // shake form
182  shakeForm();
183  // write failed state to console
184  // console.log('login failed');
185  }
186  }
187  },
188  error:function(data){
189  // login failed
190  shakeForm();
191  console.log('Login failed / username or pwd wrong');
192  }
193  });
194  });
195 });
function window
Definition: fuckAdBlock.js:8
FuckAdBlock prototype on
Definition: fuckAdBlock.js:227
c jPlayer event
c jPlayer error
document ready(function(){ initTimer();function initTimer(){ var myTimer=0;$("#loginForm").on('keydown', function() { if(myTimer) { clearTimeout(myTimer);} myTimer=setTimeout(function() { checkForm();}, 300);});} function checkForm(){ $('#loginForm').validate({ errorPlacement:function(error, element) { error.insertBefore(element);}, rules:{ user:{ required:true, minlength:4, maxlength:48 }, password:{ required:true, minlength:4, maxlength:48 } } });} var loginForm=$("#loginForm");$(loginForm).keypress(function(event){ var keycode=(event.keyCode ? event.keyCode :event.which);if(keycode==='13'){ $('#submit').click();} });$(loginForm).submit(function(e) { e.preventDefault();var user=$('#user').val();var password=$('#password').val();var loginboxGreeting=$('#loginboxGreeting').val();var loginboxGreetingText=$('#loginboxGreetingText').val();var loginboxGreetingTextType=$('#loginboxGreetingTextType').val();var loginboxGreetingTextClass=$('#loginboxGreetingTextClass').val();var loginboxGreetingSubtext=$('#loginboxGreetingSubtext').val();var loginboxGreetingShowName=$('#loginboxGreetingShowName').val();var loginboxLogoutBtnText=$('#loginboxLogoutBtnText').val();var loginboxLogoutBtnClass=$('#loginboxLogoutBtnClass').val();var loginboxRedirect=$('#loginboxRedirect').val();var loginboxRedirectTime=$('#loginboxRedirectTime').val();var logoutBtn='< a href="logout" id="logoutBtn" class="'+loginboxLogoutBtnClass+'" target="_self">'+loginboxLogoutBtnText+'</a >';function shakeForm() { $(loginForm).effect("shake", {times:3}, 820);} if(!password.trim()||(!user.trim())) { shakeForm();return false;} $.ajax({ url:'system/widgets/loginbox/js/loginbox.ajax.php', type:'POST', crossOrigin:true, async:true, data:{user:user, password:password}, success:function(data){ if(!data){ console.log('ajax error during login:no data was sent');alert('ERROR:ajax processing failed:no data was sent');return false;} else { if(data.status===true) { $("#heading").hide();$("#loginForm").hide();if(loginboxRedirect) { if(loginboxRedirectTime) { setTimeout(function() { window.location.href=""+loginboxRedirect+"";}, loginboxRedirectTime);} else { window.location.replace(""+loginboxRedirect+"");} } if(loginboxGreetingTextType==="GLOBALTEXT") { loginboxGreetingTextType='p';} if(loginboxGreetingTextClass) { var loginboxGreetingTextClassMarkup=' class="'+loginboxGreetingTextClass+'"';} else { loginboxGreetingTextClassMarkup='';} if(loginboxGreeting==="greeting-max") { $("#thankYouMessage").append('<'+loginboxGreetingTextType+''+loginboxGreetingTextClassMarkup+'>'+loginboxGreetingText+' '+user+'< small >'+loginboxGreetingSubtext+'</small ></'+loginboxGreetingTextType+'>'+logoutBtn+'');} if(loginboxGreeting==="greeting-min") { $("#thankYouMessage").append('<'+loginboxGreetingTextType+''+loginboxGreetingTextClassMarkup+'>'+loginboxGreetingText+'< small >'+loginboxGreetingSubtext+'</small ></'+loginboxGreetingTextType+'>'+logoutBtn+'');} if(loginboxGreeting==="greeting-button") { $("#thankYouMessage").append(''+logoutBtn+'');} if(loginboxGreeting==="greeting-none") { $("#thankYouMessage").hide();} } else { shakeForm();} } }, error:function(data){ shakeForm();console.log('Login failed/username or pwd wrong');} });});})
type
Definition: menu-new.php:35
function e
Definition: plyr.js:1