This repository has been archived by the owner on Mar 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
emoji-data: add core plugin for emoji info in dom
- Loading branch information
René Kooi
committed
Aug 22, 2015
1 parent
d761f5b
commit ab99295
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
define(function (require, exports, module) { | ||
|
||
const Plugin = require('../Plugin') | ||
const Events = require('plug/core/Events') | ||
const emoji = require('plug/util/emoji') | ||
const { around } = require('meld') | ||
|
||
const EmojiDataPlugin = Plugin.extend({ | ||
name: 'Emoji Data', | ||
description: 'Adds CSS classes and HTML5 data attributes to emoji images.', | ||
|
||
enable() { | ||
this.advice = around(emoji, 'replacement', joinpoint => { | ||
let name = joinpoint.args[2] | ||
let html = joinpoint.proceed() | ||
return html.replace( | ||
' class="emoji-inner', | ||
` data-emoji-name="${name}" class="emoji-inner extplug-emoji-${name}` | ||
) | ||
}) | ||
|
||
this.listenTo(Events, 'chat:afterreceive', (msg, el) => { | ||
el.find('.gemoji-plug').each(function () { | ||
let inner = $(this) | ||
let emojiName = inner.attr('class').match(/gemoji-plug-(\S+)/) | ||
if (emojiName) { | ||
inner.attr('data-emoji-name', emojiName[1]) | ||
.addClass(`extplug-emoji-${name}`) | ||
} | ||
}) | ||
}) | ||
}, | ||
|
||
disable() { | ||
this.advice.remove() | ||
} | ||
}) | ||
|
||
module.exports = EmojiDataPlugin | ||
|
||
}) |