Replacing SVG polyfill to fix event issues

This commit is contained in:
Bruno Alves de Faria 2017-09-05 20:53:20 -03:00
parent 233d12c481
commit b6b3a443a2
9 changed files with 24 additions and 30 deletions

View File

@ -37,6 +37,7 @@
.warning-icon, svg
width: 22px
height: 20px
pointer-events: inherit
.warning-icon
margin: 7px auto 0

View File

@ -0,0 +1,9 @@
import { Meteor } from 'meteor/meteor';
import writeScript from './lib/writeScript';
// Fix SVG+USE issues
writeScript('svg4everybody.min.js');
Meteor.startup(() => {
// Call the SVG polyfill
window.svg4everybody();
});

View File

@ -1,19 +1,6 @@
import { $ } from 'meteor/jquery';
import { absoluteUrl } from './lib/absoluteUrl';
import writeScript from './lib/writeScript';
/* jshint -W060 */
// Check if browser is IE and add the polyfill scripts
if (navigator && /MSIE \d|Trident.*rv:/.test(navigator.userAgent)) {
const writeScript = fileName => {
const src = absoluteUrl(`/packages/ohif_polyfill/public/js/${fileName}`);
document.write(`<script src="${src}"><\/script>`);
};
writeScript('svgxuse.min.js');
writeScript('typedarray.min.js');
window.addEventListener('click', event => {
if (!window.SVGElementInstance || !(event.target instanceof SVGElementInstance)) return;
$(event.target.correspondingUseElement).trigger('click');
}, true);
}

View File

@ -1 +1,2 @@
import './ie';
import './all.js';
import './ie.js';

View File

