mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 08:32:45 +08:00
add callback priority to tags html
This commit is contained in:
parent
0b81a93020
commit
89bd538742
|
@ -392,6 +392,7 @@ class PluginApi {
|
|||
|
||||
/**
|
||||
* Register a callback to be called every time tags render
|
||||
* highest priority callbacks are called first
|
||||
* example:
|
||||
*
|
||||
* callback = function(topic, params) {
|
||||
|
@ -400,11 +401,11 @@ class PluginApi {
|
|||
* }
|
||||
* }
|
||||
*
|
||||
* api.addTagsHtmlCallback(callback);
|
||||
* api.addTagsHtmlCallback(callback, {priority: 100});
|
||||
*
|
||||
**/
|
||||
addTagsHtmlCallback(callback) {
|
||||
addTagsHtmlCallback(callback);
|
||||
addTagsHtmlCallback(callback, options) {
|
||||
addTagsHtmlCallback(callback, options);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,10 +1,20 @@
|
|||
import renderTag from 'discourse/lib/render-tag';
|
||||
|
||||
let callbacks = null;
|
||||
let priorities = null;
|
||||
|
||||
export function addTagsHtmlCallback(callback) {
|
||||
export function addTagsHtmlCallback(callback, options) {
|
||||
callbacks = callbacks || [];
|
||||
callbacks.push(callback);
|
||||
priorities = priorities || [];
|
||||
const priority = (options && options.priority) || 0;
|
||||
|
||||
let i = 0;
|
||||
while(i < priorities.length && priorities[i] > priority) {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
priorities.splice(i, 0, priority);
|
||||
callbacks.splice(i, 0, callback);
|
||||
};
|
||||
|
||||
export default function(topic, params){
|
||||
|
|
Loading…
Reference in New Issue
Block a user