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;
|
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
|
||||||
<a href="#" class="triggerMore">$this->labelMore</a>
|
<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 {
|
|||||||
<a href="#" class="triggerLess">$this->labelLess</a>
|
<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() {
|
||||||
|
Loading…
Reference in New Issue
Block a user