Implemented URL query parsing for initial token /opa/?token=abcde
[src/app-framework-demo.git] / afb-client / bower_components / viewport-units-buggyfill / viewport-units-buggyfill.hacks.js
1 /*!
2  * viewport-units-buggyfill.hacks v0.4.1
3  * @web: https://github.com/rodneyrehm/viewport-units-buggyfill/
4  * @author: Zoltan Hawryluk - http://www.useragentman.com/
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.viewportUnitsBuggyfillHacks = factory();
20   }
21 }(this, function () {
22   'use strict';
23
24   var options;
25   var calcExpression = /calc\(/g;
26   var quoteExpression = /[\"\']/g;
27   var urlExpression = /url\([^\)]*\)/g;
28   var isOldInternetExplorer = false;
29   var supportsVminmax = true;
30   var supportsVminmaxCalc = true;
31
32   // WARNING!
33   // Do not remove the following conditional comment.
34   // It is required to identify the current version of IE
35
36   /*@cc_on
37
38   @if (@_jscript_version <= 10)
39     isOldInternetExplorer = true;
40     supportsVminmaxCalc = false;
41     supportsVminmax = false;
42   @end
43
44   @*/
45
46   // iOS SAFARI, IE9: abuse "content" if "use_css_content_hack" specified
47   // IE9: abuse "behavior" if "use_css_behavior_hack" specified
48   function checkHacks(declarations, rule, name, value) {
49     if (!options.contentHack && !options.behaviorHack) {
50       return;
51     }
52
53     if (name !== 'content' && name !== 'behavior') {
54       return;
55     }
56
57     var needsCalcFix = (options.contentHack && !supportsVminmaxCalc && name === 'content' && value.indexOf('use_css_content_hack') > -1);
58     var needsVminVmaxFix = (options.behaviorHack && !supportsVminmax && name === 'behavior' && value.indexOf('use_css_behavior_hack') > -1);
59     if (!needsCalcFix && !needsVminVmaxFix) {
60       return;
61     }
62
63     var fakeRules = value.replace(quoteExpression, '');
64     if (needsVminVmaxFix) {
65       fakeRules = fakeRules.replace(urlExpression, '');
66     }
67
68     fakeRules.split(';').forEach(function(fakeRuleElement) {
69       var fakeRule = fakeRuleElement.split(':');
70       if (fakeRule.length !== 2) {
71         return;
72       }
73
74       var name = fakeRule[0].trim();
75       var value = fakeRule[1].trim();
76       if (name === 'use_css_content_hack' || name === 'use_css_behavior_hack') {
77         return;
78       }
79
80       declarations.push([rule, name, value]);
81       if (calcExpression.test(value)) {
82         var webkitValue = value.replace(calcExpression, '-webkit-calc(');
83         declarations.push([rule, name, webkitValue]);
84       }
85     });
86   }
87
88   return {
89     required: function(options) {
90       return options.isMobileSafari || isOldInternetExplorer;
91     },
92
93     initialize: function(initOptions) {
94       options = initOptions;
95
96       // Test viewport units support in calc() expressions
97       var div = document.createElement('div');
98       div.style.width = '1vmax';
99       supportsVminmax = div.style.width !== '';
100
101       // there is no accurate way to detect this programmatically.
102       if (options.isMobileSafari) {
103         supportsVminmaxCalc = false;
104       }
105     },
106
107     initializeEvents: function(options, refresh, _refresh) {
108       if (options.force) {
109         return;
110       }
111
112       if (isOldInternetExplorer && !options._listeningToResize) {
113         window.addEventListener('resize', _refresh, true);
114         options._listeningToResize = true;
115       }
116     },
117
118     findDeclarations: function(declarations, rule, name, value) {
119       if (name === null) {
120         // KeyframesRule does not have a CSS-PropertyName
121         return;
122       }
123
124       checkHacks(declarations, rule, name, value);
125     },
126
127     overwriteDeclaration: function(rule, name, _value) {
128       if (isOldInternetExplorer && name === 'filter') {
129         // remove unit "px" from complex value, e.g.:
130         // filter: progid:DXImageTransform.Microsoft.DropShadow(OffX=5.4px, OffY=3.9px, Color=#000000);
131         _value = _value.replace(/px/g, '');
132       }
133
134       return _value;
135     }
136   };
137
138 }));