ENHANCEMENT Soft-code CSS explicit height and compute against rows

This commit is contained in:
Damian Mooyman 2017-08-01 13:59:35 +12:00
parent 078a508d71
commit ae97c15e42
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
3 changed files with 21 additions and 3 deletions

View File

@ -51,7 +51,14 @@ class HTMLEditorField extends TextareaField
* @config
* @var int
*/
private static $default_rows = 30;
private static $default_rows = 20;
/**
* Extra height per row
*
* @var int
*/
private static $fixed_row_height = 20;
/**
* ID or instance of editorconfig
@ -110,7 +117,17 @@ class HTMLEditorField extends TextareaField
public function getAttributes()
{
// Fix CSS height based on rows
$rowHeight = $this->config()->get('fixed_row_height');
$attributes = [];
if ($rowHeight) {
$height = $this->getRows() * $rowHeight;
$attributes['style'] = sprintf('height: %dpx;', $height);
}
// Merge attributes
return array_merge(
$attributes,
parent::getAttributes(),
$this->getEditorConfig()->getAttributes()
);

View File

@ -332,7 +332,6 @@ class TinyMCEConfig extends HTMLEditorConfig
return [
'data-editor' => 'tinyMCE', // Register ss.editorWrappers.tinyMCE
'data-config' => Convert::array2json($this->getConfig()),
'style' => 'height:350px'
];
}

View File

@ -8,6 +8,7 @@ use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
use SilverStripe\Forms\HTMLEditor\TinyMCECombinedGenerator;
use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;
use SilverStripe\View\SSViewer;
class TinyMCECombinedGeneratorTest extends SapphireTest
{
@ -18,6 +19,7 @@ class TinyMCECombinedGeneratorTest extends SapphireTest
// Set custom base_path for tinymce
Director::config()->set('alternate_base_folder', __DIR__ . '/TinyMCECombinedGeneratorTest');
Director::config()->set('alternate_base_url', 'http://www.mysite.com/basedir/');
SSViewer::config()->set('themes', [ SSViewer::DEFAULT_THEME ]);
TinyMCEConfig::config()->set('base_dir', 'tinymce');
}
@ -45,7 +47,7 @@ class TinyMCECombinedGeneratorTest extends SapphireTest
/** @var TinyMCECombinedGenerator $generator */
$generator = Injector::inst()->create(TinyMCECombinedGenerator::class);
$this->assertEquals(
'_tinymce/tinymce-testconfig-8d695fc0be.js',
'_tinymce/tinymce-testconfig-6422b3814d.js',
$generator->generateFilename($c),
"Filename for config: " . json_encode($c->getAttributes()) . " should match expected value"
);