'use strict';

angular.module('theLawFactory')
.directive('readMode', ['$location', function($location) {
    return {
        restrict: 'A',
        controller: function($scope) {
            $scope.read = $location.search()['read'] === '1';

            $scope.readmode = function () {
                $("#sidebar").addClass('readmode');
                if ($scope.mod === 'amendements') {
                    $location.replace();
                    $location.search('read', '1');
                }
                $scope.read = true;
            };

            $scope.viewmode = function () {
                $("#sidebar").removeClass('readmode');
                if ($scope.mod === 'amendements') {
                    $location.replace();
                    $location.search('read', null);
                }
                $scope.read = false;
            };

            if ($scope.read) {
                $scope.readmode();
            }
        }
    }
}]);

'use strict';

angular.module('theLawFactory')
.directive('readMode', ['$location', function($location) {
    return {
        restrict: 'A',
        controller: function($rootScope, $scope) {
            $rootScope.read = $location.search()['read'] === '1';

            $rootScope.readmode = function () {
                $("#sidebar").addClass('readmode');
                if ($scope.mod === 'amendements') {
                    $location.replace();
                    $location.search('read', '1');
                }
                $rootScope.read = true;
            };

            $rootScope.viewmode = function () {
                $("#sidebar").removeClass('readmode');
                if ($scope.mod === 'amendements') {
                    $location.replace();
                    $location.search('read', null);
                }
                $rootScope.read = false;
            };

            if ($rootScope.read) {
                $rootScope.readmode();
            }
        }
    }
}]);

Move readmode to root scope
Move readmode to root scope

Prevents incorrect angular scope inheritance behaviour (calling $scope.readmode()
would set the "read" variable on the calling scope, not in the readMode controller
scope).
