Changed style in forms\ToggleField.php

This commit is contained in:
assertchris 2016-04-20 15:00:38 +12:00
parent f49c0b58d9
commit 8e7e783dd0
No known key found for this signature in database
GPG Key ID: C214A2526E8D4631

View File

@ -34,13 +34,24 @@ class ToggleField extends ReadonlyField {
*/ */
public $truncateChars; public $truncateChars;
/**
* @var null|int
*/
public $charNum;
/**
* @var bool
*/
public $startClosed;
/** /**
* @param name The field name * @param name The field name
* @param title The field title * @param title The field title
* @param value The current value * @param value The current value
*/ */
public function __construct($name, $title = "", $value = "") { public function __construct($name, $title = '', $value = '') {
Deprecation::notice('4.0', 'Use custom javascript with a ReadOnlyField'); Deprecation::notice('4.0', 'Use custom javascript with a ReadOnlyField');
$this->labelMore = _t('ToggleField.MORE', 'more'); $this->labelMore = _t('ToggleField.MORE', 'more');
$this->labelLess = _t('ToggleField.LESS', 'less'); $this->labelLess = _t('ToggleField.LESS', 'less');
@ -50,24 +61,32 @@ class ToggleField extends ReadonlyField {
} }
public function Field($properties = array()) { public function Field($properties = array()) {
$content = '';
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js'); Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js');
Requirements::javascript(FRAMEWORK_DIR . "/javascript/ToggleField.js"); Requirements::javascript(FRAMEWORK_DIR . '/javascript/ToggleField.js');
if($this->startClosed) $this->addExtraClass('startClosed'); if($this->startClosed) {
$this->addExtraClass('startClosed');
}
$valforInput = $this->value ? Convert::raw2att($this->value) : ""; $valueForInput = '';
$rawInput = Convert::html2raw($valforInput);
if($this->charNum) $reducedVal = substr($rawInput,0,$this->charNum); if($this->value) {
else $reducedVal = DBField::create_field('Text',$rawInput)->{$this->truncateMethod}(); $valueForInput = Convert::raw2att($this->value);
}
// only create togglefield if the truncated content is shorter $rawInput = Convert::html2raw($valueForInput);
if(strlen($reducedVal) < strlen($rawInput)) {
if($this->charNum) {
$reducedValue = substr($rawInput, 0, $this->charNum);
} else {
$reducedValue = DBField::create_field('Text', $rawInput)->{$this->truncateMethod}();
}
// only create toggle field if the truncated content is shorter
if(strlen($reducedValue) < strlen($rawInput)) {
$content = <<<HTML $content = <<<HTML
<div class="readonly typography contentLess" style="display: none"> <div class="readonly typography contentLess" style="display: none">
$reducedVal $reducedValue
&nbsp;<a href="#" class="triggerMore">$this->labelMore</a> &nbsp;<a href="#" class="triggerMore">$this->labelMore</a>
</div> </div>
<div class="readonly typography contentMore"> <div class="readonly typography contentMore">
@ -75,7 +94,7 @@ class ToggleField extends ReadonlyField {
&nbsp;<a href="#" class="triggerLess">$this->labelLess</a> &nbsp;<a href="#" class="triggerLess">$this->labelLess</a>
</div> </div>
<br /> <br />
<input type="hidden" name="$this->name" value="$valforInput" /> <input type="hidden" name="$this->name" value="$valueForInput" />
HTML; HTML;
} else { } else {
$this->dontEscape = true; $this->dontEscape = true;
@ -91,7 +110,11 @@ HTML;
* @param boolean * @param boolean
*/ */
public function startClosed($bool) { public function startClosed($bool) {
($bool) ? $this->addExtraClass('startClosed') : $this->removeExtraClass('startClosed'); if($bool) {
$this->addExtraClass('startClosed');
} else {
$this->removeExtraClass('startClosed');
}
} }
public function Type() { public function Type() {