| 1 |
( 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 |
/** |
| 18 |
* Callback event for button to creating pages inside error message. |
| 19 |
* |
| 20 |
* @param {Event} e |
| 21 |
*/ |
| 22 |
|
| 23 |
const createPages = function createPages( e ) { |
| 24 |
const $button = $( this ).addClass( 'disabled' ); |
| 25 |
e.preventDefault(); |
| 26 |
$.post( { |
| 27 |
url: $button.attr( 'href' ), |
| 28 |
data: { |
| 29 |
'lp-ajax': 'create-pages', |
| 30 |
}, |
| 31 |
dataType: 'text', |
| 32 |
success: function success( res ) { |
| 33 |
const $message = $button.closest( '.lp-notice' ).html( '<p>' + res + '</p>' ); |
| 34 |
setTimeout( function() { |
| 35 |
$message.fadeOut(); |
| 36 |
}, 2000 ); |
| 37 |
}, |
| 38 |
} ); |
| 39 |
}; |
| 40 |
|
| 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 |
const lpMetaboxFileInput = () => { |
| 173 |
$( '.lp-meta-box__file' ).each( ( i, element ) => { |
| 174 |
let lpImageFrame; |
| 175 |
|
| 176 |
const imageGalleryIds = $( element ).find( '.lp-meta-box__file_input' ); |
| 177 |
const listImages = $( element ).find( '.lp-meta-box__file_list' ); |
| 178 |
const btnUpload = $( element ).find( '.btn-upload' ); |
| 179 |
const isMultil = !! $( element ).data( 'multil' ); |
| 180 |
|
| 181 |
$( btnUpload ).on( 'click', ( event ) => { |
| 182 |
event.preventDefault(); |
| 183 |
|
| 184 |
if ( lpImageFrame ) { |
| 185 |
lpImageFrame.open(); |
| 186 |
return; |
| 187 |
} |
| 188 |
|
| 189 |
lpImageFrame = wp.media( { |
| 190 |
states: [ |
| 191 |
new wp.media.controller.Library( { |
| 192 |
filterable: 'all', |
| 193 |
multiple: isMultil, |
| 194 |
} ), |
| 195 |
], |
| 196 |
} ); |
| 197 |
|
| 198 |
lpImageFrame.on( 'select', function() { |
| 199 |
const selection = lpImageFrame.state().get( 'selection' ); |
| 200 |
let attachmentIds = imageGalleryIds.val(); |
| 201 |
|
| 202 |
selection.forEach( function( attachment ) { |
| 203 |
attachment = attachment.toJSON(); |
| 204 |
|
| 205 |
if ( attachment.id ) { |
| 206 |
if ( ! isMultil ) { |
| 207 |
attachmentIds = attachment.id; |
| 208 |
listImages.empty(); |
| 209 |
} else { |
| 210 |
attachmentIds = attachmentIds ? attachmentIds + ',' + attachment.id : attachment.id; |
| 211 |
} |
| 212 |
|
| 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 |
} |
| 226 |
} |
| 227 |
} ); |
| 228 |
|
| 229 |
delImage(); |
| 230 |
|
| 231 |
imageGalleryIds.val( attachmentIds ); |
| 232 |
} ); |
| 233 |
|
| 234 |
lpImageFrame.open(); |
| 235 |
} ); |
| 236 |
|
| 237 |
if ( isMultil ) { |
| 238 |
listImages.sortable( { |
| 239 |
items: 'li.image', |
| 240 |
cursor: 'move', |
| 241 |
scrollSensitivity: 40, |
| 242 |
forcePlaceholderSize: true, |
| 243 |
forceHelperSize: false, |
| 244 |
helper: 'clone', |
| 245 |
opacity: 0.65, |
| 246 |
placeholder: 'lp-metabox-sortable-placeholder', |
| 247 |
start( event, ui ) { |
| 248 |
ui.item.css( 'background-color', '#f6f6f6' ); |
| 249 |
}, |
| 250 |
stop( event, ui ) { |
| 251 |
ui.item.removeAttr( 'style' ); |
| 252 |
}, |
| 253 |
update() { |
| 254 |
let attachmentIds = ''; |
| 255 |
|
| 256 |
listImages.find( 'li.image' ).css( 'cursor', 'default' ).each( function() { |
| 257 |
const attachmentId = $( this ).attr( 'data-attachment_id' ); |
| 258 |
attachmentIds = attachmentIds + attachmentId + ','; |
| 259 |
} ); |
| 260 |
|
| 261 |
delImage(); |
| 262 |
|
| 263 |
imageGalleryIds.val( attachmentIds ); |
| 264 |
}, |
| 265 |
} ); |
| 266 |
} |
| 267 |
|
| 268 |
const delImage = () => { |
| 269 |
$( listImages ).find( 'li.image' ).each( ( i, ele ) => { |
| 270 |
const del = $( ele ).find( 'a.delete' ); |
| 271 |
|
| 272 |
del.on( 'click', function() { |
| 273 |
$( ele ).remove(); |
| 274 |
|
| 275 |
if ( isMultil ) { |
| 276 |
let attachmentIds = ''; |
| 277 |
|
| 278 |
$( listImages ).find( 'li.image' ).css( 'cursor', 'default' ).each( function() { |
| 279 |
const attachmentId = $( this ).attr( 'data-attachment_id' ); |
| 280 |
attachmentIds = attachmentIds + attachmentId + ','; |
| 281 |
} ); |
| 282 |
|
| 283 |
imageGalleryIds.val( attachmentIds ); |
| 284 |
} else { |
| 285 |
imageGalleryIds.val( '' ); |
| 286 |
} |
| 287 |
|
| 288 |
return false; |
| 289 |
} ); |
| 290 |
} ); |
| 291 |
}; |
| 292 |
|
| 293 |
delImage(); |
| 294 |
} ); |
| 295 |
}; |
| 296 |
|
| 297 |
const onReady = function onReady() { |
| 298 |
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 ); |
| 303 |
$( '.learn-press-tip' ).LP( 'QuickTip' ); //$('.learn-press-tabs').LP('AdminTab'); |
| 304 |
|
| 305 |
$( 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 ) |
| 309 |
.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 |
} ); |
| 480 |
} ); |
| 481 |
} |
| 482 |
|
| 483 |
$.fn._filter_post_by_author(); |
| 484 |
|
| 485 |
// Scroll to Passing grade when click link final Quiz in Course Setting. |
| 486 |
if ( window.location.hash ) { |
| 487 |
const hash = window.location.hash; |
| 488 |
|
| 489 |
if ( hash == '#_lp_passing_grade' ) { |
| 490 |
const ele = document.querySelector( hash ); |
| 491 |
|
| 492 |
$( 'html, body' ).animate( { |
| 493 |
scrollTop: $( hash ).offset().top, |
| 494 |
}, 900, 'swing' ); |
| 495 |
|
| 496 |
ele.parentNode.style.border = '2px solid orangered'; |
| 497 |
} |
| 498 |
} |
| 499 |
|
| 500 |
// Show/hide meta-box field with type checkbox |
| 501 |
$( 'input' ).on( 'click', function( e ) { |
| 502 |
const el = $( e.target ); |
| 503 |
if ( ! el.length ) { |
| 504 |
return; |
| 505 |
} |
| 506 |
|
| 507 |
const id = el.attr( 'id' ); |
| 508 |
if ( ! id ) { |
| 509 |
return; |
| 510 |
} |
| 511 |
|
| 512 |
const classHide = id.replace( 'learn_press_', '' ); |
| 513 |
const elHide = $( `.show_if_${ classHide }` ); |
| 514 |
|
| 515 |
if ( el.is( ':checked' ) ) { |
| 516 |
elHide.show(); |
| 517 |
} else { |
| 518 |
elHide.hide(); |
| 519 |
} |
| 520 |
} ); |
| 521 |
}; |
| 522 |
|
| 523 |
$( document ).ready( onReady ); |
| 524 |
}( jQuery ) ); |
| 525 |
|