2 var win = CKEDITOR.document.getWindow(),
3 pixelate = CKEDITOR.tools.cssLength;
5 CKEDITOR.plugins.add('inline_resize', {
6 init: function( editor ) {
7 var config = editor.config;
9 editor.on('loaded', function() {
11 }, null, null, 20); // same priority as floatspace so that both get initialized
15 function parentScroll(e) {
16 var position = e.$.getAttribute("position"),
17 excludeStaticParent = position === "absolute";
18 return e.getParents().filter( function(parent) {
19 var style = window.getComputedStyle(parent.$);
20 if ( excludeStaticParent && style.position === "static" )
22 return (/(auto|scroll)/).test( style['overflow'] + style["overflow-y"] + style["overflow-x"] );
26 function parentDialog(e) {
27 return e.getParents().filter( function(parent) {
28 return parent.$.classList.contains("ui-dialog-content")
32 function attach( editor ) {
33 var config = editor.config,
34 parent = parentScroll(editor.element),
35 divelt = editor.element.getNext(function(elt){return elt.getAttribute("class") === "cke_textarea_inline"}),
36 inline = editor.element.$.classList.contains("texteditor-in-dialog");
41 dialog = parentDialog(divelt);
44 var resize = function (width, height) {
46 if ( !( editable = editor.editable() ) )
49 editable.setStyle('width', pixelate(width));
50 editable.setStyle('height', pixelate(height));
53 var layout = function ( evt ) {
55 if ( !( editable = editor.editable() ) )
58 // Show up the space on focus gain.
59 if ( evt && evt.name == 'focus' )
62 var editorPos = editable.getDocumentPosition();
63 var editorRect = editable.getClientRect();
64 var floatRect = float_space.getClientRect();
65 var viewRect = win.getViewPaneSize();
67 float_space.setStyle( 'position', 'absolute' );
69 var dialogPos = dialog.getDocumentPosition();
70 float_space.setStyle( 'top', pixelate( editorPos.y - dialogPos.y + editorRect.height - floatRect.height + 1 ) );
72 //float_space.setStyle( 'left', pixelate( editorPos.x - dialogPos.x + editorRect.width - floatRect.width ) );
73 // floatRect.width seems to be far to high on first dialog popup
74 float_space.setStyle( 'left', pixelate( editorPos.x - dialogPos.x + editorRect.width - 11 ) );
76 float_space.setStyle( 'top', pixelate( editorPos.y + editorRect.height - floatRect.height + 1) );
77 float_space.setStyle( 'right', pixelate( viewRect.width - editorRect.right ) );
81 var float_html = '<div class="cke_editor_inline_resize_button">\u25E2</div>'; // class so that csss can overrise content and style
82 var float_space = inline ? divelt.getParent().append( CKEDITOR.dom.element.createFromHtml( float_html ))
83 : CKEDITOR.document.getBody().append( CKEDITOR.dom.element.createFromHtml( float_html ));
85 var drag_handler = function( evt ) {
86 var width = startSize.width + evt.data.$.screenX - origin.x,
87 height = startSize.height + evt.data.$.screenY - origin.y;
89 width = Math.max( config.resize_minWidth || 200, Math.min( width || 0, config.resize_maxWidth || 9000) );
90 height = Math.max( config.resize_minHeight || 75, Math.min( height || 0, config.resize_maxHeight || 9000) );
92 resize( width, height );
96 var drag_end_handler = function() {
97 CKEDITOR.document.removeListener( 'mousemove', drag_handler );
98 CKEDITOR.document.removeListener( 'mouseup', drag_end_handler );
100 if ( editor.document ) {
101 editor.document.removeListener( 'mousemove', drag_handler );
102 editor.document.removeListener( 'mouseup', drag_end_handler );
106 var mousedown_fn = function( evt ) {
108 if ( !( editable = editor.editable() ) )
111 var editorRect = editable.getClientRect();
112 startSize = { width: editorRect.width, height: editorRect.height };
113 origin = { x: evt.data.$.screenX, y: evt.data.$.screenY };
115 if (config.resize_minWidth > startSize.width) config.resize_minWidth = startSize.width;
116 if (config.resize_minHeight > startSize.height) config.resize_minHeight = startSize.height;
118 CKEDITOR.document.on( 'mousemove', drag_handler );
119 CKEDITOR.document.on( 'mouseup', drag_end_handler );
121 if ( editor.document ) {
122 editor.document.on( 'mousemove', drag_handler );
123 editor.document.on( 'mouseup', drag_end_handler );
126 evt.data.$.preventDefault();
129 float_space.setStyle( 'overflow', 'hidden' );
130 float_space.setStyle( 'cursor', 'se-resize' )
131 float_space.on('mousedown', mousedown_fn);
132 float_space.unselectable();
135 editor.on( 'focus', function( evt ) {
139 parent.forEach(function(e){
140 e.on('scroll', function (evt) { layout(evt) });
143 editor.on( 'blur', function() {
147 editor.on( 'destroy', function() {
148 float_space.remove();
151 if ( editor.focusManager.hasFocus )
154 editor.focusManager.add( float_space, 1 );
162 * textarea/div mode safe, currently simply assumes that textarea inline is used
163 * positioning of resize handle is not browser zomm safe
164 * positioning of resize handle in dialog with scroll bars is broken