viewport_units_buggyfill 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/viewport_units_buggyfill/version.rb +3 -0
- data/lib/viewport_units_buggyfill.rb +5 -0
- data/vendor/assets/javascripts/viewport-units-buggyfill.js +424 -0
- data/viewport_units_buggyfill.gemspec +24 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6269bc15e5a5f8f9b95b110d02e262c550030ca3
|
4
|
+
data.tar.gz: 61a8e77e38d066a4012f5d7c208c1e8b8f736e76
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 03a573ef10160d28f30cd4ffdd15746a493ed4b5c56254c4d9feccfa99b63ff3ea12c7d72c09ab72db3d90cffaff41edf8671f02750d4b064dc4e5162ab757d6
|
7
|
+
data.tar.gz: 41c83fc020eab821063eb4f96002e4188f94a26f929527607d17a5184dc53c058e8f853fb6e36cf2e56dcf750fb4438730b91e36aa9bb0f28989fbc526fe330f
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Tang Rufus
|
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,49 @@
|
|
1
|
+
# ViewportUnitsBuggyfill
|
2
|
+
|
3
|
+
This gem bundles the contents of [Viewport Units Buggyfill](https://github.com/rodneyrehm/viewport-units-buggyfill) from [rodneyrehm](http://rodneyrehm.de/en/)
|
4
|
+
|
5
|
+
Making viewport units (vh|vw|vmin|vmax) work properly in Mobile Safari.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'viewport_units_buggyfill'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install viewport_units_buggyfill
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
The viewport-units-buggyfill file will be added to the asset pipeline and available for you to use. In `app/assets/javascripts/application.js`, add this line:
|
26
|
+
|
27
|
+
```
|
28
|
+
//= require viewport-units-buggyfill
|
29
|
+
```
|
30
|
+
|
31
|
+
## Change log
|
32
|
+
|
33
|
+
###0.1.0 (25 May 2015)
|
34
|
+
|
35
|
+
Initial release with viewport-units-buggyfill.js v0.5.3
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Feel free to open an issue ticket if you find something that could be improved. A couple notes:
|
40
|
+
|
41
|
+
If it's an issue pertaining to the viewport-units-buggyfill javascript, please report it to the viewport-units-buggyfill project.
|
42
|
+
|
43
|
+
If the viewport-units-buggyfill scripts are outdated (i.e. maybe a new version of viewport-units-buggyfill was released yesterday), feel free to open an issue and prod us to get that thing updated. However, for security reasons, we won't be accepting pull requests with updated viewport-units-buggyfill scripts.
|
44
|
+
|
45
|
+
1. Fork it ( https://github.com/[my-github-username]/viewport_units_buggyfill/fork )
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'viewport_units_buggyfill'
|
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
@@ -0,0 +1,424 @@
|
|
1
|
+
/*!
|
2
|
+
* viewport-units-buggyfill v0.5.3
|
3
|
+
* @web: https://github.com/rodneyrehm/viewport-units-buggyfill/
|
4
|
+
* @author: Rodney Rehm - http://rodneyrehm.de/en/
|
5
|
+
*/
|
6
|
+
|
7
|
+
(function (root, factory) {
|
8
|
+
'use strict';
|
9
|
+
if (typeof define === 'function' && define.amd) {
|
10
|
+
// AMD. Register as an anonymous module.
|
11
|
+
define([], factory);
|
12
|
+
} else if (typeof exports === 'object') {
|
13
|
+
// Node. Does not work with strict CommonJS, but
|
14
|
+
// only CommonJS-like enviroments that support module.exports,
|
15
|
+
// like Node.
|
16
|
+
module.exports = factory();
|
17
|
+
} else {
|
18
|
+
// Browser globals (root is window)
|
19
|
+
root.viewportUnitsBuggyfill = factory();
|
20
|
+
}
|
21
|
+
}(this, function () {
|
22
|
+
'use strict';
|
23
|
+
/*global document, window, navigator, location, XMLHttpRequest, XDomainRequest*/
|
24
|
+
|
25
|
+
var initialized = false;
|
26
|
+
var options;
|
27
|
+
var userAgent = window.navigator.userAgent;
|
28
|
+
var viewportUnitExpression = /([+-]?[0-9.]+)(vh|vw|vmin|vmax)/g;
|
29
|
+
var forEach = [].forEach;
|
30
|
+
var dimensions;
|
31
|
+
var declarations;
|
32
|
+
var styleNode;
|
33
|
+
var isBuggyIE = false;
|
34
|
+
var isOldIE = false;
|
35
|
+
var isOperaMini = userAgent.indexOf('Opera Mini') > -1;
|
36
|
+
|
37
|
+
var isMobileSafari = /(iPhone|iPod|iPad).+AppleWebKit/i.test(userAgent) && (function() {
|
38
|
+
// Regexp for iOS-version tested against the following userAgent strings:
|
39
|
+
// Example WebView UserAgents:
|
40
|
+
// * iOS Chrome on iOS8: "Mozilla/5.0 (iPad; CPU OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) CriOS/39.0.2171.50 Mobile/12B410 Safari/600.1.4"
|
41
|
+
// * iOS Facebook on iOS7: "Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D201 [FBAN/FBIOS;FBAV/12.1.0.24.20; FBBV/3214247; FBDV/iPhone6,1;FBMD/iPhone; FBSN/iPhone OS;FBSV/7.1.1; FBSS/2; FBCR/AT&T;FBID/phone;FBLC/en_US;FBOP/5]"
|
42
|
+
// Example Safari UserAgents:
|
43
|
+
// * Safari iOS8: "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4"
|
44
|
+
// * Safari iOS7: "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A4449d Safari/9537.53"
|
45
|
+
var iOSversion = userAgent.match(/OS (\d)/);
|
46
|
+
// viewport units work fine in mobile Safari and webView on iOS 8+
|
47
|
+
return iOSversion && iOSversion.length>1 && parseInt(iOSversion[1]) < 8;
|
48
|
+
})();
|
49
|
+
|
50
|
+
var isBadStockAndroid = (function() {
|
51
|
+
// Android stock browser test derived from
|
52
|
+
// http://stackoverflow.com/questions/24926221/distinguish-android-chrome-from-stock-browser-stock-browsers-user-agent-contai
|
53
|
+
var isAndroid = userAgent.indexOf(' Android ') > -1;
|
54
|
+
if (!isAndroid) {
|
55
|
+
return false;
|
56
|
+
}
|
57
|
+
|
58
|
+
var isStockAndroid = userAgent.indexOf('Version/') > -1;
|
59
|
+
if (!isStockAndroid) {
|
60
|
+
return false;
|
61
|
+
}
|
62
|
+
|
63
|
+
var versionNumber = parseFloat((userAgent.match('Android ([0-9.]+)') || [])[1]);
|
64
|
+
// anything below 4.4 uses WebKit without *any* viewport support,
|
65
|
+
// 4.4 has issues with viewport units within calc()
|
66
|
+
return versionNumber <= 4.4;
|
67
|
+
})();
|
68
|
+
|
69
|
+
// Do not remove the following comment!
|
70
|
+
// It is a conditional comment used to
|
71
|
+
// identify old Internet Explorer versions
|
72
|
+
|
73
|
+
/*@cc_on
|
74
|
+
|
75
|
+
@if (9 <= @_jscript_version && @_jscript_version <= 10)
|
76
|
+
isBuggyIE = true;
|
77
|
+
@end
|
78
|
+
|
79
|
+
@if (@_jscript_version < 9) {
|
80
|
+
isOldIE = true;
|
81
|
+
}
|
82
|
+
@end
|
83
|
+
|
84
|
+
@*/
|
85
|
+
|
86
|
+
// added check for IE11, since it *still* doesn't understand vmax!!!
|
87
|
+
if (!isBuggyIE) {
|
88
|
+
isBuggyIE = !!navigator.userAgent.match(/Trident.*rv[ :]*11\./);
|
89
|
+
}
|
90
|
+
function debounce(func, wait) {
|
91
|
+
var timeout;
|
92
|
+
return function() {
|
93
|
+
var context = this;
|
94
|
+
var args = arguments;
|
95
|
+
var callback = function() {
|
96
|
+
func.apply(context, args);
|
97
|
+
};
|
98
|
+
|
99
|
+
clearTimeout(timeout);
|
100
|
+
timeout = setTimeout(callback, wait);
|
101
|
+
};
|
102
|
+
}
|
103
|
+
|
104
|
+
// from http://stackoverflow.com/questions/326069/how-to-identify-if-a-webpage-is-being-loaded-inside-an-iframe-or-directly-into-t
|
105
|
+
function inIframe() {
|
106
|
+
try {
|
107
|
+
return window.self !== window.top;
|
108
|
+
} catch (e) {
|
109
|
+
return true;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
function initialize(initOptions) {
|
114
|
+
if (initialized) {
|
115
|
+
return;
|
116
|
+
}
|
117
|
+
|
118
|
+
if (initOptions === true) {
|
119
|
+
initOptions = {
|
120
|
+
force: true
|
121
|
+
};
|
122
|
+
}
|
123
|
+
|
124
|
+
options = initOptions || {};
|
125
|
+
options.isMobileSafari = isMobileSafari;
|
126
|
+
options.isBadStockAndroid = isBadStockAndroid;
|
127
|
+
|
128
|
+
if (isOldIE || (!options.force && !isMobileSafari && !isBuggyIE && !isBadStockAndroid && !isOperaMini && (!options.hacks || !options.hacks.required(options)))) {
|
129
|
+
// this buggyfill only applies to mobile safari, IE9-10 and the Stock Android Browser.
|
130
|
+
if (window.console && isOldIE) {
|
131
|
+
console.info('viewport-units-buggyfill requires a proper CSSOM and basic viewport unit support, which are not available in IE8 and below');
|
132
|
+
}
|
133
|
+
|
134
|
+
return {
|
135
|
+
init: function () {}
|
136
|
+
};
|
137
|
+
}
|
138
|
+
|
139
|
+
options.hacks && options.hacks.initialize(options);
|
140
|
+
|
141
|
+
initialized = true;
|
142
|
+
styleNode = document.createElement('style');
|
143
|
+
styleNode.id = 'patched-viewport';
|
144
|
+
document.head.appendChild(styleNode);
|
145
|
+
|
146
|
+
// Issue #6: Cross Origin Stylesheets are not accessible through CSSOM,
|
147
|
+
// therefore download and inject them as <style> to circumvent SOP.
|
148
|
+
importCrossOriginLinks(function() {
|
149
|
+
var _refresh = debounce(refresh, options.refreshDebounceWait || 100);
|
150
|
+
// doing a full refresh rather than updateStyles because an orientationchange
|
151
|
+
// could activate different stylesheets
|
152
|
+
window.addEventListener('orientationchange', _refresh, true);
|
153
|
+
// orientationchange might have happened while in a different window
|
154
|
+
window.addEventListener('pageshow', _refresh, true);
|
155
|
+
|
156
|
+
if (options.force || isBuggyIE || inIframe()) {
|
157
|
+
window.addEventListener('resize', _refresh, true);
|
158
|
+
options._listeningToResize = true;
|
159
|
+
}
|
160
|
+
|
161
|
+
options.hacks && options.hacks.initializeEvents(options, refresh, _refresh);
|
162
|
+
|
163
|
+
refresh();
|
164
|
+
});
|
165
|
+
}
|
166
|
+
|
167
|
+
function updateStyles() {
|
168
|
+
styleNode.textContent = getReplacedViewportUnits();
|
169
|
+
// move to the end in case inline <style>s were added dynamically
|
170
|
+
styleNode.parentNode.appendChild(styleNode);
|
171
|
+
}
|
172
|
+
|
173
|
+
function refresh() {
|
174
|
+
if (!initialized) {
|
175
|
+
return;
|
176
|
+
}
|
177
|
+
|
178
|
+
findProperties();
|
179
|
+
|
180
|
+
// iOS Safari will report window.innerWidth and .innerHeight as 0 unless a timeout is used here.
|
181
|
+
// TODO: figure out WHY innerWidth === 0
|
182
|
+
setTimeout(function() {
|
183
|
+
updateStyles();
|
184
|
+
}, 1);
|
185
|
+
}
|
186
|
+
|
187
|
+
function findProperties() {
|
188
|
+
declarations = [];
|
189
|
+
forEach.call(document.styleSheets, function(sheet) {
|
190
|
+
if (sheet.ownerNode.id === 'patched-viewport' || !sheet.cssRules || sheet.ownerNode.getAttribute('data-viewport-units-buggyfill') === 'ignore') {
|
191
|
+
// skip entire sheet because no rules are present, it's supposed to be ignored or it's the target-element of the buggyfill
|
192
|
+
return;
|
193
|
+
}
|
194
|
+
|
195
|
+
if (sheet.media && sheet.media.mediaText && window.matchMedia && !window.matchMedia(sheet.media.mediaText).matches) {
|
196
|
+
// skip entire sheet because media attribute doesn't match
|
197
|
+
return;
|
198
|
+
}
|
199
|
+
|
200
|
+
forEach.call(sheet.cssRules, findDeclarations);
|
201
|
+
});
|
202
|
+
|
203
|
+
return declarations;
|
204
|
+
}
|
205
|
+
|
206
|
+
function findDeclarations(rule) {
|
207
|
+
if (rule.type === 7) {
|
208
|
+
var value;
|
209
|
+
|
210
|
+
// there may be a case where accessing cssText throws an error.
|
211
|
+
// I could not reproduce this issue, but the worst that can happen
|
212
|
+
// this way is an animation not running properly.
|
213
|
+
// not awesome, but probably better than a script error
|
214
|
+
// see https://github.com/rodneyrehm/viewport-units-buggyfill/issues/21
|
215
|
+
try {
|
216
|
+
value = rule.cssText;
|
217
|
+
} catch(e) {
|
218
|
+
return;
|
219
|
+
}
|
220
|
+
|
221
|
+
viewportUnitExpression.lastIndex = 0;
|
222
|
+
if (viewportUnitExpression.test(value)) {
|
223
|
+
// KeyframesRule does not have a CSS-PropertyName
|
224
|
+
declarations.push([rule, null, value]);
|
225
|
+
options.hacks && options.hacks.findDeclarations(declarations, rule, null, value);
|
226
|
+
}
|
227
|
+
|
228
|
+
return;
|
229
|
+
}
|
230
|
+
|
231
|
+
if (!rule.style) {
|
232
|
+
if (!rule.cssRules) {
|
233
|
+
return;
|
234
|
+
}
|
235
|
+
|
236
|
+
forEach.call(rule.cssRules, function(_rule) {
|
237
|
+
findDeclarations(_rule);
|
238
|
+
});
|
239
|
+
|
240
|
+
return;
|
241
|
+
}
|
242
|
+
|
243
|
+
forEach.call(rule.style, function(name) {
|
244
|
+
var value = rule.style.getPropertyValue(name);
|
245
|
+
// preserve those !important rules
|
246
|
+
if (rule.style.getPropertyPriority(name)) {
|
247
|
+
value += ' !important';
|
248
|
+
}
|
249
|
+
|
250
|
+
viewportUnitExpression.lastIndex = 0;
|
251
|
+
if (viewportUnitExpression.test(value)) {
|
252
|
+
declarations.push([rule, name, value]);
|
253
|
+
options.hacks && options.hacks.findDeclarations(declarations, rule, name, value);
|
254
|
+
}
|
255
|
+
});
|
256
|
+
}
|
257
|
+
|
258
|
+
function getReplacedViewportUnits() {
|
259
|
+
dimensions = getViewport();
|
260
|
+
|
261
|
+
var css = [];
|
262
|
+
var buffer = [];
|
263
|
+
var open;
|
264
|
+
var close;
|
265
|
+
|
266
|
+
declarations.forEach(function(item) {
|
267
|
+
var _item = overwriteDeclaration.apply(null, item);
|
268
|
+
var _open = _item.selector.length ? (_item.selector.join(' {\n') + ' {\n') : '';
|
269
|
+
var _close = new Array(_item.selector.length + 1).join('\n}');
|
270
|
+
|
271
|
+
if (!_open || _open !== open) {
|
272
|
+
if (buffer.length) {
|
273
|
+
css.push(open + buffer.join('\n') + close);
|
274
|
+
buffer.length = 0;
|
275
|
+
}
|
276
|
+
|
277
|
+
if (_open) {
|
278
|
+
open = _open;
|
279
|
+
close = _close;
|
280
|
+
buffer.push(_item.content);
|
281
|
+
} else {
|
282
|
+
css.push(_item.content);
|
283
|
+
open = null;
|
284
|
+
close = null;
|
285
|
+
}
|
286
|
+
|
287
|
+
return;
|
288
|
+
}
|
289
|
+
|
290
|
+
if (_open && !open) {
|
291
|
+
open = _open;
|
292
|
+
close = _close;
|
293
|
+
}
|
294
|
+
|
295
|
+
buffer.push(_item.content);
|
296
|
+
});
|
297
|
+
|
298
|
+
if (buffer.length) {
|
299
|
+
css.push(open + buffer.join('\n') + close);
|
300
|
+
}
|
301
|
+
|
302
|
+
// Opera Mini messes up on the content hack (it replaces the DOM node's innerHTML with the value).
|
303
|
+
// This fixes it. We test for Opera Mini only since it is the most expensive CSS selector
|
304
|
+
// see https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors
|
305
|
+
if (isOperaMini) {
|
306
|
+
css.push('* { content: normal !important; }');
|
307
|
+
}
|
308
|
+
|
309
|
+
return css.join('\n\n');
|
310
|
+
}
|
311
|
+
|
312
|
+
function overwriteDeclaration(rule, name, value) {
|
313
|
+
var _value;
|
314
|
+
var _selectors = [];
|
315
|
+
|
316
|
+
_value = value.replace(viewportUnitExpression, replaceValues);
|
317
|
+
|
318
|
+
if (options.hacks) {
|
319
|
+
_value = options.hacks.overwriteDeclaration(rule, name, _value);
|
320
|
+
}
|
321
|
+
|
322
|
+
if (name) {
|
323
|
+
// skipping KeyframesRule
|
324
|
+
_selectors.push(rule.selectorText);
|
325
|
+
_value = name + ': ' + _value + ';';
|
326
|
+
}
|
327
|
+
|
328
|
+
var _rule = rule.parentRule;
|
329
|
+
while (_rule) {
|
330
|
+
_selectors.unshift('@media ' + _rule.media.mediaText);
|
331
|
+
_rule = _rule.parentRule;
|
332
|
+
}
|
333
|
+
|
334
|
+
return {
|
335
|
+
selector: _selectors,
|
336
|
+
content: _value
|
337
|
+
};
|
338
|
+
}
|
339
|
+
|
340
|
+
function replaceValues(match, number, unit) {
|
341
|
+
var _base = dimensions[unit];
|
342
|
+
var _number = parseFloat(number) / 100;
|
343
|
+
return (_number * _base) + 'px';
|
344
|
+
}
|
345
|
+
|
346
|
+
function getViewport() {
|
347
|
+
var vh = window.innerHeight;
|
348
|
+
var vw = window.innerWidth;
|
349
|
+
|
350
|
+
return {
|
351
|
+
vh: vh,
|
352
|
+
vw: vw,
|
353
|
+
vmax: Math.max(vw, vh),
|
354
|
+
vmin: Math.min(vw, vh)
|
355
|
+
};
|
356
|
+
}
|
357
|
+
|
358
|
+
function importCrossOriginLinks(next) {
|
359
|
+
var _waiting = 0;
|
360
|
+
var decrease = function() {
|
361
|
+
_waiting--;
|
362
|
+
if (!_waiting) {
|
363
|
+
next();
|
364
|
+
}
|
365
|
+
};
|
366
|
+
|
367
|
+
forEach.call(document.styleSheets, function(sheet) {
|
368
|
+
if (!sheet.href || origin(sheet.href) === origin(location.href) || sheet.ownerNode.getAttribute('data-viewport-units-buggyfill') === 'ignore') {
|
369
|
+
// skip <style> and <link> from same origin or explicitly declared to ignore
|
370
|
+
return;
|
371
|
+
}
|
372
|
+
|
373
|
+
_waiting++;
|
374
|
+
convertLinkToStyle(sheet.ownerNode, decrease);
|
375
|
+
});
|
376
|
+
|
377
|
+
if (!_waiting) {
|
378
|
+
next();
|
379
|
+
}
|
380
|
+
}
|
381
|
+
|
382
|
+
function origin(url) {
|
383
|
+
return url.slice(0, url.indexOf('/', url.indexOf('://') + 3));
|
384
|
+
}
|
385
|
+
|
386
|
+
function convertLinkToStyle(link, next) {
|
387
|
+
getCors(link.href, function() {
|
388
|
+
var style = document.createElement('style');
|
389
|
+
style.media = link.media;
|
390
|
+
style.setAttribute('data-href', link.href);
|
391
|
+
style.textContent = this.responseText;
|
392
|
+
link.parentNode.replaceChild(style, link);
|
393
|
+
next();
|
394
|
+
}, next);
|
395
|
+
}
|
396
|
+
|
397
|
+
function getCors(url, success, error) {
|
398
|
+
var xhr = new XMLHttpRequest();
|
399
|
+
if ('withCredentials' in xhr) {
|
400
|
+
// XHR for Chrome/Firefox/Opera/Safari.
|
401
|
+
xhr.open('GET', url, true);
|
402
|
+
} else if (typeof XDomainRequest !== 'undefined') {
|
403
|
+
// XDomainRequest for IE.
|
404
|
+
xhr = new XDomainRequest();
|
405
|
+
xhr.open('GET', url);
|
406
|
+
} else {
|
407
|
+
throw new Error('cross-domain XHR not supported');
|
408
|
+
}
|
409
|
+
|
410
|
+
xhr.onload = success;
|
411
|
+
xhr.onerror = error;
|
412
|
+
xhr.send();
|
413
|
+
return xhr;
|
414
|
+
}
|
415
|
+
|
416
|
+
return {
|
417
|
+
version: '0.5.3',
|
418
|
+
findProperties: findProperties,
|
419
|
+
getCss: getReplacedViewportUnits,
|
420
|
+
init: initialize,
|
421
|
+
refresh: refresh
|
422
|
+
};
|
423
|
+
|
424
|
+
}));
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'viewport_units_buggyfill/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'viewport_units_buggyfill'
|
8
|
+
spec.version = ViewportUnitsBuggyfill::VERSION
|
9
|
+
spec.authors = ['Tang Rufus']
|
10
|
+
spec.email = ['tangrufus@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'This gem bundles the contents of Viewport Units Buggyfill from rodneyrehm'
|
13
|
+
spec.description = 'Making viewport units (vh|vw|vmin|vmax) work properly in Mobile Safari.'
|
14
|
+
spec.homepage = 'https://github.com/TangRufus/viewport_units_buggyfill'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: viewport_units_buggyfill
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tang Rufus
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Making viewport units (vh|vw|vmin|vmax) work properly in Mobile Safari.
|
42
|
+
email:
|
43
|
+
- tangrufus@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rubocop.yml"
|
50
|
+
- ".travis.yml"
|
51
|
+
- CODE_OF_CONDUCT.md
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- lib/viewport_units_buggyfill.rb
|
59
|
+
- lib/viewport_units_buggyfill/version.rb
|
60
|
+
- vendor/assets/javascripts/viewport-units-buggyfill.js
|
61
|
+
- viewport_units_buggyfill.gemspec
|
62
|
+
homepage: https://github.com/TangRufus/viewport_units_buggyfill
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.4.6
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: This gem bundles the contents of Viewport Units Buggyfill from rodneyrehm
|
86
|
+
test_files: []
|