YUI recommends YUI3.
YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.
This documentation is no longer maintained.
This example shows how to customize the Resize Utility for things like the Rich Text Editor Control.
Setting up the Editor's HTML is done by creating a textarea
control on the page.
1 | <form method="post" action="#" id="form1"> |
2 | <textarea id="editor" name="editor" rows="20" cols="75"> |
3 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse justo nibh, |
4 | pharetra at, adipiscing ullamcorper, rutrum ac, enim. Nullam pretium interdum metus. |
5 | Ut in neque. Vivamus ut lorem vitae turpis porttitor tempor. Nam consectetuer est quis lacus. |
6 | </textarea> |
7 | </form> |
view plain | print | ? |
Once the textarea
is on the page, then initialize the Editor like this:
1 | (function() { |
2 | //Setup some private variables |
3 | var Dom = YAHOO.util.Dom, |
4 | Event = YAHOO.util.Event; |
5 | |
6 | Event.onDOMReady(function() { |
7 | editor = new YAHOO.widget.SimpleEditor('editor', { |
8 | height: '300px', |
9 | width: '522px', |
10 | dompath: true, |
11 | animate: true |
12 | }); |
13 | editor.render(); |
14 | }); |
15 | |
16 | })(); |
view plain | print | ? |
Now we listen for the editorContentLoaded
event and setup our Resize instance.
1 | editor.on('editorContentLoaded', function() { |
2 | resize = new YAHOO.util.Resize(editor.get('element_cont').get('element'), { |
3 | handles: ['br'], |
4 | autoRatio: true, |
5 | status: true, |
6 | proxy: true |
7 | }); |
8 | }); |
view plain | print | ? |
Now we have a resizable Editor instance, but it doesn't resize the way we want. It only resizes the outer element. But we want the Editor to resize the content area as well.
This is where the config option setSize
comes in. When you set the setSize
option to false (only when using the proxy config),
the Resize Utility will not resize the element. It will return the data needed to resize it in the resize
Event.
So now we listen for the startResize
Event to set the disabled
option on the Editor instance.
Then we listen for the resize
Event to get the new height and width. Once we have that we can do a little math and tell the Editor instance to resize itself.
1 | resize = new YAHOO.util.Resize(editor.get('element_cont').get('element'), { |
2 | handles: ['br'], |
3 | autoRatio: true, |
4 | status: true, |
5 | proxy: true, |
6 | setSize: false //This is where the magic happens |
7 | }); |
8 | resize.on('startResize', function() { |
9 | this.hide(); |
10 | this.set('disabled', true); |
11 | }, editor, true); |
12 | resize.on('resize', function(args) { |
13 | var h = args.height; |
14 | var th = (this.toolbar.get('element').clientHeight + 2); //It has a 1px border.. |
15 | var dh = (this.dompath.clientHeight + 1); //It has a 1px top border.. |
16 | var newH = (h - th - dh); |
17 | this.set('width', args.width + 'px'); |
18 | this.set('height', newH + 'px'); |
19 | this.set('disabled', false); |
20 | this.show(); |
21 | }, editor, true); |
view plain | print | ? |
Next we will override the default Resize CSS and make the handle a little bigger.
1 | /* The ID of the editor's container and the bottom right resize handle. */ |
2 | #editor_container .yui-resize-handle-br { |
3 | /* Make the handle a little bigger than the default */ |
4 | height: 11px; |
5 | width: 11px; |
6 | /* Resposition the image */ |
7 | background-position: -20px -60px; |
8 | /* Kill the hover on the handle */ |
9 | background-color: transparent; |
10 | } |
view plain | print | ? |
1 | (function() { |
2 | var Dom = YAHOO.util.Dom, |
3 | Event = YAHOO.util.Event, |
4 | editor = null, |
5 | resize = null; |
6 | |
7 | Event.onDOMReady(function() { |
8 | editor = new YAHOO.widget.SimpleEditor('editor', { |
9 | height: '300px', |
10 | width: '522px', |
11 | dompath: true, |
12 | animate: true |
13 | }); |
14 | editor.on('editorContentLoaded', function() { |
15 | resize = new YAHOO.util.Resize(editor.get('element_cont').get('element'), { |
16 | handles: ['br'], |
17 | autoRatio: true, |
18 | status: true, |
19 | proxy: true, |
20 | setSize: false //This is where the magic happens |
21 | }); |
22 | resize.on('startResize', function() { |
23 | this.hide(); |
24 | this.set('disabled', true); |
25 | }, editor, true); |
26 | resize.on('resize', function(args) { |
27 | var h = args.height; |
28 | var th = (this.toolbar.get('element').clientHeight + 2); //It has a 1px border.. |
29 | var dh = (this.dompath.clientHeight + 1); //It has a 1px top border.. |
30 | var newH = (h - th - dh); |
31 | this.set('width', args.width + 'px'); |
32 | this.set('height', newH + 'px'); |
33 | this.set('disabled', false); |
34 | this.show(); |
35 | }, editor, true); |
36 | }); |
37 | editor.render(); |
38 | }); |
39 | |
40 | })(); |
view plain | print | ? |
All YUI 2.x users should review the YUI 2.8.2 security bulletin, which discusses a vulnerability present in YUI 2.4.0-2.8.1.
Copyright © 2013 Yahoo! Inc. All rights reserved.