PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
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
← All changes | assets/src/js/admin/admin.js +86 -345 4.1.7.14.4.8 View file →
@@ -1,20 +1,9 @@
1 +import { initElsTomSelect, searchUserOnListPost } from './init-tom-select.js';
2 +import { AdminUtilsFunctions, Api, Utils } from './utils-admin.js';
3 +import { DropdownPages } from './share/dropdown-pages.js';
4 +
1 5 ( function( $ ) {
2 - const updateItemPreview = function updateItemPreview() {
3 - $.ajax( {
4 - url: '',
5 - data: {
6 - 'lp-ajax': 'toggle_item_preview',
7 - item_id: this.value,
8 - previewable: this.checked ? 'yes' : 'no',
9 - nonce: $( this ).attr( 'data-nonce' ),
10 - },
11 - dataType: 'text',
12 - success: function success( response ) {
13 - response = LP.parseJSON( response );
14 - },
15 - } );
16 - };
17 6 /**
18 7 * Callback event for button to creating pages inside error message.
19 8 *
20 9 * @param {Event} e
@@ -37,139 +26,8 @@
37 26 },
38 27 } );
39 28 };
40 29
41 - const hideUpgradeMessage = function hideUpgradeMessage( e ) {
42 - e.preventDefault();
43 - const $btn = $( this );
44 - $btn.closest( '.lp-upgrade-notice' ).fadeOut();
45 - $.post( {
46 - url: '',
47 - data: {
48 - 'lp-hide-upgrade-message': 'yes',
49 - },
50 - success: function success( res ) {},
51 - } );
52 - };
53 -
54 - const pluginActions = function pluginActions( e ) {
55 - // Premium addon
56 - if ( $( e.target ).hasClass( 'buy-now' ) ) {
57 - return;
58 - }
59 -
60 - e.preventDefault();
61 - const $plugin = $( this ).closest( '.plugin-card' );
62 -
63 - if ( $( this ).hasClass( 'updating-message' ) ) {
64 - return;
65 - }
66 -
67 - $( this ).addClass( 'updating-message button-working disabled' );
68 - $.ajax( {
69 - url: $( this ).attr( 'href' ),
70 - data: {},
71 - success: function success( r ) {
72 - $.ajax( {
73 - url: window.location.href,
74 - success: function success( r ) {
75 - const $p = $( r ).find( '#' + $plugin.attr( 'id' ) );
76 -
77 - if ( $p.length ) {
78 - $plugin.replaceWith( $p );
79 - } else {
80 - $plugin.find( '.plugin-action-buttons a' ).removeClass( 'updating-message button-working' ).html( learn_press_admin_localize.plugin_installed );
81 - }
82 - },
83 - } );
84 - },
85 - } );
86 - };
87 -
88 - const preventDefault = function preventDefault( e ) {
89 - e.preventDefault();
90 - return false;
91 - };
92 -
93 - $.fn._filter_post_by_author = function() {
94 - const $input = $( '#post-search-input' );
95 -
96 - if ( ! $input.length ) {
97 - return;
98 - }
99 -
100 - const $form = $( $input[ 0 ].form );
101 - const $select = $( '<select name="author" id="author"></select>' ).insertAfter( $input ).select2( {
102 - ajax: {
103 - url: window.location.href + '&lp-ajax=search-authors',
104 - dataType: 'json',
105 - s: '',
106 - },
107 - placeholder: wp.i18n.__( 'Search by user', 'learnpress' ),
108 - minimumInputLength: 3,
109 - allowClear: true,
110 - } ).on( 'select2:select', function() {
111 - $( 'input[name="author"]' ).val( $select.val() );
112 - } );
113 -
114 - $form.on( 'submit', function() {
115 - const url = window.location.href.removeQueryVar( 'author' ).addQueryVar( 'author', $select.val() );
116 - } );
117 - };
118 -
119 - const updateDb = () => {
120 - $( '.lp-button-upgrade' ).each( function() {
121 - $( this ).on( 'click', function( e ) {
122 - e.preventDefault();
123 -
124 - $( '#lp-update-db-modal' ).removeClass( 'lp-update-db-modal__hidden' );
125 - } );
126 - } );
127 -
128 - $( '.lp-update-db-modal__button' ).on( 'click', function( e ) {
129 - e.preventDefault();
130 -
131 - const $button = $( this );
132 - const btnText = $button.text();
133 - const btxUpdating = $button.data( 'loading' );
134 -
135 - const textSuccess = $( '.lp-update-db-modal__content-text' ).data( 'text' );
136 -
137 - $button.addClass( 'loading' );
138 - $button.text( btxUpdating );
139 -
140 - const updateRequest = () => {
141 - $.ajax( {
142 - url: lpGlobalSettings.ajax + '?action=lp_update_database',
143 - method: 'GET',
144 - success( response ) {
145 - if ( response.status === 'success' ) {
146 - $button.text( btnText );
147 -
148 - $( '.lp-update-db-modal__content' ).addClass( 'lp-update-db-modal__success' );
149 - $( '.lp-update-db-modal__content-text > h3' ).text( textSuccess );
150 -
151 - $button.removeClass( 'loading' );
152 - return false;
153 - }
154 - updateRequest();
155 - },
156 - } );
157 - };
158 -
159 - updateRequest();
160 - } );
161 -
162 - const lpUpdateModal = () => {
163 - $( '.lp-update-db-modal__cancel' ).on( 'click', function( e ) {
164 - e.preventDefault();
165 - $( '#lp-update-db-modal' ).addClass( 'lp-update-db-modal__hidden' );
166 - } );
167 - };
168 -
169 - lpUpdateModal();
170 - };
171 -
172 30 const lpMetaboxFileInput = () => {
173 31 $( '.lp-meta-box__file' ).each( ( i, element ) => {
174 32 let lpImageFrame;
175 33
@@ -209,21 +67,12 @@
209 67 } else {
210 68 attachmentIds = attachmentIds ? attachmentIds + ',' + attachment.id : attachment.id;
211 69 }
212 70
213 - if ( attachment.type === 'image' ) {
214 - const attachmentImage = attachment.sizes && attachment.sizes.thumbnail ? attachment.sizes.thumbnail.url : attachment.url;
215 -
216 - listImages.append(
217 - '<li class="lp-meta-box__file_list-item image" data-attachment_id="' + attachment.id + '"><img src="' + attachmentImage +
218 - '" /><ul class="actions"><li><a href="#" class="delete"></a></li></ul></li>'
219 - );
220 - } else {
221 - listImages.append(
222 - '<li class="lp-meta-box__file_list-item image" data-attachment_id="' + attachment.id + '"><img class="is_file" src="' + attachment.icon +
223 - '" /><span>' + attachment.filename + '</span><ul class="actions"><li><a href="#" class="delete"></a></li></ul></li>'
224 - );
225 - }
71 + listImages.append(
72 + '<li class="lp-meta-box__file_list-item image" data-attachment_id="' + attachment.id + '"><img class="is_file" src="' + attachment.icon +
73 + '" /><span>' + attachment.filename + '</span><ul class="actions"><li><a href="#" class="delete"></a></li></ul></li>'
74 + );
226 75 }
227 76 } );
228 77
229 78 delImage();
@@ -295,199 +144,32 @@
295 144 };
296 145
297 146 const onReady = function onReady() {
298 147 lpMetaboxFileInput();
299 - updateDb();
300 - $( '.learn-press-dropdown-pages' ).LP( 'DropdownPages' );
301 - $( '.learn-press-advertisement-slider' ).LP( 'Advertisement', 'a', 's' ).appendTo( $( '#wpbody-content' ) );
302 - $( '.learn-press-toggle-item-preview' ).on( 'change', updateItemPreview );
148 + //updateDb();
149 + const dropdownPages = new DropdownPages();
150 + dropdownPages.init();
151 + //$( '.learn-press-advertisement-slider' ).LP( 'Advertisement', 'a', 's' ).appendTo( $( '#wpbody-content' ) );
152 + //$( '.learn-press-toggle-item-preview' ).on( 'change', updateItemPreview );
303 153 $( '.learn-press-tip' ).LP( 'QuickTip' ); //$('.learn-press-tabs').LP('AdminTab');
304 154
305 155 $( document ).on( 'click', '#learn-press-create-pages', createPages )
306 - .on( 'click', '.lp-upgrade-notice .close-notice', hideUpgradeMessage )
307 - .on( 'click', '.plugin-action-buttons a', pluginActions )
308 - .on( 'click', '[data-remove-confirm]', preventDefault )
156 + //.on( 'click', '.lp-upgrade-notice .close-notice', hideUpgradeMessage )
157 + //.on( 'click', '.plugin-action-buttons a', pluginActions )
158 + //.on( 'click', '[data-remove-confirm]', preventDefault )
309 159 .on( 'mousedown', '.lp-sortable-handle', function( e ) {
310 - $( 'html, body' ).addClass( 'lp-item-moving' );
311 - $( e.target ).closest( '.lp-sortable-handle' ).css( 'cursor', 'inherit' );
312 - } ).on( 'mouseup', function( e ) {
313 - $( 'html, body' ).removeClass( 'lp-item-moving' );
314 - $( '.lp-sortable-handle' ).css( 'cursor', '' );
315 - } );
316 -
317 - /**
318 - * Function Export invoice LP Order
319 - *
320 - * @author hungkv
321 - * @since 3.2.7.8
322 - */
323 - if ( $( '#order-export__section' ).length ) {
324 - const tabs = document.querySelectorAll( '.tabs' );
325 - const tab = document.querySelectorAll( '.tab' );
326 - const panel = document.querySelectorAll( '.panel' );
327 -
328 - function onTabClick( event ) {
329 - // deactivate existing active tabs and panel
330 -
331 - for ( let i = 0; i < tab.length; i++ ) {
332 - tab[ i ].classList.remove( 'active' );
333 - }
334 -
335 - for ( let i = 0; i < panel.length; i++ ) {
336 - panel[ i ].classList.remove( 'active' );
337 - }
338 -
339 - // activate new tabs and panel
340 - event.target.classList.add( 'active' );
341 - const classString = event.target.getAttribute( 'data-target' );
342 - document.getElementById( 'panels' ).getElementsByClassName( classString )[ 0 ].classList.add( 'active' );
343 - }
344 -
345 - for ( let i = 0; i < tab.length; i++ ) {
346 - tab[ i ].addEventListener( 'click', onTabClick, false );
347 - }
348 -
349 - // modal export order to pdf
350 -
351 - // Get the modal
352 - const modal = document.getElementById( 'myModal' );
353 -
354 - // Get the button that opens the modal
355 - const btn = document.getElementById( 'order-export__button' );
356 -
357 - // Get the <span> element that closes the modal
358 - const span = document.getElementsByClassName( 'close' )[ 0 ];
359 -
360 - // When the user clicks on the button, open the modal
361 - btn.onclick = function() {
362 - modal.style.display = 'block';
363 - };
364 -
365 - // When the user clicks on <span> (x), close the modal
366 - span.onclick = function() {
367 - modal.style.display = 'none';
368 - };
369 -
370 - // When the user clicks anywhere outside of the modal, close it
371 - window.onclick = function( event ) {
372 - if ( event.target == modal ) {
373 - modal.style.display = 'none';
374 - }
375 - };
376 -
377 - if ( $( '#lp-invoice__content' ).length ) {
378 - $( '#lp-invoice__export' ).click( function() {
379 - const doc = new jsPDF( 'p', 'pt', 'letter' );
380 -
381 - // We'll make our own renderer to skip this editor
382 - const specialElementHandlers = {
383 - '#bypassme'( element, renderer ) {
384 - return true;
385 - },
386 - };
387 - const margins = {
388 - top: 80,
389 - bottom: 60,
390 - left: 40,
391 - width: 522,
392 - };
393 -
394 - doc.fromHTML(
395 - $( '#lp-invoice__content' )[ 0 ],
396 - margins.left, // x coord
397 - margins.top, { // y coord
398 - width: margins.width, // max width of content on PDF
399 - elementHandlers: specialElementHandlers,
400 - },
401 - function( dispose ) {
402 - // dispose: object with X, Y of the last line add to the PDF
403 - // this allow the insertion of new lines after html
404 - const blob = doc.output( 'blob' );
405 - window.open( URL.createObjectURL( blob ) );
406 - }, margins );
407 - } );
408 - }
409 -
410 - // Script update option export to pdf
411 - $( '#lp-invoice__update' ).click( function() {
412 - let order_id = $( this ).data( 'id' ),
413 - site_title = $( 'input[name="site_title"]' ),
414 - order_date = $( 'input[name="order_date"]' ),
415 - invoice_no = $( 'input[name="invoice_no"]' ),
416 - order_customer = $( 'input[name="order_customer"]' ),
417 - order_email = $( 'input[name="order_email"]' ),
418 - order_payment = $( 'input[name="order_payment"]' );
419 - if ( site_title.is( ':checked' ) ) {
420 - site_title = 'check';
421 - } else {
422 - site_title = 'uncheck';
423 - }
424 - if ( order_date.is( ':checked' ) ) {
425 - order_date = 'check';
426 - } else {
427 - order_date = 'uncheck';
428 - }
429 - if ( invoice_no.is( ':checked' ) ) {
430 - invoice_no = 'check';
431 - } else {
432 - invoice_no = 'uncheck';
433 - }
434 - if ( order_customer.is( ':checked' ) ) {
435 - order_customer = 'check';
436 - } else {
437 - order_customer = 'uncheck';
438 - }
439 - if ( order_email.is( ':checked' ) ) {
440 - order_email = 'check';
441 - } else {
442 - order_email = 'uncheck';
443 - }
444 - if ( order_payment.is( ':checked' ) ) {
445 - order_payment = 'check';
446 - } else {
447 - order_payment = 'uncheck';
448 - }
449 -
450 - $.ajax( {
451 - type: 'post',
452 - dataType: 'html',
453 - url: 'admin-ajax.php',
454 - data: {
455 - site_title,
456 - order_date,
457 - invoice_no,
458 - order_customer,
459 - order_email,
460 - order_id,
461 - order_payment,
462 - action: 'learnpress_update_order_exports',
463 - },
464 - beforeSend() {
465 - $( '.export-options__loading' ).addClass( 'active' );
466 - },
467 - success( response ) {
468 - $( '#lp-invoice__content' ).html( '' );
469 - $( '#lp-invoice__content' ).append( response );
470 - $( '.export-options__loading' ).removeClass( 'active' );
471 - $( '.options-tab' ).removeClass( 'active' );
472 - $( '.preview-tab' ).addClass( 'active' );
473 - $( '#panels .export-options' ).removeClass( 'active' );
474 - $( '#panels .pdf-preview' ).addClass( 'active' );
475 - },
476 - error( jqXHR, textStatus, errorThrown ) {
477 - console.log( 'The following error occured: ' + textStatus, errorThrown );
478 - },
479 - } );
160 + $( 'html, body' ).addClass( 'lp-item-moving' );
161 + $( e.target ).closest( '.lp-sortable-handle' ).css( 'cursor', 'inherit' );
162 + } ).on( 'mouseup', function( e ) {
163 + $( 'html, body' ).removeClass( 'lp-item-moving' );
164 + $( '.lp-sortable-handle' ).css( 'cursor', '' );
480 165 } );
481 - }
482 166
483 - $.fn._filter_post_by_author();
484 -
485 167 // Scroll to Passing grade when click link final Quiz in Course Setting.
486 168 if ( window.location.hash ) {
487 169 const hash = window.location.hash;
488 170
489 - if ( hash == '#_lp_passing_grade' ) {
171 + if ( hash === '#_lp_passing_grade' ) {
490 172 const ele = document.querySelector( hash );
491 173
492 174 $( 'html, body' ).animate( {
493 175 scrollTop: $( hash ).offset().top,
@@ -497,20 +179,79 @@
497 179 }
498 180 }
499 181
500 182 // Show/hide meta-box field with type checkbox
501 - $( 'input' ).on( 'click' , function ( e ) {
183 + /*$( 'input' ).on( 'click', function( e ) {
502 184 const el = $( e.target );
185 + if ( ! el.length ) {
186 + return;
187 + }
188 +
503 189 const id = el.attr( 'id' );
504 - const classHide = id.replace('learn_press_', '');
505 - const elHide = $(`.show_if_${classHide}`);
190 + if ( ! id ) {
191 + return;
192 + }
506 193
507 - if ( el.is(':checked') ) {
194 + const classHide = id.replace( 'learn_press_', '' );
195 + const elHide = $( `.show_if_${ classHide }` );
196 +
197 + if ( el.is( ':checked' ) ) {
508 198 elHide.show();
509 199 } else {
510 200 elHide.hide();
511 201 }
512 - });
202 + } );*/
513 203 };
514 204
515 205 $( document ).ready( onReady );
516 206 }( jQuery ) );
207 +
208 +const showHideOptionsDependency = ( e, target ) => {
209 + if ( target.tagName === 'INPUT' ) {
210 + if ( target.closest( '.forminp ' ) ) {
211 + const nameInput = target.name;
212 + const classDependency = nameInput.replace( 'learn_press_', '' );
213 +
214 + const elClassDependency = document.querySelectorAll( `.show_if_${ classDependency }` );
215 + if ( elClassDependency ) {
216 + elClassDependency.forEach( ( el ) => {
217 + el.classList.toggle( 'lp-option-disabled' );
218 + } );
219 + }
220 + } else if ( target.closest( '.lp-meta-box' ) ) {
221 + const elLPMetaBox = target.closest( '.lp-meta-box' );
222 + const nameInput = target.name;
223 +
224 + const elClassDependency = elLPMetaBox.querySelectorAll( `[data-dependency="${ nameInput }"]` );
225 + if ( elClassDependency ) {
226 + elClassDependency.forEach( ( el ) => {
227 + el.classList.toggle( 'lp-option-disabled' );
228 + } );
229 + }
230 + }
231 + }
232 +};
233 +
234 +// Events
235 +document.addEventListener( 'click', ( e ) => {
236 + const target = e.target;
237 + showHideOptionsDependency( e, target );
238 + // For case click add on Widgets of WordPress.
239 + initElsTomSelect();
240 +} );
241 +
242 +document.addEventListener( 'DOMContentLoaded', () => {
243 + searchUserOnListPost();
244 + // Sure that the TomSelect is loaded if listen can't find elements.
245 + initElsTomSelect();
246 +} );
247 +
248 +// Listen element select created on DOM.
249 +Utils.lpOnElementReady( 'select.lp-tom-select', ( e ) => {
250 + initElsTomSelect();
251 +} );
252 +
253 +Utils.lpOnElementReady( '#posts-filter', ( e ) => {
254 + searchUserOnListPost();
255 +} );
256 +
257 +window.lpFindTomSelect = initElsTomSelect;