# Namespace: CB_Touch

## CB_Touch

Static class to manage the touch events. It will return itself if it is tried to be instantiated. It can also use Pressure.js and Hammer.js.

Source:
  - CrossBase/input/CB_Touch.js, line 12

### Members

#### <static, readonly> DEFAULT_FORCE :number

  Default value for the force attribute if no one is detected.

  ##### Type:

  - number
  Default Value:
    - 1
  Source:
    - CrossBase/input/CB_Touch.js, line 24

### Methods

#### <static> delay( [delayMs] [, index]) → {boolean}

  First time, this function will return true. Next calls, with same index, returns false during the previously-defined time set in the previous call and true after that delay. After the first call, next calls of this function with same index will be ignored (returning always false) until the delay provided expires. If it is called after a previous call with the same index and the delay of the previous call already expired, it will act as it was the first call again. Useful, for example, to prevent the onTouchStart event to fire twice or more when a layer (container) is closed and behind there is another one with also the onTouchStart event.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `delayMs` | integer | <optional> | CB_Touch._delayMsDefault | Delay desired in milliseconds. For same indexes, this parameter will be ignored if there was a previous call to this function whose delay did not expire yet.
  `index` | integer | string | <optional> | 0 | Desired index to identify the process.

  Source:
    - CrossBase/input/CB_Touch.js, line 344

  ##### Returns:

  First time, this function will return true. Next calls with the same index, returns false during the given time and true after that delay. After the first call, next calls with same index of this function will be ignored (returning always false) until the delay provided expires. If it is called after a previous call with the same index and the delay of the previous call already expired, it will act as it was the first call again.

  Type
    boolean

#### <static> getData() → {Event|null}

  Returns the last touch event object (if any), processed by `CB_Touch.normalizeEvent` internally, which was used in the last touch event fired, if that touch event was touchstart, touchenter or touchmove. The touchend and touchleave events set it to "null".

  Source:
    - CrossBase/input/CB_Touch.js, line 169

  ##### Returns:

  Returns the last touch event affected, if any.

  Type
    Event | null

#### <static> getHammerJSObject() → {Object}

  Returns the Hammer.js object (if any). Useful for managing touch gestures.

  Source:
    - CrossBase/input/CB_Touch.js, line 317

  ##### Returns:

  Returns the Hammer.js object (if any).

  Type
    Object

#### <static> getMaxTouchPoints() → {integer|null}

  Returns the maximum of touch points supported by the device (if possible).

  Source:
    - CrossBase/input/CB_Touch.js, line 180

  ##### Returns:

  Maximum touch points supported by the device (if possible). If it cannot be detected, returns null.

  Type
    integer | null

#### <static> getPressureJSObject() → {Object}

  Returns the Pressure.js object (if any). Useful for managing Force Touch/3D Touch and Pointer Pressure features.

  Source:
    - CrossBase/input/CB_Touch.js, line 328

  ##### Returns:

  Returns the Pressure.js object (if any).

  Type
    Object

#### <static> normalizeEvent(e) → {Event}

  Tries to return the touch event object with some properties normalized (since different clients can use different values), when possible. It also calls the `CB_Events.normalize` and `CB_Touch.normalizePoints` functions internally. Some properties affected could be targetTouches, touches, changedTouches, etc.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `e` | Event | Touch event object. If not provided, it will use the value of "event", "window.event", "Event" or an empty object ("{}").

  Source:
    - CrossBase/input/CB_Touch.js, line 110
  To Do:
    - Add more properties and methods to normalize (if needed)

  ##### Returns:

  Returns the touch event object normalized.

  Type
    Event

#### <static> normalizeForce(force) → {Event}

  Normalizes the given "force" property value across different clients. The new attached methods and properties may include polyfills, etc. This function is called by `CB_Touch.normalizePoint` automatically.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `force` | number | Force value to be normalized.

  Source:
    - CrossBase/input/CB_Touch.js, line 92
  To Do:
    - Not all web clients are the same, so not all should be normalized.

  ##### Returns:

  Returns the force value normalized.

  Type
    Event

#### <static> normalizePoint(point) → {Touch}

  Normalizes a given point. Calls `CB_Touch.normalizeForce` internally. This function is called by `CB_Touch.normalizePoints` automatically.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `point` | Touch | Touch object to be normalized.

  Source:
    - CrossBase/input/CB_Touch.js, line 148

  ##### Returns:

  Returns the given point normalized.

  Type
    Touch

#### <static> normalizePoints(points) → {TouchList|array}

  Normalizes a given list of points. Calls `CB_Touch.normalizePoint` internally. This function is called by `CB_Touch.normalizeEvent` automatically.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `points` | TouchList | array | TouchList or array with the points (Touch objects) to be normalized.

  Source:
    - CrossBase/input/CB_Touch.js, line 131

  ##### Returns:

  Returns the given points normalized.

  Type
    TouchList | array

