MediaWiki: Tweeki.js: Perbedaan antara revisi

Dari GBI Danau Bogor Raya
Lompat ke: navigasi, cari
Leo (bicara | kontrib)
Perbaiki parse error baris 40 ("/ /" -> "//"); jaga #myAccordion dan msnry yang tidak ada
Leo (bicara | kontrib)
Setiap blok dijaga (elemen/library tidak ada -> dilewati); kategori dipindah utuh; Masonry tunggu library async
Baris 1: Baris 1:
/* Any JavaScript here will be loaded for users using the Tweeki skin */
/* Any JavaScript here will be loaded for users using the Tweeki skin */
/* Setiap blok dijaga: kalau elemen/library yang dicari tidak ada di halaman ini,
  blok itu dilewati. Dulu satu error menghentikan seluruh file. */


$(function () {
$(function () {
   $('[data-toggle="tooltip"]').tooltip()
   $('[data-toggle="tooltip"]').tooltip();
})
});


var tableOffset = $("#table-1").offset().top;
// Header tabel #table-1 menempel saat digulir (butuh #header-fixed di halaman)
var $header = $("#table-1 > thead").clone();
(function () {
var $fixedHeader = $("#header-fixed").append($header);
  var $table = $('#table-1');
  var $fixedHeader = $('#header-fixed');
  if (!$table.length || !$fixedHeader.length) {
    return;
  }
  var tableOffset = $table.offset().top;
  $fixedHeader.append($table.children('thead').clone());


$(window).bind("scroll", function() {
  $(window).on('scroll', function () {
  var offset = $(this).scrollTop();
    var offset = $(this).scrollTop();


  if (offset >= tableOffset && $fixedHeader.is(":hidden")) {
    if (offset >= tableOffset && $fixedHeader.is(':hidden')) {
    $fixedHeader.show();
      $fixedHeader.show();
  } else if (offset < tableOffset) {
    } else if (offset < tableOffset) {
    $fixedHeader.hide();
      $fixedHeader.hide();
    }
  });
}());
 
// Pindahkan kategori ke sidebar kanan
(function () {
  var one = document.querySelector('#sidebar-right');
  var catlinks = document.querySelector('.catlinks');
  if (!one || !catlinks) {
    return;
   }
   }
});
  // salin ke array dulu: .children ikut berubah saat elemen dipindah (dulu yang terpindah hanya selang-seling)
 
  Array.prototype.slice.call(catlinks.children).forEach(function (child) {
var one = document.querySelector("#sidebar-right");
var children = document.querySelector(".catlinks").children;
 
Array.prototype.forEach.call(children, function (child) {
     one.appendChild(child);
     one.appendChild(child);
});
  });
}());




// Bootstrap 5
// Bootstrap 5


var alertList = document.querySelectorAll('.alert')
if (window.bootstrap) {
alertList.forEach(function (alert) {
  document.querySelectorAll('.alert').forEach(function (alert) {
  new bootstrap.Alert(alert)
    new bootstrap.Alert(alert);
});
  });
  document.querySelectorAll('[data-bs-toggle="popover"]').forEach(function (popoverTriggerEl) {
    new bootstrap.Popover(popoverTriggerEl);
  });
}


const popoverTriggerList = document.querySelectorAll('[data-bs-toggle="popover"]')
const popoverList = [...popoverTriggerList].map(popoverTriggerEl => new bootstrap.Popover(popoverTriggerEl))


// MASONRY: .grid > .grid-item. Library dimuat async dari CDN (hook BeforePageDisplay di
// LocalSettings), jadi bisa belum tersedia saat file ini jalan -> coba lagi saat window load.
var msnry = null;


