Hi, LegoKTM, I tried your suggestion again, just to be sure, and I can confirm that this still does not load the callback properly. I set the value to callback: removeDuplicateLinks Now it does not load the function at all.
On Mon, Apr 21, 2014 at 8:37 PM, Lego KTM legoktm.wikipedia@gmail.comwrote:
On Mon, Apr 21, 2014 at 4:09 PM, Justin Folvarcik jfolvarcik@gmail.com wrote:
I'm trying to write a script to remove duplicate links with the click of
a
button in the toolbar, yet when I set the function as the callback for
the
button, it runs the function on page load. This is what I've got:
function removeDuplicateLinks(){
var box =$('[id^=wpTextbox]'); var text = box.val(); var start=text.split(''); var i; for (i = 1;typeof(start[i]) !== 'undefined' ;i++){
console.log(start[i]); start[i] = start[i].split('')[0]; text = text.replace('/[[' + start[i] + ']]/', start[i]); } box.val(text); } 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".
} );
}
I've tried setting the callback to 'removeDuplicateLinks', removeDuplicateLinks, and I've even tried turning it into an anonymous function bound to a variable, which I then tried to pass as the callback. Am I misusing syntax, here?
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.
-- Legoktm
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l