<ul class="ratingList jsOnly">
{foreach from=$field->getRatings() item=rating}
- <li data-rating="{@$rating}"><span class="icon icon24 {if $rating <= $field->getValue()}{implode from=$field->getActiveCssClasses() item=cssClass glue=' '}{@$cssClass}{/implode}{else}{implode from=$field->getDefaultCssClasses() item=cssClass glue=' '}{@$cssClass}{/implode}{/if} pointer jsTooltip" title="{lang maximumRating=$field->getMaximum()}wcf.form.field.rating.ratingTitle{/lang}"></span></li>
+ <li data-rating="{@$rating}">
+ <button type="button" class="jsTooltip" title="{lang maximumRating=$field->getMaximum()}wcf.form.field.rating.ratingTitle{/lang}">
+ {if $rating <= $field->getValue()}
+ {icon size=24 name='star' type='solid'}
+ {else}
+ {icon size=24 name='star'}
+ {/if}
+ </button>
+ </li>
{/foreach}
{if $field->isNullable()}
- <li class="ratingMetaButton" data-action="removeRating"><span class="icon icon24 fa-times pointer jsTooltip" title="{lang}wcf.form.field.rating.removeRating{/lang}"></span></li>
+ <li class="ratingMetaButton" data-action="removeRating">
+ <button type="button" class="jsTooltip" title="{lang}wcf.form.field.rating.removeRating{/lang}">
+ {icon size=24 name='xmark'}
+ </button>
+ </li>
{/if}
</ul>
<noscript>
require(['WoltLabSuite/Core/Form/Builder/Field/Controller/Rating'], function(FormBuilderFieldRating) {
new FormBuilderFieldRating(
'{@$field->getPrefixedId()}',
- {if $field->getValue() !== null}{@$field->getValue()}{else}''{/if},
- [ {implode from=$field->getActiveCssClasses() item=cssClass}'{@$cssClass}'{/implode} ],
- [ {implode from=$field->getDefaultCssClasses() item=cssClass}'{@$cssClass}'{/implode} ]
+ {if $field->getValue() !== null}{@$field->getValue()}{else}''{/if}
);
});
</script>
import * as Environment from "../../../../Environment";
class Rating {
- protected readonly _activeCssClasses: string[];
- protected readonly _defaultCssClasses: string[];
protected readonly _field: HTMLElement;
protected readonly _input: HTMLInputElement;
protected readonly _ratingElements: Map<string, HTMLElement>;
- constructor(fieldId: string, value: string, activeCssClasses: string[], defaultCssClasses: string[]) {
+ constructor(fieldId: string, value: string) {
this._field = document.getElementById(fieldId + "Container")!;
if (this._field === null) {
throw new Error("Unknown field with id '" + fieldId + "'");
this._input.value = value;
this._field.appendChild(this._input);
- this._activeCssClasses = activeCssClasses;
- this._defaultCssClasses = defaultCssClasses;
-
this._ratingElements = new Map();
const ratingList = this._field.querySelector(".ratingList")!;
const currentRating = target.dataset.rating!;
this._ratingElements.forEach((ratingElement, rating) => {
- const icon = ratingElement.getElementsByClassName("icon")[0]! as HTMLElement;
+ const icon = ratingElement.querySelector("fa-icon")!;
this._toggleIcon(icon, ~~rating <= ~~currentRating);
});
*/
protected _listItemMouseLeave(): void {
this._ratingElements.forEach((ratingElement) => {
- const icon = ratingElement.getElementsByClassName("icon")[0]! as HTMLElement;
+ const icon = ratingElement.querySelector("fa-icon")!;
this._toggleIcon(icon, false);
});
*/
protected _restoreRating(): void {
this._ratingElements.forEach((ratingElement, rating) => {
- const icon = ratingElement.getElementsByClassName("icon")[0]! as HTMLElement;
+ const icon = ratingElement.querySelector("fa-icon")!;
this._toggleIcon(icon, ~~rating <= ~~this._input.value);
});
/**
* Toggles the state of the given icon based on the given state parameter.
*/
- protected _toggleIcon(icon: HTMLElement, active = false): void {
+ protected _toggleIcon(icon: FaIcon, active = false): void {
if (active) {
- icon.classList.remove(...this._defaultCssClasses);
- icon.classList.add(...this._activeCssClasses);
+ icon.setIcon("star", true);
} else {
- icon.classList.remove(...this._activeCssClasses);
- icon.classList.add(...this._defaultCssClasses);
+ icon.setIcon("star");
}
}
}
<ul class="ratingList jsOnly">
{foreach from=$field->getRatings() item=rating}
- <li data-rating="{@$rating}"><span class="icon icon24 {if $rating <= $field->getValue()}{implode from=$field->getActiveCssClasses() item=cssClass glue=' '}{@$cssClass}{/implode}{else}{implode from=$field->getDefaultCssClasses() item=cssClass glue=' '}{@$cssClass}{/implode}{/if} pointer jsTooltip" title="{lang maximumRating=$field->getMaximum()}wcf.form.field.rating.ratingTitle{/lang}"></span></li>
+ <li data-rating="{@$rating}">
+ <button type="button" class="jsTooltip" title="{lang maximumRating=$field->getMaximum()}wcf.form.field.rating.ratingTitle{/lang}">
+ {if $rating <= $field->getValue()}
+ {icon size=24 name='star' type='solid'}
+ {else}
+ {icon size=24 name='star'}
+ {/if}
+ </button>
+ </li>
{/foreach}
{if $field->isNullable()}
- <li class="ratingMetaButton" data-action="removeRating"><span class="icon icon24 fa-times pointer jsTooltip" title="{lang}wcf.form.field.rating.removeRating{/lang}"></span></li>
+ <li class="ratingMetaButton" data-action="removeRating">
+ <button type="button" class="jsTooltip" title="{lang}wcf.form.field.rating.removeRating{/lang}">
+ {icon size=24 name='xmark'}
+ </button>
+ </li>
{/if}
</ul>
<noscript>
require(['WoltLabSuite/Core/Form/Builder/Field/Controller/Rating'], function(FormBuilderFieldRating) {
new FormBuilderFieldRating(
'{@$field->getPrefixedId()}',
- {if $field->getValue() !== null}{@$field->getValue()}{else}''{/if},
- [ {implode from=$field->getActiveCssClasses() item=cssClass}'{@$cssClass}'{/implode} ],
- [ {implode from=$field->getDefaultCssClasses() item=cssClass}'{@$cssClass}'{/implode} ]
+ {if $field->getValue() !== null}{@$field->getValue()}{else}''{/if}
);
});
</script>
Core = tslib_1.__importStar(Core);
Environment = tslib_1.__importStar(Environment);
class Rating {
- constructor(fieldId, value, activeCssClasses, defaultCssClasses) {
+ constructor(fieldId, value) {
this._field = document.getElementById(fieldId + "Container");
if (this._field === null) {
throw new Error("Unknown field with id '" + fieldId + "'");
this._input.type = "hidden";
this._input.value = value;
this._field.appendChild(this._input);
- this._activeCssClasses = activeCssClasses;
- this._defaultCssClasses = defaultCssClasses;
this._ratingElements = new Map();
const ratingList = this._field.querySelector(".ratingList");
ratingList.addEventListener("mouseleave", () => this._restoreRating());
const target = event.currentTarget;
const currentRating = target.dataset.rating;
this._ratingElements.forEach((ratingElement, rating) => {
- const icon = ratingElement.getElementsByClassName("icon")[0];
+ const icon = ratingElement.querySelector("fa-icon");
this._toggleIcon(icon, ~~rating <= ~~currentRating);
});
}
*/
_listItemMouseLeave() {
this._ratingElements.forEach((ratingElement) => {
- const icon = ratingElement.getElementsByClassName("icon")[0];
+ const icon = ratingElement.querySelector("fa-icon");
this._toggleIcon(icon, false);
});
}
*/
_restoreRating() {
this._ratingElements.forEach((ratingElement, rating) => {
- const icon = ratingElement.getElementsByClassName("icon")[0];
+ const icon = ratingElement.querySelector("fa-icon");
this._toggleIcon(icon, ~~rating <= ~~this._input.value);
});
}
*/
_toggleIcon(icon, active = false) {
if (active) {
- icon.classList.remove(...this._defaultCssClasses);
- icon.classList.add(...this._activeCssClasses);
+ icon.setIcon("star", true);
}
else {
- icon.classList.remove(...this._activeCssClasses);
- icon.classList.add(...this._defaultCssClasses);
+ icon.setIcon("star");
}
}
}
* the the field is not nullable, the minimum value will be automatically set when the field's value
* is requested the first time.
*
- * By default, the active rating state is represented by orange stars and the default state by white
- * stars with a black border.
- *
* This field uses the `wcf.form.field.rating` language item as the default form field label and has
* a minimum rating of `1` and a maximum rating of `5`.
*
}
use TNullableFormField;
- /**
- * CSS classes for the active state of the rating elements
- * @var string[]
- */
- protected $activeCssClasses = ['fa-star', 'orange'];
-
- /**
- * CSS classes for the default state of the rating elements
- * @var string[]
- */
- protected $defaultCssClasses = ['fa-star-o'];
-
/**
* @inheritDoc
*/
$this->maximum(5);
}
- /**
- * Sets the CSS classes for the active state of the rating elements.
- *
- * @param string[] $cssClasses active state CSS classes
- * @return static this form field
- * @throws \InvalidArgumentException if no or invalid CSS classes are given
- */
- public function activeCssClasses(array $cssClasses)
- {
- if (empty($cssClasses)) {
- throw new \InvalidArgumentException("No css classes for active state given for field '{$this->getId()}'.");
- }
-
- foreach ($cssClasses as $cssClass) {
- static::validateClass($cssClass);
- }
-
- $this->activeCssClasses = $cssClasses;
-
- return $this;
- }
-
- /**
- * Sets the CSS classes for the default state of the rating elements.
- *
- * @param string[] $cssClasses default state CSS classes
- * @return static this form field
- * @throws \InvalidArgumentException if no or invalid CSS classes are given
- */
- public function defaultCssClasses(array $cssClasses)
- {
- if (empty($cssClasses)) {
- throw new \InvalidArgumentException("No css classes for default state given for field '{$this->getId()}'.");
- }
-
- foreach ($cssClasses as $cssClass) {
- static::validateClass($cssClass);
- }
-
- $this->defaultCssClasses = $cssClasses;
-
- return $this;
- }
-
- /**
- * Returns the CSS classes for the active state of the rating elements.
- *
- * @return string[]
- */
- public function getActiveCssClasses()
- {
- return $this->activeCssClasses;
- }
-
- /**
- * Returns the CSS classes for the default state of the rating elements.
- *
- * @return string[]
- */
- public function getDefaultCssClasses()
- {
- return $this->defaultCssClasses;
- }
-
/**
* Returns the sorted list of possible ratings used to generate the form field's html code.
*
> li {
display: inline-block;
}
+
+ fa-icon[name="star"][solid] {
+ color: #f90;
+ }
}