Skip to content
This repository has been archived by the owner on Nov 10, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3496 from staceymosier/RHDX-221--webinar-countdown
Browse files Browse the repository at this point in the history
[RHDX-221] Add webinar countdown component
  • Loading branch information
staceymosier committed Feb 28, 2020
2 parents 3265aaa + 717906a commit c8678f4
Show file tree
Hide file tree
Showing 23 changed files with 360 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ dependencies:
- field.field.assembly.call_to_action.field_background_image
- field.field.assembly.call_to_action.field_cta_content
- field.field.assembly.call_to_action.field_cta_link
- field.field.assembly.call_to_action.field_display_cta_timer
- field.field.assembly.call_to_action.field_display_cta_timer_label
- field.field.assembly.call_to_action.field_navigation_title
- field.field.assembly.call_to_action.field_title
- image.style.thumbnail
module:
- datetime
- field_layout
- image
- layout_discovery
Expand Down Expand Up @@ -56,6 +59,20 @@ content:
third_party_settings: { }
type: link_default
region: content
field_display_cta_timer:
weight: 26
settings: { }
third_party_settings: { }
type: datetime_default
region: content
field_display_cta_timer_label:
weight: 27
settings:
size: 60
placeholder: ''
third_party_settings: { }
type: string_textfield
region: content
field_navigation_title:
weight: 4
settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ dependencies:
- field.field.assembly.call_to_action.field_background_image
- field.field.assembly.call_to_action.field_cta_content
- field.field.assembly.call_to_action.field_cta_link
- field.field.assembly.call_to_action.field_display_cta_timer
- field.field.assembly.call_to_action.field_display_cta_timer_label
- field.field.assembly.call_to_action.field_navigation_title
- field.field.assembly.call_to_action.field_title
module:
- datetime
- fences
- field_layout
- layout_discovery
Expand Down Expand Up @@ -59,6 +62,30 @@ content:
fences_label_classes: ''
type: link_class
region: content
field_display_cta_timer:
type: datetime_default
weight: 4
region: content
label: hidden
settings:
timezone_override: UTC
format_type: html_datetime
third_party_settings:
fences:
fences_field_tag: div
fences_field_classes: ''
fences_field_item_tag: div
fences_field_item_classes: ''
fences_label_tag: div
fences_label_classes: ''
field_display_cta_timer_label:
type: string
weight: 3
region: content
label: hidden
settings:
link_to_entity: false
third_party_settings: { }
field_title:
weight: 0
label: hidden
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
uuid: abc3e596-dc3d-4416-af44-b4c2d748de80
langcode: en
status: true
dependencies:
config:
- assembly.assembly_type.call_to_action
- field.storage.assembly.field_display_cta_timer
module:
- datetime
id: assembly.call_to_action.field_display_cta_timer
field_name: field_display_cta_timer
entity_type: assembly
bundle: call_to_action
label: 'Display CTA Timer'
description: 'Provide a datetime (EST / GMT-05:00) if you would like to hide a CTA button and display a countdown/timer ex. preceding an event like a webinar. Once this datetime has been reached, the countdown/timer will be hidden and the CTA will display.'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: datetime
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
uuid: 429a703a-d938-4fb5-9879-49272548e331
langcode: en
status: true
dependencies:
config:
- assembly.assembly_type.call_to_action
- field.storage.assembly.field_display_cta_timer_label
id: assembly.call_to_action.field_display_cta_timer_label
field_name: field_display_cta_timer_label
entity_type: assembly
bundle: call_to_action
label: 'Display CTA Timer Label'
description: 'This text will display over the timer/countdown component ex. "Event starting in...", "Event coming soon", "Webinar available in...", etc.'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
uuid: d5085b7f-c3a5-4f59-a71f-29aaca3e38b1
langcode: en
status: true
dependencies:
module:
- assembly
- datetime
id: assembly.field_display_cta_timer
field_name: field_display_cta_timer
entity_type: assembly
type: datetime
settings:
datetime_type: datetime
module: datetime
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
uuid: 3e8cc0df-e8e0-4f71-9ff3-1a14a27b7e6a
langcode: en
status: true
dependencies:
module:
- assembly
id: assembly.field_display_cta_timer_label
field_name: field_display_cta_timer_label
entity_type: assembly
type: string
settings:
max_length: 255
is_ascii: false
case_sensitive: false
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @file
* Javascript Countdown Component
* Provides a countdown to reveal the call to action.
* Also see https://codepen.io/SitePoint/pen/MwNPVq,
* https://www.techrepublic.com/article/convert-the-local-time-to-another-time-zone-with-this-javascript/
*/

