Skip to content

Commit

Permalink
rewrite: hide header in iframe + redirect after selecting counter
Browse files Browse the repository at this point in the history
  • Loading branch information
hirviid committed Apr 3, 2023
1 parent 750e94e commit c0f3dba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
27 changes: 16 additions & 11 deletions app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ angular
url: '/',
requiresCounter: true,
redirectOnScan: true,
force: true,
views: {
content: {
templateUrl: 'views/passholder/search/content-search.html',
Expand Down Expand Up @@ -167,22 +168,26 @@ angular
return;
}

// Block the state change and emit the new path to the parent window for further handling.
event.preventDefault();
window.parent.postMessage({
source: 'BALIE',
type: 'URL_CHANGED',
payload: {
path: to
}
}, '*');
if (runningInIframe && !toState.force) {
// Block the state change and emit the new path to the parent window for further handling.
event.preventDefault();
window.parent.postMessage({
source: 'BALIE',
type: 'URL_CHANGED',
payload: {
path: to
}
}, '*');
}
});

function activeCounterListener() {
window.addEventListener('message', function(event) {
if (event.data.source === 'BALIE' && event.data.type === 'SET_COUNTER') {
var counterId = event.data.payload.counter.id;
counterService.setActiveByActorId(counterId);
var counterId = event.data.payload.counter.id;
counterService.setActiveByActorId(counterId).then(function() {
$state.go('counter.main');
});
}
});

Expand Down
2 changes: 1 addition & 1 deletion app/scripts/counter/counter.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function counterService($q, $http, $rootScope, $cookies, uitid, appConfig, momen
};

service.setActiveByActorId = function (actorId) {
service.getList().then(() => {
return service.getList().then(() => {
var counterFound = null;
angular.forEach(service.list, function(counter) {
if (counter.actorId === actorId) {
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/utilities/app.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function appController($rootScope, $location, $state, $stateParams, appConfig, u
app.user = undefined;
app.counter = undefined;
app.buildNumber = appConfig.buildNumber;

app.runningInIframe = window !== window.parent;

function browserEngineIsOlderThan(requiredEngineVersion){
var matches = navigator.userAgent.match(/(.*)\/(.*)$/);
Expand Down
2 changes: 1 addition & 1 deletion app/views/header.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="container">
<nav class="navbar navbar-inverse" ng-init="isCollapsedHeaderNavbar=true">
<nav class="navbar navbar-inverse" ng-init="isCollapsedHeaderNavbar=true" ng-show="!app.runningInIframe">

<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
Expand Down

0 comments on commit c0f3dba

Please sign in to comment.