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

Tingle preloader #164

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions dist/tingle.css
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,30 @@
}
}

/* preloader
-------------------------------------------------------------- */

.tingle-preloader {
visibility: hidden;
opacity: 0;

position: fixed;
top: 50%;
left: 50%;
width: 200px;
height: 200px;
transform: translateX(-50%) translateY(-50%);

transition: 500ms;
}

.tingle-preloader.tingle-preloader--active {
visibility: visible;
opacity: 1;
transition: 500ms;
}


/* animations
-------------------------------------------------------------- */

Expand Down
37 changes: 35 additions & 2 deletions dist/tingle.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @license MIT
*/

// @ts-check
/* global define, module */
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
Expand All @@ -20,6 +21,11 @@
/* ----------------------------------------------------------- */

var isBusy = false
var isLoading = false

var elements = {
preloader: document.querySelector('.tingle-preloader')
}

function Modal (options) {
var defaults = {
Expand Down Expand Up @@ -50,7 +56,7 @@
_bindEvents.call(this)

// insert modal in dom
document.body.appendChild(this.modal, document.body.firstChild)
document.body.appendChild(this.modal)

if (this.opts.footer) {
this.addFooter()
Expand All @@ -59,6 +65,14 @@
return this
}

Modal.prototype._loading = function (_isLoading) {
isLoading = _isLoading
}

Modal.prototype._isLoading = function () {
return isLoading
}

Modal.prototype._busy = function (state) {
isBusy = state
}
Expand Down Expand Up @@ -94,6 +108,9 @@
if (this._isBusy()) return
this._busy(true)

// Reset loading flag
this.hidePreloader()

var self = this

// before open callback
Expand Down Expand Up @@ -289,6 +306,22 @@
}
}

Modal.prototype.showPreloader = function () {
if (!this._isLoading()) {
this._loading(true)
if (elements.preloader) {
elements.preloader.classList.add('tingle-preloader--active')
}
}
}

Modal.prototype.hidePreloader = function () {
this._loading(false)
if (elements.preloader) {
elements.preloader.classList.remove('tingle-preloader--active')
}
}

/* ----------------------------------------------------------- */
/* == private methods */
/* ----------------------------------------------------------- */
Expand All @@ -310,7 +343,7 @@
this.modal = document.createElement('div')
this.modal.classList.add('tingle-modal')

// remove cusor if no overlay close method
// remove cursor if no overlay close method
if (this.opts.closeMethods.length === 0 || this.opts.closeMethods.indexOf('overlay') === -1) {
this.modal.classList.add('tingle-modal--noOverlayClose')
}
Expand Down
2 changes: 1 addition & 1 deletion dist/tingle.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading