Skip to content

Commit

Permalink
enhancement: fix the autocomplete rebind + escaping the selector (to …
Browse files Browse the repository at this point in the history
…be able to detect id including []
  • Loading branch information
gregorybesson committed Jan 1, 2017
1 parent 6ce435a commit ca9d237
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/server/public/abejs/scripts/modules/EditorAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export default class EditorAutocomplete {
this._handleSelectValue = this._selectValue.bind(this)
this._handleRefresh = this._refresh.bind(this)

this._autocompletesRemove = [].slice.call(document.querySelectorAll('[data-autocomplete-remove=true]'))
this._autocompletes = [].slice.call(document.querySelectorAll('[data-autocomplete=true]'))
this._autocompletesRefresh = [].slice.call(document.querySelectorAll('[data-autocomplete-refresh=true]'))

this._currentInput = null
this._divWrapper = document.createElement('div')
this._divWrapper.classList.add('autocomplete-wrapper')
Expand All @@ -38,6 +34,10 @@ export default class EditorAutocomplete {
}

rebind() {
this._autocompletesRemove = [].slice.call(document.querySelectorAll('[data-autocomplete-remove=true]'))
this._autocompletes = [].slice.call(document.querySelectorAll('[data-autocomplete=true]'))
this._autocompletesRefresh = [].slice.call(document.querySelectorAll('[data-autocomplete-refresh=true]'))

document.body.removeEventListener('mouseup', this._handleDocumentClick)
document.body.addEventListener('mouseup', this._handleDocumentClick)

Expand Down Expand Up @@ -96,7 +96,6 @@ export default class EditorAutocomplete {
eval(`json.${id} = ${JSON.stringify(toSave)}`)

this._json.data = json

if(typeof nodeComments !== 'undefined' && nodeComments !== null && nodeComments.length > 0) {

try {
Expand Down Expand Up @@ -476,7 +475,8 @@ export default class EditorAutocomplete {

_remove(e) {
var target = e.currentTarget.parentNode
this._currentInput = document.querySelector(`#${target.getAttribute('data-parent-id')}`)
var escapedSelector = target.getAttribute('data-parent-id').replace(/(:|\.|\[|\])/g,'\\$1')
this._currentInput = document.querySelector(`#${escapedSelector}`)
target.parentNode.removeChild(target)
this._saveData()
this._currentInput = null
Expand Down

0 comments on commit ca9d237

Please sign in to comment.