aboutsummaryrefslogtreecommitdiffstats
path: root/demo/src/js/lib/sprite.js
diff options
context:
space:
mode:
authorSam Potts <me@sampotts.me>2017-10-26 00:10:56 +1100
committerSam Potts <me@sampotts.me>2017-10-26 00:10:56 +1100
commit959b5a20e39c2ba4a05c6e417c02184ca24804cd (patch)
tree28b2cb298fae25e58ecc6e6d88d8f951931ee92d /demo/src/js/lib/sprite.js
parent9de5c0cf39f12a4e2e62b62cb68b71159b3c77ac (diff)
downloadplyr-959b5a20e39c2ba4a05c6e417c02184ca24804cd.tar.lz
plyr-959b5a20e39c2ba4a05c6e417c02184ca24804cd.tar.xz
plyr-959b5a20e39c2ba4a05c6e417c02184ca24804cd.zip
Inlined SVGs, fixed build
Diffstat (limited to 'demo/src/js/lib/sprite.js')
-rw-r--r--demo/src/js/lib/sprite.js89
1 files changed, 0 insertions, 89 deletions
diff --git a/demo/src/js/lib/sprite.js b/demo/src/js/lib/sprite.js
deleted file mode 100644
index bcd8a0b7..00000000
--- a/demo/src/js/lib/sprite.js
+++ /dev/null
@@ -1,89 +0,0 @@
-// ==========================================================================
-// SVG sprite loading and caching
-// This file should be at the top of the body to avoid a flash
-// Usage: loadSprite('https://cdn.com/path/to/sprite.svg', 'sprite-id');
-// The second argument is optional but prevents loading twice
-// ==========================================================================
-
-(function() {
- window.loadSprite = function(url, id) {
- if (typeof url !== "string") {
- return;
- }
-
- var body = document.body;
- var prefix = "cache-";
- var hasId = typeof id === "string";
- var isCached = false;
-
- // Check for *actual* storage support
- var cacheSupported = (function() {
- if (!hasId) {
- return false;
- }
- var test = '___test';
- try {
- localStorage.setItem(test, test);
- localStorage.removeItem(test);
- return true;
- } catch (e) {
- return false;
- }
- })();
-
- function updateSprite(container, data) {
- // Inject content
- container.innerHTML = data;
-
- // Inject the SVG to the body
- body.insertBefore(container, body.childNodes[0]);
- }
-
- // Only load once
- if (!hasId || document.querySelectorAll("#" + id).length === 0) {
- // Create container
- var container = document.createElement("div");
- container.setAttribute("hidden", "");
-
- if (hasId) {
- container.setAttribute("id", id);
- }
-
- // Check in cache
- if (cacheSupported) {
- var cached = localStorage.getItem(prefix + id);
- isCached = cached !== null;
-
- if (isCached) {
- var data = JSON.parse(cached);
- updateSprite(container, data.content);
- }
- }
-
- // ReSharper disable once InconsistentNaming
- var xhr = new XMLHttpRequest();
-
- // XHR for Chrome/Firefox/Opera/Safari
- if ("withCredentials" in xhr) {
- xhr.open("GET", url, true);
- }
- // Not supported
- else {
- return;
- }
-
- // Once loaded, inject to container and body
- xhr.onload = function() {
- if (cacheSupported) {
- localStorage.setItem(prefix + id, JSON.stringify({
- content: xhr.responseText
- }));
- }
-
- updateSprite(container, xhr.responseText);
- };
-
- xhr.send();
- }
- }
-})();