Giter Site home page Giter Site logo

viewport-units-buggyfill's Introduction

Viewport Units Buggyfill™

This is a buggyfill (fixing bad behavior), not a polyfill (adding missing behavior). That said, it provides hacks for you to get viewport units working in old IE and Android Stock Browser as well. If the browser doesn't know how to deal with the viewport units - vw, vh, vmin and vmax - this library will not improve the situation unless you're using the hacks detailed below. The buggyfill uses the CSSOM to access the defined styles rather than ship its own CSS parser, that'S why the hacks abuse the CSS property content to get the values across.


Amongst other things, the buggyfill helps with the following problems:

  • viewport units (vh|vw|vmin|vmax) in Mobile Safari
  • viewport units inside calc() expressions in Mobile Safari and IE9+ (hack)
  • vmin, vmax in IE9+ (hack)
  • viewport units in old Android Stock Browser (hack)

The buggyfill iterates through all defined styles the document knows and extracts those that uses a viewport unit. After resolving the relative units against the viewport's dimensions, CSS is put back together and injected into the document in a <style> element. Listening to the orientationchange event allows the buggyfill to update the calculated dimensions accordingly.

The hacks use the content property to transport viewport-unit styles that need to be calculated by script, this is done because unsupporting browsers do not expose original declarations such as height: calc(100vh - 10px):

content: 'viewport-units-buggyfill; width: 50vmin; height: 50vmax; top: calc(50vh - 100px); left: calc(50vw - 100px);';

Note: The content hack may not work well on <img> and other replaced elements, even though it should compute to content: normal; on regular elements. If you find yourself in such a situation, this may be a way out:

img {
  content: normal !important;
}

Note: This buggyfill only works on stylesheets! viewport units used in style attributes are not resolved.

Note: The buggyfill can easily trip over files host on different origins (requiring CORS) and relative URLs to images/fonts/… within stylesheets. #11

Using viewport-units-buggyfill

After loading the buggyfill from npm (npm install viewport-units-buggyfill) or bower (bower install viewport-units-buggyfill), it has to be required and initialized:

require('viewport-units-buggyfill').init();

If you're - for whatever reason - not using a package manager, include the script as follows:

<script src="viewport-units-buggyfill.js"></script>
<script>window.viewportUnitsBuggyfill.init();</script>

To engage the buggyfill with hacks, pass them in at initialization:

var hacks = require('viewport-units-buggyfill/viewport-units-buggyfill.hacks');
require('viewport-units-buggyfill').init({
  hacks: hacks
});

To exempt certain stylesheets from being processed, the attribute data-viewport-units-buggyfill="ignore":

<link rel="stylesheet" href="file-to-ignore.css" data-viewport-units-buggyfill="ignore">
<link rel="stylesheet" href="file-to-process.css">

API

viewport-units-buggyfill exposes the following API:

var viewportUnitsBuggyfill = require('viewport-units-buggyfill');

// find viewport-unit declarations,
// convert them to pixels,
// inject style-element into document,
// register orientationchange event (and resize events in IE9+) to repeat when necessary
// will only engage for Mobile Safari on iOS and IE9+
viewportUnitsBuggyfill.init();

// ignore user agent force initialization
viewportUnitsBuggyfill.init({force: true});

// reduces the amount of times the buggyfill is reinitialized on window resize in IE
// for performance reasons.
viewportUnitsBuggyfill.init({refreshDebounceWait: 250});

// This enables abusing the CSS property 'content' to allow transporting
// viewport unit values for browsers with spotty support:
//   * vmin in IE9
//   * vmax in IE9, iOS <= 6
//   * calc(vh/vmin) in iOS < 8 and Android Stock Browser <= 4.4
//   * all of viewport units in Android Stock Browser <= 4.3
//
// To engage these hacks, you need to load the hacks file as well:
//
//   <script src="/path/to/viewport-units-buggyfill.hacks.js"></script>
//
viewportUnitsBuggyfill.init({hacks: window.viewportUnitsBuggyfillHacks});

// append the patched stylesheet to body instead of head
viewportUnitsBuggyfill.init({appendToBody: true});

// update internal declarations cache and recalculate pixel styles
// this is handy when you add styles after .init() was run
viewportUnitsBuggyfill.refresh();

// you can do things manually (without the style-element injection):
// identify all declarations using viewport units
viewportUnitsBuggyfill.findProperties();
var cssText = viewportUnitsBuggyfill.getCss();

