2018-06-24 16:07:22 +03:00
|
|
|
/* ===========================================================
|
|
|
|
* trumbowyg.mention.js v0.1
|
|
|
|
* Mention plugin for Trumbowyg
|
|
|
|
* http://alex-d.github.com/Trumbowyg
|
|
|
|
* ===========================================================
|
|
|
|
* Author : Viper
|
|
|
|
* Github: https://github.com/Globulopolis
|
|
|
|
* Website: http://киноархив.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function ($) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var defaultOptions = {
|
2020-05-12 21:47:37 +03:00
|
|
|
source: [],
|
2018-06-24 16:07:22 +03:00
|
|
|
formatDropdownItem: formatDropdownItem,
|
|
|
|
formatResult: formatResult
|
|
|
|
};
|
|
|
|
|
|
|
|
$.extend(true, $.trumbowyg, {
|
|
|
|
langs: {
|
2020-05-12 21:47:37 +03:00
|
|
|
// jshint camelcase:false
|
2018-06-24 16:07:22 +03:00
|
|
|
en: {
|
|
|
|
mention: 'Mention'
|
|
|
|
},
|
2020-05-12 21:47:37 +03:00
|
|
|
da: {
|
|
|
|
mention: 'Nævn'
|
|
|
|
},
|
2018-06-24 16:07:22 +03:00
|
|
|
fr: {
|
2020-05-12 21:47:37 +03:00
|
|
|
mention: 'Mentionner'
|
2018-06-24 16:07:22 +03:00
|
|
|
},
|
|
|
|
ru: {
|
|
|
|
mention: 'Упомянуть'
|
|
|
|
},
|
|
|
|
tr: {
|
|
|
|
mention: 'Bahset'
|
2020-05-12 21:47:37 +03:00
|
|
|
},
|
|
|
|
zh_tw: {
|
|
|
|
mention: '標記'
|
|
|
|
},
|
|
|
|
pt_br: {
|
|
|
|
mention: 'Menção'
|
|
|
|
},
|
|
|
|
ko: {
|
|
|
|
mention: '언급'
|
|
|
|
},
|
|
|
|
// jshint camelcase:true
|
2018-06-24 16:07:22 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
plugins: {
|
|
|
|
mention: {
|
|
|
|
init: function (trumbowyg) {
|
|
|
|
trumbowyg.o.plugins.mention = $.extend(true, {}, defaultOptions, trumbowyg.o.plugins.mention || {});
|
|
|
|
|
|
|
|
var btnDef = {
|
|
|
|
dropdown: buildDropdown(trumbowyg.o.plugins.mention.source, trumbowyg)
|
|
|
|
};
|
|
|
|
|
|
|
|
trumbowyg.addBtnDef('mention', btnDef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build dropdown list
|
|
|
|
*
|
2020-05-12 21:47:37 +03:00
|
|
|
* @param {Array} items Items
|
|
|
|
* @param {object} trumbowyg Editor
|
2018-06-24 16:07:22 +03:00
|
|
|
*
|
2020-05-12 21:47:37 +03:00
|
|
|
* @return {Array}
|
2018-06-24 16:07:22 +03:00
|
|
|
*/
|
|
|
|
function buildDropdown(items, trumbowyg) {
|
|
|
|
var dropdown = [];
|
|
|
|
|
2020-05-12 21:47:37 +03:00
|
|
|
$.each(items, function (i, item) {
|
|
|
|
var btn = 'mention-' + i,
|
|
|
|
btnDef = {
|
|
|
|
hasIcon: false,
|
|
|
|
text: trumbowyg.o.plugins.mention.formatDropdownItem(item),
|
|
|
|
fn: function () {
|
|
|
|
trumbowyg.execCmd('insertHTML', trumbowyg.o.plugins.mention.formatResult(item));
|
2018-06-24 16:07:22 +03:00
|
|
|
|
2020-05-12 21:47:37 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2018-06-24 16:07:22 +03:00
|
|
|
|
2020-05-12 21:47:37 +03:00
|
|
|
trumbowyg.addBtnDef(btn, btnDef);
|
|
|
|
dropdown.push(btn);
|
|
|
|
});
|
2018-06-24 16:07:22 +03:00
|
|
|
|
|
|
|
return dropdown;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format item in dropdown.
|
|
|
|
*
|
|
|
|
* @param {object} item Item object.
|
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
function formatDropdownItem(item) {
|
|
|
|
return item.login;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format result pasted in editor.
|
|
|
|
*
|
|
|
|
* @param {object} item Item object.
|
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
function formatResult(item) {
|
|
|
|
return '@' + item.login + ' ';
|
|
|
|
}
|
|
|
|
})(jQuery);
|