Файл: wysiwyg/tinymce/files/plugins/smiles/plugin.min.js
Строк: 93
<?php
tinymce.PluginManager.add('smiles', function (editor, url) {
if(!editor.settings.smiles_url){
return false;
}
var smiles = [];
var smiles_list = [];
var load = function (callback) {
if(smiles.length > 0){
return callback();
}
$.ajax({
url: editor.settings.smiles_url,
type: "POST",
async: false,
success: function(result){
if(!result.smiles){ return; }
for(var s in result.smiles){
var tag = '<img class="smile_image" title="'+s+'" src="'+result.smiles[s]+'" />';
smiles.push({
text: s,
value: s,
icon: tag
});
smiles_list[s] = tag;
}
},
dataType: 'json'
});
return callback();
};
var openDialog = function () {
return editor.windowManager.open({
title: 'Insert smiles',
body: {
type: 'panel',
items: [{
type: 'collection',
columns: 'auto',
name: 'results'
}]
},
initialData: {
results: smiles
},
onAction: function (api, details) {
if (details.name === 'results') {
editor.insertContent(smiles_list[details.value]);
api.close();
}
},
buttons: [
{
type: 'cancel',
text: 'Close',
primary: true
}
]
});
};
editor.ui.registry.addButton('smiles', {
tooltip: 'Insert smiles',
icon: 'emoji',
onAction: function () {
load(openDialog);
}
});
editor.ui.registry.addAutocompleter('smilesComplete', {
ch: ')',
minChars: 1,
columns: 'auto',
fetch: function (pattern) {
return load(function (){
var matchedChars = smiles.filter(function (char) {
return char.text.indexOf(pattern) !== -1;
});
return new tinymce.util.Promise(function (resolve) {
var results = matchedChars.map(function (char) {
return {
value: char.value,
text: char.text,
icon: char.icon
};
});
resolve(results);
});
});
},
onAction: function (autocompleteApi, rng, value) {
editor.selection.setRng(rng);
editor.insertContent(smiles_list[value]);
autocompleteApi.hide();
}
});
return {
getMetadata: function () {
return {
name: "Smiles",
url: "https://instantcms.ru/"
};
}
};
});
?>