|
3 | 3 | * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/ |
4 | 4 | import { StringExt } from './BaseTypes'; |
5 | 5 | import { Geometry } from './Geometry'; |
| 6 | +import URI from 'urijs'; |
6 | 7 |
|
7 | 8 | /** |
8 | 9 | * @description 浏览器名称,依赖于 userAgent 属性,BROWSER_NAME 可以是空,或者以下浏览器: |
@@ -129,28 +130,28 @@ const DOTS_PER_INCH = 96; |
129 | 130 | const Util = { |
130 | 131 |
|
131 | 132 | /** |
132 | | - * @memberOf CommonUtil |
133 | | - * @description 对象拷贝赋值。 |
134 | | - * @param {Object} dest - 目标对象。 |
135 | | - * @param {Object} arguments - 待拷贝的对象。 |
136 | | - * @returns {Object} 赋值后的目标对象。 |
137 | | - */ |
| 133 | + * @memberOf CommonUtil |
| 134 | + * @description 对象拷贝赋值。 |
| 135 | + * @param {Object} dest - 目标对象。 |
| 136 | + * @param {Object} arguments - 待拷贝的对象。 |
| 137 | + * @returns {Object} 赋值后的目标对象。 |
| 138 | + */ |
138 | 139 | assign(dest) { |
139 | 140 | for (var index = 0; index < Object.getOwnPropertyNames(arguments).length; index++) { |
140 | | - var arg = Object.getOwnPropertyNames(arguments)[index]; |
| 141 | + var arg = Object.getOwnPropertyNames(arguments)[index]; |
141 | 142 | if (arg == "caller" || arg == "callee" || arg == "length" || arg == "arguments") { |
142 | | - continue; |
143 | | - } |
144 | | - var obj = arguments[arg]; |
145 | | - if (obj) { |
146 | | - for (var j = 0; j < Object.getOwnPropertyNames(obj).length; j++) { |
147 | | - var key = Object.getOwnPropertyNames(obj)[j]; |
| 143 | + continue; |
| 144 | + } |
| 145 | + var obj = arguments[arg]; |
| 146 | + if (obj) { |
| 147 | + for (var j = 0; j < Object.getOwnPropertyNames(obj).length; j++) { |
| 148 | + var key = Object.getOwnPropertyNames(obj)[j]; |
148 | 149 | if (arg == "caller" || arg == "callee" || arg == "length" || arg == "arguments") { |
149 | | - continue; |
150 | | - } |
151 | | - dest[key] = obj[key]; |
152 | | - } |
| 150 | + continue; |
| 151 | + } |
| 152 | + dest[key] = obj[key]; |
153 | 153 | } |
| 154 | + } |
154 | 155 | } |
155 | 156 | return dest; |
156 | 157 | }, |
@@ -667,46 +668,15 @@ const Util = { |
667 | 668 | if (!url) { |
668 | 669 | return true; |
669 | 670 | } |
670 | | - var index = url.indexOf('//'); |
671 | | - var documentUrl = document.location.toString(); |
672 | | - var documentIndex = documentUrl.indexOf('//'); |
| 671 | + const index = url.indexOf('//'); |
673 | 672 | if (index === -1) { |
674 | 673 | return true; |
675 | | - } else { |
676 | | - var protocol; |
677 | | - var substring = (protocol = url.substring(0, index)); |
678 | | - var documentSubString = documentUrl.substring(documentIndex + 2); |
679 | | - documentIndex = documentSubString.indexOf('/'); |
680 | | - var documentPortIndex = documentSubString.indexOf(':'); |
681 | | - var documentDomainWithPort = documentSubString.substring(0, documentIndex); |
682 | | - //var documentPort; |
683 | | - |
684 | | - var documentprotocol = document.location.protocol; |
685 | | - if (documentPortIndex !== -1) { |
686 | | - // documentPort = +documentSubString.substring(documentPortIndex, documentIndex); |
687 | | - } else { |
688 | | - documentDomainWithPort += ':' + (documentprotocol.toLowerCase() === 'http:' ? 80 : 443); |
689 | | - } |
690 | | - if (documentprotocol.toLowerCase() !== substring.toLowerCase()) { |
691 | | - return false; |
692 | | - } |
693 | | - substring = url.substring(index + 2); |
694 | | - var portIndex = substring.indexOf(':'); |
695 | | - index = substring.indexOf('/'); |
696 | | - var domainWithPort = substring.substring(0, index); |
697 | | - var domain; |
698 | | - if (portIndex !== -1) { |
699 | | - domain = substring.substring(0, portIndex); |
700 | | - } else { |
701 | | - domain = substring.substring(0, index); |
702 | | - domainWithPort += ':' + (protocol.toLowerCase() === 'http:' ? 80 : 443); |
703 | | - } |
704 | | - var documentDomain = document.domain; |
705 | | - if (domain === documentDomain && domainWithPort === documentDomainWithPort) { |
706 | | - return true; |
707 | | - } |
708 | 674 | } |
709 | | - return false; |
| 675 | + return Util.isSameDomain(url, document.location.toString()); |
| 676 | + }, |
| 677 | + |
| 678 | + isSameDomain(url, otherUrl) { |
| 679 | + return new URI(url).normalize().origin() === new URI(otherUrl).normalize().origin(); |
710 | 680 | }, |
711 | 681 |
|
712 | 682 | /** |
|
0 commit comments