mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 19:39:30 +08:00
select-kit initial plugin api implementation (0.8.13)
``` api.modifySelectKit("identifier-of-the-select-targeted") .modifyContent((context, existingContent) => {}) .appendContent(() => {}) .prependContent(() => {}) .onSelect((context, val) => {}); ```
This commit is contained in:
@ -25,7 +25,16 @@ function modifyContent(pluginApiIdentifiers, contentFunction) {
|
||||
_modifyContentCallbacks[pluginApiIdentifiers].push(contentFunction);
|
||||
}
|
||||
|
||||
export function applyContentPluginApiCallbacks(identifiers, content) {
|
||||
let _onSelectCallbacks = {};
|
||||
function onSelect(pluginApiIdentifiers, mutationFunction) {
|
||||
if (Ember.isNone(_onSelectCallbacks[pluginApiIdentifiers])) {
|
||||
_onSelectCallbacks[pluginApiIdentifiers] = [];
|
||||
}
|
||||
|
||||
_onSelectCallbacks[pluginApiIdentifiers].push(mutationFunction);
|
||||
}
|
||||
|
||||
export function applyContentPluginApiCallbacks(identifiers, content, context) {
|
||||
identifiers.forEach((key) => {
|
||||
(_prependContentCallbacks[key] || []).forEach((c) => {
|
||||
content = c().concat(content);
|
||||
@ -34,13 +43,19 @@ export function applyContentPluginApiCallbacks(identifiers, content) {
|
||||
content = content.concat(c());
|
||||
});
|
||||
(_modifyContentCallbacks[key] || []).forEach((c) => {
|
||||
content = c(content);
|
||||
content = c(context, content);
|
||||
});
|
||||
});
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
export function applyOnSelectPluginApiCallbacks(identifiers, val, context) {
|
||||
identifiers.forEach((key) => {
|
||||
(_onSelectCallbacks[key] || []).forEach((c) => c(context, val));
|
||||
});
|
||||
}
|
||||
|
||||
export function modifySelectKit(pluginApiIdentifiers) {
|
||||
return {
|
||||
appendContent: (content) => {
|
||||
@ -54,6 +69,10 @@ export function modifySelectKit(pluginApiIdentifiers) {
|
||||
modifyContent: (callback) => {
|
||||
modifyContent(pluginApiIdentifiers, callback);
|
||||
return modifySelectKit(pluginApiIdentifiers);
|
||||
},
|
||||
onSelect: (callback) => {
|
||||
onSelect(pluginApiIdentifiers, callback);
|
||||
return modifySelectKit(pluginApiIdentifiers);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -62,6 +81,7 @@ export function clearCallbacks() {
|
||||
_appendContentCallbacks = {};
|
||||
_prependContentCallbacks = {};
|
||||
_modifyContentCallbacks = {};
|
||||
_onSelectCallbacks = {};
|
||||
}
|
||||
|
||||
const EMPTY_ARRAY = Object.freeze([]);
|
||||
|
Reference in New Issue
Block a user