You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

336 lines
41 KiB
JavaScript

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/* global wpforms_edit_post_education */
/**
* WPForms Edit Post Education function.
*
* @since 1.8.1
*/
'use strict';
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var WPFormsEditPostEducation = window.WPFormsEditPostEducation || function (document, window, $) {
/**
* Public functions and properties.
*
* @since 1.8.1
*
* @type {object}
*/
var app = {
/**
* Determine if the notice was showed before.
*
* @since 1.8.1
*/
isNoticeVisible: false,
/**
* Start the engine.
*
* @since 1.8.1
*/
init: function init() {
$(window).on('load', function () {
// In the case of jQuery 3.+, we need to wait for a ready event first.
if (typeof $.ready.then === 'function') {
$.ready.then(app.load);
} else {
app.load();
}
});
},
/**
* Page load.
*
* @since 1.8.1
*/
load: function load() {
if (!app.isGutenbergEditor()) {
app.maybeShowClassicNotice();
app.bindClassicEvents();
return;
}
var blockLoadedInterval = setInterval(function () {
if (!document.querySelector('.editor-post-title__input, iframe[name="editor-canvas"]')) {
return;
}
clearInterval(blockLoadedInterval);
if (!app.isFse()) {
app.maybeShowGutenbergNotice();
app.bindGutenbergEvents();
return;
}
var iframe = document.querySelector('iframe[name="editor-canvas"]');
var observer = new MutationObserver(function () {
var iframeDocument = iframe.contentDocument || iframe.contentWindow.document || {};
if (iframeDocument.readyState === 'complete' && iframeDocument.querySelector('.editor-post-title__input')) {
app.maybeShowGutenbergNotice();
app.bindFseEvents();
observer.disconnect();
}
});
observer.observe(document.body, {
subtree: true,
childList: true
});
}, 200);
},
/**
* Bind events for Classic Editor.
*
* @since 1.8.1
*/
bindClassicEvents: function bindClassicEvents() {
var $document = $(document);
if (!app.isNoticeVisible) {
$document.on('input', '#title', app.maybeShowClassicNotice);
}
$document.on('click', '.wpforms-edit-post-education-notice-close', app.closeNotice);
},
/**
* Bind events for Gutenberg Editor.
*
* @since 1.8.1
*/
bindGutenbergEvents: function bindGutenbergEvents() {
var $document = $(document);
$document.on('DOMSubtreeModified', '.edit-post-layout', app.distractionFreeModeToggle);
if (app.isNoticeVisible) {
return;
}
$document.on('input', '.editor-post-title__input', app.maybeShowGutenbergNotice).on('DOMSubtreeModified', '.editor-post-title__input', app.maybeShowGutenbergNotice);
},
/**
* Bind events for Gutenberg Editor in FSE mode.
*
* @since 1.8.1
*/
bindFseEvents: function bindFseEvents() {
var $iframe = $('iframe[name="editor-canvas"]');
$(document).on('DOMSubtreeModified', '.edit-post-layout', app.distractionFreeModeToggle);
$iframe.contents().on('DOMSubtreeModified', '.editor-post-title__input', app.maybeShowGutenbergNotice);
},
/**
* Determine if the editor is Gutenberg.
*
* @since 1.8.1
*
* @returns {boolean} True if the editor is Gutenberg.
*/
isGutenbergEditor: function isGutenbergEditor() {
return typeof wp !== 'undefined' && typeof wp.blocks !== 'undefined';
},
/**
* Determine if the editor is Gutenberg in FSE mode.
*
* @since 1.8.1
*
* @returns {boolean} True if the Gutenberg editor in FSE mode.
*/
isFse: function isFse() {
return Boolean($('iframe[name="editor-canvas"]').length);
},
/**
* Create a notice for Gutenberg.
*
* @since 1.8.1
*/
showGutenbergNotice: function showGutenbergNotice() {
wp.data.dispatch('core/notices').createInfoNotice(wpforms_edit_post_education.gutenberg_notice.template, app.getGutenbergNoticeSettings());
// The notice component doesn't have a way to add HTML id or class to the notice.
// Also, the notice became visible with a delay on old Gutenberg versions.
var hasNotice = setInterval(function () {
var noticeBody = $('.wpforms-edit-post-education-notice-body');
if (!noticeBody.length) {
return;
}
var $notice = noticeBody.closest('.components-notice');
$notice.addClass('wpforms-edit-post-education-notice');
$notice.find('.is-secondary, .is-link').removeClass('is-secondary').removeClass('is-link').addClass('is-primary');
clearInterval(hasNotice);
}, 100);
},
/**
* Get settings for the Gutenberg notice.
*
* @since 1.8.1
*
* @returns {object} Notice settings.
*/
getGutenbergNoticeSettings: function getGutenbergNoticeSettings() {
var pluginName = 'wpforms-edit-post-product-education-guide';
var noticeSettings = {
id: pluginName,
isDismissible: true,
HTML: true,
__unstableHTML: true,
actions: [{
className: 'wpforms-edit-post-education-notice-guide-button',
variant: 'primary',
label: wpforms_edit_post_education.gutenberg_notice.button
}]
};
if (!wpforms_edit_post_education.gutenberg_guide) {
noticeSettings.actions[0].url = wpforms_edit_post_education.gutenberg_notice.url;
return noticeSettings;
}
var Guide = wp.components.Guide;
var useState = wp.element.useState;
var registerPlugin = wp.plugins.registerPlugin;
var unregisterPlugin = wp.plugins.unregisterPlugin;
var GutenbergTutorial = function GutenbergTutorial() {
var _useState = useState(true),
_useState2 = _slicedToArray(_useState, 2),
isOpen = _useState2[0],
setIsOpen = _useState2[1];
if (!isOpen) {
return null;
}
return (
/*#__PURE__*/
// eslint-disable-next-line react/react-in-jsx-scope
React.createElement(Guide, {
className: "edit-post-welcome-guide",
onFinish: function onFinish() {
unregisterPlugin(pluginName);
setIsOpen(false);
},
pages: app.getGuidePages()
})
);
};
noticeSettings.onDismiss = app.updateUserMeta;
noticeSettings.actions[0].onClick = function () {
return registerPlugin(pluginName, {
render: GutenbergTutorial
});
};
return noticeSettings;
},
/**
* Get Guide pages in proper format.
*
* @since 1.8.1
*
* @returns {Array} Guide Pages.
*/
getGuidePages: function getGuidePages() {
var pages = [];
wpforms_edit_post_education.gutenberg_guide.forEach(function (page) {
pages.push({
/* eslint-disable react/react-in-jsx-scope */
content: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("h1", {
className: "edit-post-welcome-guide__heading"
}, page.title), /*#__PURE__*/React.createElement("p", {
className: "edit-post-welcome-guide__text"
}, page.content)),
image: /*#__PURE__*/React.createElement("img", {
className: "edit-post-welcome-guide__image",
src: page.image,
alt: page.title
})
/* eslint-enable react/react-in-jsx-scope */
});
});
return pages;
},
/**
* Show notice if the page title matches some keywords for Classic Editor.
*
* @since 1.8.1
*/
maybeShowClassicNotice: function maybeShowClassicNotice() {
if (app.isNoticeVisible) {
return;
}
if (app.isTitleMatchKeywords($('#title').val())) {
app.isNoticeVisible = true;
$('.wpforms-edit-post-education-notice').removeClass('wpforms-hidden');
}
},
/**
* Show notice if the page title matches some keywords for Gutenberg Editor.
*
* @since 1.8.1
*/
maybeShowGutenbergNotice: function maybeShowGutenbergNotice() {
if (app.isNoticeVisible) {
return;
}
var $postTitle = app.isFse() ? $('iframe[name="editor-canvas"]').contents().find('.editor-post-title__input') : $('.editor-post-title__input');
var tagName = $postTitle.prop('tagName');
var title = tagName === 'TEXTAREA' ? $postTitle.val() : $postTitle.text();
if (app.isTitleMatchKeywords(title)) {
app.isNoticeVisible = true;
app.showGutenbergNotice();
}
},
/**
* Add notice class when the distraction mode is enabled.
*
* @since 1.8.1.2
*/
distractionFreeModeToggle: function distractionFreeModeToggle() {
if (!app.isNoticeVisible) {
return;
}
var $document = $(document);
var isDistractionFreeMode = Boolean($document.find('.is-distraction-free').length);
if (!isDistractionFreeMode) {
return;
}
var isNoticeHasClass = Boolean($('.wpforms-edit-post-education-notice').length);
if (isNoticeHasClass) {
return;
}
var $noticeBody = $document.find('.wpforms-edit-post-education-notice-body');
var $notice = $noticeBody.closest('.components-notice');
$notice.addClass('wpforms-edit-post-education-notice');
},
/**
* Determine if the title matches keywords.
*
* @since 1.8.1
*
* @param {string} titleValue Page title value.
*
* @returns {boolean} True if the title matches some keywords.
*/
isTitleMatchKeywords: function isTitleMatchKeywords(titleValue) {
var expectedTitleRegex = new RegExp(/\b(contact|form)\b/i);
return expectedTitleRegex.test(titleValue);
},
/**
* Close a notice.
*
* @since 1.8.1
*/
closeNotice: function closeNotice() {
$(this).closest('.wpforms-edit-post-education-notice').remove();
app.updateUserMeta();
},
/**
* Update user meta and don't show the notice next time.
*
* @since 1.8.1
*/
updateUserMeta: function updateUserMeta() {
$.post(wpforms_edit_post_education.ajax_url, {
action: 'wpforms_education_dismiss',
nonce: wpforms_edit_post_education.education_nonce,
section: 'edit-post-notice'
});
}
};
return app;
}(document, window, jQuery);
WPFormsEditPostEducation.init();
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfc2xpY2VkVG9BcnJheSIsImFyciIsImkiLCJfYXJyYXlXaXRoSG9sZXMiLCJfaXRlcmFibGVUb0FycmF5TGltaXQiLCJfdW5z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