Skip to content

Commit 38f950e

Browse files
committed
infopanel-updated
1 parent 13e71f0 commit 38f950e

File tree

4 files changed

+78
-58
lines changed

4 files changed

+78
-58
lines changed

build/nodegame-window.js

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* # GameWindow
3-
* Copyright(c) 2020 Stefano Balietti <ste@nodegame.org>
3+
* Copyright(c) 2021 Stefano Balietti <ste@nodegame.org>
44
* MIT Licensed
55
*
66
* API to interface nodeGame with the browser window
@@ -853,17 +853,16 @@
853853
*
854854
* Appends a configurable div element at to "top" of the page
855855
*
856-
* @param {Element} root Optional. The HTML element to which the info
857-
* panel will be appended. Default:
856+
* @param {object} opts Optional. Configuration options: TODO
858857
*
859-
* - above the main frame, or
860-
* - below the header, or
861-
* - inside _documents.body_.
858+
* - toggleBtn
859+
* - toggleBtnLabel
860+
* - toggleBtnRoot:
861+
* - force: destroys current Info Panel
862862
*
863-
* @param {string} frameName Optional. The name of the iframe. Default:
864-
* 'ng_mainframe'
865863
* @param {boolean} force Optional. Will create the frame even if an
866-
* existing one is found. Default: FALSE
864+
* existing one is found. Deprecated, use force flag in options.
865+
* Default: FALSE
867866
*
868867
* @return {InfoPanel} A reference to the InfoPanel object
869868
*
@@ -873,20 +872,32 @@
873872
*/
874873
GameWindow.prototype.generateInfoPanel = function(opts, force) {
875874
var infoPanelDiv, root, btn;
875+
opts = opts || {};
876+
877+
// Backward compatible.
878+
if ('undefined' === typeof force) force = opts.force;
879+
880+
if (force && this.infoPanel) {
881+
this.infoPanel.destroy();
882+
this.infoPanel = null;
883+
}
876884

877885
if (this.infoPanel) {
878-
if (!force) {
879-
throw new Error('GameWindow.generateInfoPanel: info panel is ' +
880-
'already existing. Use force to regenerate.');
881-
}
882-
else {
883-
this.infoPanel.destroy();
884-
this.infoPanel = null;
886+
if (this.infoPanel.toggleBtn) {
887+
if ('undefined' === typeof opts.toggleBtn) {
888+
opts.toggleBtn = false;
889+
}
885890
}
891+
// if (!force) {
892+
// throw new Error('GameWindow.generateInfoPanel: info panel is ' +
893+
// 'already existing. Use force to regenerate.');
894+
// }
895+
896+
}
897+
else {
898+
this.infoPanel = new node.InfoPanel(opts);
886899
}
887-
opts = opts || {};
888900

889-
this.infoPanel = new node.InfoPanel(opts);
890901
infoPanelDiv = this.infoPanel.infoPanelDiv;
891902

892903
root = opts.root;
@@ -907,27 +918,27 @@
907918
document.body.appendChild(infoPanelDiv);
908919
}
909920

910-
// Adds Toggle Button if not
911-
if (opts.btn !== false) {
921+
// Adds Toggle Button if not false.
922+
if (opts.toggleBtn !== false) {
912923
root = null;
913-
if (!opts.btnRoot) {
924+
if (!opts.toggleBtnRoot) {
914925
if (this.headerElement) root = this.headerElement;
915926
}
916927
else {
917-
if ('string' === typeof opts.btnRoot) {
918-
root = W.gid(opts.btnRoot);
928+
if ('string' === typeof opts.toggleBtnRoot) {
929+
root = W.gid(opts.toggleBtnRoot);
919930
}
920931
else {
921-
root = opts.btnRoot;
932+
root = opts.toggleBtnRoot;
922933
}
923934
if (!J.isElement(root)) {
924-
throw new Error('GameWindow.generateInfoPanel: btnRoot ' +
925-
'did not resolve to a valid HTMLElement: ' +
926-
opts.btnRoot);
935+
throw new Error('GameWindow.generateInfoPanel: ' +
936+
'toggleBtnRoot did not resolve to a ' +
937+
'valid HTMLElement: ' + opts.toggleBtnRoot);
927938
}
928939
}
929940
if (root) {
930-
btn = W.infoPanel.createToggleButton(opts.btnLabel);
941+
btn = W.infoPanel.createToggleBtn(opts.toggleBtnLabel);
931942
root.appendChild(btn);
932943
}
933944
}
@@ -3823,6 +3834,7 @@
38233834
* @see InfoPanel.toggleBtn
38243835
* @see InfoPanel.toggle
38253836
*/
3837+
InfoPanel.prototype.createToggleBtn =
38263838
InfoPanel.prototype.createToggleButton = function(label) {
38273839
var that, button;
38283840

build/nodegame-window.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/GameWindow.js

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* # GameWindow
3-
* Copyright(c) 2020 Stefano Balietti <ste@nodegame.org>
3+
* Copyright(c) 2021 Stefano Balietti <ste@nodegame.org>
44
* MIT Licensed
55
*
66
* API to interface nodeGame with the browser window
@@ -853,17 +853,16 @@
853853
*
854854
* Appends a configurable div element at to "top" of the page
855855
*
856-
* @param {Element} root Optional. The HTML element to which the info
857-
* panel will be appended. Default:
856+
* @param {object} opts Optional. Configuration options: TODO
858857
*
859-
* - above the main frame, or
860-
* - below the header, or
861-
* - inside _documents.body_.
858+
* - toggleBtn
859+
* - toggleBtnLabel
860+
* - toggleBtnRoot:
861+
* - force: destroys current Info Panel
862862
*
863-
* @param {string} frameName Optional. The name of the iframe. Default:
864-
* 'ng_mainframe'
865863
* @param {boolean} force Optional. Will create the frame even if an
866-
* existing one is found. Default: FALSE
864+
* existing one is found. Deprecated, use force flag in options.
865+
* Default: FALSE
867866
*
868867
* @return {InfoPanel} A reference to the InfoPanel object
869868
*
@@ -873,20 +872,28 @@
873872
*/
874873
GameWindow.prototype.generateInfoPanel = function(opts, force) {
875874
var infoPanelDiv, root, btn;
875+
opts = opts || {};
876+
877+
// Backward compatible.
878+
if ('undefined' === typeof force) force = opts.force;
879+
880+
if (force && this.infoPanel) {
881+
this.infoPanel.destroy();
882+
this.infoPanel = null;
883+
}
876884

877885
if (this.infoPanel) {
878-
if (!force) {
879-
throw new Error('GameWindow.generateInfoPanel: info panel is ' +
880-
'already existing. Use force to regenerate.');
881-
}
882-
else {
883-
this.infoPanel.destroy();
884-
this.infoPanel = null;
886+
if (this.infoPanel.toggleBtn) {
887+
if ('undefined' === typeof opts.toggleBtn) {
888+
opts.toggleBtn = false;
889+
}
885890
}
891+
node.warn('W.generateInfoPanel: Info Panel already existing.')
892+
}
893+
else {
894+
this.infoPanel = new node.InfoPanel(opts);
886895
}
887-
opts = opts || {};
888896

889-
this.infoPanel = new node.InfoPanel(opts);
890897
infoPanelDiv = this.infoPanel.infoPanelDiv;
891898

892899
root = opts.root;
@@ -907,27 +914,27 @@
907914
document.body.appendChild(infoPanelDiv);
908915
}
909916

910-
// Adds Toggle Button if not
911-
if (opts.btn !== false) {
917+
// Adds Toggle Button if not false.
918+
if (opts.toggleBtn !== false) {
912919
root = null;
913-
if (!opts.btnRoot) {
920+
if (!opts.toggleBtnRoot) {
914921
if (this.headerElement) root = this.headerElement;
915922
}
916923
else {
917-
if ('string' === typeof opts.btnRoot) {
918-
root = W.gid(opts.btnRoot);
924+
if ('string' === typeof opts.toggleBtnRoot) {
925+
root = W.gid(opts.toggleBtnRoot);
919926
}
920927
else {
921-
root = opts.btnRoot;
928+
root = opts.toggleBtnRoot;
922929
}
923930
if (!J.isElement(root)) {
924-
throw new Error('GameWindow.generateInfoPanel: btnRoot ' +
925-
'did not resolve to a valid HTMLElement: ' +
926-
opts.btnRoot);
931+
throw new Error('GameWindow.generateInfoPanel: ' +
932+
'toggleBtnRoot did not resolve to a ' +
933+
'valid HTMLElement: ' + opts.toggleBtnRoot);
927934
}
928935
}
929936
if (root) {
930-
btn = W.infoPanel.createToggleButton(opts.btnLabel);
937+
btn = W.infoPanel.createToggleBtn(opts.toggleBtnLabel);
931938
root.appendChild(btn);
932939
}
933940
}

lib/InfoPanel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@
309309
* @see InfoPanel.toggleBtn
310310
* @see InfoPanel.toggle
311311
*/
312+
InfoPanel.prototype.createToggleBtn =
312313
InfoPanel.prototype.createToggleButton = function(label) {
313314
var that, button;
314315

0 commit comments

Comments
 (0)