visibilityjs 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7a9ba4d047ee0acc40d0d22d42616c46bd4bfb51
4
+ data.tar.gz: f663938cead70fd0e1059d7a8f0183712f55e77e
5
+ SHA512:
6
+ metadata.gz: b4ffa46278c837e7aeae670815bde746294c3c52c6ab900677aa4077efaf57bdf1565855903684bc3327d2b51d3b183834d6939fabb4cc73a5ce86e06aff6022
7
+ data.tar.gz: c55f49573bc8cf75db252692e4a57f2d4d7385f2b409fa72c0c40fa0b3148b8d9c4d992270d7b6e972bfcdeb1351a07ebc774c89aac96f2a7e42249555b59e78
@@ -1,54 +1,60 @@
1
- == 1.0.0 (Discoverer 2, stable)
1
+ ## 1.1.0 “Explorer 6, photo”
2
+ * Prevent to run timer often, that it’s interval, when visibility was changed.
3
+ * Allow to install by Bower package manager.
4
+ * Change license to MIT.
5
+ * Reduce library size.
6
+
7
+ ## 1.0.0 “Discoverer 2, stable”
2
8
  * Remove jQuery.Chrono integration.
3
9
  * Remove outdated Firefox prefix.
4
10
 
5
- == 0.6.2 (Pioneer 4, american sun)
11
+ ## 0.6.2 Pioneer 4, american sun
6
12
  * Decrease files size (by compressible code and UnglifyJS 2).
7
13
  * Remove unnecessary vendor prefixes from fallback.
8
14
 
9
- == 0.6.1 (Vanguard 2, weather)
15
+ ## 0.6.1 Vanguard 2, weather
10
16
  * Remove unnecessary vendor prefixes.
11
17
 
12
- == 0.6 (Luna 1, Mechta)
18
+ ## 0.6 Luna 1, Mechta
13
19
  * Methods onVisible and afterPrerendering return listener ID (by mcfedr).
14
20
  * Fix documentation (by Erwann Mest).
15
21
 
16
- == 0.5 (SCORE, communication)
22
+ ## 0.5 SCORE, communication
17
23
  * Split library to core and timers modules.
18
24
  * Allow to unbind change listener.
19
25
  * Use common logic in change(), afterPrerendering() and onVisible().
20
26
 
21
- == 0.4.5 (Pioneer 3, closer)
27
+ ## 0.4.5 Pioneer 3, closer
22
28
  * Fix gem assets directory.
23
29
  * Update development dependencies.
24
30
 
25
- == 0.4.4 (Pioneer 1, deeper into space)
31
+ ## 0.4.4 Pioneer 1, deeper into space
26
32
  * Remove non-ASCII symbols from gemspec.
27
33
  * Print testing URL in test task.
28
34
 
29
- == 0.4.3 (Explorer 4, short)
35
+ ## 0.4.3 Explorer 4, short
30
36
  * Fix gemspec issue with Bundler.
31
37
 
32
- == 0.4.2 (Sputnik 3, real)
38
+ ## 0.4.2 Sputnik 3, real
33
39
  * Reorder code to show first public and common methods.
34
40
  * Use node.js Cake instead of Ruby’s Rake to build tasks.
35
41
  * Move to Mocha, Chai and Sinon.JS for tests.
36
42
  * Move autogenerated minified to GitHub downloads.
37
43
 
38
- == 0.4.1 (Explorer 3, repeat)
44
+ ## 0.4.1 Explorer 3, repeat
39
45
  * Fix documentation and gemspec.
40
46
 
41
- == 0.4 (Vanguard 1, alternative)
47
+ ## 0.4 Vanguard 1, alternative
42
48
  * Add fallback API support by focus/blur hack to all browsers.
43
49
 
44
- == 0.3 (Explorer 1, answer)
50
+ ## 0.3 Explorer 1, answer
45
51
  * Rename gem to visibilityjs.
46
52
  * Fix gem integration with Asset Pipeline paths.
47
53
 
48
- == 0.2 (Sputnik 2, Laika)
54
+ ## 0.2 Sputnik 2, Laika
49
55
  * Rename support() to isSupported() and notPrerender() to afterPrerendering().
