--- /dev/null
+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