forked from ezsystems/PlatformUIBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
embed.jsx
104 lines (92 loc) · 3.38 KB
/
embed.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Copyright (C) eZ Systems AS. All rights reserved.
* For full copyright and license information view LICENSE file distributed with this source code.
*/
YUI.add('ez-alloyeditor-button-embed', function (Y) {
"use strict";
var AlloyEditor = Y.eZ.AlloyEditor,
React = Y.eZ.React,
ButtonEmbed;
/**
* The ButtonEmbed component represents a button to add an embed element.
*
* @uses AlloyEditor.ButtonCommand
* @uses AlloyEditor.ButtonStateClasses
* @uses eZ.AlloyEditorToolbarConfig.ButtonEmbedDiscoverContent
*
* @class eZ.AlloyEditor.ButtonEmbed
*/
ButtonEmbed = React.createClass({
mixins: [
AlloyEditor.ButtonCommand,
AlloyEditor.ButtonStateClasses,
Y.eZ.AlloyEditorButton.WidgetButton,
Y.eZ.AlloyEditorButton.ButtonEmbedDiscoverContent,
],
statics: {
key: 'ezembed'
},
getDefaultProps: function () {
return {
command: 'ezembed',
modifiesSelection: true,
udwTitle: 'Select a content to embed',
udwContentDiscoveredMethod: '_addEmbed',
};
},
/**
* Returns the UDW title to pick a Content to embed.
*
* @method _getUDWTitle
* @protected
* @return {String}
*/
_getUDWTitle: function () {
return Y.eZ.trans('select.a.content.to.embed', {}, 'onlineeditor');
},
/**
* Checks if the command is disabled in the current selection.
*
* @method isDisabled
* @return {Boolean} True if the command is disabled, false otherwise.
*/
isDisabled: function () {
return !this.props.editor.get('nativeEditor').ezembed.canBeAdded();
},
/**
* Executes the command generated by the ezembed plugin and set the
* correct value based on the choosen content.
*
* @method _addEmbed
* @param {EventFacade} e the result of the choice in the UDW
* @protected
*/
_addEmbed: function (e) {
var contentInfo = e.selection.contentInfo,
widget,
scrollY;
if (navigator.userAgent.indexOf('Chrome') > -1) {
// Workaround for https://jira.ez.no/browse/EZP-28078
scrollY = window.pageYOffset;
this.execCommand();
window.scroll(window.pageXOffset, scrollY);
} else {
this.execCommand();
}
this._setContentInfo(contentInfo);
widget = this._getWidget().setWidgetContent('');
this._fireUpdatedEmbed(e.selection);
widget.setFocused(true);
},
render: function () {
var css = "ae-button ez-ae-labeled-button" + this.getStateClasses(), disabled = this.isDisabled();
return (
<button className={css} disabled={disabled} onClick={this._chooseContent} tabIndex={this.props.tabIndex}>
<span className="ez-ae-icon ez-ae-icon-embed ez-font-icon"></span>
<p className="ez-ae-label">{Y.eZ.trans('embed', {}, 'onlineeditor')}</p>
</button>
);
},
});
AlloyEditor.Buttons[ButtonEmbed.key] = AlloyEditor.ButtonEmbed = ButtonEmbed;
});