50
56
  * Fix IE 6 and 7 support.
51
57
  * Documentation fixes by Peter Zotov.
52
58
 
53
- == 0.1 (Sputnik 1, the first)
59
+ ## 0.1 Sputnik 1, the first
54
60
  * Initial release.
data/LICENSE CHANGED
@@ -1,165 +1,20 @@
1
- GNU LESSER GENERAL PUBLIC LICENSE
2
- Version 3, 29 June 2007
3
-
4
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
- Everyone is permitted to copy and distribute verbatim copies
6
- of this license document, but changing it is not allowed.
7
-
8
-
9
- This version of the GNU Lesser General Public License incorporates
10
- the terms and conditions of version 3 of the GNU General Public
11
- License, supplemented by the additional permissions listed below.
12
-
13
- 0. Additional Definitions.
14
-
15
- As used herein, "this License" refers to version 3 of the GNU Lesser
16
- General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
- General Public License.
18
-
19
- "The Library" refers to a covered work governed by this License,
20
- other than an Application or a Combined Work as defined below.
21
-
22
- An "Application" is any work that makes use of an interface provided
23
- by the Library, but which is not otherwise based on the Library.
24
- Defining a subclass of a class defined by the Library is deemed a mode
25
- of using an interface provided by the Library.
26
-
27
- A "Combined Work" is a work produced by combining or linking an
28
- Application with the Library. The particular version of the Library
29
- with which the Combined Work was made is also called the "Linked
30
- Version".
31
-
32
- The "Minimal Corresponding Source" for a Combined Work means the
33
- Corresponding Source for the Combined Work, excluding any source code
34
- for portions of the Combined Work that, considered in isolation, are
35
- based on the Application, and not on the Linked Version.
36
-
37
- The "Corresponding Application Code" for a Combined Work means the
38
- object code and/or source code for the Application, including any data
39
- and utility programs needed for reproducing the Combined Work from the
40
- Application, but excluding the System Libraries of the Combined Work.
41
-
42
- 1. Exception to Section 3 of the GNU GPL.
43
-
44
- You may convey a covered work under sections 3 and 4 of this License
45
- without being bound by section 3 of the GNU GPL.
46
-
47
- 2. Conveying Modified Versions.
48
-
49
- If you modify a copy of the Library, and, in your modifications, a
50
- facility refers to a function or data to be supplied by an Application
51
- that uses the facility (other than as an argument passed when the
52
- facility is invoked), then you may convey a copy of the modified
53
- version:
54
-
55
- a) under this License, provided that you make a good faith effort to
56
- ensure that, in the event an Application does not supply the
57
- function or data, the facility still operates, and performs
58
- whatever part of its purpose remains meaningful, or
59
-
60
- b) under the GNU GPL, with none of the additional permissions of
61
- this License applicable to that copy.
62
-
63
- 3. Object Code Incorporating Material from Library Header Files.
64
-
65
- The object code form of an Application may incorporate material from
66
- a header file that is part of the Library. You may convey such object
67
- code under terms of your choice, provided that, if the incorporated
68
- material is not limited to numerical parameters, data structure
69
- layouts and accessors, or small macros, inline functions and templates
70
- (ten or fewer lines in length), you do both of the following:
71
-
72
- a) Give prominent notice with each copy of the object code that the
73
- Library is used in it and that the Library and its use are
74
- covered by this License.
75
-
76
- b) Accompany the object code with a copy of the GNU GPL and this license
77
- document.
78
-
79
- 4. Combined Works.
80
-
81
- You may convey a Combined Work under terms of your choice that,
82
- taken together, effectively do not restrict modification of the
83
- portions of the Library contained in the Combined Work and reverse
84
- engineering for debugging such modifications, if you also do each of
85
- the following:
86
-
87
- a) Give prominent notice with each copy of the Combined Work that
88
- the Library is used in it and that the Library and its use are
89
- covered by this License.
90
-
91
- b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
- document.
93
-
94
- c) For a Combined Work that displays copyright notices during
95
- execution, include the copyright notice for the Library among
96
- these notices, as well as a reference directing the user to the
97
- copies of the GNU GPL and this license document.
98
-
99
- d) Do one of the following:
100
-
101
- 0) Convey the Minimal Corresponding Source under the terms of this
102
- License, and the Corresponding Application Code in a form
103
- suitable for, and under terms that permit, the user to
104
- recombine or relink the Application with a modified version of
105
- the Linked Version to produce a modified Combined Work, in the
106
- manner specified by section 6 of the GNU GPL for conveying
107
- Corresponding Source.
108
-
109
- 1) Use a suitable shared library mechanism for linking with the
110
- Library. A suitable mechanism is one that (a) uses at run time
111
- a copy of the Library already present on the user's computer
112
- system, and (b) will operate properly with a modified version
113
- of the Library that is interface-compatible with the Linked
114
- Version.
115
-
116
- e) Provide Installation Information, but only if you would otherwise
117
- be required to provide such information under section 6 of the
118
- GNU GPL, and only to the extent that such information is
119
- necessary to install and execute a modified version of the
120
- Combined Work produced by recombining or relinking the
121
- Application with a modified version of the Linked Version. (If
122
- you use option 4d0, the Installation Information must accompany
123
- the Minimal Corresponding Source and Corresponding Application
124
- Code. If you use option 4d1, you must provide the Installation
125
- Information in the manner specified by section 6 of the GNU GPL
126
- for conveying Corresponding Source.)
127
-
128
- 5. Combined Libraries.
129
-
130
- You may place library facilities that are a work based on the
131
- Library side by side in a single library together with other library
132
- facilities that are not Applications and are not covered by this
133
- License, and convey such a combined library under terms of your
134
- choice, if you do both of the following:
135
-
136
- a) Accompany the combined library with a copy of the same work based
137
- on the Library, uncombined with any other library facilities,
138
- conveyed under the terms of this License.
139
-
140
- b) Give prominent notice with the combined library that part of it
141
- is a work based on the Library, and explaining where to find the
142
- accompanying uncombined form of the same work.
143
-
144
- 6. Revised Versions of the GNU Lesser General Public License.
145
-
146
- The Free Software Foundation may publish revised and/or new versions
147
- of the GNU Lesser General Public License from time to time. Such new
148
- versions will be similar in spirit to the present version, but may
149
- differ in detail to address new problems or concerns.
150
-
151
- Each version is given a distinguishing version number. If the
152
- Library as you received it specifies that a certain numbered version
153
- of the GNU Lesser General Public License "or any later version"
154
- applies to it, you have the option of following the terms and
155
- conditions either of that published version or of any later version
156
- published by the Free Software Foundation. If the Library as you
157
- received it does not specify a version number of the GNU Lesser
158
- General Public License, you may choose any version of the GNU Lesser
159
- General Public License ever published by the Free Software Foundation.
160
-
161
- If the Library as you received it specifies that a proxy can decide
162
- whether future versions of the GNU Lesser General Public License shall
163
- apply, that proxy's public statement of acceptance of any version is
164
- permanent authorization for you to choose that version for the
165
- Library.
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2011 Andrey Sitnik <andrey@sitnik.ru>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
- # Visibility.js: a wrapper for the Page Visibility API
1
+ # Visibility.js
2
2
 
