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
/**
* JS events for the view manager
*
* @package LifterLMS/Scripts
*
* @since 3.8.0
* @since 4.2.0 Added access plans action button selector to the list of links to update.
*
* @version 4.2.0
*/
( function( $, undefined ) {
window.llms = window.llms || {};
var ViewManager = function() {
var currentView = 'self',
currentNonce;
/**
* Set the current Nonce
*
* @param string nonce a nonce
* @since 3.8.0
* @version 3.8.0
*/
this.set_nonce = function( nonce ) {
currentNonce = nonce;
return this;
}
/**
* Set the current view
*
* @param string view a view option
* @since 3.8.0
* @version 3.8.0
*/
this.set_view = function( view ) {
currentView = view;
return this;
}
/**
* Update various links on the page for easy navigation when using views.
*
* @since 3.8.0
* @since 4.2.0 Added access plans action button selector to the list of links to update.
*
* @return void
*/
this.update_links = function() {
if ( 'self' === currentView || ! currentNonce ) {
return;
}
var $links = $( '.llms-widget-syllabus .llms-lesson a, .llms-course-progress a, .llms-lesson-preview a.llms-lesson-link, .llms-parent-course-link a.llms-lesson-link, .llms-access-plans a.llms-button-action' );
$links.each( function() {
var $link = $( this ),
href = $link.attr( 'href' ),
split = href.split( '?' ),
qs = {};
if ( split.length > 1 ) {
$.each( split[1].split( '&' ), function( i, pair ) {
pair = pair.split( '=' );
qs[ pair[0] ] = pair[1];
} );
}
qs['llms-view-as'] = currentView;
qs.view_nonce = currentNonce;
$link.attr( 'href', split[0] + '?' + $.param( qs ) );
} );
}
};
// initialize the object
window.llms.ViewManager = new ViewManager();
} )( jQuery );