Révision 98df731a
Ajouté par Assos Assos il y a plus de 7 ans
drupal7/sites/all/modules/media/modules/media_wysiwyg/js/media_wysiwyg.format_form.js | ||
---|---|---|
30 | 30 |
} |
31 | 31 |
}; |
32 | 32 |
|
33 |
Drupal.media.formatForm.getEditorContent = function(fieldKey) { |
|
34 |
// This is the default implementation of an overridable function: |
|
35 |
// Each javascript rich-text editor module should provide an override implementation |
|
36 |
// of this function which fetches content from the appropriate editor-specific variable. |
|
37 |
|
|
38 |
// This current implementation explicitly handles the editors from the |
|
39 |
// WYSIWYG and Media CKEditor modules: it should be modified to remove that |
|
40 |
// as soon as each module has been confirmed to provide their own implementation. |
|
41 |
|
|
42 |
if (Drupal.wysiwyg && Drupal.wysiwyg.instances[fieldKey]) { |
|
43 |
// Retrieve the content from the editor provided by the WYSIWYG Module. |
|
44 |
// Remove this case once the WYSIWYG module provides an override for this function. |
|
45 |
return Drupal.wysiwyg.instances[fieldKey].getContent(); |
|
46 |
} |
|
47 |
else if (typeof CKEDITOR !== 'undefined' && CKEDITOR.instances[fieldKey]) { |
|
48 |
// Retrieve the content from the editor provided by the Media CKEditor Module. |
|
49 |
// Remove this case once the Media CKEditor module provides an override for this function. |
|
50 |
return CKEDITOR.instances[fieldKey].getData(); |
|
51 |
} |
|
52 |
else { |
|
53 |
// Default case => no known WYSIWYG editor. |
|
54 |
return null; |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
33 | 58 |
Drupal.media.formatForm.getOptions = function () { |
34 | 59 |
// Get all the values |
35 | 60 |
var ret = {}; |
... | ... | |
51 | 76 |
|
52 | 77 |
ret[field.name] = field.value; |
53 | 78 |
|
54 |
// When a field uses a WYSIWYG format, the value needs to be extracted. |
|
79 |
// When a field uses a WYSIWYG format, the value needs to be extracted and encoded.
|
|
55 | 80 |
if (field.name.match(/\[format\]/i)) { |
56 | 81 |
field.name = field.name.replace(/\[format\]/i, '[value]'); |
57 |
field.key = 'edit-' + field.name.replace(/[_\[]/g, '-').replace(/[\]]/g, '');
|
|
82 |
field.key = 'edit-' + field.name.replace(/[_\[]/g, '-').replace(/[\]]/g, ''); |
|
58 | 83 |
|
59 |
if (Drupal.wysiwyg && Drupal.wysiwyg.instances[field.key]) { |
|
60 |
// Retrieve the content from the WYSIWYG instance. |
|
61 |
ret[field.name] = Drupal.wysiwyg.instances[field.key].getContent(); |
|
62 |
|
|
63 |
// Encode the content to play nicely within JSON. |
|
64 |
ret[field.name] = encodeURIComponent(ret[field.name]); |
|
84 |
// Attempt to retrieve content for this field from any associated javascript rich-text editor. |
|
85 |
var editorContent = Drupal.media.formatForm.getEditorContent(field.key); |
|
86 |
if (editorContent) { |
|
87 |
// Replace the already-cached value with the value from the editor. |
|
88 |
ret[field.name] = editorContent; |
|
89 |
} |
|
90 |
else { |
|
91 |
// An editor was not used for this field - either because none was configured for the selected format, |
|
92 |
// or possibly because the user chose to revert to the plain-text editor (CKEditor allows that). |
|
93 |
// Replace the already-cached value with the raw value from the long-text field value. |
|
94 |
// (Replacment is needed because this function may be invoked multiple times on the same field, |
|
95 |
// and so the cached value may already have been encoded - we don't want to double-encode it!) |
|
96 |
ret[field.name] = $('#' + field.key).val(); |
|
65 | 97 |
} |
98 |
|
|
99 |
// Encode the formatted value to play nicely within JSON. |
|
100 |
// (It could contain HTML and other quoted entities, no matter what sort of editor was used) |
|
101 |
ret[field.name] = encodeURIComponent(ret[field.name]); |
|
66 | 102 |
} |
67 | 103 |
}); |
68 | 104 |
|
Formats disponibles : Unified diff
Weekly update of contrib modules