3
- Visibility.js allows you to determine whether your web page is visible to a
4
- user, is hidden in background tab or is prerendering. It allows you to use
5
- the page visibility state in JavaScript logic and improve browser performance
3
+ <img align="right" width="100" src="http://ai.github.io/visibility.js/logo.svg" title="Visibility.js logo by Eugenia Tuchapets">
4
+
5
+ Visibility.js is a wrapper for the [Page Visibility API]. It hides vendor prefixes and adds high level functions.
6
+
7
+ Page Visibility API allows you to determine whether your web page is visible to
8
+ a user, is hidden in background tab or is prerendering. It allows you to use
9
+ the page visibility state in JavaScript logic and improve browser performance
6
10
  by disabling unnecessary timers and AJAX requests, or improve user interface
7
11
  experience (for example, by stopping video playback or slideshow when user
8
12
  switches to another browser tab).
@@ -12,15 +16,6 @@ the user has not still opened the link, and don’t count this as a visit in yo
12
16
  analytics module, or do not run heavy calculations or other actions which will
13
17
  disable the prerendering.
14
18
 
15
- This library is a wrapper of the [Page Visibility API]. It eases usage
16
- of the API by hiding vendor-specific property prefixes and adding some
17
- high-level functions.
18
-
19
- In most cases you don’t need to check whether the Page Visibility API is
20
- actually supported in the browser as, if it does not, the library will just
21
- assume that the page is visible all the time, and your logic will still work
22
- correctly, albeit less effective in some cases.
23
-
24
19
  Page Visibility API is [natively supported] by all browsers. For old browsers
