PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.4
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.4
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 4.2.1 All 138 releases
learnpress / assets / src / js / admin / admin.js

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

256 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { initElsTomSelect, searchUserOnListPost } from './init-tom-select.js';
2 import { AdminUtilsFunctions, Api, Utils } from './utils-admin.js';
3
4 ( function( $ ) {
5 /**
6 * Callback event for button to creating pages inside error message.
7 *
8 * @param {Event} e
9 */
10
11 const createPages = function createPages( e ) {
12 const $button = $( this ).addClass( 'disabled' );
13 e.preventDefault();
14 $.post( {
15 url: $button.attr( 'href' ),
16 data: {
17 'lp-ajax': 'create-pages',
18 },
19 dataType: 'text',
20 success: function success( res ) {
21 const $message = $button.closest( '.lp-notice' ).html( '<p>' + res + '</p>' );
22 setTimeout( function() {
23 $message.fadeOut();
24 }, 2000 );
25 },
26 } );
27 };
28
29 const lpMetaboxFileInput = () => {
30 $( '.lp-meta-box__file' ).each( ( i, element ) => {
31 let lpImageFrame;
32
33 const imageGalleryIds = $( element ).find( '.lp-meta-box__file_input' );
34 const listImages = $( element ).find( '.lp-meta-box__file_list' );
35 const btnUpload = $( element ).find( '.btn-upload' );
36 const isMultil = !! $( element ).data( 'multil' );
37
38 $( btnUpload ).on( 'click', ( event ) => {
39 event.preventDefault();
40
41 if ( lpImageFrame ) {
42 lpImageFrame.open();
43 return;
44 }
45
46 lpImageFrame = wp.media( {
47 states: [
48 new wp.media.controller.Library( {
49 filterable: 'all',
50 multiple: isMultil,
51 } ),
52 ],
53 } );
54
55 lpImageFrame.on( 'select', function() {
56 const selection = lpImageFrame.state().get( 'selection' );
57 let attachmentIds = imageGalleryIds.val();
58
59 selection.forEach( function( attachment ) {
60 attachment = attachment.toJSON();
61
62 if ( attachment.id ) {
63 if ( ! isMultil ) {
64 attachmentIds = attachment.id;
65 listImages.empty();
66 } else {
67 attachmentIds = attachmentIds ? attachmentIds + ',' + attachment.id : attachment.id;
68 }
69
70 listImages.append(
71 '<li class="lp-meta-box__file_list-item image" data-attachment_id="' + attachment.id + '"><img class="is_file" src="' + attachment.icon +
72 '" /><span>' + attachment.filename + '</span><ul class="actions"><li><a href="#" class="delete"></a></li></ul></li>'
73 );
74 }
75 } );
76
77 delImage();
78
79 imageGalleryIds.val( attachmentIds );
80 } );
81
82 lpImageFrame.open();
83 } );
84
85 if ( isMultil ) {
86 listImages.sortable( {
87 items: 'li.image',
88 cursor: 'move',
89 scrollSensitivity: 40,
90 forcePlaceholderSize: true,
91 forceHelperSize: false,
92 helper: 'clone',
93 opacity: 0.65,
94 placeholder: 'lp-metabox-sortable-placeholder',
95 start( event, ui ) {
96 ui.item.css( 'background-color', '#f6f6f6' );
97 },
98 stop( event, ui ) {
99 ui.item.removeAttr( 'style' );
100 },
101 update() {
102 let attachmentIds = '';
103
104 listImages.find( 'li.image' ).css( 'cursor', 'default' ).each( function() {
105 const attachmentId = $( this ).attr( 'data-attachment_id' );
106 attachmentIds = attachmentIds + attachmentId + ',';
107 } );
108
109 delImage();
110
111 imageGalleryIds.val( attachmentIds );
112 },
113 } );
114 }
115
116 const delImage = () => {
117 $( listImages ).find( 'li.image' ).each( ( i, ele ) => {
118 const del = $( ele ).find( 'a.delete' );
119
120 del.on( 'click', function() {
121 $( ele ).remove();
122
123 if ( isMultil ) {
124 let attachmentIds = '';
125
126 $( listImages ).find( 'li.image' ).css( 'cursor', 'default' ).each( function() {
127 const attachmentId = $( this ).attr( 'data-attachment_id' );
128 attachmentIds = attachmentIds + attachmentId + ',';
129 } );
130
131 imageGalleryIds.val( attachmentIds );
132 } else {
133 imageGalleryIds.val( '' );
134 }
135
136 return false;
137 } );
138 } );
139 };
140
141 delImage();
142 } );
143 };
144
145 const onReady = function onReady() {
146 lpMetaboxFileInput();
147 //updateDb();
148 $( '.learn-press-dropdown-pages' ).LP( 'DropdownPages' );
149 //$( '.learn-press-advertisement-slider' ).LP( 'Advertisement', 'a', 's' ).appendTo( $( '#wpbody-content' ) );
150 //$( '.learn-press-toggle-item-preview' ).on( 'change', updateItemPreview );
151 $( '.learn-press-tip' ).LP( 'QuickTip' ); //$('.learn-press-tabs').LP('AdminTab');
152
153 $( document ).on( 'click', '#learn-press-create-pages', createPages )
154 //.on( 'click', '.lp-upgrade-notice .close-notice', hideUpgradeMessage )
155 //.on( 'click', '.plugin-action-buttons a', pluginActions )
156 //.on( 'click', '[data-remove-confirm]', preventDefault )
157 .on( 'mousedown', '.lp-sortable-handle', function( e ) {
158 $( 'html, body' ).addClass( 'lp-item-moving' );
159 $( e.target ).closest( '.lp-sortable-handle' ).css( 'cursor', 'inherit' );
160 } ).on( 'mouseup', function( e ) {
161 $( 'html, body' ).removeClass( 'lp-item-moving' );
162 $( '.lp-sortable-handle' ).css( 'cursor', '' );
163 } );
164
165 // Scroll to Passing grade when click link final Quiz in Course Setting.
166 if ( window.location.hash ) {
167 const hash = window.location.hash;
168
169 if ( hash === '#_lp_passing_grade' ) {
170 const ele = document.querySelector( hash );
171
172 $( 'html, body' ).animate( {
173 scrollTop: $( hash ).offset().top,
174 }, 900, 'swing' );
175
176 ele.parentNode.style.border = '2px solid orangered';
177 }
178 }
179
180 // Show/hide meta-box field with type checkbox
181 /*$( 'input' ).on( 'click', function( e ) {
182 const el = $( e.target );
183 if ( ! el.length ) {
184 return;
185 }
186
187 const id = el.attr( 'id' );
188 if ( ! id ) {
189 return;
190 }
191
192 const classHide = id.replace( 'learn_press_', '' );
193 const elHide = $( `.show_if_${ classHide }` );
194
195 if ( el.is( ':checked' ) ) {
196 elHide.show();
197 } else {
198 elHide.hide();
199 }
200 } );*/
201 };
202
203 $( document ).ready( onReady );
204 }( jQuery ) );
205
206 const showHideOptionsDependency = ( e, target ) => {
207 if ( target.tagName === 'INPUT' ) {
208 if ( target.closest( '.forminp ' ) ) {
209 const nameInput = target.name;
210 const classDependency = nameInput.replace( 'learn_press_', '' );
211
212 const elClassDependency = document.querySelectorAll( `.show_if_${ classDependency }` );
213 if ( elClassDependency ) {
214 elClassDependency.forEach( ( el ) => {
215 el.classList.toggle( 'lp-option-disabled' );
216 } );
217 }
218 } else if ( target.closest( '.lp-meta-box' ) ) {
219 const elLPMetaBox = target.closest( '.lp-meta-box' );
220 const nameInput = target.name;
221
222 const elClassDependency = elLPMetaBox.querySelectorAll( `[data-dependency="${ nameInput }"]` );
223 if ( elClassDependency ) {
224 elClassDependency.forEach( ( el ) => {
225 el.classList.toggle( 'lp-option-disabled' );
226 } );
227 }
228 }
229 }
230 };
231
232 // Events
233 document.addEventListener( 'click', ( e ) => {
234 const target = e.target;
235 showHideOptionsDependency( e, target );
236 // For case click add on Widgets of WordPress.
237 initElsTomSelect();
238 } );
239
240 document.addEventListener( 'DOMContentLoaded', () => {
241 searchUserOnListPost();
242 // Sure that the TomSelect is loaded if listen can't find elements.
243 initElsTomSelect();
244 } );
245
246 // Listen element select created on DOM.
247 Utils.lpOnElementReady( 'select.lp-tom-select', ( e ) => {
248 initElsTomSelect();
249 } );
250
251 Utils.lpOnElementReady( '#posts-filter', ( e ) => {
252 searchUserOnListPost();
253 } );
254
255 window.lpFindTomSelect = initElsTomSelect;
256