Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Commit

Permalink
Fixing IE11 CORS issues with CSS files
Browse files Browse the repository at this point in the history
  • Loading branch information
sgarbesi committed Oct 4, 2014
1 parent 079c57f commit 673863b
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 65 deletions.
140 changes: 140 additions & 0 deletions .eslintrc
@@ -0,0 +1,140 @@
{
"env": {
"browser": true,
"node": false,
"amd": true
},

"rules": {
"no-alert": 2,
"no-array-constructor": 2,
"no-bitwise": 0,
"no-caller": 2,
"no-catch-shadow": 2,
"no-comma-dangle": 2,
"no-cond-assign": 2,
"no-console": 2,
"no-constant-condition": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-delete-var": 2,
"no-div-regex": 2,
"no-dupe-keys": 2,
"no-else-return": 2,
"no-empty": 2,
"no-empty-class": 2,
"no-empty-label": 2,
"no-eq-null": 2,
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": 2,
"no-extra-semi": 2,
"no-extra-strict": 2,
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-implied-eval": 2,
"no-inner-declarations": [2, "functions"],
"no-invalid-regexp": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-lonely-if": 2,
"no-loop-func": 2,
"no-mixed-requires": [2, false],
"no-multi-str": 2,
"no-native-reassign": 2,
"no-negated-in-lhs": 2,
"no-nested-ternary": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 2,
"no-new-wrappers": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-path-concat": 2,
"no-plusplus": 0,
"no-process-exit": 2,
"no-proto": 2,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-restricted-modules": 2,
"no-return-assign": 0,
"no-script-url": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": [2, true],
"no-space-before-semi": 2,
"no-sparse-arrays": 2,
"no-sync": 0,
"no-ternary": 0,
"no-trailing-spaces": 2,
"no-undef": 2,
"no-undefined": 2,
"no-undef-init": 2,
"no-underscore-dangle": 2,
"no-unreachable": 2,
"no-unused-expressions": 2,
"no-unused-vars": [2, {
"vars": "all",
"args": "after-used"
}],
"no-use-before-define": 2,
"no-warning-comments": [1, {
"terms": ["@todo", "@bug", "@urgent"],
"location": "start"
}],
"no-with": 2,
"no-wrap-func": 2,
"no-mixed-spaces-and-tabs": [2, true],

"block-scoped-var": 2,
"brace-style": [2, "1tbs"],
"camelcase": 0,
"complexity": [0, 11],
"consistent-return": 2,
"consistent-this": [0, "me"],
"curly": [2, "all"],
"default-case": 2,
"dot-notation": 2,
"eol-last": 2,
"eqeqeq": 2,
"func-names": 0,
"func-style": [2, "expression"],
"no-global-strict": [2, "never"],
"guard-for-in": 2,
"max-depth": [0, 5],
"max-len": [0, 120, 4],
"max-nested-callbacks": [0, 5],
"max-params": [0, 15],
"max-statements": [0, 10],
"handle-callback-err": 2,
"new-cap": 0,
"new-parens": 2,
"one-var": 0,
"quote-props": 0,
"quotes": [2, "single"],
"radix": 2,
"semi": 2,
"sort-vars": 2,
"space-after-keywords": [2, "always"],
"space-in-brackets": [2, "never"],
"space-infix-ops": 2,
"space-return-throw-case": 2,
"space-unary-word-ops": 2,
"strict": 2,
"use-isnan": 2,
"valid-jsdoc": 2,
"valid-typeof": 2,
"wrap-iife": 2,
"wrap-regex": 2,
"yoda": [2, "never"]
}
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,12 @@
CHANGELOG
========

## v1.1.5 / 2014-10-04
- Fixing CORS issues with IE11 and stylesheets.
- Added `fbk` as a library alias for short-hand. e.g. `fbk.load()`
- Added ESLint for linting
- Added aliases `deps` and `dependencies` for `options.shim`

## v1.1.4 / 2014-09-02
- Moved CHANGELOG from `README.md` to `CHANGELOG.md`
- Fixing typo in README.md
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -10,8 +10,8 @@ Fallback JS
######<a class="button1" href="https://github.com/dolox/fallback/" title="Fallback JS on GitHub" target="_blank">GitHub Repository</a>

#Downloads
######<a class="button2" href="https://raw.github.com/dolox/fallback/v1.1.4/fallback.min.js" title="Production version of Fallback JS" target="_blank">Production (v1.1.4)</a> *Compressed 3.16 KB*
######<a class="button2" href="https://raw.github.com/dolox/fallback/v1.1.4/fallback.js" title="Development version of Fallback JS" target="_blank">Development (v1.1.4)</a> *Uncompressed 11.49 KB*
######<a class="button2" href="https://raw.github.com/dolox/fallback/v1.1.5/fallback.min.js" title="Production version of Fallback JS" target="_blank">Production (v1.1.5)</a> *Compressed 3.16 KB*
######<a class="button2" href="https://raw.github.com/dolox/fallback/v1.1.5/fallback.js" title="Development version of Fallback JS" target="_blank">Development (v1.1.5)</a> *Uncompressed 11.49 KB*

**SEE WORKING DEMOS WITH SOURCE CODE AT <a href="http://plnkr.co/tags/fallbackjs">http://plnkr.co/tags/fallbackjs</a>**

Expand Down
8 changes: 8 additions & 0 deletions demo/build/index.js
Expand Up @@ -12,6 +12,10 @@ if (!window.fallback) {
fallback.ready = {};
}

if (!window.fbk) {
var fbk = {};
}

// fallback.importer / .ready on demand example
fallback.importer({
'#postload': 'index.css',
Expand All @@ -30,6 +34,10 @@ fallback.importer({
'//js/loader.js?i=vendor/jquery-ui.min.js'
]
}, {
// This is for the minifier. DO NOT REMOVE!
deps: {},
dependencies: {},

// Only load jQuery UI after jQuery itself has loaded!
shim: {
'jQuery.ui': ['jQuery']
Expand Down
125 changes: 71 additions & 54 deletions fallback.js
@@ -1,7 +1,6 @@
/* fallback.js v1.1.4 | http://fallback.io/ | Salvatore Garbesi <sal@dolox.com> | (c) 2013 Dolox Inc. */
/*jslint browser: true*/
/* fallback.js v1.1.5 | http://fallback.io/ | Salvatore Garbesi <sal@dolox.com> | (c) 2013 Dolox Inc. */

(function (window, document, undefined) {
(function (window, document) {
'use strict';

var fallback = {
Expand Down Expand Up @@ -36,11 +35,12 @@

// Bootstrap our library.
fallback.bootstrap = function() {
var index, type;
var index;

for (index in fallback.utilities) {
type = fallback.utilities[index];
fallback.utility(type);
if (fallback.utilities[index]) {
fallback.utility(fallback.utilities[index]);
}
}
};

Expand All @@ -50,7 +50,9 @@
// Setup individual utility function.
fallback.utility = function(type) {
fallback['is_' + type.toLowerCase()] = function(variable) {
/*eslint-disable*/
return Object.prototype.toString.call(variable) == '[object ' + type + ']';
/*eslint-enable*/
};
};

Expand Down Expand Up @@ -81,22 +83,25 @@
// Check if our variable is defined.
fallback.is_defined = function(variable) {
try {
/*jslint evil: true*/
/*eslint-disable*/
if (eval('window.' + variable)) {
return true;
}
/*eslint-enable*/
} catch (exception) {
return false;
}

return false;
};

// Import and cleanse libraries from user input.
fallback.importer = function(libraries, options) {
var me = this, current, index;
var me = this;
var current, index;
var library, urls;
var cleansed_shims, shim, shims, shim_libraries, shim_libraries_cleansed;
var cleansed_shims, shim, shims;
var shim_libraries, shim_libraries_cleansed;

// Cleanse the libraries.
var cleansed_libraries = {};
Expand Down Expand Up @@ -134,53 +139,64 @@
// Cleanse the shims.
cleansed_shims = {};

if (me.is_object(options) && me.is_object(options.shim)) {
shims = options.shim;
if (me.is_object(options)) {
// Shim aliases, `deps` and dependencies`.
if (!me.is_object(options.shim)) {
if (me.is_object(options.deps)) {
options.shim = options.deps;
} else if (me.is_object(options.dependencies)) {
options.shim = options.dependencies;
}
}

for (shim in shims) {
shim_libraries = shims[shim];
if (me.is_object(options.shim)) {
shims = options.shim;

// If `shim` doesn't exist in libraries, skip, it's invalid.
if (!me.libraries[shim]) {
continue;
}
for (shim in shims) {
shim_libraries = shims[shim];

// If `shim_libraries` is undefined, null or an empty string, skip, it's invalid.
if (!shim_libraries) {
continue;
}
// If `shim` doesn't exist in libraries, skip, it's invalid.
if (!me.libraries[shim]) {
continue;
}

// If `shim_libraries` is a string, convert it to any array.
if (me.is_string(shim_libraries)) {
shim_libraries = [shim_libraries];
}
// If `shim_libraries` is undefined, null or an empty string, skip, it's invalid.
if (!shim_libraries) {
continue;
}

// If `shim_libraries` is not an array, skip, it's invalid.
if (!me.is_array(shim_libraries)) {
continue;
}
// If `shim_libraries` is a string, convert it to any array.
if (me.is_string(shim_libraries)) {
shim_libraries = [shim_libraries];
}

// If `shim_libraries` is not an array, skip, it's invalid.
if (!me.is_array(shim_libraries)) {
continue;
}

// Check to make sure the libraries exist otherwise remove them.
shim_libraries_cleansed = [];
// Check to make sure the libraries exist otherwise remove them.
shim_libraries_cleansed = [];

for (index in shim_libraries) {
library = shim_libraries[index];
for (index in shim_libraries) {
library = shim_libraries[index];

// Make sure the library actually exists and that it's not itself.
if (me.libraries[library] && library !== shim) {
shim_libraries_cleansed.push(library);
// Make sure the library actually exists and that it's not itself.
if (me.libraries[library] && library !== shim) {
shim_libraries_cleansed.push(library);
}
}
}

// Check to see if the shim already exists, if it does, merge the new shims.
current = [];
// Check to see if the shim already exists, if it does, merge the new shims.
current = [];

if (me.is_array(me.shims[shim])) {
current = me.shims[shim];
}
if (me.is_array(me.shims[shim])) {
current = me.shims[shim];
}

cleansed_shims[shim] = shim_libraries_cleansed;
me.shims[shim] = current.concat(shim_libraries_cleansed);
cleansed_shims[shim] = shim_libraries_cleansed;
me.shims[shim] = current.concat(shim_libraries_cleansed);
}
}
}

Expand Down Expand Up @@ -209,16 +225,16 @@
continue;
}

if (stylesheet.rules) {
found = me.css.scan(stylesheet.rules, selector);
// Issues with CORS at times, don't let the script bomb.
try {
if (stylesheet.rules) {
found = me.css.scan(stylesheet.rules, selector);

if (found) {
return found;
if (found) {
return found;
}
}
}

// Issues with CORS at times, don't let the script bomb.
try {
if (stylesheet.cssRules) {
found = me.css.scan(stylesheet.cssRules, selector);

Expand Down Expand Up @@ -520,5 +536,6 @@
};

fallback.bootstrap();
window.fallback = fallback;
})(window, document, undefined);

window.fallback = window.fbk = fallback;
}(window, document));

0 comments on commit 673863b

Please sign in to comment.