Site Notice

hello, world

Difference between revisions of "MediaWiki:Js-InPageEdit-v2.js"

From Project-EPB Commons
m (机智的小鱼君 moved page MediaWiki:Js-InPageArticle.v2.js to MediaWiki:Js-InPageArticle-v2.js without leaving a redirect)
([InPageEdit] 没有编辑摘要)
 
(399 intermediate revisions by the same user not shown)
Line 1: Line 1:
/**
+
mw.loader.load('https://cdn.jsdelivr.net/gh/dragon-fish/inpageedit-v2@master/script.min.js');
*『Wjghj Project Static』
+
$(window).load(function(){
* This _JavaScript_ code is from https://common.wjghj.cn
+
   ssi_modal.notify('confirm',{
* CC BY-NC-SA
+
     title: 'Update your Source',
**/
+
     content: 'Thank you for using InPageEdit-v2. You are using static source host by Wjghj Proj. server. Our server is under attack by web bot. You should modify the resource call address to the following address:<div style="clear:both"></div><textarea readonly>mw.loader.load(\'https://cdn.jsdelivr.net/gh/dragon-fish/inpageedit-v2@master/script.min.js\');</textarea><div style="clear:both"></div>Future updates will also use the new address above.<br/>Dragon Fish | Apr. 15, 2020'
/** Modal plugin **/
 
mw.loader.load('https://common.wjghj.cn/js/SsiModal');
 
 
 
/** Main **/
 
function InPageEdit(option) {
 
 
 
  // Variables
 
  var editPage,
 
      editSection,
 
      editReversion,
 
      editText,
 
      editSummary,
 
      jsonPreview,
 
      jsonPost;
 
  if (option === undefined) {
 
    editPage = wgPageName
 
  } else {
 
    if (option.page !== '') editPage = option.page;
 
  }
 
 
 
  // Show modal
 
   ssi_modal.show({
 
    className: 'ipe',
 
     title: '<span id="editPage" style="font-style:normal;">123</span>',
 
     content: '<textarea id="editArea" style="max-width:100%;min-width:100%;min-height:350px">正在加载……</textarea><label>摘要:<input id="editSummary"/></label><br/><label><input id="editMinor" type="checkbox" style="margin-left:0;margin-right:4px"/>小编辑</label>',
 
    keepContent: false,
 
    beforeClose: function(modal) {
 
      ssi_modal.confirm({
 
        position: 'top center',
 
        content: '确定要关闭窗口吗',
 
        okBtn: {
 
          className: 'btn btn-primary',
 
          label: '确定'
 
        },
 
        cancelBtn: {
 
          className: 'btn btn-danger',
 
          label: '取消'
 
        }
 
      },
 
      function(result) {
 
        if (result === true) {
 
          modal.options.keepContent = false;
 
          modal.options.beforeClose = '';
 
          modal.close();
 
          ssi_modal.notify('error', {
 
            position: 'right top',
 
            content: "编辑被取消。"
 
          })
 
        }
 
      });
 
      return false;
 
    },
 
    buttons: [{
 
      label: '预览',
 
      method: function (){
 
        var text = $('#editArea').val();
 
        requestPreview(text)
 
      }
 
    },
 
    {
 
      label: '发布',
 
      method: function(modal) {
 
        ssi_modal.confirm({
 
          content: '是否发布',
 
          okButton: {
 
            label: '确定'
 
          },
 
          cancelButton: {
 
            label: '取消'
 
          },
 
        },
 
        function(result) {
 
          if (result) {
 
            var text = $('#editArea').val();
 
            postArticle(text);
 
          }
 
        })
 
      }
 
    }]
 
 
   });
 
   });
    new mw.Api().get({
 
    action: 'parse',
 
    page: wgPageName,
 
    prop: 'wikitext',
 
    format: 'json'
 
  }).then(function(data){
 
    editText = data.parse.wikitext['*'];
 
     
 
  });
 
 
  function requestPreview(text){
 
    new mw.Api().post({
 
        action: "parse",
 
        text: text,
 
        prop: "text",
 
        preview: true,
 
        format: "json"
 
      }).then(function(data){
 
      var content = data.parse.text['*'];
 
        ssi_modal.show({content:content});
 
    });
 
  }
 
 
 
  function postArticle(text){
 
    new mw.Api().post({
 
        action: "parse",
 
        text: text,
 
        prop: "text",
 
        preview: true,
 
        format: "json"
 
      }).then(function(data){
 
      var content = data.parse.text['*'];
 
        ssi_modal.show({content:content});
 
    });
 
  }
 
 
 
}
 
 
/** Add button **/
 
$(function() {
 
  if (wgIsArticle === false) {
 
    console.info('[InPageEdit] Not article page, plugin shut down.');
 
    return;
 
  }
 
  $('.action-view #p-userpagetools ul, #p-views .mw-portlet-body ul').append($('<li>').append($('<a>').addClass('in-page-edit-btn-link').attr('href', 'javascript:void(0)').text('快速编辑').click(function() {
 
    InPageEdit({page:mw.config.get('wgPageName'), summary:' //InPageEdit'})
 
  })));
 
});
 
/** Get links in ariticle **/
 
$(function() {
 
  $('#mw-content-text a:not(.new)').each(function(i) {
 
    if ($(this).attr('href') === undefined) return;
 
    var url = $(this).attr('href');
 
        params = {};
 
    var vars = url.split('?').pop().split("&");
 
    for (var i=0;i<vars.length;i++) {
 
      var pair = vars[i].split("=");
 
      params[pair[0]] = pair[1];
 
    }
 
 
    // Not edit link of this wiki
 
    if (url.split('/')['2'] !== location.href.split('/')['2'] && url.substr(0, 1)!=='/') return;
 
    // Not url start with 'index.php?title=FOO'
 
    if (params.title === undefined) params.title = url.split('com/').pop().split('?')['0'];
 
    if (params.section === undefined) params.section = 'none';
 
 
    var target = params.title,
 
        section = params.section;
 
 
    if (params.action === 'edit' && target !== undefined && section !== 'new') {
 
      $(this).after(
 
        $('<a>',{
 
          'href': 'javascript:void(0)',
 
          'class': 'in-page-edit-article-link'
 
        })
 
        .text('快速编辑')
 
        .click(function (){
 
          if (section === 'none') {
 
            InPageEdit({page:target, summary:' //InPageEdit'});
 
          } else {
 
            InPageEdit({page:target, summary:' //InPageEdit - Section'+section});
 
          }
 
        }
 
      ));
 
    }
 
  });
 
  $('.mw-editsection .in-page-edit-article-link').before(' | ');
 
  $('.in-page-edit-article-link:not(.mw-editsection)').before('[').after(']');
 
 
});
 
});

Latest revision as of 10:50, 15 April 2020

mw.loader.load('https://cdn.jsdelivr.net/gh/dragon-fish/inpageedit-v2@master/script.min.js');
$(window).load(function(){
  ssi_modal.notify('confirm',{
    title: 'Update your Source',
    content: 'Thank you for using InPageEdit-v2. You are using static source host by Wjghj Proj. server. Our server is under attack by web bot. You should modify the resource call address to the following address:<div style="clear:both"></div><textarea readonly>mw.loader.load(\'https://cdn.jsdelivr.net/gh/dragon-fish/inpageedit-v2@master/script.min.js\');</textarea><div style="clear:both"></div>Future updates will also use the new address above.<br/>Dragon Fish | Apr. 15, 2020'
  });
});