1(function($){ 2 "use strict"; 3 4 var gdlr_lms_debounce = function(func, threshold, execAsap){ 5 6 var timeout; 7 8 return function debounced(){ 9 10 var obj = this, args = arguments; 11 12 function delayed(){ 13 if( !execAsap ){ 14 func.apply(obj, args); 15 } 16 timeout = null; 17 }; 18 19 if( timeout ){ 20 clearTimeout(timeout); 21 }else if( execAsap ){ 22 func.apply(obj, args); 23 } 24 timeout = setTimeout(delayed, threshold); 25 }; 26 } 27 28 // responsive video 29 $.fn.gdlr_lms_fluid_video = function(){ 30 $(this).find('iframe[src^="http://www.youtube.com"], iframe[src^="https://www.youtube.com"], iframe[src^="//www.youtube.com"],' + 31 'iframe[src^="http://player.vimeo.com"], iframe[src^="https://player.vimeo.com"], iframe[src^="//player.vimeo.com"]').each(function(){ 32 if( ($(this).is('embed') && $(this).parent('object').length) || $(this).parent('.fluid-width-video-wrapper').length ){ return; } 33 if( !$(this).attr('id') ){ $(this).attr('id', 'gdlr-video-' + Math.floor(Math.random()*999999)); } 34 35 // ignore if inside layerslider 36 if( $(this).closest('.ls-container').length <= 0 ){ 37 var ratio = $(this).height() / $(this).width(); 38 $(this).removeAttr('height').removeAttr('width');
39 $(this).wrap('<div class="gdlr-fluid-video-wrapper"></div>').parent().css('padding-top', (ratio * 100)+"%"); 40 } 41 42 }); 43 44 $(window).trigger('resize'); 45 } 46 47 // create the alert message 48 function gdlr_lms_confirm(options){ 49 var settings = $.extend({ 50 text: 'Are you sure you want to do this ?', 51 sub: '', 52 yes: 'Yes', 53 no: 'No', 54 success: function(){} 55 }, options); 56 57 var confirm_button = $('<a class="gdlr-lms-button blue">' + settings.yes + '</a>'); 58 var decline_button = $('<a class="gdlr-lms-button red">' + settings.no + '</a>'); 59 var confirm_box = $('<div class="gdlr-lms-confirm-wrapper"></div>'); 60 var confirm_overlay = $('<div class="gdlr-lms-confirm-overlay"></div>'); 61 62 confirm_box.append('<span class="head">' + settings.text + '</span>'); 63 if( settings.sub != '' ){ 64 confirm_box.append('<span class="sub">' + settings.sub + '</span>'); 65 } 66 confirm_box.append(confirm_button); 67 confirm_box.append(decline_button); 68 69 $('body').append(confirm_overlay).append(confirm_box); 70 71 // center the alert box position 72 confirm_box.css({ 'margin-left': -(confirm_box.outerWidth() / 2), 'margin-top': -(confirm_box.outerHeight() / 2)}); 73 74 // animate the alert box 75 confirm_box.animate({opacity:1},{duration: 200}); 76 confirm_overlay.animate({opacity:0.75},{duration: 150}); 77 78 confirm_button.on('click', function(){
79 if(typeof(settings.success) == 'function'){ settings.success(); } 80 confirm_box.fadeOut(200, function(){ $(this).remove(); }); 81 confirm_overlay.fadeOut(200, function(){ $(this).remove(); }); 82 }); 83 decline_button.on('click', function(){ 84 confirm_box.fadeOut(200, function(){ $(this).remove(); }); 85 confirm_overlay.fadeOut(200, function(){ $(this).remove(); }); 86 }); 87 } 88 function gdlr_lms_notice(options){ 89 var settings = $.extend({ 90 text: 'Please try again', 91 sub: '', 92 ok: 'Ok', 93 success: function(){} 94 }, options); 95 96 var confirm_button = $('<a class="gdlr-lms-button blue">' + settings.ok + '</a>'); 97 var confirm_box = $('<div class="gdlr-lms-confirm-wrapper"></div>'); 98 var confirm_overlay = $('<div class="gdlr-lms-confirm-overlay"></div>'); 99 100 confirm_box.append('<span class="head">' + settings.text + '</span>'); 101 if( settings.sub != '' ){ 102 confirm_box.append('<span class="sub">' + settings.sub + '</span>'); 103 } 104 confirm_box.append(confirm_button); 105 $('body').append(confirm_overlay).append(confirm_box); 106 107 // center the alert box position 108 confirm_box.css({ 'margin-left': -(confirm_box.outerWidth() / 2), 'margin-top': -(confirm_box.outerHeight() / 2)}); 109 110 // animate the alert box 111 confirm_box.animate({opacity:1},{duration: 200}); 112 confirm_overlay.animate({opacity:0.75},{duration: 150}); 113 114 confirm_button.on('click', function(){
115 if(typeof(settings.success) == 'function'){ settings.success(); } 116 confirm_box.fadeOut(200, function(){ $(this).remove(); }); 117 confirm_overlay.fadeOut(200, function(){ $(this).remove(); }); 118 }); 119 } 120 121 function gdlr_lms_lightbox(content, allow_close){ 122 var lightbox = $('<div class="gdlr-lms-lightbox-wrapper"></div>').appendTo('body'); 123 var overlay = $('<div class="gdlr-lms-lightbox-overlay" ></div>'); 124 125 var content_return = ''; 126 if( content.attr('data-return') == 'parent' ){ 127 content_return = content.parent(); 128 } 129 130 // close lightbox 131 if( allow_close ){ 132 overlay.on('click', function(){ 133 lightbox.fadeOut(200, function(){ 134 if( content_return ){ 135 content_return.append($(this).find('.gdlr-lms-lightbox-container')); 136 } 137 $(this).remove(); 138 }); 139 }); 140 141 content.find('.gdlr-lms-lightbox-close').on('click', function(){ 142 lightbox.fadeOut(200, function(){ 143 if( content_return ){ 144 content_return.append($(this).find('.gdlr-lms-lightbox-container')); 145 } 146 $(this).remove(); 147 }); 148 }); 149 } 150 151 152 153 content.find('.gdlr-lms-lightbox-printer').on('click', function(){ 154 var printContents = $($(this).siblings('.gdlr-printable').html()); 155 $('body').children('div, img, section').css('display', 'none'); 156 $('body').append(printContents); 157 $('html, body').css('background-color', '#fff'); 158 window.print(); 159 printContents.remove(); 160 $('html, body').css('background-color', ''); 161 $('body').children('div, img, section').css('display', 'block'); 162 }); 163 164 lightbox.append(overlay).append(content); 165 lightbox.fadeIn(200); 166 167 lightbox.gdlr_lms_fluid_video(); 168 169 // set height for certificate 170 if( content.children().is('.certificate-form-printable') ){ 171 content.css('margin-top', -content.height()/2); 172 } 173 } 174 175 function gdlr_lms_format_time(second){ 176 var hrs = parseInt(second / 3600); 177 second = second % 3600; 178 179 var mins = parseInt(second / 60); 180 mins = (mins < 10)? '0' + mins: mins; 181 182 second = second % 60; 183 second = (second < 10)? '0' + second: second; 184 185 return hrs + ':' + mins + ':' + second; 186 } 187 188 $(document).ready(function(){ 189 190 // date picker 191 $('input.gdlr-lms-date-picker').datepicker({ 192 dateFormat : 'yy-mm-dd' 193 }); 194 195 // rating 196 $('.rating-form .gdlr-rating-input').each(function(){ 197 $(this).children().on('mouseover', function(){ 198 $(this).parent().siblings('.rating-input').val($(this).attr("data-value")); 199 200 if($(this).is('i')){ $(this).removeClass().addClass('icon-star-half-empty fa fa-star-half-empty'); } 201 $(this).prevAll('i').removeClass().addClass('icon-star fa fa-star'); 202 $(this).nextAll('i').removeClass().addClass('icon-star-empty fa fa-star-o'); 203 }); 204 }); 205 206 // upload admin author image 207 $('#gdlr-admin-author-image').change(function(){ 208 $(this).parents('form').submit(); 209 }) 210 $('.gdlr-page-profile .gdlr-lms-admin-head-thumbnail').on('click', function(){ 211 $('#gdlr-admin-author-image').trigger('click'); 212 }); 213 214 // cancel booking 215 $('.gdlr-lms-cancel-booking, .gdlr-lms-delete-student').on('click', function(){ 216 var cancel_button = $(this); 217 var action = 'gdlr_lms_cancel_booking'; 218 if( $(this).is('.gdlr-lms-delete-student') ){ 219 action = 'gdlr_lms_delete_student'; 220 } 221 222 gdlr_lms_confirm({ 223 text: cancel_button.attr('data-title'), 224 yes: cancel_button.attr('data-yes'), 225 no: cancel_button.attr('data-no'), 226 success: function(){ 227 $.ajax({
228 type: 'POST', 229 url: cancel_button.attr('data-ajax'), 230 data: {'action':action,'id': cancel_button.attr('data-id')}, 231 dataType: 'json', 232 error: function(a, b, c){ console.log(a, b, c); }, 233 success: function(data){ 234 location.reload(); 235 } 236 }); 237 } 238 }); 239 240 return false; 241 }); 242 243 // view quiz answer 244 $('.gdlr-lms-view-correct-answer').on('click', function(){ 245 var view_button = $(this); 246 gdlr_lms_confirm({ 247 text: view_button.attr('data-title'), 248 sub: view_button.attr('data-sub-title'), 249 yes: view_button.attr('data-yes'), 250 no: view_button.attr('data-no'), 251 success: function(){ 252 location.href = view_button.attr('href'); 253 } 254 }); 255 256 return false; 257 }); 258 259 // equally set course style-2 height 260 $(window).resize(function(){ 261 $('.gdlr-lms-course-grid2-wrapper').each(function(){ 262 var max_height = 0; 263 var child_elements = $(this).find('.gdlr-lms-item'); 264 265 child_elements.css('height', 'auto'); 266 if($(window).width() <= '767') return; 267 268 child_elements.each(function(){ 269 if($(this).height() > max_height) max_height = $(this).height(); 270 }); 271 child_elements.height(max_height); 272 }); 273 }); 274 275 // init the lightbox 276 $('[data-rel="gdlr-lms-lightbox"]').on('click', function(){ 277 var content = $(this).siblings('.' + $(this).attr('data-lb-open')); 278 if( !content.attr('data-return') ){ 279 var content = $(this).siblings('.' + $(this).attr('data-lb-open')).clone(true); 280 } 281 if(content.length > 0){ gdlr_lms_lightbox(content, true); } 282 }); 283 $('[data-rel="gdlr-lms-lightbox2"]').on('click', function(){ 284 var content = $(this).siblings('.gdlr-lms-lightbox-container-wrapper').clone(true);
285 content.children('.' + $(this).attr('data-lb-open')).css('display', 'block'); 286 if(content.length > 0){ gdlr_lms_lightbox(content, true); } 287 }); 288 $('[data-rel="gdlr-lms-lightbox3"]').on('click', function(){ 289 $(this).parents('.gdlr-lms-lightbox-container').fadeOut(200) 290 .siblings('.' + $(this).attr('data-lb-open')).fadeIn(200); 291 }); 292 293 // quiz timer 294 $('.gdlr-lms-quiz-timer input[name="timeleft"]').each(function(){ 295 if($(this).attr('data-full') == '0' || $(this).attr('data-full') == '') return; 296 297 var current_form = $(this).closest('form'); 298 var ajax_url = window.location.href; 299 300 var timer = $(this); 301 var display = timer.siblings('.timer'); 302 var time_left = parseInt(timer.val()); 303 var save_duration = 5; 304 305 var i = setInterval(function(){ 306 if( time_left > 0 ){ 307 time_left = time_left - 1; 308 timer.val(time_left); 309 timer.trigger('change'); 310 display.html(gdlr_lms_format_time(time_left)); 311 }else{ 312 var content = timer.siblings('.quiz-timeout-form').clone(true); 313 gdlr_lms_lightbox(content, false); 314 clearInterval(i); 315 } 316 317 if( time_left % save_duration == 0 ){ 318 $.ajax({
319 type : 'POST', 320 url : ajax_url, 321 data : 'ajax_req=1&' + current_form.serialize(), 322 dataType: 'json', 323 success : function( data ){ console.log('data is saved'); }, 324 error : function( xhr, err ){ console.log(xhr, err); } 325 }); 326 } 327 }, 1000); 328 }); 329 $('.submit-quiz-timeout-form').on('click',function(){ 330 $(this).parents('.gdlr-lms-lightbox-wrapper').fadeOut(200, function(){ 331 $(this).remove(); 332 }); 333 334 $('.finish-quiz-form-button').trigger('click'); 335 }); 336 337 // quiz form submit 338 $('.submit-quiz-form').on('click',function(){ 339 var current_form = $(this).parents('form'); 340 341 if( current_form.length <= 0 ){ current_form = $('form.gdlr-lms-quiz-type'); } 342 343 current_form.attr('action', $(this).attr('href')); 344 current_form.submit(); 345 return false; 346 }); 347 348 // finish course button 349 $('.finish-quiz-form-button').on('click', function(){ 350 var current_button = $(this); 351 if( current_button.html() == current_button.attr('data-loading') ){ 352 return false; 353 } 354 355 current_button.html(current_button.attr('data-loading')); 356 var quiz_form = current_button.parents('form'); 357 358 $.ajax({ 359 type: 'POST', 360 url: current_button.attr('href'), 361 data: quiz_form.serialize(), 362 dataType: 'json', 363 error: function(a, b, c){ console.log(a, b, c); }, 364 success: function(){ 365 var content = current_button.siblings('.finish-quiz-form').clone(true); 366 gdlr_lms_lightbox(content, false); 367 } 368 }); 369 370 return false; 371 }); 372 373 // payment selection 374 $('.gdlr-payment-method input[name="payment-method"]').on('click', function(){ 375 $(this).parent('label').addClass('gdlr-active').siblings().removeClass('gdlr-active'); 376 }); 377 378 // buy / book button 379 $('.buy-form form, .book-form form').each(function(){ 380 if( $(this).hasClass('gdlr-no-ajax') ) return; 381 382 $(this).on('price-calculate', function(){ 383 var price_one = $(this).find('.price-one'); 384 var price_format = price_one.siblings('.format').val(); 385 var price = parseFloat(price_one.val()) * parseInt($(this).find('input[name="quantity"]').val()); 386 387 var discount = $(this).find('input.coupon-amount'); 388 var discount_type = discount.siblings('input.coupon-type'); 389 var discount_price = 0; 390 if( discount_type.val() == 'percent' ){ 391 discount_price = parseFloat( price * parseFloat(discount.val()) / 100 ); 392 }else if( discount_type.val() == 'amount' ){ 393 discount_price = parseFloat( discount.val() ); 394 } 395 if( discount_price > price ){ 396 discount_price = price; 397 } 398 399 price = price - discount_price; 400 price_one.siblings('.price').val(price); 401 price_one.siblings('.price-display').val(price_format.replace('NUMBER', price)); 402 discount.siblings('.discount-amount').val(discount_price); 403 }); 404 405 $(this).find('input[name="quantity"]').on('keyup', function(){ 406 if( $(this).val() != '' ){ 407 $(this).closest('form').trigger('price-calculate'); 408 } 409 }); 410 411 $(this).find('.gdlr-lms-coupon-code').on('keyup', gdlr_lms_debounce(function(){ 412 var current_form = $(this).closest('form'); 413 var coupon_code = $(this); 414 415 if( $(this).val() != '' ){ 416 $(this).siblings('.gdlr-lms-coupon-head').removeClass().addClass('gdlr-lms-coupon-head coupon-loading'); 417 $(this).siblings('.gdlr-lms-coupon-status').slideUp(200); 418 419 $.ajax({
420 type: 'POST', 421 url: current_form.attr('data-ajax'), 422 data: {action:'lms_check_coupon_code', id: $(this).val(), course_id: current_form.find('input[name="course_id"]').val()}, 423 dataType: 'json', 424 error: function(a, b, c){ console.log(a, b, c); }, 425 success: function(data){ 426 if( data.status == 'failed' ){ 427 coupon_code.siblings('.gdlr-lms-coupon-head').removeClass().addClass('gdlr-lms-coupon-head coupon-wrong'); 428 if( data.message ){ 429 coupon_code.siblings('.gdlr-lms-coupon-status').html(data.message).slideDown(200); 430 }else{ 431 coupon_code.siblings('.gdlr-lms-coupon-status').slideUp(200); 432 } 433 }else if( data.status == 'success' ){ 434 coupon_code.siblings('input.coupon-amount').val(data.amount); 435 coupon_code.siblings('input.coupon-type').val(data.type); 436 coupon_code.siblings('.gdlr-lms-coupon-head').removeClass().addClass('gdlr-lms-coupon-head coupon-correct'); 437 if( data.message ){ 438 coupon_code.siblings('.gdlr-lms-coupon-status').html(data.message).slideDown(200); 439 }else{ 440 coupon_code.siblings('.gdlr-lms-coupon-status').slideUp(200); 441 } 442 } 443 444 current_form.trigger('price-calculate'); 445 } 446 }); 447 }else{ 448 $(this).siblings('.gdlr-lms-coupon-head').removeClass().addClass('gdlr-lms-coupon-head'); 449 $(this).siblings('.gdlr-lms-coupon-status').slideUp(200); 450 } 451 }, 500)); 452 453 $(this).on('submit', function(e){ 454 var current_form = $(this); 455 var notice = $(this).find('.gdlr-lms-notice').slideUp(200); 456 var loading = $(this).find('.gdlr-lms-loading').slideDown(200); 457 458 $.ajax({
459 type: 'POST', 460 url: $(this).attr('data-ajax'), 461 data: jQuery(this).serialize(), 462 dataType: 'json', 463 error: function(a, b, c){ console.log(a, b, c); }, 464 success: function(data){ 465 if( data.status == 'success' ){ 466 notice.addClass('success'); 467 }else{ 468 notice.removeClass('success'); 469 } 470 471 notice.html(data.message).slideDown(200); 472 loading.slideUp(200); 473 474 if( data.status == 'success' && data.redirect ){ 475 if( data.redirect == true ){ 476 if( data.id ){ 477 current_form.find('[name="invoice"]').val(data.id); 478 } 479 current_form[0].submit(); 480 }else{ 481 window.location.replace(data.redirect); 482 } 483 }else if( data.status == 'success' && data.payment == 'cloud' ){ 484 var payments = new cp.CloudPayments({ language: "en-US" }); 485 payments.charge( data.data, 486 function (options){ 487 $.ajax({ 488 type: 'POST', 489 url: current_form.attr('data-ajax'), 490 data: { action:'gdlr_lms_cloud_payment', return_val:options }, 491 dataType: 'json', 492 error: function(a, b, c){ console.log(a, b, c); }, 493 success: function(data2){ 494 if( data2.status == 'success' ){ 495 if( data2.redirect ){ 496 window.location.replace(data2.redirect); 497 } 498 }else{ 499 if( data2.message ){ 500 gdlr_lms_notice({ 501 text: data2.message, 502 sub: (data2.message_sub)? data2.message_sub: '', 503 ok: data.ok_button 504 }); 505 } 506 } 507 } 508 }); 509 }, 510 function (reason, options){ 511 gdlr_lms_notice({ 512 text: data.payment_failed_text, 513 sub: reason, 514 ok: data.ok_button 515 }); 516 } 517 ); 518 } 519 } 520 }); 521 522 e.preventDefault(); 523 e.returnValue = false; 524 }); 525 526 }); 527 }); 528 529 $(window).on('load', function(){ $(this).trigger('resize'); }); 530 531})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.