1 // https://civicrm.org/licensing
3 // This defines an interface which by default only handles plain textareas
4 // A wysiwyg implementation can extend this by overriding as many of these functions as needed
6 supportsFileUploads
: false,
8 return $.Deferred().resolve();
11 updateElement
: _
.noop
,
12 getVal: function(item
) {
15 setVal: function(item
, val
) {
16 return $(item
).val(val
);
18 insert: function(item
, text
) {
19 CRM
.wysiwyg
._insertIntoTextarea(item
, text
);
21 focus: function(item
) {
24 // Fallback function to use when a wysiwyg has not been initialized
25 _insertIntoTextarea: function(item
, text
) {
26 var origVal
= $(item
).val();
27 var origPos
= item
[0].selectionStart
;
28 var newVal
= origVal
+ text
;
30 var newPos
= (origPos
+ text
.length
);
31 item
[0].selectionStart
= newPos
;
32 item
[0].selectionEnd
= newPos
;
33 $(item
).triggerHandler('change');
34 CRM
.wysiwyg
.focus(item
);
36 // Create a "collapsed" textarea that expands into a wysiwyg when clicked
37 createCollapsed: function(item
) {
40 .on('blur', function () {
41 CRM
.wysiwyg
.destroy(item
);
42 $(item
).hide().next('.replace-plain').show().html($(item
).val());
44 .after('<div class="replace-plain" tabindex="0"></div>');
45 $(item
).next('.replace-plain')
46 .attr('title', ts('Click to edit'))
48 .on('click keypress', function (e
) {
49 // Stop browser from opening clicked links
51 $(item
).show().next('.replace-plain').hide();
52 CRM
.wysiwyg
.create(item
);