add callback priority to tags html

This commit is contained in:
Sam 2017-03-01 12:56:29 -05:00
parent 0b81a93020
commit 89bd538742
2 changed files with 16 additions and 5 deletions

View File

@ -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);
};
/**

View File

@ -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){