Révision 98df731a
Ajouté par Assos Assos il y a plus de 7 ans
drupal7/sites/all/modules/media_ckeditor/js/plugins/media/plugin.js | ||
---|---|---|
13 | 13 |
var mediaPluginDefinition = { |
14 | 14 |
icons: 'media', |
15 | 15 |
requires: ['button'], |
16 |
// Check if this instance has widget support. All the default distributions
|
|
17 |
// of the editor have the widget plugin disabled by default.
|
|
18 |
hasWidgetSupport: typeof(CKEDITOR.plugins.registered.widget) != 'undefined',
|
|
16 |
// All the default distributions of the editor have the widget plugin
|
|
17 |
// disabled by default. |
|
18 |
hasWidgetSupport: false,
|
|
19 | 19 |
mediaLegacyWrappers: false, |
20 |
onLoad: function() { |
|
21 |
// Check if this instance has widget support. |
|
22 |
mediaPluginDefinition.hasWidgetSupport = typeof(CKEDITOR.plugins.registered.widget) != 'undefined'; |
|
23 |
// Add dependency to widget plugin if possible. |
|
24 |
if (parseFloat(CKEDITOR.version) >= 4.3 && mediaPluginDefinition.hasWidgetSupport) { |
|
25 |
mediaPluginDefinition.requires.push('widget'); |
|
26 |
} |
|
27 |
}, |
|
20 | 28 |
|
21 | 29 |
// Wrap Drupal plugin in a proxy plugin. |
22 | 30 |
init: function(editor){ |
... | ... | |
52 | 60 |
} |
53 | 61 |
}); |
54 | 62 |
|
63 |
// Add a Ckeditor context menu item for editing already-inserted media. |
|
64 |
if (editor.contextMenu) { |
|
65 |
editor.addCommand('mediaConfigure', { |
|
66 |
exec: function (editor) { |
|
67 |
editor.execCommand('media'); |
|
68 |
}, |
|
69 |
}); |
|
70 |
|
|
71 |
editor.addMenuGroup('mediaGroup'); |
|
72 |
editor.addMenuItem('mediaConfigureItem', { |
|
73 |
label: Drupal.t('Media settings'), |
|
74 |
icon: this.path + 'images/icon.gif', |
|
75 |
command: 'mediaConfigure', |
|
76 |
group: 'mediaGroup' |
|
77 |
}); |
|
78 |
|
|
79 |
editor.contextMenu.addListener(function(element) { |
|
80 |
if (element.getAttribute('data-media-element') || |
|
81 |
element.find('[data-media-element]').count()) { |
|
82 |
return { mediaConfigureItem: CKEDITOR.TRISTATE_OFF }; |
|
83 |
}; |
|
84 |
}); |
|
85 |
} |
|
86 |
|
|
87 |
// Add the toolbar button. |
|
55 | 88 |
editor.ui.addButton( 'Media', |
56 | 89 |
{ |
57 | 90 |
label: 'Add media', |
... | ... | |
83 | 116 |
CKEDITOR.dtd.$object['mediawrapper'] = 1; |
84 | 117 |
} |
85 | 118 |
function prepareDataForWysiwygMode(data) { |
86 |
data = Drupal.media.filter.replaceTokenWithPlaceholder(data); |
|
119 |
if (typeof Drupal.media !== 'undefined') { |
|
120 |
data = Drupal.media.filter.replaceTokenWithPlaceholder(data); |
|
121 |
} |
|
87 | 122 |
// Legacy media wrapper. |
88 | 123 |
mediaPluginDefinition.mediaLegacyWrappers = (data.indexOf("<!--MEDIA-WRAPPER-START-") !== -1); |
89 | 124 |
if (mediaPluginDefinition.mediaLegacyWrappers) { |
... | ... | |
98 | 133 |
replacement = '<!--MEDIA-WRAPPER-START-$1-->$2<!--MEDIA-WRAPPER-END-$1-->'; |
99 | 134 |
} |
100 | 135 |
data = data.replace(/<mediawrapper data="(.*?)">(.*?)<\/mediawrapper>/gi, replacement); |
101 |
data = Drupal.media.filter.replacePlaceholderWithToken(data); |
|
136 |
if (typeof Drupal.media !== 'undefined') { |
|
137 |
data = Drupal.media.filter.replacePlaceholderWithToken(data); |
|
138 |
} |
|
102 | 139 |
return data; |
103 | 140 |
} |
104 | 141 |
|
... | ... | |
126 | 163 |
return new CKEDITOR.htmlParser.text(token); |
127 | 164 |
} |
128 | 165 |
return false; |
166 |
}, |
|
167 |
|
|
168 |
init: function() { |
|
169 |
// Add double-click functionality to the widget. |
|
170 |
this.on('doubleclick', function(evt) { |
|
171 |
editor.execCommand('media'); |
|
172 |
}, null, null, 5 ); |
|
129 | 173 |
} |
130 | 174 |
}); |
131 | 175 |
} |
... | ... | |
214 | 258 |
} |
215 | 259 |
} |
216 | 260 |
}; |
217 |
// Add dependency to widget plugin if possible. |
|
218 |
if (parseFloat(CKEDITOR.version) >= 4.3 && mediaPluginDefinition.hasWidgetSupport) { |
|
219 |
mediaPluginDefinition.requires.push('widget'); |
|
220 |
} |
|
261 |
|
|
221 | 262 |
CKEDITOR.plugins.add( 'media', mediaPluginDefinition); |
222 | 263 |
} )(); |
Formats disponibles : Unified diff
Weekly update of contrib modules