# Class: MediaQueriesEvents

## MediaQueriesEvents

#### new MediaQueriesEvents(breakpointsList [, userOptions])

  Manage media queries events

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `breakpointsList` | Array.<Breakpoint> |  |
  `userOptions` | Object | <optional> | ###### Properties
  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `unit` | String | <optional> | "px" |

  ##### Example

      let mquery = new MediaQueriesEvents( [
             "name" :        "mob",
             "query":        window.matchMedia( '(max-width:767px)' )
         },
         {
             "name" :        "tab",
             "query":        window.matchMedia( '(min-width:768px) and (max-width:959px)' )
         },
         {
             "name" :        "desk",
             "query":        window.matchMedia( '(min-width:960px)' )
         } ] );

      or

       let mquery = new MediaQueriesEvents( [
             "name" :        "mob",
             "max":          767
         },
         {
             "name" :        "tab",
             "min":          768,
             "max":          956
         },
         {
             "name" :        "desk",
             "max":          960
         } ],
         {
            "unit": "px" // Default value
         }
      );

      // Register a function to be call when leaving any breakpoint
      mquery.register( callback, MediaQueriesEvents.TYPE_ON_LEAVE );

      // Remove a function to be called
      mquery.remove( callback );

      // Bind a function to be call when entering the "small" breakpoint
      mquery.on( callback, 'small' );
      // Same as
      mquery.on( callback, 'small', MediaQueriesEvents.TYPE_ON_ENTER );

      // Unbind the function
      mquery.off( callback, 'small' );

      // Refresh all registered function for the current breakpoint
      mquery.refresh();

      // Call a function with the current breakpoint in parameters.
      mquery.get( callback );

      // Return true if `breakpointName` is the name of the current breakpoint
      boolean = mquery.is( 'desk' );

      // Current active breakpoint
      myBreakpoint = mquery.currentBreakpoint; // => {name, query, ...} or false
      myBreakpoint.is( 'mob' ); // => true|false
      myBreakpoint.in( ['mob', 'tab'] ); // => true|false

      // List of all breakpoints
      array = mquery.list;

      // Check if the current breakpoint is in a list.
      boolean = mquery.in(['mob', 'tab']);

      // Pause media queries watch
      mquery.suspend();

      // Resume media queries watch
      mquery.resume();

### Members

#### <static, readonly> TYPE_ON_BOTH :Number

  Mediaquery both callback type

  ##### Type:

  - Number

#### <static, readonly> TYPE_ON_ENTER :Number

  Mediaquery entering callback type

  ##### Type:

  - Number

#### <static, readonly> TYPE_ON_LEAVE :Number

  Mediaquery leaving callback type

  ##### Type:

  - Number

#### <readonly> currentBreakpoint :False|Breakpoint

  Current active breakpoint

  ##### Type:

  - False | Breakpoint

#### <readonly> list :Array.<Breakpoint>

  List of all breakpoints

  ##### Type:

  - Array.<Breakpoint>

### Methods

#### get(callback)

  Call a function with the current breakpoint

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `callback` | function | Function to call

  ##### Returns:

  Type
    MediaQueriesEvents

#### getValue(obj)

  Return the value of the property with the name of the current breakpoint of an object

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `obj` | Object |

  ##### Returns:

  Type
    *

  ##### Example

      mediaQueryEvent.getValue( { "small": "val1", "medium": "val2", ... } );
      Ih the current breakpoint name is "small", it will return "val1"

#### in(breakpointNameList)

  Check if the current breakpoint is in a list

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `breakpointNameList` | Array.<String> | Array of breakpoint name

  ##### Returns:

  Type
    Boolean

#### is(breakpointName)

  Check if we are in a specific range

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `breakpointName` | String | Name of a breakpoint

  ##### Returns:

  Type
    Boolean

#### off(callback, breakpointName)

  Unbind a function to be called on a specific breakpoint

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `callback` | function | Function to remove from the registered function list
  `breakpointName` | String | Name of the breakpoint

  ##### Returns:

  Type
    MediaQueriesEvents

#### on(callback, breakpointName [, type])

  Bind a function to be called on a specific breakpoint

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `callback` | MediaQueriesEvents_Handler |  |  | Callback
  `breakpointName` | String |  |  | Name of the breakpoint
  `type` | String | <optional> | MediaQueriesEvents.TYPE_ON_ENTER | Select when the function will be called: when entering the query, when leaving it, or on both

  ##### Returns:

  Type
    MediaQueriesEvents

#### refresh()

  Force the refresh of all registered function

  ##### Returns:

  Type
    MediaQueriesEvents

#### register(callback [, type])

  Register a function to be called on all media queries change

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `callback` | MediaQueriesEvents_Handler |  |  | Function to call on mediaquery change
  `type` | String | <optional> | MediaQueriesEvents.TYPE_ON_ENTER | Select when the function will be called: when entering the query, when leaving it, or on both

  ##### Returns:

  Type
    MediaQueriesEvents

#### remove(callback)

  Unregister a function

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `callback` | function | Function to remove from the registered function list

  ##### Returns:

  Type
    MediaQueriesEvents

#### resume()

  Active media queries callback

  ##### Returns:

  Type
    MediaQueriesEvents

#### suspend()

  Stop media queries callback

  ##### Returns:

  Type
    MediaQueriesEvents

#### which()

  Return the currentbreakpointsList breakpoint
  Deprecated:
    - - Use mediaquerisEvent.currentBreakpoint instead

  ##### Returns:

  Type
    False | Breakpoint

### Type Definitions

#### Breakpoint

  ##### Properties:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `name` | String |  |
  `query` | Object |  | Object buid with the window.matchMedia() function
  `min` | Number | <optional> | mediaquery lower bound
  `max` | Number | <optional> | mediaquery upper bound
  `in` | function |  | Return true if the breakpoint is in the list: breakpoint.in(['bp1', 'bp2'])
  `is` | function |  | Return true if the name passed to the function is the name of the breakpoint: breakpoint.is('bp1')

#### MediaQueriesEvents_Handler(breakpoint, isMatching)

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `breakpoint` | Breakpoint |
  `isMatching` | Boolean | True if we enter the query, false if we leave

#### Search results