Skip to content

Commit 23d5d5a

Browse files
authored
Merge pull request #413 from ProgressPlanner/filip/yoast-ravi-styling
Consistent styling for Ravi focus icon
2 parents 2907b77 + 2f6d569 commit 23d5d5a

4 files changed

Lines changed: 69 additions & 30 deletions

File tree

assets/css/focus-element.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
gap: 0.25rem;
1717
background-color: #fff9f0;
1818
font-size: 0.75rem;
19-
border: 2px solid #faa310;
19+
border: 2px solid #faa310 !important;
2020
border-radius: 1rem;
2121
color: #534786;
2222
font-weight: 600;

assets/js/yoast-focus-element.js

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

classes/suggested-tasks/local-tasks/providers/integrations/yoast/class-add-yoast-providers.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public function enqueue_assets( $hook ) {
6363
],
6464
]
6565
);
66+
67+
// Enqueue the style.
68+
\progress_planner()->get_admin__enqueue()->enqueue_style( 'progress-planner/focus-element' );
6669
}
6770
/**
6871
* Add the providers.

classes/suggested-tasks/local-tasks/providers/integrations/yoast/class-organization-logo.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ public function get_focus_tasks() {
7373
'iconElement' => 'legend.yst-label',
7474
'valueElement' => [
7575
'elementSelector' => $this->yoast_seo->helpers->options->get( 'company_or_person', 'company' ) !== 'person'
76-
? 'input[name="wpseo_titles.company_logo_id"]'
77-
: 'input[name="wpseo_titles.person_logo_id"]',
76+
? 'input[name="wpseo_titles.company_logo"]'
77+
: 'input[name="wpseo_titles.person_logo"]',
7878
'attributeName' => 'value',
79-
'attributeValue' => '0',
79+
'attributeValue' => '',
8080
'operator' => '!=',
8181
],
8282
];

0 commit comments

Comments
 (0)