[Mobile] Add classes to body

Add classes describing device characteristics to the
body of the current document at start-up. Refactor
device matchers out of the mct-device directive for
reuse and consistency here.

https://github.com/nasa/openmctweb/issues/169
This commit is contained in:
Victor Woeltjen
2015-12-29 11:57:48 -08:00
parent 9c4c020f54
commit d397f0f283
3 changed files with 118 additions and 24 deletions

View File

@ -22,31 +22,10 @@
/*global define,Promise*/
define(
function () {
['./DeviceMatchers'],
function (DeviceMatchers) {
'use strict';
var DEVICE_MATCHERS = {
mobile: function (agentService) {
return agentService.isMobile();
},
phone: function (agentService) {
return agentService.isPhone();
},
tablet: function (agentService) {
return agentService.isTablet();
},
desktop: function (agentService) {
return !agentService.isMobile();
},
portrait: function (agentService) {
return agentService.isPortrait();
},
landscape: function (agentService) {
return agentService.isLandscape();
}
};
/**
* The `mct-device` directive, when applied as an attribute,
* only includes the element when the device being used matches
@ -77,7 +56,7 @@ define(
function deviceMatches(tokens) {
tokens = tokens || "";
return tokens.split(" ").every(function (token) {
var fn = DEVICE_MATCHERS[token];
var fn = DeviceMatchers[token];
return fn && fn(agentService);
});
}