This repository has been archived by the owner on Apr 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
editor-plugin.js
91 lines (71 loc) · 2.88 KB
/
editor-plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
module.exports = {
plugin: true,
created: function () {
var vm = this, editor = this.$parent.editor;
if (!editor || !editor.htmleditor) {
return;
}
this.galleries = [];
this.resource = this.$resource('api/gallery{/id}');
editor.addButton('gallery', {
title: this.$trans('Gallery'),
label: '<img src="' + this.$url('packages/shw/gallery/assets/img/editor-icon.svg') + '" width="12px" height="12px" />'
});
editor.options.toolbar.push('gallery');
editor
.on('action.gallery', function (e, editor) {
vm.openModal();
})
.on('render', function () {
vm.galleries = editor.replaceInPreview(/\[gallery(.*?)\/]/gi, vm.replaceInPreview);
})
.on('renderLate', function () {
while (vm.$children.length) {
vm.$children[0].$destroy();
}
Vue.nextTick(function () {
editor.preview.find('gallery-preview').each(function () {
vm.$compile(this);
});
});
});
editor.debouncedRedraw();
},
methods: {
openModal: function () {
var editor = this.$parent.editor, cursor = editor.editor.getCursor();
new this.$options.utils['gallery-picker']({
parent: this,
data: {
gallery: '',
galleries: this.galleries
}
}).$mount()
.$appendTo('body')
.$on('select', function (gallery) {
var replacement = '[gallery id="' + gallery.id + '"';
(gallery.limit > 1) ? replacement += ' limit="' + gallery.limit +'"' : '';
replacement += ' showLink="' + gallery.showLink + '"/]';
editor.editor.replaceRange(replacement, cursor);
});
},
replaceInPreview: function (data) {
var options = {
id: data.matches[1].match(/id="(.+?)"/)[1],
limit: (data.matches[1].match(/limit="(.+?)"/)) ? data.matches[1].match(/limit="(.+?)"/)[1] : false,
showLink: data.matches[1].match(/showLink="(.+?)"/)[1],
};
var preview = '<gallery-preview :id="' + options.id + '" ';
preview += (options.limit) ? ':limit="' + options.limit + '" ' : '';
preview += ':show-link="' + options.showLink + '"></gallery-preview>';
return preview;
}
},
components: {
'gallery-preview': require('../../components/gallery-preview.vue')
},
utils: {
'gallery-picker': Vue.extend(require('../../components/gallery-picker.vue'))
}
};
window.Editor.components['plugin-gallery'] = module.exports;