Site Notice

hello, world

InPageEdit-v2/SDK

From Project-EPB Commons
< InPageEdit-v2
Revision as of 23:22, 23 November 2019 by 机智的小鱼君 (talk | contribs) ([InPageEdit] 没有编辑摘要 (第8部分))

快速编辑

InPageEdit.edit(options)

  • options: {object}
    • page: 必须;编辑的页面名
    • revision: 修订版本号,如果与当前页面版本号不同则取代
    • section: 编辑的段落编号

最基础的调用

InPageEdit.edit({
  page: mw.config.get('wgPageName')
});

<html><button onclick="InPageEdit.edit({

 page: mw.config.get('wgPageName')

});">测试</button></html>

快速重定向

InPageEdit.redirect(type)

  • type: "string"(to/from)
    • from 重定向页面至此
    • to 将此页面重定向到

最基础的调用

InPageEdit.redirect('from');
InPageEdit.redirect('to');

<html><button onclick="InPageEdit.redirect('from')">测试from</button> <button onclick="InPageEdit.redirect('to')">测试to</button></html>

快速删除

InPageEdit.deletepage()

  • ?

快速重命名

InPageEdit.renamepage()

  • ?

InPageEdit设置

InPageEdit.preference()

  • 打开设置窗口

<html><button onclick="InPageEdit.preference()">测试</button></html>

比较差异

InPageEdit.quickDiff(options)

  • options: {object}
    • fromtitle: First title to compare.
    • fromid: First page ID to compare. Type: integer
    • fromrev: First revision to compare. Type: integer
    • fromtext: Use this text instead of the content specified by fromtitle, fromid or fromrev.
    • frompst: Do a pre-save transform on fromtext. Type: boolean
    • <code">totitle: Second title to compare.
    • toid: Second page ID to compare. Type: integer
    • torev: Second revision to compare. Type: integer
    • torelative: Compare to a relative revision of fromtitle, fromid or fromrev. All the other "to" options will be ignored. Possible values: prev, next, cur
    • totext: Use this text instead of the content specified by totitle, toid, torev, or torelative.
    • topst: Do a pre-save transform on totext. Type: boolean

最简单的示例,比较本页面最后一次修改

InPageEdit.quickDiff({
  fromtitle: mw.config.get('wgPageName'),
  torelative: 'prev'
});

<html><button onclick="InPageEdit.quickDiff({

 fromtitle: mw.config.get('wgPageName'),
 torelative: 'prev'

});">测试</button></html>

添加编辑链接

该模块在页面加载时将运行一次

当页面为文章页时,会以以下参数自动运行一次: InPageEdit.articleLink($('#mw-content-text a:not(.new)'))

InPageEdit.articleLink(element)

  • element: <element>
    • 缺省值:$('#mw-content-text a:not(.new)')
    • 将该链接作为编辑链接,识别并添加快速编辑链接

无示例

加载框

不建议使用

这是一个内部模块,用于在特定步骤遮挡屏幕阻止用户的其他操作,不应该单独使用。如果您喜欢ipe-progress-bar,请使用该部件:
<div class="ipe-progress" style="width:100%;"><div class="progress-bar"></div></div>

InPageEdit.progress(title)

  • title: "string",√boolean×
    • true: 将顶层加载框状态切换为已完成
    • false: 关闭顶层的加载框
    • string: 以字符串为标题创建加载框
function testProgress() {
  InPageEdit.progress('正在测试加载框……');
  setTimeout(function(){
    InPageEdit.progress(true);
    setTimeout(function(){
      InPageEdit.progress(false);
    },3000);
  },5000);
}

<html><button onclick="testProgress()">测试</button> <script> function testProgress() {

 InPageEdit.progress('正在测试加载框……');
 setTimeout(function(){
   InPageEdit.progress(true);
   setTimeout(function(){
     InPageEdit.progress(false);
   },3000);
 },5000);

} </script></html>

实例演示

通过IPE的扩展接口,您可以制作很多自定义插件,这里提供一些简单、实用的代码实例

在编辑链接后添加快速编辑链接

此示例代码已在Vector、Timeless以及Hydra皮肤上测试可用

$(function(){
  $('#ca-view').after(
    $('<li>',{
      id:'ca-quick-edit',
      class:'collapsible'
    }).append(
      $('<span>').append(
        $('<a>',{
          href: 'javascript:void(0)'
        })
        .text('快速编辑')
        .click(function(){
          InPageEdit.edit({
            page: mw.config.get('wgPageName'),
            revision: mw.config.get('wgRevisionId')
          });
        })
      )
    )
  );
});