Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

91 строка
2.5 KiB

  1. /*
  2. Copyright 2018 Adobe. All rights reserved.
  3. This file is licensed to you under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License. You may obtain a copy
  5. of the License at http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software distributed under
  7. the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
  8. OF ANY KIND, either express or implied. See the License for the specific language
  9. governing permissions and limitations under the License.
  10. */
  11. // UMD pattern via umdjs
  12. (function (root, factory) {
  13. if (typeof define === 'function' && define.amd) {
  14. // AMD
  15. define([], factory);
  16. }
  17. else if (typeof module === 'object' && module.exports) {
  18. // CommonJS-like
  19. module.exports = factory();
  20. }
  21. else {
  22. // Browser
  23. root.loadIcons = factory();
  24. }
  25. }(typeof self !== 'undefined' ? self : this, function() {
  26. function handleError(string) {
  27. string = 'loadIcons: '+string;
  28. var error = new Error(string);
  29. console.error(error.toString());
  30. if (typeof callback === 'function') {
  31. callback(error);
  32. }
  33. }
  34. function injectSVG(svgURL, callback) {
  35. var error;
  36. // 200 for web servers, 0 for CEP panels
  37. if (this.status !== 200 && this.status !== 0) {
  38. handleError('Failed to fetch icons, server returned ' + this.status);
  39. return;
  40. }
  41. // Parse the SVG
  42. var parser = new DOMParser();
  43. try {
  44. var doc = parser.parseFromString(this.responseText, 'image/svg+xml');
  45. var svg = doc.firstChild;
  46. }
  47. catch (err) {
  48. handleError('Error parsing SVG: ' + err);
  49. return;
  50. }
  51. // Make sure a real SVG was returned
  52. if (svg && svg.tagName === 'svg') {
  53. // Hide the element
  54. svg.style.display = 'none';
  55. svg.setAttribute('data-url', svgURL);
  56. // Insert it into the head
  57. document.head.insertBefore(svg, null);
  58. // Pass the SVG to the callback
  59. if (typeof callback === 'function') {
  60. callback(null, svg);
  61. }
  62. }
  63. else {
  64. handleError('Parsed SVG document contained something other than an SVG');
  65. }
  66. }
  67. function loadIcons(svgURL, callback) {
  68. // Request the SVG sprite
  69. var req = new XMLHttpRequest();
  70. req.open('GET', svgURL, true);
  71. req.addEventListener('load', injectSVG.bind(req, svgURL, callback));
  72. req.addEventListener('error', function(event) {
  73. handleError('Request failed');
  74. });
  75. req.send();
  76. }
  77. return loadIcons;
  78. }));