From e7bf5952d0729b37e677168b6e8fbd1ce58ed1a2 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 10 Aug 2014 17:28:37 +0200 Subject: First version --- point/control/control.js | 83 +++++++++++++++++++++++++++++++++++++++++++ point/control/fullscreen.js | 68 +++++++++++++++++++++++++++++++++++ point/control/layout.js | 61 ++++++++++++++++++++++++++++++++ point/control/network.js | 58 ++++++++++++++++++++++++++++++ point/control/slide.js | 86 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 356 insertions(+) create mode 100644 point/control/control.js create mode 100644 point/control/fullscreen.js create mode 100644 point/control/layout.js create mode 100644 point/control/network.js create mode 100644 point/control/slide.js (limited to 'point/control') diff --git a/point/control/control.js b/point/control/control.js new file mode 100644 index 0000000..4ec21da --- /dev/null +++ b/point/control/control.js @@ -0,0 +1,83 @@ +/* + * This file is part of "What's The Point" + * Copyright (C) 2014 Pacien TRAN-GIRARD + * + * "What's The Point" is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * "What's The Point" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +define(function () { + + var control = { + + MODE: { + MASTER: "master", + SLAVE: "slave", + FREE: "free", + }, + + EVENT: { + GOTO: "goTo", + SLIDE: "slide", + SHOW: "show", + TOGGLE: "toggle", + TRIGGER: "trigger", + }, + + SLIDE: { + + }, + + GOTO: { + PREVIOUS_SLIDE: "previousSlide", + NEXT_SLIDE: "nextSlide", + FIRST_SLIDE: "firstSlide", + LAST_SLIDE: "lastSlide", + }, + + SHOW: { + SLIDES: "slides", + NOTES: "notes", + }, + + TOGGLE: { + FULLSCREEN: "fullscreen", + }, + + TRIGGER: { + + }, + + init: function () { + return; + }, + + dispatchEvent: function (eventType, eventDetail, forward) { + return document.dispatchEvent(new CustomEvent(eventType, { + "detail": { + "detail": eventDetail, + "forward": forward !== undefined ? forward : true, + }, + })); + }, + + bindEvent: function (eventType, eventListener) { + document.addEventListener(eventType, function (event) { + eventListener(event.detail); + }); + }, + }; + + return control; + +}); diff --git a/point/control/fullscreen.js b/point/control/fullscreen.js new file mode 100644 index 0000000..6e53bc4 --- /dev/null +++ b/point/control/fullscreen.js @@ -0,0 +1,68 @@ +/* + * This file is part of "What's The Point" + * Copyright (C) 2014 Pacien TRAN-GIRARD + * + * "What's The Point" is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * "What's The Point" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +define(["control/control"], function (control) { + + var fullscreen = { + + init: function () { + this.bindEvent(); + }, + + toggleFullscreen: function () { + // from + // https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode#Toggling_fullscreenController_mode + if (!document.fullscreenControllerElement && // alternative + // standard method + !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {// current + // working + // methods + if (document.documentElement.requestFullscreen) { + document.documentElement.requestFullscreen(); + } else if (document.documentElement.msRequestFullscreen) { + document.documentElement.msRequestFullscreen(); + } else if (document.documentElement.mozRequestFullScreen) { + document.documentElement.mozRequestFullScreen(); + } else if (document.documentElement.webkitRequestFullscreen) { + document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); + } + } else { + if (document.exitFullscreen) { + document.exitFullscreen(); + } else if (document.msExitFullscreen) { + document.msExitFullscreen(); + } else if (document.mozCancelFullScreen) { + document.mozCancelFullScreen(); + } else if (document.webkitExitFullscreen) { + document.webkitExitFullscreen(); + } + } + }, + + bindEvent: function () { + control.bindEvent(control.EVENT.TOGGLE, function (toggleEvent) { + if (toggleEvent.detail === control.TOGGLE.FULLSCREEN) { + fullscreen.toggleFullscreen(); + } + }); + }, + }; + + return fullscreen; + +}); diff --git a/point/control/layout.js b/point/control/layout.js new file mode 100644 index 0000000..84a55ff --- /dev/null +++ b/point/control/layout.js @@ -0,0 +1,61 @@ +/* + * This file is part of "What's The Point" + * Copyright (C) 2014 Pacien TRAN-GIRARD + * + * "What's The Point" is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * "What's The Point" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +define(["control/control"], function (control) { + + var layout = { + + init: function () { + this.screen = document.getElementsByTagName("p-screen")[0]; + this.bindEvent(); + }, + + CLASS: { + SLIDES: "slides", + NODES: "notes", + }, + + reset: function () { + for (var className in this.CLASS) { + this.screen.classList.remove(this.CLASS[className]); + } + }, + + show: function (element) { + this.reset(); + switch (element) { + case control.SHOW.SLIDES: + this.screen.classList.add("slides"); + break; + + case control.SHOW.NOTES: + this.screen.classList.add("notes"); + break; + } + }, + + bindEvent: function () { + control.bindEvent(control.EVENT.SHOW, function (showEvent) { + layout.show(showEvent.detail); + }); + }, + }; + + return layout; + +}); diff --git a/point/control/network.js b/point/control/network.js new file mode 100644 index 0000000..e782257 --- /dev/null +++ b/point/control/network.js @@ -0,0 +1,58 @@ +/* + * This file is part of "What's The Point" + * Copyright (C) 2014 Pacien TRAN-GIRARD + * + * "What's The Point" is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * "What's The Point" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +define([ "control/control", "libs/webcastor/webcastor", "control/slide" ], function (control, webcastor, slide) { + + var network = { + + init: function (settings) { + webcastor.init(settings, function () { + network.bindEvents(); + }); + }, + + send: function (event, eventDetail) { + var message = JSON.stringify({ + "event": event, + "eventDetail": eventDetail, + }); + webcastor.send(message); + }, + + bindEvent: function (event) { + control.bindEvent(event, function (eventDetail) { + if (!eventDetail.forward) { + return false; + } + network.send(event, eventDetail.detail); + }); + }, + + /* local -> network */ + bindEvents: function () { + var events = [ control.EVENT.SLIDE, control.EVENT.TRIGGER ]; + for (var i = 0; i < events.length; i++) { + this.bindEvent(events[i]); + } + }, + + }; + + return network; + +}); diff --git a/point/control/slide.js b/point/control/slide.js new file mode 100644 index 0000000..c539a60 --- /dev/null +++ b/point/control/slide.js @@ -0,0 +1,86 @@ +/* + * This file is part of "What's The Point" + * Copyright (C) 2014 Pacien TRAN-GIRARD + * + * "What's The Point" is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * "What's The Point" is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +define(["control/control"], function (control) { + + var slide = { + + init: function () { + this.slideCount = document.getElementsByTagName("p-slide").length; + this.start(); + this.bindEvent(); + }, + + start: function () { + var slideIndex = location.hash.substr(1); + location.hash = 0; + location.hash = 1; + this.setCurrentSlide(slideIndex); + }, + + setCurrentSlide: function (slideIndex) { + if (isNaN(slideIndex) || slideIndex < 1 || slideIndex > this.slideCount) { + return false; + } + location.hash = slideIndex; + return true; + }, + + getCurrentSlideIndex: function () { + var hash = location.hash.substring(1); + return isNaN(hash) || hash < 1 || hash > this.slideCount ? 0 : Number(hash); + }, + + shift: function (delta) { + return this.getCurrentSlideIndex() + delta; + }, + + getIndex: function (target) { + switch (target) { + case control.GOTO.PREVIOUS_SLIDE: + return this.shift(-1); + + case control.GOTO.NEXT_SLIDE: + return this.shift(+1); + + case control.GOTO.FIRST_SLIDE: + return 1; + + case control.GOTO.LAST_SLIDE: + return this.slideCount; + } + }, + + translate: function (target) { + control.dispatchEvent(control.EVENT.SLIDE, this.getIndex(target)); + }, + + bindEvent: function () { + control.bindEvent(control.EVENT.GOTO, function (gotoEvent) { + slide.translate(gotoEvent.detail); + }); + + control.bindEvent(control.EVENT.SLIDE, function (slideEvent) { + slide.setCurrentSlide(slideEvent.detail); + }); + }, + }; + + return slide; + +}); -- cgit v1.2.3