|
@@ -1,3 +1,12 @@
|
|
|
|
+var faCogActive = true;
|
|
|
|
+var faThLargeActive = false;
|
|
|
|
+var activeIcon = getVariable('active_icon');
|
|
|
|
+if (activeIcon) {
|
|
|
|
+ faCogActive = activeIcon === 'fa-cog'? true : false;
|
|
|
|
+ faThLargeActive = activeIcon === 'fa-th-large'? true : false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
const panelsConfig = {
|
|
const panelsConfig = {
|
|
stylePrefix: 'pn-',
|
|
stylePrefix: 'pn-',
|
|
defaults: [
|
|
defaults: [
|
|
@@ -53,7 +62,7 @@ const panelsConfig = {
|
|
id: 'open-tm',
|
|
id: 'open-tm',
|
|
className: 'fa fa-cog',
|
|
className: 'fa fa-cog',
|
|
command: 'open-tm',
|
|
command: 'open-tm',
|
|
- active: true,
|
|
+ active: faCogActive,
|
|
togglable: true,
|
|
togglable: true,
|
|
attributes: { title: 'Settings' },
|
|
attributes: { title: 'Settings' },
|
|
},
|
|
},
|
|
@@ -64,13 +73,14 @@ const panelsConfig = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
+ {
|
|
-
|
|
+ id: 'open-blocks',
|
|
-
|
|
+ className: 'fa fa-th-large',
|
|
-
|
|
+ command: 'open-blocks',
|
|
-
|
|
+ active: faThLargeActive,
|
|
-
|
|
+ togglable: true,
|
|
-
|
|
+ attributes: { title: 'Open Blocks' },
|
|
|
|
+ },
|
|
],
|
|
],
|
|
},
|
|
},
|
|
],
|
|
],
|
|
@@ -139,29 +149,45 @@ const editor = grapesjs.init({
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
+
|
|
|
|
+const bm = editor.Blocks;
|
|
|
|
+bm.add('block_p', {
|
|
|
|
+
|
|
|
|
+ label: 'Paragraph',
|
|
|
|
+ media: `<svg style="width:20px;height:20px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M192 32l64 0 160 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-32 0 0 352c0 17.7-14.3 32-32 32s-32-14.3-32-32l0-352-32 0 0 352c0 17.7-14.3 32-32 32s-32-14.3-32-32l0-96-32 0c-88.4 0-160-71.6-160-160s71.6-160 160-160z"/></svg>`,
|
|
|
|
+ content: '<p>insert your text here</p>',
|
|
|
|
+});
|
|
|
|
+bm.add('block_span', {
|
|
|
|
+
|
|
|
|
+ label: 'Text',
|
|
|
|
+ media: `<svg style="width:20px;height:20px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--!Font Awesome Free 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M32 32C14.3 32 0 46.3 0 64S14.3 96 32 96l128 0 0 352c0 17.7 14.3 32 32 32s32-14.3 32-32l0-352 128 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L192 32 32 32z"/></svg>`,
|
|
|
|
+ content: '<span>insert your text here</span>',
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
const am = editor.AssetManager;
|
|
const am = editor.AssetManager;
|
|
|
|
|
|
editor.getWrapper().set({ locked: true });
|
|
editor.getWrapper().set({ locked: true });
|
|
-
|
|
|
|
|
|
|
|
-const edit_classes = ['mtb_edit'];
|
|
+
|
|
editor.getComponents().each(component => {
|
|
editor.getComponents().each(component => {
|
|
component.onAll(component => {
|
|
component.onAll(component => {
|
|
|
|
|
|
- let html = component.toHTML();
|
|
+
|
|
- const classes = component.getClasses();
|
|
+
|
|
-
|
|
+
|
|
- const hasIntersection = classes.some(item => {
|
|
+
|
|
-
|
|
+
|
|
- if (Array.isArray(item)) {
|
|
+
|
|
- return item.some(subItem => edit_classes.includes(subItem));
|
|
+
|
|
- }
|
|
+
|
|
-
|
|
+
|
|
- return edit_classes.includes(item);
|
|
+
|
|
- });
|
|
+
|
|
|
|
|
|
|
|
|
|
- if (hasIntersection || component.get('attributes').mtb_edit == 'true') {
|
|
+ if (component.get('attributes').mtb_edit == 'true') {
|
|
component.set({ locked: false });
|
|
component.set({ locked: false });
|
|
setBorder(component);
|
|
setBorder(component);
|
|
}
|
|
}
|
|
@@ -180,15 +206,13 @@ editor.getComponents().each(component => {
|
|
if (component.get('attributes').mtb_edit_this == 'false') {
|
|
if (component.get('attributes').mtb_edit_this == 'false') {
|
|
component.set({ locked: true });
|
|
component.set({ locked: true });
|
|
}
|
|
}
|
|
-
|
|
|
|
})
|
|
})
|
|
-
|
|
|
|
});
|
|
});
|
|
|
|
|
|
function setBorder(component) {
|
|
function setBorder(component) {
|
|
if (component.attributes.tagName == 'a') {
|
|
if (component.attributes.tagName == 'a') {
|
|
component.setStyle({
|
|
component.setStyle({
|
|
- border: '3px dotted #f08300'
|
|
+ border: '2px dotted #f08300'
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
component.setStyle({
|
|
component.setStyle({
|
|
@@ -197,24 +221,32 @@ function setBorder(component) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
editor.on('component:selected', (comp) => {
|
|
editor.on('component:selected', (comp) => {
|
|
|
|
|
|
const selectedComponent = editor.getSelected();
|
|
const selectedComponent = editor.getSelected();
|
|
- const defaultToolbar = selectedComponent.get('toolbar');
|
|
+
|
|
- selectedComponent.set({
|
|
+
|
|
-
|
|
+ if (selectedComponent.get('attributes').mtb_edit == 'true' || selectedComponent.get('attributes').mtb_edit_this == 'true') {
|
|
- toolbar: [ ]
|
|
+ selectedComponent.set({
|
|
- });
|
|
+ toolbar: [
|
|
|
|
+ ]
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ selectedComponent.set({
|
|
|
|
+
|
|
|
|
+ toolbar: [{
|
|
|
|
+ attributes: { class: 'fa fa-clone' },
|
|
|
|
+ command: 'tlb-clone',
|
|
|
|
+ title: 'Clone',
|
|
|
|
+ }, {
|
|
|
|
+ attributes: { class: 'fa fa-trash' },
|
|
|
|
+ command: 'tlb-delete',
|
|
|
|
+ title: 'Delete',
|
|
|
|
+ }]
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
if (selectedComponent.attributes.tagName == 'img') {
|
|
if (selectedComponent.attributes.tagName == 'img') {
|
|
@@ -224,13 +256,10 @@ editor.on('component:selected', (comp) => {
|
|
el.addEventListener('dblclick', () => {
|
|
el.addEventListener('dblclick', () => {
|
|
am.open({
|
|
am.open({
|
|
types: ['image'],
|
|
types: ['image'],
|
|
-
|
|
|
|
select(asset, complete) {
|
|
select(asset, complete) {
|
|
const selected = editor.getSelected();
|
|
const selected = editor.getSelected();
|
|
if (selected) {
|
|
if (selected) {
|
|
selected.addAttributes({ src: asset.getSrc() });
|
|
selected.addAttributes({ src: asset.getSrc() });
|
|
-
|
|
|
|
-
|
|
|
|
complete && am.close();
|
|
complete && am.close();
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -241,24 +270,11 @@ editor.on('component:selected', (comp) => {
|
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
-var open_tm_show = true;
|
|
|
|
-var cogIcons = document.querySelectorAll('.fa-cog');
|
|
|
|
-cogIcons.forEach(function(icon) {
|
|
|
|
- icon.addEventListener('click', function() {
|
|
|
|
-
|
|
|
|
- if (open_tm_show) {
|
|
|
|
- open_tm_show = false;
|
|
|
|
- } else {
|
|
|
|
- open_tm_show = true;
|
|
|
|
- }
|
|
|
|
- leftPanelDisplay(open_tm_show);
|
|
|
|
- });
|
|
|
|
-});
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
function leftPanelDisplay(isShow = true) {
|
|
function leftPanelDisplay(isShow = true) {
|
|
if (isShow) {
|
|
if (isShow) {
|
|
-
|
|
|
|
-
|
|
|
|
let elements1 = document.querySelectorAll('.gjs-pn-views-container');
|
|
let elements1 = document.querySelectorAll('.gjs-pn-views-container');
|
|
elements1.forEach(function(element) {
|
|
elements1.forEach(function(element) {
|
|
element.style.display = 'block';
|
|
element.style.display = 'block';
|
|
@@ -268,23 +284,23 @@ function leftPanelDisplay(isShow = true) {
|
|
element.style = 'border_bottom: 2px solid var(--gjs-main-dark-color)';
|
|
element.style = 'border_bottom: 2px solid var(--gjs-main-dark-color)';
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
-
|
|
|
|
-
|
|
|
|
let elements1 = document.querySelectorAll('.gjs-pn-views-container');
|
|
let elements1 = document.querySelectorAll('.gjs-pn-views-container');
|
|
elements1.forEach(function(element) {
|
|
elements1.forEach(function(element) {
|
|
element.style.display = 'none';
|
|
element.style.display = 'none';
|
|
});
|
|
});
|
|
let elements2 = document.querySelectorAll('.gjs-pn-views');
|
|
let elements2 = document.querySelectorAll('.gjs-pn-views');
|
|
elements2.forEach(function(element) {
|
|
elements2.forEach(function(element) {
|
|
- element.style = 'border:none';
|
|
+ element.style = 'border-bottom:none';
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
editor.on('load', () => {
|
|
editor.on('load', () => {
|
|
-
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
const targetElement = document.querySelector('.fa-arrows-alt');
|
|
const targetElement = document.querySelector('.fa-arrows-alt');
|
|
|
|
|
|
@@ -321,8 +337,9 @@ editor.on('load', () => {
|
|
window.location.href = redirectUrl;
|
|
window.location.href = redirectUrl;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
-
|
|
+
|
|
-
|
|
+
|
|
|
|
+
|
|
customSelect = document.querySelector('.custom-select');
|
|
customSelect = document.querySelector('.custom-select');
|
|
|
|
|
|
const sendButton = document.createElement('button');
|
|
const sendButton = document.createElement('button');
|
|
@@ -333,12 +350,69 @@ editor.on('load', () => {
|
|
sendButton.classList.add('layui-btn-radius');
|
|
sendButton.classList.add('layui-btn-radius');
|
|
sendButton.style = 'margin-left:10px;height:25px;line-height:25px;padding:0 10px;vertical-align:unset;';
|
|
sendButton.style = 'margin-left:10px;height:25px;line-height:25px;padding:0 10px;vertical-align:unset;';
|
|
customSelect.insertAdjacentElement('afterend', sendButton);
|
|
customSelect.insertAdjacentElement('afterend', sendButton);
|
|
|
|
+
|
|
|
|
+ sendButton.addEventListener('click', function () {
|
|
|
|
+
|
|
|
|
+ loadIndex = layer.load(0, {shade: [0.5, '#000']});
|
|
|
|
+
|
|
|
|
+ $.ajax({
|
|
|
|
+ url: '/dist/visual-editor/publish',
|
|
|
|
+ type: 'POST',
|
|
|
|
+ headers: {
|
|
|
|
+ 'X-CSRF-TOKEN': csrfToken,
|
|
|
|
+ },
|
|
|
|
+ data: {},
|
|
|
|
+ success: function (res) {
|
|
|
|
+ layer.close(loadIndex);
|
|
|
|
+ layer.msg(res.message,{shade: [0.5, '#000']});
|
|
|
|
+ },
|
|
|
|
+ error: function (err) {
|
|
|
|
+ layer.close(loadIndex);
|
|
|
|
+ layer.msg(err,{shade: [0.5, '#000']});
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ var gjsPnBtn = document.querySelectorAll('.gjs-pn-btn');
|
|
|
|
+ var headRightBtn = ['fa-cog', 'fa-th-large'];
|
|
|
|
+ gjsPnBtn.forEach(function(icon1) {
|
|
|
|
+ let hasIntersection = headRightBtn.some(function(btnClass) {
|
|
|
|
+ return icon1.classList.contains(btnClass);
|
|
|
|
+ });
|
|
|
|
+ if (hasIntersection) {
|
|
|
|
+ icon1.addEventListener('click', function() {
|
|
|
|
+ hasActive = false;
|
|
|
|
+ gjsPnBtn.forEach(function(icon) {
|
|
|
|
+ if (icon.classList.contains('gjs-pn-active')) {
|
|
|
|
+ hasActive = true;
|
|
|
|
+ saveVariable('active_icon',icon.classList.item(2));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if (hasActive) {
|
|
|
|
+ leftPanelDisplay(true);
|
|
|
|
+ } else {
|
|
|
|
+ leftPanelDisplay(false);
|
|
|
|
+ saveVariable('active_icon','none');
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (faCogActive === false && faThLargeActive === false) {
|
|
|
|
+ leftPanelDisplay(false)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
|
|
+
|
|
layer.close(loadIndex);
|
|
layer.close(loadIndex);
|
|
|
|
+
|
|
});
|
|
});
|
|
|
|
|
|
-
|
|
+
|
|
editor.on('update', () => {
|
|
editor.on('update', () => {
|
|
const html = editor.getHtml();
|
|
const html = editor.getHtml();
|
|
|
|
|
|
@@ -354,7 +428,7 @@ editor.on('update', () => {
|
|
},
|
|
},
|
|
success: function (res) {
|
|
success: function (res) {
|
|
if (res.status != 1) {
|
|
if (res.status != 1) {
|
|
- alert('save error');
|
|
+ layer.msg('save data error, please try again later!',{shade: [0.5, '#000']});
|
|
}
|
|
}
|
|
},
|
|
},
|
|
error: function (err) {
|
|
error: function (err) {
|
|
@@ -363,6 +437,7 @@ editor.on('update', () => {
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
editor.on('asset:upload:start', () => {
|
|
editor.on('asset:upload:start', () => {
|
|
loadIndex = layer.load(0, {shade: [0.5, '#000']});
|
|
loadIndex = layer.load(0, {shade: [0.5, '#000']});
|
|
@@ -378,3 +453,14 @@ layui.use('flow', function(){
|
|
|
|
|
|
flow.lazyimg();
|
|
flow.lazyimg();
|
|
});
|
|
});
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+function saveVariable(name, value) {
|
|
|
|
+ localStorage.setItem(name, JSON.stringify(value));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function getVariable(name) {
|
|
|
|
+ const value = localStorage.getItem(name);
|
|
|
|
+ return value ? JSON.parse(value) : null;
|
|
|
|
+}
|