(function ($, Drupal) {

function toggleCountdownAndCTA(clock) {
$(clock).next().removeClass('hide');
$(clock).addClass('hide');
}

function getTimeRemaining(countdownDate) {
var now = new Date().toLocaleString('en-US', {timeZone: 'America/New_York'});
var countdownDateObj = new Date(countdownDate);

var t = Date.parse(countdownDateObj) - Date.parse(now);
var seconds = Math.floor((t / 1000) % 60);
var minutes = Math.floor((t / 1000 / 60) % 60);
var hours = Math.floor((t / (1000 * 60 * 60)) % 24);
var days = Math.floor(t / (1000 * 60 * 60 * 24));
return {
'total': t,
'days': days,
'hours': hours,
'minutes': minutes,
'seconds': seconds
};
}

function initializeClock(clock, countdownDate) {
var daysSpan = clock.find('.days span');
var hoursSpan = clock.find('.hours span');
var minutesSpan = clock.find('.minutes span');
var secondsSpan = clock.find('.seconds span');

function updateClock(clock) {
var t = getTimeRemaining(countdownDate);
daysSpan.html(t.days);
hoursSpan.html(('0' + t.hours).slice(-2));
minutesSpan.html(('0' + t.minutes).slice(-2));
secondsSpan.html(('0' + t.seconds).slice(-2));

if (t.total <= 0) {
clearInterval(timeinterval);
toggleCountdownAndCTA(clock);
}
}

updateClock(clock);
var timeinterval = setInterval(updateClock, 1000, clock);
}

Drupal.behaviors.rhd_CtaCountdown = {
attach: function (context, settings) {
$('.assembly-type-call_to_action.has-countdown', context).once('rhdCTACountdown').each(function (){
var clock = $('.rhd-c-countdown', $(this));
var countdownDate = settings.rhd_assemblies.countdown_date;
var startingOffsetTime = getTimeRemaining(countdownDate);

if (startingOffsetTime.total == 0) {
toggleCountdownAndCTA(clock);
} else {
$(clock).removeClass('hide');
initializeClock( clock, countdownDate);
}
});
}
}

})(jQuery, Drupal);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
countdown:
version: VERSION
js:
js/countdown.js: {}
dependencies:
- core/jquery
- core/jquery.once
- core/drupal
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,28 @@ function rhd_assemblies_entity_presave(EntityInterface $entity) {
* Implements hook_preprocess_assembly().
*/
function rhd_assemblies_preprocess_assembly(&$variables) {
// Retrieve the parent entity of this assembly.
$assembly = $variables['elements']['#assembly'];
$parent = $variables['elements']['#parent'];
$type = $assembly->bundle();

if ($parent) {
// Make assembly ID match pattern used for on page navigation.
$id = $variables['elements']['#assembly']->id();
$css_id = Html::cleanCssIdentifier('assembly-' . $parent['field_name'] . '-' . $id);
$variables['attributes']->offsetSet('id', $css_id);
}

// Call to Action Countdown Component.
if ($assembly->hasField('field_display_cta_timer')) {
$cta_timer = $assembly->get('field_display_cta_timer')->value;

if ($cta_timer) {
$variables['attributes']['class'][] = 'has-countdown';
$variables['has_countdown'] = TRUE;
$variables['#attached']['library'][] = 'rhd_assemblies/countdown';
$variables['#attached']['drupalSettings']['rhd_assemblies']['countdown_date'] = $cta_timer;
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@import "components/buttons";
@import "components/cards";
@import "components/code-snippet";
@import "components/countdown";
@import "components/curated-products";
@import "components/divider";
@import "components/curated-links";
Expand All @@ -54,7 +55,6 @@
@import "components/pager";
@import "components/topic-page";
@import "components/cta-form";
@import "components/rich-text-columns";
@import "components/featured-evangelists";
@import "components/rhd-top-nav";
@import "components/nav-search";
Expand Down Expand Up @@ -87,5 +87,5 @@
// Final theme overrides
@import "rhd-global-styles";

// Drupal Admin specific overrides
// Drupal Admin specific overrides
@import "rhd-drupal-admin-overrides";
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
color: var(--pfe-theme--color--text--on-dark, $white);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
@import "../mixins";

.component {
&.assembly-type-call_to_action {
background-color: var(--rhd-theme--ui-background-dark--light-blue);
@include with-background-padding;

.cta__container {
text-align: center;
color: #FFFFFF;
}

.cta__title,
.cta__content {
color: #FFFFFF;
// @to-do: This is applied without hte .dark classname; Is this assembly always dark?
color: var(--rhd-theme--component-font--color-light);
}

.cta__title,
.cta__content {
// @to-do: This is applied without hte .dark classname; Is this assembly always dark?
color: var(--rhd-theme--component-font--color-light);
margin-bottom: var(--rhd-theme--container-spacer-md);
}

&.left {
float: none !important;
text-align: left;

.cta__title,
.cta__content,
.cta__cta {
text-align: left;
}
}
&.dark {
background-color: #242424;
background-color: var(--rhd-theme--component-background--color-dark);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}
}

// OTHER VISUAL STYLES

.rhd-c-card-grid {

&.centered {
Expand All @@ -53,22 +53,5 @@
.rhd-c-card:last-of-type {margin-right: var(--pf-l-flex--spacer--lg);}
}
}

&.dark {
background: #252525;

.pf-c-title {
color: #FFF;
}

.rhd-c-card-grid__cta a,
.rhd-c-card-grid__cta button{
@extend .pf-m-secondary-on-dark;
&::after {
border: 1px solid var(--rhd-c-button--m-secondary-alt-dark--BorderColor);
}
}
}

}

Loading

0 comments on commit c8678f4

Please sign in to comment.