Skip to content

Instantly share code, notes, and snippets.

@timhunt
Created July 4, 2017 14:07
Show Gist options
  • Save timhunt/52afd16353fd80c7e1beb1958316f9da to your computer and use it in GitHub Desktop.
Save timhunt/52afd16353fd80c7e1beb1958316f9da to your computer and use it in GitHub Desktop.
Simplest possible drag-drop
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Allows the dashboard boxes to be customised.
*
* @package block_dashboardboxes
* @copyright 2017 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* @module block_dashboardboxes/reorder_list
*/
define(['jquery', 'core/modal_factory', 'core/modal_events', 'tool_lp/dragdrop-reorder'],
function($, ModalFactory, ModalEvents, dragdrop) {
/**
* @alias block_dashboardboxes/reorder_list
*/
var t = {
init: function () {
dragdrop.dragdrop('moveitems',
'Move item',
{identifier: 'movecompetency', component: 'tool_lp'},
{identifier: 'movecompetencyafter', component: 'tool_lp'},
'item',
'list',
'item',
t.drop);
},
drop: function(drag, drop) {
alert(drag);
alert(drop);
}
}
return t;
}
);
<?php
require_once(__DIR__ . '/config.php');
require_login();
$PAGE->set_context(context_system::instance());
$PAGE->set_url('/test.php');
echo $OUTPUT->header();
?>
<ul class="list">
<li class="item" id="1">Item 1</li>
<li class="item" id="2">Item 2</li>
<li class="item" id="3">Item 3</li>
</ul>
<?php
$PAGE->requires->js_call_amd('block_dashboardboxes/reorder_list', 'init');
echo $OUTPUT->footer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment