Commit | Line | Data |
---|---|---|
7c523661 TC |
1 | // https://civicrm.org/licensing |
2 | (function($, _) { | |
f91b1c0c CW |
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 | |
5 | CRM.wysiwyg = { | |
6 | supportsFileUploads: false, | |
c63f9bfb CW |
7 | create: function() { |
8 | return $.Deferred().resolve(); | |
9 | }, | |
f91b1c0c CW |
10 | destroy: _.noop, |
11 | updateElement: _.noop, | |
12 | getVal: function(item) { | |
13 | return $(item).val(); | |
14 | }, | |
15 | setVal: function(item, val) { | |
16 | return $(item).val(val); | |
17 | }, | |
18 | insert: function(item, text) { | |
19 | CRM.wysiwyg._insertIntoTextarea(item, text); | |
20 | }, | |
21 | focus: function(item) { | |
22 | $(item).focus(); | |
23 | }, | |
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; | |
29 | $(item).val(newVal); | |
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); | |
35 | }, | |
0bd65d9b | 36 | // Create a "collapsed" textarea that expands into a wysiwyg when clicked |
f91b1c0c CW |
37 | createCollapsed: function(item) { |
38 | $(item) | |
39 | .hide() | |
f91b1c0c CW |
40 | .on('blur', function () { |
41 | CRM.wysiwyg.destroy(item); | |
42 | $(item).hide().next('.replace-plain').show().html($(item).val()); | |
0bd65d9b CW |
43 | }) |
44 | .after('<div class="replace-plain" tabindex="0"></div>'); | |
45 | $(item).next('.replace-plain') | |
46 | .attr('title', ts('Click to edit')) | |
47 | .html($(item).val()) | |
48 | .on('click keypress', function (e) { | |
49 | // Stop browser from opening clicked links | |
50 | e.preventDefault(); | |
51 | $(item).show().next('.replace-plain').hide(); | |
52 | CRM.wysiwyg.create(item); | |
f91b1c0c | 53 | }); |
f91b1c0c | 54 | } |
7c523661 | 55 | }; |
7c523661 | 56 | })(CRM.$, CRM._); |