CKEDITOR.plugins.add('tirusgallery', {
icons: 'gallery',
init: function(editor) {
editor.addCommand('tirusgalleryDialog', new CKEDITOR.dialogCommand('tirusgalleryDialog'));
editor.ui.addButton('Tirusgallery', {
label: 'Insert gallery',
command: 'tirusgalleryDialog',
toolbar: 'insert'
});
}
});
CKEDITOR.dialog.add('tirusgalleryDialog', function(editor) {
var config = {
title: 'Galleries',
minWidth: 400,
minHeight: 100,
contents: [
{
id: 'tab-basic',
label: 'Choose your gallery',
elements: [
{
type: 'select',
id: 'category',
label: 'Category',
items: [],
onLoad: function() {
(function($) {
$.ajax({
url: "/gallery/getgalleries",
dataType: 'json',
data: "",
success: function(data) {
$("label").each(function() {
var value = $(this).html();
if (value == "Category") {
cms_pageSelectElement = $(".cke_dialog_ui_input_select", $(this).parent());
}
if (value == "Album") {
album_pageSelectElement = $(".cke_dialog_ui_input_select", $(this).parent());
}
});
$(cms_pageSelectElement).append("");
$.each(data.result, function(index, value) {
$(cms_pageSelectElement).append(
""
);
});
$(cms_pageSelectElement).change(function() {
var val = $(this).val();
if (val) {
$(album_pageSelectElement).find('option').remove();
console.log("/gallery/getgalleryalbum/" + val);
$.getJSON("/gallery/getgalleryalbum/" + val, function(data) {
$(album_pageSelectElement).append("");
$.each(data.result, function(index, value) {
$(album_pageSelectElement).append(
""
);
});
;
});
}
});
}
});
})(jQuery);
}
},
{
type: 'select',
id: 'album',
label: 'Album',
items: []
}
]
}
],
onOk: function() {
var dialog = this;
var abbr = editor.document.createElement('gallery');
//abbr.setAttribute('title', dialog.getValueOf('tab-basic', 'title'));
abbr.setText('[*]albumList,' + dialog.getValueOf('tab-basic', 'album') + '[/*]');
editor.insertElement(abbr);
}
};
return config;
});