Setting up the Editor's HTML is done by creating a textarea control on the page.
Setting up the Editor's Javascript
Once the textarea is on the page, then initialize the Editor like this:
Adding and Controlling the New Button
Here we subscribe to the toolbarLoaded Custom Event and create the new Button (flickr). After adding it to the group called insertitem, we subscribe to it's flickrClick Custom Event.
Inside this Custom Event, we set the STOP_EXEC_COMMAND var to true, which will keep the Editor from trying to run execCommand('flickr', '')
Then we call gutter.toggle() which will either hide or show our custom panel.
Styling the New Button
There are 2 important states to style a button in the toolbar.
First is the default state, that can be accessed via this CSS rule: .yui-toolbar-container .yui-toolbar-flickr span.yui-toolbar-icon
Second is the selected state, that can be accessed via this CSS rule: .yui-toolbar-container .yui-toolbar-flickr-selected span.yui-toolbar-icon
.yui-toolbar-container is the class applied to the top-most container of the toolbar.
.yui-toolbar-icon is an extra SPAN injected into the button for spriting an image.
.yui-toolbar-VALUE is a dynamic class added to the button based on the value passed into the button's config. It is used for specific styling of a button that may appear in several places on the page.
The Style Rules to Create the Flickr Button in This Example
The Gutter Panel Full Javascript Source
The gutter in this example is not part of the Editor, but could easily be modified to do other things.
Setting Up the Autocomplete Control
First we wait until flickr_search is available on the page. Then we set up a click handler on flickr_results to see if the user clicked an image.
If an image is clicked, we will call myEditor.execCommand('insertimage', IMG) to insert the image into the Editor.
This Autocomplete control uses a DataSource that points to Flickr Web Services; Flickr returns XML data via a simple PHP proxy. In order to return valid data from the Flickr application, scriptQueryParameter has been customized to be tags, and scriptQueryAppend is used to pass in additional required arguments. The cache has been disabled so that each query is forced to make a trip to the live application.
This instance of AutoComplete defines a robust custom formatResult function that parses result data into custom HTML markup that displays an actual image from the Flickr server. Automatic highlighting of the first result item in the container has been disabled by setting autoHighlight to false.
YUI Logger Output:
Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.