ผู้ใช้:Lux2545/monobook.js

จาก วิกิพจนานุกรม พจนานุกรมเสรี

หมายเหตุ: หลังเผยแพร่ คุณอาจต้องล้างแคชเว็บเบราว์เซอร์ของคุณเพื่อดูการเปลี่ยนแปลง

  • ไฟร์ฟอกซ์ / ซาฟารี: กด Shift ค้างขณะคลิก Reload หรือกด Ctrl-F5 หรือ Ctrl-R (⌘-R บนแมค)
  • กูเกิล โครม: กด Ctrl-Shift-R (⌘-Shift-R บนแมค)
  • อินเทอร์เน็ตเอกซ์พลอเรอร์ และ Edge: กด Ctrl ค้างขณะคลิก Refresh หรือกด Ctrl-F5
  • โอเปร่า: กด Ctrl-F5
/* This script works best with stylesheet: ผู้ใช้:Lux2545/vector.css */
var thaiDigit = { '๐':'0', '๑':'1', '๒':'2', '๓':'3', '๔':'4', '๕':'5', '๖':'6', '๗':'7', '๘':'8', '๙':'9' };
var wikiNamespace = { 'File':'ไฟล์', 'Image':'ไฟล์', 'ภาพ':'ไฟล์', 'Media':'สื่อ', 'Category':'หมวดหมู่', 'Template':'แม่แบบ' };
 
$(document).ready(function() {
 
  /* New buttons in toolbar when editing */
  if (typeof $.fn.wikiEditor != 'undefined') {
    $('#wpTextbox1').wikiEditor('addToToolbar', {
      'section': 'main',
      'group': 'format',
      'tools': {
        'underline': {
          'label': 'ขีดเส้นใต้',
          'type': 'button',
          'icon': 'http://upload.wikimedia.org/wikipedia/commons/1/13/Toolbaricon_regular_U_underline.png',
          'action': {
            'type': 'encapsulate',
            'options': {
              'pre': '<u>',
              'peri': 'ข้อความขีดเส้นใต้',
              'post': '</u>'
            }
          }
        },
        'stroke': {
          'label': 'ขีดฆ่า',
          'type': 'button',
          'icon': 'http://upload.wikimedia.org/wikipedia/commons/f/f9/Toolbaricon_regular_S_stroke.png',
          'action': {
            'type': 'encapsulate',
            'options': {
              'pre': '<s>',
              'peri': 'ข้อความขีดฆ่า',
              'post': '</s>'
            }
          }
        },
        'superscript': {
          'label': 'ตัวยก',
          'type': 'button',
          'icon': 'http://upload.wikimedia.org/wikipedia/commons/2/2c/Toolbaricon_regular_x_superscript_italic_2.png',
          'action': {
            'type': 'encapsulate',
            'options': {
              'pre': '<sup>',
              'peri': 'ข้อความตัวยก',
              'post': '</sup>'
            }
          }
        },
        'subscript': {
          'label': 'ตัวห้อย',
          'type': 'button',
          'icon': 'http://upload.wikimedia.org/wikipedia/commons/2/21/Toolbaricon_regular_x_subscript_italic_2.png',
          'action': {
            'type': 'encapsulate',
            'options': {
              'pre': '<sub>',
              'peri': 'ข้อความตัวห้อย',
              'post': '</sub>'
            }
          }
        }
      }
    });
    $('#wpTextbox1').wikiEditor('addToToolbar', {
      'section': 'main',
      'groups': {
        'extra': {
          'tools': {
            'cleanup': {
              'label': 'เก็บกวาด',
              'type': 'button',
              'icon': 'http://upload.wikimedia.org/wikipedia/en/thumb/f/f2/Edit-clear.svg/40px-Edit-clear.svg.png',
              'action': {
                'type': 'callback',
                'execute': function() {
                  var content = $('#wpTextbox1').val();
                  content = content.replace(/^[ \t]+/gm, '')                   /* trims leading spaces */
                    .replace(/[ \t]+$/gm, '')                                  /* trims trailing spaces */
                    .replace(/[ \t]+/g, ' ')                                   /* removes more than one spaces */
                    .replace(/\n\n+/g, '\n\n')                                 /* removes more than two newlines */
                    .replace(/^([\*#:;]+)[ \t]*/gm, '$1 ')                     /* aligns lists and blocks */
                    .replace(/^(=+)[ \t]*([^\n]*?)[ \t]*(=+)$/gm, '$1 $2 $1')  /* aligns and fixes headings */
                    .replace(/\[\[([^\n]*?)\|\1\]\]/g, '[[$1]]')               /* cancels same link replacements */
                    .replace(/(File|Image|ภาพ|Media|Category|Template)(?=:)/gi, function(ns) { /* replaces some namespaces */
                      return wikiNamespace[ns];
                    });
                  $('#wpTextbox1').val(content);
                }
              }
            },
            'arabic-number': {
              'label': 'ใช้เลขอารบิก',
              'type': 'button',
              'icon': 'http://upload.wikimedia.org/wikipedia/commons/0/03/Toolbaricon_regular_1.png',
              'action': {
                'type': 'callback',
                'execute': function() {
                  var content = $('#wpTextbox1').val();
                  content = content.replace(/[๐-๙]/g, function(d) {
                    return thaiDigit[d];
                  });
                  $('#wpTextbox1').val(content);
                }
              }
            }
          }
        }
      }
    });
  }
 
  /* New dropdown tab for extra functionality */
  var $extraMenu = $('#p-cactions').clone().attr('id', 'p-extra');
  $extraMenu.find('span').text('เพิ่มเติม');
  var $extraMenuList = $extraMenu.find('ul').empty();
 
  if ($('#ca-edit a').attr('href') != undefined) {
    var editFirstSectionLink = $('#ca-edit a').attr('href') + '&section=0';
    $('<li id="ca-edit-first"><a title="แก้ไขส่วนแรก" href="' + editFirstSectionLink
      + '">แก้ไขส่วนแรก</a></li>').appendTo($extraMenuList);
  }
 
  if ($('#ca-history a').attr('href') != undefined) {
    var viewLatestDiffLink = $('#ca-history a').attr('href') + 'submit&diff=0';
    $('<li id="ca-latest-diff"><a title="ส่วนต่างล่าสุด" href="' + viewLatestDiffLink
      + '">ส่วนต่างล่าสุด</a></li>').appendTo($extraMenuList);
  }
 
  if (1) {
    $('<li id="ca-red-link"></li>').append('<a title="รายชื่อลิงก์แดง" href="#">รายชื่อลิงก์แดง</a>').click(function() {
      if ($('#mw-js-message').children().length == 0) {
        $('#mw-js-message').html('<p>นี่คือรายชื่อลิงก์แดงทั้งหมดที่ปรากฏในหน้านี้</p><ul class="red-link"></ul>');
        $('#mw-js-message ul').append($('a.new').clone()).find('a.new').wrap('<li></li>');
        $('#mw-js-message').hide();
      }
      $('#mw-js-message').slideToggle('slow');
    }).appendTo($extraMenuList);
  }
 
  if ($extraMenuList.find('li').length == 0) {
    $extraMenu.addClass('emptyPortlet');
  } else {
    $extraMenu.removeClass('emptyPortlet');
  }
  $('#p-views').after($extraMenu);
 
});