25
20
  you can use `lib/visibility.fallback.js` with focus/blur hack (note that this
26
21
  hack have issue, that document become to be hidden, when browser just
@@ -73,10 +68,7 @@ Visibility.every(minute, 5 * minute, function () {
73
68
  });
74
69
  ```
75
70
 
76
- Note that the callback will also be executed on every `hidden`->`visible` state
77
- change to update old contents.
78
-
79
- `Visibility.every` returns a timer identifier, much like the `setTimeout`
71
+ `Visibility.every` returns a timer identifier, much like the `setInterval`
80
72
  function. It cannot be passed to `clearInterval`, through, and you should use
81
73
  `Visibility.stop(id)` to stop the timer.
82
74
 
@@ -197,7 +189,7 @@ $(document).load(function () {
197
189
  Using `Visibility.change(callback)` you can listen to visibility state changing
198
190
  events. The `callback` takes 2 arguments: an event object and a state name.
199
191
 
200
- Let’s collect some statistics with this evented approach:
192
+ Let’s collect some statistics with this events approach:
201
193
 
202
194
  ```js
203
195
  Visibility.change(function (e, state) {
@@ -244,13 +236,21 @@ notification.onOutOfDate(function () {
244
236
  Visibility.js is shipped with 4 files:
245
237
 
246
238
  * `visibility.core` – core module.
247
- * `visibility.timers` – `every` and `stop` methods to set `setTimeout` depend
239
+ * `visibility.timers` – `every` and `stop` methods to set `setInterval` depend
248
240
  on visibility state.
249
241
  * `visibility` – `visibility.core` and `visibility.timers` together.
250
242
  * `visibility.fallback` – fallback for browser without Page Visibility API.
251
243
  It use document `focus`/`blur` events, so document become to be hidden,
252
244
  when browser just lose focus, but still visible for user.
253
245
 
246
+ ### Bower
247
+
248
+ Visibility.js is available by Bower package manager:
249
+
250
+ ```
251
+ bower install --save visibilityjs
252
+ ```
253
+
254
254
  ### Ruby on Rails
255
255
 
256
256
  For Ruby on Rails you can use gem for Assets Pipeline.
@@ -286,7 +286,7 @@ If you don’t use any assets packaging manager use [cdnjs](http://cdnjs.com/).
286
286
  Add to your site:
287
287
 
288
288
  ```html
289
- <script src="//cdnjs.cloudflare.com/ajax/libs/visibility.js/1.0.0/visibility.min.js"></script>
289
+ <script src="//cdnjs.cloudflare.com/ajax/libs/visibility.js/1.1.0/visibility.min.js"></script>
290
290
  ```
291
291
 
292
292
  ### Other
@@ -1,21 +1,3 @@
1
- /*
2
- * Copyright 2011 Andrey “A.I.” Sitnik <andrey@sitnik.ru>,
3
- * sponsored by Evil Martians.
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU Lesser General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU Lesser General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU Lesser General Public License
16
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
1
  ;(function (undefined) {
20
2
  "use strict";
21
3
 
@@ -73,10 +55,10 @@
73
55
  if ( !self.isSupported() ) {
74
56
  return false;
75
57
  }
76
- self._lastCallback += 1;
77
- var number = self._lastCallback;
58
+ self._lastId += 1;
59
+ var number = self._lastId;
78
60
  self._callbacks[number] = callback;
79
- self._setListener();
61
+ self._listen();
80
62
  return number;
81
63
  },
82
64
 
@@ -160,36 +142,36 @@
160
142
  _doc: window.document,
161
143
 
162
144
  // Vendor prefix cached by `_prefix` function.
163
- _chechedPrefix: null,
145
+ _cached: null,
164
146
 
165
147
  // Is listener for `visibilitychange` event is already added
166
- // by `_setListener` method.
167
- _listening: false,
148
+ // by `_listen` method.
149
+ _enable: false,
168
150
 
169
151
  // Last timer number.
170
- _lastCallback: -1,
152
+ _lastId: -1,
171
153
 
172
154
  // Callbacks from `change` method, that wait visibility changes.
173
155
  _callbacks: { },
174
156
 
175
157
  // Variable to check hidden-visible state changes.
176
- _hiddenBefore: false,
158
+ _wasHidden: false,
177
159
 
178
160
  // Initialize variables on page loading.
179
161
  _init: function () {
180
- self._hiddenBefore = self.hidden();
162
+ self._wasHidden = self.hidden();
181
163
  },
182
164
 
183
165
  // Detect vendor prefix and return it.
184
166
  _prefix: function () {
185
- if ( null !== self._chechedPrefix ) {
186
- return self._chechedPrefix;
167
+ if ( null !== self._cached ) {
168
+ return self._cached;
187
169
  }
188
170
  if ( defined(self._doc.visibilityState) ) {
189
- return self._chechedPrefix = '';
171
+ return self._cached = '';
190
172
  }
191
173
  if ( defined(self._doc.webkitVisibilityState) ) {
192
- return self._chechedPrefix = 'webkit';
174
+ return self._cached = 'webkit';
193
175
  }
194
176
  },
195
177
 
@@ -214,32 +196,32 @@
214
196
  },
215
197
 
216
198
  // Listener for `visibilitychange` event.
217
- _onChange: function(event) {
199
+ _change: function(event) {
218
200
  var state = self.state();
219
201
 
220
202
  for ( var i in self._callbacks ) {
221
203
  self._callbacks[i].call(self._doc, event, state);
222
204
  }
223
205
 
224
- self._hiddenBefore = self.hidden();
206
+ self._wasHidden = self.hidden();
225
207
  },
226
208
 
227
209
  // Set listener for `visibilitychange` event.
228
- _setListener: function () {
229
- if ( self._listening ) {
210
+ _listen: function () {
211
+ if ( self._enable ) {
230
212
  return;
231
213
  }
232
214
  var event = self._prefix() + 'visibilitychange';
233
215
  var listener = function () {
234
- self._onChange.apply(Visibility, arguments);
216
+ self._change.apply(Visibility, arguments);
235
217
  };
236
218
  if ( self._doc.addEventListener ) {
237
219
  self._doc.addEventListener(event, listener, false);
238
220
  } else {
239
221
  self._doc.attachEvent(event, listener);
240
222
  }
241
- self._listening = true;
242
- self._hiddenBefore = self.hidden();
223
+ self._enable = true;
224
+ self._wasHidden = self.hidden();
243
225
  }
244
226
 
245
227
  };
@@ -1,21 +1,3 @@
1
- /*
2
- * Copyright 2011 Andrey “A.I.” Sitnik <andrey@sitnik.ru>,
3
- * sponsored by Evil Martians.
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU Lesser General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU Lesser General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU Lesser General Public License
16
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
- */
18
-
19
1
  // Add Page Visibility API support to old browsers by focus/blur hack.
20
2
  //
21
3
  // Include this script _before_ Visibility.js.
@@ -29,8 +11,7 @@
29
11
  ;(function () {
30
12
  "use strict";
31
13
 
32
- if ( document.visibilityState || document.webkitVisibilityState ||
33
- document.mozVisibilityState ) {
14
+ if ( document.visibilityState || document.webkitVisibilityState ) {
34
15
  return;
35
16
  }
36
17
 
@@ -48,7 +29,7 @@
48
29
  document.dispatchEvent(event);
49
30
  } else {
50
31
  if ( typeof(Visibility) == 'object' ) {
51
- Visibility._onChange.call(Visibility, { })
32
+ Visibility._change.call(Visibility, { });
52
33
  }
53
34
  }
54
35
  }