-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Silverstripe 4 support updating code
- Loading branch information
1 parent
0960fa2
commit 882d139
Showing
7 changed files
with
61 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,2 @@ | ||
<?php | ||
|
||
if (!defined('TEXTTARGETLENGTH_DIR')) { | ||
//Assumes this module is installed in web root | ||
define('TEXTTARGETLENGTH_DIR', basename(dirname(__FILE__))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
--- | ||
Name: text-target-length | ||
--- | ||
TextField: | ||
SilverStripe\Forms\TextareaField: | ||
extensions: | ||
- TextTargetLengthExtension | ||
TextareaField: | ||
- JonoM\SilverStripeTextTargetLength\TextTargetLengthExtension | ||
SilverStripe\Forms\TextareaField: | ||
extensions: | ||
- TextTargetLengthExtension | ||
HTMLEditorField: | ||
- JonoM\SilverStripeTextTargetLength\TextTargetLengthExtension | ||
SilverStripe\Forms\HTMLEditor\HTMLEditorField: | ||
extensions: | ||
- TextTargetLengthExtension | ||
- JonoM\SilverStripeTextTargetLength\TextTargetLengthExtension |
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
{ | ||
"name": "jonom/silverstripe-text-target-length", | ||
"description": "Set character length recommendations on SilverStripe text form fields", | ||
"type": "silverstripe-module", | ||
"keywords": ["silverstripe", "textfield", "textareafield", "target"], | ||
"license": "BSD-3-Clause", | ||
"authors": [{ | ||
"name": "Jonathon Menz", | ||
"homepage": "http://jonathonmenz.com" | ||
}], | ||
"require": { | ||
"silverstripe/framework": "^3.1" | ||
}, | ||
"extra": { | ||
"installer-name": "text-target-length" | ||
} | ||
"name": "jonom/silverstripe-text-target-length", | ||
"description": "Set character length recommendations on SilverStripe text form fields", | ||
"type": "silverstripe-vendormodule", | ||
"keywords": ["silverstripe", "textfield", "textareafield", "target"], | ||
"license": "BSD-3-Clause", | ||
"authors": [{ | ||
"name": "Jonathon Menz", | ||
"homepage": "http://jonathonmenz.com" | ||
}], | ||
"require": { | ||
"silverstripe/framework": "^4.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"JonoM\\SilverStripeTextTargetLength\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"expose": [ | ||
"client" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,55 @@ | ||
<?php | ||
|
||
namespace JonoM\SilverStripeTextTargetLength; | ||
|
||
use SilverStripe\Core\Extension; | ||
use SilverStripe\View\Requirements; | ||
|
||
/** | ||
* Apply this extension to text editing form field such as TextareaField | ||
* to allow setting of ideal, min and max lengths. These are | ||
* soft limits only, to give CMS users an idea of target length. | ||
*/ | ||
class TextTargetLengthExtension extends Extension | ||
{ | ||
|
||
/** | ||
* Set a target character length for text in a field. | ||
* | ||
* @param Int $idealCharCount the ideal number of characters for this text | ||
* @param Int $minCharCount (default: null) the minimum number of characters for this text | ||
* @param Int $maxCharCount (default: null) the maximum number of characters for this text | ||
* @return FormField | ||
*/ | ||
public function setTargetLength($idealCharCount, $minCharCount = null, $maxCharCount = null) | ||
{ | ||
/** | ||
* Set a target character length for text in a field. | ||
* | ||
* @param Int $idealCharCount the ideal number of characters for this text | ||
* @param Int $minCharCount (default: null) the minimum number of characters for this text | ||
* @param Int $maxCharCount (default: null) the maximum number of characters for this text | ||
* @return FormField | ||
*/ | ||
public function setTargetLength($idealCharCount, $minCharCount = null, $maxCharCount = null) | ||
{ | ||
$field = $this->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: <b>{value}%</b> <i>{remark}</i>')); | ||
$field->setAttribute('data-hint-length-tooshort', _t('TextTargetLength.LengthTooShort', 'Keep going!')); | ||
$field->setAttribute('data-hint-length-toolong', _t('TextTargetLength.LengthTooLong', 'Too long')); | ||
$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; | ||
} | ||
} |