learndash_template_script.js
5.65 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
if ( typeof flip_expand_collapse === 'undefined' ) {
function flip_expand_collapse( what, id ) {
//console.log(id + ':' + document.getElementById( 'list_arrow.flippable-'+id).className);
if ( jQuery( what + '-' + id + ' .list_arrow.flippable' ).hasClass( 'expand' ) ) {
jQuery( what + '-' + id + ' .list_arrow.flippable' ).removeClass( 'expand' );
jQuery( what + '-' + id + ' .list_arrow.flippable' ).addClass( 'collapse' );
jQuery( what + '-' + id + ' .flip' ).slideUp();
} else {
jQuery( what + '-' + id + ' .list_arrow.flippable' ).removeClass( 'collapse' );
jQuery( what + '-' + id + ' .list_arrow.flippable' ).addClass( 'expand' );
jQuery( what + '-' + id + ' .flip' ).slideDown();
}
return false;
}
}
if ( typeof flip_expand_all === 'undefined' ) {
function flip_expand_all( what ) {
jQuery( what + ' .list_arrow.flippable' ).removeClass( 'collapse' );
jQuery( what + ' .list_arrow.flippable' ).addClass( 'expand' );
jQuery( what + ' .flip' ).slideDown();
return false;
}
}
if ( typeof flip_collapse_all === 'undefined' ) {
function flip_collapse_all( what ) {
jQuery( what + ' .list_arrow.flippable' ).removeClass( 'expand' );
jQuery( what + ' .list_arrow.flippable' ).addClass( 'collapse' );
jQuery( what + ' .flip' ).slideUp();
return false;
}
}
String.prototype.toHHMMSS = function() {
sec_numb = parseInt( this, 10 );
var hours = Math.floor( sec_numb / 3600 );
var minutes = Math.floor( ( sec_numb - ( hours * 3600 ) ) / 60 );
var seconds = sec_numb - ( hours * 3600 ) - ( minutes * 60 );
if ( hours < 10 ) {
hours = '0' + hours;
}
if ( minutes < 10 ) {
minutes = '0' + minutes;
}
if ( seconds < 10 ) {
seconds = '0' + seconds;
}
var time = hours + ':' + minutes + ':' + seconds;
return time;
};
jQuery( function() {
if ( jQuery( '.learndash_timer' ).length ) {
jQuery( '.learndash_timer' ).each( function( idx, item ) {
var timer_el = jQuery( item );
var timer_seconds = timer_el.data( 'timer-seconds' );
var button_ref = timer_el.data( 'button' );
if ( ( typeof button_ref !== 'undefined' ) && ( jQuery( button_ref ).length ) ) {
var timer_button_el = jQuery( button_ref );
if ( ( typeof timer_seconds !== 'undefined' ) && ( typeof timer_button_el !== 'undefined' ) ) {
timer_button_el.attr( 'disabled', true );
timer_seconds = parseInt( timer_seconds );
var cookie_key = timer_el.attr( 'data-cookie-key' );
if ( typeof cookie_key !== 'undefined' ) {
var cookie_name = 'learndash_timer_cookie_' + cookie_key;
} else {
var cookie_name = 'learndash_timer_cookie';
}
var cookie_timer_seconds = jQuery.cookie( cookie_name );
if ( typeof cookie_timer_seconds !== 'undefined' ) {
timer_seconds = parseInt( cookie_timer_seconds );
}
//jQuery.removeCookie( cookie_name );
if ( timer_seconds >= 1 ) {
var learndash_timer_var = setInterval( function() {
timer_seconds = timer_seconds - 1;
var time_display = timer_seconds.toString().toHHMMSS();
timer_el.html( time_display );
if ( timer_seconds <= 0 ) {
clearInterval( learndash_timer_var );
timer_button_el.attr( 'disabled', false );
timer_el.html( '' );
timer_el.hide();
jQuery.cookie( cookie_name, 0 );
timer_button_el.trigger( 'learndash-time-finished' );
}
// Store the timer state (value) into a cookie. This is done if the page reloads the student can resume
// the time instead of restarting.
jQuery.cookie( cookie_name, timer_seconds );
}, 1000 );
} else {
timer_button_el.attr( 'disabled', false );
timer_el.html( '' );
jQuery.cookie( cookie_name, 0 );
//jQuery.removeCookie( cookie_name );
}
}
}
} );
}
} );
jQuery( function() {
if ( typeof sfwd_data !== 'undefined' ) {
if ( typeof sfwd_data.json !== 'undefined' ) {
sfwd_data = sfwd_data.json.replace( /"/g, '"' );
sfwd_data = JSON.parse( sfwd_data );
}
}
jQuery( '#ld_course_info' ).on( 'click', 'a.user_statistic', learndash_show_user_statistic );
jQuery( '#learndash_profile' ).on( 'click', 'a.user_statistic', learndash_show_user_statistic );
function learndash_show_user_statistic( e ) {
e.preventDefault();
var refId = jQuery( this ).data( 'ref_id' );
var quizId = jQuery( this ).data( 'quiz_id' );
var userId = jQuery( this ).data( 'user_id' );
var statistic_nonce = jQuery( this ).data( 'statistic_nonce' );
var post_data = {
action: 'wp_pro_quiz_admin_ajax_statistic_load_user',
func: 'statisticLoadUser',
data: {
quizId: quizId,
userId: userId,
refId: refId,
statistic_nonce: statistic_nonce,
avg: 0,
},
};
jQuery( '#wpProQuiz_user_overlay, #wpProQuiz_loadUserData' ).show();
var content = jQuery( '#wpProQuiz_user_content' ).hide();
jQuery.ajax( {
type: 'POST',
url: sfwd_data.ajaxurl,
dataType: 'json',
cache: false,
data: post_data,
error: function( jqXHR, textStatus, errorThrown ) {
},
success: function( reply_data ) {
if ( typeof reply_data.html !== 'undefined' ) {
content.html( reply_data.html );
jQuery( 'a.wpProQuiz_update', content ).remove();
jQuery( 'a#wpProQuiz_resetUserStatistic', content ).remove();
jQuery( 'body' ).trigger( 'learndash-statistics-contentchanged' );
jQuery( '#wpProQuiz_user_content' ).show();
jQuery( '#wpProQuiz_loadUserData' ).hide();
content.find( '.statistic_data' ).on( 'click', function() {
jQuery( this ).parents( 'tr' ).next().toggle( 'fast' );
return false;
} );
}
},
} );
jQuery( '#wpProQuiz_overlay_close' ).on( 'click', function() {
jQuery( '#wpProQuiz_user_overlay' ).hide();
} );
}
} );