diff --git a/res/app/components/stf/basic-mode/index.js b/res/app/components/stf/basic-mode/index.js index d46d5e13..160f6040 100644 --- a/res/app/components/stf/basic-mode/index.js +++ b/res/app/components/stf/basic-mode/index.js @@ -1,6 +1,5 @@ require('./basic-mode.css') module.exports = angular.module('stf.basic-mode', [ - ]) .directive('basicMode', require('./basic-mode-directive')) diff --git a/res/app/components/stf/landscape/index.js b/res/app/components/stf/landscape/index.js new file mode 100644 index 00000000..6420d66c --- /dev/null +++ b/res/app/components/stf/landscape/index.js @@ -0,0 +1,4 @@ +module.exports = angular.module('stf.landscape', [ + require('stf/browser-info').name +]) + .directive('landscape', require('./landscape-directive')) diff --git a/res/app/components/stf/landscape/landscape-directive.js b/res/app/components/stf/landscape/landscape-directive.js new file mode 100644 index 00000000..ae9090eb --- /dev/null +++ b/res/app/components/stf/landscape/landscape-directive.js @@ -0,0 +1,52 @@ +module.exports = function landscapeDirective(BrowserInfo, $document, $window, $rootScope) { + return { + restrict: 'A', + link: function (scope, element, attrs) { + console.log($window.orientation) + + if (typeof $window.orientation !== 'undefined') { + if ($window.orientation === 0) { + rotateHostAndGuest(true) + } else { + rotateHostAndGuest(false) + } + } + + function rotateHostAndGuest(portrait) { + //console.log(scope.control) + if (portrait) { + if (scope.control) { + scope.control.rotate(0) + } + angular.element($document[0].body).addClass('guest-portrait') + angular.element($document[0].body).removeClass('guest-landscape') + } else { + if (scope.control) { + scope.control.rotate(90) + } + angular.element($document[0].body).addClass('guest-landscape') + angular.element($document[0].body).removeClass('guest-portrait') + } + } + + function guestDisplayRotatated(eventData) { + var isPortrait = (window.innerHeight > window.innerWidth) + rotateHostAndGuest(isPortrait) + } + + if (BrowserInfo.deviceorientation) { + window.addEventListener('orientationchange', guestDisplayRotatated, true) + } + + function off() { + if (BrowserInfo.deviceorientation) { + window.removeEventListener('orientationchange', guestDisplayRotatated) + } + } + + scope.$on('$destroy', off) + + + } + } +} diff --git a/res/app/components/stf/landscape/landscape-spec.js b/res/app/components/stf/landscape/landscape-spec.js new file mode 100644 index 00000000..95f16600 --- /dev/null +++ b/res/app/components/stf/landscape/landscape-spec.js @@ -0,0 +1,23 @@ +describe('landscape', function () { + + beforeEach(module('stf.landscape')); + + var scope, compile; + + beforeEach(inject(function ($rootScope, $compile) { + scope = $rootScope.$new(); + compile = $compile; + })); + + it('should ...', function () { + + /* + To test your directive, you need to create some html that would use your directive, + send that through compile() then compare the results. + + var element = compile('