Skip to content

Support passing Element into loading container property #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
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
11 changes: 8 additions & 3 deletions docs/components/loading.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ API:
parameters:
description: function to close loading.
default: null
- name: container
type: HTMLElement, String
parameters: null
description: Container that will be loading, pass a HTMLElement or query selector
default: null
- name: color
type: String
parameters: RGB, HEX, primary, danger, success, dark, warning
Expand Down Expand Up @@ -325,7 +330,7 @@ For the examples, the request or the delay is simulated with `setTimeout`.
```html
<template lang="html">
<div class="centerx">
<vs-button id="button-with-loading" class="vs-con-loading__container" @click="openLoadingContained" vs-type="relief" vs-color="primary">Button with Loading</vs-button>
<vs-button ref="loadableButton" id="button-with-loading" class="vs-con-loading__container" @click="openLoadingContained" vs-type="relief" vs-color="primary">Button with Loading</vs-button>
<vs-button @click="openLoadingInDiv" vs-type="relief" vs-color="primary">Div with Loading</vs-button>
<div class="fill-row">
<div id="div-with-loading" class="vs-con-loading__container">Load Me!</div>
Expand All @@ -346,11 +351,11 @@ export default {
this.$vs.loading({
background: this.backgroundLoading,
color: this.colorLoading,
container: '#button-with-loading',
container: this.refs.loadableButton,
scale: 0.45
})
setTimeout( ()=> {
this.$vs.loading.close('#button-with-loading > .con-vs-loading')
this.$vs.loading.close(this.refs.loadableButton)
}, 3000);
},
openLoadingInDiv(){
Expand Down
27 changes: 18 additions & 9 deletions src/functions/vsLoading/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,29 @@ export default {
instance.$data.text = parameters.text
instance.$data.clickEffect = parameters.clickEffect
if(parameters.container) {
containerx = document.querySelector(parameters.container)
containerx = parameters.container instanceof Element ? parameters.container : document.querySelector(parameters.container)
}
}
instance.vm = instance.$mount();
containerx.insertBefore(instance.vm.$el, containerx.firstChild)
},
close(elx){
let el = elx || 'body > .con-vs-loading'
let loadings = document.querySelectorAll(el)
loadings.forEach((loading)=>{
loading.classList.add('beforeRemove')
setTimeout(()=>{
loading.remove()
},300)
})
let loadings

if (elx instanceof Element) {
// Mimicking the behavior of doing `elx.querySelectorAll('> .con-vs-loading')` but `>` is not well supported.
// We are doing this because we can only add the respective classes to .con-vs-loading
loadings = Array.from(elx.children).filter(el => el.classList.contains('.con-vs-loading'))
} else {
loadings = document.querySelectorAll(elx || 'body > .con-vs-loading')
}

loadings
.forEach((loading)=>{
loading.classList.add('beforeRemove')
setTimeout(()=>{
loading.remove()
},300)
})
}
}