Skip to content
Snippets Groups Projects
Commit cbeb37c6 authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

Merge branch 'master' into 'feature/gutenberg'

feat(js): added support for gutenberg

See merge request wpdesk/wp-notice!19
parents 73496eac ac30ace4
No related branches found
No related tags found
1 merge request!20Feature/gutenberg
Pipeline #10806 passed with stages
in 2 minutes and 7 seconds
jQuery( document ).ready(function() {
jQuery('.wpdesk').each(function( index ) {
var classList = jQuery(this).attr('class').split(/\s+/);
var type = '';
jQuery.each(classList, function(index, item) {
if (item.startsWith('notice-')) {
type = item.replace('notice-','');
}
});
content = this.innerText;
actions = [];
jQuery.each(jQuery(this).find('a'), function(index, item) {
text = item.innerText;
actions.push({
url: item.href,
label: text.charAt(0).toUpperCase() + text.slice(1),
});
});
isDismiss = jQuery(this).hasClass('is-dismissible');
window.wp.data.dispatch( 'core/notices' ).createNotice(
type,
content,
{
isDismissible: isDismiss,
actions: actions
}
);
});
} );
...@@ -83,6 +83,18 @@ class Notice ...@@ -83,6 +83,18 @@ class Notice
$this->addAction(); $this->addAction();
} }
/**
* @return bool
*/
public function isBlockEditor()
{
if ( !function_exists( 'get_current_screen' ) ) {
require_once ABSPATH . '/wp-admin/includes/screen.php';
}
return \get_current_screen()->is_block_editor();
}
/** /**
* @return string * @return string
*/ */
...@@ -163,6 +175,7 @@ class Notice ...@@ -163,6 +175,7 @@ class Notice
[$this, 'showNotice'], [$this, 'showNotice'],
self::ADMIN_FOOTER_BASE_PRIORITY + intval($this->priority) self::ADMIN_FOOTER_BASE_PRIORITY + intval($this->priority)
); );
add_action('admin_head', [$this,'addGutenbergScript']);
$this->actionAdded = true; $this->actionAdded = true;
} }
} }
...@@ -183,6 +196,16 @@ class Notice ...@@ -183,6 +196,16 @@ class Notice
} }
} }
/**
* Enqueue admin scripts.
*/
public function addGutenbergScript()
{
if ($this->isBlockEditor()) {
include_once 'views/admin-head-js-gutenberg.php';
}
}
/** /**
* Add attribute. * Add attribute.
* *
...@@ -202,9 +225,9 @@ class Notice ...@@ -202,9 +225,9 @@ class Notice
protected function getNoticeClass() protected function getNoticeClass()
{ {
if ('updated' === $this->noticeType) { if ('updated' === $this->noticeType) {
$notice_class = 'notice ' . $this->noticeType; $notice_class = 'wpdesk notice ' . $this->noticeType;
} else { } else {
$notice_class = 'notice notice-' . $this->noticeType; $notice_class = 'wpdesk notice notice-' . $this->noticeType;
} }
if ($this->dismissible) { if ($this->dismissible) {
$notice_class .= ' is-dismissible'; $notice_class .= ' is-dismissible';
......
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
?>
<script type="text/javascript">
<?php include dirname(__FILE__) . '/../../../../assets/js/gutenberg.js'; ?>
</script>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment