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