Mercurial > hg > rr-repo
comparison sites/all/modules/wysiwyg/editors/js/none.js @ 0:ff03f76ab3fe
initial version
author | danieleb <danielebarchiesi@me.com> |
---|---|
date | Wed, 21 Aug 2013 18:51:11 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ff03f76ab3fe |
---|---|
1 (function($) { | |
2 | |
3 /** | |
4 * Attach this editor to a target element. | |
5 * | |
6 * @param context | |
7 * A DOM element, supplied by Drupal.attachBehaviors(). | |
8 * @param params | |
9 * An object containing input format parameters. Default parameters are: | |
10 * - editor: The internal editor name. | |
11 * - theme: The name/key of the editor theme/profile to use. | |
12 * - field: The CSS id of the target element. | |
13 * @param settings | |
14 * An object containing editor settings for all enabled editor themes. | |
15 */ | |
16 Drupal.wysiwyg.editor.attach.none = function(context, params, settings) { | |
17 if (params.resizable) { | |
18 var $wrapper = $('#' + params.field).parents('.form-textarea-wrapper:first'); | |
19 $wrapper.addClass('resizable'); | |
20 if (Drupal.behaviors.textarea) { | |
21 Drupal.behaviors.textarea.attach(); | |
22 } | |
23 } | |
24 }; | |
25 | |
26 /** | |
27 * Detach a single or all editors. | |
28 * | |
29 * The editor syncs its contents back to the original field before its instance | |
30 * is removed. | |
31 * | |
32 * @param context | |
33 * A DOM element, supplied by Drupal.attachBehaviors(). | |
34 * @param params | |
35 * (optional) An object containing input format parameters. If defined, | |
36 * only the editor instance in params.field should be detached. Otherwise, | |
37 * all editors should be detached and saved, so they can be submitted in | |
38 * AJAX/AHAH applications. | |
39 * @param trigger | |
40 * A string describing why the editor is being detached. | |
41 * Possible triggers are: | |
42 * - unload: (default) Another or no editor is about to take its place. | |
43 * - move: Currently expected to produce the same result as unload. | |
44 * - serialize: The form is about to be serialized before an AJAX request or | |
45 * a normal form submission. If possible, perform a quick detach and leave | |
46 * the editor's GUI elements in place to avoid flashes or scrolling issues. | |
47 * @see Drupal.detachBehaviors | |
48 */ | |
49 Drupal.wysiwyg.editor.detach.none = function (context, params, trigger) { | |
50 if (typeof params != 'undefined' && (trigger != 'serialize')) { | |
51 var $wrapper = $('#' + params.field).parents('.form-textarea-wrapper:first'); | |
52 $wrapper.removeOnce('textarea').removeClass('.resizable-textarea') | |
53 .find('.grippie').remove(); | |
54 } | |
55 }; | |
56 | |
57 /** | |
58 * Instance methods for plain text areas. | |
59 */ | |
60 Drupal.wysiwyg.editor.instance.none = { | |
61 insert: function(content) { | |
62 var editor = document.getElementById(this.field); | |
63 | |
64 // IE support. | |
65 if (document.selection) { | |
66 editor.focus(); | |
67 var sel = document.selection.createRange(); | |
68 sel.text = content; | |
69 } | |
70 // Mozilla/Firefox/Netscape 7+ support. | |
71 else if (editor.selectionStart || editor.selectionStart == '0') { | |
72 var startPos = editor.selectionStart; | |
73 var endPos = editor.selectionEnd; | |
74 editor.value = editor.value.substring(0, startPos) + content + editor.value.substring(endPos, editor.value.length); | |
75 } | |
76 // Fallback, just add to the end of the content. | |
77 else { | |
78 editor.value += content; | |
79 } | |
80 }, | |
81 | |
82 setContent: function (content) { | |
83 $('#' + this.field).val(content); | |
84 }, | |
85 | |
86 getContent: function () { | |
87 return $('#' + this.field).val(); | |
88 } | |
89 }; | |
90 | |
91 })(jQuery); |