emoji-plugin/js/plugin.js

59 lines
1.9 KiB
JavaScript
Raw Normal View History

2014-09-17 17:24:13 +04:00
/*!
* This file is a part of Mibew Emoji Plugin.
*
2014-10-22 17:26:21 +04:00
* Copyright 2014 Dmitriy Simushev <simushevds@gmail.com>.
2014-09-17 17:24:13 +04:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function (Mibew, emojify) {
2014-09-18 13:21:55 +04:00
// Initialize separated Marionette.js module for the plugin.
2014-09-17 17:24:13 +04:00
var module = Mibew.Application.module(
2014-09-18 13:21:55 +04:00
'MibewEmojiPlugin',
2014-09-17 17:24:13 +04:00
{startWithParent: false}
);
2014-09-18 13:21:55 +04:00
// Make the plugin works together with "Chat" and "Invitation" modules.
var eventsMap = {
'start': function() {
module.start();
},
'stop': function() {
module.stop();
}
}
Mibew.Application.Chat.on(eventsMap);
Mibew.Application.Invitation.on(eventsMap);
2014-09-17 17:24:13 +04:00
module.addInitializer(function() {
2014-09-26 13:58:30 +04:00
emojify.setConfig({
img_dir: Mibew.PluginOptions.MibewEmoji.imagesDir,
ignore_emoticons: Mibew.PluginOptions.MibewEmoji.ignoreEmoticons
});
2014-09-17 17:24:13 +04:00
// Update message body right after it is added to the messages
// collection.
Mibew.Objects.Collections.messages.on('add', function(model) {
var kind = model.get('kind');
if (kind == model.KIND_USER || kind == model.KIND_AGENT) {
model.set(
'message',
emojify.replace(model.get('message'))
2014-09-17 17:24:13 +04:00
);
}
});
});
})(Mibew, emojify);