From 710659a9fbf00cdb57426e3d266b99267358b124 Mon Sep 17 00:00:00 2001 From: Jonathon Menz Date: Fri, 11 Mar 2016 11:56:07 -0800 Subject: [PATCH] HTMLEditorField support --- README.md | 9 ++++++--- _config/config.yml | 3 +++ code/TextTargetLengthExtension.php | 3 +-- javascript/text-target-length.js | 16 ++++++++++++++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d4b9a66..fdc84db 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ If you see a field marked 'Description' you know roughly what type of content to put in there. But how do you know how much of it to write? A single sentence might do, but maybe a paragraph or more is required? A great content plan should recommend an ideal length for every type of content, so content authors and designers alike can make informed decisions. -This module extends the `TextField` and `TextareaField` classes in SilverStripe to allow you to set a recommended content length, and set soft upper and lower limits on character count. +This module extends the `TextField`, `TextareaField` and `HTMLEditorField` classes in SilverStripe to allow you to set a recommended content length, and set soft upper and lower limits on character count. ## Requirements @@ -22,7 +22,7 @@ I promise it's worth your time to learn how to use Composer. If painless updatin ## How to use -With the module installed you can call call `setTargetLength()` on `TextField` and `TextareaField` form fields. +With the module installed you can call call `setTargetLength()` on `TextField`, `TextareaField` and `HTMLEditorField` form fields. ```php // Ideal length: 100 characters @@ -34,6 +34,10 @@ $field->setTargetLength(100); // Minimum: 25 // Maximum: 150 $field->setTargetLength(100, 25, 150); + +// Prefer to think in word count? +// 6 characters per word works okay for English +$field->setTargetLength(50*6); ``` ## Want to see more like this? @@ -44,7 +48,6 @@ I donate a lot of my time to open-source projects, so if you use this module in ## To Do - - [ ] Extension for HTMLEditorField? - [ ] Translation - [ ] Customise hint text through config diff --git a/_config/config.yml b/_config/config.yml index 007a3c6..a2c2cbe 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -7,3 +7,6 @@ TextField: TextareaField: extensions: - TextTargetLengthExtension +HTMLEditorField: + extensions: + - TextTargetLengthExtension diff --git a/code/TextTargetLengthExtension.php b/code/TextTargetLengthExtension.php index 9de9d35..aec4eb9 100755 --- a/code/TextTargetLengthExtension.php +++ b/code/TextTargetLengthExtension.php @@ -1,7 +1,7 @@ ' + targetFulfilled + '% ' + remark + ''); field.data('previousCount', charCount); }, + getText: function() { + var field = $(this); + if (field.hasClass('htmleditor')) { + var editor = tinyMCE.getInstanceById(field.attr('ID')); + if (editor !== undefined) { + return $(editor.getContent()).text(); + } else { + return $('
').html(field.val()).text(); + } + } + return field.val(); + }, onadd: function() { // Insert extra markup var field = $(this);