Am I correct in assuming that adding a check for
mw.toolbar will help
prevent the code from causing errors when in an edit view without a toolbar?
On Wed, Apr 23, 2014 at 7:14 AM, Krinkle <krinklemail(a)gmail.com> wrote:
On 22 Apr 2014, at 02:37, Lego KTM
<legoktm.wikipedia(a)gmail.com> wrote:
On Mon, Apr 21, 2014 at 4:09 PM, Justin Folvarcik
<jfolvarcik(a)gmail.com>
wrote:
function removeDuplicateLinks(){
..
}
if (wgAction == 'edit'){
mw.toolbar.addButton( {
imageFile: '
http://localhost/wikidev/images/2/20/Button_cite_template.png'#39;,
speedTip: 'Remove duplicate links',
callback: removeDuplicateLinks(),
Change this line to "callback: removeDuplicateLinks".
Your code had "removeDuplicateLinks()", which would execute the
function, and set the return value as the callback, while you wanted
the actual function. Simply removing the () fixes that.
Indeed. That was the reason it ran on page load, because it was being
invoked directly by your code when creating the button object.
To Justin: Please also change the code to extend the if-statement from `(
wgAction === "edit" )` to be `( wgAction === "edit" &&
mw.toolbar )`.
On 22 Apr 2014, at 15:42, Erwin Dokter <erwin(a)darcoury.nl> wrote:
What I *suspect* you are doing wrong is... using the 'callback:'
parameter. I think this is the addButton's function callback. It stands to
reason that it would be executed once the addButton function has done its
work.
From what I have been able to discern from the badly organized
documentation
(again, I may be totally misguided), is that you want to use
the 'action:' parameter instead.
The mw.toolbar interface neither documents nor implements any such
function. There is no such thing as button.callback or button.action, and
for as long as I can remember, such feature never existed.
As for documentation, this particular method is quite well-documented:
https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.toolbar-method…
If you need a callback, I'd recommend you re-enable the WikiEditor toolbar
instead of the legacy classic toolbar, and use its API to add a button
instead.
The WikiEditor API provides a wide range of features, including a callback.
— Krinkle
_______________________________________________
Wikitech-l mailing list
Wikitech-l(a)lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l
--
----
Justin Folvarcik
*"When the power of love overcomes the love of power, the world will
finally know peace."*-Jimi Hendrix
_______________________________________________
Wikitech-l mailing list
Wikitech-l(a)lists.wikimedia.org