In CSS you can declare fallbacks to be used by the buggyfill's hacks:

.my-viewport-units-using-thingie {
  width: 50vmin;
  height: 50vmax;
  top: calc(50vh - 100px);
  left: calc(50vw - 100px);

  /* hack to engage viewport-units-buggyfill */
  content: 'viewport-units-buggyfill; width: 50vmin; height: 50vmax; top: calc(50vh - 100px); left: calc(50vw - 100px);';
}

The buggyfill emits the event viewport-unit-buggyfill-init before initializing and viewport-unit-buggyfill-style after applying the fixed styles to the document. The events are dispatched on window and may be used as follows:

window.addEventListener('viewport-unit-buggyfill-init', function() {
  console.log('getting lost in CSSOM');
});
window.addEventListener('viewport-unit-buggyfill-style', function() {
  console.log('updated rules using viewport unit');
});

Cross Origin Stylesheets

Warning: Including stylesheets from third party services, like Google WebFonts, requires those resources to be served with appropriate CORS headers. You may also need to be aware of the fact that relative URLs within those stylesheets are NOT resolved, possibly leading to missing fonts and images.

Changelog

0.6.2 (July 21st 2017)

  • allow appending generated CSS to <body> - #84
  • do not break URLs when replacing viewport units - #78
  • wrapping everything in an IIFE - #80

0.6.1 (March 16th 2017)

0.6.0 (March 19th 2016)

  • enabling the buggyfill for iOS 8 and iOS 9 - #67, #35
  • enabling the buggyfill for Microsoft Edge, as it still does not understand vmax - #60
  • adding init option ignoreVmax to prevent IE9+ from engaging the hack - #56
  • fixing foreign origin access violation in Internet Explorer - #61, #38

0.5.5 (August 21st 2015)

  • adding events viewport-unit-buggyfill-init and viewport-unit-buggyfill-style (#63 by redaxmedia, #62)

0.5.4 (July 15th 2015)

  • changing Internet Explorer detection from Conditional Comments to UA sniffing - (#57 by dillonlucente, #43, #40)

0.5.3 (April 21st 2015)

  • fixing CORS importer to respect data-viewport-units-buggyfill="ignore" (#48)

0.5.2 (April 5th 2015)

  • fixing init for IE8 and below to avoid exception due to bad CSSOM (#46, #47 by zoltan-dulac)

0.5.1 (March 10th 2015)

  • fixing generated <style> element to maintain highest precedence (#36)
  • fixing the preservation of !important rules (#44, #45 by mderazon)

0.5.0 (December 23rd 2014)

WARNING: Breaking Changes (and a Merry Christmas to you, too :)

  • not engaging the buggyfill on iOS8+ anymore (#19, #23, #27)
  • also engaging buggyfill for WebViews in <iOS8 (#30)
  • fixing stock Android browser behavior of viewport units when changing breakpoints
  • fixing content hack breaking in Opera Mini (because it actually inlines the content everywhere)
  • fixing rule.cssText throwing an Error in IE (not reproducible, whatever) #21)
  • remove separate CSS content and behavior hacks and merge them into one. This is a backward compatibility breaking change! The only acceptable way to specify viewport-unit rules to a non-supporting browser now is content: "viewport-units-buggyfill; width: 20vw;" (#20, #25)
  • removing need for initialization options behaviorHack and contentHack, passing hacks will suffice (#20, #25)
  • adding IE11 to the list to fix its vmax support (#31)
  • adding <link rel="…" data-viewport-units-buggyfill="ignore"> to prevent specific stylesheets from being processed (suggested in #11)

0.4.1 (September 8th 2014)

  • fixing bower.json (… narf)

0.4.0 (September 8th 2014)

  • fixes IE9 and Safari native way of calculating viewport units differently inside of a frame. Without this buggyfill, IE9 will assume the 100vw and 100vh to be the width and height of the parent document’s viewport, while Safari for iOS will choose 1px (!!!!) for both.
  • fixes IE9's issue when calculate viewport units correctly when changing media-query breakpoints.
  • adds vmin support for IE9 (instead of vm, IE9's equivalent to vmin) and vmax support to IE9 and 10. (Note that this will only work when initializing with viewportUnitsBuggyfill.init({hacks: window.viewportUnitsBuggyfillHacks});) and adding the viewport-units-buggyfill.hacks.js to the page after viewport-units-buggyfill.js.
.myLargeBlock {
  /* Non-IE browsers */
  width: 50vmin;
  height: 50vmax;

  /* IE9 and 10 */
  behavior: 'use_css_behavior_hack: true; width: 50vmin; height: 50vmax;';
  /* WARNING: this syntax has been changed in v0.5.0 */
}
  • adds the ability for viewport units to be used inside of calc() expressions in iOS Safari and IE9+, via the use of the content CSS property. This seems like a good compromise since content is only valid inside ::before and ::after rules (as a result, it is not recommended use this hack inside of these rules). (Note that this will only work when initializing with viewportUnitsBuggyfill.init({hacks: window.viewportUnitsBuggyfillHacks});) and adding the viewport-units-buggyfill.hacks.js to the page after viewport-units-buggyfill.js.
.box {
  top: calc(50vh - 100px);
  left: calc(50vw - 100px);

  /*
   * Here is the code for WebKit browsers that will allow
   * viewport-units-buggyfill.js to perform calc on viewport
   * units.
   */
   content: 'use_css_content_hack: true; top: calc(50vh -  100px); left: calc(50vw -  100px);';
  /* WARNING: this syntax has been changed in v0.5.0 */
}
  • Using the above hack one can also add support for vmax support in Safari for the older iOS6
  • Adds support for viewport units inside of IE's filter property (a.k.a. Visual Filters).
  • Added debounce initialization parameter, if it is desirable to not have IE9+ fire the polyfill so many times on a resize event.

0.3.1 (April 16th 2014)

  • fixing browser detection to include UIWebView - Issue #7, tylerstalder

0.3.0 (April 9th 2014)

  • fixing cross origin resource problem with CSSOM - Issue #6

0.2.3 (March 10th 2014)

  • fixing multiple competing media-attribute-switched stylesheets - Issue #5
  • fixing double initialization and call of reresh() without being initialized - Issue #3
  • fixing <br>s caused by innerText by using textContent instead

0.2.2 (January 31st 2014)

  • fixing unhandled empty <style> elements - Issue #2

0.2.1 (January 25th 2014)

  • adding force option to init()
  • fixing the handling of non-iterable CSSRules - Issue #1

0.2.0 (January 24th 2014)

  • optimizing generated CSS (by grouping selectors)
  • adding browser sniffing

0.1.0 (January 23rd 2014)

  • Initial Version

License

viewport-unit-buggyfill is published under the MIT License.

viewport-units-buggyfill's People

Contributors

dartess avatar filipbech avatar gabrielloeb avatar gaearon avatar gianlucaguarini avatar jabes avatar jfabre avatar krzysiek1507 avatar liurhoramen avatar mderazon avatar nathankoop avatar rodneyrehm avatar s-h-a-d-o-w avatar tylerstalder avatar vincent-aubert avatar winner95 avatar zoltan-dulac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

viewport-units-buggyfill's Issues

Buggyfill Hack: Safari 7.0 and older and Chrome 26 and older don't support viewport units in calc() expressions

According to http://caniuse.com/#search=calc , Safari 7.0 and older and Chrome 26 and older don't support viewport units in calc() expressions.

Is Buggyfill detecting this issue?

I've tried to use hacks to solve it, but it seems is not working on calc() functions.

To give an example, my CSS looks something like this:

.class{
left: calc(50% - 11vh);
top: calc(50% + 25vh);
content: 'viewport-units-buggyfill; left: calc(50% - 53px); top: calc(50% - 117px);';
}

I've tried it on an iPhone4 with iOS7 and the hack is not overwritting the top and left property as supposed.

Is there anything I'm doing wrong? Or Buggyfill is not detecting the viewport units in calc() functions as not supported??

Viewport units fixed in iOS8

I can confirm that viewport units are finally fixed in iOS 8 that was just released.

Maybe we can update the UA test to exclude iOS 8 and only load the buggyfill in <iOS7, as from what I can tell at the moment "isMobileSafari" targets all versions which isn't optimal?

For a reference:

This is the UA on my iPhone 4S running iOS 7.0.3 which I purposely haven't yet updated to iOS8:

Mozilla/5.0 (iPhone; CPU iPhone OS 7_0_3 like Mac OS X) 
AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 
Mobile/11B511 Safari/9537.53

And here is the UA of my iPad Air running iOS 8.0:

Mozilla/5.0 (iPad; CPU OS 8_0 like Mac OS X) 
AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 
Mobile/12A365 Safari/600.1.4

Wrap in the module?

I do not use the package manager to store the connected resources, but I use gulp to build the project. Apparently, because of the above "strict mode", the string } (this, function () { was replaced with } (undefined, function () { and everything broke. I wrapped all the contents in an anonymous module (function(){ ... })(), this solved the problem. Be it worth adding your file so that its behavior can not be broken outside?

Incorrect regex for iOS version

viewport-units-buggyfill.js

Line 45 was: var iOSversion = userAgent.match(/OS (\d)/);

Guessing it should be: var iOSversion = userAgent.match(/OS (\d+)/);

As an aside, should like 48 read like this?

return iOSversion && iOSversion.length>1 && parseInt(iOSversion[1], 10) < 8;

distinct handling using multiple css files

In case of using more than one css file, the viewport-units-buggyfill has to treat the fixes for the css files separately in order to avoid fixes used in the one file (e.g. mobile css) are also applied to the other (e.g. desktop css)

Should be recalculated on resize?

The script recalculates on orientationchange event. I think we should recalculate dimensions on other events. One case I have currently problem with is scrolling on iOS Safari. When you scroll down the tab bar disappear and viewport height changes (expands by viewport height). We could use window.onresize event. Maybe there's some other way?

Custom event for processing needed

Hello,

old Android browsers usually have render issues while applying the viewport units hack.

For that reason I like to hide parts and show them once the hack was completed. Can you provide a custom event like viewportUnitsBuggyfillPatched that triggers on window? Maybe other events are usefull too?

At the moment I obeserve the #patched-viewport what is kind of bad.

$('#patched-viewport').on('DOMNodeInserted', function () {
    alert('viewportUnitsBuggyfillPatched');
});

Thank you

Edge Support

Apparently Edge still does not understand vmax. Just updating the regex at line 87 makes everything better!

if (!isBuggyIE) {
isBuggyIE = !!navigator.userAgent.match(/Trident._rv[ :]_11|2./);
}

Bug on img

When appling on an img tag something like this:

#div img{
    max-height: 40vh;
    content: 'viewport-units-buggyfill; max-height: 40vh;';
}

the img disapear.
A workaround can be use moodernizr to inject cssvhunit class to html, and then in css add this rule:

.cssvhunit #div img{
    content: normal !important;
}

!important styles don't get overriden

I have a React.js component that is setting the height of the component as an inline style and I have no control over it.
To make it work with buggyfill, I had to create a class with !important to override the precedency of the inline styles of the lib. Therefor I have something like this in my CSS file:

.map {
  height: 85vh !important;
}

When debugging on IOS7, I see the fixed px class that is the result of buggyfill, but the above class definition still takes precedency over the 3 (the buggyfill version, the inline version and the !important class version)

Any ideas how to bypass this ?

Breaks in IE10 on Windows 7

screen shot 2015-01-15 at 15 46 28

The script completely breaks my website when viewed in IE10 on Windows 7 (in VirtualBox). I attached a screenshot of what's going wrong and the errors it throws. It's working fine in IE9 on Windows 7 and IE11 on Windows 8.1, both in VirtualBox as well.

Minified stylesheets not being converted

I just noticed trouble targetting and converting vh-units in my compiled minified stylesheet. I had to create the specific vh-units in a non-minified .css for the conversion to work.

Rounded values for some cases

At first a big thanks for your work, buggyfill seems to work like expected on iPad and iPhone.

What would be really useful is an option to round the values in some cases to integers. I’m using vw mainly for grid layouts where it’s a good decision to get the exact value so that the sum of all divs is exactly 100vw.

But sometimes I’m using vmax for font-size or logos where a value of something like 26.208000000000002px doesn’t looks really nice. So it would be nice, if there was an option to set some values to integer (maybe through an additional content-value).

CORS cloudfront/s3 caching

I've encountered an issue today where:
1- My first request to my css file on cloudfront (from head) would get cached.
2- The second (CORS) request to my css from this library would still get the
same cached response even though there's a valid origin header in the request.
3- That would result in Safari denying the CORS because Cloudfront won't
return the proper headers.

I hacked it by adding changing the url in the getCors function to:

url = url + "?rng=" Math.random()

It works like a charm in my case because I needed to make sure that the CORS request wouldn't receive a cached response.

Here's the issue I'm talking about:
https://forums.aws.amazon.com/thread.jspa?messageID=555417&#555417
http://stackoverflow.com/questions/12498704/cached-non-cors-response-conflicts-with-new-cors-request

I would like to transform this issue into a PR, but I think it's best that I get your opinion on how you would want to implement the fix first.

Thanks.

Chrome test

First off, thanks for the great project!

I'm testing a website on an old phone using Chrome.

I notice if I comment out the if block starting at

https://github.com/rodneyrehm/viewport-units-buggyfill/blob/master/viewport-units-buggyfill.js#L59

then it runs, as the line at https://github.com/rodneyrehm/viewport-units-buggyfill/blob/master/viewport-units-buggyfill.js#L59 returns true. If I leave it uncommented, it doesn't run (as the if block at https://github.com/rodneyrehm/viewport-units-buggyfill/blob/master/viewport-units-buggyfill.js#L111 is entered). I guess my question relates to the comment:

this buggyfill only applies to mobile safari, IE9-10 and the Stock Android Browser.

Can I ask why the tests have been set up to not run at least in this specific case? I'm not sure I follow the reasoning behind simple test for Chrome, and preventing this polyfill from doing it's work if it is.

The chrome version i'm running is 18.0.1025469 with the Android version being 4.1.1.

Thanks again!

Overpowered IE11 check breaks client-supported properties

Hi,

The check here causes issues when using units other than vmax. Rather than taking a sledgehammer/all-or-nothing approach, this check should be made later on to determine if vmax support is necessary, and should only apply fixes for vmax.

// added check for IE11, since it *still* doesn't understand vmax!!!
  if (!isBuggyIE) {
    isBuggyIE = !!navigator.userAgent.match(/Trident.*rv[ :]*11\./);
  }

rule within media query not overriding other rule

First of all, thanks a TON for this! It definitely spared me at least a couple grey hairs.

Not sure if this is a bug or not, but I thought I would mention it here in case anyone runs into it. If you have a standard rule, something like:

.sidebar
{
    flex-basis: 80vmax;
}

and a rule within a media query which overrides it:

@media all and (orientation:portrait)
{
    .sidebar
    {
        flex-basis: auto;
    }
}

the "auto" won't take effect when the media query is active. In this case, the easy workaround is to just specify both flex-basis values in their own media queries as follows:

@media all and (orientation:landscape)
{
    .sidebar
    {
        flex-basis: 80vmax;
    }
}

@media all and (orientation:portrait)
{
    .sidebar
    {
        flex-basis: auto;
    }
}

Again, thanks a lot to everyone that's worked on this, and I hope this helps out!

Fix doesn't work when using Chrome on iOS < 8

The check for iOS Safari doesn't pick up Chrome on iOS. I've replaced the version check with:

var versions = /iPhone OS (\d+)/.exec(window.navigator.userAgent);

Which picks up both user agents and everything seems to work. Thought I'd run this by you before sending you a pull request as I wasn't sure if there was any built in behaviour to check for Chrome on iOS.

I cannot be able to use the script

Sorry this may be very silly but I don't know what I'm doing wrong. I got:

.selection__content {
  background: rgba($purple, 0.3);
  min-height: calc(100vh - 260px); //need viewport unit fallback
  padding-top: $space*3;

  /*
   * Here is the code for WebKit browsers that will allow
   * viewport-units-buggyfill.js to perform calc on viewport
   * units.
   */
  content: 'use_css_content_hack: true; min-height: calc(100vh - 260px);';

  @media only screen and (min-width: 992px) { // bootstrap-md
    min-height: calc(100vh - 200px);
    content: 'use_css_content_hack: true; min-height: calc(100vh - 200px);';
  }
}

That is my scss, and I'd installed the script through bower, and my index.html (and all my *.html) has the following:

<script src="bower_components/viewport-units-buggyfill/viewport-units-buggyfill.js"></script>
<script src="bower_components/viewport-units-buggyfill/viewport-units-buggyfill.hacks.js"></script>

On my document ready I'm writing:

window.viewportUnitsBuggyfill.init({
    hacks: window.viewportUnitsBuggyfillHacks,
    contentHack: true,
    behaviorHack: true,
    refreshDebounceWait: 250
 });

Perhaps if I go to the console I see a defined value for viewportUnitsBuggyfill and viewportUnitsBuggyfillHacks

So, I don't know, what I'm missing.

Again sorry for the question, since apparently I'm the only one that have this issue here, my bad. :/

Conflicting with fonts.googleapis.com

Not working if css from google apis have been used:

<link href='http://fonts.googleapis.com/css?family=Roboto:100,300%7CRoboto+Condensed:300&amp;subset=latin,cyrillic' rel='stylesheet' type='text/css'>

breaks on pages with no CSS rules

Line 58 reads:

  forEach.call(sheet.cssRules, findDeclarations);

On <style> tags which lead to empty stylesheets, sheet.cssRules is null, which causes an error on my iOS7 device. If a stylesheet (for whatever reason) is empty, we should probably just skip the sheet:

  if (!sheet.cssRules) return;

Make Internet Explorer check compatible with uglify

The isOldInternetExplorer variable is always false if using uglify (and maybe other minification methods) since comments gets stripped. I suggest changing to another method for checking Internet Explorer versions.

viewportUnitExpression is matching base64 strings

See:

var viewportUnitExpression = /([+-]?[0-9.]+)(vh|vw|vmin|vmax)/g;

This expression need to be stricter to prevent matching characters within a base64 encoded string. This issue was identified in our application, where this buggyfill script was "corrupting" base64 encoded images.

I wonder if simply adding word boundary metacharacters around the expression will suffice, but as this repository does not contain any sort of automated testing tools, I cannot be sure, and I don't really have the time to manually test this change.

Here's the change: https://gist.github.com/badsyntax/bc4423dc51b04f54ae52/revisions

Breaks fonts

As soon as I add window.viewportUnitsBuggyfill.init(); i get the following errors:

[Error] XMLHttpRequest cannot load http://fonts.googleapis.com/css?family=Roboto%3A300. Origin http://www.blueleafstudio.net is not allowed by Access-Control-Allow-Origin. (environmentally-friendly-web-hosting, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (fontawesome-webfont.woff, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (fontawesome-webfont.ttf, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (fontawesome-webfont.svg, line 0)

It's looking for the fonts at http://www.blueleafstudio.net/fonts/fontawesome-webfont.woff?v=4.0.3 (which is my website) when it should be looking for them at http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css
The font starts loading fine and even renders until viewport-units-buggyfill kicks in.

vh-based rules don't respect media queries

When I write rules in media queries, I noticed that the last rule of a given selector using vh units override any succeeding rule targeting the same selector bu using different units (i.e. not vh). Also, the same vh-based rule inside any media queries will get executed regardless of whether the query returns true or not.

I understand that your implementation pulls vh-based rules out of stylesheets and into the HTML, but perhaps you could make it so that every succeeding use of the selector gets pulled as well, and that any wrapping media queries is also grabbed.

Problem when media query changes vw to em in font-size in IE9+

Hi,

I've got a problem when adding a media query that changes font-size of an element from vw to em, when using IE 9+.
It keeps calculating conversion between them of the previous value (vw in this case), so the newer one (em) doesn't work properly...

I've created an example that reproduces the problem...
http://jsfiddle.net/celio_latorraca/ekvbycdx/6/

You just need to access JS Fiddle with IE and resize the iframe to see what happens.
To facilitate debugging, it's changing color between blue and red when media query changes...
So, to understand the problem, when the font color is red, the font-size is in em and don't changes with window resize... But, when it is blue, it follows the resizing.

Thanks!

Buggyfill not working on Safari 5.1.7 on Windows 7

I'm having a problem with Safari 5.1.7 on Windows 7, even when I use the force:true option.
Just to make it easier and avoid coding errors I'm trying with the vh.html example and I get it working on SRWare Iron Versión 40.0.2150.0, Chrome 42.0.2311.90 m and IE11, but not in Safari.

Safari UserAgent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2

I'm also having this problem on some android platforms but I don't know what I'm doing wrong or what's happening because I don't get any errors of any kind.

Any help is really appreciated :)

Thanks in advance!

create PostCSS processor to generate `content: …` hack properties

In a build pipeline this would work very much like Autoprefixer - refactoring CSS after it's gone through SASS/LESS/whatever, adding the missing pieces.

Based on PostCSS a "simple" processor could identify all the rules using viewport units (e.g. width: 50vw;), aggregate them into a content: "viewport-units-buggyfill; width: 50vw;"; property and add them back to the declaration block. The processor should also check for the existence of the content property an issue a warning/error if one were created on generated content.

This would automate turning

.some-selector {
  width: 50vw;
}

into

.some-selector {
  width: 50vw;
  content: "viewport-units-buggyfill; width: 50vw;";
}

thus making viewport units work "immediately" in old Android Stock Browsers (amongst others).

CORS stylesheets broken for relative resources

Simply downloading and injecting a CSS file into the DOM will break fonts and images referenced by a relative URL. This is because relative URLs within a <link>ed stylesheet are resolved against the URL of the CSS resource, but all resources in a <style> element are resolved against the URL of the document.

After downloading and before injecting the CSS, a processing step has to be introduced that scans the document for url("") and @import ""; occurrences and resolves relative paths against the stylesheet's URL.

Depending on URI.absoluteTo() for the heavy lifting may seem convenient, but adds way too much to the file size. The DOM URL interface is not available on iOS 7.

This doesn't seem to work with sass variables

Do we necessarily have to include here the final value?
I am notifying that the bugyfill doesn't work with sass variables.

Something like:

  margin-top: $header-height-small;
  width: $content-width-small;
  max-width: $content-width-small;
  height: $content-height-small;
  /* Viewport-units-buggyfill.js */
   content: 'viewport-units-buggyfill; margin-top: $header-height-small; width: $content-width-small; max-width: $content-width-small; height: $content-height-small;';

Is it possible to include sass variables in this bugyfill?

IE raises "Access denied" error in some cases

I'm getting occasional localized errors in my JS logs translating as "Access denied" from IE 11 with stacks like this:

Error: Toegang geweigerd. // Error: Access denied

  at findProperties (app/~/viewport-units-buggyfill/viewport-units-buggyfill.js?:189)
  at func (app/~/viewport-units-buggyfill/viewport-units-buggyfill.js?:164)
  at func (app/~/viewport-units-buggyfill/viewport-units-buggyfill.js?:90)

I don't think the line numbers are very accurate, but from my understand this is caused by accessing document.styleSheets when some stylesheet is loaded from another host.

Shall we try-catch it?

Can seem to get this to work with vh

I have a css file that is full of various vh values for padding on elements, margins, etc...

When I load up both scripts and then do

viewportUnitsBuggyfill.init({hacks: window.viewportUnitsBuggyfillHacks});

Nothing gets fixed. I see some elements sort of shift for a sec, but things do not end up as I would expect them. For example I have a dev that is set to height: 90vh. 90% of the viewport height. When the page loads on iPad and the above script command runs, the div is definitely not 90% of the page height. It's like 1000% of the page height. It's so big I can't even tell.

I am testing on an iPad and am using remote safari webkit inspector debugging and I don't get any errors or anything like that (except for some AJAX CORS errors for some things that don't matter on the page).

What am I doing wrong? Any tips? The docs make it sound like it should just work but it just isn't...

Error in IE8

Hey, I'm getting an error in IE8. This breaks all my javascript :)
I'm using version 0.5.1.

bildschirmfoto 2015-03-26 um 17 38 02

translateX with vmin not working correctly in IE10

Hi, I am using the buggyfill on an angular app, using ng-class to add/remove two classes. I am shifting the position of the image of a map (when the user opens a details panel) based on vmin like so:

.region__map--open {
  transform: translateX(-50vmin);
  transition: .5s;
  /* hack to engage viewport-units-buggyfill */
  content: 'viewport-units-buggyfill; transform: translateX(-50vmin); -ms-transform: translateX(-50vmin);';
}

And when closing the details panel, I translate back to 0 like so:

.region__map--closed {
  transform: translateX(0);
  -ms-transform: translateX(0);
  transition: .5s;
}

Working great in chrome, IE9 and IE11, however in IE10, when I open the panel the map barely moves when it translates, as if the vmin value is not being calculated properly. When I close the panel and the 'region__map--closed' class takes effect, the map suddenly snaps to where it should have been while open, then slides closed to the proper closed place.

Is this a bug with the buggyfill? :/

`behavior` vs `content` - why the distinction?

I'm currently fiddling with the buggyfill on Android Stock Browser 4.3 (which does not support viewport units at all). By overwriting the required callback to always return true, I could use the content hack to use viewport units on any property. (If viewport units are not supported, supportsVminmaxCalc is false, too).

This left me wondering what the distinction content and behavior was supposed to achieve in the first place. Should we not simply dumb it down to a single property (i.e. content)? Should we then replace use_content_hack: true; with a simple prefix (e.g. viewport-units-buggyfill:)?

Evaluating this property would be triggered by missing support for viewport-units in general, missing support of vmin and vmax and missing viewport-unit support in calc.

cc @zoltan-dulac

@import stylesheets are not processed

Stylesheets loaded by way of @import are not exposed in document.styleSheets, and thus are not processed by the buggyfill. @import rules are represented by the CSSImportRule interface (type 3), exposing the referenced sheet at rule.styleSheet.

rule.href and rule.styleSheet.href may not match, as the former is the literal value specified by @import, the latter is the the fully qualified ("resolved") URL of the given resource. As we can't access the foreign-origin CSSOM at all, we won't be able to read the qualified URL but will have to work with the unresolved URL instead.

These @import rules can be made available in their own origin-localized <style> element because they must precede any other rule (other than @charset). Document order can thus be maintained easily by prepending separate <style> elements for each encountered @import.

Until someone requests @import-support (or sends a PR, hinthint) this issue is considered to be an explanation and warning of lack of support.

New check for IE10 won't work

The below code from 985b9a6 seems not to work for IE 10 since the revision token ("rv") was introduced with IE 11 (see here).

  // added check for IE10, IE11 and Edge < 20, since it *still* doesn't understand vmax
  // http://caniuse.com/#feat=viewport-units
  if (!isBuggyIE) {
    isBuggyIE = !!navigator.userAgent.match(/Trident.*rv[ :]*1[01]\.| Edge\/1\d\./);
  }

Something like this may work, though not very pretty.

isBuggyIE = !!navigator.userAgent.match(/MSIE 10\.|Trident.*rv[ :]*1[01]\.| Edge\/1\d\./);

vh sometimes returns 0

This is only in iOS6, so maybe that's outside your scope.
In my current project, when using vh units, it results in a height of 0.
Using buggyfill doesn't fix the issue. Not sure if this is even possible to address with a javascript fix (can't do much with something that returns a zero I imagine) but maybe it can be tricked into recalculating or maybe you have any insight on why this happens?

In this example, the divs collapse in iOS6 so you can't scroll the page:
http://lab.marlon.be/mar100/world/v01/templates/vunits.html

Fails silently on CSS loaded from subdomain

Due to the Cross Origin Policy, documents.stylesheets[x].cssRules returns null for stylesheets loaded from a different domain, including subdomains. This means the script has nothing relevant to process, and simply doesn't work. This is especially frustrating for people like myself who serve static content like CSS, JS, and images from a CDN.

I've been looking around and haven't found a fix yet. Possibly CORS, but I'm still testing things out. Do you have any ideas?

Application

I'm a complete n00b. please explain how to use this in my markup? What are the files needed? what should be the markup in HTML etc.

Thanks

Sorry for the mundane question

At least some versions of iOS 8 still need this fix

I have an iPhone with IOS 8:
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B440 Safari/600.1.4

With 0.5.0 which claims:

0.5.0 (December 23rd 2014)
WARNING: Breaking Changes (and a Merry Christmas to you, too :)
not engaging the buggyfill on iOS8+ anymore (#19, #23, #27)

I have to use force:
window.viewportUnitsBuggyfill.init({force: true});

Else....see the difference.
image1
image2

Script errors in IE

This script gives me site-breaking errors in IE. Although I use the normal init, not forced, the line

var value = rule.cssText;

in the method findDeclarations(rule) is the curprit. The error is Member not found. This breaks the rest of my javascript in IE10, IE11 seems to cope and carry on. But the errors are still there.

Is there anything you can do about this?

Error on iOS8 without set force to true

Hi! first of all thanks fot that code, it works like a charm, the only thing is that I don't wan't to force the buggyfill in browsers that support vh and vw correctly, but on the iOS7, if I don't force it, it fails on the vh units, any idea why?

Error when identifying old Internet Explorer version

Hi,

I'm getting error when the test checks for old IE version:

/*@cc_on

  @if (@_jscript_version <= 10)
    isOldInternetExplorer = true;
  @end

@*/

The error I'm getting is: Unable to get property 'init' of undefined or null reference

This can be fixed by putting variable identifier in front of isOldInternetExplorer So the working check would be looking like this:

/*@cc_on

  @if (@_jscript_version <= 10)
    var isOldInternetExplorer = true;
  @end

@*/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.