User:Most2dot0/common.js

From Angelina Jordan Wiki
Revision as of 22:26, 5 November 2025 by Most2dot0 (talk | contribs) (changed to more Cargo API, specific table description included)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
//syntax highlighter
mw.loader.load('//www.mediawiki.org/w/index.php?title=MediaWiki:Gadget-DotsSyntaxHighlighter.js&action=raw&ctype=text/javascript');
syntaxHighlighterConfig = { parameterColor: "#FFDD99" }

/*
// Auto-reload page content if marker element is present
$(document).ready(function() {
    const marker = document.getElementById('auto-reload-trigger');
    if (!marker) return;

    const period = Math.max(5, parseInt(marker.dataset.period || "30", 10)); // seconds
    const limit = parseInt(marker.dataset.limit || "10", 10); // max reloads
    let count = 0;

    // Create and insert status display
    const statusBox = $('<div id="auto-reload-status" style="margin:10px 0;padding:5px;border:1px solid #ccc;font-size:90%;width:fit-content;background:#f8f8f8;"></div>');
    statusBox.text(`Reloads done: ${count} / ${limit}`);
    $('#mw-content-text').before(statusBox);

    function reloadContent() {
        if (count >= limit) {
            statusBox.text(`Reload complete (${count}/${limit})`);
            return;
        }
        count++;
        statusBox.text(`Reloads done: ${count} / ${limit}`);

        $.ajax({
            url: location.href,
            cache: false,
            success: function(data) {
                const newContent = $(data).find('#mw-content-text');
                if (newContent.length) {
                    $('#mw-content-text').replaceWith(newContent);
                    mw.hook('wikipage.content').fire($('#mw-content-text'));
                }
            }
        });
    }

    setInterval(reloadContent, period * 1000);
});  
*/
/* test AJAX load of cargo query templates */
$(function() {
  $('.cargo-placeholder').on('click', function() {
    var $div = $(this);
    var $content = $div.find('.mw-collapsible-content');
    if ($content.data('loaded')) return; // only once

    var song = $div.data('song');

    // Construct API call
    var apiUrl = mw.util.wikiScript('api') + '?action=cargoquery&format=json' +
      '&tables=Performances,Videos' +
      '&join_on=Performances.perfID=Videos.perfID' +
      '&fields=Performances.date,Performances.event,Performances.type,Videos.url,Performances.pos,Performances.comment,Performances.partners' +
      '&where=' + encodeURIComponent('Performances.song="' + song + '"') +
      '&group_by=Performances.perfID' +
      '&order_by=Performances.date,Performances.pos,Videos.rating';

    $.getJSON(apiUrl, function(data) {
      if (!data || !data.cargoquery || !data.cargoquery.length) {
        $content.html('<em>No results found.</em>');
        return;
      }

      var rows = data.cargoquery.map(function(entry) {
        var r = entry.title;
        return '<tr>' +
          '<td>' + mw.html.escape(r.event || '') + '</td>' +
          '<td>' + mw.html.escape(r.date || '') + '</td>' +
          '<td>' + mw.html.escape(r.type || '') + '</td>' +
          '<td>' + (r.url ? '<a href="' + mw.html.escape(r.url) + '">Video</a>' : '') + '</td>' +
          '<td>' + mw.html.escape(r.comment || '') + '</td>' +
          '</tr>';
      }).join('');

      var table =
        '<table class="wikitable sortable" style="width:100%;margin:0;">' +
        '<tr><th>Event</th><th>Date</th><th>Type</th><th>Video</th><th>Comment</th></tr>' +
        rows +
        '</table>';

      $content.html(table).data('loaded', true);
    }).fail(function() {
      $content.html('<em>Error loading data.</em>');
    });
  });
});