-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaemcomponentsearchbookmarklet.js
83 lines (82 loc) · 3.02 KB
/
aemcomponentsearchbookmarklet.js
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
(function () {
var PREFIX = '/apps';
if (!window.Coral) {
alert('Not Site Admin or AEM page in Edit Mode!');
throw new Error('not a coral page!');
}
var ui = $(window).adaptTo('foundation-ui'),
ID_DLG = 'compsDlg',
old = document.getElementById(ID_DLG);
ui.wait();
if (old) {
old.show();
ui.clearWait();
throw new Error('dialog exists! show');
}
Coral.Autocomplete.prototype._setInputValues = Coral.Autocomplete.prototype._handleInput = Coral.Autocomplete.prototype._handleItemSelectedChange = function () {
return false;
};
Coral.Autocomplete.prototype._handleItemValueChange = function (e) {
e.preventDefault();
e.stopImmediatePropagation();
return false;
};
Coral.Autocomplete.prototype._handleSelect = function (evt) {
evt.preventDefault();
evt.stopImmediatePropagation();
Coral.commons.nextFrame(function () {
window.open(`/mnt/overlay/wcm/core/content/sites/components/details.html${evt.matchedTarget.value}`, '_compDetails').focus();
});
};
fetch(`${window.location.origin}/bin/querybuilder.json?group.1_type=cq:Template&group.2_type=cq:Component&group.p.or=true&orderby=path&orderby.sort=asc&p.limit=-1&path=${PREFIX}`).then((resp) => resp.json()).then((data) => {
showData(data.hits);
}).catch((err) => {
ui.notify('', err, 'warning');
console.log(err);
}).finally(function () {
ui.clearWait();
});
function showData(items) {
var compList = new Coral.Autocomplete().set({
placeholder: 'Type component name',
icon: 'search',
});
compList.style.width = '37em';
var len = items.length;
for (var i = 0; i < len; i++) {
var item, resType, group;
item = items[i];
resType = item.path.replace('/apps/', '');
group = '';
if (!item.path.startsWith(PREFIX)) {
continue;
}
var entry = new Coral.Autocomplete.Item().set({
value: item.path,
content: {
innerHTML: `<li class='coral-List--minimal' title='${resType}'>${group}<b>${Granite.I18n.get(item.title)}</b> (${resType})</li>`,
},
});
compList.items.add(entry);
}
var dialogContent = new Coral.Dialog.Content();
dialogContent.appendChild(compList);
dialogContent.style.width = '40em';
window._dlg = new Coral.Dialog().set({
id: ID_DLG,
header: {
innerHTML: 'Components Lookup <span style=\'font-size:8pt;color:#ccc\'>(ESC to close)</span> <a class=\'coral-Link\' tabindex=\'-1\' target=\'_aemComps\' href=\'/libs/wcm/core/content/sites/components.html\'><coral-icon icon=\'alias\' size=\'XS\'></coral-icon></a>',
},
content: dialogContent,
footer: {
innerHTML: `<button is='coral-button'variant='primary'coral-close=''>Close</button>`,
},
}).show();
compList.showSuggestions();
compList._triggerChangeEvent = false;
ui.clearWait();
$(window._dlg).on('coral-overlay:open', function (e) {
$(window._dlg).find('coral-autocomplete input.coral-Autocomplete-input').focus();
});
}
})();