From 87de38ae1de72799e4fd336a0487d33eed6ecf3f Mon Sep 17 00:00:00 2001 From: kashomon Date: Sun, 30 Nov 2014 19:41:15 -0700 Subject: [PATCH] Fix preventDefault behavior (maybe). Add escape to game info window. --- src/depgen.py | 1 + src/displays/statusbar/statusbar.js | 24 +++- src/htmltests/TextOnlyTester.html | 178 ++++++++++++++++++++++++++++ src/parse/tygem_test.js | 4 +- src/util/enums.js | 2 +- src/util/key_mappings.js | 16 ++- src/widgets/base_widget.js | 19 ++- src/widgets/manager.js | 5 + src/widgets/options/base_options.js | 10 +- 9 files changed, 244 insertions(+), 15 deletions(-) create mode 100644 src/htmltests/TextOnlyTester.html diff --git a/src/depgen.py b/src/depgen.py index c9728f44..aebd6020 100755 --- a/src/depgen.py +++ b/src/depgen.py @@ -28,6 +28,7 @@ 'htmltests/PositionTester.html': False, 'htmltests/ProblemTester.html': False, 'htmltests/QunitTest.html': True, + 'htmltests/TextOnlyTester.html': False, 'htmltests/ThemeTester.html': False, 'htmltests/TygemGameTester.html': False, } diff --git a/src/displays/statusbar/statusbar.js b/src/displays/statusbar/statusbar.js index e86c92d2..139695b6 100644 --- a/src/displays/statusbar/statusbar.js +++ b/src/displays/statusbar/statusbar.js @@ -81,12 +81,25 @@ glift.displays.statusbar._StatusBar.prototype = { }, gameInfoTheme.textDiv); textDiv.css(textDivCss); + + var exitScreen = function() { + newDiv.remove(); + }; if (glift.platform.isMobile()) { - textDiv.on('touchend', function() { newDiv.remove(); }); + textDiv.on('touchend', exitScreen); } else { - textDiv.on('click', function() { newDiv.remove(); }); + textDiv.on('click', exitScreen); } + var instanceId = this.widget.manager.id; + var oldEscAction = glift.keyMappings.getFuncOrIcon(instanceId, 'ESCAPE'); + glift.keyMappings.registerKeyAction(instanceId, 'ESCAPE', function() { + exitScreen(); + if (oldEscAction) { + glift.keyMappings.registerKeyAction(instanceId, 'ESCAPE', oldEscAction); + } + }); + // This is a hack until a better solution for captures can be crafted. var captureArr = [ {displayName: 'Captured White Stones', value: captureCount.WHITE}, @@ -117,6 +130,7 @@ glift.displays.statusbar._StatusBar.prototype = { * Note: Key bindings are set in the base_widget. */ fullscreen: function() { + // TODO(kashomon): Support true fullscreen: issues/69 var widget = this.widget, wrapperDivId = widget.wrapperDivId, newDivId = wrapperDivId + '_fullscreen', @@ -135,8 +149,6 @@ glift.displays.statusbar._StatusBar.prototype = { }, this.theme.statusBar.fullscreen); newDiv.css(cssObj); - // TODO(kashomon): Support true fullscreen: issues/69 - // Prevent scrolling outside the div body.addClass('glift-fullscreen-no-scroll').append(newDiv); manager.prevScrollTop = @@ -154,8 +166,8 @@ glift.displays.statusbar._StatusBar.prototype = { /** Returns Glift to non-fullscreen */ unfullscreen: function() { - if (!this.widget.manager.fullscreenDivId) { - return; // We're not fullscreened + if (!this.widget.manager.isFullscreen()) { + return; } var widget = this.widget, wrapperDivEl = glift.dom.elem(widget.wrapperDivId), diff --git a/src/htmltests/TextOnlyTester.html b/src/htmltests/TextOnlyTester.html new file mode 100644 index 00000000..4e0c7bec --- /dev/null +++ b/src/htmltests/TextOnlyTester.html @@ -0,0 +1,178 @@ + + + + + Text Only Tester + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ +
+ + diff --git a/src/parse/tygem_test.js b/src/parse/tygem_test.js index 541bc7fc..34ccaaab 100644 --- a/src/parse/tygem_test.js +++ b/src/parse/tygem_test.js @@ -13,8 +13,8 @@ glift.parse.tygemTest = function() { deepEqual(mt.properties().getOneValue('PB'), 'go48 (2K)'); mt.moveDown(); - deepEqual(mt.properties().getAsPoint('B'), point(15, 3)); + deepEqual(mt.properties().getAsPoint('B').toString(), point(15, 15).toString()); mt.moveDown(); - deepEqual(mt.properties().getAsPoint('W'), point(3, 16)); + deepEqual(mt.properties().getAsPoint('W').toString(), point(3, 2).toString()); }); }; diff --git a/src/util/enums.js b/src/util/enums.js index c9f0e6b8..1914ce3c 100644 --- a/src/util/enums.js +++ b/src/util/enums.js @@ -142,7 +142,7 @@ glift.enums = { GAME_VIEWER: 'GAME_VIEWER', REDUCED_GAME_VIEWER: 'REDUCED_GAME_VIEWER', STANDARD_PROBLEM: 'STANDARD_PROBLEM', - BOARD_EDITOR: 'BOARD_EDITOR' + BOARD_EDITOR: 'BOARD_EDITOR', }, boardComponents: { diff --git a/src/util/key_mappings.js b/src/util/key_mappings.js index ee74655a..baf03415 100644 --- a/src/util/key_mappings.js +++ b/src/util/key_mappings.js @@ -148,8 +148,12 @@ glift.keyMappings = { if (argType === 'function') { funcOrIcon(widget); - if (event.preventDefault) event.preventDefault(); - else event.returnValue = false; // IE + if (manager.isFullscreen()) { + // We don't want the widget interacting with anything else while + // full-screen. + if (event.preventDefault) event.preventDefault(); + else event.returnValue = false; // IE + } } else if (argType === 'string') { // Assume it's an icon-action-path // icon namespaces look like: icons.arrowleft.mouseup @@ -159,8 +163,12 @@ glift.keyMappings = { action = action[actionNamespace[i]]; } action(keyEvent, widget); - if (event.preventDefault) event.preventDefault(); - else event.returnValue = false; // IE + if (manager.isFullscreen()) { + // We don't want the widget interacting with anything else while + // full-screen. + if (event.preventDefault) event.preventDefault(); + else event.returnValue = false; // IE + } } } }; diff --git a/src/widgets/base_widget.js b/src/widgets/base_widget.js index f5364772..1ff7279a 100644 --- a/src/widgets/base_widget.js +++ b/src/widgets/base_widget.js @@ -61,7 +61,7 @@ glift.widgets.BaseWidget.prototype = { parentDivBbox, this.displayOptions.boardRegion, this.displayOptions.intersections, - this.sgfOptions.uiComponents, + this._getUiComponents(this.sgfOptions), this.displayOptions.oneColumnSplits, this.displayOptions.twoColumnSplits).calcWidgetPositioning(); @@ -143,6 +143,23 @@ glift.widgets.BaseWidget.prototype = { return this; }, + /** Gets the UI icons to use */ + _getUiComponents: function(sgfOptions) { + var base = sgfOptions.uiComponents; + base = base.slice(0, base.length); // make a shallow copy. + var rmItem = function(arr, key) { + var idx = arr.indexOf(key); + if (idx > -1) { + arr.shift(idx); + } + } + sgfOptions.disableStatusBar && rmItem(base, 'STATUS_BAR'); + sgfOptions.disableBoard && rmItem(base, 'BOARD'); + sgfOptions.disableCommentBox && rmItem(base, 'COMMENT_BOX'); + sgfOptions.disableIonBar && rmItem(base, 'ICONBAR'); + return base; + }, + /** * Create divs from positioning (WidgetBoxes) and the wrapper div id. */ diff --git a/src/widgets/manager.js b/src/widgets/manager.js index ff79ad5d..2868abdc 100644 --- a/src/widgets/manager.js +++ b/src/widgets/manager.js @@ -320,6 +320,11 @@ glift.widgets.WidgetManager.prototype = { loader(this.sgfColIndex + 1); }, + /** Whether or not the widget is currently fullscreened. */ + isFullscreen: function() { + return !!this.fullscreenDivId; + }, + /** Enable auto-resizing of the glift instance. */ enableFullscreenAutoResize: function() { if (window.onresize) { this.oldWindowResize = window.onresize; } diff --git a/src/widgets/options/base_options.js b/src/widgets/options/base_options.js index e53f3f0a..516e3be9 100644 --- a/src/widgets/options/base_options.js +++ b/src/widgets/options/base_options.js @@ -190,6 +190,15 @@ glift.widgets.options.baseOptions = { 'ICONBAR' ], + /** + * Convenience variables for disabling ui components. + * @api(experimental) + */ + disableStatusBar: false, + disableBoard: false, + disableCommentBox: false, + disableIconBar: false, + /** * Icons to use in the status bar. * @api(1.0) @@ -200,7 +209,6 @@ glift.widgets.options.baseOptions = { 'game-info', 'move-indicator', 'fullscreen' - // TODO(kashomon): Add a settings icon. // 'settings-wrench' ],