Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions app/code/Magento/Theme/view/base/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
*/

var config = {
'waitSeconds': 0,
'map': {
waitSeconds: 0,
map: {
'*': {
'ko': 'knockoutjs/knockout',
'knockout': 'knockoutjs/knockout',
'mageUtils': 'mage/utils/main',
'rjsResolver': 'mage/requirejs/resolver'
}
},
'shim': {
shim: {
'jquery/jquery-migrate': ['jquery'],
'jquery/jstree/jquery.hotkeys': ['jquery'],
'jquery/hover-intent': ['jquery'],
Expand All @@ -28,7 +28,7 @@ var config = {
},
'magnifier/magnifier': ['jquery']
},
'paths': {
paths: {
'jquery/validate': 'jquery/jquery.validate',
'jquery/hover-intent': 'jquery/jquery.hoverIntent',
'jquery/file-uploader': 'jquery/fileUploader/jquery.fileupload-fp',
Expand All @@ -40,26 +40,47 @@ var config = {
'tinycolor': 'jquery/spectrum/tinycolor',
'jquery-ui-modules': 'jquery/ui-modules'
},
'deps': [
deps: [
'jquery/jquery-migrate'
],
'config': {
'mixins': {
config: {
mixins: {
'jquery/jstree/jquery.jstree': {
'mage/backend/jstree-mixin': true
},
'jquery': {
'jquery/patches/jquery': true
}
},
'text': {
text: {
'headers': {
'X-Requested-With': 'XMLHttpRequest'
}
}
}
};

/* eslint-disable max-depth */
/**
* Adds polyfills only for browser contexts which prevents bundlers from including them.
*/
if (typeof window !== 'undefined' && window.document) {
/**
* Polyfill localStorage and sessionStorage for browsers that do not support them.
*/
try {
if (!window.localStorage || !window.sessionStorage) {
throw new Error();
}

localStorage.setItem('storage_test', 1);
localStorage.removeItem('storage_test');
} catch (e) {
config.deps.push('mage/polyfill');
}
}
/* eslint-enable max-depth */

require(['jquery'], function ($) {
'use strict';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<css src="mage/calendar.css"/>
<script src="requirejs/require.js"/>
<script src="mage/polyfill.js"/>
</head>
<body>
<referenceBlock name="head.additional">
Expand Down
40 changes: 21 additions & 19 deletions lib/web/mage/polyfill.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
try {
if (!window.localStorage || !window.sessionStorage) {
throw new Error();
}
(function (root, doc) {
'use strict';

var Storage;

localStorage.setItem('storage_test', 1);
localStorage.removeItem('storage_test');
} catch (e) {
(function () {
'use strict';
try {
if (!root.localStorage || !root.sessionStorage) {
throw new Error();
}

localStorage.setItem('storage_test', 1);
localStorage.removeItem('storage_test');
} catch (e) {
/**
* Returns a storage object to shim local or sessionStorage
* @param {String} type - either 'local' or 'session'
*/
var Storage = function (type) {
Storage = function (type) {
var data;

/**
Expand All @@ -32,7 +34,7 @@ try {
} else {
expires = '';
}
document.cookie = name + '=' + value + expires + '; path=/';
doc.cookie = name + '=' + value + expires + '; path=/';
}

/**
Expand All @@ -41,7 +43,7 @@ try {
*/
function readCookie(name) {
var nameEQ = name + '=',
ca = document.cookie.split(';'),
ca = doc.cookie.split(';'),
i = 0,
c;

Expand Down Expand Up @@ -70,11 +72,11 @@ try {
return 'localstorage';
}

if (!window.name) {
window.name = new Date().getTime();
if (!root.name) {
root.name = new Date().getTime();
}

return 'sessionStorage' + window.name;
return 'sessionStorage' + root.name;
}

/**
Expand Down Expand Up @@ -170,7 +172,7 @@ try {
};
};

window.localStorage.prototype = window.localStorage = new Storage('local');
window.sessionStorage.prototype = window.sessionStorage = new Storage('session');
})();
}
root.localStorage.prototype = root.localStorage = new Storage('local');
root.sessionStorage.prototype = root.sessionStorage = new Storage('session');
}
})(window, document);