Skip to content

Commit

Permalink
improvement: Added new javascript event to that fires every time a no…
Browse files Browse the repository at this point in the history
…tice is displayed

improvement: Added class to courier notice for gform-confirmation
improvement: Added new Notice Meta for gform-confirmation
  • Loading branch information
aaronware committed Oct 15, 2020
1 parent 7041885 commit bdb4bf9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
8 changes: 7 additions & 1 deletion assets/js/frontend/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,14 @@ export default function core() {
$( '.courier-notices[data-courier-placement="' + settings.placement + '"]' )
.append( $notice );

$notice.slideDown( 'fast' );
$notice.slideDown( 'fast', 'swing', function() {
const event = new CustomEvent( 'courierNoticeDisplayed', { detail: index });

document.dispatchEvent(event);
});
} );


}
} );

Expand Down
7 changes: 6 additions & 1 deletion js/courier-notices.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions src/Controller/Courier_REST_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public function display_notices( WP_REST_Request $request ) {
'include_dismissed' => false,
'prioritize_persistent_global' => true,
'ids_only' => false,
'number' => 4,
'number' => 4, // @todo this should be a setting.
'placement' => 'header',
'query_args' => array(),
);
Expand All @@ -220,9 +220,12 @@ public function display_notices( WP_REST_Request $request ) {
$notices = array();

foreach ( $notice_posts as $courier_notice ) {
$notice_data = $notices_data->get_notice_meta( $courier_notice->ID );
$notice = new View();
$post_classes = 'courier-notice courier_notice alert alert-box courier_type-' . $notice_data['type'][0]->slug;
$notice_data = $notices_data->get_notice_meta( $courier_notice->ID );
$notice = new View();
$post_classes = array( 'courier-notice courier_notice alert alert-box' );
$post_classes[] = 'courier_type-' . $notice_data['type'][0]->slug;
$post_classes[] = $notice_data['is_confirmation'] ? 'gform-confirmation' : '';

$notice->assign( 'notice_id', $courier_notice->ID );
$notice->assign( 'show_hide_title', $notice_data['show_hide_title'] );

Expand Down
2 changes: 1 addition & 1 deletion src/Helper/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function courier_notices_add_notice( $notice = '', $types = array( 'Informationa
update_post_meta( $notice_id, '_courier_dismissible', 1 );
}

return true;
return $notice_id;
} else {
return false;
}
Expand Down
5 changes: 1 addition & 4 deletions src/Model/Courier_Notice/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@ public function get_notices( $args = array(), $ajax_post_data = array() ) {

$post_list = array_merge( $global_posts, $global_dismissible_posts );

Utils::courier_notices_debug_log( $post_list, 'Query', false );

// Prioritize Persistent Global Notes to the top by getting them separately and putting them at the front of the line.
if ( true === $args['prioritize_persistent_global'] ) {
$persistent_global = $this->get_persistent_global_notices(
Expand Down Expand Up @@ -345,8 +343,6 @@ public function get_notices( $args = array(), $ajax_post_data = array() ) {
$query_args = wp_parse_args( $args, $query_args );
$final_notices_query = new \WP_Query( $query_args );

Utils::courier_notices_debug_log( $final_notices_query, 'Query', false );

return ( $final_notices_query->have_posts() ) ? $final_notices_query->posts : array();
}

Expand Down Expand Up @@ -505,6 +501,7 @@ public function get_notice_meta( int $courier_notice_id ) {
'style' => $courier_style,
'type' => $courier_type,
'icon' => $courier_icon,
'is_confirmation' => has_term( 'gform-confirmation', 'courier_visibility_rules', $courier_notice_id ),
);

return apply_filters( 'courier_notices_notice_meta', $notices_meta );
Expand Down

0 comments on commit bdb4bf9

Please sign in to comment.