(function(){ "use strict"; angular.module("raz") .service("lcmStandardsCheckboxService", ["$window", function($window){ var defaultShowStandards = false; var showStandards = null; var subscribers = []; var storageKey = 'lcm-standards-checkbox'; function fromStorage() { var storageVal = $window.sessionStorage.getItem(storageKey); if (storageVal !== null) { return storageVal === 'true'; } return null; } function toStorage() { $window.sessionStorage.setItem(storageKey, showStandards); } function initFromSession() { var storageValue = fromStorage(); if (storageValue !== null) { showStandards = storageValue; } else { showStandards = getDefault(); } } function getDefault() { return defaultShowStandards; } function toggleShowStandards() { showStandards = !showStandards; toStorage(); notifySubscribers(); } function getShowStandards() { return showStandards; } function onUpdate(callback) { subscribers.push(callback); } function notifySubscribers() { for (var i = 0; i < subscribers.length; i++) { subscribers[i](showStandards); } } initFromSession(); return { toggleShowStandards: toggleShowStandards, getShowStandards: getShowStandards, onUpdate: onUpdate }; }]); })();