*
* @param string wysiwygSelector
*/
- init: function (wysiwygSelector) {
+ init: function (wysiwygSelector, smiliesTabMenuId, formBuilderUsage) {
this._proxy = new WCF.Action.Proxy({
success: $.proxy(this._success, this)
});
this._wysiwygSelector = wysiwygSelector;
+ this._smiliesTabMenuId = smiliesTabMenuId || 'smilies-' + this._wysiwygSelector;
+ this._formBuilderUsage = formBuilderUsage || false;
- $('#smilies-' + this._wysiwygSelector).on('messagetabmenushow', $.proxy(this._click, this));
+ $('#' + this._smiliesTabMenuId).on('messagetabmenushow', $.proxy(this._click, this));
},
/**
_click: function (event, data) {
event.preventDefault();
- var $categoryID = parseInt(data.activeTab.tab.data('smileyCategoryID'));
+ if (this._formBuilderUsage) {
+ var href = data.activeTab.tab.children('a').prop('href');
+ if (href.match(/#([a-zA-Z0-9_-]+)$/)) {
+ var anchor = RegExp.$1;
+
+ if (anchor.match(this._smiliesTabMenuId.replace(/Container$/, '') + '_smileyCategoryTab(\\d+)Container')) {
+ var categoryID = parseInt(RegExp.$1);
+ }
+ else {
+ console.debug("[WCF.Message.SmileyCategories] Cannot extract category id for tab '" + data.activeTab.tab.wcfIdentify() + "'.");
+ return;
+ }
+ }
+ else {
+ console.debug("[WCF.Message.SmileyCategories] Cannot extract category id for tab '" + data.activeTab.tab.wcfIdentify() + "'.");
+ return;
+ }
+ }
+ else {
+ var categoryID = parseInt(data.activeTab.tab.data('smileyCategoryID'));
+ }
// ignore global category, will always be pre-loaded
- if (!$categoryID) {
+ if (!categoryID) {
return;
}
}
// cache exists
- if (this._cache[$categoryID] !== undefined) {
- data.activeTab.container.html(this._cache[$categoryID]);
+ if (this._cache[categoryID] !== undefined) {
+ data.activeTab.container.html(this._cache[categoryID]);
return;
}
this._proxy.setOption('data', {
actionName: 'getSmilies',
className: 'wcf\\data\\smiley\\category\\SmileyCategoryAction',
- objectIDs: [$categoryID]
+ objectIDs: [categoryID]
});
this._proxy.sendRequest();
},
var $categoryID = parseInt(data.returnValues.smileyCategoryID);
this._cache[$categoryID] = data.returnValues.template;
- $('#smilies-' + this._wysiwygSelector + '-' + $categoryID).html(data.returnValues.template);
+ if (this._formBuilderUsage) {
+ $('#' + this._smiliesTabMenuId.replace(/Container$/, '') + '_smileyCategoryTab' + $categoryID + 'Container').html(data.returnValues.template);
+ }
+ else {
+ $('#smilies-' + this._wysiwygSelector + '-' + $categoryID).html(data.returnValues.template);
+ }
}
});
*/
public function __construct() {
$this->attribute('data-preselect', 'true')
- ->attribute('data-collapsible', 'false')
- ->useAnchors(false);
+ ->attribute('data-collapsible', 'false');
}
/**
public function populate() {
parent::populate();
- $smileyCategories = SmileyCache::getInstance()->getCategories();
+ $smileyCategories = array_values(SmileyCache::getInstance()->getCategories());
- foreach ($smileyCategories as $smileyCategory) {
+ foreach ($smileyCategories as $index => $smileyCategory) {
$smileyCategory->loadSmilies();
if (count($smileyCategory) > 0) {
+ // all of the smilies not in the first category are loaded via
+ // JavaScript
+ $smilies = [];
+ if (!$index) {
+ $smilies = SmileyCache::getInstance()->getCategorySmilies($smileyCategory->categoryID ?: null);
+ }
+
$this->appendChild(
TabFormContainer::create($this->getId() . '_smileyCategoryTab' . $smileyCategory->categoryID)
->label(StringUtil::encodeHTML($smileyCategory->getTitle()))
->removeClass('section')
->appendChild(
WysiwygSmileyFormNode::create($this->getId() . '_smileyCategory' . $smileyCategory->categoryID)
- ->smilies(SmileyCache::getInstance()->getCategorySmilies($smileyCategory->categoryID ?: null))
+ ->smilies($smilies)
)
)
);