$(function()
{
/**
* Primary button in the editor toolbar
*/
var $draftButton = $('<button>', {
id: "xfDraft-1",
type: 'button',
tabindex: '-1',
role: 'button',
'aria-controls': 'dropdown-menu-xfDraft-1',
'aria-expanded': "false",
'aria-haspopup': 'true',
class: 'fr-command fr-btn fr-dropdown',
'data-cmd': 'xfDraft',
'data-title': 'Drafts'
});
var $faIcon = $('<i>', {
class: 'far fa-save',
ariaHidden: 'true'
})
var $srOnlyLabel = $('<span>', {
class: 'fr-sr-only'
}).text('Drafts');
$faIcon.appendTo($draftButton);
$srOnlyLabel.appendTo($draftButton);
$($draftButton).appendTo($('.rte-tab--beforePreview'));
/**
* Drop-down menu for the primary button added
*/
var $draftMenuContainer = $('<div />', {
id: 'dropdown-menu-xfDraft-1',
class: 'fr-dropdown-menu',
role: 'listbox',
'aria-labelledby': 'xfDraft-1',
'aria-hidden': 'true'
});
var $dropdownWrapper = $('<div />', {
class: 'fr-dropdown-wrapper',
role: 'presentation'
});
var $dropdownContent = $('<div />', {
class: 'fr-dropdown-content',
role: 'presentation'
});
var $dropdownList = $('<ul />', {
class: 'fr-dropdown-list',
role: 'presentation'
});
var dropdownListButtons = [
{param: 'xfDraftSave', title: 'Save draft'},
{param: 'xfDraftDelete', title: 'Delete draft'}
];
$.each(dropdownListButtons, function ()
{
var $listItem = $('<li />', {
role: 'presentation'
});
$('<a />', {
class: 'fr-command',
tabindex: '-1',
role: 'option',
'data-cmd': 'xfDraft',
'data-param1': this.param,
title: this.title
}).text(this.title).appendTo($listItem);
$listItem.appendTo($dropdownList)
});
$dropdownList.appendTo($dropdownContent);
$dropdownContent.appendTo($dropdownWrapper);
$dropdownWrapper.appendTo($draftMenuContainer);
$draftMenuContainer.insertAfter('#xfDraft-1');
// Update the quick reply form
var $quickReplyForm = $('.js-quickReply'),
initList = $quickReplyForm.attr('data-xf-init');
if (initList === undefined)
{
initList = '';
}
initList += ' draft';
var draftUrl = location.pathname;
if (window.location.search) // don't care about having /page-420 or anything like that
{
draftUrl += location.search;
}
draftUrl += '/draft';
$quickReplyForm
.attr('data-xf-init', initList)
.data('draft-url', draftUrl)
.data('auto-draft-autosave', '69') // hehe
XF.activate($quickReplyForm);
var $messageHtml = $quickReplyForm.find('textarea[name="message_html"]');
if (XF.isElementWithinDraftForm($quickReplyForm))
{
$quickReplyForm.data('delay', 500);
XF.Element.applyHandler($quickReplyForm, 'draft-trigger');
}
});