Skip to content
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

added function spinWithClickShield that adds a click shield to block use... #289

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
46 changes: 38 additions & 8 deletions spin.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,31 @@
Spinner.defaults = {}

merge(Spinner.prototype, {
/**
* Adds the spinner to the given target element. If this instance is already
* spinning, it is automatically removed from its previous target b calling
* stop() internally. It will create a modal that blocks clicks with the
* CSS class name provided.
*/
spinWithClickShield: function (target, clickShieldClassName) {
this.spin(target)
var self = this
var o = self.opts
clickShieldClassName = clickShieldClassName || o.clickShieldClassName
var clickShieldEl = self.clickShieldEl = css(createEl(0, { className: clickShieldClassName }), { position: o.position, width: '100%', zIndex: o.zIndex })

css(clickShieldEl, {
left: 0,
top: 0,
right: 0,
bottom: 0
})

if (target) {
target.insertBefore(clickShieldEl, target.firstChild || null)
}
return self
},

/**
* Adds the spinner to the given target element. If this instance is already
Expand Down Expand Up @@ -199,14 +224,19 @@
/**
* Stops and removes the Spinner.
*/
stop: function() {
var el = this.el
if (el) {
clearTimeout(this.timeout)
if (el.parentNode) el.parentNode.removeChild(el)
this.el = undefined
}
return this
stop: function () {
var self = this;
var removeElement = function (target) {
if (target) {
clearTimeout(self.timeout)
if (target.parentNode) target.parentNode.removeChild(target)
}
}
removeElement(self.el)
self.el = undefined
removeElement(self.clickShieldEl)
self.clickShieldEl = undefined
return this
},

/**
Expand Down