PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.6.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.6.9
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / assets / src / js / admin / share / advertisement.js

advertisement.js in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.6.9, at assets/src/js/admin/share/advertisement.js

80 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function( $ ) {
2 function LP_Advertisement_Slider( el, options ) {
3 this.options = $.extend( {}, options || {} );
4 let $el = $( el ),
5 $items = $el.find( '.slide-item' ),
6 $controls = $( '<div class="slider-controls"><div class="prev-item"></div><div class="next-item"></div></div>' ),
7 $wrapItems = $( '<div class="slider-items"></div>' ).append( $items ),
8 itemIndex = 0,
9 timer = null;
10
11 function init() {
12 createHTML();
13 bindEvents();
14 activeItem();
15 }
16
17 function createHTML() {
18 $el.append( $wrapItems );
19 $items.each( function() {
20 $( this ).append( $controls.clone() );
21 } );
22 }
23
24 function activeItem( index ) {
25 index = index !== undefined ? index : itemIndex;
26 const activeItem = $items.eq( index );
27
28 activeItem.show();
29 // A ha???
30 setTimeout( function() {
31 activeItem.addClass( 'slide-active' );
32 }, 1 );
33
34 activeItem.siblings().removeClass( 'slide-active' );
35
36 timer && clearTimeout( timer );
37 timer = setTimeout( function() {
38 activeItem.siblings().hide();
39 }, 500 );
40 }
41
42 function nextItem() {
43 if ( itemIndex < $items.length - 1 ) {
44 itemIndex++;
45 } else {
46 itemIndex = 0;
47 }
48 activeItem( itemIndex );
49 }
50
51 function prevItem() {
52 if ( itemIndex > 0 ) {
53 itemIndex--;
54 } else {
55 itemIndex = $items.length - 1;
56 }
57 activeItem( itemIndex );
58 }
59
60 function bindEvents() {
61 $el.on( 'click', '.next-item', nextItem );
62 $el.on( 'click', '.prev-item', prevItem );
63 }
64
65 init();
66 }
67
68 $.fn.LP( 'Advertisement', function( opts ) {
69 return $.each( this, function() {
70 let $slider = $( this ).data( 'LP_Advertisement_Slider' );
71 if ( ! $slider ) {
72 $slider = new LP_Advertisement_Slider( this, opts );
73 $( this ).data( 'LP_Advertisement_Slider', $slider );
74 }
75 return this;
76 } );
77 } );
78 }( jQuery ) );
79
80