1function updateHistory(p = 0) { 2 var $ = jQuery; 3 4 if (typeof user_history_params == 'undefined') { 5 return; 6 } 7 8 if ($('.wp-manga-chapter-img').length > 0) { 9 var img = $('.wp-manga-chapter-img').prop('id'); 10 var img_id = img.replace('image-', ''); 11 } else { 12 var img_id = ''; 13 } 14 15 $.ajax({ 16 url: user_history_params.ajax_url, 17 type: 'POST', 18 data: { 19 action: 'manga-user-history', 20 postID: user_history_params.postID, 21 chapterSlug: user_history_params.chapter, 22 paged: p ? p : user_history_params.page, 23 img_id: img_id, 24 nonce: user_history_params.nonce 25 } 26 }); 27} 28 29function madara_update_views() { 30 var $ = jQuery; 31 32 if ($('body').hasClass('single-wp-manga')) { 33 // is Manga Detail or Reading page 34 if (typeof manga !== 'undefined') { 35 if (manga.enable_manga_view != "0") { 36 $.ajax({ 37 url: manga.ajax_url, 38 type: 'POST', 39 data: { 40 action: 'manga_views', 41 manga: manga.manga_id, 42 chapter: manga.chapter_slug 43 }, 44 success: function (data) { 45 //console.log(data); 46 }, 47 complete: function (e) { 48 //console.log(e.responseJSON); 49 } 50 }); 51 } 52 } 53 } 54} 55 56window.wpmanga = {}; 57window.wpmanga.setCookie = function (cname, cvalue, exdays) { 58 var d = new Date(); 59 d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); 60 var expires = "expires=" + d.toUTCString(); 61 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; 62} 63 64window.wpmanga.getCookie = function (cname) { 65 var name = cname + "="; 66 var decodedCookie = decodeURIComponent(document.cookie); 67 var ca = decodedCookie.split(';'); 68 for (var i = 0; i < ca.length; i++) { 69 var c = ca[i]; 70 while (c.charAt(0) == ' ') { 71 c = c.substring(1); 72 } 73 if (c.indexOf(name) == 0) { 74 return c.substring(name.length, c.length); 75 } 76 } 77 return ""; 78} 79 80window.wpmanga.removeCookie = function (cname) { 81 document.cookie = cname + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; 82} 83 84jQuery(document).ready(function ($) { 85 86 function readingScrollToTop() { 87 $('html, body').animate({ scrollTop: $('.c-blog-post .reading-content').offset().top }, 500); 88 } 89 90 var wp_manga_load_chapters = (page, callback) => { 91 92 $.ajax({ 93 url: manga.base_url + 'ajax/chapters/?t=' + page, 94 type: 'POST', 95 context: { 96 page 97 }, 98 success: function (data) { 99 $('#manga-chapters-holder').html(data); 100 101 $(document).trigger('wp_manga_after_load_chapters_list'); 102 callback(page); 103 }, 104 complete: function (e) { 105 106 } 107 }); 108 } 109 110 if ($('#manga-chapters-holder').length) { 111 wp_manga_load_chapters(1, () => {}); 112 } else { 113 setTimeout(function () { $(document).trigger('wp_manga_after_load_chapters_list'); }, 1000); 114 } 115 116 $(document).on('wp_manga_after_load_chapters_list', function(){ 117 if($('.listing-chapters_wrap .pagination').length){ 118 $('.listing-chapters_wrap .pagination .page a').on('click', function(){ 119 if(!$('.listing-chapters_wrap .pagination').hasClass('loading')){ 120 if(!$(this).parent().hasClass("current")){ 121 $('.listing-chapters_wrap .pagination').addClass('loading'); 122 123 var page = $(this).data('page'); 124 125 wp_manga_load_chapters(page, (page) => { 126 $('.listing-chapters_wrap .pagination').removeClass('loading'); 127 $('.listing-chapters_wrap .pagination .page').removeClass("current"); 128 $('.listing-chapters_wrap .pagination .page-' + page).addClass("current"); 129 }); 130 } 131 } 132 133 return false; 134 }) 135 } 136 }) 137 138 function load_chapters_selectbox() { 139 if ($('.chapter-selection').length > 0) { 140 var selector = $('.chapter-selection'); 141 var args = { 142 action: 'manga_get_reading_nav', 143 manga: $(selector[0]).data('manga'), 144 chapter: $(selector[0]).data('chapter'), 145 volume_id: $(selector[0]).data('vol'), 146 style: $(selector[0]).data('style'), 147 type: $(selector[0]).data('type'), 148 }; 149 150 $.ajax({ 151 url: manga.ajax_url, 152 type: 'POST', 153 data: args, 154 success: function (data) { 155 $('.chapter-selection').each(function () { 156 $(this).html(data); 157 }); 158 159 $(document).trigger('wp_manga_after_load_reading_nav'); 160 }, 161 complete: function (e) { 162 //console.log(e.responseJSON); 163 } 164 }); 165 } else { 166 // trigger to register onclick eevnt 167 $(document).trigger('wp_manga_after_load_reading_nav'); 168 } 169 } 170 171 function chapterNavigationAjax(navigation) { 172 if (typeof window.manga_navigating !== 'undefined' && window.manga_navigating) { 173 return; // flag to prevent recursive event 174 } 175 176 if (typeof mangaReadingAjax == 'undefined') { 177 return false;
178 } 179 180 var readContainer = $('.read-container'), 181 loadingHTML = '<i class="fas fa-spinner fa-spin"></i>', 182 currentPageSelect = $('.wp-manga-nav select#single-pager > option[selected="selected"]'), 183 prevBtn = $('.nav-links .nav-previous'), 184 nextBtn = $('.nav-links .nav-next'), 185 breadCrumb = $('.wp-manga-nav .entry-header_wrap').html(), 186 pagination = $('.select-pagination'); 187 188 window.manga_navigating = true; 189 190 $.ajax({ 191 type: 'GET', 192 url: manga.ajax_url + '?' + navigation, 193 beforeSend: function () { 194 readContainer.html(loadingHTML); 195 pagination.hide(); 196 $('.wp-manga-nav select').each(function () { 197 $(this).prop('disabled', true); 198 }); 199 }, 200 success: function (response) { 201 if (response.success) { 202 203 readContainer.html(response.data.data.content); 204 205 $('.wp-manga-nav').replaceWith(response.data.data.nav); 206 $('.entry-header .wp-manga-nav').prepend('<div class="entry-header_wrap">' + breadCrumb + '</div>'); 207 208 pagination.show(); 209 210 // reattach events 211 wp_manga_on_chapter_navlinks_click(); 212 madara_update_views(); 213 load_chapters_selectbox(); 214 215 $('.wp-manga-nav select').each(function () { 216 $(this).prop('disabled', false); 217 }); 218 219 if (typeof updateHistory !== 'undefined') { 220 updateHistory($('#single-pager').val()); 221 } 222 223 } else { 224 readContainer.html(response.data.message); 225 } 226 227 readingScrollToTop(); 228 229 window.manga_navigating = false; 230 $(document).trigger('wp_manga_chapterNavigationAjax_done'); 231 }, 232 error: function (xhr, textStatus) { 233 window.manga_navigating = false; 234 } 235 }); 236 } 237 238 function chapterPreloadedImagesNavigation(next = true) { 239 240 var $curPage = $('#single-pager'), 241 curPageVal = $curPage.val(); 242 243 if (next) { 244 curPageVal++; 245 } else { 246 curPageVal--; 247 } 248 249 var resp = loadPreloadedImage(curPageVal); 250 251 return resp; 252 253 } 254 255 function loadPreloadedImage(page) { 256 257 readingScrollToTop(); 258 259 page = parseInt(page); 260 261 var curPageOption = $('#single-pager option[value="' + page + '"]'); 262 var $readingContent = $('.reading-content'); 263 264 if (curPageOption.length > 0) { 265 266 // Mark destination page as selected 267 $('.selectpicker_page select').each(function () { 268 $('option', $(this)).removeAttr('selected'); 269 $('option[value="' + page + '"]', $(this)).prop('selected', true); 270 $('option[value="' + page + '"]', $(this)).attr('selected', 'selected'); 271 $(this).val(page); 272 }); 273 274 // Change the URL in prev & next btn 275 var prevPage = page - 1, 276 nextPage = page + 1, 277 prevPageOption = $('#single-pager option[value="' + prevPage + '"]'), 278 nextPageOption = $('#single-pager option[value="' + nextPage + '"]'); 279 280 var volSelect = $('.volume-select'); 281 282 var mangaHasVolume = volSelect.length > 0 ? true : false; 283 284 var curVol = mangaHasVolume ? volSelect.val() : 0; 285 286 var curVolChapSelect = $('.selectpicker_chapter[for="volume-id-' + curVol + '"] .single-chapter-select'); 287 288 if (typeof curVolChapSelect === 'undefined' || typeof curVolChapSelect[0] === 'undefined') { 289 // chapter list is not loaded yet 290 return; 291 } 292 293 selector = curVolChapSelect.first(); 294 295 // Index starts from 1 296 var curChapIndex = selector.find(":selected").index() + 1, 297 curVolIndex = mangaHasVolume ? volSelect[0].selectedIndex + 1 : null; 298 299 var vol_order = mangaHasVolume ? $(volSelect[0]).data('order') : 0; // smallest, oldest Vol on top (1) || biggest, latest Vol on top (0) 300 301 if (mangaHasVolume) { 302 volSelect = $(volSelect[0]); 303 } 304 305 var nextBtn = $('.nav-next a'), 306 prevBtn = $('.nav-previous a'); 307 var order = nextBtn.data('order'); // ASC time or z-a (1) | DESC time or a-z(0) 308 309 // On any case, show both btn first 310 nextBtn.show(); 311 prevBtn.show(); 312 313 // Handle prev 314 var prevURL = ''; 315 var prevNavURL = ''; 316 317 if (prevPageOption.length > 0) { 318 319 // console.log( 'Chapter has prev page' ); 320 321 prevURL = prevPageOption.data('redirect'); 322 323 prevNavURL = $('.nav-next a').data('navigation'); 324 325 if (typeof prevNavURL !== 'undefined') { 326 var replace = manga.manga_paged_var + '=(\d+)'; 327 var re = new RegExp(replace, "g"); 328 329 prevNavURL = prevNavURL.replace(re, prevPage); 330 } 331 } else { 332 // If this is first page of chapter 333 var prevChapIndex = (order ? curChapIndex + 1 : curChapIndex - 1); 334 var prevVolIndex = mangaHasVolume ? (vol_order ? curVolIndex - 1 : curVolIndex + 1) : null; 335 var prevVolChapList = mangaHasVolume ? $('.selectpicker_chapter:nth-child(' + prevVolIndex + ') .single-chapter-select').first() : null; 336
337 if ((prevChapIndex <= 0 && !order) || (order && prevChapIndex > selector.find('option').length)) { 338 // If this is the first chapter of the volume 339 340 // console.log( 'First chap' ); 341 if (prevVolIndex === null || (mangaHasVolume && vol_order && prevVolIndex <= 0) || (mangaHasVolume && !vol_order && prevVolIndex > volSelect.find('option').length)) { 342 343 // console.log( 'First volume' ); 344 345 // If it's the first volume then hide the prev button 346 prevBtn.hide(); 347 } else { 348 // Else go to the last chapter of prev volume 349 var prevChapSelect = prevVolChapList.find('option:nth-child(' + (order ? 2 : prevVolChapList.find('option').length) + ')'); 350 351 prevURL = prevChapSelect.data('redirect'); 352 prevNavURL = prevChapSelect.data('navigation'); 353 } 354 } else { // if this isn't first chapter, then give prev chapter URL for prev btn 355 var curVolChapSelect = $('.selectpicker_chapter[for="volume-id-' + curVol + '"] .single-chapter-select'); 356 357 if (typeof curVolChapSelect === 'undefined' || typeof curVolChapSelect[0] === 'undefined') { 358 // chapter list is not loaded yet 359 return; 360 } 361 362 selector = curVolChapSelect.first(); 363 364 var prevChapSelect = $(selector).find('option:nth-child(' + prevChapIndex + ')'); 365 366 prevURL = prevChapSelect.data('redirect'); 367 prevNavURL = prevChapSelect.data('navigation'); 368 369 if (typeof prevChapLastPage !== 'undefined') { 370 // add manga-paged to prev chap URLs 371 prevURL = prevURL.replace('/p/1', '/p/' + prevChapLastPage); 372 prevNavURL += '&' + manga.manga_paged_var + '=' + prevChapLastPage; 373 } 374 } 375 } 376 prevBtn.data('navigation', prevNavURL); 377 prevBtn.attr('href', prevURL); 378 379 // Handle next 380 var nextURL = ''; 381 var nextNavURL = ''; 382 var lastPageOfLastChap = false; 383 384 if (nextPageOption.length > 0) { // if there is next page on chapter 385 386 // console.log( 'Chapter has next page' ); 387 388 nextURL = nextPageOption.data('redirect'); 389 390 nextNavURL = $('.nav-next a').data('navigation'); 391 392 if (typeof nextNavURL !== 'undefined') { 393 var replace = manga.manga_paged_var + '=(\d+)'; 394 var re = new RegExp(replace, "g"); 395 396 nextNavURL = nextNavURL.replace(re, nextPage); 397 } 398 399 } else { // If this is the last page of chapter 400 401 // console.log( 'Chapter ended' ); 402 403 var nextChapIndex = (order ? curChapIndex - 1 : curChapIndex + 1); 404 405 var curVolChapSelect = $('.selectpicker_chapter[for="volume-id-' + curVol + '"] .single-chapter-select'); 406 407 if (typeof curVolChapSelect === 'undefined' || typeof curVolChapSelect[0] === 'undefined') { 408 // chapter list is not loaded yet 409 return; 410 } 411 412 selector = curVolChapSelect.first(); 413 414 if ((curChapIndex === $(selector).find('option').length && !order) || (curChapIndex == 1 && order)) { // If this is the last chapter of volume 415 416 // console.log( 'Volume ended' ); 417 418 var nextVolIndex = mangaHasVolume ? (vol_order ? curVolIndex + 1 : curVolIndex - 1) : null; 419 420 if (!mangaHasVolume || (curVolIndex === volSelect.find('option').length && vol_order) || (curVolIndex === 1 && !vol_order)) { //If it's last volume or manga has no volume and this is the last chap 421 422 // console.log( 'Manga ended' ); 423 424 // If it's the last page of last chap 425 if (mangaNav.backInfoPage == 'on' && $('.btn-primary .back').length == 0) { 426 nextBtn.text(mangaNav.text.backInfoPage).removeClass('next_page').addClass('back'); 427 nextURL = mangaNav.mangaUrl; 428 lastPageOfLastChap = true; 429 } else { //hide if there's no back info page 430 nextBtn.hide(); 431 } 432 } else { 433 // Else go to the first chapter of next volume 434 var nextVolChapList = $('.selectpicker_chapter:nth-child(' + nextVolIndex + ') .single-chapter-select').first(); 435 var nextChapSelect = nextVolChapList.find('option:nth-child(' + (order ? nextVolChapList.find('option').length : 2) + ')'); 436 437 nextURL = nextChapSelect.data('redirect'); 438 nextNavURL = nextChapSelect.data('navigation'); 439 } 440 } else { // if this isn't last chapter, then give next chapter URL for next btn 441 var curVolChapSelect = $('.selectpicker_chapter[for="volume-id-' + curVol + '"] .single-chapter-select'); 442 443 if (typeof curVolChapSelect === 'undefined' || typeof curVolChapSelect[0] === 'undefined') { 444 // chapter list is not loaded yet 445 return; 446 } 447 448 selector = curVolChapSelect.first(); 449 450 var nextChapSelect = $(selector).find('option:nth-child(' + nextChapIndex + ')'); 451 452 nextURL = nextChapSelect.data('redirect'); 453 nextNavURL = nextChapSelect.data('navigation'); 454 } 455 } 456 457 nextBtn.data('navigation', nextNavURL); 458 nextBtn.attr('href', nextURL); 459 460 // if it's not last page of last chap, make sure it has correct class and text of Next button 461 if (!lastPageOfLastChap) { 462 nextBtn.text(mangaNav.text.next).addClass('next_page').removeClass('back'); 463 } 464 465 // Remove all current images 466 $readingContent.find('img').remove(); 467 468 var paged = chapter_images_per_page * (page - 1) + 1; 469 var hasCursorLink = $('.reading-content .page-prev-link').length; 470 471 var images_html = ''; 472 for (var i = 1; i <= chapter_images_per_page; i++) { 473 474 if (typeof chapter_preloaded_images[paged - 1] !== 'undefined') { 475 images_html += '<img id="image-' + paged + '" data-image-paged="' + paged + '" src="' + chapter_preloaded_images[paged - 1] + '" class="wp-manga-chapter-img">'; 476 477 paged++; 478 } else { 479 break; 480 } 481 } 482 483 if (hasCursorLink) { //If there is cursor link then append after the prev cursor link 484 $(images_html).insertAfter('.reading-content .page-prev-link'); 485 } else { //or just append it to .reading-content 486 $('.reading-content').append(images_html); 487 } 488 489 if (typeof updateHistory !== 'undefined') { 490 updateHistory(paged); 491 } 492 493 $(document).trigger('wp_manga_after_load_chapter_page', [page]); 494 495 return true; 496 } else { 497 return false;
498 } 499 500 } 501 502 $(document).on('wp_manga_chapterNavigationAjax_done', function () { 503 if (typeof updateHistory !== 'undefined') { 504 user_history_params.chapter = $('.single-chapter-select').val(); 505 updateHistory(1); 506 } 507 }); 508 509 $('.btn-text-reading-increase').on('click', function (e) { 510 var fontSize = $('.reading-content .text-left').css('font-size'); 511 var newFontValue = parseInt(fontSize.replace('px', '')) + 1; 512 $('.reading-content .text-left').css('font-size', newFontValue + 'px'); 513 $('.reading-content .text-left').css('line-height', (newFontValue * 1.5) + 'px'); 514 // save cookie 515 window.wpmanga.setCookie('wpmanga-reading-fontsize', newFontValue, 30); 516 517 e.preventDefault(); 518 e.stopPropagation(); 519 return false; 520 }); 521 522 $('.btn-text-reading-decrease').on('click', function (e) { 523 var fontSize = $('.reading-content .text-left').css('font-size'); 524 var newFontValue = parseInt(fontSize.replace('px', '')) - 1; 525 $('.reading-content .text-left').css('font-size', (newFontValue < 5 ? 5 : newFontValue) + 'px'); 526 527 $('.reading-content .text-left').css('line-height', (newFontValue < 5 ? 7.5 : newFontValue * 1.5) + 'px'); 528 529 // save cookie 530 window.wpmanga.setCookie('wpmanga-reading-fontsize', newFontValue, 30); 531 532 e.preventDefault(); 533 e.stopPropagation(); 534 return false; 535 }); 536 537 $('#text-chapter-toolbar a').on('click', function (e) { 538 $('.entry-header.footer').toggleClass('sticky'); 539 $('#text-chapter-toolbar').toggleClass('sticky'); 540 541 e.preventDefault(); 542 e.stopPropagation(); 543 return false; 544 }); 545 546 // Handle navigate by clicked Back/Forward in button in browser 547 /* 548 * Temp remove it as it reloads page even on link with hashtag 549 550 $(window).on('popstate', function () { 551 552 var curURL = window.location.href, 553 use_preloaded_images = false, 554 redirect = true, 555 navNext = $('.select-pagination .nav-links .nav-next > a.next_page'), 556 navPrev = $('.select-pagination .nav-links .nav-next > a.prev_page'), 557 isNext = false; 558 559 if (curURL == navNext.attr('href')) { 560 isNext = true; 561 navigation = navNext.data('navigation'); 562 } else if (curURL == navPrev.attr('href')) { 563 navigation = navPrev.data('navigation'); 564 } 565 566 // If use preloaded images is on, then use it first 567 if (typeof chapter_preloaded_images !== 'undefined') { 568 use_preloaded_images = chapterPreloadedImagesNavigation(isNext ? true : false ); 569 570 if (use_preloaded_images) { 571 redirect = false; 572 } 573 } 574 575 // If use preloaded image failed, then use ajax if it's on 576 if (!use_preloaded_images && typeof navigation !== 'undefined' && navigation !== '' && typeof mangaReadingAjax !== 'undefined') { 577 chapterNavigationAjax(navigation); 578 redirect = false; 579 } 580 581 if (redirect) { 582 window.location.reload(); 583 } 584 585 }); 586 587 **/ 588 589 function wp_manga_on_chapter_navlinks_click() { 590 //chapter next page ajax 591 $('.wp-manga-nav .nav-links > div > a.btn').each(function () { 592 $(this).unbind('click'); 593 $(this).on('click', function (e) { 594 if ($(this).hasClass('back')) { 595 return true; 596 } 597 598 var navigation = $(this).data('navigation'), 599 url = $(this).attr('href'); 600 601 var use_preloaded_images = false, 602 redirect = true; 603 604 // If use preloaded images is on, then use it first 605 if (typeof chapter_preloaded_images !== 'undefined') { 606 use_preloaded_images = chapterPreloadedImagesNavigation($(this).hasClass('next_page') ? true : false); 607 608 if (use_preloaded_images) { 609 e.preventDefault(); 610 redirect = false; 611 } 612 } 613 614 // If use preloaded image failed, then use ajax if it's on 615 if (!use_preloaded_images && typeof navigation !== 'undefined' && navigation !== '' && typeof mangaReadingAjax !== 'undefined') { 616 e.preventDefault(); 617 618 $(document).trigger('wp_manga_on_chapter_navlinks_click'); 619 620 chapterNavigationAjax(navigation); 621 redirect = false; 622 } 623 624 if (typeof url !== 'undefined' && url !== '') { 625 history.pushState({}, null, url); 626 } 627 628 if (redirect) { 629 window.location = url; 630 return true; 631 } else { 632 return false; 633 } 634 635 }); 636 }); 637 } 638 wp_manga_on_chapter_navlinks_click(); 639 640 // if reading list style is used, scroll on mouse click 641 function wp_manga_scroll_on_click() { 642 if ($('body').hasClass('click-to-scroll')) { 643 $('.manga-reading-list-style .chapter-type-manga .reading-content').on('click', function (e) { 644 if (e.target.nodeName != 'INPUT') { 645 $('html, body').animate({ scrollTop: $(document).scrollTop() + 500 }, 200); 646 } 647 }); 648 649 $('.chapter-type-text .reading-content').on('click', function (e) { 650 if (e.target.nodeName != 'INPUT') { 651 $('html, body').animate({ scrollTop: $(document).scrollTop() + 500 }, 1000); 652 } 653 }); 654 } 655 } 656 wp_manga_scroll_on_click(); 657 658 /* 659 $(document).on('click', '.chapter-type-manga .c-blog-post .entry-content .entry-content_wrap .reading-content img', function(e){ 660 e.preventDefault(); 661 if($('.wp-manga-nav .nav-links a.next_page').length > 0){ 662 $('.wp-manga-nav .nav-links a.next_page')[0].click(); 663 } 664 }); 665 */ 666 667 //navigate by keyword button 668 if ($('body').hasClass('keyboard-navigate')) { 669 $(document).keydown(function (e) { 670 var redirect = ''; 671 672 // check if there is any focus input or textarea 673 if (document.activeElement && document.activeElement.tagName == 'INPUT' || document.activeElement.tagName == 'TEXTAREA' || e.target.className.includes('ql-editor')) { 674 return; 675 } 676 677 if (e.keyCode == 37 && $('.wp-manga-nav .nav-links .nav-previous > a').length > 0) { //left key 678 $('.wp-manga-nav .nav-links a.prev_page')[0].click(); 679 } else if (e.keyCode == 39 && $('.wp-manga-nav .nav-links .nav-next > a').length > 0) { //right key 680 $('.wp-manga-nav .nav-links a.next_page')[0].click(); 681 } 682 }); 683 } 684 685 //prevent empty Comment content submitting 686 $(document).ready(function () { 687 $('textarea#comment').attr('required', 'required'); 688 689 $('#commentform').on('submit', function () { 690 if (!$('#commentform')[0].checkValidity()) {
691 alert('Comment cannot be empty'); 692 return false; 693 } 694 return true; 695 }); 696 697 load_chapters_selectbox(); 698 }); 699 700 $(document).on('wp_manga_after_load_reading_nav', function () { 701 //show appropriate chapter select for volume 702 $(document).on('change', '.selectpicker.volume-select', function () { 703 $('.chapters_selectbox_holder .c-selectpicker.selectpicker_chapter').each(function () { 704 $(this).hide(); 705 }); 706 $('.chapters_selectbox_holder .c-selectpicker.selectpicker_chapter[for="volume-id-' + $(this).val() + '"]').show(); 707 }); 708 709 $(document).on('change', '.wp-manga-nav .single-chapter-select, #single-pager, .wp-manga-nav .host-select, .wp-manga-nav .reading-style-select', function (e) { 710 711 e.preventDefault(); 712 713 var isPageSelect = $(this).attr('id') == 'single-pager' ? true : false; 714 var isChapterSelect = $(this).hasClass('single-chapter-select') ? true : false; 715 716 if (isPageSelect || isChapterSelect) { 717 var navigation = $(this).find('option:selected').data('navigation'); 718 var url = $(this).find('option:selected').data('redirect'); 719 720 var use_preloaded_images = false, 721 redirect = true; 722 723 if (isPageSelect && typeof chapter_preloaded_images !== 'undefined') { 724 $(this).blur(); 725 use_preloaded_images = loadPreloadedImage($(this).val()); 726 727 if (use_preloaded_images) { 728 redirect = false; 729 } 730 } 731 732 if (!use_preloaded_images && typeof mangaReadingAjax !== 'undefined' && typeof navigation !== 'undefined' && navigation !== '') { 733 chapterNavigationAjax(navigation); 734 redirect = false; 735 } 736 737 if (!redirect) { 738 if (typeof url !== 'undefined' && url !== '') { 739 history.pushState({}, null, url); 740 } 741 742 return false; 743 } 744 745 } 746 747 var t = $(this); 748 var redirect = t.find(':selected').attr('data-redirect'); 749 750 if (redirect != '#') { 751 window.location = redirect; 752 } 753 754 $(document).trigger('wp_manga_chapter_redirect', [$(this), redirect, isPageSelect, isChapterSelect]); 755 }); 756 }); 757 758 var ajaxHandling = false; 759 var loginModal = false; 760 761 // bookmark action 762 $(document).on('click', '.wp-manga-action-button', function (e) { 763 764 e.preventDefault(); 765 766 if ($(this).attr('data-action') == 'bookmark') { 767 if (typeof requireLogin2BookMark !== 'undefined') { 768 $('.modal#form-login').modal('show'); 769 $('input[name="bookmarking"]').val('1'); 770 return; 771 } 772 773 if ($('.add-bookmark').length != 0) { 774 $('.add-bookmark').css('opacity', '0.5'); 775 } else { 776 // chapter reading page 777 var li = $('.action_list_icon a.wp-manga-action-button[data-action="bookmark"]').parent(); 778 li.css('opacity', '0.5'); 779 } 780 781 if (!ajaxHandling) { 782 ajaxHandling = true; 783 var t = $(this); 784 var postID = t.data('post'); 785 786 var volSelect = $('.volume-select'); 787 788 var mangaHasVolume = volSelect.length > 0 ? true : false; 789 790 var curVol = mangaHasVolume ? volSelect.val() : 0; 791 792 var curVolChapSelect = $('.selectpicker_chapter[for="volume-id-' + curVol + '"] .single-chapter-select'); 793 794 var chapter = $('#wp-manga-current-chap').length > 0 ? $('#wp-manga-current-chap').val() : ''; // get selected chapter slug 795 796 var page = t.data('page'); 797 jQuery.ajax({ 798 url: manga.ajax_url, 799 type: 'POST', 800 data: { 801 action: 'wp-manga-user-bookmark', 802 postID: postID, 803 chapter: chapter, 804 page: page, 805 }, 806 success: function (response) { 807 if (response.success) { 808 if ($('.add-bookmark').length != 0) { 809 // manga detail page 810 $('.add-bookmark').empty(); 811 $('.add-bookmark').append(response.data); 812 $('.add-bookmark').css('opacity', '1'); 813 } else { 814 // chapter reading page 815 var li = 816 $('.action_list_icon a.wp-manga-action-button[data-action="bookmark"]').parent(); 817 li.empty(); 818 li.append(response.data); 819 li.css('opacity', '1'); 820 } 821 822 } else { 823 if (!response.data) { 824 alert('Some errors occured. Please try again'); 825 } else { 826 if (response.data.code == 'login_error') { 827 828 } else { 829 alert(response.data.code); 830 } 831 } 832 } 833 }, 834 complete: function (xhr, textStatus) { 835 ajaxHandling = false;
836 } 837 }); 838 } 839 } else { 840 if ($(this).attr('data-action') == 'toggle-contrast') { 841 $('body').toggleClass('text-ui-light'); 842 843 // save cookie 844 window.wpmanga.setCookie('wpmanga-reading-contrast', $('body').hasClass('text-ui-light') ? 'light' : 'dark', 30); 845 846 if (typeof DISQUS !== 'undefined') { 847 DISQUS.reset({ 848 reload: true, 849 config: disqus_config 850 }); 851 } 852 } 853 } 854 }) 855 856 var ajaxBookmarkDelete = false; 857 $(document).on('click', '.wp-manga-delete-bookmark', function (e) { 858 859 e.preventDefault(); 860 861 if (!ajaxBookmarkDelete) { 862 863 ajaxBookmarkDelete = true; 864 var t = $(this); 865 var postID = t.data('post-id'); 866 var rowBookmark = $(this).closest("tr"); 867 868 if (rowBookmark.length != 0) { 869 rowBookmark.css('opacity', '0.5'); 870 var isMangaSingle = 0; 871 } 872 873 if ($('.add-bookmark .action_icon .wp-manga-delete-bookmark').length != 0) { 874 var isMangaSingle = 1; 875 $('.add-bookmark').css('opacity', '0.5'); 876 } else { 877 var isMangaSingle = 0; 878 // chapter reading page 879 var li = $('.action_list_icon a.wp-manga-action-button[data-action="bookmark"]').parent(); 880 li.css('opacity', '0.5'); 881 } 882 883 jQuery.ajax({ 884 url: manga.ajax_url, 885 type: 'POST', 886 data: { 887 action: 'wp-manga-delete-bookmark', 888 postID: postID, 889 isMangaSingle: isMangaSingle 890 }, 891 success: function (response) { 892 if (response.success) { 893 if (rowBookmark.length != 0) { 894 rowBookmark.fadeOut(); 895 rowBookmark.remove(); 896 } 897 if (typeof isMangaSingle !== 'undefined' && isMangaSingle == true) { 898 $('.add-bookmark').empty(); 899 $('.add-bookmark').append(response.data); 900 $('.add-bookmark').css('opacity', '1'); 901 } else if (typeof isMangaSingle !== 'undefined' && isMangaSingle == false) { 902 if (response.data.is_empty == true) { 903 alert(response.data.msg); 904 } else { 905 // chapter reading page 906 var li = $('.action_list_icon a.wp-manga-delete-bookmark').parent(); 907 li.empty(); 908 li.append(response.data); 909 li.css('opacity', '1'); 910 } 911 } 912 } 913 }, 914 complete: function (xhr, textStatus) { 915 ajaxBookmarkDelete = false; 916 } 917 }); 918 } 919 }) 920 921 var ajaxBookmarkDelete = false; 922 $(document).on('click', '#delete-bookmark-manga', function (e) { 923 e.preventDefault(); 924 if (!ajaxBookmarkDelete) { 925 ajaxBookmarkDelete = true; 926 var bookmark = []; 927 $('.bookmark-checkbox:checkbox:checked').each(function (i) { 928 bookmark[i] = $(this).val(); 929 $(this).closest('tr').addClass('remove'); 930 $(this).closest('tr').css('opacity', '0.5'); 931 }); 932 jQuery.ajax({ 933 url: manga.ajax_url, 934 type: 'POST', 935 data: { 936 action: 'wp-manga-delete-multi-bookmark', 937 bookmark: bookmark, 938 }, 939 success: function (response) { 940 941 if (response.success) { 942 $('tr.remove').remove(); 943 } 944 }, 945 complete: function (xhr, textStatus) { 946 ajaxBookmarkDelete = false; 947 } 948 }); 949 } 950 }) 951 952 $(document).on('change', '#wp-manga-bookmark-checkall', function (e) { 953 e.preventDefault(); 954 var t = $(this); 955 var chechbox = $('.bookmark-checkbox'); 956 if (chechbox.length > 0) { 957 if (t.is(':checked')) { 958 $.each(chechbox, function (i, e) { 959 $(e).prop('checked', true); 960 }) 961 } else { 962 $.each(chechbox, function (i, e) { 963 $(e).prop('checked', false); 964 }) 965 } 966 } 967 }) 968 969 // search 970 // manga-search-field 971 $('form.manga-search-form.ajax input.manga-search-field').each(function () { 972 973 var searchIcon = $(this).parent().children('.ion-ios-search-strong'); 974 975 var append = $(this).parent(); 976 977 $(this).autocomplete({ 978 appendTo: append, 979 source: function (request, resp) { 980 $.ajax({ 981 url: manga.ajax_url, 982 type: 'POST', 983 dataType: 'json', 984 data: { 985 action: 'wp-manga-search-manga', 986 title: request.term, 987 }, 988 success: function (data) { 989 resp($.map(data.data, function (item) { 990 if (true == data.success) { 991 return { 992 label: item.title, 993 value: item.title, 994 url: item.url, 995 type: item.type 996 } 997 } else { 998 return { 999 label: item.message, 1000 value: item.message, 1001 type: item.type, 1002 click: false 1003 } 1004 } 1005 })) 1006 } 1007 }); 1008 }, 1009 select: function (e, ui) { 1010 if (ui.item.url) { 1011 window.location.href = ui.item.url; 1012 } else { 1013 if (ui.item.click) { 1014 return true; 1015 } else { 1016 return false;
1017 } 1018 } 1019 }, 1020 open: function (e, ui) { 1021 var acData = $(this).data('uiAutocomplete'); 1022 acData.menu.element.addClass('manga-autocomplete').find('li div').each(function () { 1023 var $self = $(this), 1024 keyword = $.trim(acData.term).split(' ').join('|'); 1025 $self.html($self.text().replace(new RegExp("(" + keyword + ")", "gi"), '<span class="manga-text-highlight">$1</span>')); 1026 }); 1027 }, 1028 change: function (e, ui) { 1029 return false; 1030 } 1031 }).autocomplete("instance")._renderItem = function (ul, item) { 1032 return $("<li class='search-item'>") 1033 .append("<div class='manga-type-" + item.type + "'>" + item.label + "</div>") 1034 .appendTo(ul); 1035 }; 1036 }); 1037 1038 $('input[name="wp-manga-user-avatar"]').on('change', function (e) { 1039 if (this.files.length) { 1040 $('.file-name').html(this.files[0].name); 1041 } else { 1042 $('.file-name').html(''); 1043 } 1044 }); 1045 1046 $(document).on('click', '#wp-manga-upload-avatar', function (e) { 1047 1048 e.preventDefault(); 1049 1050 var thisBtn = $(this), 1051 chooseAvatar = $('.choose-avatar'), 1052 userAvatarSection = $('.c-user-avatar'); 1053 1054 var fd = new FormData(); 1055 var userAvatar = $('input[name="wp-manga-user-avatar"]')[0].files[0]; 1056 var userID = $('input[name="userID"]').val(); 1057 var _wpnonce = $('input[name="_wpnonce"]').val(); 1058 1059 fd.append('action', 'wp-manga-upload-avatar'); 1060 fd.append('userAvatar', userAvatar); 1061 fd.append('userID', userID); 1062 fd.append('_wpnonce', _wpnonce); 1063 1064 jQuery.ajax({ 1065 url: manga.ajax_url, 1066 type: 'POST', 1067 enctype: 'multipart/form-data', 1068 cache: false, 1069 contentType: false, 1070 processData: false, 1071 data: fd, 1072 beforeSend: function () { 1073 thisBtn.attr('disabled', 'disabled'); 1074 chooseAvatar.addClass('uploading'); 1075 }, 1076 success: function (response) { 1077 if (response.success) { 1078 userAvatarSection.empty(); 1079 userAvatarSection.append(response.data); 1080 } else { 1081 alert(response.data.msg); 1082 } 1083 }, 1084 complete: function (response, xhr) { 1085 thisBtn.removeAttr('disabled'); 1086 chooseAvatar.removeClass('uploading'); 1087 } 1088 }); 1089 1090 }); 1091 1092 $(document).on('click', '.remove-manga-history', function (e) { 1093 e.preventDefault(); 1094 var postID = $(this).data('manga'); 1095 var item = $(this).closest('.col-md-4'); 1096 1097 item.css('opacity', '0.5'); 1098 $.ajax({ 1099 url: manga.ajax_url, 1100 type: 'POST', 1101 data: { 1102 'action': 'manga-remove-history', 1103 'postID': postID, 1104 }, 1105 success: function (response) { 1106 if (response.success) { 1107 item.fadeOut(); 1108 item.remove(); 1109 if (response.data.is_empty == true) { 1110 $('.tab-pane#history').empty(); 1111 $('.tab-pane#history').append(response.data.msg); 1112 } 1113 } else { 1114 item.css('opacity', '1'); 1115 } 1116 } 1117 }); 1118 }); 1119 1120 //Ajax pagination 1121 var wpMangaAjaxPosts = false; 1122 1123 $(document).on('click', '.wp-manga-ajax-button', function (e) { 1124 1125 e.preventDefault(); 1126 if (wpMangaAjaxPosts == false) { 1127 1128 wpMangaAjaxPosts = true; 1129 1130 var t = $(this), 1131 e = $(this).data('element'), 1132 template = $(this).data('template'), 1133 button = $(this).parent(); 1134 1135 t.addClass('loading'); 1136 1137 $.ajax({ 1138 url: manga.ajax_url, 1139 type: 'POST', 1140 data: { 1141 action: 'wp_manga_archive_loadmore', 1142 manga_args: manga_args, 1143 template: template 1144 }, 1145 success: function (response) { 1146 t.removeClass('loading'); 1147 $('.wp-manga-query-vars').remove(); 1148 $(e).append(response); 1149 1150 if (manga_args.paged >= manga_args.max_num_pages) { 1151 button.remove(); 1152 } 1153 } 1154 }) 1155 1156 1157 } 1158 }); 1159 1160 // quick navigate to first chapter for Video Manga - disabled 1161 /* 1162 $(".page-item-detail.video").each(function () { 1163 $('.item-thumb a', $(this)).on('click', function (e) { 1164 var parent = $(this).closest('.page-item-detail'); 1165 1166 $latest_chapter = $('.list-chapter .chapter-item', parent)[0]; 1167 if ($latest_chapter) { 1168 var chapter_url = $($('.chapter a', parent)[0]).attr('href'); 1169 1170 location.href = chapter_url; 1171 1172 e.stopPropagation(); 1173 return false; 1174 } 1175 }); 1176 1177 }); 1178 */ 1179 1180 if ($('body').hasClass('reading-manga')) { 1181 var $schema_cookie = window.wpmanga.getCookie('wpmanga-reading-contrast'); 1182 if ($schema_cookie != '') { 1183 if ($schema_cookie == 'light') { 1184 $('body').addClass('text-ui-light'); 1185 $('body').removeClass('text-ui-dark'); 1186 } else { 1187 $('body').removeClass('text-ui-light'); 1188 $('body').addClass('text-ui-dark'); 1189 } 1190 } 1191 1192 var fontsize = window.wpmanga.getCookie('wpmanga-reading-fontsize'); 1193 if ($('.c-page-content.chapter-type-text').length > 0 && fontsize) { 1194 $('.reading-content .text-left').css('font-size', fontsize + 'px'); 1195 $('.reading-content .text-left').css('line-height', (fontsize * 1.5) + 'px'); 1196 } 1197 } 1198 1199 madara_update_views(); 1200}); 1201 1202if (typeof wpdiscuzAjaxObj !== 'undefined') { 1203 wpdiscuzAjaxObj.wp_manga_chapter_comment = function (data, isNative, isShowTopLoading) { 1204 data.append('chapterId', jQuery('#wp-manga-current-chap') ? jQuery('#wp-manga-current-chap').data('id') : ''); 1205 return data; 1206 }; 1207}
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.