mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Changed style in forms\ToggleField.php
This commit is contained in:
parent
f49c0b58d9
commit
8e7e783dd0
@ -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
|
||||
<a href="#" class="triggerMore">$this->labelMore</a>
|
||||
</div>
|
||||
<div class="readonly typography contentMore">
|
||||
@ -75,7 +94,7 @@ class ToggleField extends ReadonlyField {
|
||||
<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() {
|
||||
|
Loading…
Reference in New Issue
Block a user