Marionette JS Client

API Docs for: 1.7.1
Show:

File: lib/marionette/multi-actions.js

  1. (function(module, ns) {

  2.   /**
  3.    * For a multifinger gesture, we can use MultiActions.
  4.    * For example, one finger to hold down
  5.    * while the other finger moves from one element to another.
  6.    *
  7.    * @class Marionette.MultiActions
  8.    * @param {Marionette.Client} context of a client.
  9.    */
  10.   function MultiActions(client) {
  11.     this.client = client;
  12.     this.multiActions = [];
  13.     this.maxLength = 0;
  14.   }

  15.   MultiActions.prototype = {

  16.     /**
  17.      * Adds a action chain for execution.
  18.      *
  19.      * @method add
  20.      * @param {Object} action {{#crossLink "Marionette.Actions"}}{{/crossLink}}.
  21.      *
  22.      * @return {Object} self.
  23.      */
  24.     add: function add(action) {
  25.       this.multiActions.push(action.actionChain);
  26.       if (action.actionChain.length > this.maxLength) {
  27.         this.maxLength = action.actionChain.length;
  28.       }
  29.       return this;
  30.     },

  31.     /**
  32.      * Send multiple action chains that have been added
  33.      * to the server side for execution.
  34.      *
  35.      * @method perform
  36.      * @param {Function} callback callback when the perform completes.
  37.      */
  38.     perform: function perform(callback) {
  39.       var cmd = {
  40.         type: 'multiAction',
  41.         value: this.multiActions,
  42.         max_length: this.maxLength
  43.       };

  44.       this.client._sendCommand(cmd, 'ok', callback);
  45.       this.multiActions = [];
  46.       return this;
  47.     }
  48.   };

  49.   module.exports = MultiActions;

  50. }.apply(
  51.   this,
  52.   (this.Marionette) ?
  53.     [Marionette('multi-actions'), Marionette] :
  54.     [module, require('../../lib/marionette/marionette')]
  55. ));

  56.