#### <static> onCancel(callbackFunction [, keepOldFunction] [, useCapture] [, target])

  Sets a function to execute when the onTouchCancel event is fired or removes it. More information: Touch events.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `callbackFunction` | function | null |  |  | The function (event listener) that we want to execute when the event is fired. The first and unique parameter received for this function will be the event object (already normalized by the `CB_Touch.normalizeEvent` function). If a null value is used, the event will be removed.
  `keepOldFunction` | boolean | <optional> | true | Defines whether we want to keep any possible previous event listener for the same target and event name or not.
  `useCapture` | boolean | <optional> | false | Defines whether the event we want to add will use capture or not. This parameter will be effective only if the current client supports the addEventListener method and will be used as its third parameter.
  `target` | Object | <optional> | document | The target where we want to attach the event listener.

  Source:
    - CrossBase/input/CB_Touch.js, line 227

#### <static> onEnd(callbackFunction [, keepOldFunction] [, useCapture] [, target])

  Sets a function to execute when the onTouchEnd event is fired or removes it. More information: Touch events.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `callbackFunction` | function | null |  |  | The function (event listener) that we want to execute when the event is fired. The first and unique parameter received for this function will be the event object (already normalized by the `CB_Touch.normalizeEvent` function). If a null value is used, the event will be removed.
  `keepOldFunction` | boolean | <optional> | true | Defines whether we want to keep any possible previous event listener for the same target and event name or not.
  `useCapture` | boolean | <optional> | false | Defines whether the event we want to add will use capture or not. This parameter will be effective only if the current client supports the addEventListener method and will be used as its third parameter.
  `target` | Object | <optional> | document | The target where we want to attach the event listener.

  Source:
    - CrossBase/input/CB_Touch.js, line 213

#### <static> onEnter(callbackFunction [, keepOldFunction] [, useCapture] [, target])

  Sets a function to execute when the onTouchEnter event is fired or removes it. More information: Touch events.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `callbackFunction` | function | null |  |  | The function (event listener) that we want to execute when the event is fired. The first and unique parameter received for this function will be the event object (already normalized by the `CB_Touch.normalizeEvent` function). If a null value is used, the event will be removed.
  `keepOldFunction` | boolean | <optional> | true | Defines whether we want to keep any possible previous event listener for the same target and event name or not.
  `useCapture` | boolean | <optional> | false | Defines whether the event we want to add will use capture or not. This parameter will be effective only if the current client supports the addEventListener method and will be used as its third parameter.
  `target` | Object | <optional> | document | The target where we want to attach the event listener.

  Source:
    - CrossBase/input/CB_Touch.js, line 241

#### <static> onLeave(callbackFunction [, keepOldFunction] [, useCapture] [, target])

  Sets a function to execute when the onTouchLeave event is fired or removes it. More information: Touch events.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `callbackFunction` | function | null |  |  | The function (event listener) that we want to execute when the event is fired. The first and unique parameter received for this function will be the event object (already normalized by the `CB_Touch.normalizeEvent` function). If a null value is used, the event will be removed.
  `keepOldFunction` | boolean | <optional> | true | Defines whether we want to keep any possible previous event listener for the same target and event name or not.
  `useCapture` | boolean | <optional> | false | Defines whether the event we want to add will use capture or not. This parameter will be effective only if the current client supports the addEventListener method and will be used as its third parameter.
  `target` | Object | <optional> | document | The target where we want to attach the event listener.

  Source:
    - CrossBase/input/CB_Touch.js, line 255

#### <static> onMove(callbackFunction [, keepOldFunction] [, useCapture] [, target])

  Sets a function to execute when the onTouchMove event is fired or removes it. More information: Touch events.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `callbackFunction` | function | null |  |  | The function (event listener) that we want to execute when the event is fired. The first and unique parameter received for this function will be the event object (already normalized by the `CB_Touch.normalizeEvent` function). If a null value is used, the event will be removed.
  `keepOldFunction` | boolean | <optional> | true | Defines whether we want to keep any possible previous event listener for the same target and event name or not.
  `useCapture` | boolean | <optional> | false | Defines whether the event we want to add will use capture or not. This parameter will be effective only if the current client supports the addEventListener method and will be used as its third parameter.
  `target` | Object | <optional> | document | The target where we want to attach the event listener.

  Source:
    - CrossBase/input/CB_Touch.js, line 269

#### <static> onStart(callbackFunction [, keepOldFunction] [, useCapture] [, target])

  Sets a function to execute when the onTouchStart event is fired or removes it. More information: Touch events.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `callbackFunction` | function | null |  |  | The function (event listener) that we want to execute when the event is fired. The first and unique parameter received for this function will be the event object (already normalized by the `CB_Touch.normalizeEvent` function). If a null value is used, the event will be removed.
  `keepOldFunction` | boolean | <optional> | true | Defines whether we want to keep any possible previous event listener for the same target and event name or not.
  `useCapture` | boolean | <optional> | false | Defines whether the event we want to add will use capture or not. This parameter will be effective only if the current client supports the addEventListener method and will be used as its third parameter.
  `target` | Object | <optional> | document | The target where we want to attach the event listener.

  Source:
    - CrossBase/input/CB_Touch.js, line 199

#### Search results