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

Commit

Permalink
feat(source-snippets): add source-snippets service to toggle visibili…
Browse files Browse the repository at this point in the history
…ty of javascript and typescript examples
  • Loading branch information
Philipp Burgmer committed Jul 28, 2015
1 parent c8b098d commit 65e46dc
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/slides/slides.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ angular.module('w11k.slides').directive('w11kSlideMaster', ['slidesConfig', func
}]);

angular.module('w11k.slides').directive('w11kSlides', [
'$location', '$window', '$document', 'SlidesService', '$rootScope', 'slidesConfig',
function ($location, $window, $document, SlidesService, $rootScope, slidesConfig) {
'$location', '$window', '$document', 'SlidesService', '$rootScope', 'slidesConfig', '$injector',
function ($location, $window, $document, SlidesService, $rootScope, slidesConfig, $injector) {
return {
restrict: 'EA',
templateUrl: slidesConfig.directiveTemplateUrl || 'slides/slides.tpl.html',
Expand Down Expand Up @@ -272,6 +272,11 @@ angular.module('w11k.slides').directive('w11kSlides', [
}
});
}

var customShortcut = slidesConfig.shortcuts[event.keyCode];
if (angular.isFunction(customShortcut) || angular.isArray(customShortcut)) {
$injector.invoke(customShortcut, {$event: event});
}
});
}
};
Expand Down
55 changes: 55 additions & 0 deletions src/source-snippets/source-snippets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict';

angular.module('w11k.slides').config(function (slidesConfig) {
slidesConfig.shortcuts = slidesConfig.shortcuts || {};

slidesConfig.shortcuts['76'] = ['SourceSnippets', function (SourceSnippets) {
SourceSnippets.toggle();
}];
});

angular.module('w11k.slides').run(function (SourceSnippets) {
// just for eager creation
SourceSnippets.init();
});

angular.module('w11k.slides').service('SourceSnippets', function ($rootScope) {
var states = {
'jsOnly': {
js: true,
ts: false,
next: 'tsOnly'
},
'tsOnly': {
js: false,
ts: true,
next: 'jsAndTs'
},
'jsAndTs': {
js: true,
ts: true,
next: 'jsOnly'
}
};

var currentState = states.jsOnly;

$rootScope.$on('src-js-current', function (event, callback) {
callback(currentState.js);
});

$rootScope.$on('src-ts-current', function (event, callback) {
callback(currentState.ts);
});

this.toggle = function () {
currentState = states[currentState.next];

$rootScope.$broadcast('src-js', currentState.js);
$rootScope.$broadcast('src-ts', currentState.ts);
};

this.init = function () {
// nothing to do here at the moment
};
});
24 changes: 18 additions & 6 deletions test/slides/usage.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@
</body>
</pre>

<pre w11k-pretty-print lang="js">
angular.module("demo").constant('slidesConfig', {
slides: [
<pre w11k-pretty-print lang="js" w11k-event-toggle="src-js">
angular.module("demo").run(function (slidesConfig) {
slidesConfig.slides: [
'title',
'about',
'end'
],
slideTemplatePrefix: 'slides/',
slideTemplateSuffix: '.tpl.html'
];
slidesConfig.slideTemplatePrefix: 'slides/',
slidesConfig.slideTemplateSuffix: '.tpl.html'
});
</pre>

<pre w11k-pretty-print lang="typescript" w11k-event-toggle="src-ts">
angular.module("demo").run(function (slidesConfig :any) {
slidesConfig.slides: [
'title',
'about',
'end'
];
slidesConfig.slideTemplatePrefix: 'slides/',
slidesConfig.slideTemplateSuffix: '.tpl.html'
});
</pre>
</div>
Expand Down

0 comments on commit 65e46dc

Please sign in to comment.