API Docs for: 0.0.2
Show:

chess.view.board.Piece Class

Module: Board
Parent Module: View

Class representing the view of chess pieces in DHTML Chess. Instances of this class are created dynamically by chess.view.Board

Methods

animationComplete

() private

Method executed when move animation is complete

createDOM

() private

Create DOM elements for the chess piece

disableDragAndDrop

()

Disable drag and drop for the chess piece. This will set the internal ddEnabled property to false and reset cursor to arrow.

dragPiece

(
  • e
)
Boolean | Undefined private

Method executed when dragging has started and mouse moves

Parameters:

  • e Event

Returns:

Boolean | Undefined:

enableDragAndDrop

()

Enable drag and drop for the chess piece. This will set the internal ddEnabled property to true and update the cursor to a pointer/hand.

flip

()

Executed when board is flipped. It will call the position method.

getColorCode

() String private

Return color code of piece, "w" or "b"

Returns:

getEl

() HTMLElement

Return HTML element of piece

Returns:

getPos

(
  • square
)
Object

Return x and y coordinate by 0x88 square number

Parameters:

Returns:

Example:

    var pos = piece.getPos();
    // may return
    {
        "x":"12.5%",
        "y":"25%"
    }

getPosOfSquare

(
  • square
)
Object

Return x and y position of square by 0x88 coordinate(without the % suffix)

Parameters:

Returns:

getSquare

() String

Return square of piece

Returns:

String: square

getSquareByCoordinates

(
  • x
  • y
)
Number private

Return 0x88 square by screen coordinates

Parameters:

Returns:

getTypeCode

() String private

Return lowercase piece type, i.e. "k","q","r","b","n" or "p"

Returns:

hide

()

Hide the chess piece

increaseZindex

() private

Move piece to front

initDragPiece

(
  • e
)
Boolean | Undefined private

Start dragging a chess piece

Parameters:

  • e Event

Returns:

Boolean | Undefined:

isAlreadyOnSquare

(
  • square
)
Boolean private

Returns true if piece is already on a given 0x88 square number

Parameters:

Returns:

isFlipped

() Boolean

Returns true if piece is already flipped

Returns:

isVisible

() Boolean

Returns true if chess piece is currently on board.

Returns:

mouseEnterPiece

() private

Method executed when mouse enters a chess piece

mouseLeavePiece

() private

Method executed when mouse leaves a chess piece

playMove

(
  • toSquare
)

Move piece on board to square

Parameters:

position

(
  • square
)

Position piece on board by 0x88 board square coordinate

Parameters:

promote

(
  • toType
)

Promote piece to this type

Parameters:

Example:

piece.promote('queen');

resize

(
  • squareSize
)

Resize piece

Parameters:

show

()

Show the chess piece

stopDragPiece

(
  • e
)
private

Stop dragging the chess piece.

Parameters:

  • e Event

updateBackgroundImage

() private

Update background image of piece when piece type is set or changed and when size of square is changed.

Attributes

color

String

Color of piece, "white" or "black"

Default: "white"

pieceType

String

Type of piece

Example:

pieceType:'knight'

square

Number

0x88 board position of piece