// bootstrap 5.3 accordion troubleshooting overlap the content when showing items with card and masonry
function initMasonry() {
// Assuming you are using Masonry; skip when the page has no #myAccordion or no msnry grid
  var grid = document.querySelector('.grid');
var accordion = document.getElementById('myAccordion');
  if (msnry || !grid || typeof Masonry === 'undefined') {
if (accordion) {
    return;
   accordion.addEventListener('shown.bs.collapse', function () {
   }
     // Re-layout Masonry grid here
  msnry = new Masonry(grid, {
     if (window.msnry) { msnry.layout(); }
     itemSelector: '.grid-item',
     percentPosition: true
   });
   });
}
}
initMasonry();
window.addEventListener('load', initMasonry);


 
// bootstrap 5.3 accordion/collapse: isi yang tadinya tersembunyi menumpuk -> susun ulang setelah terbuka
// COBA MASONRY LISTEN UNTUK COLLAPSE
['myAccordion', 'collapseMasonry'].forEach(function (id) {
 
   var el = document.getElementById(id);
// 1. Initialize Masonry on the grid
  if (el) {
const grid = document.querySelector('.grid');
    el.addEventListener('shown.bs.collapse', function () {
const msnry = new Masonry(grid, {
      if (msnry) {
  itemSelector: '.grid-item',
        msnry.layout();
   percentPosition: true
      }
});
    });
 
  }
// 2. Target the Bootstrap collapse element
const collapseElement = document.getElementById('collapseMasonry');
 
// 3. Relayout Masonry only after the collapse finishes opening
collapseElement.addEventListener('shown.bs.collapse', function () {
  msnry.layout();
});
});

Revisi per 30 Oktober 2026 17.08

/* Any JavaScript here will be loaded for users using the Tweeki skin */
/* Setiap blok dijaga: kalau elemen/library yang dicari tidak ada di halaman ini,
   blok itu dilewati. Dulu satu error menghentikan seluruh file. */

$(function () {
  $('[data-toggle="tooltip"]').tooltip();
});

// Header tabel #table-1 menempel saat digulir (butuh #header-fixed di halaman)
(function () {
  var $table = $('#table-1');
  var $fixedHeader = $('#header-fixed');
  if (!$table.length || !$fixedHeader.length) {
    return;
  }
  var tableOffset = $table.offset().top;
  $fixedHeader.append($table.children('thead').clone());

  $(window).on('scroll', function () {
    var offset = $(this).scrollTop();

    if (offset >= tableOffset && $fixedHeader.is(':hidden')) {
      $fixedHeader.show();
    } else if (offset < tableOffset) {
      $fixedHeader.hide();
    }
  });
}());

// Pindahkan kategori ke sidebar kanan
(function () {
  var one = document.querySelector('#sidebar-right');
  var catlinks = document.querySelector('.catlinks');
  if (!one || !catlinks) {
    return;
  }
  // salin ke array dulu: .children ikut berubah saat elemen dipindah (dulu yang terpindah hanya selang-seling)
  Array.prototype.slice.call(catlinks.children).forEach(function (child) {
    one.appendChild(child);
  });
}());


// Bootstrap 5

if (window.bootstrap) {
  document.querySelectorAll('.alert').forEach(function (alert) {
    new bootstrap.Alert(alert);
  });
  document.querySelectorAll('[data-bs-toggle="popover"]').forEach(function (popoverTriggerEl) {
    new bootstrap.Popover(popoverTriggerEl);
  });
}


// MASONRY: .grid > .grid-item. Library dimuat async dari CDN (hook BeforePageDisplay di
// LocalSettings), jadi bisa belum tersedia saat file ini jalan -> coba lagi saat window load.
var msnry = null;

function initMasonry() {
  var grid = document.querySelector('.grid');
  if (msnry || !grid || typeof Masonry === 'undefined') {
    return;
  }
  msnry = new Masonry(grid, {
    itemSelector: '.grid-item',
    percentPosition: true
  });
}
initMasonry();
window.addEventListener('load', initMasonry);

// bootstrap 5.3 accordion/collapse: isi yang tadinya tersembunyi menumpuk -> susun ulang setelah terbuka
['myAccordion', 'collapseMasonry'].forEach(function (id) {
  var el = document.getElementById(id);
  if (el) {
    el.addEventListener('shown.bs.collapse', function () {
      if (msnry) {
        msnry.layout();
      }
    });
  }
});