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

feature(js): support for gutenberg

parent 64c38af5
No related branches found
No related tags found
1 merge request!20Feature/gutenberg
Pipeline #10873 passed
jQuery( document ).ready(function() { jQuery( document ).ready(function() {
jQuery('.wpdesk').each(function( index ) { jQuery('.wpdesk-notice-gutenberg').each(function( index ) {
var classList = jQuery(this).attr('class').split(/\s+/); var classList = jQuery(this).attr('class').split(/\s+/);
var type = ''; var type = '';
jQuery.each(classList, function(index, item) { jQuery.each(classList, function(index, item) {
......
...@@ -58,6 +58,12 @@ class Notice ...@@ -58,6 +58,12 @@ class Notice
*/ */
protected $attributes = array(); protected $attributes = array();
/**
* Show notice in gutenberg editor.
*
* @var bool
*/
protected $showInGutenberg = false;
/** /**
* WPDesk_Flexible_Shipping_Notice constructor. * WPDesk_Flexible_Shipping_Notice constructor.
...@@ -67,19 +73,22 @@ class Notice ...@@ -67,19 +73,22 @@ class Notice
* @param bool $dismissible Is dismissible. * @param bool $dismissible Is dismissible.
* @param int $priority Notice priority. * @param int $priority Notice priority.
* @param array $attributes Attributes. * @param array $attributes Attributes.
* @param bool $showInGutenberg Show notice in gutenberg editor.
*/ */
public function __construct( public function __construct(
$noticeContent, $noticeContent,
$noticeType = 'info', $noticeType = 'info',
$dismissible = false, $dismissible = false,
$priority = 10, $priority = 10,
$attributes = array() $attributes = array(),
$showInGutenberg = false
) { ) {
$this->noticeContent = $noticeContent; $this->noticeContent = $noticeContent;
$this->noticeType = $noticeType; $this->noticeType = $noticeType;
$this->dismissible = $dismissible; $this->dismissible = $dismissible;
$this->priority = $priority; $this->priority = $priority;
$this->attributes = $attributes; $this->attributes = $attributes;
$this->showInGutenberg = $showInGutenberg;
$this->addAction(); $this->addAction();
} }
...@@ -225,9 +234,9 @@ class Notice ...@@ -225,9 +234,9 @@ class Notice
protected function getNoticeClass() protected function getNoticeClass()
{ {
if ('updated' === $this->noticeType) { if ('updated' === $this->noticeType) {
$notice_class = 'wpdesk notice ' . $this->noticeType; $notice_class = 'notice ' . $this->noticeType;
} else { } else {
$notice_class = 'wpdesk notice notice-' . $this->noticeType; $notice_class = 'notice notice-' . $this->noticeType;
} }
if ($this->dismissible) { if ($this->dismissible) {
$notice_class .= ' is-dismissible'; $notice_class .= ' is-dismissible';
...@@ -235,6 +244,9 @@ class Notice ...@@ -235,6 +244,9 @@ class Notice
if (isset($this->attributes['class'])) { if (isset($this->attributes['class'])) {
$notice_class .= ' ' . $this->attributes['class']; $notice_class .= ' ' . $this->attributes['class'];
} }
if ($this->showInGutenberg) {
$notice_class .= 'wpdesk-notice-gutenberg';
}
return $notice_class; return $notice_class;
} }
......
...@@ -32,15 +32,17 @@ class PermanentDismissibleNotice extends Notice ...@@ -32,15 +32,17 @@ class PermanentDismissibleNotice extends Notice
* @param string $noticeType Notice type. * @param string $noticeType Notice type.
* @param int $priority Priority * @param int $priority Priority
* @param array $attributes Attributes. * @param array $attributes Attributes.
* @param bool $showInGutenberg Show notice in gutenberg editor.
*/ */
public function __construct( public function __construct(
$noticeContent, $noticeContent,
$noticeName, $noticeName,
$noticeType = 'info', $noticeType = 'info',
$priority = 10, $priority = 10,
$attributes = array() $attributes = array(),
$showInGutenberg = false
) { ) {
parent::__construct($noticeContent, $noticeType, true, $priority, $attributes); parent::__construct($noticeContent, $noticeType, true, $priority, $attributes, $showInGutenberg);
$this->noticeName = $noticeName; $this->noticeName = $noticeName;
$this->noticeDismissOptionName = static::OPTION_NAME_PREFIX . $noticeName; $this->noticeDismissOptionName = static::OPTION_NAME_PREFIX . $noticeName;
if (self::OPTION_VALUE_DISMISSED === get_option($this->noticeDismissOptionName, '')) { if (self::OPTION_VALUE_DISMISSED === get_option($this->noticeDismissOptionName, '')) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment