Skip to content

Commit

Permalink
Refactor the getOrigin function
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyamoon committed Nov 11, 2016
1 parent 416eb2f commit 9e38a75
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
18 changes: 12 additions & 6 deletions svgxuse.js
Expand Up @@ -2,7 +2,7 @@
* @copyright Copyright (c) 2016 IcoMoon.io
* @license Licensed under MIT license
* See https://github.com/Keyamoon/svgxuse
* @version 1.1.22
* @version 1.1.23
*/
/*jslint browser: true */
/*global XDomainRequest, MutationObserver, window */
Expand Down Expand Up @@ -50,16 +50,22 @@
// In IE 9, cross origin requests can only be sent using XDomainRequest.
// XDomainRequest would fail if CORS headers are not set.
// Therefore, XDomainRequest should only be used with cross origin requests.
function getOrigin(href) {
var a = document.createElement('a');
a.href = href;
return a.protocol + a.hostname;
function getOrigin(loc) {
var a;
if (loc.protocol !== undefined) {
a = loc;
} else {
a = document.createElement('a');
a.href = loc;
}
return a.protocol.replace(/:/g, '') + a.host;
}
var Request;
var origin = location.protocol + location.hostname;
var origin;
var origin2;
if (window.XMLHttpRequest) {
Request = new XMLHttpRequest();
origin = getOrigin(location);
origin2 = getOrigin(url);
if (Request.withCredentials === undefined && origin2 !== '' && origin2 !== origin) {
Request = XDomainRequest || undefined;
Expand Down
12 changes: 6 additions & 6 deletions svgxuse.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9e38a75

Please sign in to comment.