luda
Version:
A library helps to build cross-framework UI components.
100 lines (83 loc) • 2.78 kB
text/coffeescript
Degradation =
_URL_ATTRIBUTE: 'data-degradation-url'
_HTML: [
'<div id="luda-degradation-html" '
'style="padding:100px 30px;text-align:center">'
'<h1>Your Browser is Too Old!</h1>'
'<p>'
'Please visit this site with a modern browser '
'<a target="_blank" href="https://www.google.com/chrome/">'
'(Chrome is recommended)'
'</a>'
'.</p>'
'</div>'
].join('')
_CSS_PROPERTIES: [
display: 'flex'
position: ['sticky||-webkit-sticky', 'fixed']
'transition'
'animation'
]
_JS_PROPERTIES:
es6Class: 'class X {}'
es6ArrowFunction: '((x) => x)()'
mutationObserver: 'new MutationObserver(function(){})'
proxy: 'new Proxy({},{})'
performance: 'performance.clearMarks()'
_NOTIFY_MILLSECONDS: 500
check: ->
()
_eval: (script) ->
geval = eval
script = '(function(){' + script + '})()'
geval script
_checkEnv: ->
if typeof document isnt 'undefined'
return window if typeof window isnt 'undefined'
return global if typeof global isnt 'undefined'
throw new Error 'Unsupported runtime environment.'
_checkJS: (properties) ->
for property, value of properties
try
value
catch err
()
throw new Error property + ' ' + err
_checkCSS: (properties) ->
ele = document.createElement 'div'
for property in properties
if typeof property is 'string'
ele, property
else
for name, value of property
ele, name
if value instanceof Array
ele, name, valueEle for valueEle in value
else
ele, name, value
_CSSPropertySupported: (ele, property) ->
unless typeof ele.style[property] is 'string'
()
throw new Error 'Unsupported CSS property: ' + property
_CSSValueSupported: (ele, property, valueStr) ->
values = valueStr.split '||'
for value in values
ele.style[property] = value
return if ele.style[property] is value
()
throw new Error 'Unsupported CSS property value: ' \
+ property + ' ' + valueStr
_notify: ->
redirectUrl = document.documentElement.getAttribute
return location.href = redirectUrl if redirectUrl
for script in document.scripts
redirectUrl = script.getAttribute
return location.href = redirectUrl if redirectUrl
_self = this
setInterval(->
unless document.getElementById 'luda-degradation-html'
document.body.innerHTML = _self._HTML if document.body
, )
Degradation.check()