Skip to content

Commit f85a78b

Browse files
committed
DOC-1820: Updated Search index to add more content and better use of search feature.
1 parent 8b78e87 commit f85a78b

File tree

1 file changed

+25
-38
lines changed

1 file changed

+25
-38
lines changed

modules/ROOT/examples/live-demos/custom-toolbar-menu-button-search/index.js

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,39 @@ tinymce.init({
22
selector: 'textarea#custom-toolbar-menu-button-search',
33
height: 500,
44
toolbar: 'mybutton',
5-
5+
toolbar: 'searchMenuButton',
66
setup: (editor) => {
7-
/* Menu items are recreated when the menu is closed and opened, so we need
8-
a variable to store the toggle menu item state. */
97
let toggleState = false;
10-
11-
/* example, adding a toolbar menu button */
12-
editor.ui.registry.addMenuButton('mybutton', {
13-
text: 'My searchable button',
14-
search: {
15-
placeholder: 'Type...'
16-
},
8+
editor.ui.registry.addMenuButton('searchMenuButton', {
9+
text: 'Searchable Menu',
10+
search: { placeholder: 'Search items...' },
1711
fetch: (callback, fetchContext) => {
18-
if (fetchContext.pattern.length > 0) {
19-
callback([
20-
{
21-
type: 'menuitem',
22-
text: `You searched for: "${fetchContext.pattern}"`,
23-
onAction: () => editor.insertContent(`<strong>Inserted selected search result</strong>`)
24-
}
25-
]);
26-
} else {
27-
const items = [
28-
{
29-
type: 'menuitem',
30-
text: 'Menu item 1',
31-
onAction: () => editor.insertContent('&nbsp;<em>You clicked menu item 1!</em>')
32-
},
33-
{
34-
type: 'togglemenuitem',
35-
text: 'Toggle menu item',
36-
onAction: () => {
37-
toggleState = !toggleState;
38-
editor.insertContent('&nbsp;<em>You toggled a menuitem ' + (toggleState ? 'on' : 'off') + '</em>');
39-
},
40-
onSetup: (api) => {
12+
// Define a list of all menu items
13+
const allItems = [
14+
{ type: 'menuitem', text: 'Apple', onAction: () => editor.insertContent('Apple') },
15+
{ type: 'menuitem', text: 'Banana', onAction: () => editor.insertContent('Banana') },
16+
{ type: 'togglemenuitem', text: 'Cherry', onAction: () => {
17+
toggleState = !toggleState;
18+
editor.insertContent('Cherry')
19+
20+
},
21+
onSetup: (api) => {
4122
api.setActive(toggleState);
4223
return () => {};
4324
}
44-
}
45-
];
46-
callback(items);
47-
}
25+
}
26+
];
27+
28+
// Use the `pattern` to filter items
29+
const filteredItems = allItems.filter(item =>
30+
item.text.toLowerCase().includes(fetchContext.pattern.toLowerCase())
31+
);
32+
33+
// Pass the filtered list to the callback
34+
callback(filteredItems);
4835
}
4936
});
50-
5137
},
38+
5239
content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }'
5340
});

0 commit comments

Comments
 (0)