【问题标题】:$(...).wikiEditor is not a function$(...).wikiEditor 不是函数
【发布时间】:2020-06-19 01:29:09
【问题描述】:

按照MediaWiki.org 上的教程,我尝试使用用户脚本自定义工具栏;但是,有时当我从 common.js 加载它时,我在控制台中收到此错误:

jQuery.Deferred exception: $(...).wikiEditor is not a function TypeError: $(...).wikiEditor is not a function
    at quickMAR_add (https://en.moegirl.org/index.php?title=User:Leranjun/quickMAR.js&action=raw&ctype=text/javascript:52:19)
    at https://en.moegirl.org/index.php?title=User:Leranjun/quickMAR.js&action=raw&ctype=text/javascript:60:12
    at mightThrow (https://en.moegirl.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1o54dq6:49:598)
    at process (https://en.moegirl.org/load.php?debug=false&lang=en&modules=jquery%2Cmediawiki&only=scripts&skin=vector&version=1o54dq6:50:269) undefined

更奇怪的是,它有时有效,有时无效……如果我将代码复制/粘贴到控制台并手动执行,它总是有效。

如果需要,源代码是here。

【问题讨论】:

  • 如果您的脚本在wikiEditor jQuery 插件注册之前运行,您只会收到此错误。我们需要查看上面包含 jQuery、插件和脚本的 HTML
  • @Phil 我很抱歉,但我不知道您所说的 HTML 和插件是什么意思。你是说编辑页面吗?
  • @frankly.not.frank 你能把这个html页面添加到顶部吗<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  • @AlwaysHelping Oopsies,忘了说我不是管理员,不能进行全局更改。更重要的是,其他jQuery函数功能齐全,所以我很确定jQuery已经包含在内了。

标签: javascript jquery mediawiki wikitext


【解决方案1】:

您需要等待工具栏准备好:

mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
    $textarea.wikiEditor(...);
} );

described on the documentation page you linked 方法不太优雅,但也可以工作。

【讨论】:

  • 我不太确定在哪里添加这个 sn-p... 是在调用 add 函数之前吗?
  • 您需要像这样包装您的$(...).wikiEditor(...) 调用,以确保在您调用它时加载$(...).wikiEditor。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-06
  • 2019-12-20
  • 1970-01-01
  • 2014-10-03
  • 2021-12-04
  • 1970-01-01
相关资源
最近更新 更多