Good to know. Also, I must have read the wrong documentation when I went to use addButton. Not sure where I got that callback parameter from. So instead I just attached an event handler to the button on click, and now it does what I want. Thanks for clearing up the confusion, Krinkle!
On Wed, Apr 23, 2014 at 6:53 PM, Krinkle <krinklem...@gmail.com> wrote: > Yes, it will ensure the code won't run if that particular toolbar isn't > enabled. > And it is also a safe guard for backwards compatibility (since the API > used to have a different interface), and forwards compatibility (it might > change). > > Usually you wouldn't need such guard and instead use a dependency, but > because you don't want to trigger a load of this module (you merely want to > hook into it if the toolbar is there, you don't want to load another > toolbar which is what adding a dependency would do). > > — Krinkle > > On 23 Apr 2014, at 14:21, Justin Folvarcik <jfolvar...@gmail.com> wrote: > > > 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 <krinklem...@gmail.com> wrote: > > > >> On 22 Apr 2014, at 02:37, Lego KTM <legoktm.wikipe...@gmail.com> wrote: > >> > >>> On Mon, Apr 21, 2014 at 4:09 PM, Justin Folvarcik < > jfolvar...@gmail.com> > >> wrote: > >>>> > >>>> function removeDuplicateLinks(){ > >>>> > >>>> .. > >>>> } > >>>> if (wgAction == 'edit'){ > >>>> mw.toolbar.addButton( { > >>>> imageFile: ' > >>>> http://localhost/wikidev/images/2/20/Button_cite_template.png', > >>>> 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 <er...@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-addButton > >> > >> 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@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@lists.wikimedia.org > > https://lists.wikimedia.org/mailman/listinfo/wikitech-l > > _______________________________________________ > Wikitech-l mailing list > Wikitech-l@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@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l