Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/components/VStep.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default {
data () {
return {
hash: sum(this.step.target),
targetElement: document.querySelector(this.step.target)
targetElement: this.step.target.startsWith('.') ? this.wrapTargets(this.step.target) : document.querySelector(this.step.target)
}
},
computed: {
Expand All @@ -104,6 +104,22 @@ export default {
}
},
methods: {
wrapTargets (targetClassSelector) {
/**
* Given a target class selector, wrap the elements identified by the selector, and
* insert the wrapped elements at the beginning of the parent. Additionally set the
* id attribute on the wrapper element.
* Note: This will likely be ugly if the target elements aren't next to each other.
*/
const elements = document.querySelectorAll(targetClassSelector)
const wrapper = document.createElement('div')
elements[0].parentNode.insertBefore(wrapper, elements[0])
for (let el of elements) {
wrapper.appendChild(el)
}
wrapper.setAttribute('id', targetClassSelector.replace(/\./, ''))
return wrapper
},
createStep () {
if (this.debug) {
console.log('[Vue Tour] The target element ' + this.step.target + ' of .v-step[id="' + this.hash + '"] is:', this.targetElement)
Expand Down