first commit
This commit is contained in:
36
wp-content/plugins/brizy/admin/static/js/cloud.js
Normal file
36
wp-content/plugins/brizy/admin/static/js/cloud.js
Normal file
@@ -0,0 +1,36 @@
|
||||
jQuery(document).ready(function ($) {
|
||||
|
||||
var BrizyCloud = {
|
||||
form: null,
|
||||
pageUrl: null,
|
||||
init: function (form) {
|
||||
BrizyCloud.form = form;
|
||||
BrizyCloud.pageUrl = form.attr('action');
|
||||
form.find('select[name=brizy-cloud-use-container]').on('change', BrizyCloud.containerChange)
|
||||
},
|
||||
containerChange: function (e) {
|
||||
var value = e.target.value;
|
||||
$.ajax({
|
||||
url: Brizy_Admin_Data.url,
|
||||
data: {action: 'brizy-cloud-projects', container: value}
|
||||
}).done(function (response) {
|
||||
var select = BrizyCloud.form
|
||||
.find('select[name=brizy-cloud-use-project]');
|
||||
|
||||
select
|
||||
.find('option[value!=0]')
|
||||
.remove();
|
||||
|
||||
for (var i = 0; i < response.data.length; i++) {
|
||||
select.append('<option value="'+response.data[i].id+'">'+response.data[i].name+'</option>')
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$(function () {
|
||||
BrizyCloud.init($('#cloud-form'));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
137
wp-content/plugins/brizy/admin/static/js/featured-image.js
Normal file
137
wp-content/plugins/brizy/admin/static/js/featured-image.js
Normal file
@@ -0,0 +1,137 @@
|
||||
jQuery(document).ready(function ($) {
|
||||
if (wp.hooks && wp.hooks.addFilter)
|
||||
wp.hooks.addFilter(
|
||||
'editor.PostFeaturedImage',
|
||||
'brizy/featuredImage',
|
||||
function (originalElement) {
|
||||
return function (origianalProps) {
|
||||
|
||||
var isDragging = false;
|
||||
var el = wp.element.createElement;
|
||||
var x = Brizy_Admin_Data.page.focalPoint.x;
|
||||
var y = Brizy_Admin_Data.page.focalPoint.y;
|
||||
|
||||
if (!origianalProps.media) {
|
||||
return el(originalElement, origianalProps);
|
||||
}
|
||||
|
||||
var clickAndMouseMoveHandler = function ( e ) {
|
||||
|
||||
if ( ! isDragging && e.type !== 'click' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $this = $(e.target);
|
||||
var imageW = $this.width();
|
||||
var imageH = $this.height();
|
||||
var $focalPointX = $('#_thumbnail_focal_point_x');
|
||||
var $focalPointY = $('#_thumbnail_focal_point_y');
|
||||
var $focalPointDiv = $('#_thumbnail_focal_point_div');
|
||||
|
||||
$focalPointDiv.on('mouseup', function () {
|
||||
isDragging = false;
|
||||
});
|
||||
|
||||
if ( window.getSelection ) {
|
||||
window.getSelection().removeAllRanges();
|
||||
} else if ( document.selection ) {
|
||||
document.selection.empty();
|
||||
}
|
||||
|
||||
// Calculate FocusPoint coordinates
|
||||
var offsetX = e.pageX - $this.offset().left;
|
||||
var offsetY = e.pageY - $this.offset().top;
|
||||
|
||||
// Calculate CSS Percentages
|
||||
var percentageX = (offsetX / imageW) * 100;
|
||||
var percentageY = (offsetY / imageH) * 100;
|
||||
|
||||
// Set positioning
|
||||
$focalPointDiv.css({
|
||||
left: percentageX.toFixed(0) + '% ',
|
||||
top: percentageY.toFixed(0) + '%'
|
||||
});
|
||||
$focalPointX.val(percentageX.toFixed(0));
|
||||
$focalPointY.val(percentageY.toFixed(0));
|
||||
|
||||
wp.data.dispatch('core/editor').editPost({
|
||||
'brizy_attachment_focal_point': {
|
||||
x: percentageX.toFixed(0),
|
||||
y: percentageY.toFixed(0)
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
return el('div', {class: 'brizy-featured-image hide-if-no-js'}, [
|
||||
el('input', {
|
||||
id: '_thumbnail_focal_point_x',
|
||||
name: '_thumbnail_focal_point_x',
|
||||
type: 'hidden',
|
||||
value: Brizy_Admin_Data.page.focalPoint.x
|
||||
}),
|
||||
el('input', {
|
||||
id: '_thumbnail_focal_point_y',
|
||||
name: '_thumbnail_focal_point_y',
|
||||
type: 'hidden',
|
||||
value: Brizy_Admin_Data.page.focalPoint.y
|
||||
}),
|
||||
el('div',
|
||||
{
|
||||
class: 'wrapper',
|
||||
onMouseLeave: function () {
|
||||
isDragging = false;
|
||||
}
|
||||
}, [
|
||||
el('img', {
|
||||
id: 'featured-image-el',
|
||||
src: origianalProps.media.source_url,
|
||||
width: "100%",
|
||||
onClick: clickAndMouseMoveHandler,
|
||||
onMouseMove: clickAndMouseMoveHandler,
|
||||
onMouseDown: function () {
|
||||
isDragging = true;
|
||||
},
|
||||
onMouseUp: function () {
|
||||
isDragging = false;
|
||||
}
|
||||
}),
|
||||
|
||||
el('div', {
|
||||
class: 'focal-point',
|
||||
id: '_thumbnail_focal_point_div',
|
||||
style: {left: x + "%", top: y + "%"},
|
||||
onMouseDown: function () {
|
||||
isDragging = true;
|
||||
}
|
||||
}),
|
||||
el('div', {class: 'deleteImage'}, [
|
||||
el('a', {
|
||||
id: 'remove-post-thumbnail', href: "#", onClick: function (e) {
|
||||
origianalProps.onRemoveImage(e);
|
||||
|
||||
Brizy_Admin_Data.page.focalPoint.x = 50;
|
||||
Brizy_Admin_Data.page.focalPoint.y = 50;
|
||||
|
||||
wp.data.dispatch('core/editor').editPost({
|
||||
'brizy_attachment_focal_point': {
|
||||
x: 50,
|
||||
y: 50
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
[
|
||||
el('svg', {class: 'brz-icon-svg'}, [
|
||||
el('use', {'xlinkHref': Brizy_Admin_Data.pluginUrl + '/editor/icons/icons.svg#nc-circle-remove'}),
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
2
wp-content/plugins/brizy/admin/static/js/hyperapp.js
Normal file
2
wp-content/plugins/brizy/admin/static/js/hyperapp.js
Normal file
@@ -0,0 +1,2 @@
|
||||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.hyperapp={})}(this,function(e){"use strict";e.h=function(e,n){for(var t=[],r=[],o=arguments.length;2<o--;)t.push(arguments[o]);for(;t.length;){var u=t.pop();if(u&&u.pop)for(o=u.length;o--;)t.push(u[o]);else null!=u&&!0!==u&&!1!==u&&r.push(u)}return"function"==typeof e?e(n||{},r):{nodeName:e,attributes:n||{},children:r,key:n&&n.key}},e.app=function(e,n,t,r){var o,u=[].map,l=r&&r.children[0]||null,i=l&&function n(e){return{nodeName:e.nodeName.toLowerCase(),attributes:{},children:u.call(e.childNodes,function(e){return 3===e.nodeType?e.nodeValue:n(e)})}}(l),y=[],g=!0,f=b(e),a=function e(r,o,u){for(var n in u)"function"==typeof u[n]?function(e,t){u[e]=function(e){var n=t(e);return"function"==typeof n&&(n=n(v(r,f),u)),n&&n!==(o=v(r,f))&&!n.then&&s(f=d(r,b(o,n),f)),n}}(n,u[n]):e(r.concat(n),o[n]=b(o[n]),u[n]=b(u[n]));return u}([],f,b(n));return s(),a;function N(e){return"function"==typeof e?N(e(f,a)):null!=e?e:""}function c(){o=!o;var e=N(t);for(r&&!o&&(l=function e(n,t,r,o,u){if(o===r);else if(null==r||r.nodeName!==o.nodeName){var l=function e(n,t){var r="string"==typeof n||"number"==typeof n?document.createTextNode(n):(t=t||"svg"===n.nodeName)?document.createElementNS("http://www.w3.org/2000/svg",n.nodeName):document.createElement(n.nodeName),o=n.attributes;if(o){o.oncreate&&y.push(function(){o.oncreate(r)});for(var u=0;u<n.children.length;u++)r.appendChild(e(n.children[u]=N(n.children[u]),t));for(var l in o)w(r,l,o[l],null,t)}return r}(o,u);n.insertBefore(l,t),null!=r&&x(n,t,r),t=l}else if(null==r.nodeName)t.nodeValue=o;else{!function(e,n,t,r){for(var o in b(n,t))t[o]!==("value"===o||"checked"===o?e[o]:n[o])&&w(e,o,t[o],n[o],r);var u=g?t.oncreate:t.onupdate;u&&y.push(function(){u(e,n)})}(t,r.attributes,o.attributes,u=u||"svg"===o.nodeName);for(var i={},f={},a=[],c=r.children,s=o.children,d=0;d<c.length;d++){a[d]=t.childNodes[d];var v=k(c[d]);null!=v&&(i[v]=[a[d],c[d]])}for(var d=0,h=0;h<s.length;){var v=k(c[d]),p=k(s[h]=N(s[h]));if(f[v])d++;else if(null==p||p!==k(c[d+1]))if(null==p||g)null==v&&(e(t,a[d],c[d],s[h],u),h++),d++;else{var m=i[p]||[];v===p?(e(t,m[0],m[1],s[h],u),d++):m[0]?e(t,t.insertBefore(m[0],a[d]),m[1],s[h],u):e(t,a[d],null,s[h],u),f[p]=s[h],h++}else null==v&&x(t,a[d],c[d]),d++}for(;d<c.length;)null==k(c[d])&&x(t,a[d],c[d]),d++;for(var d in i)f[d]||x(t,i[d][0],i[d][1])}return t}(r,l,i,i=e)),g=!1;y.length;)y.pop()()}function s(){o||(o=!0,setTimeout(c))}function b(e,n){var t={};for(var r in e)t[r]=e[r];for(var r in n)t[r]=n[r];return t}function d(e,n,t){var r={};return e.length?(r[e[0]]=1<e.length?d(e.slice(1),n,t[e[0]]):n,b(t,r)):n}function v(e,n){for(var t=0;t<e.length;)n=n[e[t++]];return n}function k(e){return e?e.key:null}function h(e){return e.currentTarget.events[e.type](e)}function w(e,n,t,r,o){if("key"===n);else if("style"===n)for(var u in b(r,t)){var l=null==t||null==t[u]?"":t[u];"-"===u[0]?e[n].setProperty(u,l):e[n][u]=l}else"o"===n[0]&&"n"===n[1]?(n=n.slice(2),e.events?r||(r=e.events[n]):e.events={},(e.events[n]=t)?r||e.addEventListener(n,h):e.removeEventListener(n,h)):n in e&&"list"!==n&&"type"!==n&&"draggable"!==n&&"spellcheck"!==n&&"translate"!==n&&!o?e[n]=null==t?"":t:null!=t&&!1!==t&&e.setAttribute(n,t),null!=t&&!1!==t||e.removeAttribute(n)}function x(e,n,t){function r(){e.removeChild(function e(n,t){var r=t.attributes;if(r){for(var o=0;o<t.children.length;o++)e(n.childNodes[o],t.children[o]);r.ondestroy&&r.ondestroy(n)}return n}(n,t))}var o=t.attributes&&t.attributes.onremove;o?o(n,r):r()}}});
|
||||
//# sourceMappingURL=hyperapp.js.map
|
||||
900
wp-content/plugins/brizy/admin/static/js/rules.js
Normal file
900
wp-content/plugins/brizy/admin/static/js/rules.js
Normal file
@@ -0,0 +1,900 @@
|
||||
var h = hyperapp.h;
|
||||
|
||||
var RULE_TYPE_INCLUDE = 1;
|
||||
var RULE_TYPE_EXCLUDE = 2;
|
||||
|
||||
var RULE_POSTS = 1;
|
||||
var RULE_TAXONOMY = 2;
|
||||
var RULE_ARCHIVE = 4;
|
||||
var RULE_TEMPLATE = 8;
|
||||
var RULE_BRIZY_TEMPLATE = 16;
|
||||
var ANY_CHILD_TAXONOMY = 128;
|
||||
var WOO_PAGES = 256;
|
||||
var RULE_DATE_ARCHIVE = 512;
|
||||
var RULE_YEAR_ARCHIVE = 1024;
|
||||
var RULE_MONTH_ARCHIVE = 2048;
|
||||
var RULE_DAY_ARCHIVE = 4096;
|
||||
|
||||
var defaultTemplateType = Brizy_Admin_Rules.templateType !== '' ? Brizy_Admin_Rules.templateType : 'single';
|
||||
var defaultAppliedFor = null;
|
||||
var defaultEntityType = null;
|
||||
|
||||
switch (defaultTemplateType) {
|
||||
case 'archive':
|
||||
defaultAppliedFor = RULE_TAXONOMY;
|
||||
defaultEntityType = 'category';
|
||||
break;
|
||||
case 'single_product':
|
||||
defaultAppliedFor = RULE_POSTS;
|
||||
defaultEntityType = 'product';
|
||||
break;
|
||||
case 'product_archive':
|
||||
defaultAppliedFor = WOO_PAGES;
|
||||
defaultEntityType = 'shop_page';
|
||||
break;
|
||||
default:
|
||||
defaultAppliedFor = RULE_POSTS;
|
||||
defaultEntityType = 'post';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
var defaultRule = {
|
||||
type: RULE_TYPE_INCLUDE,
|
||||
appliedFor: defaultAppliedFor,
|
||||
entityType: defaultEntityType,
|
||||
entityValues: []
|
||||
};
|
||||
|
||||
var state = {
|
||||
locked: false,
|
||||
templateType: defaultTemplateType,
|
||||
rule: defaultRule,
|
||||
rules: {
|
||||
single: [],
|
||||
archive: [],
|
||||
single_product: [],
|
||||
product_archive: [],
|
||||
},
|
||||
errors: "",
|
||||
groups: [],
|
||||
};
|
||||
|
||||
state.rules[state.templateType] = Brizy_Admin_Rules.rules;
|
||||
|
||||
var apiCache = {
|
||||
groupList: null,
|
||||
postGroupListPromise: [],
|
||||
archiveGroupListPromise: [],
|
||||
templateGroupListPromise: [],
|
||||
postList: [],
|
||||
termList: []
|
||||
};
|
||||
|
||||
var api = {
|
||||
getGroupList: function (templateType) {
|
||||
|
||||
if (!apiCache.groupList) {
|
||||
apiCache.groupList = [];
|
||||
}
|
||||
|
||||
if (apiCache.groupList && apiCache.groupList[templateType])
|
||||
return apiCache.groupList[templateType];
|
||||
|
||||
return apiCache.groupList[templateType] = jQuery.getJSON(Brizy_Admin_Rules.url, {
|
||||
action: Brizy_Admin_Rules.prefix + "_rule_group_list",
|
||||
hash: Brizy_Admin_Rules.hash,
|
||||
version: Brizy_Admin_Data.editorVersion,
|
||||
context: 'template-rules',
|
||||
templateType: templateType
|
||||
})
|
||||
},
|
||||
|
||||
getPostsGroupList: function (postType, templateType) {
|
||||
|
||||
if (apiCache.postGroupListPromise[postType + templateType])
|
||||
return apiCache.postGroupListPromise[postType + templateType];
|
||||
|
||||
return apiCache.postGroupListPromise[postType + templateType] = jQuery.getJSON(Brizy_Admin_Rules.url, {
|
||||
action: Brizy_Admin_Rules.prefix + "_rule_posts_group_list",
|
||||
postType: postType,
|
||||
hash: Brizy_Admin_Rules.hash,
|
||||
version: Brizy_Admin_Data.editorVersion,
|
||||
context: 'template-rules',
|
||||
templateType: templateType
|
||||
})
|
||||
},
|
||||
|
||||
getArchiveGroupList: function (taxonomy, templateType) {
|
||||
|
||||
if (apiCache.archiveGroupListPromise[taxonomy + templateType])
|
||||
return apiCache.archiveGroupListPromise[taxonomy + templateType];
|
||||
|
||||
return apiCache.archiveGroupListPromise[taxonomy + templateType] = jQuery.getJSON(Brizy_Admin_Rules.url, {
|
||||
action: Brizy_Admin_Rules.prefix + "_rule_archive_group_list",
|
||||
taxonomy: taxonomy,
|
||||
hash: Brizy_Admin_Rules.hash,
|
||||
version: Brizy_Admin_Data.editorVersion,
|
||||
context: 'template-rules',
|
||||
templateType: templateType
|
||||
})
|
||||
},
|
||||
|
||||
getTemplateGroupList: function (templateType) {
|
||||
if (apiCache.templateGroupListPromise[templateType + '-author'])
|
||||
return apiCache.templateGroupListPromise[templateType + '-author'];
|
||||
|
||||
return apiCache.templateGroupListPromise[templateType + '-author'] = jQuery.getJSON(Brizy_Admin_Rules.url, {
|
||||
action: Brizy_Admin_Rules.prefix + "_rule_template_group_list",
|
||||
hash: Brizy_Admin_Rules.hash,
|
||||
version: Brizy_Admin_Data.editorVersion,
|
||||
context: 'template-rules',
|
||||
templateType: templateType
|
||||
})
|
||||
},
|
||||
|
||||
getTerms: function (taxonomy) {
|
||||
if (apiCache.termList[taxonomy])
|
||||
return apiCache.termList[taxonomy];
|
||||
|
||||
return jQuery.getJSON(Brizy_Admin_Rules.url, {
|
||||
action: Brizy_Admin_Rules.prefix + "_get_terms",
|
||||
hash: Brizy_Admin_Rules.hash,
|
||||
version: Brizy_Admin_Data.editorVersion,
|
||||
taxonomy: taxonomy
|
||||
}).done(function (data) {
|
||||
apiCache.termList[taxonomy] = jQuery.Deferred().resolve(data);
|
||||
});
|
||||
},
|
||||
|
||||
validateRule: function (rule) {
|
||||
|
||||
var url = new URL(Brizy_Admin_Rules.url);
|
||||
url.searchParams.append('action', Brizy_Admin_Rules.prefix + '_validate_rule');
|
||||
url.searchParams.append('hash', Brizy_Admin_Rules.hash);
|
||||
url.searchParams.append('post', Brizy_Admin_Rules.id);
|
||||
url.searchParams.append('version', Brizy_Admin_Data.editorVersion);
|
||||
url.searchParams.append('dataVersion', 0);
|
||||
url.searchParams.append('ignoreDataVersion', 1);
|
||||
|
||||
return jQuery.ajax({
|
||||
type: "POST",
|
||||
url: url.toString(),
|
||||
data: JSON.stringify(rule),
|
||||
contentType: "application/json; charset=utf-8"
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
var actions = {
|
||||
getState: function (value) {
|
||||
return function (state) {
|
||||
return state;
|
||||
};
|
||||
},
|
||||
|
||||
updateGroups: function (value) {
|
||||
return function (state) {
|
||||
return {
|
||||
groups: value,
|
||||
};
|
||||
};
|
||||
},
|
||||
setLocked: function (value) {
|
||||
return function (state) {
|
||||
return {
|
||||
locked: value,
|
||||
};
|
||||
};
|
||||
},
|
||||
rule: {
|
||||
update: function (rule) {
|
||||
return function (state) {
|
||||
return rule;
|
||||
};
|
||||
},
|
||||
|
||||
setType: function (value) {
|
||||
return function (state) {
|
||||
return {type: value};
|
||||
};
|
||||
},
|
||||
setAppliedFor: function (value) {
|
||||
return function (state) {
|
||||
return {appliedFor: value};
|
||||
};
|
||||
},
|
||||
setEntityType: function (value) {
|
||||
return function (state) {
|
||||
return {entityType: value};
|
||||
};
|
||||
},
|
||||
setEntityValues: function (value) {
|
||||
return function (state) {
|
||||
return {entityValues: value};
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
resetRule: function () {
|
||||
return function (state) {
|
||||
switch (state.templateType) {
|
||||
case 'archive':
|
||||
defaultAppliedFor = RULE_TAXONOMY;
|
||||
defaultEntityType = 'category';
|
||||
break;
|
||||
|
||||
default:
|
||||
defaultAppliedFor = RULE_POSTS;
|
||||
defaultEntityType = 'post';
|
||||
break;
|
||||
}
|
||||
|
||||
var defaultRule = {
|
||||
type: RULE_TYPE_INCLUDE,
|
||||
appliedFor: defaultAppliedFor,
|
||||
entityType: defaultEntityType,
|
||||
entityValues: []
|
||||
};
|
||||
|
||||
return {errors: "", rule: defaultRule};
|
||||
};
|
||||
},
|
||||
addFormErrors: function (errors) {
|
||||
return function (state) {
|
||||
return {errors: errors};
|
||||
};
|
||||
},
|
||||
|
||||
addRule: function (rule) {
|
||||
return function (state) {
|
||||
|
||||
switch (state.templateType) {
|
||||
case 'archive':
|
||||
defaultAppliedFor = RULE_TAXONOMY;
|
||||
defaultEntityType = 'category';
|
||||
break;
|
||||
|
||||
default:
|
||||
defaultAppliedFor = RULE_POSTS;
|
||||
defaultEntityType = 'post';
|
||||
break;
|
||||
}
|
||||
|
||||
var defaultRule = {
|
||||
type: RULE_TYPE_INCLUDE,
|
||||
appliedFor: defaultAppliedFor,
|
||||
entityType: defaultEntityType,
|
||||
entityValues: []
|
||||
};
|
||||
|
||||
return {
|
||||
rules: {[state.templateType]: [...state.rules[state.templateType] || [], rule]},
|
||||
rule: defaultRule,
|
||||
errors: ""
|
||||
};
|
||||
};
|
||||
},
|
||||
removeRule: function (rule) {
|
||||
return function (state) {
|
||||
var rules = state.rules[state.templateType];
|
||||
rules.splice(rules.indexOf(rule), 1);
|
||||
return {
|
||||
rules: {
|
||||
[state.templateType]: rules
|
||||
}
|
||||
};
|
||||
};
|
||||
},
|
||||
setTemplateType: function (type) {
|
||||
return function (state) {
|
||||
return {
|
||||
templateType: type,
|
||||
};
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
function arr_diff(a1, a2) {
|
||||
|
||||
var a = [], diff = [];
|
||||
|
||||
for (var i = 0; i < a1.length; i++) {
|
||||
a[a1[i]] = true;
|
||||
}
|
||||
|
||||
for (var i = 0; i < a2.length; i++) {
|
||||
if (a[a2[i]]) {
|
||||
delete a[a2[i]];
|
||||
} else {
|
||||
a[a2[i]] = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (var k in a) {
|
||||
diff.push(k);
|
||||
}
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
|
||||
var RuleTypeField = function (params) {
|
||||
return function (state, action) {
|
||||
return h(
|
||||
"span",
|
||||
{
|
||||
class: "brizy-rule-select",
|
||||
},
|
||||
|
||||
h(
|
||||
"select",
|
||||
{
|
||||
name: params.name,
|
||||
style: {width: "100px"},
|
||||
// oncreate: function (element) {
|
||||
// var el = jQuery(element);
|
||||
// el.on("change", function(e){ action.rule.setType(e.target.value); });
|
||||
// el.select2();
|
||||
// },
|
||||
// onremove: function (element, done) {
|
||||
// jQuery(element).select2("destroy");
|
||||
// done();
|
||||
// },
|
||||
onchange: function (e) {
|
||||
action.rule.setType(e.target.value);
|
||||
}
|
||||
},
|
||||
[
|
||||
h(
|
||||
"option",
|
||||
{
|
||||
value: RULE_TYPE_INCLUDE,
|
||||
selected: parseInt(params.value) === RULE_TYPE_INCLUDE
|
||||
},
|
||||
"Include"
|
||||
),
|
||||
h(
|
||||
"option",
|
||||
{
|
||||
value: RULE_TYPE_EXCLUDE,
|
||||
selected: parseInt(params.value) === RULE_TYPE_EXCLUDE
|
||||
},
|
||||
"Exclude"
|
||||
)
|
||||
]
|
||||
)
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
var BrzSelect2 = function (params) {
|
||||
|
||||
var oncreate = function (element) {
|
||||
|
||||
var el = jQuery(element);
|
||||
el.on("change", params.onChange);
|
||||
|
||||
if (typeof params.optionRequest === 'function') {
|
||||
const optionRequest = params.optionRequest();
|
||||
|
||||
if (typeof params.optionRequest === 'function') {
|
||||
optionRequest.done(function (response) {
|
||||
var options = params.convertResponseToOptions(response);
|
||||
options.forEach(function (option) {
|
||||
el.append(option);
|
||||
});
|
||||
el.select2();
|
||||
});
|
||||
} else {
|
||||
var options = params.convertResponseToOptions(optionRequest);
|
||||
options.forEach(function (option) {
|
||||
el.append(option);
|
||||
});
|
||||
el.select2();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var onremove = function (element, done) {
|
||||
if (jQuery(element).data('select2')) {
|
||||
jQuery(element).select2("destroy");
|
||||
}
|
||||
done();
|
||||
};
|
||||
|
||||
return h(
|
||||
"select",
|
||||
{
|
||||
key: params.id + '|' + params.value,
|
||||
akey: params.id + '|' + params.value,
|
||||
style: params.style,
|
||||
oncreate: oncreate,
|
||||
onremove: onremove,
|
||||
name: params.name,
|
||||
},
|
||||
[]
|
||||
);
|
||||
};
|
||||
|
||||
var RulePostsGroupSelectField = function (params) {
|
||||
return function (state, actions) {
|
||||
var appliedFor = params.rule.appliedFor;
|
||||
var entityType = params.rule.entityType;
|
||||
var value = String(params.rule.entityValues[0] ? params.rule.entityValues[0] : '');
|
||||
|
||||
var convertResponseToOptions = function (response) {
|
||||
var groups = [];
|
||||
groups.push(new Option("All", '', true, value === ''));
|
||||
response.data.forEach(function (group) {
|
||||
if (group.title === "") {
|
||||
group.items.forEach(function (option) {
|
||||
var optionValue = String(option.value);
|
||||
var selected = params.rule.entityValues.includes(optionValue);
|
||||
groups.push(new Option(option.title, optionValue, false, selected));
|
||||
});
|
||||
} else {
|
||||
var groupElement = document.createElement("OPTGROUP");
|
||||
groupElement.label = group.title;
|
||||
|
||||
if (group.items.length > 0) {
|
||||
group.items.forEach(function (option) {
|
||||
var optionValue = String(option.value);
|
||||
var selected = params.rule.entityValues.includes(optionValue);
|
||||
groupElement.appendChild(new Option(option.title, optionValue, false, selected))
|
||||
});
|
||||
groups.push(groupElement);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return groups;
|
||||
};
|
||||
|
||||
|
||||
return h(
|
||||
BrzSelect2,
|
||||
{
|
||||
id: "post-groups-" + entityType + '-' + params.type,
|
||||
style: params.style ? params.style : {width: "200px"},
|
||||
name: params.name,
|
||||
optionRequest: function () {
|
||||
actions.setLocked(true);
|
||||
return api.getPostsGroupList(entityType, params.type).done(function (data) {
|
||||
actions.setLocked(false);
|
||||
return data;
|
||||
});
|
||||
},
|
||||
convertResponseToOptions: convertResponseToOptions,
|
||||
onChange: params.onChange,
|
||||
},
|
||||
[]
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
var RuleArchiveGroupSelectField = function (params) {
|
||||
return function (state, actions) {
|
||||
var appliedFor = params.rule.appliedFor;
|
||||
var taxonomy = params.rule.entityType;
|
||||
var value = String(params.rule.entityValues[0] ? params.rule.entityValues[0] : '');
|
||||
|
||||
var convertResponseToOptions = function (response) {
|
||||
var groups = [];
|
||||
groups.push(new Option("All", '', false, value === ''));
|
||||
response.data.forEach(function (group) {
|
||||
|
||||
if (group.title === "") {
|
||||
group.items.forEach(function (option) {
|
||||
var optionValue = String(option.value);
|
||||
groups.push(new Option(option.title, optionValue, false, params.rule.entityValues.includes(optionValue)));
|
||||
});
|
||||
} else {
|
||||
var groupElement = document.createElement("OPTGROUP");
|
||||
groupElement.label = group.title;
|
||||
|
||||
if (group.items.length > 0) {
|
||||
group.items.forEach(function (option) {
|
||||
var optionValue = String(option.value);
|
||||
groupElement.appendChild(new Option(option.title, optionValue, false, params.rule.entityValues.includes(optionValue)))
|
||||
});
|
||||
groups.push(groupElement);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return groups;
|
||||
};
|
||||
|
||||
return h(
|
||||
BrzSelect2,
|
||||
{
|
||||
id: "archive-groups-" + params.taxonomy,
|
||||
style: params.style ? params.style : {width: "200px"},
|
||||
name: params.name,
|
||||
optionRequest: function () {
|
||||
actions.setLocked(true);
|
||||
return api.getArchiveGroupList(taxonomy, params.type).done(function (data) {
|
||||
actions.setLocked(false);
|
||||
return data;
|
||||
});
|
||||
},
|
||||
convertResponseToOptions: convertResponseToOptions,
|
||||
onChange: params.onChange,
|
||||
},
|
||||
[]
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
var RuleAuthorGroupSelectField = function (params) {
|
||||
return function (state, actions) {
|
||||
var appliedFor = params.rule.appliedFor;
|
||||
var taxonomy = params.rule.entityType;
|
||||
var value = String(params.rule.entityValues[0] ? params.rule.entityValues[0] : '');
|
||||
|
||||
var convertResponseToOptions = function (response) {
|
||||
var groups = [];
|
||||
groups.push(new Option("All", '', false, value === ''));
|
||||
response.data.forEach(function (group) {
|
||||
|
||||
if (group.title === "") {
|
||||
group.items.forEach(function (option) {
|
||||
var optionValue = String(option.value);
|
||||
groups.push(new Option(option.title, optionValue, false, params.rule.entityValues.includes(optionValue)));
|
||||
});
|
||||
} else {
|
||||
var groupElement = document.createElement("OPTGROUP");
|
||||
groupElement.label = group.title;
|
||||
|
||||
if (group.items.length > 0) {
|
||||
group.items.forEach(function (option) {
|
||||
var optionValue = String(option.value);
|
||||
groupElement.appendChild(new Option(option.title, optionValue, false, params.rule.entityValues.includes(optionValue)))
|
||||
});
|
||||
groups.push(groupElement);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return groups;
|
||||
};
|
||||
|
||||
return h(
|
||||
BrzSelect2,
|
||||
{
|
||||
id: "archive-groups-author",
|
||||
style: params.style ? params.style : {width: "200px"},
|
||||
name: params.name,
|
||||
optionRequest: function () {
|
||||
actions.setLocked(true);
|
||||
return api.getTemplateGroupList(params.type).done(function (data) {
|
||||
actions.setLocked(false);
|
||||
return data;
|
||||
});
|
||||
},
|
||||
convertResponseToOptions: convertResponseToOptions,
|
||||
onChange: params.onChange,
|
||||
},
|
||||
[]
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
var RuleApplyGroupField = function (params) {
|
||||
return function (state, actions) {
|
||||
|
||||
var appliedFor = params.rule.appliedFor;
|
||||
var entityType = params.rule.entityType;
|
||||
var value = appliedFor + "|" + entityType;
|
||||
var groups = [];
|
||||
|
||||
params.groups.forEach(function (group) {
|
||||
var options = [];
|
||||
group.items.forEach(function (option) {
|
||||
var optionValue = option.groupValue + "|" + option.value;
|
||||
var attributes = {
|
||||
value: optionValue,
|
||||
selected: optionValue === value
|
||||
};
|
||||
options.push(h("option", attributes, option.title));
|
||||
});
|
||||
const attributes = {label: group.title};
|
||||
|
||||
if (group.value + "|" === "|") {
|
||||
groups.push(h("option", {value: "|"}, group.title));
|
||||
} else {
|
||||
groups.push(h("optgroup", attributes, options));
|
||||
}
|
||||
});
|
||||
|
||||
const attributes = {
|
||||
name: params.name,
|
||||
style: {width: "200px"},
|
||||
class: "brizy-rule-select--options[] ",
|
||||
onchange: function (e) {
|
||||
var values = e.target.value.split("|");
|
||||
actions.rule.update({
|
||||
appliedFor: parseInt(values[0]),
|
||||
entityType: values[1],
|
||||
entityValues: []
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var elements = [
|
||||
h("span", {class: "brizy-rule-select brizy-rule-select2"},
|
||||
h("select", attributes, groups)
|
||||
)
|
||||
];
|
||||
|
||||
switch (parseInt(appliedFor)) {
|
||||
case RULE_POSTS:
|
||||
elements.push(
|
||||
h("span", {class: "brizy-rule-select brizy-rule-select2"}, [
|
||||
h(RulePostsGroupSelectField, {
|
||||
id: params.type + appliedFor + value,
|
||||
key: params.type + appliedFor + value,
|
||||
rule: params.rule,
|
||||
type: params.type,
|
||||
name: params.type ? 'brizy-' + params.type + '-rule-entity-values[]' : '',
|
||||
onChange: function (e) {
|
||||
actions.rule.update({
|
||||
entityValues: e.target.value ? [e.target.value] : [],
|
||||
});
|
||||
}
|
||||
})
|
||||
]));
|
||||
break;
|
||||
case RULE_TAXONOMY:
|
||||
elements.push(
|
||||
h("span", {class: "brizy-rule-select brizy-rule-select2"}, [
|
||||
h(RuleArchiveGroupSelectField, {
|
||||
id: params.type + appliedFor + value,
|
||||
key: params.type + appliedFor + value,
|
||||
rule: params.rule,
|
||||
type: params.type,
|
||||
taxonomy: entityType,
|
||||
name: params.type ? 'brizy-' + params.type + '-rule-entity-values[]' : '',
|
||||
onChange: function (e) {
|
||||
actions.rule.update({
|
||||
entityValues: e.target.value ? [e.target.value] : [],
|
||||
});
|
||||
}
|
||||
})
|
||||
]));
|
||||
break;
|
||||
|
||||
case RULE_TEMPLATE:
|
||||
if (entityType === 'author') {
|
||||
elements.push(
|
||||
h("span", {class: "brizy-rule-select brizy-rule-select2"}, [
|
||||
h(RuleAuthorGroupSelectField, {
|
||||
id: params.type + appliedFor + value,
|
||||
key: params.type + appliedFor + value,
|
||||
rule: params.rule,
|
||||
type: params.type,
|
||||
name: params.type ? 'brizy-' + params.type + '-rule-entity-values[]' : '',
|
||||
onChange: function (e) {
|
||||
actions.rule.update({
|
||||
entityValues: e.target.value ? [e.target.value] : [],
|
||||
});
|
||||
}
|
||||
})
|
||||
]));
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
return h("span", {}, elements);
|
||||
};
|
||||
};
|
||||
|
||||
var RuleForm = function (params) {
|
||||
var elements = [
|
||||
h("h4", {}, "Add New Condition"),
|
||||
h(RuleTypeField, {value: String(params.rule.type)}),
|
||||
h(RuleApplyGroupField, {rule: params.rule, groups: params.groups, type: params.type}),
|
||||
h("input", {
|
||||
type: "button",
|
||||
class: "button",
|
||||
onclick: params.onSubmit,
|
||||
value: "Add"
|
||||
})
|
||||
];
|
||||
|
||||
if (params.errors) {
|
||||
elements.push(h("p", {class: "error"}, params.errors));
|
||||
}
|
||||
|
||||
return h("div", {class: "brizy-rule-new-condition"}, elements);
|
||||
};
|
||||
|
||||
var RuleListItem = function (params) {
|
||||
var rule = params.rule;
|
||||
var key = 'list-' + rule.type + rule.appliedType + rule.appliedFor + rule.entityValues.join('') + params.index;
|
||||
return h("div", {class: "rule", key: key}, [
|
||||
|
||||
h("span", {class: 'rule-fields'}, [
|
||||
h(RuleTypeField, {value: String(params.rule.type), name: 'brizy-' + params.type + '-rule-type[]'}),
|
||||
h(RuleApplyGroupField, {
|
||||
rule: params.rule,
|
||||
groups: params.groups,
|
||||
type: params.type,
|
||||
name: 'brizy-' + params.type + '-rule-group[]'
|
||||
}),
|
||||
h('div', {class: 'overlay'}, [])
|
||||
]),
|
||||
h("input", {
|
||||
class: "brizy-delete-rule ",
|
||||
type: "button",
|
||||
value: "Delete",
|
||||
onclick: function (e) {
|
||||
if (confirm('Are you sure you want to delete?'))
|
||||
params.onDelete(params.rule);
|
||||
}
|
||||
})
|
||||
]);
|
||||
};
|
||||
|
||||
var RuleList = function (params) {
|
||||
var elements = [];
|
||||
if (params.rules.length) {
|
||||
elements.push(h("h4", {}, "Where do You Want to Display it"));
|
||||
}
|
||||
|
||||
params.rules.forEach(function (rule, index) {
|
||||
elements.push(
|
||||
h(RuleListItem, {
|
||||
index: index,
|
||||
rule: rule,
|
||||
groups: params.groups,
|
||||
onDelete: params.onDelete,
|
||||
type: params.type
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
return h("div", {}, elements);
|
||||
};
|
||||
|
||||
var TemplateTypeSelect = function (params) {
|
||||
return h(
|
||||
"fieldset", {class: 'brizy-template-type'}, [
|
||||
h('h4', {}, 'Template Type'),
|
||||
h('label', {}, [
|
||||
h('input', {
|
||||
type: 'radio',
|
||||
name: 'brizy-template-type',
|
||||
onchange: params.onChange,
|
||||
value: 'single',
|
||||
checked: 'single' === params.value
|
||||
}),
|
||||
h('span', {class: "date-time-text format-i18n"}, Brizy_Admin_Rules.labels.single),
|
||||
]),
|
||||
h('label', {}, [
|
||||
h('input', {
|
||||
type: 'radio',
|
||||
name: 'brizy-template-type',
|
||||
onchange: params.onChange,
|
||||
value: 'archive',
|
||||
checked: 'archive' === params.value
|
||||
}),
|
||||
h('span', {class: "date-time-text format-i18n"}, Brizy_Admin_Rules.labels.archive),
|
||||
]),
|
||||
...(Brizy_Admin_Rules.labels.single_product ?
|
||||
[h('label', {}, [
|
||||
h('input', {
|
||||
type: 'radio',
|
||||
name: 'brizy-template-type',
|
||||
onchange: params.onChange,
|
||||
value: 'single_product',
|
||||
checked: 'single_product' === params.value
|
||||
}),
|
||||
h('span', {class: "date-time-text format-i18n"}, Brizy_Admin_Rules.labels.single_product),
|
||||
]), h('label', {}, [
|
||||
h('input', {
|
||||
type: 'radio',
|
||||
name: 'brizy-template-type',
|
||||
onchange: params.onChange,
|
||||
value: 'product_archive',
|
||||
checked: 'product_archive' === params.value
|
||||
}),
|
||||
h('span', {class: "date-time-text format-i18n"}, Brizy_Admin_Rules.labels.product_archive),
|
||||
])] : []),
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
var ruleView = function (state, actions) {
|
||||
|
||||
return h(
|
||||
"div",
|
||||
{
|
||||
class: "rules-container",
|
||||
oncreate: function () {
|
||||
if (state.templateType != '')
|
||||
actions.setLocked(true);
|
||||
api.getGroupList(state.templateType).done(function (response) {
|
||||
actions.updateGroups(response.data)
|
||||
actions.setLocked(false);
|
||||
});
|
||||
},
|
||||
},
|
||||
[
|
||||
h(
|
||||
TemplateTypeSelect, {
|
||||
value: state.templateType,
|
||||
onChange: function (e) {
|
||||
const type = e.target.value && e.target.value != "null"
|
||||
? e.target.value
|
||||
: null;
|
||||
|
||||
actions.setLocked(true);
|
||||
actions.setTemplateType(type);
|
||||
api.getGroupList(type).done(function (response) {
|
||||
actions.updateGroups(response.data);
|
||||
actions.rule.update({
|
||||
appliedFor: String(response.data[0].value),
|
||||
entityType: String(response.data[0].items[0].value),
|
||||
});
|
||||
actions.setLocked(false);
|
||||
});
|
||||
}
|
||||
}, []
|
||||
),
|
||||
h(RuleList, {
|
||||
type: state.templateType,
|
||||
rules: state.rules[state.templateType] || [],
|
||||
groups: state.groups,
|
||||
onDelete: function (rule) {
|
||||
actions.removeRule(rule);
|
||||
}
|
||||
}),
|
||||
state.templateType ? [
|
||||
h(RuleForm, {
|
||||
type: state.templateType,
|
||||
rule: state.rule,
|
||||
groups: state.groups,
|
||||
errors: state.errors,
|
||||
onSubmit: function () {
|
||||
var rules = state.rules[state.templateType] || [];
|
||||
|
||||
try {
|
||||
rules.forEach(rule => {
|
||||
if (rule.type !== state.rule.type) return;
|
||||
if (rule.appliedFor !== state.rule.appliedFor) return;
|
||||
if (rule.entityType !== state.rule.entityType) return;
|
||||
if (arr_diff(rule.entityValues, state.rule.entityValues).length > 0) return;
|
||||
throw 'This rule already exist';
|
||||
});
|
||||
} catch (error) {
|
||||
actions.addFormErrors('This rule already exist');
|
||||
return;
|
||||
}
|
||||
api.validateRule(state.rule)
|
||||
.done(function () {
|
||||
actions.addRule(state.rule);
|
||||
actions.resetRule();
|
||||
})
|
||||
.fail(function (response) {
|
||||
if (response.responseJSON && response.responseJSON.data) {
|
||||
if (response.responseJSON.data.message)
|
||||
actions.addFormErrors(response.responseJSON.data.message);
|
||||
else
|
||||
actions.addFormErrors("Failed to add the rule");
|
||||
}
|
||||
});
|
||||
}
|
||||
})] :
|
||||
[],
|
||||
state.locked ? [h('div', {class: 'lock-screen'}, "Loading..")] : [],
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
jQuery(document).ready(function ($) {
|
||||
hyperapp.app(state, actions, ruleView, document.getElementById("rules"));
|
||||
});
|
||||
|
||||
237
wp-content/plugins/brizy/admin/static/js/script.js
Normal file
237
wp-content/plugins/brizy/admin/static/js/script.js
Normal file
@@ -0,0 +1,237 @@
|
||||
jQuery(document).ready(function ($) {
|
||||
|
||||
$( '.brz-review-deserve, .brz-review-later, .brz-review-done' ).on( 'click', function ( e ) {
|
||||
|
||||
var btn = $( this );
|
||||
notice = btn.closest( '.brz-notice' );
|
||||
|
||||
if ( ! btn.hasClass( 'brz-review-deserve' ) ) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
$.ajax( {
|
||||
url: Brizy_Admin_Data.url,
|
||||
type: 'POST',
|
||||
data: {
|
||||
'action': 'brizy-dismiss-notice',
|
||||
'nonce': Brizy_Admin_Data.nonce,
|
||||
'repeat': !!btn.hasClass( 'brz-review-later' )
|
||||
}
|
||||
} );
|
||||
|
||||
notice.animate({
|
||||
opacity: '-=1'
|
||||
}, 1000, function() {
|
||||
notice.remove();
|
||||
});
|
||||
} );
|
||||
|
||||
var BrizyFeedbackDialog = {
|
||||
|
||||
init: function () {
|
||||
|
||||
if ( ! $( '#brz-deactivate-feedback-dialog' ).length && typeof dialog !== "function" ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.initDialog();
|
||||
|
||||
$( 'tr[data-slug="brizy"] .deactivate' ).click( function ( e ) {
|
||||
e.preventDefault();
|
||||
$( '#brz-deactivate-feedback-dialog' ).dialog( 'open' );
|
||||
} );
|
||||
|
||||
$( '#brz-deactivate-feedback-dialog input:radio' ).change( function () {
|
||||
|
||||
var radio = $( this ),
|
||||
submitBtn = $( '.brz-feedback-submit' ),
|
||||
skipBtn = $( '.brz-feedback-skip' );
|
||||
|
||||
$( '.brz-feedback-text' ).addClass( 'hidden' );
|
||||
submitBtn.prop( 'disabled', false );
|
||||
skipBtn.prop( 'disabled', false );
|
||||
|
||||
if ( radio.val() === 'brizy_pro' ) {
|
||||
submitBtn.prop( 'disabled', true );
|
||||
skipBtn.prop( 'disabled', true );
|
||||
}
|
||||
|
||||
radio.parent().find( '.brz-feedback-text' ).removeClass( 'hidden' );
|
||||
} );
|
||||
},
|
||||
submitFeedback: function () {
|
||||
|
||||
var redirect = false;
|
||||
|
||||
$( '#brz-deactivate-feedback-dialog input:radio' ).each( function () {
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
redirect = true;
|
||||
}
|
||||
} );
|
||||
|
||||
if ( !redirect ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$( '.brz-feedback-submit .ui-button-text' ).addClass( 'brz-loading' ).text( '' );
|
||||
|
||||
$.ajax( {
|
||||
url: Brizy_Admin_Data.url,
|
||||
type: 'POST',
|
||||
data: {
|
||||
'action': 'brizy-send-feedback',
|
||||
'nonce': Brizy_Admin_Data.nonce,
|
||||
'form': $( 'form.brz-deactivate-feedback-dialog-form' ).serialize()
|
||||
}
|
||||
} );
|
||||
|
||||
setTimeout( function () {
|
||||
location.href = $( 'tr[data-slug="brizy"] .deactivate a' ).attr( 'href' );
|
||||
}, 1000 );
|
||||
},
|
||||
initDialog: function () {
|
||||
|
||||
$( '#brz-deactivate-feedback-dialog' ).dialog( {
|
||||
dialogClass: 'brz-deactivate-modal',
|
||||
autoOpen: false,
|
||||
draggable: false,
|
||||
width: 'auto',
|
||||
modal: true,
|
||||
resizable: false,
|
||||
closeOnEscape: true,
|
||||
buttons: [
|
||||
{
|
||||
text: Brizy_Admin_Data.l10n.deactivateFeedbackSubmitBtn,
|
||||
class: 'brz-feedback-submit',
|
||||
click: function () {
|
||||
BrizyFeedbackDialog.submitFeedback();
|
||||
}
|
||||
},
|
||||
{
|
||||
text: Brizy_Admin_Data.l10n.deactivateFeedbackSkipBtn,
|
||||
class: 'brz-feedback-skip',
|
||||
click: function () {
|
||||
location.href = $( 'tr[data-slug="brizy"] .deactivate a' ).attr( 'href' );
|
||||
}
|
||||
}
|
||||
],
|
||||
open: function () {
|
||||
var overlay = $('.ui-widget-overlay');
|
||||
|
||||
overlay.addClass( 'brz-deactivate-overlay' );
|
||||
|
||||
$( '.brz-feedback-text' ).addClass( 'hidden' );
|
||||
$( '.brz-deactivate-modal input:radio' ).prop( 'checked', false );
|
||||
|
||||
// close dialog by clicking the overlay behind it
|
||||
overlay.bind( 'click', function () {
|
||||
$( '#brz-deactivate-feedback-dialog' ).dialog( 'close' );
|
||||
} );
|
||||
|
||||
$( '.brz-feedback-submit' ).prop( 'disabled', false );
|
||||
$( '.brz-feedback-skip' ).prop( 'disabled', false );
|
||||
},
|
||||
create: function () {
|
||||
// style fix for WordPress admin
|
||||
$( '.ui-dialog-titlebar-close' ).addClass( 'ui-button' );
|
||||
},
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
$('.enable-brizy-editor').on('click', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
jQuery(window).off('beforeunload.edit-post');
|
||||
|
||||
if (wp.autosave) {
|
||||
wp.autosave.server.triggerSave();
|
||||
}
|
||||
|
||||
window.location = $(this).attr('href');
|
||||
});
|
||||
|
||||
// Open our submenu link "Get Help" in a new tab.
|
||||
$( '#get-help,#go-pro' ).parent().attr( 'target', '_blank' );
|
||||
|
||||
var BrizyGutenberg = {
|
||||
|
||||
insertBrizyBtn: function () {
|
||||
|
||||
if ( $( '.edit-post-header-toolbar .brizy-buttons' ).length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var guten = $( '#editor' ),
|
||||
html = $( '#brizy-gutenberg-btn-middle' ).html();
|
||||
|
||||
if ( ! guten ) {
|
||||
return;
|
||||
}
|
||||
|
||||
guten.find( '.edit-post-header-toolbar' ).append( $( '#brizy-gutenberg-btn-switch-mode' ).html() );
|
||||
|
||||
if ( html && ! $( '.brizy-buttons-gutenberg' ).length ) {
|
||||
guten.find( '.edit-post-visual-editor .block-editor-writing-flow' ).append( html );
|
||||
guten.find( '.editor-post-text-editor' ).after( html );
|
||||
}
|
||||
},
|
||||
|
||||
init: function () {
|
||||
var self = this;
|
||||
|
||||
if (typeof wp.data != 'undefined') {
|
||||
wp.data.subscribe(function () {
|
||||
setTimeout( function () {
|
||||
self.insertBrizyBtn();
|
||||
}, 1 );
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var BrizyMaintenance = {
|
||||
getSelectAccessRole: function() {
|
||||
return $( '#brizy-maintenance-access-role' );
|
||||
},
|
||||
getSelectMode: function() {
|
||||
return $( 'select[name="brizy-maintenance[mode]"]' );
|
||||
},
|
||||
handleEvents: function () {
|
||||
this.getSelectAccessRole().change( function ( e ) {
|
||||
var display = 'custom' === $( this ).val() ? 'table-cell' : 'none';
|
||||
$( '.brizy-maintenance-roles th, .brizy-maintenance-roles td' ).css( 'display', display );
|
||||
} );
|
||||
|
||||
this.getSelectMode().change( function ( e ) {
|
||||
var self = $( this ),
|
||||
trs = self.closest( 'table' ).find( 'tr:not(#brizy-maintenance-js-mode)' );
|
||||
|
||||
if ( self.val() ) {
|
||||
trs.removeClass( 'hidden' );
|
||||
} else {
|
||||
trs.addClass( 'hidden' );
|
||||
}
|
||||
} );
|
||||
|
||||
this.getSelectMode().trigger( 'change' );
|
||||
this.getSelectAccessRole().trigger( 'change' );
|
||||
},
|
||||
|
||||
init: function () {
|
||||
if ( ! this.getSelectAccessRole().length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.handleEvents();
|
||||
}
|
||||
};
|
||||
|
||||
$( function () {
|
||||
BrizyGutenberg.init();
|
||||
BrizyFeedbackDialog.init();
|
||||
BrizyMaintenance.init();
|
||||
} );
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user