Commit d116a41b authored by Benni Mack's avatar Benni Mack Committed by Georg Ringer
Browse files

[!!!][TASK] FormEngine: Unify resizable textareas

TYPO3 has some special functionality
for FormEngine textareas (without RTE).
The options are available through the users'
settings.

1. Resize a textarea
2. "Autogrow" a textarea. As soon as
the contents are larger than the textarea
the textarea's height is adapted.

The first feature (and option) is dropped. Although
it is working natively in most browsers (except IE)
via CSS, the horizontal resizing is a no-go for forms,
as agreed with the Design Team.

The second feature is rewritten with a unified
solution based on jQuery, which loads only when
needed (and works with AJAX) and works in all
browsers.

Resolves: #64131
Resolves: #55540
Releases: master
Change-Id: Id3f2c520fd76043e2cce80e92732a12e58e395ac
Reviewed-on: http://review.typo3.org/35794

Reviewed-by: Benjamin Kott's avatarBenjamin Kott <info@bk2k.info>
Tested-by: Benjamin Kott's avatarBenjamin Kott <info@bk2k.info>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
parent c064eb5d
/*!
Autosize 1.18.17 as UMD module
license: MIT
http://www.jacklmoore.com/autosize
derived: https://github.com/bmack/autosize
*/
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// CommonJS
factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
var
defaults = {
className: 'autosizejs',
id: 'autosizejs',
append: '\n',
callback: false,
resizeDelay: 10,
placeholder: true
},
// border:0 is unnecessary, but avoids a bug in Firefox on OSX
copy = '<textarea tabindex="-1" style="position:absolute; top:-999px; left:0; right:auto; bottom:auto; border:0; padding: 0; -moz-box-sizing:content-box; -webkit-box-sizing:content-box; box-sizing:content-box; word-wrap:break-word; height:0 !important; min-height:0 !important; overflow:hidden; transition:none; -webkit-transition:none; -moz-transition:none;"/>',
// line-height is conditionally included because IE7/IE8/old Opera do not return the correct value.
typographyStyles = [
'fontFamily',
'fontSize',
'fontWeight',
'fontStyle',
'letterSpacing',
'textTransform',
'wordSpacing',
'textIndent',
'whiteSpace'
],
// to keep track which textarea is being mirrored when adjust() is called.
mirrored,
// the mirror element, which is used to calculate what size the mirrored element should be.
mirror = $(copy).data('autosize', true)[0];
// test that line-height can be accurately copied.
mirror.style.lineHeight = '99px';
if ($(mirror).css('lineHeight') === '99px') {
typographyStyles.push('lineHeight');
}
mirror.style.lineHeight = '';
$.fn.autosize = function (options) {
if (!this.length) {
return this;
}
options = $.extend({}, defaults, options || {});
if (mirror.parentNode !== document.body) {
$(document.body).append(mirror);
}
return this.each(function () {
var
ta = this,
$ta = $(ta),
maxHeight,
minHeight,
boxOffset = 0,
callback = $.isFunction(options.callback),
originalStyles = {
height: ta.style.height,
overflow: ta.style.overflow,
overflowY: ta.style.overflowY,
wordWrap: ta.style.wordWrap,
resize: ta.style.resize
},
timeout,
width = $ta.width(),
taResize = $ta.css('resize');
if ($ta.data('autosize')) {
// exit if autosize has already been applied, or if the textarea is the mirror element.
return;
}
$ta.data('autosize', true);
if ($ta.css('box-sizing') === 'border-box' || $ta.css('-moz-box-sizing') === 'border-box' || $ta.css('-webkit-box-sizing') === 'border-box'){
boxOffset = $ta.outerHeight() - $ta.height();
}
// IE8 and lower return 'auto', which parses to NaN, if no min-height is set.
minHeight = Math.max(parseFloat($ta.css('minHeight')) - boxOffset || 0, $ta.height());
$ta.css({
overflow: 'hidden',
overflowY: 'hidden',
wordWrap: 'break-word' // horizontal overflow is hidden, so break-word is necessary for handling words longer than the textarea width
});
if (taResize === 'vertical') {
$ta.css('resize','none');
} else if (taResize === 'both') {
$ta.css('resize', 'horizontal');
}
// getComputedStyle is preferred here because it preserves sub-pixel values, while jQuery's .width() rounds to an integer.
function setWidth() {
var width;
var style = window.getComputedStyle ? window.getComputedStyle(ta, null) : null;
if (style) {
width = parseFloat(style.width);
if (style.boxSizing === 'border-box' || style.webkitBoxSizing === 'border-box' || style.mozBoxSizing === 'border-box') {
$.each(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'], function(i,val){
width -= parseFloat(style[val]);
});
}
} else {
width = $ta.width();
}
mirror.style.width = Math.max(width,0) + 'px';
}
function initMirror() {
var styles = {};
mirrored = ta;
mirror.className = options.className;
mirror.id = options.id;
maxHeight = parseFloat($ta.css('maxHeight'));
// mirror is a duplicate textarea located off-screen that
// is automatically updated to contain the same text as the
// original textarea. mirror always has a height of 0.
// This gives a cross-browser supported way getting the actual
// height of the text, through the scrollTop property.
$.each(typographyStyles, function(i,val){
styles[val] = $ta.css(val);
});
$(mirror).css(styles).attr('wrap', $ta.attr('wrap'));
setWidth();
// Chrome-specific fix:
// When the textarea y-overflow is hidden, Chrome doesn't reflow the text to account for the space
// made available by removing the scrollbar. This workaround triggers the reflow for Chrome.
if (window.chrome) {
var width = ta.style.width;
ta.style.width = '0px';
var ignore = ta.offsetWidth;
ta.style.width = width;
}
}
// Using mainly bare JS in this function because it is going
// to fire very often while typing, and needs to very efficient.
function adjust() {
var height, originalHeight;
if (mirrored !== ta) {
initMirror();
} else {
setWidth();
}
if (!ta.value && options.placeholder) {
// If the textarea is empty, copy the placeholder text into
// the mirror control and use that for sizing so that we
// don't end up with placeholder getting trimmed.
mirror.value = ($ta.attr("placeholder") || '');
} else {
mirror.value = ta.value;
}
mirror.value += options.append || '';
mirror.style.overflowY = ta.style.overflowY;
originalHeight = parseFloat(ta.style.height) || 0;
// Setting scrollTop to zero is needed in IE8 and lower for the next step to be accurately applied
mirror.scrollTop = 0;
mirror.scrollTop = 9e4;
// Using scrollTop rather than scrollHeight because scrollHeight is non-standard and includes padding.
height = mirror.scrollTop;
if (maxHeight && height > maxHeight) {
ta.style.overflowY = 'scroll';
height = maxHeight;
} else {
ta.style.overflowY = 'hidden';
if (height < minHeight) {
height = minHeight;
}
}
height += boxOffset;
if (Math.abs(originalHeight - height) > 1/100) {
ta.style.height = height + 'px';
// Trigger a repaint for IE8 for when ta is nested 2 or more levels inside an inline-block
mirror.className = mirror.className;
if (callback) {
options.callback.call(ta,ta);
}
$ta.trigger('autosize.resized');
}
}
function resize () {
clearTimeout(timeout);
timeout = setTimeout(function(){
var newWidth = $ta.width();
if (newWidth !== width) {
width = newWidth;
adjust();
}
}, parseInt(options.resizeDelay,10));
}
if ('onpropertychange' in ta) {
if ('oninput' in ta) {
// Detects IE9. IE9 does not fire onpropertychange or oninput for deletions,
// so binding to onkeyup to catch most of those occasions. There is no way that I
// know of to detect something like 'cut' in IE9.
$ta.on('input.autosize keyup.autosize', adjust);
} else {
// IE7 / IE8
$ta.on('propertychange.autosize', function(){
if(event.propertyName === 'value'){
adjust();
}
});
}
} else {
// Modern Browsers
$ta.on('input.autosize', adjust);
}
// Set options.resizeDelay to false if using fixed-width textarea elements.
// Uses a timeout and width check to reduce the amount of times adjust needs to be called after window resize.
if (options.resizeDelay !== false) {
$(window).on('resize.autosize', resize);
}
// Event for manual triggering if needed.
// Should only be needed when the value of the textarea is changed through JavaScript rather than user input.
$ta.on('autosize.resize', adjust);
// Event for manual triggering that also forces the styles to update as well.
// Should only be needed if one of typography styles of the textarea change, and the textarea is already the target of the adjust method.
$ta.on('autosize.resizeIncludeStyle', function() {
mirrored = null;
adjust();
});
$ta.on('autosize.destroy', function(){
mirrored = null;
clearTimeout(timeout);
$(window).off('resize', resize);
$ta
.off('autosize')
.off('.autosize')
.css(originalStyles)
.removeData('autosize');
});
// Call adjust in case the textarea already contains text.
adjust();
});
};
}));
/*!
Autosize 1.18.17 as UMD module
license: MIT
http://www.jacklmoore.com/autosize
derived: https://github.com/bmack/autosize
*/
(function(a){if(typeof define==="function"&&define.amd){define(["jquery"],a);}else{if(typeof exports==="object"){a(require("jquery"));}else{a(jQuery);}}}(function(b){var e={className:"autosizejs",id:"autosizejs",append:"\n",callback:false,resizeDelay:10,placeholder:true},f='<textarea tabindex="-1" style="position:absolute; top:-999px; left:0; right:auto; bottom:auto; border:0; padding: 0; -moz-box-sizing:content-box; -webkit-box-sizing:content-box; box-sizing:content-box; word-wrap:break-word; height:0 !important; min-height:0 !important; overflow:hidden; transition:none; -webkit-transition:none; -moz-transition:none;"/>',a=["fontFamily","fontSize","fontWeight","fontStyle","letterSpacing","textTransform","wordSpacing","textIndent","whiteSpace"],d,c=b(f).data("autosize",true)[0];c.style.lineHeight="99px";if(b(c).css("lineHeight")==="99px"){a.push("lineHeight");}c.style.lineHeight="";b.fn.autosize=function(g){if(!this.length){return this;}g=b.extend({},e,g||{});if(c.parentNode!==document.body){b(document.body).append(c);}return this.each(function(){var m=this,l=b(m),s,u,k=0,t=b.isFunction(g.callback),n={height:m.style.height,overflow:m.style.overflow,overflowY:m.style.overflowY,wordWrap:m.style.wordWrap,resize:m.style.resize},p,h=l.width(),j=l.css("resize");if(l.data("autosize")){return;}l.data("autosize",true);if(l.css("box-sizing")==="border-box"||l.css("-moz-box-sizing")==="border-box"||l.css("-webkit-box-sizing")==="border-box"){k=l.outerHeight()-l.height();}u=Math.max(parseFloat(l.css("minHeight"))-k||0,l.height());l.css({overflow:"hidden",overflowY:"hidden",wordWrap:"break-word"});if(j==="vertical"){l.css("resize","none");}else{if(j==="both"){l.css("resize","horizontal");}}function o(){var w;var v=window.getComputedStyle?window.getComputedStyle(m,null):null;if(v){w=parseFloat(v.width);if(v.boxSizing==="border-box"||v.webkitBoxSizing==="border-box"||v.mozBoxSizing==="border-box"){b.each(["paddingLeft","paddingRight","borderLeftWidth","borderRightWidth"],function(x,y){w-=parseFloat(v[y]);});}}else{w=l.width();}c.style.width=Math.max(w,0)+"px";}function r(){var w={};d=m;c.className=g.className;c.id=g.id;s=parseFloat(l.css("maxHeight"));b.each(a,function(y,z){w[z]=l.css(z);});b(c).css(w).attr("wrap",l.attr("wrap"));o();if(window.chrome){var v=m.style.width;m.style.width="0px";var x=m.offsetWidth;m.style.width=v;}}function q(){var v,w;if(d!==m){r();}else{o();}if(!m.value&&g.placeholder){c.value=(l.attr("placeholder")||"");}else{c.value=m.value;}c.value+=g.append||"";c.style.overflowY=m.style.overflowY;w=parseFloat(m.style.height)||0;c.scrollTop=0;c.scrollTop=90000;v=c.scrollTop;if(s&&v>s){m.style.overflowY="scroll";v=s;}else{m.style.overflowY="hidden";if(v<u){v=u;}}v+=k;if(Math.abs(w-v)>1/100){m.style.height=v+"px";c.className=c.className;if(t){g.callback.call(m,m);}l.trigger("autosize.resized");}}function i(){clearTimeout(p);p=setTimeout(function(){var v=l.width();if(v!==h){h=v;q();}},parseInt(g.resizeDelay,10));}if("onpropertychange" in m){if("oninput" in m){l.on("input.autosize keyup.autosize",q);}else{l.on("propertychange.autosize",function(){if(event.propertyName==="value"){q();}});}}else{l.on("input.autosize",q);}if(g.resizeDelay!==false){b(window).on("resize.autosize",i);}l.on("autosize.resize",q);l.on("autosize.resizeIncludeStyle",function(){d=null;q();});l.on("autosize.destroy",function(){d=null;clearTimeout(p);b(window).off("resize",i);l.off("autosize").off(".autosize").css(n).removeData("autosize");});q();});};}));
This diff is collapsed.
.ux-resizable-handle-east, .ux-resizable-handle-east textarea {
cursor: e-resize;
}
.ux-resizable-handle-south, .ux-resizable-handle-south textarea {
cursor: s-resize;
}
.ux-resizable-handle-west, .ux-resizable-handle-west textarea {
cursor: w-resize;
}
.ux-resizable-handle-north, .ux-resizable-handle-north textarea {
cursor: n-resize;
}
.ux-resizable-handle-southeast, .ux-resizable-handle-southeast textarea {
cursor: se-resize;
}
.ux-resizable-handle-northwest, .ux-resizable-handle-northwest textarea {
cursor: nw-resize;
}
.ux-resizable-handle-northeast, .ux-resizable-handle-northeast textarea {
cursor: ne-resize;
}
.ux-resizable-handle-southwest, .ux-resizable-handle-southwest textarea {
cursor: sw-resize;
}
.ux-resizable-handle-east, .ux-resizable-handle-east textarea {
cursor: e-resize;
}
.ux-resizable-handle-south, .ux-resizable-handle-south textarea {
cursor: s-resize;
}
.ux-resizable-handle-west, .ux-resizable-handle-west textarea {
cursor: w-resize;
}
.ux-resizable-handle-north, .ux-resizable-handle-north textarea {
cursor: n-resize;
}
.ux-resizable-handle-southeast, .ux-resizable-handle-southeast textarea {
cursor: se-resize;
}
.ux-resizable-handle-northwest, .ux-resizable-handle-northwest textarea {
cursor: nw-resize;
}
.ux-resizable-handle-northeast, .ux-resizable-handle-northeast textarea {
cursor: ne-resize;
}
.ux-resizable-handle-southwest, .ux-resizable-handle-southwest textarea {
cursor: sw-resize;
}
textarea.resizable {
background-image: url(resize.gif);
background-position: bottom right;
background-repeat: no-repeat;
}
\ No newline at end of file
......@@ -344,7 +344,7 @@ class FlexElement extends AbstractFormElement {
. 'eval(unescape("' . rawurlencode(implode(';', $this->formEngine->additionalJS_post)) . '").' . $replace . ');'
. 'TBE_EDITOR.addActionChecks("submit", unescape("'
. rawurlencode(implode(';', $this->formEngine->additionalJS_submit)) . '").' . $replace . ');'
. 'TYPO3.TCEFORMS.update();'
. 'TYPO3.FormEngine.reinitialize();'
. 'return false;';
// Kasper's comment (kept for history):
// Maybe there is a better way to do this than store the HTML for the new element
......
......@@ -160,6 +160,12 @@ class TextElement extends AbstractFormElement {
$classes[] = 'enable-tab';
}
$formWidthText = $this->formWidthText($cols, $wrap);
// add the max-height from the users' preference to it
$maximumHeight = (int)$this->getBackendUserAuthentication()->uc['resizeTextareas_MaxHeight'];
if ($maximumHeight > 0) {
$formWidthText = str_replace('style="', 'style="max-height: ' . $maximumHeight . 'px; ', $formWidthText);
}
// Extract class attributes from $formWidthText (otherwise it would be added twice to the output)
$res = array();
if (preg_match('/ class="(.+?)"/', $formWidthText, $res)) {
......
......@@ -4046,18 +4046,13 @@ class FormEngine {
$pageRenderer->loadPrototype();
$pageRenderer->loadJquery();
$pageRenderer->loadExtJS();
// Make textareas resizable and flexible
$beUserAuth = $this->getBackendUserAuthentication();
if (!($beUserAuth->uc['resizeTextareas'] == '0' && $beUserAuth->uc['resizeTextareas_Flexible'] == '0')) {
$pageRenderer->addCssFile($this->backPath . 'js/extjs/ux/resize.css');
$this->loadJavascriptLib('js/extjs/ux/ext.resizable.js');
}
$resizableSettings = array(
'textareaMaxHeight' => $beUserAuth->uc['resizeTextareas_MaxHeight'] > 0 ? $beUserAuth->uc['resizeTextareas_MaxHeight'] : '600',
'textareaFlexible' => !$beUserAuth->uc['resizeTextareas_Flexible'] == '0',
'textareaResize' => !$beUserAuth->uc['resizeTextareas'] == '0'
// Make textareas resizable and flexible ("autogrow" in height)
$textareaSettings = array(
'autosize' => (bool)$beUserAuth->uc['resizeTextareas_Flexible']
);
$pageRenderer->addInlineSettingArray('', $resizableSettings);
$pageRenderer->addInlineSettingArray('Textarea', $textareaSettings);
$this->loadJavascriptLib('sysext/backend/Resources/Public/JavaScript/jsfunc.evalfield.js');
$this->loadJavascriptLib('sysext/backend/Resources/Public/JavaScript/jsfunc.tbe_editor.js');
......
......@@ -627,6 +627,18 @@ define('TYPO3/CMS/Backend/FormEngine', ['jquery'], function ($) {
}
};
/**
* convert all textareas so they grow when it is typed in.
*/
FormEngine.convertTextareasResizable = function() {
var $elements = $('.tceforms-textarea');
if (TYPO3.settings.Textarea.autosize && $elements.length) {
require(['jquery/jquery.autosize.min'], function() {
$elements.autosize();
});
}
};
/**
* this is the main function that is called on page load, but also after elements are asynchroniously
* called e.g. after IRRE elements are loaded again, or a new flexform section is added.
......@@ -643,6 +655,7 @@ define('TYPO3/CMS/Backend/FormEngine', ['jquery'], function ($) {
}
// apply DatePicker to all date time fields
require(['TYPO3/CMS/Backend/DateTimePicker']);
FormEngine.convertTextareasResizable();
};
/**
......
......@@ -11,43 +11,9 @@
* The TYPO3 project - inspiring people to share!
*/
Ext.ns('TYPO3');
// class to manipulate TCEFORMS
TYPO3.TCEFORMS = {
init: function() {
Ext.QuickTips.init();
this.update();
},
update: function() {
this.convertTextareasResizable();
},
convertTextareasResizable: function() {
var textAreas = Ext.select("textarea[id^=tceforms-textarea-]");
textAreas.each(function(element) {
if (TYPO3.settings.textareaFlexible) {
var elasticTextarea = new Ext.ux.elasticTextArea().applyTo(element.dom.id, {
minHeight: 50,
maxHeight: TYPO3.settings.textareaMaxHeight
});
}
if (TYPO3.settings.textareaResize) {
element.addClass('resizable');
var dwrapped = new Ext.Resizable(element.dom.id, {
minWidth: 300,
minHeight: 50,
dynamic: true
});
}
});
}
}
Ext.onReady(TYPO3.TCEFORMS.init, TYPO3.TCEFORMS);
Ext.onReady(function() {
Ext.QuickTips.init();
});
// Fix for slider TCA control in IE9
Ext.override(Ext.dd.DragTracker, {
......
====================================================
Breaking: #64131 - Resizable Textarea option removed
====================================================
Description
===========
The User Setting "Resizable Textarea" for FormEngine textarea fields has been removed.
Impact
======
The option and its feature is no longer available.
......@@ -123,11 +123,6 @@ if (TYPO3_MODE === 'BE') {
'LLL:EXT:setup/mod/locallang.xlf:clearSessionVarsQuestion'
)
),
'resizeTextareas' => array(
'type' => 'check',
'label' => 'LLL:EXT:setup/mod/locallang.xlf:resizeTextareas',
'csh' => 'resizeTextareas'
),
'resizeTextareas_Flexible' => array(
'type' => 'check',
'label' => 'LLL:EXT:setup/mod/locallang.xlf:resizeTextareas_Flexible',
......@@ -146,7 +141,7 @@ if (TYPO3_MODE === 'BE') {
),
'showitem' => '--div--;LLL:EXT:setup/mod/locallang.xlf:personal_data,realName,email,emailMeAtLogin,password,password2,lang,
--div--;LLL:EXT:setup/mod/locallang.xlf:opening,startModule,thumbnailsByDefault,titleLen,
--div--;LLL:EXT:setup/mod/locallang.xlf:editFunctionsTab,edit_RTE,edit_docModuleUpload,showHiddenFilesAndFolders,resizeTextareas,resizeTextareas_Flexible,resizeTextareas_MaxHeight,copyLevels,recursiveDelete,resetConfiguration,clearSessionVars,
--div--;LLL:EXT:setup/mod/locallang.xlf:editFunctionsTab,edit_RTE,edit_docModuleUpload,showHiddenFilesAndFolders,resizeTextareas_Flexible,resizeTextareas_MaxHeight,copyLevels,recursiveDelete,resetConfiguration,clearSessionVars,
--div--;LLL:EXT:setup/mod/locallang.xlf:adminFunctions,debugInWindow'
);
}
\ No newline at end of file
}
......@@ -336,6 +336,11 @@ div.typo3-TCEforms div.c-tablayer table > tbody > tr > td > table.wrapperTable >
margin: 0 0.5em 0.5em 0;
position: relative;
}
// no manual resizing for textareas (works on non-IE browser only anyways)
// as it is handled by JS: "autosize"
.tceforms-textarea {
resize: none;
}
//
// TCEforms suggest
......
......@@ -9116,6 +9116,9 @@ div.typo3-TCEforms div.c-tablayer table > tbody > tr > td > table.wrapperTable >
margin: 0 0.5em 0.5em 0;
position: relative;
}
.tceforms-textarea {
resize: none;
}
div.typo3-TCEforms-suggest-position-right {
margin-left: 10px;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment