Skip to content

Commit

Permalink
Fix #25 - option for showing custom emoji first
Browse files Browse the repository at this point in the history
  • Loading branch information
pitaj committed Jul 19, 2019
1 parent 0d144fb commit 963090e
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 5 deletions.
13 changes: 13 additions & 0 deletions lib/index.ts
Expand Up @@ -93,11 +93,24 @@ const addStylesheet = (data: {
callback(null, data);
};

const configGet = (config: any, next: NodeBack<any>) => {
settings.getOne('customFirst', (err, customFirst) => {
if (err) {
next(err);
return;
}

config.emojiCustomFirst = customFirst;
next(null, config);
});
};

export {
init,
adminMenu,
composerFormatting,
plugins,
parse,
addStylesheet,
configGet,
};
14 changes: 11 additions & 3 deletions lib/settings.ts
Expand Up @@ -8,11 +8,13 @@ const settings: {
interface Settings {
parseNative: boolean;
parseAscii: boolean;
customFirst: boolean;
}

const defaults: Settings = {
parseNative: true,
parseAscii: true,
customFirst: false,
};

const get = (callback: NodeBack<{ [key: string]: any }>) => {
Expand Down Expand Up @@ -55,14 +57,20 @@ const set = (data: {

settings.set('emoji', sets, callback);
};
const getOne = (field: string, callback: NodeBack<any>) => {
settings.getOne('emoji', field, (err, val) => {
const getOne = (field: keyof Settings, callback: NodeBack<any>) => {
settings.getOne('emoji', field, (err, str) => {
if (err) {
callback(err);
return;
}

callback(null, JSON.parse(val));
const defaultVal = defaults[field];
let val = JSON.parse(str);
if (typeof val !== typeof defaultVal) {
val = defaultVal;
}

callback(null, val);
});
};
const setOne = (field: string, value: any, callback: NodeBack<void>) => {
Expand Down
3 changes: 2 additions & 1 deletion plugin.json
Expand Up @@ -32,6 +32,7 @@
{ "hook": "filter:parse.post", "method": "parse.post", "priority": 9 },
{ "hook": "action:plugin.activate", "method": "plugins.activation" },
{ "hook": "action:plugin.deactivate", "method": "plugins.deactivation" },
{ "hook": "filter:meta.getLinkTags", "method": "addStylesheet" }
{ "hook": "filter:meta.getLinkTags", "method": "addStylesheet" },
{ "hook": "filter:config.get", "method": "configGet" }
]
}
1 change: 1 addition & 0 deletions public/admin.js
Expand Up @@ -9,6 +9,7 @@ define('admin/plugins/emoji', [], function () {
var settings = {
parseAscii: !!$('#emoji-parseAscii').prop('checked'),
parseNative: !!$('#emoji-parseNative').prop('checked'),
customFirst: !!$('#emoji-customFirst').prop('checked'),
};
$.get(window.config.relative_path + '/api/admin/plugins/emoji/save', { settings: JSON.stringify(settings) }, function () {
window.app.alertSuccess();
Expand Down
2 changes: 1 addition & 1 deletion public/language/en-US/admin/plugins/emoji.json
Expand Up @@ -2,7 +2,7 @@
"settings": "Settings",
"settings.parseAscii": "Replace common ASCII characters like <code>:)</code>, <code>-_-</code>, etc",
"settings.parseNative": "Replace native unicode emoji characters with emoji provided by emoji packs",
"settings.shouldBuild": "Re-build emoji assets on the next forum restart",
"settings.customFirst": "Place your custom emoji first in the dialog",
"build": "Build Emoji Assets",
"build_description": "Compile the necessary metadata and static assets from all emoji packs. <br> This is usually unnecessary to do yourself, but if emojis aren't showing up, try this first."
}
4 changes: 4 additions & 0 deletions public/lib/emoji-dialog.ts
Expand Up @@ -46,6 +46,10 @@ const priorities: {
other: 0,
};

if (window.config.emojiCustomFirst) {
priorities.custom = 100;
}

const translator = Translator.create();

function stringCompare(a: string, b: string) {
Expand Down
1 change: 1 addition & 0 deletions public/lib/types.d.ts
Expand Up @@ -4,6 +4,7 @@ interface Window {
config: {
relative_path: string;
'cache-buster': string;
emojiCustomFirst: boolean;
};
app: {
alertSuccess(message?: string): void;
Expand Down
7 changes: 7 additions & 0 deletions public/templates/admin/plugins/emoji.tpl
Expand Up @@ -14,6 +14,13 @@
[[admin/plugins/emoji:settings.parseNative]]
</label>
</div>

<div class="form-group">
<label for="emoji-customFirst">
<input id="emoji-customFirst" type="checkbox" <!-- IF settings.customFirst --> checked <!-- ENDIF settings.customFirst --> />
[[admin/plugins/emoji:settings.customFirst]]
</label>
</div>
</div>

<div class="panel-footer">
Expand Down

0 comments on commit 963090e

Please sign in to comment.