Skip to content

Commit

Permalink
fix: errors on blocks in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Jul 26, 2017
1 parent 26c5b25 commit 4674ec7
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/server/public/abecms/css/styles.css

Large diffs are not rendered by default.

Expand Up @@ -104,11 +104,9 @@ export default class EditorAutocomplete {
}

_changeSelect(e) {
console.log('onchange select triggered')
var target = e.currentTarget
var option = target.querySelector('option:checked')
this._currentInput = target
console.log(target)
this._addResult(
option,
target.getAttribute('data-display'),
Expand Down
46 changes: 23 additions & 23 deletions src/server/public/abecms/scripts/modules/EditorInputs.js
Expand Up @@ -88,26 +88,26 @@ export default class EditorInputs {
this.rebind()
}

_hideIfEmpty(node, value) {
let attr

//attr = node.getAttribute('data-abe-')
attr = /data-abe-(.*?)=/.exec(node.nodeValue)
if (Array.isArray(attr) && attr.length > 1) attr = attr[1]

var hide = IframeNode(
'#page-template',
'[data-if-empty-clear="' + attr + '"]'
)[0]

if (typeof hide !== 'undefined' && hide !== null) {
if (value === '') {
hide.style.display = 'none'
} else {
hide.style.display = ''
}
}
}
// _hideIfEmpty(node, value) {
// let attr

// //attr = node.getAttribute('data-abe-')
// attr = /data-abe-(.*?)=/.exec(node.nodeValue)
// if (Array.isArray(attr) && attr.length > 1) attr = attr[1]

// var hide = IframeNode(
// '#page-template',
// '[data-if-empty-clear="' + attr + '"]'
// )[0]

// if (typeof hide !== 'undefined' && hide !== null) {
// if (value === '') {
// hide.style.display = 'none'
// } else {
// hide.style.display = ''
// }
// }
// }

/**
* [_inputBlur description]
Expand All @@ -120,7 +120,7 @@ export default class EditorInputs {

var nodes = EditorUtils.getNode(EditorUtils.getAttr(e.target))
Array.prototype.forEach.call(nodes, node => {
this._hideIfEmpty(node, e.target.value)
//this._hideIfEmpty(node, e.target.value)
if (node.nodeType === 8) {
node.parentNode.classList.remove('select-border')
node.parentNode.classList.remove('display-attr')
Expand All @@ -142,7 +142,7 @@ export default class EditorInputs {
_inputKeyup(e) {
var nodes = EditorUtils.getNode(EditorUtils.getAttr(e.target))
Array.prototype.forEach.call(nodes, node => {
this._hideIfEmpty(node, e.target.value)
//this._hideIfEmpty(node, e.target.value)
EditorUtils.formToHtml(node, e.target)
})
}
Expand All @@ -167,7 +167,7 @@ export default class EditorInputs {
* @return {[type]} [description]
*/
_inputFocus(e) {
EditorUtils.checkAttribute()
//EditorUtils.checkAttribute()
EditorUtils.scrollToInputElement(e.target)

// switch to set appropriate output {text|link|image|...}
Expand Down
12 changes: 6 additions & 6 deletions src/server/public/abecms/scripts/modules/EditorSave.js
Expand Up @@ -24,12 +24,12 @@ export default class EditorSave {
btnSave.addEventListener('click', this._handleSubmitClick)
})

var pageTpl = document.querySelector('#page-template')
if (typeof pageTpl !== 'undefined' && pageTpl !== null) {
document.querySelector('#page-template').addEventListener('load', () => {
EditorUtils.checkAttribute()
})
}
// var pageTpl = document.querySelector('#page-template')
// if (typeof pageTpl !== 'undefined' && pageTpl !== null) {
// document.querySelector('#page-template').addEventListener('load', () => {
// EditorUtils.checkAttribute()
// })
// }

if (typeof this._abeForm !== 'undefined' && this._abeForm !== null) {
this._formSubmit()
Expand Down
40 changes: 21 additions & 19 deletions src/server/public/abecms/scripts/modules/EditorUtils.js
Expand Up @@ -11,26 +11,28 @@ Handlebars.registerHelper('i18nAbe', translate)
Handlebars.registerHelper('printJson', printJson)

export default class EditorUtils {
static checkAttribute() {
let formAbes = document.querySelectorAll('.form-abe')
// static checkAttribute() {
// let formAbes = document.querySelectorAll('.form-abe')

Array.prototype.forEach.call(formAbes, formAbe => {
var hide = IframeNode(
'#page-template',
'[data-if-empty-clear="' + formAbe.getAttribute('data-id') + '"]'
)
if (hide != null) {
hide = hide[0]
if (typeof hide !== 'undefined' && hide !== null) {
if (formAbe.value === '') {
hide.style.display = 'none'
} else {
hide.style.display = ''
}
}
}
})
}
// Array.prototype.forEach.call(formAbes, formAbe => {
// console.log('checkAttribute')
// console.log(formAbe.getAttribute('data-id'))
// // var hide = IframeNode(
// // '#page-template',
// // '[data-if-empty-clear="' + formAbe.getAttribute('data-id') + '"]'
// // )
// // if (hide != null) {
// // hide = hide[0]
// // if (typeof hide !== 'undefined' && hide !== null) {
// // if (formAbe.value === '') {
// // hide.style.display = 'none'
// // } else {
// // hide.style.display = ''
// // }
// // }
// // }
// })
// }

static scrollToInputElement(target) {
var visible = target.getAttribute('data-visible')
Expand Down
21 changes: 15 additions & 6 deletions src/server/public/abecms/scripts/utils/iframe.js
Expand Up @@ -43,13 +43,17 @@ export function IframeNode(frameId, selector) {

// searching Abe tags in <style> tags
if (result.length === 0) {
// let eachStylePattern = new RegExp(
// '[\\S\\s]*?(\\/\\*<!--ABE ' +
// key +
// '[\\S\\s]*?--->\\*\\/)([\\S\\s]*?)(\\/\\*<!--\\/ABE--->\\*\\/)[\\S\\s]*?'
// )
let eachStylePattern = new RegExp(
'[\\S\\s]*?(\\/\\*<!--ABE ' +
'(\\/\\*<!--ABE ' +
key +
'[\\S\\s]*?--->\\*\\/)([\\S\\s]*?)(\\/\\*<!--\\/ABE--->\\*\\/)[\\S\\s]*?'
)
'[\\S\\s]*?--->\\*\\/)([\\S\\s]*?)(\\/\\*<!--\\/ABE--->\\*\\/)'
)
let styles = iframe.getElementsByTagName('style')

Array.prototype.forEach.call(styles, style => {
let matchFromExec = eachStylePattern.exec(style.textContent)
if (matchFromExec != null && matchFromExec[1] != null) {
Expand All @@ -74,10 +78,15 @@ export function IframeNode(frameId, selector) {

// searching Abe tags in <script> tags
if (result.length === 0) {
// let eachScriptPattern = new RegExp(
// '[\\S\\s]*?(\\/\\*<!--ABE ' +
// key +
// '[\\S\\s]*?--->\\*\\/)([\\S\\s]*?)(\\/\\*<!--\\/ABE--->\\*\\/)[\\S\\s]*?'
// )
let eachScriptPattern = new RegExp(
'[\\S\\s]*?(\\/\\*<!--ABE ' +
'(\\/\\*<!--ABE ' +
key +
'[\\S\\s]*?--->\\*\\/)([\\S\\s]*?)(\\/\\*<!--\\/ABE--->\\*\\/)[\\S\\s]*?'
'[\\S\\s]*?--->\\*\\/)([\\S\\s]*?)(\\/\\*<!--\\/ABE--->\\*\\/)'
)
let scripts = iframe.getElementsByTagName('script')

Expand Down
1 change: 0 additions & 1 deletion src/server/sass/modules/_editor-tabs.scss
Expand Up @@ -4,7 +4,6 @@
background-color: #fff;
padding: 20px 10px 10px;
border-top: none;
overflow: hidden;
height: 100%;
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/sass/modules/_editor.scss
Expand Up @@ -20,7 +20,7 @@ body {
padding-top: 24px;
}
#abeForm{
padding-bottom: 50px;
margin-bottom: 50px;
}
.icon{
position: relative;
Expand Down

0 comments on commit 4674ec7

Please sign in to comment.