visibilityjs 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.4 (Vanguard 1, alternative)
2
+ * Add fallback API support by focus/blur hack to all browsers.
3
+
1
4
  == 0.3 (Explorer 1, answer)
2
5
  * Rename gem to visibilityjs.
3
6
  * Fix gem integration with Asset Pipeline paths.
data/README.md CHANGED
@@ -21,8 +21,19 @@ actually supported in the browser as, if it does not, the library will just
21
21
  assume that the page is visible all the time, and your logic will still work
22
22
  correctly, albeit less effective in some cases.
23
23
 
24
+ Page Visibility API is natively supported by Google Chrome and IE 10. You can
25
+ add support to Firefox 5 by [MozVisibility] hack (include it before
26
+ Visibility.js). For others browsers you can use `lib/visibility.fallback.js`
27
+ with focus/blur hack (note that this hack have some issue,
28
+ see falllback documentation).
29
+
24
30
  [Page Visibility API]: http://www.w3.org/TR/2011/WD-page-visibility-20110602/
25
- [prerendering]: http://code.google.com/chrome/whitepapers/prerender.html
31
+ [prerendering]: http://code.google.com/chrome/whitepapers/prerender.html
32
+ [MozVisibility]: https://github.com/private-face/mozvisibility
33
+
34
+ ## Translations
35
+
36
+ Документация на русском: <http://habrahabr.ru/blogs/javascript/125833/>
26
37
 
27
38
  ## States
28
39
 
@@ -77,7 +88,7 @@ function. It cannot be passed to `clearInterval`, through, and you should use
77
88
  `Visibility.stop(id)` to stop the timer.
78
89
 
79
90
  ```js
80
- slideshow = Visibility.every(5 * 1000, function () {
91
+ var slideshow = Visibility.every(5 * 1000, function () {
81
92
  nextSlide();
82
93
  });
83
94
 
@@ -237,6 +248,11 @@ If you don’t use Rails 3.1 or assets packaging manager you can use an already
237
248
  minified version of the library, located in repository as
238
249
  `lib/visibility.min.js`.
239
250
 
251
+ ## Alternatives
252
+
253
+ If you need smaller and simpler wrapper (for example, just to hide vendor
254
+ prefixes), you can use [visibly.js](https://github.com/addyosmani/visibly.js).
255
+
240
256
  ## Contributing
241
257
 
242
258
  To run project tests and minimize source you’ll need to have Ruby and Bundler
@@ -0,0 +1,75 @@
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
+ // Add Page Visibility API support to old browsers by focus/blur hack.
20
+ //
21
+ // Include this script _before_ Visibility.js.
22
+ //
23
+ // Note, that this hack doesn’t correctly emulate Page Visibility API:
24
+ // when user change focus from browser to another window (browser and your
25
+ // page may stay visible), this hack will decide, that you page is hidden.
26
+ //
27
+ // For Firefox 5 it will be better to use MozVisibility hack without this issue.
28
+ // See <https://github.com/private-face/mozvisibility>.
29
+ ;(function() {
30
+ "use strict";
31
+
32
+ if ( document.visibilityState || document.webkitVisibilityState ||
33
+ document.msVisibilityState || document.mozVisibilityState ||
34
+ document.oVisibilityState ) {
35
+ return;
36
+ }
37
+
38
+ document.hidden = false;
39
+ document.visibilityState = 'visible';
40
+
41
+ var event = null
42
+ var i = 0
43
+ var fireEvent = function () {
44
+ if( document.createEvent ) {
45
+ if ( !event ) {
46
+ event = document.createEvent('HTMLEvents');
47
+ event.initEvent('visibilitychange', true, true);
48
+ }
49
+ document.dispatchEvent(event);
50
+ } else {
51
+ if ( typeof(Visibility) == 'object' ) {
52
+ Visibility._onVisibilityChange.call(Visibility, { })
53
+ }
54
+ }
55
+ }
56
+
57
+ var onfocus = function () {
58
+ document.hidden = false;
59
+ document.visibilityState = 'visible';
60
+ fireEvent();
61
+ };
62
+ var onblur = function () {
63
+ document.hidden = true;
64
+ document.visibilityState = 'hidden';
65
+ fireEvent();
66
+ }
67
+
68
+ if ( document.addEventListener ) {
69
+ window.addEventListener('focus', onfocus, true);
70
+ window.addEventListener('blur', onblur, true);
71
+ } else {
72
+ document.attachEvent('onfocusin', onfocus);
73
+ document.attachEvent('onfocusout', onblur);
74
+ }
75
+ })();
@@ -147,9 +147,14 @@
147
147
  return;
148
148
  }
149
149
  var event = this._prefix() + 'visibilitychange';
150
- this._doc.addEventListener(event, function () {
150
+ var listener = function () {
151
151
  Visibility._onVisibilityChange.apply(Visibility, arguments);
152
- }, false);
152
+ };
153
+ if ( this._doc.addEventListener ) {
154
+ this._doc.addEventListener(event, listener, false);
155
+ } else {
156
+ this._doc.attachEvent(event, listener);
157
+ }
153
158
  this._listening = true;
154
159
  this._hiddenBefore = this.hidden();
155
160
  },
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: visibilityjs
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- version: "0.3"
8
+ - 4
9
+ version: "0.4"
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Andrey \xE2\x80\x9CA.I.\xE2\x80\x9D Sitnik"
@@ -14,11 +14,10 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-07-31 00:00:00 +04:00
17
+ date: 2011-09-11 00:00:00 +04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- prerelease: false
22
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
23
22
  none: false
24
23
  requirements:
@@ -35,6 +34,7 @@ dependencies:
35
34
  requirement: *id001
36
35
  type: :runtime
37
36
  name: sprockets
37
+ prerelease: false
38
38
  description: Visibility.js allow you to determine whether your web page is visible to an user, is hidden in background tab or is prerendering. It allows you use the page visibility state in JavaScript logic and improve browser performance or improve user interface experience.
39
39
  email:
40
40
  - andrey@sitnik.ru
@@ -48,6 +48,7 @@ extra_rdoc_files:
48
48
  - ChangeLog
49
49
  files:
50
50
  - vendor/assets/javascripts/visibility.js
51
+ - vendor/assets/javascripts/visibility.fallback.js
51
52
  - lib/visibilityjs.rb
52
53
  - LICENSE
53
54
  - README.md