forked from MegaGM/nodebb-plugin-mega-colors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
button.js
35 lines (35 loc) · 1.12 KB
/
button.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
$('document').ready(function () {
require(['composer', 'composer/controls'], function (composer, controls) {
var text, start, end;
composer.addButton('fa fa-eyedropper', function (textarea, selectionStart, selectionEnd) {
text = textarea;
});
$(document).on('click', '[data-format="eyedropper"]', function () {
$('.fa-eyedropper').ColorPicker({
onShow: function (el) {
$(el).show();
return false;
controls.updateTextareaSelection(text, start, end);
},
onHide: function (el) {
$(el).hide();
return false;
},
onSubmit: function (hsb, hex, rgb, el) {
$(el).ColorPickerHide();
if (start === end) {
controls.insertIntoTextarea(text, '%(#' + hex + ')[Colored Text Here]');
controls.updateTextareaSelection(text, start + 11, end + 28);
} else {
controls.wrapSelectionInTextareaWith(text, '%(#' + hex + ')[', ']');
controls.updateTextareaSelection(text, start + 11, end + 11);
}
}
}).trigger('click');
});
$(document).on('blur', 'textarea.write', function () {
start = this.selectionStart;
end = this.selectionEnd;
});
});
});