A Jodit plugin that adds a Google search button to the toolbar. This plugin allows users to quickly search for selected text or the current paragraph in Google.
Add "google-search" to your Jodit's extraPlugins configuration:
Copyconst editor = Jodit.make('#editor', { extraPlugins: ['google-search'] });
The plugin adds a button to the toolbar in the "search" group. You can customize the toolbar to include this button:
Copyconst editor = Jodit.make('#editor', { extraPlugins: ['google-search'], buttons: ['bold', 'italic', 'google'] });
You can also customize the button's position by defining a custom toolbar:
Copyconst editor = Jodit.make('#editor', { extraPlugins: ['google-search'], toolbar: { items: [ 'source', '|', 'bold', 'italic', '|', 'google', '|', 'ul', 'ol', '|', 'font', 'fontsize', 'brush', 'paragraph' ] } });
You can trigger the Google search functionality programmatically using the startSearch
command:
Copyconst editor = Jodit.make('#editor', { extraPlugins: ['google-search'] }); // Trigger Google search for the selected text or current paragraph editor.execCommand('startSearch');
Copyconst editor = Jodit.make('#editor', { extraPlugins: ['google-search'], buttons: ['bold', 'italic', 'google'] });
Copyconst editor = Jodit.make('#editor', { extraPlugins: ['google-search'], toolbar: { items: [ 'source', '|', 'bold', 'italic', '|', 'ul', 'ol', '|', 'font', 'fontsize', 'brush', 'paragraph', '|', 'google' ] } });
Copyconst editor = Jodit.make('#editor', { extraPlugins: ['google-search'] }); // Create a custom button outside the editor const searchButton = document.createElement('button'); searchButton.textContent = 'Search in Google'; document.body.appendChild(searchButton); // Add event listener to trigger Google search searchButton.addEventListener('click', () => { editor.execCommand('startSearch'); });
The plugin registers a command called startSearch
that performs the following actions:
The button is automatically disabled when the editor is empty, ensuring that users can only perform searches when there is content to search for.