@ -1,10 +1,10 @@
import { Meteor } from 'meteor/meteor';
export const absoluteUrl = function(path) {
export default function(path) {
if (path) {
// Remove the leading "/"
path = path.replace(/^\//, '');
}
return Meteor.absoluteUrl(path);
};
}

View File

@ -0,0 +1,7 @@
/* jshint -W060 */
import absoluteUrl from './absoluteUrl';
export default function(fileName) {
const src = absoluteUrl(`/packages/ohif_polyfill/public/js/${fileName}`);
document.write(`<script src="${src}"><\/script>`);
}

View File

@ -12,7 +12,7 @@ Package.onUse(function(api) {
api.use('jquery');
// Assets to be imported dynamically
api.addAssets('public/js/svgxuse.min.js', 'client');
api.addAssets('public/js/svg4everybody.min.js', 'client');
api.addAssets('public/js/typedarray.min.js', 'client');
// Client imports

View File

@ -0,0 +1 @@
!function(a,b){"function"==typeof define&&define.amd?define([],function(){return a.svg4everybody=b()}):"object"==typeof module&&module.exports?module.exports=b():a.svg4everybody=b()}(this,function(){function a(a,b,c){if(c){var d=document.createDocumentFragment(),e=!b.hasAttribute("viewBox")&&c.getAttribute("viewBox");e&&b.setAttribute("viewBox",e);for(var f=c.cloneNode(!0);f.childNodes.length;)d.appendChild(f.firstChild);a.appendChild(d)}}function b(b){b.onreadystatechange=function(){if(4===b.readyState){var c=b._cachedDocument;c||(c=b._cachedDocument=document.implementation.createHTMLDocument(""),c.body.innerHTML=b.responseText,b._cachedTarget={}),b._embeds.splice(0).map(function(d){var e=b._cachedTarget[d.id];e||(e=b._cachedTarget[d.id]=c.getElementById(d.id)),a(d.parent,d.svg,e)})}},b.onreadystatechange()}function c(c){function e(){for(var c=0;c<o.length;){var h=o[c],i=h.parentNode,j=d(i),k=h.getAttribute("xlink:href")||h.getAttribute("href");if(!k&&g.attributeName&&(k=h.getAttribute(g.attributeName)),j&&k){if(f)if(!g.validate||g.validate(k,j,h)){i.removeChild(h);var l=k.split("#"),q=l.shift(),r=l.join("#");if(q.length){var s=m[q];s||(s=m[q]=new XMLHttpRequest,s.open("GET",q),s.send(),s._embeds=[]),s._embeds.push({parent:i,svg:j,id:r}),b(s)}else a(i,j,document.getElementById(r))}else++c,++p}else++c}(!o.length||o.length-p>0)&&n(e,67)}var f,g=Object(c),h=/\bTrident\/[567]\b|\bMSIE (?:9|10)\.0\b/,i=/\bAppleWebKit\/(\d+)\b/,j=/\bEdge\/12\.(\d+)\b/,k=/\bEdge\/.(\d+)\b/,l=window.top!==window.self;f="polyfill"in g?g.polyfill:h.test(navigator.userAgent)||(navigator.userAgent.match(j)||[])[1]<10547||(navigator.userAgent.match(i)||[])[1]<537||k.test(navigator.userAgent)&&l;var m={},n=window.requestAnimationFrame||setTimeout,o=document.getElementsByTagName("use"),p=0;f&&e()}function d(a){for(var b=a;"svg"!==b.nodeName.toLowerCase()&&(b=b.parentNode););return b}return c});

View File

@ -1,12 +0,0 @@
/*!
* @copyright Copyright (c) 2017 IcoMoon.io
* @license Licensed under MIT license
* See https://github.com/Keyamoon/svgxuse
* @version 1.2.4
*/
(function(){if("undefined"!==typeof window&&window.addEventListener){var e=Object.create(null),n,t,d=function(){clearTimeout(t);t=setTimeout(n,100)},q=function(){},u=function(){var f;window.addEventListener("resize",d,!1);window.addEventListener("orientationchange",d,!1);window.MutationObserver?(f=new MutationObserver(d),f.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0}),q=function(){try{f.disconnect(),window.removeEventListener("resize",d,!1),window.removeEventListener("orientationchange",
d,!1)}catch(w){}}):(document.documentElement.addEventListener("DOMSubtreeModified",d,!1),q=function(){document.documentElement.removeEventListener("DOMSubtreeModified",d,!1);window.removeEventListener("resize",d,!1);window.removeEventListener("orientationchange",d,!1)})},v=function(f){function e(a){var c;void 0!==a.protocol?c=a:(c=document.createElement("a"),c.href=a);return c.protocol.replace(/:/g,"")+c.host}var d,p;window.XMLHttpRequest&&(d=new XMLHttpRequest,p=e(location),f=e(f),d=void 0===d.withCredentials&&
""!==f&&f!==p?XDomainRequest||void 0:XMLHttpRequest);return d};n=function(){function d(){--r;0===r&&(q(),u())}function l(a){return function(){!0!==e[a.base]&&(a.isXlink?a.useEl.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","#"+a.hash):a.useEl.setAttribute("href","#"+a.hash))}}function n(a){return function(){var c=document.body,b=document.createElement("x");a.onload=null;b.innerHTML=a.responseText;if(b=b.getElementsByTagName("svg")[0])b.setAttribute("aria-hidden","true"),b.style.position=
"absolute",b.style.width=0,b.style.height=0,b.style.overflow="hidden",c.insertBefore(b,c.firstChild);d()}}function p(a){return function(){a.onerror=null;a.ontimeout=null;d()}}var a,c,m,g,r=0,b,k=!1,h;q();h=document.getElementsByTagName("use");for(g=0;g<h.length;g+=1){try{c=h[g].getBoundingClientRect()}catch(x){c=!1}(a=h[g].getAttribute("href"))?k=!1:(a=h[g].getAttributeNS("http://www.w3.org/1999/xlink","href"),k=!0);m=a&&a.split?a.split("#"):["",""];a=m[0];m=m[1];b=c&&0===c.left&&0===c.right&&0===
c.top&&0===c.bottom;c&&0===c.width&&0===c.height&&!b?a.length&&(b=e[a],!0!==b&&setTimeout(l({useEl:h[g],base:a,hash:m,isXlink:k}),0),void 0===b&&(k=v(a),void 0!==k&&(b=new k,e[a]=b,b.onload=n(b),b.onerror=p(b),b.ontimeout=p(b),b.open("GET",a),b.send(),r+=1))):b?a.length&&e[a]&&setTimeout(l({useEl:h[g],base:a,hash:m,isXlink:k}),0):void 0===e[a]?e[a]=!0:e[a].onload&&(e[a].abort(),delete e[a].onload,e[a]=!0)}h="";r+=1;d()};var l;l=function(){window.removeEventListener("load",l,!1);t=setTimeout(n,0)};
"complete"!==document.readyState?window.addEventListener("load",l,!1):l()}})();