Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

Commit

Permalink
feat(mode): expose set and toggle mode (screen and export) via Slides…
Browse files Browse the repository at this point in the history
…Service
  • Loading branch information
Philipp Burgmer committed Nov 25, 2015
1 parent b5d502c commit c49fde8
Showing 1 changed file with 45 additions and 26 deletions.
71 changes: 45 additions & 26 deletions src/slides/slides.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';

/* @ngInject */
function SlidesService(slidesConfig, $location, $rootScope) {
function SlidesService(slidesConfig, $location, $rootScope, $window) {
var activeSlide;

function activateFirstSlide() {
Expand Down Expand Up @@ -30,6 +30,9 @@
}
});

var localStorageModeKey = 'w11k-slides.mode';
var mode = 'export';

function mapSlidesConfig() {
var prefix = slidesConfig.slideTemplatePrefix || 'slides/content/';
var suffix = slidesConfig.slideTemplateSuffix || '.html';
Expand Down Expand Up @@ -116,6 +119,37 @@
this.navigateTo(previous.name);
}
}.bind(this);

this.getMode = function () {
return mode;
}.bind(this);

this.setMode = function (newMode) {
mode = newMode;

if (angular.isDefined($window.localStorage)) {
$window.localStorage[localStorageModeKey] = mode;
}

$rootScope.$emit(this.events.modeChanged, mode);
}.bind(this);

this.toggleMode = function () {
var newMode;

if (mode === 'export') {
newMode = 'screen';
}
else if (mode === 'screen') {
newMode = 'export';
}

this.setMode(newMode);
}.bind(this);

this.events = {
modeChanged: 'w11k-slides.modeChanged'
};
}

/* @ngInject */
Expand Down Expand Up @@ -183,32 +217,14 @@
}

/* @ngInject */
function w11kSlidesDirective($window, $document, SlidesService, slidesConfig, $injector) {
function w11kSlidesDirective($window, $document, SlidesService, slidesConfig, $injector, $rootScope) {
return {
restrict: 'EA',
templateUrl: slidesConfig.directiveTemplateUrl || 'slides/slides.html',
replace: true,
link: function (scope, jqElement) {
var element = jqElement[0];

var localStorageModeKey = 'w11k-slides.mode';
var mode = 'export';

function toggleMode() {
if (mode === 'export') {
mode = 'screen';
}
else if (mode === 'screen') {
mode = 'export';
}

setMode(mode);

if (angular.isDefined($window.localStorage)) {
$window.localStorage[localStorageModeKey] = mode;
}
}

function setMode(mode) {
if (mode === 'export') {
element.classList.remove('screen');
Expand All @@ -220,6 +236,10 @@
}
}

function toggleMode() {
SlidesService.toggleMode();
}

function toggleOverlay() {
element.querySelector('div.overlay').classList.toggle('active');
}
Expand Down Expand Up @@ -272,12 +292,11 @@
}
}

if (angular.isDefined($window.localStorage)) {
if (angular.isDefined($window.localStorage[localStorageModeKey])) {
mode = $window.localStorage[localStorageModeKey];
setMode(mode);
}
}
setMode(SlidesService.getMode());

$rootScope.$on(SlidesService.events.modeChanged, function (event, mode) {
setMode(mode);
});

$document.bind('keydown', function (event) {

Expand Down

0 comments on commit c49fde8

Please sign in to comment.