izitoast 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/izitoast.gemspec +35 -0
- data/lib/izitoast.rb +5 -0
- data/lib/izitoast/version.rb +3 -0
- data/vendor/assets/javascripts/iziToast.js +791 -0
- data/vendor/assets/stylesheets/iziToast.css +1620 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 459868307a4489ece61211b3137bd9c78c81c88a
|
4
|
+
data.tar.gz: 33c8b5aea7e02eb7fd81dbcd3d4e24aabf27792c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b61d837ca40732ec100d4da9b40a3d667e070278e4784ba3426c4e4f1165e6ca667a6c8d91fe88bdbad2578a91d088f06b43455f31d00a6ca7203e07c77d340c
|
7
|
+
data.tar.gz: 70810c709c4f98787857ee7cc47bc17212887982f9e2cbb06c10c820b4c8b3753559df1202901f2243be67f7c728235b019ed23adebdbe757ccfa9d7191bb83e
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at badalloffsh@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Shamil
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Izitoast
|
2
|
+
|
3
|
+
Simple wrapper around [IZITOAST](http://izitoast.marcelodolce.com) js notification plugin [visit Authors website.](https://www.google.com "Marcelo Dolce")
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'izitoast'
|
12
|
+
```
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
|
18
|
+
Add this line to your application.js file:
|
19
|
+
|
20
|
+
```javascript
|
21
|
+
//= require iziToast
|
22
|
+
```
|
23
|
+
|
24
|
+
Add this line to your application.scss (css):
|
25
|
+
|
26
|
+
```scss
|
27
|
+
@import "iziToast";
|
28
|
+
```
|
29
|
+
|
30
|
+
That's it. It works now
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
To test how it works, open your browser console and execute next command:
|
34
|
+
|
35
|
+
```javascript
|
36
|
+
iziToast.success({
|
37
|
+
title: 'Hey',
|
38
|
+
message: "It's alive! Congratulations!"
|
39
|
+
});
|
40
|
+
```
|
41
|
+
|
42
|
+
You will see notification in the bottom-right corner of your browser.
|
43
|
+
|
44
|
+
To find more about usage options, please [visit Authors website.](https://www.google.com "Marcelo Dolce")
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/BadAllOff/izitoast. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
49
|
+
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
54
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "izitoast"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/izitoast.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'izitoast/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "izitoast"
|
8
|
+
spec.version = Izitoast::VERSION
|
9
|
+
spec.authors = ["Shamil"]
|
10
|
+
spec.email = ["badalloffsh@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Simple wrapper around IZITOAST js notification plugin}
|
13
|
+
spec.description = %q{}
|
14
|
+
spec.homepage = "https://github.com/BadAllOff/iziToast-rails"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
end
|
data/lib/izitoast.rb
ADDED
@@ -0,0 +1,791 @@
|
|
1
|
+
/*
|
2
|
+
* iziToast | v1.1.1
|
3
|
+
* http://izitoast.marcelodolce.com
|
4
|
+
* by Marcelo Dolce.
|
5
|
+
*/
|
6
|
+
(function (root, factory) {
|
7
|
+
if (typeof define === 'function' && define.amd) {
|
8
|
+
define([], factory(root));
|
9
|
+
} else if (typeof exports === 'object') {
|
10
|
+
module.exports = factory(root);
|
11
|
+
} else {
|
12
|
+
root.iziToast = factory(root);
|
13
|
+
}
|
14
|
+
})(typeof global !== "undefined" ? global : this.window || this.global, function (root) {
|
15
|
+
|
16
|
+
'use strict';
|
17
|
+
|
18
|
+
//
|
19
|
+
// Variables
|
20
|
+
//
|
21
|
+
var $iziToast = {},
|
22
|
+
PLUGIN_NAME = 'iziToast',
|
23
|
+
BODY = document.querySelector('body'),
|
24
|
+
ISMOBILE = (/Mobi/.test(navigator.userAgent)) ? true : false,
|
25
|
+
ISCHROME = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor),
|
26
|
+
ISFIREFOX = typeof InstallTrigger !== 'undefined',
|
27
|
+
ACCEPTSTOUCH = 'ontouchstart' in document.documentElement,
|
28
|
+
POSITIONS = ['bottomRight','bottomLeft','bottomCenter','topRight','topLeft','topCenter','center'],
|
29
|
+
THEMES = {
|
30
|
+
info: {
|
31
|
+
color: "blue",
|
32
|
+
icon: "ico-info"
|
33
|
+
},
|
34
|
+
success: {
|
35
|
+
color: "green",
|
36
|
+
icon: "ico-check",
|
37
|
+
},
|
38
|
+
warning: {
|
39
|
+
color: "yellow",
|
40
|
+
icon: "ico-warning",
|
41
|
+
},
|
42
|
+
error: {
|
43
|
+
color: "red",
|
44
|
+
icon: "ico-error",
|
45
|
+
}
|
46
|
+
},
|
47
|
+
MOBILEWIDTH = 568,
|
48
|
+
CONFIG = {};
|
49
|
+
|
50
|
+
// Default settings
|
51
|
+
var defaults = {
|
52
|
+
class: '',
|
53
|
+
title: '',
|
54
|
+
titleColor: '',
|
55
|
+
message: '',
|
56
|
+
messageColor: '',
|
57
|
+
backgroundColor: '',
|
58
|
+
color: '', // blue, red, green, yellow
|
59
|
+
icon: '',
|
60
|
+
iconText: '',
|
61
|
+
iconColor: '',
|
62
|
+
image: '',
|
63
|
+
imageWidth: 50,
|
64
|
+
zindex: 99999,
|
65
|
+
layout: 1,
|
66
|
+
balloon: false,
|
67
|
+
close: true,
|
68
|
+
rtl: false,
|
69
|
+
position: 'bottomRight', // bottomRight, bottomLeft, topRight, topLeft, topCenter, bottomCenter, center
|
70
|
+
target: '',
|
71
|
+
targetFirst: true,
|
72
|
+
timeout: 5000,
|
73
|
+
drag: true,
|
74
|
+
pauseOnHover: true,
|
75
|
+
resetOnHover: false,
|
76
|
+
progressBar: true,
|
77
|
+
progressBarColor: '',
|
78
|
+
animateInside: true,
|
79
|
+
buttons: {},
|
80
|
+
transitionIn: 'fadeInUp', // bounceInLeft, bounceInRight, bounceInUp, bounceInDown, fadeIn, fadeInDown, fadeInUp, fadeInLeft, fadeInRight, flipInX
|
81
|
+
transitionOut: 'fadeOut', // fadeOut, fadeOutUp, fadeOutDown, fadeOutLeft, fadeOutRight, flipOutX
|
82
|
+
transitionInMobile: 'fadeInUp',
|
83
|
+
transitionOutMobile: 'fadeOutDown',
|
84
|
+
onOpen: function () {},
|
85
|
+
onClose: function () {}
|
86
|
+
};
|
87
|
+
|
88
|
+
//
|
89
|
+
// Methods
|
90
|
+
//
|
91
|
+
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Polyfill for remove() method
|
95
|
+
*/
|
96
|
+
if (!('remove' in Element.prototype)) {
|
97
|
+
Element.prototype.remove = function() {
|
98
|
+
if (this.parentNode) {
|
99
|
+
this.parentNode.removeChild(this);
|
100
|
+
}
|
101
|
+
};
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
* A simple forEach() implementation for Arrays, Objects and NodeLists
|
106
|
+
* @private
|
107
|
+
* @param {Array|Object|NodeList} collection Collection of items to iterate
|
108
|
+
* @param {Function} callback Callback function for each iteration
|
109
|
+
* @param {Array|Object|NodeList} scope Object/NodeList/Array that forEach is iterating over (aka `this`)
|
110
|
+
*/
|
111
|
+
var forEach = function (collection, callback, scope) {
|
112
|
+
if (Object.prototype.toString.call(collection) === '[object Object]') {
|
113
|
+
for (var prop in collection) {
|
114
|
+
if (Object.prototype.hasOwnProperty.call(collection, prop)) {
|
115
|
+
callback.call(scope, collection[prop], prop, collection);
|
116
|
+
}
|
117
|
+
}
|
118
|
+
} else {
|
119
|
+
if(collection){
|
120
|
+
for (var i = 0, len = collection.length; i < len; i++) {
|
121
|
+
callback.call(scope, collection[i], i, collection);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
};
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Merge defaults with user options
|
129
|
+
* @private
|
130
|
+
* @param {Object} defaults Default settings
|
131
|
+
* @param {Object} options User options
|
132
|
+
* @returns {Object} Merged values of defaults and options
|
133
|
+
*/
|
134
|
+
var extend = function (defaults, options) {
|
135
|
+
var extended = {};
|
136
|
+
forEach(defaults, function (value, prop) {
|
137
|
+
extended[prop] = defaults[prop];
|
138
|
+
});
|
139
|
+
forEach(options, function (value, prop) {
|
140
|
+
extended[prop] = options[prop];
|
141
|
+
});
|
142
|
+
return extended;
|
143
|
+
};
|
144
|
+
|
145
|
+
|
146
|
+
/**
|
147
|
+
* Create a fragment DOM elements
|
148
|
+
* @private
|
149
|
+
*/
|
150
|
+
var createFragElem = function(htmlStr) {
|
151
|
+
var frag = document.createDocumentFragment(),
|
152
|
+
temp = document.createElement('div');
|
153
|
+
temp.innerHTML = htmlStr;
|
154
|
+
while (temp.firstChild) {
|
155
|
+
frag.appendChild(temp.firstChild);
|
156
|
+
}
|
157
|
+
return frag;
|
158
|
+
};
|
159
|
+
|
160
|
+
|
161
|
+
/**
|
162
|
+
* Check if is a color
|
163
|
+
* @private
|
164
|
+
*/
|
165
|
+
var isColor = function(color){
|
166
|
+
if( color.substring(0,1) == "#" || color.substring(0,3) == "rgb" || color.substring(0,3) == "hsl" ){
|
167
|
+
return true;
|
168
|
+
} else {
|
169
|
+
return false;
|
170
|
+
}
|
171
|
+
};
|
172
|
+
|
173
|
+
|
174
|
+
/**
|
175
|
+
* Drag method of toasts
|
176
|
+
* @private
|
177
|
+
*/
|
178
|
+
var drag = function() {
|
179
|
+
|
180
|
+
return {
|
181
|
+
move: function(toast, instance, settings, xpos) {
|
182
|
+
|
183
|
+
var opacity,
|
184
|
+
opacityRange = 0.3,
|
185
|
+
distance = 180;
|
186
|
+
|
187
|
+
toast.style.transform = 'translateX('+xpos + 'px)';
|
188
|
+
|
189
|
+
if(xpos > 0){
|
190
|
+
opacity = (distance-xpos) / distance;
|
191
|
+
if(opacity < opacityRange){
|
192
|
+
instance.hide(extend(settings, { transitionOut: 'fadeOutRight', transitionOutMobile: 'fadeOutRight' }), toast, 'drag');
|
193
|
+
}
|
194
|
+
} else {
|
195
|
+
opacity = (distance+xpos) / distance;
|
196
|
+
if(opacity < opacityRange){
|
197
|
+
instance.hide(extend(settings, { transitionOut: 'fadeOutLeft', transitionOutMobile: 'fadeOutLeft' }), toast, 'drag');
|
198
|
+
}
|
199
|
+
}
|
200
|
+
toast.style.opacity = opacity;
|
201
|
+
|
202
|
+
if(opacity < opacityRange){
|
203
|
+
|
204
|
+
if(ISCHROME || ISFIREFOX)
|
205
|
+
toast.style.left = xpos+'px';
|
206
|
+
|
207
|
+
toast.parentNode.style.opacity = opacityRange;
|
208
|
+
|
209
|
+
this.stopMoving(toast, null);
|
210
|
+
}
|
211
|
+
|
212
|
+
},
|
213
|
+
startMoving: function(toast, instance, settings, e) {
|
214
|
+
|
215
|
+
e = e || window.event;
|
216
|
+
var posX = ((ACCEPTSTOUCH) ? e.touches[0].clientX : e.clientX),
|
217
|
+
toastLeft = toast.style.transform.replace('px)', '');
|
218
|
+
toastLeft = toastLeft.replace('translateX(', '');
|
219
|
+
var offsetX = posX - toastLeft;
|
220
|
+
|
221
|
+
toast.classList.remove(settings.transitionIn);
|
222
|
+
toast.classList.remove(settings.transitionInMobile);
|
223
|
+
toast.style.transition = "";
|
224
|
+
|
225
|
+
if (ACCEPTSTOUCH) {
|
226
|
+
document.ontouchmove = function(e) {
|
227
|
+
e.preventDefault();
|
228
|
+
e = e || window.event;
|
229
|
+
var posX = e.touches[0].clientX,
|
230
|
+
finalX = posX - offsetX;
|
231
|
+
drag.move(toast, instance, settings, finalX);
|
232
|
+
};
|
233
|
+
} else {
|
234
|
+
document.onmousemove = function(e) {
|
235
|
+
e.preventDefault();
|
236
|
+
e = e || window.event;
|
237
|
+
var posX = e.clientX,
|
238
|
+
finalX = posX - offsetX;
|
239
|
+
drag.move(toast, instance, settings, finalX);
|
240
|
+
};
|
241
|
+
}
|
242
|
+
|
243
|
+
},
|
244
|
+
stopMoving: function(toast, e) {
|
245
|
+
|
246
|
+
if (ACCEPTSTOUCH) {
|
247
|
+
document.ontouchmove = function() {};
|
248
|
+
} else {
|
249
|
+
document.onmousemove = function() {};
|
250
|
+
}
|
251
|
+
toast.style.transition = "transform 0.4s ease, opacity 0.4s ease";
|
252
|
+
toast.style.opacity = "";
|
253
|
+
toast.style.transform = "";
|
254
|
+
window.setTimeout(function() {
|
255
|
+
toast.style.transition = "";
|
256
|
+
}, 400);
|
257
|
+
}
|
258
|
+
};
|
259
|
+
|
260
|
+
}();
|
261
|
+
|
262
|
+
|
263
|
+
/**
|
264
|
+
* Do the calculation to move the progress bar
|
265
|
+
* @private
|
266
|
+
*/
|
267
|
+
var moveProgress = function(toast, settings, callback){
|
268
|
+
|
269
|
+
var isPaused = false;
|
270
|
+
var isReseted = false;
|
271
|
+
var isClosed = false;
|
272
|
+
var timerTimeout = null;
|
273
|
+
var elem = toast.querySelector("."+PLUGIN_NAME+"-progressbar div");
|
274
|
+
var progressBar = {
|
275
|
+
hideEta: null,
|
276
|
+
maxHideTime: null,
|
277
|
+
currentTime: new Date().getTime(),
|
278
|
+
updateProgress: function()
|
279
|
+
{
|
280
|
+
isPaused = toast.classList.contains(PLUGIN_NAME+'-paused') ? true : false;
|
281
|
+
isReseted = toast.classList.contains(PLUGIN_NAME+'-reseted') ? true : false;
|
282
|
+
isClosed = toast.classList.contains(PLUGIN_NAME+'-closed') ? true : false;
|
283
|
+
|
284
|
+
if(isReseted){
|
285
|
+
clearTimeout(timerTimeout);
|
286
|
+
elem.style.width = '100%';
|
287
|
+
moveProgress(toast, settings, callback);
|
288
|
+
toast.classList.remove(PLUGIN_NAME+'-reseted');
|
289
|
+
}
|
290
|
+
if(isClosed){
|
291
|
+
clearTimeout(timerTimeout);
|
292
|
+
toast.classList.remove(PLUGIN_NAME+'-closed');
|
293
|
+
}
|
294
|
+
|
295
|
+
if(!isPaused && !isReseted && !isClosed){
|
296
|
+
progressBar.currentTime = progressBar.currentTime+10;
|
297
|
+
var percentage = ((progressBar.hideEta - (progressBar.currentTime)) / progressBar.maxHideTime) * 100;
|
298
|
+
elem.style.width = percentage + '%';
|
299
|
+
|
300
|
+
if(Math.round(percentage) < 0 || typeof toast != 'object'){
|
301
|
+
clearTimeout(timerTimeout);
|
302
|
+
callback.apply();
|
303
|
+
}
|
304
|
+
}
|
305
|
+
|
306
|
+
}
|
307
|
+
};
|
308
|
+
if (settings.timeout > 0) {
|
309
|
+
progressBar.maxHideTime = parseFloat(settings.timeout);
|
310
|
+
progressBar.hideEta = new Date().getTime() + progressBar.maxHideTime;
|
311
|
+
timerTimeout = setInterval(progressBar.updateProgress, 10);
|
312
|
+
}
|
313
|
+
};
|
314
|
+
|
315
|
+
/**
|
316
|
+
* Destroy the current initialization.
|
317
|
+
* @public
|
318
|
+
*/
|
319
|
+
$iziToast.destroy = function () {
|
320
|
+
|
321
|
+
forEach(document.querySelectorAll('.'+PLUGIN_NAME+'-wrapper'), function(element, index) {
|
322
|
+
element.remove();
|
323
|
+
});
|
324
|
+
|
325
|
+
forEach(document.querySelectorAll('.'+PLUGIN_NAME), function(element, index) {
|
326
|
+
element.remove();
|
327
|
+
});
|
328
|
+
|
329
|
+
// Remove event listeners
|
330
|
+
document.removeEventListener(PLUGIN_NAME+'-open', {}, false);
|
331
|
+
document.removeEventListener(PLUGIN_NAME+'-close', {}, false);
|
332
|
+
|
333
|
+
// Reset variables
|
334
|
+
CONFIG = {};
|
335
|
+
};
|
336
|
+
|
337
|
+
/**
|
338
|
+
* Initialize Plugin
|
339
|
+
* @public
|
340
|
+
* @param {Object} options User settings
|
341
|
+
*/
|
342
|
+
$iziToast.settings = function (options) {
|
343
|
+
|
344
|
+
// Destroy any existing initializations
|
345
|
+
$iziToast.destroy();
|
346
|
+
|
347
|
+
CONFIG = options;
|
348
|
+
defaults = extend(defaults, options || {});
|
349
|
+
};
|
350
|
+
|
351
|
+
|
352
|
+
/**
|
353
|
+
* Building themes functions.
|
354
|
+
* @public
|
355
|
+
* @param {Object} options User settings
|
356
|
+
*/
|
357
|
+
forEach(THEMES, function (theme, name) {
|
358
|
+
|
359
|
+
$iziToast[name] = function (options) {
|
360
|
+
|
361
|
+
var settings = extend(CONFIG, options || {});
|
362
|
+
settings = extend(theme, settings || {});
|
363
|
+
|
364
|
+
this.show(settings);
|
365
|
+
};
|
366
|
+
|
367
|
+
});
|
368
|
+
|
369
|
+
|
370
|
+
/**
|
371
|
+
* Close the specific Toast
|
372
|
+
* @public
|
373
|
+
* @param {Object} options User settings
|
374
|
+
*/
|
375
|
+
$iziToast.hide = function (options, $toast, closedBy) {
|
376
|
+
|
377
|
+
var settings = extend(defaults, options || {});
|
378
|
+
closedBy = closedBy || false;
|
379
|
+
|
380
|
+
if(typeof $toast != 'object'){
|
381
|
+
$toast = document.querySelector($toast);
|
382
|
+
}
|
383
|
+
$toast.classList.add(PLUGIN_NAME+'-closed');
|
384
|
+
|
385
|
+
if(settings.transitionIn || settings.transitionInMobile){
|
386
|
+
$toast.classList.remove(settings.transitionIn);
|
387
|
+
$toast.classList.remove(settings.transitionInMobile);
|
388
|
+
}
|
389
|
+
|
390
|
+
if(ISMOBILE || window.innerWidth <= MOBILEWIDTH){
|
391
|
+
if(settings.transitionOutMobile)
|
392
|
+
$toast.classList.add(settings.transitionOutMobile);
|
393
|
+
} else{
|
394
|
+
if(settings.transitionOut)
|
395
|
+
$toast.classList.add(settings.transitionOut);
|
396
|
+
}
|
397
|
+
var H = $toast.parentNode.offsetHeight;
|
398
|
+
$toast.parentNode.style.height = H+'px';
|
399
|
+
$toast.style.pointerEvents = 'none';
|
400
|
+
|
401
|
+
if(!ISMOBILE || window.innerWidth > MOBILEWIDTH){
|
402
|
+
$toast.parentNode.style.transitionDelay = '0.2s';
|
403
|
+
}
|
404
|
+
|
405
|
+
setTimeout(function() {
|
406
|
+
$toast.parentNode.style.height = '0px';
|
407
|
+
$toast.parentNode.style.overflow = '';
|
408
|
+
window.setTimeout(function(){
|
409
|
+
$toast.parentNode.remove();
|
410
|
+
},1000);
|
411
|
+
},200);
|
412
|
+
|
413
|
+
if (settings.class){
|
414
|
+
try {
|
415
|
+
var event;
|
416
|
+
if (window.CustomEvent) {
|
417
|
+
event = new CustomEvent(PLUGIN_NAME+'-close', {detail: {class: settings.class}});
|
418
|
+
} else {
|
419
|
+
event = document.createEvent('CustomEvent');
|
420
|
+
event.initCustomEvent(PLUGIN_NAME+'-close', true, true, {class: settings.class});
|
421
|
+
}
|
422
|
+
document.dispatchEvent(event);
|
423
|
+
} catch(ex){
|
424
|
+
console.warn(ex);
|
425
|
+
}
|
426
|
+
}
|
427
|
+
|
428
|
+
if(typeof settings.onClose !== "undefined"){
|
429
|
+
settings.onClose.apply(null, [settings, $toast, closedBy]);
|
430
|
+
}
|
431
|
+
};
|
432
|
+
|
433
|
+
/**
|
434
|
+
* Create and show the Toast
|
435
|
+
* @public
|
436
|
+
* @param {Object} options User settings
|
437
|
+
*/
|
438
|
+
$iziToast.show = function (options) {
|
439
|
+
|
440
|
+
var that = this;
|
441
|
+
|
442
|
+
// Merge user options with defaults
|
443
|
+
var settings = extend(CONFIG, options || {});
|
444
|
+
settings = extend(defaults, settings);
|
445
|
+
|
446
|
+
var $toastCapsule = document.createElement("div");
|
447
|
+
$toastCapsule.classList.add(PLUGIN_NAME+"-capsule");
|
448
|
+
|
449
|
+
var $toast = document.createElement("div");
|
450
|
+
$toast.classList.add(PLUGIN_NAME);
|
451
|
+
|
452
|
+
if(ISMOBILE || window.innerWidth <= MOBILEWIDTH){
|
453
|
+
if(settings.transitionInMobile.length>0)
|
454
|
+
$toast.classList.add(settings.transitionInMobile);
|
455
|
+
} else {
|
456
|
+
if(settings.transitionIn.length>0)
|
457
|
+
$toast.classList.add(settings.transitionIn);
|
458
|
+
}
|
459
|
+
|
460
|
+
if(settings.rtl){
|
461
|
+
$toast.classList.add(PLUGIN_NAME + '-rtl');
|
462
|
+
}
|
463
|
+
|
464
|
+
if (settings.color.length > 0) { //#, rgb, rgba, hsl
|
465
|
+
|
466
|
+
if( isColor(settings.color) ){
|
467
|
+
$toast.style.background = settings.color;
|
468
|
+
} else {
|
469
|
+
$toast.classList.add(PLUGIN_NAME+'-color-'+settings.color);
|
470
|
+
}
|
471
|
+
}
|
472
|
+
if (settings.backgroundColor.length > 0) {
|
473
|
+
$toast.style.background = settings.backgroundColor;
|
474
|
+
}
|
475
|
+
|
476
|
+
if (settings.class){
|
477
|
+
$toast.classList.add(settings.class);
|
478
|
+
}
|
479
|
+
|
480
|
+
if (settings.image) {
|
481
|
+
var $cover = document.createElement("div");
|
482
|
+
$cover.classList.add(PLUGIN_NAME + '-cover');
|
483
|
+
$cover.style.width = settings.imageWidth + "px";
|
484
|
+
$cover.style.backgroundImage = 'url(' + settings.image + ')';
|
485
|
+
$toast.appendChild($cover);
|
486
|
+
}
|
487
|
+
|
488
|
+
var $buttonClose;
|
489
|
+
if(settings.close){
|
490
|
+
$buttonClose = document.createElement("button");
|
491
|
+
$buttonClose.classList.add(PLUGIN_NAME + '-close');
|
492
|
+
$toast.appendChild($buttonClose);
|
493
|
+
} else {
|
494
|
+
if(settings.rtl){
|
495
|
+
$toast.style.paddingLeft = "30px";
|
496
|
+
} else {
|
497
|
+
$toast.style.paddingRight = "30px";
|
498
|
+
}
|
499
|
+
}
|
500
|
+
|
501
|
+
if (settings.progressBar) {
|
502
|
+
|
503
|
+
var $progressBar = document.createElement("div");
|
504
|
+
$progressBar.classList.add(PLUGIN_NAME + '-progressbar');
|
505
|
+
|
506
|
+
var $progressBarDiv = document.createElement("div");
|
507
|
+
$progressBarDiv.style.background = settings.progressBarColor;
|
508
|
+
|
509
|
+
$progressBar.appendChild($progressBarDiv);
|
510
|
+
$toast.appendChild($progressBar);
|
511
|
+
|
512
|
+
setTimeout(function() {
|
513
|
+
moveProgress($toast, settings, function(){
|
514
|
+
that.hide(settings, $toast);
|
515
|
+
});
|
516
|
+
},300);
|
517
|
+
}
|
518
|
+
else if( settings.progressBar === false && settings.timeout > 0){
|
519
|
+
setTimeout(function() {
|
520
|
+
that.hide(settings, $toast);
|
521
|
+
}, settings.timeout);
|
522
|
+
}
|
523
|
+
|
524
|
+
var $toastBody = document.createElement("div");
|
525
|
+
$toastBody.classList.add(PLUGIN_NAME + '-body');
|
526
|
+
|
527
|
+
if (settings.image) {
|
528
|
+
if(settings.rtl){
|
529
|
+
$toastBody.style.marginRight = (settings.imageWidth + 10) + 'px';
|
530
|
+
} else {
|
531
|
+
$toastBody.style.marginLeft = (settings.imageWidth + 10) + 'px';
|
532
|
+
}
|
533
|
+
}
|
534
|
+
|
535
|
+
if (settings.icon) {
|
536
|
+
var $icon = document.createElement("i");
|
537
|
+
$icon.setAttribute("class", PLUGIN_NAME + '-icon ' + settings.icon);
|
538
|
+
|
539
|
+
if (settings.iconText){
|
540
|
+
$icon.appendChild(document.createTextNode(settings.iconText));
|
541
|
+
}
|
542
|
+
|
543
|
+
if(settings.rtl){
|
544
|
+
$toastBody.style.paddingRight = '33px';
|
545
|
+
} else {
|
546
|
+
$toastBody.style.paddingLeft = '33px';
|
547
|
+
}
|
548
|
+
|
549
|
+
if (settings.iconColor){
|
550
|
+
$icon.style.color = settings.iconColor;
|
551
|
+
}
|
552
|
+
$toastBody.appendChild($icon);
|
553
|
+
}
|
554
|
+
|
555
|
+
var $strong = document.createElement("strong");
|
556
|
+
if (settings.titleColor.length > 0) {
|
557
|
+
$strong.style.color = settings.titleColor;
|
558
|
+
}
|
559
|
+
$strong.appendChild(createFragElem(settings.title));
|
560
|
+
|
561
|
+
var $p = document.createElement("p");
|
562
|
+
if (settings.messageColor.length > 0) {
|
563
|
+
$p.style.color = settings.messageColor;
|
564
|
+
}
|
565
|
+
$p.appendChild(createFragElem(settings.message));
|
566
|
+
|
567
|
+
if(settings.layout > 1){
|
568
|
+
$toast.classList.add(PLUGIN_NAME+"-layout"+settings.layout);
|
569
|
+
}
|
570
|
+
|
571
|
+
if(settings.balloon){
|
572
|
+
$toast.classList.add(PLUGIN_NAME+"-balloon");
|
573
|
+
}
|
574
|
+
|
575
|
+
$toastBody.appendChild($strong);
|
576
|
+
$toastBody.appendChild($p);
|
577
|
+
|
578
|
+
var $buttons;
|
579
|
+
if (settings.buttons.length > 0) {
|
580
|
+
|
581
|
+
$buttons = document.createElement("div");
|
582
|
+
$buttons.classList.add(PLUGIN_NAME + '-buttons');
|
583
|
+
|
584
|
+
$p.style.marginRight = '15px';
|
585
|
+
|
586
|
+
var i = 0;
|
587
|
+
forEach(settings.buttons, function (value, index) {
|
588
|
+
$buttons.appendChild(createFragElem(value[0]));
|
589
|
+
|
590
|
+
var $btns = $buttons.childNodes;
|
591
|
+
|
592
|
+
$btns[i].addEventListener('click', function (e) {
|
593
|
+
e.preventDefault();
|
594
|
+
var ts = value[1];
|
595
|
+
return new ts(that, $toast);
|
596
|
+
});
|
597
|
+
|
598
|
+
i++;
|
599
|
+
});
|
600
|
+
$toastBody.appendChild($buttons);
|
601
|
+
}
|
602
|
+
|
603
|
+
$toast.appendChild($toastBody);
|
604
|
+
$toastCapsule.style.visibility = 'hidden';
|
605
|
+
$toastCapsule.appendChild($toast);
|
606
|
+
|
607
|
+
setTimeout(function() {
|
608
|
+
var H = $toast.offsetHeight;
|
609
|
+
var style = $toast.currentStyle || window.getComputedStyle($toast);
|
610
|
+
var marginTop = style.marginTop;
|
611
|
+
marginTop = marginTop.split("px");
|
612
|
+
marginTop = parseInt(marginTop[0]);
|
613
|
+
var marginBottom = style.marginBottom;
|
614
|
+
marginBottom = marginBottom.split("px");
|
615
|
+
marginBottom = parseInt(marginBottom[0]);
|
616
|
+
|
617
|
+
$toastCapsule.style.visibility = '';
|
618
|
+
$toastCapsule.style.height = (H+marginBottom+marginTop)+'px';
|
619
|
+
setTimeout(function() {
|
620
|
+
$toastCapsule.style.height = 'auto';
|
621
|
+
if(settings.target){
|
622
|
+
$toastCapsule.style.overflow = 'visible';
|
623
|
+
}
|
624
|
+
},1000);
|
625
|
+
}, 100);
|
626
|
+
|
627
|
+
var position = settings.position,
|
628
|
+
$wrapper;
|
629
|
+
|
630
|
+
if(settings.target){
|
631
|
+
|
632
|
+
$wrapper = document.querySelector(settings.target);
|
633
|
+
$wrapper.classList.add(PLUGIN_NAME + '-target');
|
634
|
+
|
635
|
+
if (settings.targetFirst) {
|
636
|
+
$wrapper.insertBefore($toastCapsule, $wrapper.firstChild);
|
637
|
+
} else {
|
638
|
+
$wrapper.appendChild($toastCapsule);
|
639
|
+
}
|
640
|
+
|
641
|
+
} else {
|
642
|
+
|
643
|
+
if( POSITIONS.indexOf(settings.position) == -1 ){
|
644
|
+
console.warn("["+PLUGIN_NAME+"] Incorrect position.\nIt can be › " + POSITIONS);
|
645
|
+
return;
|
646
|
+
}
|
647
|
+
|
648
|
+
if(ISMOBILE || window.innerWidth <= MOBILEWIDTH){
|
649
|
+
if(settings.position == "bottomLeft" || settings.position == "bottomRight" || settings.position == "bottomCenter"){
|
650
|
+
position = PLUGIN_NAME+'-wrapper-bottomCenter';
|
651
|
+
}
|
652
|
+
else if(settings.position == "topLeft" || settings.position == "topRight" || settings.position == "topCenter"){
|
653
|
+
position = PLUGIN_NAME+'-wrapper-topCenter';
|
654
|
+
}
|
655
|
+
else{
|
656
|
+
position = PLUGIN_NAME+'-wrapper-center';
|
657
|
+
}
|
658
|
+
} else {
|
659
|
+
position = PLUGIN_NAME+'-wrapper-'+position;
|
660
|
+
}
|
661
|
+
$wrapper = document.querySelector('.' + PLUGIN_NAME + '-wrapper.'+position);
|
662
|
+
|
663
|
+
if (!$wrapper) {
|
664
|
+
$wrapper = document.createElement("div");
|
665
|
+
$wrapper.classList.add(PLUGIN_NAME + '-wrapper');
|
666
|
+
$wrapper.classList.add(position);
|
667
|
+
document.body.appendChild($wrapper);
|
668
|
+
}
|
669
|
+
if(settings.position == "topLeft" || settings.position == "topCenter" || settings.position == "topRight"){
|
670
|
+
$wrapper.insertBefore($toastCapsule, $wrapper.firstChild);
|
671
|
+
} else {
|
672
|
+
$wrapper.appendChild($toastCapsule);
|
673
|
+
}
|
674
|
+
}
|
675
|
+
|
676
|
+
if (!isNaN(settings.zindex)) {
|
677
|
+
$wrapper.style.zIndex = settings.zindex;
|
678
|
+
} else {
|
679
|
+
console.warn("["+PLUGIN_NAME+"] Invalid zIndex.");
|
680
|
+
}
|
681
|
+
|
682
|
+
settings.onOpen.apply(null, [settings, $toast]);
|
683
|
+
|
684
|
+
try {
|
685
|
+
var event;
|
686
|
+
if (window.CustomEvent) {
|
687
|
+
event = new CustomEvent(PLUGIN_NAME+'-open', {detail: {class: settings.class}});
|
688
|
+
} else {
|
689
|
+
event = document.createEvent('CustomEvent');
|
690
|
+
event.initCustomEvent(PLUGIN_NAME+'-open', true, true, {class: settings.class});
|
691
|
+
}
|
692
|
+
document.dispatchEvent(event);
|
693
|
+
} catch(ex){
|
694
|
+
console.warn(ex);
|
695
|
+
}
|
696
|
+
|
697
|
+
if(settings.animateInside){
|
698
|
+
$toast.classList.add(PLUGIN_NAME+'-animateInside');
|
699
|
+
|
700
|
+
var timeAnimation1 = 200;
|
701
|
+
var timeAnimation2 = 100;
|
702
|
+
var timeAnimation3 = 300;
|
703
|
+
if(settings.transitionIn == "bounceInLeft"){
|
704
|
+
timeAnimation1 = 400;
|
705
|
+
timeAnimation2 = 200;
|
706
|
+
timeAnimation3 = 400;
|
707
|
+
}
|
708
|
+
|
709
|
+
window.setTimeout(function(){
|
710
|
+
$strong.classList.add('slideIn');
|
711
|
+
},timeAnimation1);
|
712
|
+
|
713
|
+
window.setTimeout(function(){
|
714
|
+
$p.classList.add('slideIn');
|
715
|
+
},timeAnimation2);
|
716
|
+
|
717
|
+
if (settings.icon) {
|
718
|
+
window.setTimeout(function(){
|
719
|
+
$icon.classList.add('revealIn');
|
720
|
+
},timeAnimation3);
|
721
|
+
}
|
722
|
+
|
723
|
+
if (settings.buttons.length > 0 && $buttons) {
|
724
|
+
var counter = 150;
|
725
|
+
forEach($buttons.childNodes, function(element, index) {
|
726
|
+
|
727
|
+
window.setTimeout(function(){
|
728
|
+
element.classList.add('revealIn');
|
729
|
+
},counter);
|
730
|
+
counter = counter + counter;
|
731
|
+
});
|
732
|
+
}
|
733
|
+
}
|
734
|
+
|
735
|
+
if($buttonClose){
|
736
|
+
$buttonClose.addEventListener('click', function (e) {
|
737
|
+
var button = e.target;
|
738
|
+
that.hide(settings, $toast, 'button');
|
739
|
+
});
|
740
|
+
}
|
741
|
+
|
742
|
+
if(settings.pauseOnHover){
|
743
|
+
|
744
|
+
$toast.addEventListener('mouseenter', function (e) {
|
745
|
+
this.classList.add(PLUGIN_NAME+'-paused');
|
746
|
+
});
|
747
|
+
$toast.addEventListener('mouseleave', function (e) {
|
748
|
+
this.classList.remove(PLUGIN_NAME+'-paused');
|
749
|
+
});
|
750
|
+
}
|
751
|
+
|
752
|
+
if(settings.resetOnHover){
|
753
|
+
|
754
|
+
$toast.addEventListener('mouseenter', function (e) {
|
755
|
+
this.classList.add(PLUGIN_NAME+'-reseted');
|
756
|
+
});
|
757
|
+
$toast.addEventListener('mouseleave', function (e) {
|
758
|
+
this.classList.remove(PLUGIN_NAME+'-reseted');
|
759
|
+
});
|
760
|
+
}
|
761
|
+
|
762
|
+
if(settings.drag){
|
763
|
+
|
764
|
+
if (ACCEPTSTOUCH) {
|
765
|
+
|
766
|
+
$toast.addEventListener('touchstart', function(e) {
|
767
|
+
drag.startMoving(this, that, settings, e);
|
768
|
+
}, false);
|
769
|
+
|
770
|
+
$toast.addEventListener('touchend', function(e) {
|
771
|
+
drag.stopMoving(this, e);
|
772
|
+
}, false);
|
773
|
+
} else {
|
774
|
+
|
775
|
+
$toast.addEventListener('mousedown', function(e) {
|
776
|
+
e.preventDefault();
|
777
|
+
drag.startMoving(this, that, settings, e);
|
778
|
+
}, false);
|
779
|
+
|
780
|
+
$toast.addEventListener('mouseup', function(e) {
|
781
|
+
e.preventDefault();
|
782
|
+
drag.stopMoving(this, e);
|
783
|
+
}, false);
|
784
|
+
}
|
785
|
+
}
|
786
|
+
|
787
|
+
|
788
|
+
};
|
789
|
+
|
790
|
+
return $iziToast;
|
791
|
+
});
|