Created
March 3, 2021 05:55
-
-
Save Mitscherlich/95706e4c900441fa549727af6388d08d to your computer and use it in GitHub Desktop.
Simple Proxy Compatibility Test.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta chaset="utf-8" /> | |
<!-- bootstrap --> | |
<link href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" /> | |
</head> | |
<body> | |
<div class="container pt-4"> | |
<div class="card"> | |
<div class="card-header">Proxy Compatibility</div> | |
<div class="card-body"> | |
<div class="alert alert-dark" id="compatibility"> | |
<span class="col-3">Proxy</span> | |
<span class="col" id="result">Testing...</span> | |
</div> | |
</div> | |
</div> | |
</div> | |
<!-- Proxy polyfill --> | |
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/proxy-polyfill/proxy.min.js"></script> | |
<!-- jQuery --> | |
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.slim.min.js"></script> | |
<script type="text/javascript"> | |
var utils = (function () { | |
var objProto = Object.prototype; | |
var toString = objProto.toString; | |
function isDef(value) { | |
return value !== void 0; | |
} | |
function isNative(Ctor) { | |
var tag = toString.call(Ctor); | |
return /[native code]/.test(tag); | |
} | |
return { | |
isDef: isDef, | |
isNative: isNative, | |
}; | |
})(); | |
</script> | |
<script type="text/javascript"> | |
(function ($) { | |
var $compatibility = $('#compatibility'); | |
var $result = $('#result'); | |
var Proxy = window.Proxy; | |
$(function () { | |
if (!utils.isDef(Proxy)) { | |
$compatibility.removeClass('alert-dark'); | |
$compatibility.addClass('alert-danger'); | |
$result.empty().text('Failed!'); | |
return; | |
} | |
if (!utils.isNative(Proxy)) { | |
$compatibility.removeClass('alert-dark'); | |
$compatibility.addClass('alert-warn'); | |
$result.empty().text('Polyfill.'); | |
return; | |
} | |
$compatibility.removeClass('alert-dark'); | |
$compatibility.addClass('alert-success'); | |
$result.empty().text('Native.'); | |
}); | |
})(window.jQuery); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment