1var opened_lesson_id = 0; 2 3var modalWindow = { 4 parent: "body", 5 windowId: null, 6 content: null, 7 width: null, 8 height: null, 9 left: null, 10 right: null, 11 top: null, 12 bigmodal: null, 13 close: function () { 14 jQuery(".guru-modal").remove(); 15 jQuery(".modal-overlay").remove(); 16 }, 17 open: function () { 18 modal_style = ""; 19 if (this.width != null && this.width != 0) { 20 screen_width = window.innerWidth; 21 screen_height = window.innerHeight; 22 23 modal_style = 'style="display:block;"'; 24 } 25 else { 26 screen_width = window.innerWidth; 27 screen_height = window.innerHeight; 28 29 modal_style = 'style="display:block;"'; 30 } 31 32 var modal = ""; 33 modal += "<div class=\"modal-overlay\"></div>"; 34 modal += "<div class=\"guru-modal p_modal\" id=\"" + this.windowId + "\">"; 35 modal += "<div class=\"guru-modal-header\"></div>"; 36 modal += "<div class=\"guru-modal-dialog\" " + modal_style + ">"; 37 modal += "<div class=\"guru-modal-content\">"; 38 modal += this.content; 39 modal += "</div>"; 40 modal += "</div>"; 41 modal += "</div>"; 42 jQuery(this.parent).append(modal); 43 44 45 jQuery(".guru-modal-dialog").append("<a class=\"close-window\" id=\"close-window\"></a>"); 46 jQuery(".close-window").click(function () { modalWindow.close(); });
47 jQuery(".modal-overlay").click(function () { modalWindow.close(); }); 48 jQuery(".guru-modal").click(function () { modalWindow.close(); }); 49 } 50}; 51 52var openMyModal = function (width, height, source) { 53 modalWindow.windowId = "myModal"; 54 55 iframe_style = ""; 56 57 if (width != 0 && height != 0) { 58 screen_width = window.innerWidth; 59 screen_height = window.innerHeight; 60 61 modalWindow.width = width; 62 modalWindow.height = height; 63 64 iframe_style = 'style="width:' + width + 'px; height:' + height + 'px;"'; 65 } 66 else { 67 modalWindow.width = 0; 68 modalWindow.height = 0; 69 iframe_style = 'style=""'; 70 } 71 72 modalWindow.content = "<iframe " + iframe_style + " id='g_preview' class='pub_modal_frame' src='" + source + "'>content</iframe>"; 73 modalWindow.open(); 74}; 75 76jQuery(document).ready(function ($) { 77 $.ajaxSetup({ cache: false }); 78 79 var $html = $('html'); 80 var $win = $(window); 81 var $doc = $(document.body); 82 var $modal; 83 var cache, params; 84 85 function createModal(source) { 86 $('body').addClass('guru-modal-opened'); 87 88 var lesson_modal_style = Joomla.getOptions('guru.lesson_modal_style'); 89 var html = ''; 90 var shownav = 'shownav'; 91 var fontello_right_open = 'fontello-right-open'; 92 93 if (window.matchMedia("(max-width: 1024px)").matches) { 94 // small device and tablet 95 shownav = ""; 96 fontello_right_open = 'fontello-left-open'; 97 } 98 99 // wrapper (start) 100 html += '<div class="guru-lesson ' + shownav + ' guru-lesson-modal-' + lesson_modal_style + '">'; 101 // header 102 html += '<div class=guru-lesson-header>'; 103 html += '<div class=guru-lesson-header-l>'; 104 html += '<div class=guru-lesson-header-label></div>'; 105 html += '</div>'; 106 html += '<div class=guru-lesson-header-r>'; 107 html += '<div id="lesson-saved-timer"></div>'; 108 html += '<a href="javascript:" class=guru-lesson-home><i class=fontello-cancel></i></a>'; 109 html += '<a href="javascript:" class=guru-lesson-togglenav><i class=' + fontello_right_open + '></i></a>'; 110 html += '</div>'; 111 html += '</div>'; 112 // content 113 html += '<div class=guru-lesson-content>'; 114 html += '<iframe id=frame-lesson-content webkitallowfullscreen mozallowfullscreen allowfullscreen frameborder=0 style="width:100%;height:100%;"></iframe>'; 115 html += '<div class=guru-lesson-loading><div class=guru-lesson-spinner></div></div>'; 116 html += '</div>'; 117 // footer 118 html += '<div id=guru-lesson-footer class=guru-lesson-footer>'; 119 120 if (lesson_view_confirm == 1) { 121 html += '<div class=guru-lesson-footer-confirm>'; 122 html += '<button class=guru-lesson-footer-confirm-btn><i class=fontello-ok-circled></i></button>'; 123 html += '<button class=guru-lesson-footer-unconfirm-btn style="display:none"><i class=fontello-ok-circled></i></button>'; 124 html += '</div>'; 125 } 126 127 html += '<div class="guru-jump-group">'; 128 html += '<button class="guru-jump-dropdown-button" style="display: none;">' + Joomla.JText._('GURU_JUMP_TO_BTN') + '</button>'; 129 html += '<ul class=guru-jump-group-button></ul>'; 130 html += '</div>' 131 132 html += '<div class=guru-lesson-footer-nav>'; 133 html += '<button class=guru-lesson-footer-prev ><i class=fontello-left-open></i> ' + prev_lang + '</button> '; 134 html += '<button class=guru-lesson-footer-next >' + next_lang + ' <i class=fontello-right-open></i></button>'; 135 html += '</div>'; 136 137 html += '</div>'; 138 // sidebar 139 html += '<div class=guru-lesson-nav>'; 140 html += '<div class=guru-lesson-nav-tab>'; 141 html += '<a href="javascript:" data-id=lessons class="guru-lesson-nav-tabitem active"><i class="fa fa-list"></i>' + Joomla.JText._('GURU_LESSION_LIST') + '</a>'; 142 html += '<a href="javascript:" data-id=description class="guru-lesson-nav-tabitem"><i class="fa fa-file-text-o"></i>' + Joomla.JText._('GURU_LESSION_DESCRIPTION') + '</a>'; 143 144 html += '<a id="comments-button" style="display:none;" href="javascript:" data-id=comments class="guru-lesson-nav-tabitem"><i class=fontello-chat></i></a>'; 145 146 html += '</div>'; 147 html += '<div class="guru-lesson-nav-content guru-lesson-nav-lessons"></div>';
148 html += '<div class="guru-lesson-nav-content guru-lesson-nav-description"></div>'; 149 html += '<div class="guru-lesson-nav-content guru-lesson-nav-comments"></div>'; 150 html += '</div>'; 151 // wrapper (end) 152 html += '</div>'; 153 154 $modal = $(html); 155 $modal.find('.guru-lesson-home').on('click', destroyWindow); 156 $modal.find('.guru-lesson-togglenav').on('click', toggleNav); 157 $modal.find('.guru-lesson-footer-prev').on('click', prevLesson); 158 $modal.find('.guru-lesson-footer-next').on('click', nextLesson); 159 $modal.find('.guru-lesson-nav-tab a').on('click', toggleNavTab); 160 $modal.find('.guru-lesson-footer-confirm-btn').on('click', function () { 161 confirmLessonView().then(() => { 162 getSidebarContent(); 163 updateLessonStatus(); 164 }) 165 }); 166 $modal.find('.guru-lesson-footer-unconfirm-btn').on('click', function () { 167 notConfirmLessonView().then(() => { 168 getSidebarContent(); 169 updateLessonStatus(); 170 }) 171 }); 172 $modal.on('click', '.guru-lesson-nav-lesson', showLesson); 173 $modal.on('guru.updateLessonProgress', function (e, lesson_id) { 174 params.cid = lesson_id; 175 getSidebarContent(); 176 updateLessonStatus(); 177 }); 178 $html.css('overflow', 'hidden'); 179 180 var isIOS = (/iphone|ipad|ipod/i).test(navigator.userAgent); 181 182 // Fix iOS issue 183 // http://stackoverflow.com/questions/35879449/iframe-cannot-scroll-because-of-setting-height-in-css 184 if (isIOS) { 185 $modal.find('.guru-lesson-content').css({ 186 'overflow-x': 'auto', 187 '-webkit-overflow-scrolling': 'touch' 188 }); 189 } 190 191 $doc.append($modal); 192 193 // loading 194 isIOS && $html.css('position', 'fixed'); 195 $modal.find('iframe').on('load', function () { 196 $modal.find('.guru-lesson-loading').fadeOut(); 197 198 if (params.duration) { 199 $("#lesson-saved-timer").html(""); 200 lesson_duration_text = ""; 201 lesson_duration = params.duration.split('x'); 202 203 if (!isNaN(parseInt(lesson_duration[0])) && !isNaN(parseInt(lesson_duration[1]))) { 204 lesson_duration_text = lesson_duration[0] + "min " + lesson_duration[1] + "sec"; 205 } 206 else if (!isNaN(parseInt(lesson_duration[0])) && isNaN(parseInt(lesson_duration[1]))) { 207 lesson_duration_text = lesson_duration[0] + "min"; 208 } 209 else if (isNaN(parseInt(lesson_duration[0])) && !isNaN(parseInt(lesson_duration[1]))) { 210 lesson_duration_text = lesson_duration[1] + "sec"; 211 } 212 213 $("#lesson-saved-timer").html('<i class="guru-course-dur"></i>' + lesson_duration_text); 214 } 215 216 getSidebarContent(); 217 getComments(params.cid); 218 updateLessonStatus(); 219 220 moveJumpButtons(); 221 isIOS && $html.css('position', ''); 222 223 setTimeout(function () { 224 lessons_not_viewed = document.getElementsByClassName("not-view"); 225 226 if (lessons_not_viewed.length == 0) { 227 // check course completed 228 var course_id = document.getElementById("course_id").value; 229 var url = params.uri + 'index.php?option=com_guru&controller=guruTasks&task=check_course_completed&ajax=1&tmpl=component&course_id=' + course_id; 230 $.ajax({
231 url: url, 232 type: 'get', 233 dataType: 'json', 234 success: function (resp) { 235 if (resp === true) { 236 $("#id-lesson-0").addClass("guru-lesson-nav-accessible"); 237 $(".redirect-lesson").show(); 238 } 239 } 240 }); 241 } 242 }, 2000); 243 244 }).attr('src', source); 245 246 startNewCourseTime(params.pid); 247 startLessonTimeView(params.cid); 248 getSidebarContent(); 249 getComments(params.cid); 250 updateLessonStatus(); 251 } 252 253 function destroyWindow() { 254 saveCurrentCourseTime(); 255 saveCurrentLessonTime(opened_lesson_id); 256 257 var course_id = document.getElementById("course_id").value; 258 var module = $('.guru-lesson-nav-current').attr("data-module-id"); 259 var lesson_id = $('.guru-lesson-nav-current').attr("data-lesson-id"); 260 261 /*var url = params.uri + 'index.php?option=com_guru&controller=guruTasks&pid=' + course_id + '&task=set_lesson_viewed&ajax=1&module='+module+'&lesson_id='+lesson_id; 262 $.ajax({ 263 url: url, 264 type: 'get', 265 dataType: 'json', 266 success: function( resp ) { 267 268 } 269 });*/ 270 271 document.getElementsByTagName("html")[0].style.overflow = "auto"; 272 document.getElementsByTagName("html")[0].style.position = ""; 273 274 $html.css('overflow', ''); 275 $win.off('resize.guru-lesson'); 276 $modal.remove(); 277 $modal = null; 278 279 $('body').removeClass('guru-modal-opened'); 280 } 281 282 function toggleNav(e) { 283 var $btn = $(e.currentTarget); 284 285 if ($modal.hasClass('shownav')) { 286 $modal.removeClass('shownav'); 287 $btn.find('i').attr('class', 'fontello-left-open'); 288 } else { 289 $modal.addClass('shownav'); 290 $btn.find('i').attr('class', 'fontello-right-open'); 291 } 292 } 293 294 function prevLesson() { 295 if (!cache) { 296 return; 297 } 298 299 var $lessons = $modal.find('.guru-lesson-nav-lessons'), 300 $current = $lessons.find('.guru-lesson-nav-current'), 301 $accessible, index; 302 303 if (!$current.length) { 304 return; 305 } 306 307 $accessible = $lessons.find('.guru-lesson-nav-accessible'); 308 index = $accessible.index($current); 309 310 if (index > 0) { 311 $accessible.eq(index - 1).click(); 312 } 313 } 314 315 function nextLesson() { 316 if (!cache) { 317 return; 318 } 319 320 var $lessons = $modal.find('.guru-lesson-nav-lessons'), 321 $current = $lessons.find('.guru-lesson-nav-current'), 322 $accessible; 323 324 if (!$current.length) { 325 return; 326 } 327 328 $accessible = $lessons.find('.guru-lesson-nav-accessible'); 329 index = $accessible.index($current); 330 331 if (index < $accessible.length - 1) { 332 nex_element = $accessible.eq(index + 1); 333 334 if ($(nex_element).parent().css('display') == 'none') { 335 return false; 336 } 337 338 $accessible.eq(index + 1).click(); 339 } 340 } 341 342 function confirmLessonView() { 343 return new Promise((resolve, reject) => { 344 var current_module_id = $('.guru-lesson-nav-current').attr("data-module-id"); 345 var current_lesson_id = $('.guru-lesson-nav-current').attr("data-lesson-id"); 346 347 var url = params.uri + 'index.php?option=com_guru&view=guruTasks&controller=guruTasks&pid=' + params.pid + '&cid=' + params.pid + '&task=set_lesson_viewed&ajax=1&lesson_id=' + parseInt(current_lesson_id) + "&module=" + parseInt(current_module_id); 348 $.ajax({ 349 url: url, 350 type: 'get', 351 dataType: 'json', 352 success: function (resp) { 353 $(".guru-lesson-footer-confirm-btn").hide(); 354 $(".guru-lesson-footer-unconfirm-btn").show(); 355 356 lessons_viewed = document.getElementsByClassName("viewed-" + current_lesson_id); 357 358 if (lessons_viewed[0] !== undefined) { 359 lessons_viewed[0].style.visibility = "visible"; 360 } 361 362 $("#id-lesson-" + current_lesson_id + " .guru-lesson-nav-check").css("background", "rgba(61, 225, 0, 0.34)"); 363 $("#id-lesson-" + current_lesson_id + " .guru-lesson-nav-check").removeClass("not-view"); 364 $("#id-lesson-" + current_lesson_id + " .guru-lesson-nav-check i").css("color", "rgb(84, 181, 81)"); 365 366 resolve(); 367 } 368 }); 369 }); 370 } 371 372 function notConfirmLessonView() { 373 return new Promise((resolve, reject) => { 374 var current_module_id = $('.guru-lesson-nav-current').attr("data-module-id"); 375 var current_lesson_id = $('.guru-lesson-nav-current').attr("data-lesson-id"); 376 377 var url = params.uri + 'index.php?option=com_guru&controller=guruTasks&pid=' + params.pid + '&cid=' + params.pid + '&task=set_lesson_notviewed&ajax=1&lesson_id=' + parseInt(current_lesson_id) + "&module=" + parseInt(current_module_id); 378 $.ajax({
379 url: url, 380 type: 'get', 381 dataType: 'json', 382 success: function (resp) { 383 $(".guru-lesson-footer-unconfirm-btn").hide(); 384 $(".guru-lesson-footer-confirm-btn").show(); 385 386 lessons_viewed = document.getElementsByClassName("viewed-" + current_lesson_id); 387 388 if (lessons_viewed[0] !== undefined) { 389 lessons_viewed[0].style.visibility = "hidden"; 390 } 391 392 $("#id-lesson-" + current_lesson_id + " .guru-lesson-nav-check").css("background-color", "#ddd"); 393 $("#id-lesson-" + current_lesson_id + " .guru-lesson-nav-check").addClass("not-view"); 394 $("#id-lesson-" + current_lesson_id + " .guru-lesson-nav-check i").css("color", "#9f9f9f"); 395 396 resolve(); 397 } 398 }); 399 }); 400 } 401 402 function updateLessonNav(index, max) { 403 if (index <= 0) { 404 $modal.find('.guru-lesson-footer-prev').attr('disabled', true); 405 } else { 406 $modal.find('.guru-lesson-footer-prev').attr('disabled', false); 407 } 408 409 if (index >= max) { 410 $modal.find('.guru-lesson-footer-next').attr('disabled', true); 411 } else { 412 $modal.find('.guru-lesson-footer-next').attr('disabled', false); 413 } 414 415 // check course completed 416 var course_id = document.getElementById("course_id").value; 417 var url = params.uri + 'index.php?option=com_guru&controller=guruTasks&task=check_course_completed&ajax=1&tmpl=component&course_id=' + course_id; 418 $.ajax({ 419 url: url, 420 type: 'get', 421 dataType: 'json', 422 success: function (resp) { 423 if (resp === true) { 424 $("#id-lesson-0").addClass("guru-lesson-nav-accessible"); 425 $(".redirect-lesson").show(); 426 } 427 } 428 }); 429 } 430 431 function updateConfirmButtons(lesson) { 432 if (lesson.viewed === true && lesson.data.layout != 12) { 433 $(".guru-lesson-footer-unconfirm-btn").show(); 434 $(".guru-lesson-footer-confirm-btn").hide(); 435 } 436 else if (lesson.viewed === false && lesson.data.layout != 12) { 437 $(".guru-lesson-footer-confirm-btn").show(); 438 $(".guru-lesson-footer-unconfirm-btn").hide(); 439 } 440 else { 441 $(".guru-lesson-footer-confirm-btn").hide(); 442 $(".guru-lesson-footer-unconfirm-btn").hide(); 443 } 444 } 445 446 function toggleNavTab(e) { 447 var $btn = $(e.currentTarget), 448 id = $btn.data('id'), 449 $content = $('.guru-lesson-nav-' + id), 450 $siblings = $content.siblings('.guru-lesson-nav-content'); 451 452 $siblings.hide(); 453 $content.show(); 454 $btn.addClass('active').siblings('.active').removeClass('active'); 455 } 456 457 function getSidebarContent() { 458 var lang_url = ""; 459 var lang_value = document.getElementById("modal-lang").value; 460 461 if (lang_value != "") { 462 lang_url = "&lang=" + lang_value; 463 } 464 465 var url = params.uri + 'index.php?option=com_guru&controller=guruTasks&pid=' + params.pid + '&cid=' + params.pid + '&task=get_lessons&ajax=1&Itemid=' + params.item_id + lang_url; 466 $.ajax({ 467 url: url, 468 type: 'get', 469 dataType: 'json', 470 success: function (resp) { 471 printSidebar(resp); 472 } 473 }); 474 } 475 476 function updateLessonStatus() { 477 var url = Joomla.getOptions('guru.tabViewComponent'); 478 479 $.ajax({ 480 url: url, 481 dataType: 'html' 482 }).done(function (res) { 483 var $chapters = $('.guru-tabs.chapter_wrap'); 484 var $html = $(res); 485 var $newChapters = $html.find('.guru-tabs.chapter_wrap'); 486 487 $chapters.each(function (idx, elm) { 488 var newHtml = $newChapters.get(idx).innerHTML; 489 $(elm).html(newHtml); 490 }); 491 }); 492 } 493 494 function printSidebar(json) { 495 if ($modal === null) { 496 return; 497 } 498 499 var $lessons = $modal.find('.guru-lesson-nav-lessons'), 500 $description = $modal.find('.guru-lesson-nav-description'), 501 html = '', 502 accessible = 0, 503 index = 0, 504 info, module, lessons, lesson, media, text, type, duration, i, j; 505 506 var current_lesson_details = null; 507 508 cache = json = json || {}; 509 info = json.info || {}; 510 511 if (cache.kunena.allow_stud == "1") { 512 document.getElementById("comments-button").style.display = "none"; 513 } 514 else if (cache.kunena.allow_stud == "0") { 515 document.getElementById("comments-button").style.display = "block"; 516 } 517 518 // update lessons 519 html += '<ul>'; 520 for (i = 0; i < json.modules.length; i++) { 521 module = json.modules[i]; 522 lessons = module.lessons; 523 html += '<li>'; 524 525 if (module.can_open_module == '1') { 526 html += '<span class=guru-lesson-nav-module><a id="id-module-' + module.module_id + '" class="guru-lesson-nav-lesson guru-lesson-nav-accessible" href="javascript:" data-mindexm="' + i + '">' + module.title + '</a></span>'; 527 } 528 else { 529 html += '<span class=guru-lesson-nav-module><a id="id-module-' + module.module_id + '" class="guru-lesson-nav-lesson" href="javascript:">' + module.title + '</a></span>'; 530 } 531 532 html += '<ul class="guru-lesson-nav-list">'; 533 534 for (j = 0; j < lessons.length; j++) { 535 lesson = lessons[j]; 536 media = lesson.data && lesson.data.media || []; 537 text = lesson.data && lesson.data.text || []; 538 type = lesson.data && lesson.data.type || []; 539 540 accessible++; 541 542 if (parseInt(lesson.id) > 0) { 543 html += '<li><a id="id-lesson-' + lesson.id + '" data-openable="' + lesson.can_open_lesson + '" data-lesson-id="' + lesson.id + '" data-module-id="' + module.module_id + '" class="guru-lesson-nav-lesson'; 544 } 545 else { 546 html += '<li class="redirect-lesson"><a id="id-lesson-' + lesson.id + '" data-lesson-id="' + lesson.id + '" data-module-id="' + module.module_id + '" class="guru-lesson-nav-lesson'; 547 } 548 549 if (params.cid == lesson.id) { 550 if (lesson_view_confirm == 0) { 551 lessons_viewed = document.getElementsByClassName("viewed-" + lesson.id); 552 lessons_viewed[0].style.visibility = "visible"; 553 } 554 555 params.current_lesson = lesson.id; 556 current_lesson_details = lesson; 557 html += ' guru-lesson-nav-current'; 558 index = accessible; 559 560 var url = params.uri + 'index.php?option=com_guru&controller=guruTasks&task=get_lesson_description&ajax=1&lesson_id=' + lesson.id; 561 $.ajax({
562 url: url, 563 type: 'get', 564 dataType: 'json', 565 success: function (resp) { 566 json = resp || {}; 567 $description.html(json.description || ''); 568 } 569 }); 570 } 571 if (+lesson.can_open_lesson) { 572 if (parseInt(lesson.id) > 0) { 573 html += ' guru-lesson-nav-accessible" href="javascript:" data-mindex="' + i + '" data-cindex="' + j; 574 } 575 else { 576 html += ' guru-lesson-nav-accessible" href="#" onclick="javascript:redirectCourseAfterComplete(\'' + lesson.url + '\')" data-mindex="' + i + '" data-cindex="' + j; 577 } 578 579 } 580 else if (lesson.alias == "completed-course-redirect") { 581 html += ' guru-lesson-nav-accessible" href="#" onclick="javascript:redirectCourseAfterComplete(\'' + lesson.url + '\')" data-mindex="' + i + '" data-cindex="' + j; 582 } 583 else { 584 if (parseInt(lesson.id) > 0) { 585 html += ' " href="javascript:" data-mindex="' + i + '" data-cindex="' + j; 586 } 587 } 588 589 html += '">' + lesson.name; 590 591 if (!+lesson.can_open_lesson) { 592 if (typeof lesson.available_div != "undefined") { 593 available_language = document.getElementById("available_language").value; 594 html += '<br /> <div class="clearfix available-area-' + lesson.id + '"><div class="pull-left">' + available_language + ": </div>" + lesson.available_div + '</div>'; 595 } 596 } 597 598 if (lesson.data && lesson.data.layout == 12) { 599 html += '<br><span><i class=fontello-check></i>' + quiz_lesson_lang; 600 } 601 else { 602 if (type.length > 0) { 603 if (type.indexOf('video') >= 0) { 604 html += '<br><span><i class=fontello-play-circled></i> ' + video_lesson_lang; 605 } 606 else if (type.indexOf('audio') >= 0) { 607 html += '<br><span><i class=icon-volume-up></i> ' + audio_lesson_lang; 608 } 609 else if (type.indexOf('docs') >= 0) { 610 html += '<br><span><i class=fontello-doc-text-inv></i> ' + document_lesson_lang; 611 } 612 else if (type.indexOf('url') >= 0) { 613 html += '<br><span><i class=icon-link-ext></i> ' + url_lesson_lang; 614 } 615 else if (type.indexOf('Article') >= 0) { 616 html += '<br><span><i class=icon-pencil></i> ' + article_lesson_lang; 617 } 618 else if (type.indexOf('image') >= 0) { 619 html += '<br><span><i class=icon-picture></i> ' + image_lesson_lang; 620 } 621 else if (type.indexOf('text') >= 0) { 622 html += '<br><span><i class=fontello-doc-text-inv></i> ' + text_lesson_lang; 623 } 624 else if (type.indexOf('file') >= 0) { 625 html += '<br><span><i class=icon-folder-empty></i> ' + file_lesson_lang; 626 } 627 } 628 } 629 630 var class_not_view = (lesson.viewed || params.cid == lesson.id) ? '' : 'not-view'; 631 632 html += '</span>'; 633 html += '<span class="guru-lesson-nav-check ' + class_not_view + '"'; 634 635 if (lesson_view_confirm == 0) { 636 html += (lesson.viewed || params.cid == lesson.id) ? 'style="background:rgba(61, 225, 0, 0.34)"' : ''; 637 } 638 else { 639 html += (lesson.viewed) ? 'style="background:rgba(61, 225, 0, 0.34)"' : ''; 640 } 641 642 html += '>'; 643 html += '<span class=guru-lesson-nav-check-circle><i class=fontello-ok '; 644 645 if (lesson_view_confirm == 0) { 646 html += (lesson.viewed || params.cid == lesson.id) ? 'style="color:rgb(84, 181, 81)"' : ''; 647 } 648 else { 649 html += (lesson.viewed) ? 'style="color:rgb(84, 181, 81)"' : ''; 650 } 651 652 html += '></i></span>'; 653 html += '</span>'; 654 655 html += '</a></li>'; 656 657 // update lesson header 658 if (params.cid == lesson.id) { 659 $modal.find('.guru-lesson-header-label').html(lesson.name || ''); 660 } 661 } 662 html += '</ul>'; 663 html += '</li>'; 664 } 665 html += '</ul>'; 666 $lessons.html(html); 667 updateLessonNav(index, accessible); 668 updateConfirmButtons(current_lesson_details); 669 } 670 671 function showLesson(e) { 672 saveCurrentCourseTime(); 673 saveCurrentLessonTime(opened_lesson_id); 674 675 $("#lesson-saved-timer").html(""); 676 677 var $btn = $(e.currentTarget), 678 data, lesson, media, text, html; 679 680 if ($btn.hasClass('guru-lesson-nav-current')) { 681 return; 682 } 683 684 if ($btn.hasClass('guru-lesson-nav-accessible')) { 685 data = $btn.data(); 686 687 if (data.mindex !== undefined) { 688 lesson = cache.modules[data.mindex].lessons[data.cindex] || {}; 689 } 690 else { 691 lesson = cache.modules[data.mindexm] || {}; 692 } 693 694 if ( 695 typeof lesson.id !== 'undefined' 696 && lesson.hasOwnProperty("course_type") 697 && lesson.hasOwnProperty("lesson_release") 698 && lesson.hasOwnProperty("next_lesson") 699 && lesson.course_type == "1" 700 && lesson.lesson_release == 5 701 && parseInt(lesson.next_lesson) > 0 702 ) { 703 704 var $next = $("#id-lesson-" + parseInt(lesson.next_lesson)); 705 if ($next.data('openable') === '1') { 706 $next.addClass("guru-lesson-nav-accessible"); 707 $(".available-area-" + parseInt(lesson.next_lesson)).hide(); 708 } 709 } 710 711 if (lesson.viewed === true) { 712 $(".guru-lesson-footer-unconfirm-btn").show(); 713 $(".guru-lesson-footer-confirm-btn").hide(); 714 } 715 else if (lesson.viewed === false) { 716 $(".guru-lesson-footer-confirm-btn").show(); 717 $(".guru-lesson-footer-unconfirm-btn").hide(); 718 } 719 else { 720 $(".guru-lesson-footer-confirm-btn").hide(); 721 $(".guru-lesson-footer-unconfirm-btn").hide(); 722 } 723 724 if (lesson_view_confirm == 0) { 725 $("#id-lesson-" + lesson.id + " .guru-lesson-nav-check").css("background", "rgba(61, 225, 0, 0.34)"); 726 $("#id-lesson-" + lesson.id + " .guru-lesson-nav-check").removeClass("not-view"); 727 } 728 729 lessons_not_viewed = document.getElementsByClassName("not-view"); 730 731 if (lessons_not_viewed.length == 0) { 732 // check course completed 733 var course_id = document.getElementById("course_id").value; 734 var url = params.uri + 'index.php?option=com_guru&controller=guruTasks&task=check_course_completed&ajax=1&tmpl=component&course_id=' + course_id; 735 $.ajax({
736 url: url, 737 type: 'get', 738 dataType: 'json', 739 success: function (resp) { 740 if (resp === true) { 741 $("#id-lesson-0").addClass("guru-lesson-nav-accessible"); 742 $(".redirect-lesson").show(); 743 } 744 } 745 }); 746 } 747 748 if (lesson_view_confirm == 0) { 749 lessons_viewed = document.getElementsByClassName("viewed-" + lesson.id); 750 751 if (lessons_viewed[0] !== undefined) { 752 lessons_viewed[0].style.visibility = "visible"; 753 } 754 } 755 756 opened_lesson_id = lesson.id; 757 startLessonTimeView(opened_lesson_id); 758 params.current_lesson = lesson.id; 759 getComments(lesson.id); 760 761 html = '<iframe id=frame-lesson-content webkitallowfullscreen mozallowfullscreen allowfullscreen frameborder=0 style="width:100%;height:100%;"></iframe>'; 762 $modal.find('.guru-lesson-nav-current').removeClass('guru-lesson-nav-current'); 763 $btn.addClass('guru-lesson-nav-current').find('.guru-lesson-nav-check-circle i').show(); 764 setModalActiveIfIsCurrent(); 765 $modal.find('.guru-lesson-header-label').html(lesson.name || ''); 766 $modal.find('.guru-lesson-content iframe').replaceWith(html); 767 768 var isIOS = (/iphone|ipad|ipod/i).test(navigator.userAgent); 769 770 // loading 771 isIOS && $html.css('position', 'fixed'); 772 $modal.find('.guru-lesson-loading').show(); 773 $modal.find('iframe').one('load', function () { 774 $modal.find('.guru-lesson-loading').fadeOut(); 775 moveJumpButtons(); 776 isIOS && $html.css('position', ''); 777 }).attr('src', lesson.url); 778 779 if (lesson.duration) { 780 lesson_duration_text = ""; 781 lesson_duration = lesson.duration.split('x'); 782 783 if (!isNaN(parseInt(lesson_duration[0])) && !isNaN(parseInt(lesson_duration[1]))) { 784 lesson_duration_text = lesson_duration[0] + "min " + lesson_duration[1] + "sec"; 785 } 786 else if (!isNaN(parseInt(lesson_duration[0])) && isNaN(parseInt(lesson_duration[1]))) { 787 lesson_duration_text = lesson_duration[0] + "min"; 788 } 789 else if (isNaN(parseInt(lesson_duration[0])) && !isNaN(parseInt(lesson_duration[1]))) { 790 lesson_duration_text = lesson_duration[1] + "sec"; 791 } 792 793 $("#lesson-saved-timer").html('<i class="guru-course-dur"></i>' + lesson_duration_text); 794 } 795 796 // get description 797 var url = params.uri + 'index.php?option=com_guru&controller=guruTasks&task=get_lesson_description&ajax=1&lesson_url=' + encodeURIComponent(lesson.url); 798 $.ajax({ 799 url: url, 800 type: 'get', 801 dataType: 'json', 802 success: function (resp) { 803 var $description = $modal.find('.guru-lesson-nav-description'); 804 json = resp || {}; 805 $description.html(json.description); 806 } 807 }); 808 809 $modal.find('.guru-lesson-content iframe').on('load', function () { 810 if (lesson.id) { 811 params.cid = lesson.id; 812 getSidebarContent(); 813 updateLessonStatus(); 814 } 815 }); 816 } 817 } 818 819 function startNewCourseTime(pid) { 820 var current_time = (new Date()).toUTCString(); 821 var id = "viewed_course_" + parseInt(pid); 822 823 sessionStorage.setItem(id, current_time); 824 } 825 826 function startLessonTimeView(lesson_id) { 827 opened_lesson_id = lesson_id; 828 829 var current_time = (new Date()).toUTCString(); 830 var id = "viewed_lesson_" + parseInt(lesson_id); 831 832 sessionStorage.setItem(id, current_time); 833 } 834 835 function saveCurrentCourseTime() { 836 var course_id = document.getElementById("course_id").value; 837 838 var start_years = getCookie(course_id, "years"); 839 var start_months = getCookie(course_id, "months"); 840 var start_days = getCookie(course_id, "days"); 841 var start_hours = getCookie(course_id, "hours"); 842 var start_minutes = getCookie(course_id, "minutes"); 843 var start_seconds = getCookie(course_id, "seconds"); 844 845 if (start_days < 10) { 846 start_days = "0" + start_days; 847 } 848 849 if (start_hours < 10) { 850 start_hours = "0" + start_hours; 851 } 852 853 if (start_minutes < 10) { 854 start_minutes = "0" + start_minutes; 855 } 856 857 if (start_seconds < 10) { 858 start_seconds = "0" + start_seconds; 859 } 860 861 var start_time = new Date(start_years, start_months, start_days, start_hours, start_minutes, start_seconds, 0); 862 var current_time = new Date(); 863 var dif_time_seconds = current_time - start_time; 864 865 dif_time_seconds = dif_time_seconds / 1000; 866 var dif_hour = Math.floor(dif_time_seconds / (60 * 60)); 867 var divisor_for_minutes = dif_time_seconds % (60 * 60); 868 var dif_min = Math.floor(divisor_for_minutes / 60); 869 var divisor_for_seconds = divisor_for_minutes % 60; 870 var dif_sec = Math.ceil(divisor_for_seconds); 871 872 var url = params.uri + 'index.php?option=com_guru&controller=guruTasks&course_id=' + course_id + '&task=saveDateTime&ajax=1&dif_hour=' + dif_hour + "&dif_min=" + dif_min + "&dif_sec=" + dif_sec; 873 $.ajax({
874 url: url, 875 type: 'get', 876 dataType: 'json', 877 success: function (resp) { 878 879 } 880 }); 881 882 startNewCourseTime(course_id); 883 } 884 885 function saveCurrentLessonTime(lesson_id) { 886 var start_years = getCookieLesson(lesson_id, "years"); 887 var start_months = getCookieLesson(lesson_id, "months"); 888 var start_days = getCookieLesson(lesson_id, "days"); 889 var start_hours = getCookieLesson(lesson_id, "hours"); 890 var start_minutes = getCookieLesson(lesson_id, "minutes"); 891 var start_seconds = getCookieLesson(lesson_id, "seconds"); 892 893 if (start_days < 10) { 894 start_days = "0" + start_days; 895 } 896 897 if (start_hours < 10) { 898 start_hours = "0" + start_hours; 899 } 900 901 if (start_minutes < 10) { 902 start_minutes = "0" + start_minutes; 903 } 904 905 if (start_seconds < 10) { 906 start_seconds = "0" + start_seconds; 907 } 908 909 var start_time = new Date(start_years, start_months, start_days, start_hours, start_minutes, start_seconds, 0); 910 var current_time = new Date(); 911 var dif_time_seconds = current_time - start_time; 912 913 dif_time_seconds = dif_time_seconds / 1000; 914 var dif_hour = Math.floor(dif_time_seconds / (60 * 60)); 915 var divisor_for_minutes = dif_time_seconds % (60 * 60); 916 var dif_min = Math.floor(divisor_for_minutes / 60); 917 var divisor_for_seconds = divisor_for_minutes % 60; 918 var dif_sec = Math.ceil(divisor_for_seconds); 919 920 var url = params.uri + 'index.php?option=com_guru&controller=guruTasks&lesson_id=' + lesson_id + '&task=saveDateTimeLesson&ajax=1&dif_hour=' + dif_hour + "&dif_min=" + dif_min + "&dif_sec=" + dif_sec; 921 922 $.ajax({ 923 url: url, 924 type: 'get', 925 dataType: 'json', 926 success: function (resp) { 927 928 } 929 }); 930 } 931 932 function getCookie(course_id, name) { 933 var id = 'viewed_course_' + parseInt(course_id); 934 var time = sessionStorage.getItem(id); 935 if (!time) { 936 return ''; 937 } 938 939 var date = (new Date(time)); 940 941 switch (name) { 942 case 'years': 943 return date.getFullYear(); 944 case 'months': 945 return date.getMonth(); 946 case 'days': 947 return date.getDate(); 948 case 'hours': 949 return date.getHours(); 950 case 'minutes': 951 return date.getMinutes(); 952 case 'seconds': 953 return date.getSeconds(); 954 default: 955 return ''; 956 } 957 } 958 959 function getCookieLesson(lesson_id, name) { 960 var id = 'viewed_lesson_' + parseInt(lesson_id); 961 var time = sessionStorage.getItem(id); 962 if (!time) { 963 return ''; 964 } 965 966 var date = (new Date(time)); 967 968 switch (name) { 969 case 'years': 970 return date.getFullYear(); 971 case 'months': 972 return date.getMonth(); 973 case 'days': 974 return date.getDate(); 975 case 'hours': 976 return date.getHours(); 977 case 'minutes': 978 return date.getMinutes(); 979 case 'seconds': 980 return date.getSeconds(); 981 default: 982 return ''; 983 } 984 } 985 986 function moveJumpButtons() { 987 var $footer = $('#guru-lesson-footer'); 988 var $jumpGroup = $("#frame-lesson-content").contents().find(".guru-jump-group-button"); 989 990 if ($jumpGroup.length && $jumpGroup.html().trim()) { 991 $footer.find('.guru-jump-group-button').html($jumpGroup.html()); 992 $footer.find('.guru-jump-group-button').removeClass('guru-modal-hidden '); 993 $footer.find('.guru-jump-dropdown-button').show(); 994 $jumpGroup.remove(); 995 } else { 996 $footer.find('.guru-jump-group-button').html(''); 997 $footer.find('.guru-jump-dropdown-button').hide(); 998 } 999 } 1000 1001 function getComments(lesson_id) { 1002 var url = params.uri + 'index.php?option=com_guru&controller=guruTasks&lesson_id=' + lesson_id + '&task=get_comments&ajax=1&Itemid=' + params.item_id; 1003 $.ajax({ 1004 url: url, 1005 type: 'get', 1006 dataType: 'json', 1007 success: function (resp) { 1008 printComments(resp); 1009 } 1010 }); 1011 } 1012 1013 function printComments(json) { 1014 if ($modal === null) { 1015 return; 1016 } 1017 1018 var $comments = $modal.find('.guru-lesson-nav-comments'); 1019 json = json || {}; 1020 $comments.html(json.commentbox + json.commentlist); 1021 $comments.find('textarea').on('keydown', commentOnKeydown); 1022 $comments.find('textarea').on('input', commentOnInput); 1023 $comments.find('button').on('click', commentOnSubmit); 1024 $comments.on('click', '.guru-comment-edit', commentOnEdit); 1025 $comments.on('click', '.guru-comment-save', commentOnEditSave); 1026 $comments.on('click', '.guru-comment-delete', commentOnDelete); 1027 } 1028 1029 function commentOnKeydown(e) { 1030 var $comments; 1031 if (e.keyCode === 13 && !e.shiftKey) { 1032 e.preventDefault(); 1033 e.stopPropagation(); 1034 $comments = $modal.find('.guru-lesson-nav-comments'); 1035 $comments.find('button').click(); 1036 return false; 1037 } 1038 } 1039 1040 function commentOnInput(e) { 1041 var value = (e.target.value || '').replace(/^\s+|\s+$/g, ''); 1042 var $button = $(e.target).siblings('button'); 1043 if (value.length) { 1044 $button.removeAttr('disabled'); 1045 } else { 1046 $button.attr('disabled', 'disabled'); 1047 } 1048 } 1049 1050 function commentOnSubmit(e) { 1051 e.preventDefault(); 1052 e.stopPropagation(); 1053 var $button = $(e.currentTarget); 1054 var $textarea = $button.siblings('textarea'); 1055 var message = $textarea.val(); 1056 var id = $textarea.data('id'); 1057 var url = params.uri + 'index.php?option=com_guru&controller=guruTasks&task=insert_comment&lessonid=' + id + '&message=' + encodeURIComponent(message) + '&ajax=1&Itemid=' + params.item_id; 1058 1059 var uniq = 'message-' + (new Date()).getTime() + '-' + Math.floor(Math.random() * 1000); 1060 1061 var html = [ 1062 '<div id="', uniq, '" class="guru-lesson-comment my-message">', 1063 '<div class="guru-lesson-comment-wrap">', 1064 '<div class="guru-lesson-comment-avatar"><span></span></div>', 1065 '<div class="guru-lesson-comment-body guru-reply-body">', 1066 '<a class="guru-lesson-comment-name" href="javascript:">You</a> ', 1067 '<span class="guru-text">', message, '</span>', 1068 '<div class="guru-lesson-comment-meta">', 1069 '<span class="guru-lesson-comment-time">a few seconds ago</span>', 1070 '</div>', 1071 '</div>', 1072 '</div>', 1073 '</div>' 1074 ].join(''); 1075 1076 $textarea.closest('.guru-lesson-comments-form').after(html); 1077 $textarea.val(''); 1078 $button.attr('disabled', 'disabled'); 1079 1080 $.ajax({
1081 url: url, 1082 type: 'get', 1083 dataType: 'json', 1084 success: function (json) { 1085 if (json && json.html) { 1086 $('#' + uniq).replaceWith(json.html); 1087 } 1088 } 1089 }); 1090 } 1091 1092 function commentOnEdit(e) { 1093 var $button = $(e.currentTarget), 1094 $ct = $button.closest('.guru-reply-body'), 1095 $text = $ct.find('.guru-text'), 1096 $textarea = $ct.find('textarea'); 1097 1098 $text.hide(); 1099 $textarea.show(); 1100 $ct.find('.guru-comment-edit').hide(); 1101 $ct.find('.guru-comment-delete').hide(); 1102 $ct.find('.guru-comment-save').show(); 1103 } 1104 1105 function commentOnEditSave(e) { 1106 var $button = $(e.currentTarget), 1107 $ct = $button.closest('.guru-reply-body'), 1108 $text = $ct.find('.guru-text'), 1109 $textarea = $ct.find('textarea'), 1110 data = $button.data(), 1111 message = $textarea.val(), 1112 url; 1113 1114 // optimistic update 1115 $text.html(message).show(); 1116 $textarea.hide(); 1117 $ct.find('.guru-comment-edit').show(); 1118 $ct.find('.guru-comment-delete').show(); 1119 $ct.find('.guru-comment-save').hide(); 1120 1121 message = encodeURIComponent(message); 1122 url = params.uri + 'index.php?option=com_guru&controller=guruTasks&task=edit_comment&lessonid=' + data.id + '&comid=' + data.resultId + '&message=' + message + '&ajax=1&Itemid=' + params.item_id; 1123 1124 $.ajax({ 1125 url: url, 1126 type: 'get', 1127 dataType: 'json', 1128 success: function () { } 1129 }); 1130 } 1131 1132 function commentOnDelete(e) { 1133 var $button = $(e.currentTarget), 1134 data = $button.data(), 1135 url; 1136 1137 $button.closest('.guru-lesson-comment').remove(); 1138 url = params.uri + 'index.php?option=com_guru&controller=guruTasks&task=delete_comment&lessonid=' + data.id + '&uid=' + data.resultUser + '&comid=' + data.resultId + '&ajax=1&Itemid=' + params.item_id; 1139 1140 $.ajax({ 1141 url: url, 1142 type: 'get', 1143 dataType: 'json', 1144 success: function () { } 1145 }); 1146 } 1147 1148 function setModalActiveIfIsCurrent() { 1149 var parent_class = $(".guru-lesson-nav-current").parent().attr('class'); 1150 1151 $(".active-module").removeClass("active-module"); 1152 1153 if (parent_class == "guru-lesson-nav-module") { 1154 parent = $(".guru-lesson-nav-current").parent(); 1155 //parent.attr('class', "guru-lesson-nav-module active-module"); 1156 } 1157 else { 1158 $(".guru-lesson-nav-module").removeClass("active-module"); 1159 } 1160 } 1161 1162 window.openMyModalNew = function (width, height, source, _params) { 1163 params = _params; 1164 createModal(source); 1165 }; 1166 1167 window.reloadCourseLessonsBarJS = function () { 1168 params.cid = params.current_lesson; 1169 getSidebarContent(); 1170 }; 1171}); 1172 1173function redirectCourseAfterComplete(redirect_url) { 1174 lessons_not_viewed = document.getElementsByClassName("not-view"); 1175 1176 if (lessons_not_viewed.length == 0) { 1177 window.location.href = redirect_url; 1178 } 1179 else { 1180 //alert(course_not_completed_lang); 1181 return false; 1182 } 1183} 1184 1185function guruJumpTo(id) { 1186 const $list = document.querySelector('.guru-jump-group-button'); 1187 if ($list) { 1188 $list.classList.add('guru-modal-hidden'); 1189 setTimeout(() => { 1190 $list.classList.remove('guru-modal-hidden'); 1191 }, 100); 1192 } 1193 1194 if (document.getElementById('id-lesson-' + id)) { 1195 document.getElementById('id-lesson-' + id).click(); 1196 } else if (document.getElementById('id-module-' + id)) { 1197 document.getElementById('id-module-' + id).click(); 1198 } 1199}
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.