-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme.script.min.js
139 lines (88 loc) · 3.63 KB
/
theme.script.min.js
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
(function($){'use strict';$(document).on('click','.sl-button',function(){var button=$(this);var post_id=button.attr('data-post-id');var security=button.attr('data-nonce');var iscomment=button.attr('data-iscomment');var allbuttons;if(iscomment==='1'){allbuttons=$('.sl-comment-button-'+post_id);}else{allbuttons=$('.sl-button-'+post_id);}
var loader=allbuttons.next('#sl-loader');if(post_id!==''){$.ajax({type:'POST',url:psyAjax.url,data:{action:'process_simple_like',post_id:post_id,nonce:security,is_comment:iscomment,},beforeSend:function(){loader.html(' <div class="loader">Loading...</div>');},success:function(response){var icon=response.icon;var count=response.count;allbuttons.html(icon+count);if(response.status==='unliked'){var like_text=psyAjax.like;allbuttons.prop('title',like_text);allbuttons.removeClass('liked');}else{var unlike_text=psyAjax.unlike;allbuttons.prop('title',unlike_text);allbuttons.addClass('liked');}
loader.empty();}});}
return false;});})(jQuery);
function pt_open_login_dialog(href){
jQuery('#pt-user-modal .modal-dialog').removeClass('registration-complete');
var modal_dialog = jQuery('#pt-user-modal .modal-dialog');
modal_dialog.attr('data-active-tab', '');
switch(href){
case '#pt-register':
modal_dialog.attr('data-active-tab', '#pt-register');
break;
case '#pt-login':
default:
modal_dialog.attr('data-active-tab', '#pt-login');
break;
}
jQuery('#pt-user-modal').modal('show');
}
function pt_close_login_dialog(){
jQuery('#pt-user-modal').modal('hide');
}
jQuery(function($){
"use strict";
/***************************
** LOGIN / REGISTER DIALOG
***************************/
// Open login/register modal
$('[href="#pt-login"], [href="#pt-register"]').click(function(e){
e.preventDefault();
pt_open_login_dialog( $(this).attr('href') );
});
// Switch forms login/register
$('.modal-footer a, a[href="#pt-reset-password"]').click(function(e){
e.preventDefault();
$('#pt-user-modal .modal-dialog').attr('data-active-tab', $(this).attr('href'));
});
// Post login form
$('#pt_login_form').on('submit', function(e){
e.preventDefault();
var button = $(this).find('button');
button.button('loading');
$.post(psyAjax.url, $('#pt_login_form').serialize(), function(data){
var obj = $.parseJSON(data);
$('.pt-login .pt-errors').html(obj.message);
if(obj.error == false){
$('#pt-user-modal .modal-dialog').addClass('loading');
window.location.reload(true);
button.hide();
}
button.button('reset');
});
});
// Post register form
$('#pt_registration_form').on('submit', function(e){
e.preventDefault();
var button = $(this).find('button');
button.button('loading');
$.post(psyAjax.url, $('#pt_registration_form').serialize(), function(data){
var obj = $.parseJSON(data);
$('.pt-register .pt-errors').html(obj.message);
if(obj.error == false){
$('#pt-user-modal .modal-dialog').addClass('registration-complete');
// window.location.reload(true);
button.hide();
}
button.button('reset');
});
});
// Reset Password
$('#pt_reset_password_form').on('submit', function(e){
e.preventDefault();
var button = $(this).find('button');
button.button('loading');
$.post(psyAjax.url, $('#pt_reset_password_form').serialize(), function(data){
var obj = $.parseJSON(data);
$('.pt-reset-password .pt-errors').html(obj.message);
// if(obj.error == false){
// $('#pt-user-modal .modal-dialog').addClass('loading');
// $('#pt-user-modal').modal('hide');
// }
button.button('reset');
});
});
if(window.location.hash == '#login'){
pt_open_login_dialog('#pt-login');
}
});