Pāriet uz saturu

MediaWiki:Common.js: Atšķirības starp versijām

No ''Latvijas Nacionālā bibliotēka''
Nav labojuma kopsavilkuma
Nav labojuma kopsavilkuma
1. rindiņa: 1. rindiņa:
/* Any JavaScript here will be loaded for all users on every page load. */
(function () {
mw.hook('wikipage.content').add(function ($content) {
   // Desired field order (based on the IDs you provided)
   var $wrap = $content.find('#mw-createaccount-form .mw-htmlform-ooui');
  var ORDER = [
  if (!$wrap.length) $wrap = $content.find('#mw-createaccount-form'); // fallback
 
  function blockFor(id) {
    var $el = $wrap.find(id);
    if (!$el.length) return null;
    // field container in both OOUI & legacy HTMLForm
    var $blk = $el.closest('.oo-ui-fieldLayout, .mw-htmlform-field, .mw-htmlform-field-HTMLCheckField, .mw-htmlform-field-HTMLInfoField, tr, li, dd, div');
    return $blk.length ? $blk : $el;
  }
 
  [
     '#wpCreateaccountMail',
     '#wpCreateaccountMail',
    '#wpReason',
     '#wpName2',
     '#wpName2',
     '#wpPassword2',
     '#wpPassword2',
     '#wpRetype',
     '#wpRetype',
'#wpEmail',
    '#wpEmail',
     '#wpRealName',
     '#wpRealName',
     '#mw-input-captchaWord',
     '#mw-input-captchaWord',
    '#wpReason',
     '#wpCreateaccount'
     '#wpCreateaccount'
   ].forEach(function (sel) {
   ];
     var b = blockFor(sel);
 
     if (b) b.appendTo($wrap); // move into desired order
  // Find the container that holds the field blocks
   });
  function findWrap($root) {
});
    var $wrap = $root.find('#mw-createaccount-form .mw-htmlform-ooui');
    if (!$wrap.length) $wrap = $root.find('#mw-createaccount-form .oo-ui-panelLayout');
    if (!$wrap.length) $wrap = $root.find('#mw-createaccount-form .mw-htmlform');
    if (!$wrap.length) $wrap = $root.find('#mw-createaccount-form');
    return $wrap.first();
  }
 
  // Given an input/button id, return its field "block" wrapper
  function fieldBlock($wrap, sel) {
     var $el = $wrap.find(sel);
     if (!$el.length) return null;
    var $blk = $el.closest(
      '.oo-ui-fieldLayout, .mw-htmlform-field, .mw-htmlform-submit,' +
      ' .mw-htmlform-field-HTMLCheckField, .mw-htmlform-field-HTMLInfoField,' +
      ' tr, li, dd, .oo-ui-widget, .oo-ui-layout, div'
    );
    return $blk.length ? $blk : $el;
  }
 
  function reorder($root) {
    var $wrap = findWrap($root);
    if (!$wrap.length) return false;
 
    var prev = null;
    for (var i = 0; i < ORDER.length; i++) {
      var $blk = fieldBlock($wrap, ORDER[i]);
      if (!$blk) continue;
 
      if (prev) {
        $blk.insertAfter(prev);  // place after the previous moved block
      } else {
        $blk.prependTo($wrap);    // first block goes to the very top
      }
      prev = $blk;
    }
    return true;
  }
 
   function run($content) {
    // Try immediately and also after short delays (OOUI may mutate after load)
    reorder($content);
    setTimeout(function () { reorder($content); }, 0);
    setTimeout(function () { reorder($content); }, 100);
    setTimeout(function () { reorder($content); }, 500);
 
    // Watch for late DOM changes and re-apply (disconnect after a bit)
    var form = document.getElementById('mw-createaccount-form');
    if (form) {
      var obs = new MutationObserver(function () { reorder($content); });
      obs.observe(form, { childList: true, subtree: true });
      setTimeout(function () { obs.disconnect(); }, 5000);
    }
  }
 
  if (mw && mw.hook) {
    mw.hook('wikipage.content').add(function ($content) { run($content); });
  } else {
    jQuery(function ($) { run($(document)); });
  }
})();

Versija, kas saglabāta 2025. gada 19. septembris, plkst. 18.48

(function () {
  // Desired field order (based on the IDs you provided)
  var ORDER = [
    '#wpCreateaccountMail',
    '#wpName2',
    '#wpPassword2',
    '#wpRetype',
    '#wpEmail',
    '#wpRealName',
    '#mw-input-captchaWord',
    '#wpReason',
    '#wpCreateaccount'
  ];

  // Find the container that holds the field blocks
  function findWrap($root) {
    var $wrap = $root.find('#mw-createaccount-form .mw-htmlform-ooui');
    if (!$wrap.length) $wrap = $root.find('#mw-createaccount-form .oo-ui-panelLayout');
    if (!$wrap.length) $wrap = $root.find('#mw-createaccount-form .mw-htmlform');
    if (!$wrap.length) $wrap = $root.find('#mw-createaccount-form');
    return $wrap.first();
  }

  // Given an input/button id, return its field "block" wrapper
  function fieldBlock($wrap, sel) {
    var $el = $wrap.find(sel);
    if (!$el.length) return null;
    var $blk = $el.closest(
      '.oo-ui-fieldLayout, .mw-htmlform-field, .mw-htmlform-submit,' +
      ' .mw-htmlform-field-HTMLCheckField, .mw-htmlform-field-HTMLInfoField,' +
      ' tr, li, dd, .oo-ui-widget, .oo-ui-layout, div'
    );
    return $blk.length ? $blk : $el;
  }

  function reorder($root) {
    var $wrap = findWrap($root);
    if (!$wrap.length) return false;

    var prev = null;
    for (var i = 0; i < ORDER.length; i++) {
      var $blk = fieldBlock($wrap, ORDER[i]);
      if (!$blk) continue;

      if (prev) {
        $blk.insertAfter(prev);   // place after the previous moved block
      } else {
        $blk.prependTo($wrap);    // first block goes to the very top
      }
      prev = $blk;
    }
    return true;
  }

  function run($content) {
    // Try immediately and also after short delays (OOUI may mutate after load)
    reorder($content);
    setTimeout(function () { reorder($content); }, 0);
    setTimeout(function () { reorder($content); }, 100);
    setTimeout(function () { reorder($content); }, 500);

    // Watch for late DOM changes and re-apply (disconnect after a bit)
    var form = document.getElementById('mw-createaccount-form');
    if (form) {
      var obs = new MutationObserver(function () { reorder($content); });
      obs.observe(form, { childList: true, subtree: true });
      setTimeout(function () { obs.disconnect(); }, 5000);
    }
  }

  if (mw && mw.hook) {
    mw.hook('wikipage.content').add(function ($content) { run($content); });
  } else {
    jQuery(function ($) { run($(document)); });
  }
})();