User:V111P/js/addToolbarButtons.js: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 43:
$.extend(button, props || {});
 
iffunction error(!button.idmsg) {
if (window.console && console.error)
console.error('addToolbarButtons.js: No' button+ id specified.'msg);
}
 
.attr if ('id', !button.id) {
error('No button id specified.');
return;
}
 
var oldButton =if ($('#' + button.id);[0]) {
error('An element with id ' + button.id + ' already exists on the page.');
return;
}
Line 57 ⟶ 66:
button.inserts = (button.before + button.between + button.after).length > 0;
if (!button.callback && !button.inserts) {
console.error('addToolbarButtons.js:Neither Noa callback function ornor characters to insert specified.');
if (window.console && console.error)
console.error('addToolbarButtons.js: No callback function or characters to insert specified.');
return;
}
 
var oldButton = $('#' + button.id);
if (oldButton[0]) {
oldButton.attr('id', button.id + '_ButtonToBeRemoved')
.replaceWith(
$(oldButton[0].cloneNode()) // clone to remove event handlers
.attr('id', button.id)
.click(button.callback)
);
return;
}
Line 111 ⟶ 108:
// add a button to the classic toolbar
mw.loader.using('mediawiki.action.edit', function () {
var tempButtonId = button.id; //+ (!button.inserts ? 'TempButton' : '');
oldButton.remove();
var tempButtonId = button.id; //+ (!button.inserts ? 'TempButton' : '');
mw.toolbar.addButton(
(button.iconUrlClassic || button.iconUrl),
Line 120 ⟶ 116:
tempButtonId
);
if (button.callbackinserts) {
button.callback && $('#' + button.id).click(button.callback);
); }
else {
var $tempButton = $('#' + tempButtonId);
if ($tempButton[0]) {
$(oldButton[0].cloneNode()) // clone the button to remove added event handlers
// if not done the selection in the textarea is collapsed
// before the callback function is called
var newB = $tempButton[0].cloneNode();
newB.id = button.id;
$tempButton.after(newB).remove();
$(newB).click(button.callback);
}
}
});