[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/lp/amd/src/ -> dragdrop-reorder.js (source)

   1  // This file is part of Moodle - http://moodle.org/
   2  //
   3  // Moodle is free software: you can redistribute it and/or modify
   4  // it under the terms of the GNU General Public License as published by
   5  // the Free Software Foundation, either version 3 of the License, or
   6  // (at your option) any later version.
   7  //
   8  // Moodle is distributed in the hope that it will be useful,
   9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11  // GNU General Public License for more details.
  12  //
  13  // You should have received a copy of the GNU General Public License
  14  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  15  
  16  /**
  17   * Drag and drop reorder via HTML5.
  18   *
  19   * @module     tool_lp/dragdrop-reorder
  20   * @package    tool_lp
  21   * @copyright  2015 Damyon Wiese <damyon@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  define(['core/str', 'core/yui'], function(str, Y) {
  25      // Private variables and functions.
  26  
  27      /**
  28       * Store the current instance of the core drag drop.
  29       *
  30       * @property dragDropInstance M.tool_lp.dragdrop_reorder
  31       */
  32      var dragDropInstance = null;
  33  
  34      /**
  35       * Translate the drophit event from YUI
  36       * into simple drag and drop nodes.
  37       * @param {Y.Event} e The yui drop event.
  38       */
  39      var proxyCallback = function(e) {
  40          var dragNode = e.drag.get('node');
  41          var dropNode = e.drop.get('node');
  42          this.callback(dragNode.getDOMNode(), dropNode.getDOMNode());
  43      };
  44  
  45      return /** @alias module:tool_lp/dragdrop-reorder */ {
  46          // Public variables and functions.
  47          /**
  48           * Create an instance of M.tool_lp.dragdrop
  49           *
  50           * @param {String} group Unique string to identify this interaction.
  51           * @param {String} dragHandleText Alt text for the drag handle.
  52           * @param {String} sameNodeText Used in keyboard drag drop for the list of items target.
  53           * @param {String} parentNodeText Used in keyboard drag drop for the parent target.
  54           * @param {String} sameNodeClass class used to find the each of the list of items.
  55           * @param {String} parentNodeClass class used to find the container for the list of items.
  56           * @param {String} dragHandleInsertClass class used to find the location to insert the drag handles.
  57           * @param {function} callback Drop hit handler.
  58           */
  59          dragdrop: function(group,
  60                             dragHandleText,
  61                             sameNodeText,
  62                             parentNodeText,
  63                             sameNodeClass,
  64                             parentNodeClass,
  65                             dragHandleInsertClass,
  66                             callback) {
  67              // Here we are wrapping YUI. This allows us to start transitioning, but
  68              // wait for a good alternative without having inconsistent UIs.
  69              str.get_strings([
  70                  {key: 'emptydragdropregion', component: 'moodle'},
  71                  {key: 'movecontent', component: 'moodle'},
  72                  {key: 'tocontent', component: 'moodle'},
  73              ]).done(function() {
  74                  Y.use('moodle-tool_lp-dragdrop-reorder', function() {
  75  
  76                      var context = {
  77                          callback: callback
  78                      };
  79                      if (dragDropInstance) {
  80                          dragDropInstance.destroy();
  81                      }
  82                      dragDropInstance = M.tool_lp.dragdrop_reorder({
  83                          group: group,
  84                          dragHandleText: dragHandleText,
  85                          sameNodeText: sameNodeText,
  86                          parentNodeText: parentNodeText,
  87                          sameNodeClass: sameNodeClass,
  88                          parentNodeClass: parentNodeClass,
  89                          dragHandleInsertClass: dragHandleInsertClass,
  90                          callback: Y.bind(proxyCallback, context)
  91                      });
  92                  });
  93              });
  94          }
  95  
  96      };
  97  });


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1