-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrumbowyg.spoiler.js
76 lines (66 loc) · 2.46 KB
/
trumbowyg.spoiler.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
(function ($, Spoiler) {
'use strict';
// Plugin default options
var defaultOptions = {
};
function buildButtonDef(trumbowyg) {
return {
fn: function () {
var $modal = trumbowyg.openModal('Spoiler', [
`<div class="${trumbowyg.o.prefix}spoiler-form-group ">
<label>Title</label>
<input id="title" class="${trumbowyg.o.prefix}spoiler-form-control title"></input>
</div>
<div class="${trumbowyg.o.prefix}spoiler-form-group">
<label>Content</label>
<textarea class="${trumbowyg.o.prefix}spoiler-form-control content"></textarea>
</div>
`
].join('\n')),
$title = $modal.find('.title'),
$content = $modal.find('.content');
// Listen clicks on modal box buttons
$modal.on('tbwconfirm', function () {
trumbowyg.restoreRange();
trumbowyg.execCmd('insertHTML', Spoiler.createHTML({
'spoilerText': $title.val(),
'spoilerContent': $content.val() ? $content.val() : (trumbowyg.getRangeText() ? trumbowyg.getRangeText() : '<br/>')
})
);
trumbowyg.execCmd('insertHTML', '<p><br></p>');
trumbowyg.closeModal();
Spoiler.initAll();
});
$modal.on('tbwcancel', function () {
trumbowyg.closeModal();
});
},
title: 'Insert spoiler',
text: '[]',
hasIcon: false
};
}
$.extend(true, $.trumbowyg, {
langs: {
en: {
spoiler: 'Add spoiler'
}
},
plugins: {
spoiler: {
init: function (trumbowyg) {
trumbowyg.o.plugins.spoiler = $.extend(true, {},
defaultOptions,
trumbowyg.o.plugins.spoiler || {}
);
trumbowyg.addBtnDef('spoiler', buildButtonDef(trumbowyg));
}
}
}
});
})(jQuery, (function() {
if (typeof module !== 'undefined' && module.exports) {
return require('@padawansoftware/spoiler.js');
}
return Spoiler;
})());