@@ -95,6 +95,8 @@ function waitForMainAndObserveContent() {
9595 const valueElement = el . querySelector (
9696 task . valueElement . elementSelector
9797 ) ;
98+ let raviIconPositionAbsolute = true ;
99+
98100 if ( valueElement ) {
99101 // We usually add icon to the option header.
100102 let addIconElement = valueElement . closest (
@@ -109,6 +111,8 @@ function waitForMainAndObserveContent() {
109111 addIconElement = valueElement
110112 . closest ( 'fieldset' )
111113 . querySelector ( task . iconElement ) ;
114+
115+ raviIconPositionAbsolute = false ;
112116 }
113117
114118 // Upload input field.
@@ -122,25 +126,37 @@ function waitForMainAndObserveContent() {
122126 '.prpl-form-row-ravi'
123127 )
124128 ) {
125- addIconElement . style . position =
126- 'relative' ;
129+ // Check for value if specified in task.
130+ const valueMatches = checkTaskValue (
131+ valueElement ,
132+ task
133+ ) ;
127134
128135 // Create a new span with the class prpl-form-row-ravi.
129136 const raviIconWrapper =
130137 document . createElement ( 'span' ) ;
131138 raviIconWrapper . classList . add (
132- 'prpl-form-row-ravi'
139+ 'prpl-form-row-ravi' ,
140+ 'prpl-element-awards-points-icon-wrapper'
133141 ) ;
134- raviIconWrapper . style . position =
135- 'absolute' ;
136- raviIconWrapper . style . right = '-1.5rem' ;
137- raviIconWrapper . style . top = '0' ;
138142
139- // Check for value if specified in task.
140- const valueMatches = checkTaskValue (
141- valueElement ,
142- task
143- ) ;
143+ if ( valueMatches ) {
144+ raviIconWrapper . classList . add (
145+ 'complete'
146+ ) ;
147+ }
148+
149+ // Styling for absolute positioning.
150+ if ( raviIconPositionAbsolute ) {
151+ addIconElement . style . position =
152+ 'relative' ;
153+
154+ raviIconWrapper . style . position =
155+ 'absolute' ;
156+ raviIconWrapper . style . right =
157+ '3.5rem' ;
158+ raviIconWrapper . style . top = '-7px' ;
159+ }
144160
145161 raviIconWrapper . appendChild (
146162 document . createElement ( 'span' )
@@ -156,16 +172,29 @@ function waitForMainAndObserveContent() {
156172 iconImg . width = 16 ;
157173 iconImg . height = 16 ;
158174
159- // Apply grayscale if state doesn't match
160- iconImg . style . filter = ! valueMatches
161- ? 'grayscale(100%)'
162- : 'none' ;
163-
164175 // Append the icon image to the raviIconWrapper.
165176 raviIconWrapper
166177 . querySelector ( 'span' )
167178 . appendChild ( iconImg ) ;
168179
180+ // Add the points to the raviIconWrapper.
181+ const pointsWrapper =
182+ document . createElement ( 'span' ) ;
183+ pointsWrapper . classList . add (
184+ 'prpl-form-row-points'
185+ ) ;
186+ pointsWrapper . textContent = valueMatches
187+ ? '✓'
188+ : '+1' ;
189+ raviIconWrapper . appendChild (
190+ pointsWrapper
191+ ) ;
192+
193+ // Finally add the raviIconWrapper to the DOM.
194+ addIconElement . appendChild (
195+ raviIconWrapper
196+ ) ;
197+
169198 // Watch for changes in aria-checked to update the icon dynamically
170199 const valueElementObserver =
171200 new MutationObserver ( ( ) => {
@@ -175,10 +204,22 @@ function waitForMainAndObserveContent() {
175204 valueElement ,
176205 task
177206 ) ;
178- iconImg . style . filter =
179- ! currentValueMatches
180- ? 'grayscale(100%)'
181- : 'none' ;
207+
208+ if ( currentValueMatches ) {
209+ raviIconWrapper . classList . add (
210+ 'complete'
211+ ) ;
212+
213+ pointsWrapper . textContent =
214+ '✓' ;
215+ } else {
216+ raviIconWrapper . classList . remove (
217+ 'complete'
218+ ) ;
219+
220+ pointsWrapper . textContent =
221+ '+1' ;
222+ }
182223 } ) ;
183224
184225 valueElementObserver . observe (
@@ -191,11 +232,6 @@ function waitForMainAndObserveContent() {
191232 ] ,
192233 }
193234 ) ;
194-
195- // Finally add the raviIconWrapper to the DOM.
196- addIconElement . appendChild (
197- raviIconWrapper
198- ) ;
199235 }
200236 }
201237 }
0 commit comments