@@ -799,30 +799,71 @@ export class CoreQuestionHelperProvider {
799799 * Returns correct icon based on the LMS version.
800800 * In LMS 4.4 and older, fa-check means correct. In 4.5+, fa-check means partially correct.
801801 *
802- * @param withPrefix Whether to include the prefix in the icon name.
803- * @returns Icon name.
802+ * @returns Icon data.
804803 */
805- getCorrectIcon ( withPrefix = true ) : string {
806- const icon = CoreSites . getRequiredCurrentSite ( ) . isVersionGreaterEqualThan ( '4.5' )
807- ? 'check-double'
808- : 'check' ;
804+ getCorrectIcon ( ) : IconData {
805+ if ( CoreSites . getCurrentSite ( ) ?. isVersionGreaterEqualThan ( '4.5' ) ) {
806+ return {
807+ name : 'circle-check' ,
808+ prefix : 'far' ,
809+ library : 'regular' ,
810+ fullName : 'far-circle-check' ,
811+ } ;
812+ } else {
813+ return {
814+ name : 'check' ,
815+ prefix : 'fas' ,
816+ library : 'solid' ,
817+ fullName : 'fas-check' ,
818+ } ;
819+ }
820+ }
809821
810- return withPrefix ? `fas-${ icon } ` : icon ;
822+ /**
823+ * Returns incorrect correct icon based on the LMS version.
824+ *
825+ * @returns Icon data.
826+ */
827+ getIncorrectIcon ( ) : IconData {
828+ if ( CoreSites . getCurrentSite ( ) ?. isVersionGreaterEqualThan ( '4.5' ) ) {
829+ return {
830+ name : 'circle-xmark' ,
831+ prefix : 'far' ,
832+ library : 'regular' ,
833+ fullName : 'far-circle-xmark' ,
834+ } ;
835+ } else {
836+ return {
837+ name : 'xmark' ,
838+ prefix : 'fas' ,
839+ library : 'solid' ,
840+ fullName : 'fas-xmark' ,
841+ } ;
842+ }
811843 }
812844
813845 /**
814846 * Returns partially correct icon based on the LMS version.
815847 * In LMS 4.4 and older, fa-check means correct. In 4.5+, fa-check means partially correct.
816848 *
817- * @param withPrefix Whether to include the prefix in the icon name.
818- * @returns Icon name.
849+ * @returns Icon data.
819850 */
820- getPartiallyCorrectIcon ( withPrefix = true ) : string {
821- const icon = CoreSites . getRequiredCurrentSite ( ) . isVersionGreaterEqualThan ( '4.5' )
822- ? 'check'
823- : 'square-check' ;
824-
825- return withPrefix ? `fas-${ icon } ` : icon ;
851+ getPartiallyCorrectIcon ( ) : IconData {
852+ if ( CoreSites . getCurrentSite ( ) ?. isVersionGreaterEqualThan ( '4.5' ) ) {
853+ return {
854+ name : 'circle-half-stroke' ,
855+ prefix : 'fas' ,
856+ library : 'solid' ,
857+ fullName : 'fas-circle-half-stroke' ,
858+ } ;
859+ } else {
860+ return {
861+ name : 'square-check' ,
862+ prefix : 'fas' ,
863+ library : 'solid' ,
864+ fullName : 'fas-square-check' ,
865+ } ;
866+ }
826867 }
827868
828869 /**
@@ -833,41 +874,42 @@ export class CoreQuestionHelperProvider {
833874 treatCorrectnessIcons ( element : HTMLElement ) : void {
834875 const icons = < HTMLElement [ ] > Array . from ( element . querySelectorAll ( 'img.icon, img.questioncorrectnessicon, i.icon' ) ) ;
835876 icons . forEach ( ( icon ) => {
836- let iconName : string | undefined ;
877+ let iconData : IconData | undefined ;
837878 let color : string | undefined ;
838879
839- const correctIcon = this . getCorrectIcon ( false ) ;
840- const partiallyCorrectIcon = this . getCorrectIcon ( false ) ;
880+ const correctIcon = this . getCorrectIcon ( ) ;
881+ const incorrectIcon = this . getIncorrectIcon ( ) ;
882+ const partiallyCorrectIcon = this . getPartiallyCorrectIcon ( ) ;
841883 if ( 'src' in icon ) {
842884 if ( ( icon as HTMLImageElement ) . src . indexOf ( 'correct' ) >= 0 ) {
843- iconName = correctIcon ;
885+ iconData = correctIcon ;
844886 color = CoreIonicColorNames . SUCCESS ;
845887 } else if ( ( icon as HTMLImageElement ) . src . indexOf ( 'incorrect' ) >= 0 ) {
846- iconName = 'xmark' ;
888+ iconData = incorrectIcon ;
847889 color = CoreIonicColorNames . DANGER ;
848890 }
849891 } else {
850- if ( icon . classList . contains ( `fa-${ partiallyCorrectIcon } ` ) ) {
851- iconName = partiallyCorrectIcon ;
892+ if ( icon . classList . contains ( `fa-${ partiallyCorrectIcon . name } ` ) ) {
893+ iconData = partiallyCorrectIcon ;
852894 color = CoreIonicColorNames . WARNING ;
853- } else if ( icon . classList . contains ( `fa-${ correctIcon } ` ) ) {
854- iconName = correctIcon ;
895+ } else if ( icon . classList . contains ( `fa-${ correctIcon . name } ` ) ) {
896+ iconData = correctIcon ;
855897 color = CoreIonicColorNames . SUCCESS ;
856- } else if ( icon . classList . contains ( ' fa-xmark' ) || icon . classList . contains ( 'fa-remove' ) ) {
857- iconName = 'xmark' ;
898+ } else if ( icon . classList . contains ( ` fa-${ incorrectIcon . name } ` ) || icon . classList . contains ( 'fa-remove' ) ) {
899+ iconData = incorrectIcon ;
858900 color = CoreIonicColorNames . DANGER ;
859901 }
860902 }
861903
862- if ( ! iconName ) {
904+ if ( ! iconData ) {
863905 return ;
864906 }
865907
866908 // Replace the icon with the font version.
867909 const newIcon : HTMLIonIconElement = document . createElement ( 'ion-icon' ) ;
868910
869- newIcon . setAttribute ( 'name' , `fas- ${ iconName } ` ) ;
870- newIcon . setAttribute ( 'src' , CoreIcons . getIconSrc ( 'font-awesome' , 'solid' , iconName ) ) ;
911+ newIcon . setAttribute ( 'name' , iconData . fullName ) ;
912+ newIcon . setAttribute ( 'src' , CoreIcons . getIconSrc ( 'font-awesome' , iconData . library , iconData . name ) ) ;
871913 newIcon . className = `core-correct-icon ion-color ion-color-${ color } questioncorrectnessicon` ;
872914 newIcon . title = icon . title ;
873915 newIcon . setAttribute ( 'aria-label' , icon . title ) ;
@@ -997,3 +1039,13 @@ export type CoreQuestionBehaviourButton = {
9971039export type CoreQuestionBehaviourCertaintyOption = CoreQuestionBehaviourButton & {
9981040 text : string ;
9991041} ;
1042+
1043+ /**
1044+ * Data about a font-awesome icon.
1045+ */
1046+ type IconData = {
1047+ name : string ;
1048+ prefix : string ;
1049+ library : string ;
1050+ fullName : string ;
1051+ } ;
0 commit comments