Skip to content

Commit bb01f01

Browse files
Merge pull request lusaxweb#247 from OzairP/master
Support passing Element into loading container property
2 parents c0dc327 + 03bec5c commit bb01f01

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

docs/components/loading.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ API:
1010
parameters:
1111
description: function to close loading.
1212
default: null
13+
- name: container
14+
type: HTMLElement, String
15+
parameters: null
16+
description: Container that will be loading, pass a HTMLElement or query selector
17+
default: null
1318
- name: color
1419
type: String
1520
parameters: RGB, HEX, primary, danger, success, dark, warning
@@ -325,7 +330,7 @@ For the examples, the request or the delay is simulated with `setTimeout`.
325330
```html
326331
<template lang="html">
327332
<div class="centerx">
328-
<vs-button id="button-with-loading" class="vs-con-loading__container" @click="openLoadingContained" vs-type="relief" vs-color="primary">Button with Loading</vs-button>
333+
<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>
329334
<vs-button @click="openLoadingInDiv" vs-type="relief" vs-color="primary">Div with Loading</vs-button>
330335
<div class="fill-row">
331336
<div id="div-with-loading" class="vs-con-loading__container">Load Me!</div>
@@ -346,11 +351,11 @@ export default {
346351
this.$vs.loading({
347352
background: this.backgroundLoading,
348353
color: this.colorLoading,
349-
container: '#button-with-loading',
354+
container: this.refs.loadableButton,
350355
scale: 0.45
351356
})
352357
setTimeout( ()=> {
353-
this.$vs.loading.close('#button-with-loading > .con-vs-loading')
358+
this.$vs.loading.close(this.refs.loadableButton)
354359
}, 3000);
355360
},
356361
openLoadingInDiv(){

src/functions/vsLoading/index.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,29 @@ export default {
1616
instance.$data.text = parameters.text
1717
instance.$data.clickEffect = parameters.clickEffect
1818
if(parameters.container) {
19-
containerx = document.querySelector(parameters.container)
19+
containerx = parameters.container instanceof Element ? parameters.container : document.querySelector(parameters.container)
2020
}
2121
}
2222
instance.vm = instance.$mount();
2323
containerx.insertBefore(instance.vm.$el, containerx.firstChild)
2424
},
2525
close(elx){
26-
let el = elx || 'body > .con-vs-loading'
27-
let loadings = document.querySelectorAll(el)
28-
loadings.forEach((loading)=>{
29-
loading.classList.add('beforeRemove')
30-
setTimeout(()=>{
31-
loading.remove()
32-
},300)
33-
})
26+
let loadings
27+
28+
if (elx instanceof Element) {
29+
// Mimicking the behavior of doing `elx.querySelectorAll('> .con-vs-loading')` but `>` is not well supported.
30+
// We are doing this because we can only add the respective classes to .con-vs-loading
31+
loadings = Array.from(elx.children).filter(el => el.classList.contains('.con-vs-loading'))
32+
} else {
33+
loadings = document.querySelectorAll(elx || 'body > .con-vs-loading')
34+
}
35+
36+
loadings
37+
.forEach((loading)=>{
38+
loading.classList.add('beforeRemove')
39+
setTimeout(()=>{
40+
loading.remove()
41+
},300)
42+
})
3443
}
3544
}

0 commit comments

Comments
 (0)