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,
10 getVal: function(item
) {
13 setVal: function(item
, val
) {
14 return $(item
).val(val
);
16 insert: function(item
, text
) {
17 CRM
.wysiwyg
._insertIntoTextarea(item
, text
);
19 focus: function(item
) {
22 // Fallback function to use when a wysiwyg has not been initialized
23 _insertIntoTextarea: function(item
, text
) {
24 var origVal
= $(item
).val();
25 var origPos
= item
[0].selectionStart
;
26 var newVal
= origVal
+ text
;
28 var newPos
= (origPos
+ text
.length
);
29 item
[0].selectionStart
= newPos
;
30 item
[0].selectionEnd
= newPos
;
31 $(item
).triggerHandler('change');
32 CRM
.wysiwyg
.focus(item
);
34 // Create a "collapsed" textarea that expands into a wysiwyg when clicked
35 createCollapsed: function(item
) {
38 .on('blur', function () {
39 CRM
.wysiwyg
.destroy(item
);
40 $(item
).hide().next('.replace-plain').show().html($(item
).val());
42 .after('<div class="replace-plain" tabindex="0"></div>');
43 $(item
).next('.replace-plain')
44 .attr('title', ts('Click to edit'))
46 .on('click keypress', function (e
) {
47 // Stop browser from opening clicked links
49 $(item
).show().next('.replace-plain').hide();
50 CRM
.wysiwyg
.create(item
);