diff --git a/src/glift-ui/displays/board/board.js b/src/glift-ui/displays/board/board.js index 653f3dd6..a0cbdbe3 100644 --- a/src/glift-ui/displays/board/board.js +++ b/src/glift-ui/displays/board/board.js @@ -109,7 +109,7 @@ glift.displays.board.Display.prototype = { var svg = this.svg_; var divId = this.divId(); var svglib = glift.displays.svg; - var idGen = glift.displays.ids.generator(divId); + var idGen = glift.displays.svg.ids.gen(divId); var goBox = env.goBoardBox; if (svg === null) { throw new Error('Base SVG object not initialized.'); diff --git a/src/glift-ui/displays/board/board_base.js b/src/glift-ui/displays/board/board_base.js index 3a32cec9..b70590d2 100644 --- a/src/glift-ui/displays/board/board_base.js +++ b/src/glift-ui/displays/board/board_base.js @@ -6,7 +6,7 @@ goog.require('glift.displays.svg'); * fill color and a border. * * @param {!glift.displays.svg.SvgObj} svg Base svg obj - * @param {!glift.displays.ids.Generator} idGen The ID generator for SVG. + * @param {!glift.displays.svg.IdGenerator} idGen The ID generator for SVG. * @param {!glift.orientation.BoundingBox} goBox The bounding box of the go board. * @param {!glift.themes.base} theme The theme object */ diff --git a/src/glift-ui/displays/board/board_labels.js b/src/glift-ui/displays/board/board_labels.js index d5a541e8..de2f00bb 100644 --- a/src/glift-ui/displays/board/board_labels.js +++ b/src/glift-ui/displays/board/board_labels.js @@ -6,7 +6,7 @@ goog.require('glift.displays.board'); * on the raw board (rather than on stones). * * @param {!glift.displays.svg.SvgObj} svg Base svg obj - * @param {!glift.displays.ids.Generator} idGen The ID generator for SVG. + * @param {!glift.displays.svg.IdGenerator} idGen The ID generator for SVG. * @param {!glift.displays.BoardPoints} boardPoints Board points object. * @param {!glift.themes.base} theme The theme object */ diff --git a/src/glift-ui/displays/board/buttons.js b/src/glift-ui/displays/board/buttons.js index e3404354..1e4cdf52 100644 --- a/src/glift-ui/displays/board/buttons.js +++ b/src/glift-ui/displays/board/buttons.js @@ -4,7 +4,7 @@ goog.require('glift.displays.board'); * Create transparent buttons that overlay each intersection. * * @param {!glift.displays.svg.SvgObj} svg Base svg obj - * @param {!glift.displays.ids.Generator} idGen The ID generator for SVG. + * @param {!glift.displays.svg.IdGenerator} idGen The ID generator for SVG. * @param {!glift.displays.BoardPoints} boardPoints Board points object. */ glift.displays.board.buttons = function(svg, idGen, boardPoints) { diff --git a/src/glift-ui/displays/board/intersections.js b/src/glift-ui/displays/board/intersections.js index a0569704..2f9ac6e2 100644 --- a/src/glift-ui/displays/board/intersections.js +++ b/src/glift-ui/displays/board/intersections.js @@ -21,7 +21,7 @@ glift.displays.board.Intersections = function( this.theme = theme; this.rotation = rotation; this.boardPoints = boardPoints; - this.idGen = glift.displays.ids.generator(this.divId); + this.idGen = glift.displays.svg.ids.gen(this.divId); /** * Defined during events. @@ -261,11 +261,13 @@ glift.displays.board.Intersections.prototype = { var child = children[i] var pt = child.data(); var starpoint = - this.svg.child(idGen.starpointGroup()).child(idGen.starpoint(pt)) + this.svg.child(idGen.starpointGroup()).child(idGen.starpoint( + /** @type {!glift.Point} */ (pt))) if (starpoint) { starpoint.setAttr('opacity', 1).updateAttrInDom('opacity'); } - var line = this.svg.child(idGen.lineGroup()).child(idGen.line(pt)) + var line = this.svg.child(idGen.lineGroup()).child(idGen.line( + /** @type {!glift.Point} */ (pt))) if (line) { line.setAttr('opacity', 1).updateAttrInDom('opacity'); } diff --git a/src/glift-ui/displays/board/lines.js b/src/glift-ui/displays/board/lines.js index 18f7e3af..2a943feb 100644 --- a/src/glift-ui/displays/board/lines.js +++ b/src/glift-ui/displays/board/lines.js @@ -6,7 +6,7 @@ goog.require('glift.displays.board'); * on the raw board (rather than on stones). * * @param {!glift.displays.svg.SvgObj} svg Base svg obj - * @param {!glift.displays.ids.Generator} idGen The ID generator for SVG. + * @param {!glift.displays.svg.IdGenerator} idGen The ID generator for SVG. * @param {!glift.displays.BoardPoints} boardPoints Board points object. * @param {!glift.themes.base} theme The theme object */ diff --git a/src/glift-ui/displays/board/marks.js b/src/glift-ui/displays/board/marks.js index ab05e5f9..b3b81899 100644 --- a/src/glift-ui/displays/board/marks.js +++ b/src/glift-ui/displays/board/marks.js @@ -5,7 +5,7 @@ * container. * * @param {!glift.displays.svg.SvgObj} svg Base svg obj - * @param {!glift.displays.ids.Generator} idGen The ID generator for SVG. + * @param {!glift.displays.svg.IdGenerator} idGen The ID generator for SVG. */ glift.displays.board.markContainer = function(svg, idGen) { svg.append(glift.displays.svg.group().setId(idGen.markGroup())); diff --git a/src/glift-ui/displays/board/starpoints.js b/src/glift-ui/displays/board/starpoints.js index 0e4054f8..3fefad19 100644 --- a/src/glift-ui/displays/board/starpoints.js +++ b/src/glift-ui/displays/board/starpoints.js @@ -3,7 +3,7 @@ * points are used * * @param {!glift.displays.svg.SvgObj} svg Base svg obj - * @param {!glift.displays.ids.Generator} idGen The ID generator for SVG. + * @param {!glift.displays.svg.IdGenerator} idGen The ID generator for SVG. * @param {!glift.displays.BoardPoints} boardPoints Board points object. * @param {!glift.themes.base} theme The theme object */ diff --git a/src/glift-ui/displays/board/stones.js b/src/glift-ui/displays/board/stones.js index f7a44beb..85b7b764 100644 --- a/src/glift-ui/displays/board/stones.js +++ b/src/glift-ui/displays/board/stones.js @@ -3,7 +3,7 @@ * all exist at the time of GoBoard creation. * * @param {!glift.displays.svg.SvgObj} svg Base svg obj - * @param {!glift.displays.ids.Generator} idGen The ID generator for SVG. + * @param {!glift.displays.svg.IdGenerator} idGen The ID generator for SVG. * @param {!glift.displays.BoardPoints} boardPoints Board points object. * @param {!glift.themes.base} theme The theme object */ @@ -32,7 +32,7 @@ glift.displays.board.stones = function(svg, idGen, boardPoints, theme) { * only created if the theme has a shadow. * * @param {!glift.displays.svg.SvgObj} svg Base svg obj - * @param {!glift.displays.ids.Generator} idGen The ID generator for SVG. + * @param {!glift.displays.svg.IdGenerator} idGen The ID generator for SVG. * @param {!glift.displays.BoardPoints} boardPoints Board points object. * @param {!glift.themes.base} theme The theme object */ diff --git a/src/glift-ui/displays/icons/bar.js b/src/glift-ui/displays/icons/bar.js index 2a352ff3..84423eed 100644 --- a/src/glift-ui/displays/icons/bar.js +++ b/src/glift-ui/displays/icons/bar.js @@ -68,7 +68,7 @@ glift.displays.icons.IconBar = function(options) { this.vertMargin = this.theme.icons.vertMargin; this.horzMargin = this.theme.icons.horzMargin; this.svg = undefined; // initialized by draw - this.idGen = glift.displays.ids.generator(this.divId); + this.idGen = glift.displays.svg.ids.gen(this.divId); // Data related to tool tips. this.tooltipTimer = undefined; diff --git a/src/glift-ui/displays/icons/icon_selector.js b/src/glift-ui/displays/icons/icon_selector.js index 455c0ec5..04720ebb 100644 --- a/src/glift-ui/displays/icons/icon_selector.js +++ b/src/glift-ui/displays/icons/icon_selector.js @@ -91,7 +91,7 @@ glift.displays.icons.IconSelector.prototype = { .setId(columnId + '_svg') .setAttr('height', '100%') .setAttr('width', '100%'); - var idGen = glift.displays.ids.generator(columnId); + var idGen = glift.displays.svg.ids.gen(columnId); var container = svglib.group().setId(idGen.iconGroup()); svg.append(container); for (var i = 0, len = transforms.length; i < len; i++) { @@ -121,7 +121,7 @@ glift.displays.icons.IconSelector.prototype = { var svglib = glift.displays.svg; for (var i = 0; i < this.iconList.length; i++) { var svg = this.svgColumnList[i]; - var idGen = glift.displays.ids.generator(this.columnIdList[i]); + var idGen = glift.displays.svg.ids.gen(this.columnIdList[i]); var iconColumn = this.iconList[i]; var container = svglib.group().setId(idGen.buttonGroup()); svg.append(container); @@ -150,7 +150,7 @@ glift.displays.icons.IconSelector.prototype = { setIconEvents: function(eventName, func) { for (var i = 0; i < this.iconList.length; i++) { - var idGen = glift.displays.ids.generator(this.columnIdList[i]); + var idGen = glift.displays.svg.ids.gen(this.columnIdList[i]); for (var j = 0; j < this.iconList[i].length; j++) { var icon = this.iconList[i][j]; var buttonId = idGen.button(icon.iconName); diff --git a/src/glift-ui/displays/ids.js b/src/glift-ui/displays/ids.js deleted file mode 100644 index c0b98e8b..00000000 --- a/src/glift-ui/displays/ids.js +++ /dev/null @@ -1,159 +0,0 @@ -goog.provide('glift.displays.ids'); -goog.provide('glift.displays.ids.Generator'); - -/** - * Collection of ID utilities, mostly for SVG. - */ -glift.displays.ids = { - /** - * Create an ID generator. - */ - generator: function(divId) { - return new glift.displays.ids.Generator(divId); - }, - - /** - * Get an ID for a SVG element (return the stringForm id). - * - * @param {string} divId - * @param {glift.enums.svgElements} type - * @param {glift.Point|Object|string=} opt_extraData - * extraData may be undefined. Usually a point, but also be an icon name. - */ - element: function(divId, type, opt_extraData) { - var base = divId + "_" + type; - if (opt_extraData !== undefined) { - if (opt_extraData.x !== undefined) { - return base + '_' + opt_extraData.x() + "_" + opt_extraData.y(); - } else { - return base + '_' + opt_extraData.toString(); - } - } else { - return base; - } - } -}; - -/** - * Id Generator constructor. - * - * @constructor @final @struct - */ -glift.displays.ids.Generator = function(divId) { - this.divId = divId; - this._eid = glift.displays.ids.element; - this._enum = glift.enums.svgElements; - - this._svg = this._eid(this.divId, this._enum.SVG); - this._board = this._eid(this.divId, this._enum.BOARD); - this._boardCoordLabelGroup = - this._eid(this.divId, this._enum.BOARD_COORD_LABELS); - this._stoneGroup = this._eid(this.divId, this._enum.STONE_CONTAINER); - this._stoneShadowGroup = - this._eid(this.divId, this._enum.STONE_SHADOW_CONTAINER); - this._starpointGroup = this._eid(this.divId, this._enum.STARPOINT_CONTAINER); - this._buttonGroup = this._eid(this.divId, this._enum.BUTTON_CONTAINER); - this._boardButton = this._eid(this.divId, this._enum.FULL_BOARD_BUTTON); - this._lineGroup = this._eid(this.divId, this._enum.BOARD_LINE_CONTAINER); - this._markGroup = this._eid(this.divId, this._enum.MARK_CONTAINER); - this._iconGroup = this._eid(this.divId, this._enum.ICON_CONTAINER); - this._intersectionsGroup = this._eid(this.divId, this._enum.BOARD); - this._eid(this.divId, this._enum.INTERSECTIONS_CONTAINER); - this._tempMarkGroup = this._eid(this.divId, this._enum.TEMP_MARK_GROUP); -}; - -glift.displays.ids.Generator.prototype = { - /** ID for the svg container. */ - svg: function() { return this._svg; }, - - /** ID for the board. */ - board: function() { return this._board; }, - - /** Group id for the board coordinate label group */ - boardCoordLabelGroup: function() { return this._boardCoordLabelGroup; }, - - /** ID for the intersections group. */ - intersections: function() { return this._intersectionsGroup; }, - - /** Group id for the stones. */ - stoneGroup: function() { return this._stoneGroup; }, - - /** Id for a stone. */ - stone: function(pt) { return this._eid(this.divId, this._enum.STONE, pt); }, - - /** Group id for the stone shadows. */ - stoneShadowGroup: function() { return this._stoneShadowGroup; }, - - /** ID for a stone shadow. */ - stoneShadow: function(pt) { - return this._eid(this.divId, this._enum.STONE_SHADOW, pt); - }, - - /** Group id for the star points. */ - starpointGroup: function() { return this._starpointGroup; }, - - /** ID for a star point. */ - starpoint: function(pt) { - return this._eid(this.divId, this._enum.STARPOINT, pt); - }, - - /** Group id for the buttons. */ - buttonGroup: function() { return this._buttonGroup; }, - - /** ID for a button. */ - button: function(name) { - return this._eid(this.divId, this._enum.BUTTON, name); - }, - - /** ID for a full-board button. */ - fullBoardButton: function() { return this._boardButton; }, - - /** Group id for the lines. */ - lineGroup: function() { return this._lineGroup; }, - - /** ID for a line. */ - line: function(pt) { - return this._eid(this.divId, this._enum.BOARD_LINE, pt); - }, - - /** Group id a Mark Container. */ - markGroup: function() { return this._markGroup; }, - - /** ID for a mark. */ - mark: function(pt) { - return this._eid(this.divId, this._enum.MARK, pt); - }, - - /** Group id for temporary marks. */ - tempMarkGroup: function() { - return this._tempMarkGroup; - }, - - /** ID for a guideline. */ - guideLine: function() { - return this._eid(this.divId, this._enum.GUIDE_LINE); - }, - - /** Group ID for the icons. */ - iconGroup: function() { return this._iconGroup; }, - - /** ID for an icon . */ - icon: function(name) { - return this._eid(this.divId, this._enum.ICON, name); - }, - - /** Group ID for the temporary icons. */ - tempIconGroup: function(name) { - return this._eid(this.divId, this._enum.TEMP_ICON_CONTAINER, name); - }, - - /** ID for a temporary icon . */ - tempIcon: function(name) { - return this._eid(this.divId, this._enum.TEMP_ICON, name); - }, - - /** ID for a temporary text. */ - tempIconText: function(name) { - return this._eid(this.divId, this._enum.TEMP_TEXT, name); - } -}; diff --git a/src/glift-ui/displays/svg/ids.js b/src/glift-ui/displays/svg/ids.js new file mode 100644 index 00000000..4cdd8272 --- /dev/null +++ b/src/glift-ui/displays/svg/ids.js @@ -0,0 +1,215 @@ +goog.provide('glift.displays.svg.ids'); +goog.provide('glift.displays.svg.IdGenerator'); + +/** + * Collection of SVG ID utilities. + */ +glift.displays.svg.ids = { + /** + * Create an ID generator. + * @param {string} divId + * @return {!glift.displays.svg.IdGenerator} + */ + gen: function(divId) { + return new glift.displays.svg.IdGenerator(divId); + }, + + /** + * Get an ID for a SVG element (return the stringForm id). + * + * @param {string} divId + * @param {glift.enums.svgElements} type + * @param {(!glift.Point|!Object|string)=} opt_extraData + * extraData may be undefined. Usually a point, but also be an icon name. + * @return {string} The relevant Id. + */ + element: function(divId, type, opt_extraData) { + var base = divId + "_" + type; + if (opt_extraData !== undefined) { + if (opt_extraData.x !== undefined) { + return base + '_' + opt_extraData.x() + "_" + opt_extraData.y(); + } else { + return base + '_' + opt_extraData.toString(); + } + } else { + return base; + } + } +}; + +/** + * Id Generator constructor. + * + * @param {string} divId + * @constructor @final @struct + */ +glift.displays.svg.IdGenerator = function(divId) { + /** @const {string} */ + this.divId = divId; + + var eidFn = glift.displays.svg.ids.element; + var svgEnum = glift.enums.svgElements; + + /** @const @private {string} */ + this.svg_ = eidFn(this.divId, svgEnum.SVG); + /** @const @private {string} */ + this.board_ = eidFn(this.divId, svgEnum.BOARD); + /** @const @private {string} */ + this.boardCoordLabelGroup_ = eidFn(this.divId, svgEnum.BOARD_COORD_LABELS); + /** @const @private {string} */ + this.stoneGroup_ = eidFn(this.divId, svgEnum.STONE_CONTAINER); + /** @const @private {string} */ + this.stoneShadowGroup_ = eidFn(this.divId, svgEnum.STONE_SHADOW_CONTAINER); + /** @const @private {string} */ + this.starpointGroup_ = eidFn(this.divId, svgEnum.STARPOINT_CONTAINER); + /** @const @private {string} */ + this.buttonGroup_ = eidFn(this.divId, svgEnum.BUTTON_CONTAINER); + /** @const @private {string} */ + this.boardButton_ = eidFn(this.divId, svgEnum.FULL_BOARD_BUTTON); + /** @const @private {string} */ + this.lineGroup_ = eidFn(this.divId, svgEnum.BOARD_LINE_CONTAINER); + /** @const @private {string} */ + this.markGroup_ = eidFn(this.divId, svgEnum.MARK_CONTAINER); + /** @const @private {string} */ + this.iconGroup_ = eidFn(this.divId, svgEnum.ICON_CONTAINER); + /** @const @private {string} */ + this.intersectionsGroup_ = eidFn(this.divId, svgEnum.INTERSECTIONS_CONTAINER); + /** @const @private {string} */ + this.tempMarkGroup_ = eidFn(this.divId, svgEnum.TEMP_MARK_GROUP); +}; + +glift.displays.svg.IdGenerator.prototype = { + /** @return {string} ID for the svg container. */ + svg: function() { return this.svg_; }, + + /** @return {string} ID for the board. */ + board: function() { return this.board_; }, + + /** @return {string} Group id for the board coordinate label group */ + boardCoordLabelGroup: function() { return this.boardCoordLabelGroup_; }, + + /** @return {string} ID for the intersections group. */ + intersections: function() { return this.intersectionsGroup_; }, + + /** @return {string} Group id for the stones. */ + stoneGroup: function() { return this.stoneGroup_; }, + + /** + * @param {!glift.Point} pt + * @return {string} Id for a stone. + */ + stone: function(pt) { + return glift.displays.svg.ids.element( + this.divId, glift.enums.svgElements.STONE, pt); + }, + + /** @return {string} Group id for the stone shadows. */ + stoneShadowGroup: function() { return this.stoneShadowGroup_; }, + + /** + * @param {!glift.Point} pt + * @return {string} Id for a stone shadow. + */ + stoneShadow: function(pt) { + return glift.displays.svg.ids.element( + this.divId, glift.enums.svgElements.STONE_SHADOW, pt); + }, + + /** @return {string} Group id for the star points. */ + starpointGroup: function() { return this.starpointGroup_; }, + + /** + * @param {!glift.Point} pt + * @return {string} Id for a star point + */ + starpoint: function(pt) { + return glift.displays.svg.ids.element( + this.divId, glift.enums.svgElements.STARPOINT, pt); + }, + + /** @return {string} Group id for a button group. */ + buttonGroup: function() { return this.buttonGroup_; }, + + /** + * @param {!string} name Of the button. + * @return {string} Id for the button. + */ + button: function(name) { + return glift.displays.svg.ids.element( + this.divId, glift.enums.svgElements.BUTTON, name); + }, + + /** @return {string} ID for a full-board button. */ + fullBoardButton: function() { return this.boardButton_; }, + + /** @return {string} Group ID for the lines. */ + lineGroup: function() { return this.lineGroup_; }, + + /** + * @param {!glift.Point} pt + * @return {string} Id for a board line. + */ + line: function(pt) { + return glift.displays.svg.ids.element( + this.divId, glift.enums.svgElements.BOARD_LINE, pt); + }, + + /** @return {string} Group id a Mark Container. */ + markGroup: function() { return this.markGroup_; }, + + /** + * @param {!glift.Point} pt + * @return {string} ID for a mark. + */ + mark: function(pt) { + return glift.displays.svg.ids.element( + this.divId, glift.enums.svgElements.MARK, pt); + }, + + /** @return {string} Group id for temporary marks. */ + tempMarkGroup: function() { + return this.tempMarkGroup_; + }, + + /** @return {string} ID for a guideline. */ + guideLine: function() { + return glift.displays.svg.ids.element( + this.divId, glift.enums.svgElements.GUIDE_LINE); + }, + + /** @return {string} Group ID for the icons. */ + iconGroup: function() { return this.iconGroup_; }, + + /** + * @param {string} name Of the icon. + * @return {string} ID for an icon. + */ + icon: function(name) { + return glift.displays.svg.ids.element( + this.divId, glift.enums.svgElements.ICON, name); + }, + + /** @return {string} ID for the temp icon group. */ + tempIconGroup: function() { + return glift.displays.svg.ids.element( + this.divId, glift.enums.svgElements.TEMP_ICON_CONTAINER); + }, + + /** + * @param {string} name Of the icon. + * @return {string} ID for the temp icon. + */ + tempIcon: function(name) { + return glift.displays.svg.ids.element( + this.divId, glift.enums.svgElements.TEMP_ICON, name); + }, + + /** + * @param {string} name Of the icon. + * @return {string} ID for the temp icon text. + */ + tempIconText: function(name) { + return glift.displays.svg.ids.element( + this.divId, glift.enums.svgElements.TEMP_TEXT, name); + }, +}; diff --git a/src/glift-ui/displays/ids_test.js b/src/glift-ui/displays/svg/ids_test.js similarity index 94% rename from src/glift-ui/displays/ids_test.js rename to src/glift-ui/displays/svg/ids_test.js index ebc0005a..3dd96442 100644 --- a/src/glift-ui/displays/ids_test.js +++ b/src/glift-ui/displays/svg/ids_test.js @@ -1,6 +1,6 @@ (function() { - module('glift.displays.idsTest'); - var idGen = glift.displays.ids.generator('foo'); + module('glift.displays.svg.idsTest'); + var idGen = glift.displays.svg.ids.gen('foo'); var pt = glift.util.point(0, 1); var name = 'start'; diff --git a/src/glift-ui/uiutil/enums.js b/src/glift-ui/uiutil/enums.js deleted file mode 100644 index 46b956e2..00000000 --- a/src/glift-ui/uiutil/enums.js +++ /dev/null @@ -1 +0,0 @@ -goog.require('glift.enums');