2017-12-09 12:42:35 +00:00
|
|
|
(function () {
|
2018-01-19 11:36:38 +00:00
|
|
|
var autoresize = (function () {
|
|
|
|
'use strict';
|
2017-12-09 12:42:35 +00:00
|
|
|
|
2018-01-19 11:36:38 +00:00
|
|
|
var Cell = function (initial) {
|
|
|
|
var value = initial;
|
|
|
|
var get = function () {
|
|
|
|
return value;
|
2017-12-09 12:42:35 +00:00
|
|
|
};
|
2018-01-19 11:36:38 +00:00
|
|
|
var set = function (v) {
|
|
|
|
value = v;
|
2017-12-09 12:42:35 +00:00
|
|
|
};
|
2018-01-19 11:36:38 +00:00
|
|
|
var clone = function () {
|
|
|
|
return Cell(get());
|
2017-12-09 12:42:35 +00:00
|
|
|
};
|
|
|
|
return {
|
2018-01-19 11:36:38 +00:00
|
|
|
get: get,
|
|
|
|
set: set,
|
|
|
|
clone: clone
|
2017-12-09 12:42:35 +00:00
|
|
|
};
|
2018-01-19 11:36:38 +00:00
|
|
|
};
|
2017-12-09 12:42:35 +00:00
|
|
|
|
2018-01-19 11:36:38 +00:00
|
|
|
var PluginManager = tinymce.util.Tools.resolve('tinymce.PluginManager');
|
2017-12-09 12:42:35 +00:00
|
|
|
|
2018-01-19 11:36:38 +00:00
|
|
|
var Env = tinymce.util.Tools.resolve('tinymce.Env');
|
2017-12-09 12:42:35 +00:00
|
|
|
|
2018-01-19 11:36:38 +00:00
|
|
|
var Delay = tinymce.util.Tools.resolve('tinymce.util.Delay');
|
2017-12-09 12:42:35 +00:00
|
|
|
|
2018-01-19 11:36:38 +00:00
|
|
|
var getAutoResizeMinHeight = function (editor) {
|
|
|
|
return parseInt(editor.getParam('autoresize_min_height', editor.getElement().offsetHeight), 10);
|
|
|
|
};
|
|
|
|
var getAutoResizeMaxHeight = function (editor) {
|
|
|
|
return parseInt(editor.getParam('autoresize_max_height', 0), 10);
|
|
|
|
};
|
|
|
|
var getAutoResizeOverflowPadding = function (editor) {
|
|
|
|
return editor.getParam('autoresize_overflow_padding', 1);
|
|
|
|
};
|
|
|
|
var getAutoResizeBottomMargin = function (editor) {
|
|
|
|
return editor.getParam('autoresize_bottom_margin', 50);
|
|
|
|
};
|
|
|
|
var shouldAutoResizeOnInit = function (editor) {
|
|
|
|
return editor.getParam('autoresize_on_init', true);
|
|
|
|
};
|
2018-01-25 16:14:37 +00:00
|
|
|
var $_1zwcl183jcun3xg6 = {
|
2018-01-19 11:36:38 +00:00
|
|
|
getAutoResizeMinHeight: getAutoResizeMinHeight,
|
|
|
|
getAutoResizeMaxHeight: getAutoResizeMaxHeight,
|
|
|
|
getAutoResizeOverflowPadding: getAutoResizeOverflowPadding,
|
|
|
|
getAutoResizeBottomMargin: getAutoResizeBottomMargin,
|
|
|
|
shouldAutoResizeOnInit: shouldAutoResizeOnInit
|
|
|
|
};
|
2017-12-09 12:42:35 +00:00
|
|
|
|
2018-01-19 11:36:38 +00:00
|
|
|
var isFullscreen = function (editor) {
|
|
|
|
return editor.plugins.fullscreen && editor.plugins.fullscreen.isFullscreen();
|
|
|
|
};
|
|
|
|
var wait = function (editor, oldSize, times, interval, callback) {
|
|
|
|
Delay.setEditorTimeout(editor, function () {
|
|
|
|
resize(editor, oldSize);
|
|
|
|
if (times--) {
|
|
|
|
wait(editor, oldSize, times, interval, callback);
|
|
|
|
} else if (callback) {
|
|
|
|
callback();
|
2017-12-09 12:42:35 +00:00
|
|
|
}
|
2018-01-19 11:36:38 +00:00
|
|
|
}, interval);
|
|
|
|
};
|
|
|
|
var toggleScrolling = function (editor, state) {
|
|
|
|
var body = editor.getBody();
|
|
|
|
if (body) {
|
|
|
|
body.style.overflowY = state ? '' : 'hidden';
|
|
|
|
if (!state) {
|
|
|
|
body.scrollTop = 0;
|
2017-12-09 12:42:35 +00:00
|
|
|
}
|
2018-01-19 11:36:38 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var resize = function (editor, oldSize) {
|
|
|
|
var deltaSize, doc, body, resizeHeight, myHeight;
|
|
|
|
var marginTop, marginBottom, paddingTop, paddingBottom, borderTop, borderBottom;
|
|
|
|
var dom = editor.dom;
|
|
|
|
doc = editor.getDoc();
|
|
|
|
if (!doc) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isFullscreen(editor)) {
|
|
|
|
toggleScrolling(editor, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
body = doc.body;
|
2018-01-25 16:14:37 +00:00
|
|
|
resizeHeight = $_1zwcl183jcun3xg6.getAutoResizeMinHeight(editor);
|
2018-01-19 11:36:38 +00:00
|
|
|
marginTop = dom.getStyle(body, 'margin-top', true);
|
|
|
|
marginBottom = dom.getStyle(body, 'margin-bottom', true);
|
|
|
|
paddingTop = dom.getStyle(body, 'padding-top', true);
|
|
|
|
paddingBottom = dom.getStyle(body, 'padding-bottom', true);
|
|
|
|
borderTop = dom.getStyle(body, 'border-top-width', true);
|
|
|
|
borderBottom = dom.getStyle(body, 'border-bottom-width', true);
|
|
|
|
myHeight = body.offsetHeight + parseInt(marginTop, 10) + parseInt(marginBottom, 10) + parseInt(paddingTop, 10) + parseInt(paddingBottom, 10) + parseInt(borderTop, 10) + parseInt(borderBottom, 10);
|
|
|
|
if (isNaN(myHeight) || myHeight <= 0) {
|
|
|
|
myHeight = Env.ie ? body.scrollHeight : Env.webkit && body.clientHeight === 0 ? 0 : body.offsetHeight;
|
|
|
|
}
|
2018-01-25 16:14:37 +00:00
|
|
|
if (myHeight > $_1zwcl183jcun3xg6.getAutoResizeMinHeight(editor)) {
|
2018-01-19 11:36:38 +00:00
|
|
|
resizeHeight = myHeight;
|
|
|
|
}
|
2018-01-25 16:14:37 +00:00
|
|
|
var maxHeight = $_1zwcl183jcun3xg6.getAutoResizeMaxHeight(editor);
|
2018-01-19 11:36:38 +00:00
|
|
|
if (maxHeight && myHeight > maxHeight) {
|
|
|
|
resizeHeight = maxHeight;
|
|
|
|
toggleScrolling(editor, true);
|
|
|
|
} else {
|
|
|
|
toggleScrolling(editor, false);
|
|
|
|
}
|
|
|
|
if (resizeHeight !== oldSize.get()) {
|
|
|
|
deltaSize = resizeHeight - oldSize.get();
|
|
|
|
dom.setStyle(editor.iframeElement, 'height', resizeHeight + 'px');
|
|
|
|
oldSize.set(resizeHeight);
|
|
|
|
if (Env.webkit && deltaSize < 0) {
|
|
|
|
resize(editor, oldSize);
|
2017-12-09 12:42:35 +00:00
|
|
|
}
|
2018-01-19 11:36:38 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var setup = function (editor, oldSize) {
|
|
|
|
editor.on('init', function () {
|
|
|
|
var overflowPadding, bottomMargin;
|
|
|
|
var dom = editor.dom;
|
2018-01-25 16:14:37 +00:00
|
|
|
overflowPadding = $_1zwcl183jcun3xg6.getAutoResizeOverflowPadding(editor);
|
|
|
|
bottomMargin = $_1zwcl183jcun3xg6.getAutoResizeBottomMargin(editor);
|
2018-01-19 11:36:38 +00:00
|
|
|
if (overflowPadding !== false) {
|
|
|
|
dom.setStyles(editor.getBody(), {
|
|
|
|
paddingLeft: overflowPadding,
|
|
|
|
paddingRight: overflowPadding
|
|
|
|
});
|
2017-12-09 12:42:35 +00:00
|
|
|
}
|
2018-01-19 11:36:38 +00:00
|
|
|
if (bottomMargin !== false) {
|
|
|
|
dom.setStyles(editor.getBody(), { paddingBottom: bottomMargin });
|
2017-12-09 12:42:35 +00:00
|
|
|
}
|
2018-01-19 11:36:38 +00:00
|
|
|
});
|
|
|
|
editor.on('nodechange setcontent keyup FullscreenStateChanged', function (e) {
|
|
|
|
resize(editor, oldSize);
|
|
|
|
});
|
2018-01-25 16:14:37 +00:00
|
|
|
if ($_1zwcl183jcun3xg6.shouldAutoResizeOnInit(editor)) {
|
2018-01-19 11:36:38 +00:00
|
|
|
editor.on('init', function () {
|
|
|
|
wait(editor, oldSize, 20, 100, function () {
|
|
|
|
wait(editor, oldSize, 5, 1000);
|
2017-12-09 12:42:35 +00:00
|
|
|
});
|
|
|
|
});
|
2018-01-19 11:36:38 +00:00
|
|
|
}
|
|
|
|
};
|
2018-01-25 16:14:37 +00:00
|
|
|
var $_7nfdri80jcun3xg0 = {
|
2018-01-19 11:36:38 +00:00
|
|
|
setup: setup,
|
|
|
|
resize: resize
|
|
|
|
};
|
2017-12-09 12:42:35 +00:00
|
|
|
|
2018-01-19 11:36:38 +00:00
|
|
|
var register = function (editor, oldSize) {
|
|
|
|
editor.addCommand('mceAutoResize', function () {
|
2018-01-25 16:14:37 +00:00
|
|
|
$_7nfdri80jcun3xg0.resize(editor, oldSize);
|
2017-12-09 12:42:35 +00:00
|
|
|
});
|
2018-01-19 11:36:38 +00:00
|
|
|
};
|
2018-01-25 16:14:37 +00:00
|
|
|
var $_91vbh17zjcun3xfy = { register: register };
|
2018-01-19 11:36:38 +00:00
|
|
|
|
|
|
|
PluginManager.add('autoresize', function (editor) {
|
|
|
|
if (!editor.inline) {
|
|
|
|
var oldSize = Cell(0);
|
2018-01-25 16:14:37 +00:00
|
|
|
$_91vbh17zjcun3xfy.register(editor, oldSize);
|
|
|
|
$_7nfdri80jcun3xg0.setup(editor, oldSize);
|
2018-01-19 11:36:38 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
var Plugin = function () {
|
|
|
|
};
|
|
|
|
|
|
|
|
return Plugin;
|
2017-12-09 12:42:35 +00:00
|
|
|
|
2018-01-19 11:36:38 +00:00
|
|
|
}());
|
|
|
|
})()
|