server-generated-popups 1.4.5 → 1.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -11
- data/app/assets/javascripts/popup.js +35 -30
- data/app/assets/stylesheets/popup.css +21 -6
- data/demo/index.html +1 -1
- data/server-generated-popups.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa77283b7bc2b244f3c595ff09168d1348b3bebf
|
4
|
+
data.tar.gz: 50eca2cc10cd4d383d9380a19b61dd6416b76541
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c6bd8f90ab1b7a934edd46f16449b45e2049339d2d085ba92f49bd438b1a705b322f1f39ebde4324039e394111de2e489ff8e89b5ffc20b11912d277993cbd1
|
7
|
+
data.tar.gz: 7b0eda5aaffbb7b96992139dfd800a45bdffd0189ebc4507ade6d0a40bb4f50e6908d662f76a7b905614e52588d6d72b0ab338f565b604ed00e9b22f5b87f20c
|
data/README.md
CHANGED
@@ -15,8 +15,6 @@ Animations, styles — all included. One line gets you a fully working solution.
|
|
15
15
|
|
16
16
|
Perfect with Rails and its [Server-generated JavaScript Responses](https://signalvnoise.com/posts/3697-server-generated-javascript-responses), but not limited to them.
|
17
17
|
|
18
|
-
The screenshot above is from [Invoices for Milestones](http://invoicesformilestones.com), where this plugin is extracted from. Invoices for Milestones is a dead simple invoicing tool for self-employed. If you work for yourself, check it out.
|
19
|
-
|
20
18
|
## Installation
|
21
19
|
|
22
20
|
### Rails
|
@@ -47,8 +45,6 @@ popup.hide('down')
|
|
47
45
|
|
48
46
|
### Options
|
49
47
|
|
50
|
-
#### Constructor options
|
51
|
-
|
52
48
|
Your popup content needs extra **padding** around it to look good? Pass the value in any units:
|
53
49
|
|
54
50
|
```javascript
|
@@ -61,20 +57,18 @@ Override **width** of the popup by passing the value in px:
|
|
61
57
|
Popup("<div>Hello</div>", {width: 300})
|
62
58
|
```
|
63
59
|
|
64
|
-
#### show method options
|
65
|
-
|
66
60
|
By default the popup will show with a **close button** in the top right corner and a **semi-transparent backdrop** beind ([like this](https://colorfulfool.github.io/server-generated-popups/demo/)). You can disable either or both:
|
67
61
|
|
68
62
|
```javascript
|
69
|
-
Popup("<div>Hello</div>"
|
63
|
+
Popup("<div>Hello</div>", {closeButton: false, backdrop: false}).show('up')
|
70
64
|
```
|
71
65
|
|
72
|
-
If you need to **do something after the popup slides onto the screen** — pass
|
66
|
+
If you need to **do something after the popup slides onto the screen** — pass a callback to `show`.
|
73
67
|
|
74
68
|
```javascript
|
75
|
-
editInvoiceDetails = Popup("<%=j render @invoice %>").show('up', {
|
76
|
-
|
77
|
-
|
69
|
+
editInvoiceDetails = Popup("<%=j render @invoice %>").show('up', function (popupWindow) {
|
70
|
+
popupWindow.style.backgroundColor = "red"
|
71
|
+
this.hide('down')
|
78
72
|
}
|
79
73
|
})
|
80
74
|
```
|
@@ -1,6 +1,6 @@
|
|
1
1
|
(function (global) {
|
2
|
-
global['Popup'] = function (
|
3
|
-
return new PopupClass(
|
2
|
+
global['Popup'] = function (content, options) {
|
3
|
+
return new PopupClass(content, options)
|
4
4
|
}
|
5
5
|
|
6
6
|
|
@@ -29,22 +29,32 @@
|
|
29
29
|
|
30
30
|
// Constructs a Popup object.
|
31
31
|
// Options: width, padding
|
32
|
-
function PopupClass(
|
33
|
-
this.options = defaultsFor(options, {width: 600
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
'
|
40
|
-
|
41
|
-
|
42
|
-
|
32
|
+
function PopupClass(content, options) {
|
33
|
+
this.options = defaultsFor(options, {width: 600,
|
34
|
+
backdrop: true, closeButton: true})
|
35
|
+
|
36
|
+
popupWidth = Math.min(window.innerWidth, this.options.width)
|
37
|
+
|
38
|
+
this.popupWindow = createElement(
|
39
|
+
'<div class="popup">' + content + '</div>',
|
40
|
+
{
|
41
|
+
'width': popupWidth.toString() + 'px',
|
42
|
+
'margin-left': (popupWidth/2 * -1).toString() + 'px',
|
43
|
+
'padding': this.options.padding
|
44
|
+
}
|
45
|
+
)
|
43
46
|
|
44
47
|
this.createBackdrop()
|
45
48
|
}
|
46
49
|
|
47
50
|
|
51
|
+
PopupClass.prototype.hideByClickOn = function (element) {
|
52
|
+
var popupObject = this
|
53
|
+
element.onclick = function () {
|
54
|
+
popupObject.hide('down')
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
48
58
|
PopupClass.prototype.distanceFromTop = function () {
|
49
59
|
return (window.innerHeight - this.popupWindow.offsetHeight)/2
|
50
60
|
}
|
@@ -79,7 +89,7 @@
|
|
79
89
|
appendToBody(this.backdrop)
|
80
90
|
}
|
81
91
|
PopupClass.prototype.showBackdrop = function () {
|
82
|
-
setStyle(this.backdrop, {visibility: 'visible', opacity:
|
92
|
+
setStyle(this.backdrop, {visibility: 'visible', opacity: 1})
|
83
93
|
}
|
84
94
|
PopupClass.prototype.hideBackdrop = function () {
|
85
95
|
backdrop = this.backdrop
|
@@ -90,33 +100,28 @@
|
|
90
100
|
}
|
91
101
|
|
92
102
|
PopupClass.prototype.createCloseButton = function () {
|
93
|
-
|
94
|
-
|
95
|
-
|
103
|
+
buttonPadding = this.options.closeButtonPadding || this.options.padding || '16px'
|
104
|
+
|
105
|
+
closeButton = createElement(
|
106
|
+
'<div class="closeButton"></div>',
|
107
|
+
{top: buttonPadding, right: buttonPadding}
|
108
|
+
)
|
96
109
|
|
97
110
|
this.hideByClickOn(closeButton)
|
98
111
|
this.popupWindow.appendChild(closeButton)
|
99
112
|
}
|
100
|
-
PopupClass.prototype.hideByClickOn = function (element) {
|
101
|
-
thisObject = this
|
102
|
-
element.onclick = function () {
|
103
|
-
thisObject.hide('down')
|
104
|
-
}
|
105
|
-
}
|
106
113
|
|
107
114
|
|
108
115
|
// Slides the popup onto the screen.
|
109
116
|
// Options: backdrop, closeButton, callback
|
110
|
-
PopupClass.prototype.show = function (direction,
|
111
|
-
options = defaultsFor(options, {backdrop: true, closeButton: true})
|
112
|
-
|
117
|
+
PopupClass.prototype.show = function (direction, callback) {
|
113
118
|
appendToBody(this.popupWindow)
|
114
119
|
start = direction == 'up' ? 'below-screen' : 'above-screen'
|
115
|
-
this.translate(start, this.distanceFromTop(),
|
120
|
+
this.translate(start, this.distanceFromTop(), callback.bind(this, this.popupWindow))
|
116
121
|
|
117
|
-
if (options.backdrop)
|
122
|
+
if (this.options.backdrop)
|
118
123
|
this.showBackdrop()
|
119
|
-
if (options.closeButton)
|
124
|
+
if (this.options.closeButton)
|
120
125
|
this.createCloseButton()
|
121
126
|
return this
|
122
127
|
}
|
@@ -136,4 +141,4 @@
|
|
136
141
|
}
|
137
142
|
|
138
143
|
|
139
|
-
})(window)
|
144
|
+
})(window)
|
@@ -1,11 +1,12 @@
|
|
1
|
+
/* This file is divided into two parts.
|
2
|
+
|
3
|
+
The first part is vital for the functioning of popups. You shouldn't edit it.
|
4
|
+
The second part defines the look. It is okay to edit. */
|
5
|
+
|
1
6
|
.popup {
|
2
7
|
position: fixed; z-index: 1050;
|
3
|
-
background: white;
|
4
8
|
left: 50%;
|
5
9
|
|
6
|
-
box-shadow: 0px 10px 20px rgba(0,0,0,0.3);
|
7
|
-
border-radius: 6px;
|
8
|
-
|
9
10
|
transition: all 0.4s linear;
|
10
11
|
}
|
11
12
|
.above-screen { top: -80%; }
|
@@ -14,7 +15,6 @@
|
|
14
15
|
#popup-backdrop {
|
15
16
|
position: fixed; z-index: 1040;
|
16
17
|
top: 0; left: 0; bottom: 0; right: 0;
|
17
|
-
background-color: black;
|
18
18
|
|
19
19
|
opacity: 0;
|
20
20
|
transition: opacity 0.3s linear;
|
@@ -25,5 +25,20 @@
|
|
25
25
|
|
26
26
|
position: absolute;
|
27
27
|
cursor: pointer;
|
28
|
-
|
28
|
+
}
|
29
|
+
|
30
|
+
/* Below is the part that's okay to rewrite */
|
31
|
+
|
32
|
+
.popup {
|
33
|
+
background: white;
|
34
|
+
box-shadow: 0px 10px 20px rgba(0,0,0,0.3);
|
35
|
+
border-radius: 6px;
|
36
|
+
}
|
37
|
+
|
38
|
+
#popup-backdrop {
|
39
|
+
background-color: rgba(0,0,0,0.5);
|
40
|
+
}
|
41
|
+
|
42
|
+
.closeButton {
|
43
|
+
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAfxJREFUOBGVk8trU1EQxnuvgdgEpKmEFk3qpnuhG7ELiaVuijsxpFSyKgZphDwW9i9QIs07BINIhAhCRGkpbRcuuqkKrkToqlKQ0GV3SUMeN/E3JSfcphHtwMnMme+b78zckzOSTCbHstnstZELWC6Xu5pKpSakRO92u9dbrdZ+PB4P/I8GhbcajcZvwzDuCF+TH7rwILRF6ItEIpuSG2aJRGIa3jdN057DSwrnVEACRBY7nc5rwDnA75IzWyaTcbbb7a/ktsBDCusLSIIxniEQJZyF9EuROHmUeJd1FA6HH8LpKExXgfhoNBrDfWDtyImSo2XhvMcbDodjyVws+JkOJFEuly9VKpVPECftdvvdarX6kvQ9q9U6GwwGj4VjtnMCAhYKBVutVpOWxzn5iq7rt2n90Fyo4jMjqGQgEDghLlE8jf/8t2LhDxXgRubBYoyxzPLwEVeFPMzOCXATNzn5I4Ur3MQb2l9gv0r+0T8F0un0FKRtitdo+60UhEKhnxaL5QHhq15nku5b/yPm83lHvV7fo/gLJz/uM3pBr4McHXkQ/6Hw0xG4cyvF6yQPXS7XEwWaPf+Rd+xjjLPNY7qhMHlMGo+pRGLU6XT6vF6vocBBj8gL+OvNZnOHDzsuuM5ccfyMzWa77/f7a4NFg3u32/0UkQPWRrFYvPwHkWvOYv3AEzcAAAAASUVORK5CYII=');
|
29
44
|
}
|
data/demo/index.html
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
</head>
|
9
9
|
<script type="text/javascript">
|
10
10
|
$(document).ready(function () {
|
11
|
-
Popup("<h2>Hello</h2><p>Did you notice that close button in the top-right corner? It comes with the lib too.</p>", {padding: '30px'}).show('up')
|
11
|
+
Popup("<h2>Hello</h2><p>Did you notice that close button in the top-right corner? It comes with the lib too.</p>", {padding: '30px'}).show('up', function (popupWindow) { popupWindow.style.opacity = 0.7; })
|
12
12
|
});
|
13
13
|
</script>
|
14
14
|
<body>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: server-generated-popups
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Khamets
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08
|
11
|
+
date: 2017-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|