From 7b6f6b89bacdc907e1e18efbb9212b6f84cb71c5 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 8 Apr 2020 18:30:14 +0200 Subject: [PATCH] wip #3577 @2.5 --- js/libs/fluidbook/fluidbook.js | 1 + js/libs/fluidbook/fluidbook.widget.js | 69 +++++++++++++++++++++++++++ style/fluidbook.less | 3 +- style/widget.less | 5 ++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 js/libs/fluidbook/fluidbook.widget.js create mode 100644 style/widget.less diff --git a/js/libs/fluidbook/fluidbook.js b/js/libs/fluidbook/fluidbook.js index 47b7e927..d62a9c80 100644 --- a/js/libs/fluidbook/fluidbook.js +++ b/js/libs/fluidbook/fluidbook.js @@ -89,6 +89,7 @@ Fluidbook.prototype = { if (typeof window.FluidbookTabs === 'function') { this.tabs = new FluidbookTabs(this); } + this.widget = new FluidbookWidget(this); this.refw = 0; this.refh = 0; diff --git a/js/libs/fluidbook/fluidbook.widget.js b/js/libs/fluidbook/fluidbook.widget.js new file mode 100644 index 00000000..cd09fbb9 --- /dev/null +++ b/js/libs/fluidbook/fluidbook.widget.js @@ -0,0 +1,69 @@ +function FluidbookWidget(fluidbook) { + this.fluidbook = fluidbook; + this.featureEnabled = true; + this.enabled = false; + + this.init(); +} + +FluidbookWidget.prototype = { + init: function () { + if ($_GET['widget'] != '1') { + return; + } + this.action = $_GET.hasOwnProperty('action') ? $_GET['action'] : 'fullscreen'; + this.enabled = true; + var $this = this; + $(this.fluidbook).on('fluidbook.resize', function () { + $this.update(); + }); + + $("#fluidbook").on('click', function () { + return $this.click(); + }); + this.update(true); + }, + + click: function () { + var active = this.isWidgetModeActive(); + if (active) { + if (this.action === 'fullscreen') { + screenfull.toggle(); + } else if (this.action === 'popup') { + top.window.open(window.location); + } + } + return !active; + }, + + update: function (force) { + var newMode = this.isWidgetModeActive(); + if (force !== true && newMode === this.enabled) { + return; + } + this.enabled = newMode; + if (this.enabled) { + this.enable(); + } else { + this.disable(); + } + }, + + enable: function () { + console.log('enable widget mode'); + $("body").addClass('widget'); + if ($_GET['background'] !== undefined) { + $("#background,#splash").attr('style', 'background-color: ' + $_GET['background'] + ' !important;background-image:none !important'); + } + }, + + disable: function () { + console.log('disable widget mode'); + $("body").removeClass('widget'); + $("#background,#splash").attr('style', ''); + }, + + isWidgetModeActive: function () { + return this.featureEnabled && !screenfull.isFullscreen; + } +} \ No newline at end of file diff --git a/style/fluidbook.less b/style/fluidbook.less index 8d49bfa8..edaa642c 100644 --- a/style/fluidbook.less +++ b/style/fluidbook.less @@ -2861,4 +2861,5 @@ body > input { } @import "mobilefirst.less"; -@import "tabs.less"; \ No newline at end of file +@import "tabs.less"; +@import "widget.less"; \ No newline at end of file diff --git a/style/widget.less b/style/widget.less new file mode 100644 index 00000000..0b78a8c0 --- /dev/null +++ b/style/widget.less @@ -0,0 +1,5 @@ +body.widget { + footer#credits { + display: none; + } +} \ No newline at end of file -- 2.39.5