-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'tango/PR-2.2-develop' into perf_mpi
- Loading branch information
Showing
7 changed files
with
152 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
app/code/Magento/Theme/view/frontend/templates/js/polyfill.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
/** | ||
* Polyfill for local storage and session storage for old browsers and with enabled private mode. | ||
* | ||
* Emulates behavior of the native local storage and session storage. Adds ability to use "getItem", "setItem", | ||
* "removeItem" methods. | ||
*/ | ||
?> | ||
|
||
<script> | ||
try { | ||
if (!window.localStorage || !window.sessionStorage) { | ||
throw new Error(); | ||
} | ||
|
||
localStorage.setItem('storage_test', 1); | ||
localStorage.removeItem('storage_test'); | ||
} catch(e) { | ||
(function () { | ||
var Storage = function (type) { | ||
var data; | ||
|
||
function createCookie(name, value, days) { | ||
var date, expires; | ||
|
||
if (days) { | ||
date = new Date(); | ||
date.setTime(date.getTime()+(days * 24 * 60 * 60 * 1000)); | ||
expires = '; expires=' + date.toGMTString(); | ||
} else { | ||
expires = ''; | ||
} | ||
document.cookie = name + '=' + value+expires+'; path=/'; | ||
} | ||
|
||
function readCookie(name) { | ||
var nameEQ = name + '=', | ||
ca = document.cookie.split(';'), | ||
i = 0, | ||
c; | ||
|
||
for (i=0; i < ca.length; i++) { | ||
c = ca[i]; | ||
|
||
while (c.charAt(0) === ' ') { | ||
c = c.substring(1,c.length); | ||
} | ||
|
||
if (c.indexOf(nameEQ) === 0) { | ||
return c.substring(nameEQ.length, c.length); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function setData(data) { | ||
data = encodeURIComponent(JSON.stringify(data)); | ||
createCookie(type === 'session' ? getSessionName() : 'localStorage', data, 365); | ||
} | ||
|
||
function clearData() { | ||
createCookie(type === 'session' ? getSessionName() : 'localStorage', '', 365); | ||
} | ||
|
||
function getData() { | ||
var data = type === 'session' ? readCookie(getSessionName()) : readCookie('localStorage'); | ||
|
||
return data ? JSON.parse(decodeURIComponent(data)) : {}; | ||
} | ||
|
||
function getSessionName() { | ||
if (!window.name) { | ||
window.name = new Date().getTime(); | ||
} | ||
|
||
return 'sessionStorage' + window.name; | ||
} | ||
|
||
data = getData(); | ||
|
||
return { | ||
length: 0, | ||
clear: function () { | ||
data = {}; | ||
this.length = 0; | ||
clearData(); | ||
}, | ||
|
||
getItem: function (key) { | ||
return data[key] === undefined ? null : data[key]; | ||
}, | ||
|
||
key: function (i) { | ||
var ctr = 0, | ||
k; | ||
|
||
for (k in data) { | ||
if (ctr.toString() === i.toString()) { | ||
return k; | ||
} else { | ||
ctr++ | ||
} | ||
} | ||
|
||
return null; | ||
}, | ||
|
||
removeItem: function (key) { | ||
delete data[key]; | ||
this.length--; | ||
setData(data); | ||
}, | ||
|
||
setItem: function (key, value) { | ||
data[key] = value.toString(); | ||
this.length++; | ||
setData(data); | ||
} | ||
}; | ||
}; | ||
|
||
window.localStorage.__proto__ = window.localStorage = new Storage('local'); | ||
window.sessionStorage.__proto__ = window.sessionStorag = new Storage('session'); | ||
})(); | ||
} | ||
</script> |