-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into USAGOV-1789-wizard-datalayer
- Loading branch information
Showing
8 changed files
with
113 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
web/modules/custom/usagov_ckeditor5_source_editing_fixup/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Module: usagov_ckeditor5_source_editing_fixup | ||
|
||
This module exists solely to remove a restriction on adding elements to the list of "Manually editable HTML tags" in the "Source editing" CKEditor 5 plugin. The problem is that if a plugin that is installed but not enabled for the current editor's configuration specifies an element as allowed, the Source Editing plugin won't let you add that element by itself -- an error message advises you to enable the plugin instead. | ||
|
||
In our case, we want to allow editors to add divs with data attributes. The conflict is with the USWDS Grid plugin, which we've chosen not to enable -- it also allows divs with "data-*" (that is, any data- attribute). But we don't want the behavior of that plugin! And since it's supplied in a module that offers multiple plugins, we can't simply disable or uninstall it. | ||
|
||
There's probably more than one active bug report about this, but this is the one I found, and specifically, the comment suggesting the workaround used here: https://www.drupal.org/project/drupal/issues/3410100#comment-15457015 | ||
|
7 changes: 7 additions & 0 deletions
7
...stom/usagov_ckeditor5_source_editing_fixup/usagov_ckeditor5_source_editing_fixup.info.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: 'USAGov CKEditor5 Source Editing Fixup' | ||
type: module | ||
description: 'Remove restrictions around elements that can be added for Source Editing mode' | ||
core_version_requirement: ^9 || ^10 | ||
package: USAgov | ||
dependencies: | ||
- drupal:ckeditor5 |
14 changes: 14 additions & 0 deletions
14
...custom/usagov_ckeditor5_source_editing_fixup/usagov_ckeditor5_source_editing_fixup.module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
/** | ||
* Implements hook_config_schema_info_alter(). | ||
* | ||
* This enables us to add elements to the "Source Editing" elements of a | ||
* CKEditor5 editor configuration, even if a disabled plugin would also supply them. | ||
* See https://www.drupal.org/project/drupal/issues/3410100#comment-15457015 | ||
*/ | ||
function usagov_ckeditor5_source_editing_fixup_config_schema_info_alter(&$definitions) { | ||
if (isset($definitions['ckeditor5.plugin.ckeditor5_sourceEditing'])) { | ||
unset($definitions['ckeditor5.plugin.ckeditor5_sourceEditing']['mapping']['allowed_tags']['sequence']['constraints']['SourceEditingRedundantTags']); | ||
} | ||
} |
144 changes: 75 additions & 69 deletions
144
web/themes/custom/usagov/scripts/callCenterWaitTimeLookup.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,88 @@ | ||
jQuery(document).ready(async function () { | ||
"use strict"; | ||
|
||
var waittime = (function() { | ||
if (jQuery("html[lang|='en']").length || | ||
jQuery("html[lang|='es']").length) { | ||
jQuery.ajax({ | ||
"url": "https://s3-us-gov-west-1.amazonaws.com/cg-4d6fb302-315f-403e-a96e-a7563ccddd3d/1.0/waittime.json", | ||
"type": "GET", | ||
"success": function (response) { | ||
var json = jQuery.parseJSON(response); | ||
var seconds = -1; | ||
function checkPagePath() { | ||
if ( | ||
window.location.pathname === "/phone" || | ||
window.location.pathname === "/es/llamenos" || | ||
window.location.pathname === "/chat" || | ||
window.location.pathname === "/es/chat" | ||
) { | ||
return true; | ||
} | ||
} | ||
|
||
if (jQuery("html[lang|='en']").length) { | ||
seconds = json.enEstimatedWaitTimeSeconds; | ||
} | ||
if (jQuery("html[lang|='es']").length) { | ||
seconds = json.spEstimatedWaitTimeSeconds; | ||
} | ||
function getCallCenterWaitTime() { | ||
let jsonSeconds; | ||
let jsonTimestamp; | ||
jQuery.ajax({ | ||
"url": "https://s3-us-gov-west-1.amazonaws.com/cg-4d6fb302-315f-403e-a96e-a7563ccddd3d/1.0/waittime.json", | ||
"type": "GET", | ||
"dataType": "json", | ||
"success": function (response) { | ||
if (window.location.pathname === "/phone") { | ||
jsonSeconds = response.call.estimatedWaitTimeSeconds.en; | ||
} | ||
else if (window.location.pathname === "/es/llamenos") { | ||
jsonSeconds = response.call.estimatedWaitTimeSeconds.sp; | ||
} | ||
else if (window.location.pathname === "/chat") { | ||
jsonSeconds = response.chat.estimatedWaitTimeSeconds.en; | ||
} | ||
else if (window.location.pathname === "/es/chat") { | ||
jsonSeconds = response.chat.estimatedWaitTimeSeconds.sp; | ||
} | ||
|
||
if (seconds >= 0) { | ||
var minutes = Math.floor(seconds / 60); | ||
var remainingMinutes = minutes % 60; | ||
seconds = seconds - (minutes * 60); | ||
var content = "Estimated wait time: "; | ||
var secondsText = " second"; | ||
var minuteText = " minute"; | ||
var noneText = "None"; | ||
jsonTimestamp = response.timestamp; | ||
createDisplayWaitTime(jsonSeconds, jsonTimestamp); | ||
}, | ||
"error": function (xhr, status, error) { | ||
console.log(error); | ||
}, | ||
}); | ||
} | ||
|
||
if (jQuery("html[lang|='es']").length) { | ||
content = "Tiempo de espera estimado: "; | ||
secondsText = " segundo"; | ||
minuteText = " minuto"; | ||
noneText = "Ninguno"; | ||
} | ||
function checkTimeStamp(timestamp) { | ||
let timeOfEstimate = timestamp ? timestamp : 0; | ||
if (Date.now() / 1000 - timeOfEstimate < 600) { | ||
return true; | ||
} | ||
} | ||
|
||
if (remainingMinutes > 0) { | ||
content += remainingMinutes + minuteText; | ||
if (remainingMinutes > 1) { | ||
content += "s"; | ||
} | ||
} | ||
function createDisplayWaitTime(actualSeconds, timestamp) { | ||
// If the estimated time was captured over 10 minutes ago, remain silent. | ||
if (checkTimeStamp(timestamp)) { | ||
let displayTime; | ||
if (actualSeconds !== -1) { | ||
if (actualSeconds < 60) { | ||
displayTime = 1; | ||
} | ||
else { | ||
displayTime = Math.round(actualSeconds / 60); | ||
} | ||
displayWaitTime(displayTime); | ||
} | ||
} | ||
} | ||
|
||
if (seconds > 0) { | ||
if (remainingMinutes > 0) { | ||
content += ", "; | ||
} | ||
content += seconds + secondsText; | ||
if (seconds > 1) { | ||
content += "s"; | ||
} | ||
} | ||
function displayWaitTime(displayTime) { | ||
let docLang = [document.documentElement.lang]; | ||
|
||
if (minutes === 0 && seconds === 0) { | ||
content = content + noneText; | ||
} | ||
let plural = displayTime > 1; | ||
const plurals = plural ? "s" : ""; | ||
|
||
// If the estimated time was captured over 10 minutes ago, remain silent. | ||
var timeOfEstimate = json.timestamp ? json.timestamp : 0; | ||
if (Date.now()/1000 - timeOfEstimate > 600) { | ||
content = ""; | ||
} | ||
const displayText = | ||
docLang[0] === "es" | ||
? `El tiempo aproximado de espera es <strong>${displayTime} minuto${plurals}</strong>.` | ||
: `The current estimated wait time is <strong>${displayTime} minute${plurals}</strong>.`; | ||
|
||
jQuery('#callCenterTime').html(content); | ||
} | ||
}, | ||
"error": function (xhr, status, error) { | ||
console.log('fail'); | ||
console.log(error); | ||
jQuery('#callCenterTime').html(error); | ||
} | ||
}); | ||
} | ||
}); | ||
jQuery('div[data-call-wait="showTime"]').replaceWith( | ||
`<div class="paragraph paragraph--type--uswds-alert paragraph--view-mode--embed paragraph--id--2485 usa-alert usa-alert--slim usa-alert--no-icon" data-call-wait='showTime'><div class="usa-alert__body"> <div class="field field--name-field-alert-body field--type-text field--label-hidden field__item">${displayText}</div> </div> </div>` | ||
); | ||
} | ||
|
||
if (jQuery('#callCenterTime').length > 0) { | ||
waittime(); | ||
setInterval(function() { | ||
waittime(); | ||
}, 60 * 1000); | ||
// upgrade: only apply to phone pages using Drupal library in usagov.libraries.yml | ||
if (checkPagePath()) { | ||
getCallCenterWaitTime(); | ||
} | ||
}); | ||
}); |