mirror of
https://github.com/openstf/stf
synced 2025-10-05 19:42:01 +02:00
Added Guest Browser properties detection (Touch, Mobile, Retina, WebGL, Websockets Binary, ...)
This commit is contained in:
parent
1c480ab801
commit
7e45141a4e
6 changed files with 147 additions and 3 deletions
127
res/app/components/stf/guest-browser/guest-browser-service.js
Normal file
127
res/app/components/stf/guest-browser/guest-browser-service.js
Normal file
|
@ -0,0 +1,127 @@
|
||||||
|
// NOTE: Most of the detections stuff from Modernizr 3.0
|
||||||
|
|
||||||
|
module.exports = function GuestBrowserServiceFactory() {
|
||||||
|
var service = {
|
||||||
|
}
|
||||||
|
|
||||||
|
var domPrefixes = 'Webkit Moz O ms'.toLowerCase().split(' ')
|
||||||
|
|
||||||
|
function createElement() {
|
||||||
|
return document.createElement.apply(document, arguments)
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasEvent() {
|
||||||
|
return (function (undefined) {
|
||||||
|
function isEventSupportedInner(eventName, element) {
|
||||||
|
var isSupported
|
||||||
|
if (!eventName) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (!element || typeof element === 'string') {
|
||||||
|
element = createElement(element || 'div')
|
||||||
|
}
|
||||||
|
eventName = 'on' + eventName
|
||||||
|
isSupported = eventName in element
|
||||||
|
return isSupported
|
||||||
|
}
|
||||||
|
|
||||||
|
return isEventSupportedInner
|
||||||
|
})()
|
||||||
|
}
|
||||||
|
|
||||||
|
function addTest(key, test) {
|
||||||
|
service[key] = (typeof test == 'function') ? test() : test
|
||||||
|
}
|
||||||
|
|
||||||
|
addTest('touch', function () {
|
||||||
|
return ('ontouchstart' in window) || window.DocumentTouch &&
|
||||||
|
document instanceof DocumentTouch
|
||||||
|
})
|
||||||
|
|
||||||
|
addTest('retina', function () {
|
||||||
|
var mediaQuery = '(-webkit-min-device-pixel-ratio: 1.5), ' +
|
||||||
|
'(min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), ' +
|
||||||
|
'(min-resolution: 1.5dppx)'
|
||||||
|
if (window.devicePixelRatio > 1) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return !!(window.matchMedia && window.matchMedia(mediaQuery).matches)
|
||||||
|
})
|
||||||
|
|
||||||
|
addTest('small', function () {
|
||||||
|
var windowWidth = window.screen.width < window.outerWidth ?
|
||||||
|
window.screen.width : window.outerWidth
|
||||||
|
return windowWidth < 500
|
||||||
|
// return !!(window.matchMedia &&
|
||||||
|
// window.matchMedia('only screen and (max-width: 760px)').matches)
|
||||||
|
})
|
||||||
|
|
||||||
|
addTest('mobile', function () {
|
||||||
|
return !!(service.small && service.touch)
|
||||||
|
})
|
||||||
|
|
||||||
|
addTest('os', function () {
|
||||||
|
var ua = navigator.userAgent
|
||||||
|
if (ua.match(/Android/i)) {
|
||||||
|
return 'android'
|
||||||
|
} else if (ua.match(/iPhone|iPad|iPod/i)) {
|
||||||
|
return 'ios'
|
||||||
|
} else {
|
||||||
|
return 'pc'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
addTest('webgl', function () {
|
||||||
|
var canvas = createElement('canvas')
|
||||||
|
if ('supportsContext' in canvas) {
|
||||||
|
return canvas.supportsContext('webgl') ||
|
||||||
|
canvas.supportsContext('experimental-webgl')
|
||||||
|
}
|
||||||
|
return !!window.WebGLRenderingContext
|
||||||
|
})
|
||||||
|
|
||||||
|
addTest('generators', function () {
|
||||||
|
try {
|
||||||
|
/* jshint evil: true */
|
||||||
|
new Function('function* test() {}')()
|
||||||
|
} catch (e) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
addTest('ua', navigator.userAgent)
|
||||||
|
|
||||||
|
addTest('websocketsbinary', function () {
|
||||||
|
var protocol = 'https:' == location.protocol ? 'wss' : 'ws',
|
||||||
|
protoBin
|
||||||
|
if ('WebSocket' in window) {
|
||||||
|
if (protoBin = 'binaryType' in WebSocket.prototype) {
|
||||||
|
return protoBin
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return !!(new WebSocket(protocol + '://.').binaryType)
|
||||||
|
} catch (e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
|
// addTest('pointerevents', function () {
|
||||||
|
// var bool = false
|
||||||
|
// var i = domPrefixes.length
|
||||||
|
// bool = hasEvent('pointerdown')
|
||||||
|
// while (i-- && !bool) {
|
||||||
|
// if (hasEvent(domPrefixes[i] + 'pointerdown')) {
|
||||||
|
// bool = true
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return bool
|
||||||
|
// })
|
||||||
|
|
||||||
|
addTest('devicemotion', 'DeviceMotionEvent' in window)
|
||||||
|
|
||||||
|
addTest('deviceorientation', 'DeviceOrientationEvent' in window)
|
||||||
|
|
||||||
|
return service
|
||||||
|
}
|
11
res/app/components/stf/guest-browser/guest-browser-spec.js
Normal file
11
res/app/components/stf/guest-browser/guest-browser-spec.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
describe('GuestBrowser', function() {
|
||||||
|
|
||||||
|
beforeEach(module('stf.guest-browser'));
|
||||||
|
|
||||||
|
it('should ...', inject(function(GuestDeviceService) {
|
||||||
|
|
||||||
|
//expect(GuestDeviceService.doSomething()).toEqual('something');
|
||||||
|
|
||||||
|
}));
|
||||||
|
|
||||||
|
})
|
4
res/app/components/stf/guest-browser/index.js
Normal file
4
res/app/components/stf/guest-browser/index.js
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
module.exports = angular.module('stf.guest-browser', [
|
||||||
|
|
||||||
|
])
|
||||||
|
.factory('GuestBrowser', require('./guest-browser-service'))
|
|
@ -22,7 +22,8 @@ module.exports = angular.module('layout', [
|
||||||
'fa.directive.borderLayout',
|
'fa.directive.borderLayout',
|
||||||
'angular-loading-bar',
|
'angular-loading-bar',
|
||||||
require('stf/common-ui').name,
|
require('stf/common-ui').name,
|
||||||
require('stf/socket/socket-state').name
|
require('stf/socket/socket-state').name,
|
||||||
|
require('stf/guest-browser').name
|
||||||
])
|
])
|
||||||
.config(['$tooltipProvider', function ($tooltipProvider) {
|
.config(['$tooltipProvider', function ($tooltipProvider) {
|
||||||
$tooltipProvider.options({
|
$tooltipProvider.options({
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module.exports = function LayoutCtrl(FatalMessageService) {
|
module.exports = function LayoutCtrl(FatalMessageService, GuestBrowser, $scope) {
|
||||||
|
$scope.guestBrowser = GuestBrowser
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ html
|
||||||
div(ng-include='"menu.jade"')
|
div(ng-include='"menu.jade"')
|
||||||
socket-state
|
socket-state
|
||||||
div(growl)
|
div(growl)
|
||||||
|
|
||||||
div(pane, pane-anchor='center').fill-height
|
div(pane, pane-anchor='center').fill-height
|
||||||
div(ng-view).fill-height
|
div(ng-view).fill-height
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue