User:Loki Laufeyjarson/common.js: Difference between revisions

From Heroes 3 wiki
Jump to navigation Jump to search
Created page with "(function () { function resolveUrl($el) { var u = $el.attr('data-audio-url'); if (u) return u; var f = $el.attr('data-audio-file'); if (!f || /\{\{/.test(f)) return null; // don’t play if a template param didn’t expand return mw.util.getUrl('Special:FilePath/' + f); } var cache = {}; mw.hook('wikipage.content').add(function ($c) { $c.on('click', '.click-audio', function (e) { e.preventDefault(); var u = resolveUrl($(this));..."
 
Blanked the page
Tag: Blanking
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
(function () {
 
  function resolveUrl($el) {
    var u = $el.attr('data-audio-url');
    if (u) return u;
    var f = $el.attr('data-audio-file');
    if (!f || /\{\{/.test(f)) return null; // don’t play if a template param didn’t expand
    return mw.util.getUrl('Special:FilePath/' + f);
  }
  var cache = {};
  mw.hook('wikipage.content').add(function ($c) {
    $c.on('click', '.click-audio', function (e) {
      e.preventDefault();
      var u = resolveUrl($(this));
      if (!u) return;
      var a = cache[u] || (cache[u] = new Audio(u));
      a.currentTime = 0;
      a.play && a.play();
    });
    $c.find('.click-audio').css('cursor', 'pointer').attr({ role: 'button', tabindex: 0 });
  });
})();

Latest revision as of 02:38, 10 September 2025