@urso/core 0.7.25 → 0.7.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/js/index.js +1 -1
- package/package.json +1 -1
- package/src/js/app.js +1 -0
- package/src/js/lib/device.js +142 -213
- package/src/js/modules/assets/controller.js +12 -0
- package/src/js/modules/assets/service.js +8 -0
package/src/js/lib/device.js
CHANGED
|
@@ -33,37 +33,37 @@ LibDevice = function () {
|
|
|
33
33
|
* @default
|
|
34
34
|
*/
|
|
35
35
|
this.cocoonJS = false;
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
/**
|
|
38
38
|
* @property {boolean} cocoonJSApp - Is this game running with CocoonJS.App?
|
|
39
39
|
* @default
|
|
40
40
|
*/
|
|
41
41
|
this.cocoonJSApp = false;
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
/**
|
|
44
44
|
* @property {boolean} cordova - Is the game running under Apache Cordova?
|
|
45
45
|
* @default
|
|
46
46
|
*/
|
|
47
47
|
this.cordova = false;
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
/**
|
|
50
50
|
* @property {boolean} node - Is the game running under Node.js?
|
|
51
51
|
* @default
|
|
52
52
|
*/
|
|
53
53
|
this.node = false;
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
/**
|
|
56
56
|
* @property {boolean} nodeWebkit - Is the game running under Node-Webkit?
|
|
57
57
|
* @default
|
|
58
58
|
*/
|
|
59
59
|
this.nodeWebkit = false;
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
/**
|
|
62
62
|
* @property {boolean} electron - Is the game running under GitHub Electron?
|
|
63
63
|
* @default
|
|
64
64
|
*/
|
|
65
65
|
this.electron = false;
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
/**
|
|
68
68
|
* @property {boolean} ejecta - Is the game running under Ejecta?
|
|
69
69
|
* @default
|
|
@@ -192,6 +192,18 @@ LibDevice = function () {
|
|
|
192
192
|
*/
|
|
193
193
|
this.quirksMode = false;
|
|
194
194
|
|
|
195
|
+
/**
|
|
196
|
+
* @property {boolean} webP - Is the browser support webP
|
|
197
|
+
* @default
|
|
198
|
+
*/
|
|
199
|
+
this.webP = false;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @property {boolean} _webPTestComplete - Is the webP test complete
|
|
203
|
+
* @default
|
|
204
|
+
*/
|
|
205
|
+
this._webPTestComplete = false;
|
|
206
|
+
|
|
195
207
|
// Input
|
|
196
208
|
|
|
197
209
|
/**
|
|
@@ -418,7 +430,7 @@ LibDevice = function () {
|
|
|
418
430
|
* @property {boolean} iPhone5 - Is running on iPhone5?
|
|
419
431
|
* @default
|
|
420
432
|
*/
|
|
421
|
-
|
|
433
|
+
this.iPhone5 = false;
|
|
422
434
|
|
|
423
435
|
/**
|
|
424
436
|
* @property {boolean} iPad - Is running on iPad?
|
|
@@ -510,37 +522,31 @@ LibDevice.whenReady = function (callback, context, nonPrimer) {
|
|
|
510
522
|
|
|
511
523
|
let readyCheck = this._readyCheck;
|
|
512
524
|
|
|
513
|
-
if (this.deviceReadyAt || !readyCheck)
|
|
514
|
-
{
|
|
525
|
+
if (this.deviceReadyAt || !readyCheck) {
|
|
515
526
|
callback.call(context, this);
|
|
516
527
|
}
|
|
517
|
-
else if (readyCheck._monitor || nonPrimer)
|
|
518
|
-
{
|
|
528
|
+
else if (readyCheck._monitor || nonPrimer) {
|
|
519
529
|
readyCheck._queue = readyCheck._queue || [];
|
|
520
530
|
readyCheck._queue.push([callback, context]);
|
|
521
531
|
}
|
|
522
|
-
else
|
|
523
|
-
{
|
|
532
|
+
else {
|
|
524
533
|
readyCheck._monitor = readyCheck.bind(this);
|
|
525
534
|
readyCheck._queue = readyCheck._queue || [];
|
|
526
535
|
readyCheck._queue.push([callback, context]);
|
|
527
|
-
|
|
536
|
+
|
|
528
537
|
let cordova = typeof window.cordova !== 'undefined';
|
|
529
538
|
let cocoonJS = navigator['isCocoonJS'];
|
|
530
539
|
|
|
531
|
-
if (document.readyState === 'complete' || document.readyState === 'interactive')
|
|
532
|
-
{
|
|
540
|
+
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
|
533
541
|
// Why is there an additional timeout here?
|
|
534
542
|
window.setTimeout(readyCheck._monitor, 0);
|
|
535
543
|
}
|
|
536
|
-
else if (cordova && !cocoonJS)
|
|
537
|
-
{
|
|
544
|
+
else if (cordova && !cocoonJS) {
|
|
538
545
|
// Ref. http://docs.phonegap.com/en/3.5.0/cordova_events_events.md.html#deviceready
|
|
539
546
|
// Cordova, but NOT Cocoon?
|
|
540
547
|
document.addEventListener('deviceready', readyCheck._monitor, false);
|
|
541
548
|
}
|
|
542
|
-
else
|
|
543
|
-
{
|
|
549
|
+
else {
|
|
544
550
|
document.addEventListener('DOMContentLoaded', readyCheck._monitor, false);
|
|
545
551
|
window.addEventListener('load', readyCheck._monitor, false);
|
|
546
552
|
}
|
|
@@ -559,12 +565,10 @@ LibDevice._readyCheck = function () {
|
|
|
559
565
|
|
|
560
566
|
let readyCheck = this._readyCheck;
|
|
561
567
|
|
|
562
|
-
if (!document.body)
|
|
563
|
-
{
|
|
568
|
+
if (!document.body || !this._webPTestComplete) {
|
|
564
569
|
window.setTimeout(readyCheck._monitor, 20);
|
|
565
570
|
}
|
|
566
|
-
else if (!this.deviceReadyAt)
|
|
567
|
-
{
|
|
571
|
+
else if (!this.deviceReadyAt) {
|
|
568
572
|
this.deviceReadyAt = Date.now();
|
|
569
573
|
|
|
570
574
|
document.removeEventListener('deviceready', readyCheck._monitor);
|
|
@@ -575,8 +579,7 @@ LibDevice._readyCheck = function () {
|
|
|
575
579
|
this.initialized = true;
|
|
576
580
|
|
|
577
581
|
let item;
|
|
578
|
-
while ((item = readyCheck._queue.shift()))
|
|
579
|
-
{
|
|
582
|
+
while ((item = readyCheck._queue.shift())) {
|
|
580
583
|
let callback = item[0];
|
|
581
584
|
let context = item[1];
|
|
582
585
|
callback.call(context, this);
|
|
@@ -603,47 +606,38 @@ LibDevice._initialize = function () {
|
|
|
603
606
|
/**
|
|
604
607
|
* Check which OS is game running on.
|
|
605
608
|
*/
|
|
606
|
-
function _checkOS
|
|
609
|
+
function _checkOS() {
|
|
607
610
|
|
|
608
611
|
let ua = navigator.userAgent;
|
|
609
612
|
|
|
610
|
-
if (/Playstation Vita/.test(ua))
|
|
611
|
-
{
|
|
613
|
+
if (/Playstation Vita/.test(ua)) {
|
|
612
614
|
device.vita = true;
|
|
613
615
|
}
|
|
614
|
-
else if (/Kindle/.test(ua) || /\bKF[A-Z][A-Z]+/.test(ua) || /Silk.*Mobile Safari/.test(ua))
|
|
615
|
-
{
|
|
616
|
+
else if (/Kindle/.test(ua) || /\bKF[A-Z][A-Z]+/.test(ua) || /Silk.*Mobile Safari/.test(ua)) {
|
|
616
617
|
device.kindle = true;
|
|
617
618
|
// This will NOT detect early generations of Kindle Fire, I think there is no reliable way...
|
|
618
619
|
// E.g. "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-80) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true"
|
|
619
620
|
}
|
|
620
|
-
else if (/Android/.test(ua))
|
|
621
|
-
{
|
|
621
|
+
else if (/Android/.test(ua)) {
|
|
622
622
|
device.android = true;
|
|
623
623
|
}
|
|
624
|
-
else if (/CrOS/.test(ua))
|
|
625
|
-
{
|
|
624
|
+
else if (/CrOS/.test(ua)) {
|
|
626
625
|
device.chromeOS = true;
|
|
627
626
|
}
|
|
628
|
-
else if (/iP[ao]d|iPhone/i.test(ua))
|
|
629
|
-
{
|
|
627
|
+
else if (/iP[ao]d|iPhone/i.test(ua)) {
|
|
630
628
|
device.iOS = true;
|
|
631
629
|
}
|
|
632
|
-
else if (/Linux/.test(ua))
|
|
633
|
-
{
|
|
630
|
+
else if (/Linux/.test(ua)) {
|
|
634
631
|
device.linux = true;
|
|
635
632
|
}
|
|
636
|
-
else if (/Mac OS/.test(ua))
|
|
637
|
-
{
|
|
633
|
+
else if (/Mac OS/.test(ua)) {
|
|
638
634
|
device.macOS = true;
|
|
639
635
|
}
|
|
640
|
-
else if (/Windows/.test(ua))
|
|
641
|
-
{
|
|
636
|
+
else if (/Windows/.test(ua)) {
|
|
642
637
|
device.windows = true;
|
|
643
638
|
}
|
|
644
639
|
|
|
645
|
-
if (/Windows Phone/i.test(ua) || /IEMobile/i.test(ua))
|
|
646
|
-
{
|
|
640
|
+
if (/Windows Phone/i.test(ua) || /IEMobile/i.test(ua)) {
|
|
647
641
|
device.android = false;
|
|
648
642
|
device.iOS = false;
|
|
649
643
|
device.macOS = false;
|
|
@@ -653,14 +647,12 @@ LibDevice._initialize = function () {
|
|
|
653
647
|
|
|
654
648
|
let silk = /Silk/.test(ua); // detected in browsers
|
|
655
649
|
|
|
656
|
-
if (device.windows || device.macOS || (device.linux && !silk) || device.chromeOS)
|
|
657
|
-
{
|
|
650
|
+
if (device.windows || device.macOS || (device.linux && !silk) || device.chromeOS) {
|
|
658
651
|
device.desktop = true;
|
|
659
652
|
}
|
|
660
653
|
|
|
661
654
|
// Windows Phone / Table reset
|
|
662
|
-
if (device.windowsPhone || ((/Windows NT/i.test(ua)) && (/Touch/i.test(ua))))
|
|
663
|
-
{
|
|
655
|
+
if (device.windowsPhone || ((/Windows NT/i.test(ua)) && (/Touch/i.test(ua)))) {
|
|
664
656
|
device.desktop = false;
|
|
665
657
|
}
|
|
666
658
|
|
|
@@ -669,7 +661,7 @@ LibDevice._initialize = function () {
|
|
|
669
661
|
/**
|
|
670
662
|
* Check HTML5 features of the host environment.
|
|
671
663
|
*/
|
|
672
|
-
function _checkFeatures
|
|
664
|
+
function _checkFeatures() {
|
|
673
665
|
|
|
674
666
|
device.canvas = !!window['CanvasRenderingContext2D'] || device.cocoonJS;
|
|
675
667
|
|
|
@@ -682,7 +674,7 @@ LibDevice._initialize = function () {
|
|
|
682
674
|
device.file = !!window['File'] && !!window['FileReader'] && !!window['FileList'] && !!window['Blob'];
|
|
683
675
|
device.fileSystem = !!window['requestFileSystem'];
|
|
684
676
|
|
|
685
|
-
device.webGL = (
|
|
677
|
+
device.webGL = (function () { try { let canvas = document.createElement('canvas'); /*Force screencanvas to false*/ canvas.screencanvas = false; return !!window.WebGLRenderingContext && (canvas.getContext('webgl') || canvas.getContext('experimental-webgl')); } catch (e) { return false; } })();
|
|
686
678
|
device.webGL = !!device.webGL;
|
|
687
679
|
|
|
688
680
|
device.worker = !!window['Worker'];
|
|
@@ -698,21 +690,18 @@ LibDevice._initialize = function () {
|
|
|
698
690
|
device.getUserMedia = device.getUserMedia && !!navigator.getUserMedia && !!window.URL;
|
|
699
691
|
|
|
700
692
|
// Older versions of firefox (< 21) apparently claim support but user media does not actually work
|
|
701
|
-
if (device.firefox && device.firefoxVersion < 21)
|
|
702
|
-
{
|
|
693
|
+
if (device.firefox && device.firefoxVersion < 21) {
|
|
703
694
|
device.getUserMedia = false;
|
|
704
695
|
}
|
|
705
696
|
|
|
706
697
|
// Excludes iOS versions as they generally wrap UIWebView (eg. Safari WebKit) and it
|
|
707
698
|
// is safer to not try and use the fast copy-over method.
|
|
708
|
-
if (!device.iOS && (device.ie || device.firefox || device.chrome))
|
|
709
|
-
{
|
|
699
|
+
if (!device.iOS && (device.ie || device.firefox || device.chrome)) {
|
|
710
700
|
device.canvasBitBltShift = true;
|
|
711
701
|
}
|
|
712
702
|
|
|
713
703
|
// Known not to work
|
|
714
|
-
if (device.safari || device.mobileSafari)
|
|
715
|
-
{
|
|
704
|
+
if (device.safari || device.mobileSafari) {
|
|
716
705
|
device.canvasBitBltShift = false;
|
|
717
706
|
}
|
|
718
707
|
|
|
@@ -721,33 +710,27 @@ LibDevice._initialize = function () {
|
|
|
721
710
|
/**
|
|
722
711
|
* Checks/configures letious input.
|
|
723
712
|
*/
|
|
724
|
-
function _checkInput
|
|
713
|
+
function _checkInput() {
|
|
725
714
|
|
|
726
|
-
if ('ontouchstart' in document.documentElement || (window.navigator.maxTouchPoints && window.navigator.maxTouchPoints >= 1))
|
|
727
|
-
{
|
|
715
|
+
if ('ontouchstart' in document.documentElement || (window.navigator.maxTouchPoints && window.navigator.maxTouchPoints >= 1)) {
|
|
728
716
|
device.touch = true;
|
|
729
717
|
}
|
|
730
718
|
|
|
731
|
-
if (window.navigator.msPointerEnabled || window.navigator.pointerEnabled)
|
|
732
|
-
{
|
|
719
|
+
if (window.navigator.msPointerEnabled || window.navigator.pointerEnabled) {
|
|
733
720
|
device.mspointer = true;
|
|
734
721
|
}
|
|
735
722
|
|
|
736
|
-
if (!device.cocoonJS)
|
|
737
|
-
{
|
|
723
|
+
if (!device.cocoonJS) {
|
|
738
724
|
// See https://developer.mozilla.org/en-US/docs/Web/Events/wheel
|
|
739
|
-
if ('onwheel' in window || (device.ie && 'WheelEvent' in window))
|
|
740
|
-
{
|
|
725
|
+
if ('onwheel' in window || (device.ie && 'WheelEvent' in window)) {
|
|
741
726
|
// DOM3 Wheel Event: FF 17+, IE 9+, Chrome 31+, Safari 7+
|
|
742
727
|
device.wheelEvent = 'wheel';
|
|
743
728
|
}
|
|
744
|
-
else if ('onmousewheel' in window)
|
|
745
|
-
{
|
|
729
|
+
else if ('onmousewheel' in window) {
|
|
746
730
|
// Non-FF legacy: IE 6-9, Chrome 1-31, Safari 5-7.
|
|
747
731
|
device.wheelEvent = 'mousewheel';
|
|
748
732
|
}
|
|
749
|
-
else if (device.firefox && 'MouseScrollEvent' in window)
|
|
750
|
-
{
|
|
733
|
+
else if (device.firefox && 'MouseScrollEvent' in window) {
|
|
751
734
|
// FF prior to 17. This should probably be scrubbed.
|
|
752
735
|
device.wheelEvent = 'DOMMouseScroll';
|
|
753
736
|
}
|
|
@@ -758,7 +741,7 @@ LibDevice._initialize = function () {
|
|
|
758
741
|
/**
|
|
759
742
|
* Checks for support of the Full Screen API.
|
|
760
743
|
*/
|
|
761
|
-
function _checkFullScreenSupport
|
|
744
|
+
function _checkFullScreenSupport() {
|
|
762
745
|
|
|
763
746
|
let fs = [
|
|
764
747
|
'requestFullscreen',
|
|
@@ -773,10 +756,8 @@ LibDevice._initialize = function () {
|
|
|
773
756
|
|
|
774
757
|
let element = document.createElement('div');
|
|
775
758
|
|
|
776
|
-
for (let i = 0; i < fs.length; i++)
|
|
777
|
-
|
|
778
|
-
if (element[fs[i]])
|
|
779
|
-
{
|
|
759
|
+
for (let i = 0; i < fs.length; i++) {
|
|
760
|
+
if (element[fs[i]]) {
|
|
780
761
|
device.fullscreen = true;
|
|
781
762
|
device.requestFullscreen = fs[i];
|
|
782
763
|
break;
|
|
@@ -794,12 +775,9 @@ LibDevice._initialize = function () {
|
|
|
794
775
|
'mozExitFullscreen'
|
|
795
776
|
];
|
|
796
777
|
|
|
797
|
-
if (device.fullscreen)
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
{
|
|
801
|
-
if (document[cfs[i]])
|
|
802
|
-
{
|
|
778
|
+
if (device.fullscreen) {
|
|
779
|
+
for (let i = 0; i < cfs.length; i++) {
|
|
780
|
+
if (document[cfs[i]]) {
|
|
803
781
|
device.cancelFullscreen = cfs[i];
|
|
804
782
|
break;
|
|
805
783
|
}
|
|
@@ -807,8 +785,7 @@ LibDevice._initialize = function () {
|
|
|
807
785
|
}
|
|
808
786
|
|
|
809
787
|
// Keyboard Input?
|
|
810
|
-
if (window['Element'] && Element['ALLOW_KEYBOARD_INPUT'])
|
|
811
|
-
{
|
|
788
|
+
if (window['Element'] && Element['ALLOW_KEYBOARD_INPUT']) {
|
|
812
789
|
device.fullscreenKeyboard = true;
|
|
813
790
|
}
|
|
814
791
|
|
|
@@ -817,51 +794,41 @@ LibDevice._initialize = function () {
|
|
|
817
794
|
/**
|
|
818
795
|
* Check what browser is game running in.
|
|
819
796
|
*/
|
|
820
|
-
function _checkBrowser
|
|
797
|
+
function _checkBrowser() {
|
|
821
798
|
|
|
822
799
|
let ua = navigator.userAgent;
|
|
823
800
|
|
|
824
|
-
if (/Arora/.test(ua))
|
|
825
|
-
{
|
|
801
|
+
if (/Arora/.test(ua)) {
|
|
826
802
|
device.arora = true;
|
|
827
803
|
}
|
|
828
|
-
else if (/Chrome\/(\d+)/.test(ua) && !device.windowsPhone)
|
|
829
|
-
{
|
|
804
|
+
else if (/Chrome\/(\d+)/.test(ua) && !device.windowsPhone) {
|
|
830
805
|
device.chrome = true;
|
|
831
806
|
device.chromeVersion = parseInt(RegExp.$1, 10);
|
|
832
807
|
}
|
|
833
|
-
else if (/Epiphany/.test(ua))
|
|
834
|
-
{
|
|
808
|
+
else if (/Epiphany/.test(ua)) {
|
|
835
809
|
device.epiphany = true;
|
|
836
810
|
}
|
|
837
|
-
else if (/Firefox\D+(\d+)/.test(ua))
|
|
838
|
-
{
|
|
811
|
+
else if (/Firefox\D+(\d+)/.test(ua)) {
|
|
839
812
|
device.firefox = true;
|
|
840
813
|
device.firefoxVersion = parseInt(RegExp.$1, 10);
|
|
841
814
|
}
|
|
842
|
-
else if (/AppleWebKit/.test(ua) && device.iOS)
|
|
843
|
-
{
|
|
815
|
+
else if (/AppleWebKit/.test(ua) && device.iOS) {
|
|
844
816
|
device.mobileSafari = true;
|
|
845
817
|
}
|
|
846
|
-
else if (/MSIE (\d+\.\d+);/.test(ua))
|
|
847
|
-
{
|
|
818
|
+
else if (/MSIE (\d+\.\d+);/.test(ua)) {
|
|
848
819
|
device.ie = true;
|
|
849
820
|
device.ieVersion = parseInt(RegExp.$1, 10);
|
|
850
821
|
}
|
|
851
|
-
else if (/Midori/.test(ua))
|
|
852
|
-
{
|
|
822
|
+
else if (/Midori/.test(ua)) {
|
|
853
823
|
device.midori = true;
|
|
854
824
|
}
|
|
855
|
-
else if (/Opera/.test(ua))
|
|
856
|
-
{
|
|
825
|
+
else if (/Opera/.test(ua)) {
|
|
857
826
|
device.opera = true;
|
|
858
827
|
}
|
|
859
|
-
else if (/Safari/.test(ua) && !device.windowsPhone)
|
|
860
|
-
{
|
|
828
|
+
else if (/Safari/.test(ua) && !device.windowsPhone) {
|
|
861
829
|
device.safari = true;
|
|
862
830
|
}
|
|
863
|
-
else if (/Trident\/(\d+\.\d+)(.*)rv:(\d+\.\d+)/.test(ua))
|
|
864
|
-
{
|
|
831
|
+
else if (/Trident\/(\d+\.\d+)(.*)rv:(\d+\.\d+)/.test(ua)) {
|
|
865
832
|
device.ie = true;
|
|
866
833
|
device.trident = true;
|
|
867
834
|
device.tridentVersion = parseInt(RegExp.$1, 10);
|
|
@@ -869,57 +836,47 @@ LibDevice._initialize = function () {
|
|
|
869
836
|
}
|
|
870
837
|
|
|
871
838
|
// Silk gets its own if clause because its ua also contains 'Safari'
|
|
872
|
-
if (/Silk/.test(ua))
|
|
873
|
-
{
|
|
839
|
+
if (/Silk/.test(ua)) {
|
|
874
840
|
device.silk = true;
|
|
875
841
|
}
|
|
876
842
|
|
|
877
843
|
// WebApp mode in iOS
|
|
878
|
-
if (navigator['standalone'])
|
|
879
|
-
{
|
|
844
|
+
if (navigator['standalone']) {
|
|
880
845
|
device.webApp = true;
|
|
881
846
|
}
|
|
882
|
-
|
|
883
|
-
if (typeof window.cordova !== "undefined")
|
|
884
|
-
{
|
|
847
|
+
|
|
848
|
+
if (typeof window.cordova !== "undefined") {
|
|
885
849
|
device.cordova = true;
|
|
886
850
|
}
|
|
887
|
-
|
|
888
|
-
if (typeof process !== "undefined" && typeof require !== "undefined")
|
|
889
|
-
{
|
|
851
|
+
|
|
852
|
+
if (typeof process !== "undefined" && typeof require !== "undefined") {
|
|
890
853
|
device.node = true;
|
|
891
854
|
}
|
|
892
|
-
|
|
893
|
-
if (device.node && typeof process.versions === 'object')
|
|
894
|
-
{
|
|
855
|
+
|
|
856
|
+
if (device.node && typeof process.versions === 'object') {
|
|
895
857
|
device.nodeWebkit = !!process.versions['node-webkit'];
|
|
896
|
-
|
|
858
|
+
|
|
897
859
|
device.electron = !!process.versions.electron;
|
|
898
860
|
}
|
|
899
|
-
|
|
900
|
-
if (navigator['isCocoonJS'])
|
|
901
|
-
{
|
|
861
|
+
|
|
862
|
+
if (navigator['isCocoonJS']) {
|
|
902
863
|
device.cocoonJS = true;
|
|
903
864
|
}
|
|
904
|
-
|
|
905
|
-
if (device.cocoonJS)
|
|
906
|
-
{
|
|
865
|
+
|
|
866
|
+
if (device.cocoonJS) {
|
|
907
867
|
try {
|
|
908
868
|
device.cocoonJSApp = (typeof CocoonJS !== "undefined");
|
|
909
869
|
}
|
|
910
|
-
catch(error)
|
|
911
|
-
{
|
|
870
|
+
catch (error) {
|
|
912
871
|
device.cocoonJSApp = false;
|
|
913
872
|
}
|
|
914
873
|
}
|
|
915
874
|
|
|
916
|
-
if (typeof window.ejecta !== "undefined")
|
|
917
|
-
{
|
|
875
|
+
if (typeof window.ejecta !== "undefined") {
|
|
918
876
|
device.ejecta = true;
|
|
919
877
|
}
|
|
920
878
|
|
|
921
|
-
if (/Crosswalk/.test(ua))
|
|
922
|
-
{
|
|
879
|
+
if (/Crosswalk/.test(ua)) {
|
|
923
880
|
device.crosswalk = true;
|
|
924
881
|
}
|
|
925
882
|
|
|
@@ -928,48 +885,42 @@ LibDevice._initialize = function () {
|
|
|
928
885
|
/**
|
|
929
886
|
* Check video support.
|
|
930
887
|
*/
|
|
931
|
-
function _checkVideo
|
|
888
|
+
function _checkVideo() {
|
|
932
889
|
|
|
933
890
|
let videoElement = document.createElement("video");
|
|
934
891
|
let result = false;
|
|
935
892
|
|
|
936
893
|
try {
|
|
937
|
-
if (result = !!videoElement.canPlayType)
|
|
938
|
-
|
|
939
|
-
if (videoElement.canPlayType('video/ogg; codecs="theora"').replace(/^no$/, ''))
|
|
940
|
-
{
|
|
894
|
+
if (result = !!videoElement.canPlayType) {
|
|
895
|
+
if (videoElement.canPlayType('video/ogg; codecs="theora"').replace(/^no$/, '')) {
|
|
941
896
|
device.oggVideo = true;
|
|
942
897
|
}
|
|
943
898
|
|
|
944
|
-
if (videoElement.canPlayType('video/mp4; codecs="avc1.42E01E"').replace(/^no$/, ''))
|
|
945
|
-
{
|
|
899
|
+
if (videoElement.canPlayType('video/mp4; codecs="avc1.42E01E"').replace(/^no$/, '')) {
|
|
946
900
|
// Without QuickTime, this value will be `undefined`. github.com/Modernizr/Modernizr/issues/546
|
|
947
901
|
device.h264Video = true;
|
|
948
902
|
device.mp4Video = true;
|
|
949
903
|
}
|
|
950
904
|
|
|
951
|
-
if (videoElement.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/^no$/, ''))
|
|
952
|
-
{
|
|
905
|
+
if (videoElement.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/^no$/, '')) {
|
|
953
906
|
device.webmVideo = true;
|
|
954
907
|
}
|
|
955
908
|
|
|
956
|
-
if (videoElement.canPlayType('video/webm; codecs="vp9"').replace(/^no$/, ''))
|
|
957
|
-
{
|
|
909
|
+
if (videoElement.canPlayType('video/webm; codecs="vp9"').replace(/^no$/, '')) {
|
|
958
910
|
device.vp9Video = true;
|
|
959
911
|
}
|
|
960
912
|
|
|
961
|
-
if (videoElement.canPlayType('application/x-mpegURL; codecs="avc1.42E01E"').replace(/^no$/, ''))
|
|
962
|
-
{
|
|
913
|
+
if (videoElement.canPlayType('application/x-mpegURL; codecs="avc1.42E01E"').replace(/^no$/, '')) {
|
|
963
914
|
device.hlsVideo = true;
|
|
964
915
|
}
|
|
965
916
|
}
|
|
966
|
-
} catch (e) {}
|
|
917
|
+
} catch (e) { }
|
|
967
918
|
}
|
|
968
919
|
|
|
969
920
|
/**
|
|
970
921
|
* Check audio support.
|
|
971
922
|
*/
|
|
972
|
-
function _checkAudio
|
|
923
|
+
function _checkAudio() {
|
|
973
924
|
|
|
974
925
|
device.audioData = !!(window['Audio']);
|
|
975
926
|
device.webAudio = !!(window['AudioContext'] || window['webkitAudioContext']);
|
|
@@ -977,38 +928,31 @@ LibDevice._initialize = function () {
|
|
|
977
928
|
let result = false;
|
|
978
929
|
|
|
979
930
|
try {
|
|
980
|
-
if (result = !!audioElement.canPlayType)
|
|
981
|
-
|
|
982
|
-
if (audioElement.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, ''))
|
|
983
|
-
{
|
|
931
|
+
if (result = !!audioElement.canPlayType) {
|
|
932
|
+
if (audioElement.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, '')) {
|
|
984
933
|
device.ogg = true;
|
|
985
934
|
}
|
|
986
935
|
|
|
987
|
-
if (audioElement.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, '') || audioElement.canPlayType('audio/opus;').replace(/^no$/, ''))
|
|
988
|
-
{
|
|
936
|
+
if (audioElement.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, '') || audioElement.canPlayType('audio/opus;').replace(/^no$/, '')) {
|
|
989
937
|
device.opus = true;
|
|
990
938
|
}
|
|
991
939
|
|
|
992
|
-
if (audioElement.canPlayType('audio/mpeg;').replace(/^no$/, ''))
|
|
993
|
-
{
|
|
940
|
+
if (audioElement.canPlayType('audio/mpeg;').replace(/^no$/, '')) {
|
|
994
941
|
device.mp3 = true;
|
|
995
942
|
}
|
|
996
943
|
|
|
997
944
|
// Mimetypes accepted:
|
|
998
945
|
// developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements
|
|
999
946
|
// bit.ly/iphoneoscodecs
|
|
1000
|
-
if (audioElement.canPlayType('audio/wav; codecs="1"').replace(/^no$/, ''))
|
|
1001
|
-
{
|
|
947
|
+
if (audioElement.canPlayType('audio/wav; codecs="1"').replace(/^no$/, '')) {
|
|
1002
948
|
device.wav = true;
|
|
1003
949
|
}
|
|
1004
950
|
|
|
1005
|
-
if (audioElement.canPlayType('audio/x-m4a;') || audioElement.canPlayType('audio/aac;').replace(/^no$/, ''))
|
|
1006
|
-
{
|
|
951
|
+
if (audioElement.canPlayType('audio/x-m4a;') || audioElement.canPlayType('audio/aac;').replace(/^no$/, '')) {
|
|
1007
952
|
device.m4a = true;
|
|
1008
953
|
}
|
|
1009
954
|
|
|
1010
|
-
if (audioElement.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, ''))
|
|
1011
|
-
{
|
|
955
|
+
if (audioElement.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, '')) {
|
|
1012
956
|
device.webm = true;
|
|
1013
957
|
}
|
|
1014
958
|
}
|
|
@@ -1020,7 +964,7 @@ LibDevice._initialize = function () {
|
|
|
1020
964
|
/**
|
|
1021
965
|
* Check PixelRatio, iOS device, Vibration API, ArrayBuffers and endianess.
|
|
1022
966
|
*/
|
|
1023
|
-
function _checkDevice
|
|
967
|
+
function _checkDevice() {
|
|
1024
968
|
|
|
1025
969
|
device.pixelRatio = window['devicePixelRatio'] || 1;
|
|
1026
970
|
device.iPhone = navigator.userAgent.toLowerCase().indexOf('iphone') != -1;
|
|
@@ -1029,17 +973,14 @@ LibDevice._initialize = function () {
|
|
|
1029
973
|
((screen.availWidth === 320 && screen.availHeight === 568) || (screen.availWidth === 568 && screen.availHeight === 320));
|
|
1030
974
|
device.iPad = navigator.userAgent.toLowerCase().indexOf('ipad') != -1;
|
|
1031
975
|
|
|
1032
|
-
if (typeof Int8Array !== 'undefined')
|
|
1033
|
-
{
|
|
976
|
+
if (typeof Int8Array !== 'undefined') {
|
|
1034
977
|
device.typedArray = true;
|
|
1035
978
|
}
|
|
1036
|
-
else
|
|
1037
|
-
{
|
|
979
|
+
else {
|
|
1038
980
|
device.typedArray = false;
|
|
1039
981
|
}
|
|
1040
982
|
|
|
1041
|
-
if (typeof ArrayBuffer !== 'undefined' && typeof Uint8Array !== 'undefined' && typeof Uint32Array !== 'undefined')
|
|
1042
|
-
{
|
|
983
|
+
if (typeof ArrayBuffer !== 'undefined' && typeof Uint8Array !== 'undefined' && typeof Uint32Array !== 'undefined') {
|
|
1043
984
|
device.littleEndian = _checkIsLittleEndian();
|
|
1044
985
|
device.LITTLE_ENDIAN = device.littleEndian;
|
|
1045
986
|
}
|
|
@@ -1048,8 +989,7 @@ LibDevice._initialize = function () {
|
|
|
1048
989
|
|
|
1049
990
|
navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate;
|
|
1050
991
|
|
|
1051
|
-
if (navigator.vibrate)
|
|
1052
|
-
{
|
|
992
|
+
if (navigator.vibrate) {
|
|
1053
993
|
device.vibration = true;
|
|
1054
994
|
}
|
|
1055
995
|
|
|
@@ -1060,7 +1000,7 @@ LibDevice._initialize = function () {
|
|
|
1060
1000
|
*
|
|
1061
1001
|
* @author Matt DesLauriers (@mattdesl)
|
|
1062
1002
|
*/
|
|
1063
|
-
function _checkIsLittleEndian
|
|
1003
|
+
function _checkIsLittleEndian() {
|
|
1064
1004
|
|
|
1065
1005
|
let a = new ArrayBuffer(4);
|
|
1066
1006
|
let b = new Uint8Array(a);
|
|
@@ -1071,17 +1011,14 @@ LibDevice._initialize = function () {
|
|
|
1071
1011
|
b[2] = 0xc3;
|
|
1072
1012
|
b[3] = 0xd4;
|
|
1073
1013
|
|
|
1074
|
-
if (c[0] == 0xd4c3b2a1)
|
|
1075
|
-
{
|
|
1014
|
+
if (c[0] == 0xd4c3b2a1) {
|
|
1076
1015
|
return true;
|
|
1077
1016
|
}
|
|
1078
1017
|
|
|
1079
|
-
if (c[0] == 0xa1b2c3d4)
|
|
1080
|
-
{
|
|
1018
|
+
if (c[0] == 0xa1b2c3d4) {
|
|
1081
1019
|
return false;
|
|
1082
1020
|
}
|
|
1083
|
-
else
|
|
1084
|
-
{
|
|
1021
|
+
else {
|
|
1085
1022
|
// Could not determine endianness
|
|
1086
1023
|
return null;
|
|
1087
1024
|
}
|
|
@@ -1093,18 +1030,16 @@ LibDevice._initialize = function () {
|
|
|
1093
1030
|
*
|
|
1094
1031
|
* @author Matt DesLauriers (@mattdesl)
|
|
1095
1032
|
*/
|
|
1096
|
-
function _checkIsUint8ClampedImageData
|
|
1033
|
+
function _checkIsUint8ClampedImageData() {
|
|
1097
1034
|
|
|
1098
|
-
if (Uint8ClampedArray === undefined)
|
|
1099
|
-
{
|
|
1035
|
+
if (Uint8ClampedArray === undefined) {
|
|
1100
1036
|
return false;
|
|
1101
1037
|
}
|
|
1102
1038
|
|
|
1103
1039
|
let elem = document.createElement('canvas');
|
|
1104
1040
|
let ctx = elem.getContext('2d');
|
|
1105
1041
|
|
|
1106
|
-
if (!ctx)
|
|
1107
|
-
{
|
|
1042
|
+
if (!ctx) {
|
|
1108
1043
|
return false;
|
|
1109
1044
|
}
|
|
1110
1045
|
|
|
@@ -1117,7 +1052,7 @@ LibDevice._initialize = function () {
|
|
|
1117
1052
|
/**
|
|
1118
1053
|
* Check whether the host environment support 3D CSS.
|
|
1119
1054
|
*/
|
|
1120
|
-
function _checkCSS3D
|
|
1055
|
+
function _checkCSS3D() {
|
|
1121
1056
|
|
|
1122
1057
|
let el = document.createElement('p');
|
|
1123
1058
|
let has3d;
|
|
@@ -1132,10 +1067,8 @@ LibDevice._initialize = function () {
|
|
|
1132
1067
|
// Add it to the body to get the computed style.
|
|
1133
1068
|
document.body.insertBefore(el, null);
|
|
1134
1069
|
|
|
1135
|
-
for (let t in transforms)
|
|
1136
|
-
|
|
1137
|
-
if (el.style[t] !== undefined)
|
|
1138
|
-
{
|
|
1070
|
+
for (let t in transforms) {
|
|
1071
|
+
if (el.style[t] !== undefined) {
|
|
1139
1072
|
el.style[t] = "translate3d(1px,1px,1px)";
|
|
1140
1073
|
has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
|
|
1141
1074
|
}
|
|
@@ -1169,28 +1102,22 @@ LibDevice._initialize = function () {
|
|
|
1169
1102
|
*/
|
|
1170
1103
|
LibDevice.canPlayAudio = function (type) {
|
|
1171
1104
|
|
|
1172
|
-
if (type === 'mp3' && this.mp3)
|
|
1173
|
-
{
|
|
1105
|
+
if (type === 'mp3' && this.mp3) {
|
|
1174
1106
|
return true;
|
|
1175
1107
|
}
|
|
1176
|
-
else if (type === 'ogg' && (this.ogg || this.opus))
|
|
1177
|
-
{
|
|
1108
|
+
else if (type === 'ogg' && (this.ogg || this.opus)) {
|
|
1178
1109
|
return true;
|
|
1179
1110
|
}
|
|
1180
|
-
else if (type === 'm4a' && this.m4a)
|
|
1181
|
-
{
|
|
1111
|
+
else if (type === 'm4a' && this.m4a) {
|
|
1182
1112
|
return true;
|
|
1183
1113
|
}
|
|
1184
|
-
else if (type === 'opus' && this.opus)
|
|
1185
|
-
{
|
|
1114
|
+
else if (type === 'opus' && this.opus) {
|
|
1186
1115
|
return true;
|
|
1187
1116
|
}
|
|
1188
|
-
else if (type === 'wav' && this.wav)
|
|
1189
|
-
{
|
|
1117
|
+
else if (type === 'wav' && this.wav) {
|
|
1190
1118
|
return true;
|
|
1191
1119
|
}
|
|
1192
|
-
else if (type === 'webm' && this.webm)
|
|
1193
|
-
{
|
|
1120
|
+
else if (type === 'webm' && this.webm) {
|
|
1194
1121
|
return true;
|
|
1195
1122
|
}
|
|
1196
1123
|
|
|
@@ -1208,20 +1135,16 @@ LibDevice.canPlayAudio = function (type) {
|
|
|
1208
1135
|
*/
|
|
1209
1136
|
LibDevice.canPlayVideo = function (type) {
|
|
1210
1137
|
|
|
1211
|
-
if (type === 'webm' && (this.webmVideo || this.vp9Video))
|
|
1212
|
-
{
|
|
1138
|
+
if (type === 'webm' && (this.webmVideo || this.vp9Video)) {
|
|
1213
1139
|
return true;
|
|
1214
1140
|
}
|
|
1215
|
-
else if (type === 'mp4' && (this.mp4Video || this.h264Video))
|
|
1216
|
-
{
|
|
1141
|
+
else if (type === 'mp4' && (this.mp4Video || this.h264Video)) {
|
|
1217
1142
|
return true;
|
|
1218
1143
|
}
|
|
1219
|
-
else if ((type === 'ogg' || type === 'ogv') && this.oggVideo)
|
|
1220
|
-
{
|
|
1144
|
+
else if ((type === 'ogg' || type === 'ogv') && this.oggVideo) {
|
|
1221
1145
|
return true;
|
|
1222
1146
|
}
|
|
1223
|
-
else if (type === 'mpeg' && this.hlsVideo)
|
|
1224
|
-
{
|
|
1147
|
+
else if (type === 'mpeg' && this.hlsVideo) {
|
|
1225
1148
|
return true;
|
|
1226
1149
|
}
|
|
1227
1150
|
|
|
@@ -1239,23 +1162,19 @@ LibDevice.canPlayVideo = function (type) {
|
|
|
1239
1162
|
*/
|
|
1240
1163
|
LibDevice.isConsoleOpen = function () {
|
|
1241
1164
|
|
|
1242
|
-
if (window.console && window.console['firebug'])
|
|
1243
|
-
{
|
|
1165
|
+
if (window.console && window.console['firebug']) {
|
|
1244
1166
|
return true;
|
|
1245
1167
|
}
|
|
1246
1168
|
|
|
1247
|
-
if (window.console)
|
|
1248
|
-
{
|
|
1169
|
+
if (window.console) {
|
|
1249
1170
|
console.profile();
|
|
1250
1171
|
console.profileEnd();
|
|
1251
1172
|
|
|
1252
|
-
if (console.clear)
|
|
1253
|
-
{
|
|
1173
|
+
if (console.clear) {
|
|
1254
1174
|
console.clear();
|
|
1255
1175
|
}
|
|
1256
1176
|
|
|
1257
|
-
if (console['profiles'])
|
|
1258
|
-
{
|
|
1177
|
+
if (console['profiles']) {
|
|
1259
1178
|
return console['profiles'].length > 0;
|
|
1260
1179
|
}
|
|
1261
1180
|
}
|
|
@@ -1283,4 +1202,14 @@ LibDevice.isAndroidStockBrowser = function () {
|
|
|
1283
1202
|
|
|
1284
1203
|
};
|
|
1285
1204
|
|
|
1205
|
+
//webP check
|
|
1206
|
+
(function () {
|
|
1207
|
+
const webP = new Image();
|
|
1208
|
+
webP.src = 'data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA';
|
|
1209
|
+
webP.onload = webP.onerror = function () {
|
|
1210
|
+
LibDevice.webP = (webP.height === 2);
|
|
1211
|
+
LibDevice._webPTestComplete = true;
|
|
1212
|
+
};
|
|
1213
|
+
})();
|
|
1214
|
+
|
|
1286
1215
|
module.exports = LibDevice;
|