From 77b2ae587d3d759460c454a37d943eee0096d8aa Mon Sep 17 00:00:00 2001 From: Chris Tombleson Date: Wed, 24 Jan 2018 11:04:57 +1300 Subject: [PATCH 1/3] Silverstripe 4 support moving code to src dir --- {code => src}/TextTargetLengthExtension.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {code => src}/TextTargetLengthExtension.php (100%) diff --git a/code/TextTargetLengthExtension.php b/src/TextTargetLengthExtension.php similarity index 100% rename from code/TextTargetLengthExtension.php rename to src/TextTargetLengthExtension.php From 0960fa2d1a841642d80c9e851bddc958c325fc1c Mon Sep 17 00:00:00 2001 From: Chris Tombleson Date: Wed, 24 Jan 2018 11:12:25 +1300 Subject: [PATCH 2/3] Silverstripe 4 support moved css & javascript to client dir --- {javascript => client/javascript}/text-target-length.js | 0 {css => client}/text-target-length.css | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {javascript => client/javascript}/text-target-length.js (100%) rename {css => client}/text-target-length.css (100%) diff --git a/javascript/text-target-length.js b/client/javascript/text-target-length.js similarity index 100% rename from javascript/text-target-length.js rename to client/javascript/text-target-length.js diff --git a/css/text-target-length.css b/client/text-target-length.css similarity index 100% rename from css/text-target-length.css rename to client/text-target-length.css From 882d1395b509c1ad2c531e1e856449126189fa8e Mon Sep 17 00:00:00 2001 From: Chris Tombleson Date: Wed, 24 Jan 2018 11:14:33 +1300 Subject: [PATCH 3/3] Silverstripe 4 support updating code --- README.md | 6 +-- _config.php | 4 -- _config/config.yml | 12 ++--- client/{ => css}/text-target-length.css | 0 client/javascript/text-target-length.js | 0 composer.json | 37 ++++++++------- src/TextTargetLengthExtension.php | 60 +++++++++++++------------ 7 files changed, 61 insertions(+), 58 deletions(-) rename client/{ => css}/text-target-length.css (100%) mode change 100755 => 100644 client/javascript/text-target-length.js mode change 100755 => 100644 src/TextTargetLengthExtension.php diff --git a/README.md b/README.md index 1d35a1b..59a1188 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This module extends the `TextField`, `TextareaField` and `HTMLEditorField` class ## Requirements -SilverStripe 3.1+ (3.3 tested) +SilverStripe 4.0+ (3.1+ in previous releases) ## Installation @@ -16,10 +16,6 @@ SilverStripe 3.1+ (3.3 tested) [Packagist listing](https://packagist.org/packages/jonom/silverstripe-text-target-length) and [installation instructions](http://doc.silverstripe.org/framework/en/trunk/installation/composer#adding-modules-to-your-project) -### Manually - -I promise it's worth your time to learn how to use Composer. If painless updating isn't your thing though you can download and extract this project, rename the module folder 'text-target-length', place it in your project root and run a dev/build?flush=1. - ## How to use With the module installed you can call call `setTargetLength()` on `TextField`, `TextareaField` and `HTMLEditorField` form fields. diff --git a/_config.php b/_config.php index 8093b43..a4abe2d 100644 --- a/_config.php +++ b/_config.php @@ -1,6 +1,2 @@ owner; $idealCharCount = (int)$idealCharCount; - if (!$idealCharCount > 0) return $field; + if (!$idealCharCount > 0) return $field; - // Set defaults - if ($minCharCount === null) $minCharCount = round($idealCharCount * .75); - if ($maxCharCount === null) $maxCharCount = round($idealCharCount * 1.25); + // Set defaults + if ($minCharCount === null) $minCharCount = round($idealCharCount * .75); + if ($maxCharCount === null) $maxCharCount = round($idealCharCount * 1.25); - // Validate - if (!($maxCharCount >= $idealCharCount && $idealCharCount >= $minCharCount)) return $field; + // Validate + if (!($maxCharCount >= $idealCharCount && $idealCharCount >= $minCharCount)) return $field; - // Activate - $field->addExtraClass('target-length'); - $field->setAttribute('data-target-ideal-length', $idealCharCount); - $field->setAttribute('data-target-min-length', $minCharCount); - $field->setAttribute('data-target-max-length', $maxCharCount); + // Activate + $field->addExtraClass('target-length'); + $field->setAttribute('data-target-ideal-length', $idealCharCount); + $field->setAttribute('data-target-min-length', $minCharCount); + $field->setAttribute('data-target-max-length', $maxCharCount); $field->setAttribute('data-hint-length-target', _t('TextTargetLength.LengthTarget', 'Length target: {value}% {remark}')); $field->setAttribute('data-hint-length-tooshort', _t('TextTargetLength.LengthTooShort', 'Keep going!')); @@ -41,11 +45,11 @@ public function setTargetLength($idealCharCount, $minCharCount = null, $maxCharC $field->setAttribute('data-hint-length-adequate', _t('TextTargetLength.LengthAdequate', 'Okay')); $field->setAttribute('data-hint-length-ideal', _t('TextTargetLength.LengthIdeal', 'Great!')); - Requirements::javascript(FRAMEWORK_DIR.'/thirdparty/jquery/jquery.js'); - Requirements::javascript(FRAMEWORK_DIR.'/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js'); - Requirements::javascript(TEXTTARGETLENGTH_DIR.'/javascript/text-target-length.js'); - Requirements::css(TEXTTARGETLENGTH_DIR.'/css/text-target-length.css'); + Requirements::javascript('silverstripe/admin:thirdparty/jquery/jquery.js'); + Requirements::javascript('silverstripe/admin:thirdparty/jquery-entwine/dist/jquery.entwine-dist.js'); + Requirements::javascript('jonom/silverstripe-text-target-length:client/javascript/text-target-length.js'); + Requirements::css('jonom/silverstripe-text-target-length:client/css/text-target-length.css'); - return $field; - } + return $field; + } }