!function($, window, document, _undefined)
{
"use strict";
XF.Sysnative = {
init: function(e, ed, xfEditor)
{
var _isBbCodeView = false;
function getButton()
{
return ed.$tb.find('.fr-command[data-cmd=xfBbCode]');
}
function getBbCodeBox()
{
var $oel = ed.$oel;
var $bbCodeBox = $oel.data('xfBbCodeBox');
if (!$bbCodeBox)
{
var borderAdjust = parseInt(ed.$wp.css('border-bottom-width'), 10)
+ parseInt(ed.$wp.css('border-top-width'), 10);
$bbCodeBox = $('<textarea class="input" style="display: none" />');
$bbCodeBox.attr('aria-label', XF.htmlspecialchars(XF.phrase('rich_text_box')));
$bbCodeBox.css({
minHeight: ed.opts.heightMin ? (ed.opts.heightMin + borderAdjust) + 'px' : null,
maxHeight: ed.opts.heightMax ? ed.opts.heightMax + 'px' : null,
height: ed.opts.height ? (ed.opts.height + borderAdjust) + 'px' : null,
padding: ed.$el.css('padding')
});
$bbCodeBox.attr('name', $oel.data('original-name'));
$oel.data('xfBbCodeBox', $bbCodeBox);
ed.$wp.after($bbCodeBox);
XF.Element.applyHandler($bbCodeBox, 'textarea-handler');
XF.Element.applyHandler($bbCodeBox, 'user-mentioner');
XF.Element.applyHandler($bbCodeBox, 'emoji-completer');
}
return $bbCodeBox;
}
ed.bbCode.toBbCode = function toBbCode(bbCode, skipFocus)
{
var apply = function(bbCode, skipFocus)
{
_isBbCodeView = true;
getButton().css('color', '#F2930D');
getBbCodeBox().prop('disabled', true);
ed.undo.saveStep();
ed.html.set(bbCode.replace(/(?:\r\n|\r|\n)/g, '<br>'));
};
if (typeof bbCode == 'string')
{
apply(bbCode, skipFocus);
}
else
{
XF.ajax('POST',
XF.canonicalizeUrl('index.php?editor/to-bb-code'),
{ html: ed.html.get() },
function (data) { apply(data.bbCode, skipFocus); }
);
}
};
ed.bbCode.toHtml = function(bbCode, skipFocus)
{
var apply = function(html)
{
_isBbCodeView = false;
getButton().removeAttr('style');
ed.html.set(html);
ed.undo.saveStep();
};
if (typeof html == 'string')
{
apply(html);
}
else
{
XF.ajax('POST',
XF.canonicalizeUrl('index.php?editor/to-bb-code'),
{ html: ed.html.get() },
function (data) {
var params = { bb_code: data.bbCode };
var $form = ed.$el.closest('form');
if ($form.length)
{
if ($form[0][ed.opts.xfBbCodeAttachmentContextInput])
{
params.attachment_hash_combined = $($form[0][ed.opts.xfBbCodeAttachmentContextInput]).val();
}
}
XF.ajax('POST',
XF.canonicalizeUrl('index.php?editor/to-html'),
params,
function (data) { apply(data.editorHtml); }
);
}
);
}
};
ed.bbCode.toggle = function()
{
if (_isBbCodeView)
{
this.toHtml();
}
else
{
this.toBbCode();
}
};
ed.bbCode.getTextArea = function()
{
return null;
}
ed.$wp.css('display', '');
getBbCodeBox().css('display', 'none').prop('disabled', true);
ed.$tb.find(' > .fr-command').not(getButton().removeClass('fr-active')).removeClass('fr-disabled');
ed.$oel.prop('disabled', false);
XF.setIsEditorEnabled(true);
XF.layoutChange();
}
};
$(document).on('editor:init', XF.Sysnative.init);
}
(jQuery, window, document);