server-generated-popups 1.4.5 → 1.4.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54c644a0cbd5e4594be54e5aa1fb197c1fe606f6
4
- data.tar.gz: e64730d032cef7af4f10b046cfb6e345c283d0f9
3
+ metadata.gz: aa77283b7bc2b244f3c595ff09168d1348b3bebf
4
+ data.tar.gz: 50eca2cc10cd4d383d9380a19b61dd6416b76541
5
5
  SHA512:
6
- metadata.gz: 6cee06105c58275ab2ed8afd117aa41faf7f4bb646920d30fc5ad1d2fe150146421e76e5d6ca771b2c23c3ceb6a556d15891d52abd80af51749f6a72c0d428a5
7
- data.tar.gz: f153297179c790ce05e9f3c6ba87fcea6154b89c109b95cff7c8404dec289ce5f0ef6a2f263a30b1940f36ad72eef716aae739dce0128e20d74bb2ff7777cb24
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>").show({closeButton: false, backdrop: false})
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 `callback` option:
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
- callback: function () {
77
- blink($('.heading'))
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 (html, options) {
3
- return new PopupClass(html, options)
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(html, options) {
33
- this.options = defaultsFor(options, {width: 600})
34
-
35
- this.popupWindow = createElement('<div class="popup">' + html + '</div>')
36
-
37
- actualWidth = Math.min(window.innerWidth, this.options.width)
38
- setStyle(this.popupWindow, {
39
- 'width': actualWidth.toString() + 'px',
40
- 'margin-left': (actualWidth/2 * -1).toString() + 'px',
41
- 'padding': this.options.padding
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: 0.5})
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
- closeButton = createElement('<div class="closeButton"></div>')
94
- margin = this.options.closeButtonPadding || this.options.padding || '16px'
95
- setStyle(closeButton, {top: margin, right: margin})
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, options) {
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(), options.callback)
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
- background: 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=');
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>
@@ -12,6 +12,6 @@ Gem::Specification.new do |gem|
12
12
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
13
  gem.name = "server-generated-popups"
14
14
  gem.require_paths = ["lib"]
15
- gem.version = "1.4.5"
15
+ gem.version = "1.4.6"
16
16
  gem.license = 'MIT'
17
17
  end
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.5
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-15 00:00:00.000000000 Z
11
+ date: 2017-11-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: