components-embed.js
1.54 KB
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
(function($, ns, channel, window) {
'use strict';
var ACTION_NAME = 'EDIT_PAGE';
var RESOURCE_PATH_ATTR = 'editpath';
var EDIT_WRAPPER_SELECTOR = '.aem-Screens-editWrapper';
// @todo move hardcoded Path to constants file
var CHANNEL_RESOURCE_TYPES = [
'screens/core/components/channel',
'screens/core/components/appchannel',
'screens/core/components/sequencechannel'
];
var editAction = new ns.ui.ToolbarAction({
name: ACTION_NAME,
icon: 'edit',
text: Granite.I18n.get('Edit'),
index: 0,
condition: function(editable) {
return typeof editable.dom.contents(EDIT_WRAPPER_SELECTOR).data(RESOURCE_PATH_ATTR) === 'string';
},
execute: function(editable) {
window.open(Granite.HTTP.externalize('/editor.html' + editable.dom.contents(EDIT_WRAPPER_SELECTOR).data(RESOURCE_PATH_ATTR) + '.edit.html'));
}
});
function isChannel() {
return ns.pageInfo && CHANNEL_RESOURCE_TYPES.indexOf(ns.pageInfo.pageResourceType) > -1 || CHANNEL_RESOURCE_TYPES.indexOf(ns.pageInfo.pageResourceSuperType) > -1;
}
/* authoring layer activation event */
channel.one('cq-editor-loaded', function() {
channel.on('cq-layer-activated', function() {
if (isChannel()) {
ns.EditorFrame.editableToolbar.registerAction(ACTION_NAME, editAction);
ns.config.toolbarActionOrder.unshift(ACTION_NAME);
}
});
});
}(Granite.$, Granite.author, Granite.$(document), this));