registerButtonCommands: function () {
$.FE.DefineIcon('lwPostMacrosInsert', {NAME: "bolt"});
$.FE.RegisterCommand('lwPostMacrosInsert', {
type: 'dropdown',
title: 'Insert Macro',
undo: true,
focus: true,
html: function () {
var o = '<ul class="fr-dropdown-list">';
LiamW.PostMacros.macroInserter.macros.forEach(function (macro, k) {
o += '<li><a class="fr-command" data-cmd="lwPostMacrosInsert" data-param1="' + k + '">' + macro['title'] + '</a></li>';
});
o += '</ul>';
return o;
},
callback: function (cmd, val) {
var ed = this;
if (LiamW.PostMacros.macroInserter.macros[val]['hasTokens'])
{
XF.ajax("get", XF.canonicalizeUrl("index.php?account/macros/tokens"), {
"macro_id": LiamW.PostMacros.macroInserter.macros[val]['macro_id'],
"action_url": ed.$oel.closest('form').attr("action"),
"editor_id": ed.$oel.attr('name')
}, function (data, status, xhr) {
XF.setupHtmlInsert(data.html, function ($html, container, onComplete) {
var overlay = new XF.Overlay(XF.getOverlayHtml({
html: $html,
title: container.title || container.h1
}));
overlay.on('overlay:hidden', function () {
overlay.destroy();
});
overlay.show();
});
});
} else
{
XF.ajax("get", XF.canonicalizeUrl('index.php?account/macros/get'), {
"macro_id": LiamW.PostMacros.macroInserter.macros[val]['macro_id'],
"action_url": ed.$oel.closest('form').attr("action")
}, function (data, status, xhr) {
LiamW.PostMacros.macroInserter.processMacroResponse(data.macro, ed);
});
}
}
});
},