Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 54... Línea 54...
54
 * @module     core/sortable_list
54
 * @module     core/sortable_list
55
 * @class      core/sortable_list
55
 * @class      core/sortable_list
56
 * @copyright  2018 Marina Glancy
56
 * @copyright  2018 Marina Glancy
57
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
57
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
58
 */
58
 */
-
 
59
define([
-
 
60
    'jquery',
-
 
61
    'core/log',
-
 
62
    'core/autoscroll',
-
 
63
    'core/event_dispatcher',
-
 
64
    'core/str',
-
 
65
    'core/modal_cancel',
59
define(['jquery', 'core/log', 'core/autoscroll', 'core/str', 'core/modal_cancel', 'core/modal_events', 'core/notification'],
66
    'core/modal_events',
-
 
67
    'core/notification',
60
function($, log, autoScroll, str, ModalCancel, ModalEvents, Notification) {
68
], function($, log, autoScroll, EventDispatcher, str, ModalCancel, ModalEvents, Notification) {
Línea 61... Línea 69...
61
 
69
 
62
    /**
70
    /**
63
     * Default parameters
71
     * Default parameters
64
     *
72
     *
Línea 189... Línea 197...
189
     *
197
     *
190
     * @public
198
     * @public
191
     * @type {Object}
199
     * @type {Object}
192
     */
200
     */
193
    SortableList.EVENTS = {
201
    SortableList.EVENTS = {
-
 
202
        // Legacy jQuery events.
194
        DRAGSTART: 'sortablelist-dragstart',
203
        DRAGSTART: 'sortablelist-dragstart',
195
        DRAG: 'sortablelist-drag',
204
        DRAG: 'sortablelist-drag',
196
        DROP: 'sortablelist-drop',
205
        DROP: 'sortablelist-drop',
197
        DRAGEND: 'sortablelist-dragend'
206
        DRAGEND: 'sortablelist-dragend',
-
 
207
        // Native Javascript events.
-
 
208
        elementDragStart: 'core/sortable_list:dragStart',
-
 
209
        elementDrag: 'core/sortable_list:drag',
-
 
210
        elementDrop: 'core/sortable_list:drop',
-
 
211
        elementDragEnd: 'core/sortable_list:dragEnd',
198
    };
212
    };
Línea 199... Línea 213...
199
 
213
 
200
    /**
214
    /**
201
     * Resets the temporary classes assigned during dragging
215
     * Resets the temporary classes assigned during dragging
Línea 336... Línea 350...
336
            autoScroll.start(function() {
350
            autoScroll.start(function() {
337
                $(window).trigger('mousemove');
351
                $(window).trigger('mousemove');
338
            });
352
            });
339
        }
353
        }
Línea 340... Línea 354...
340
 
354
 
341
       this.executeCallback(SortableList.EVENTS.DRAGSTART);
355
       this.executeCallback(SortableList.EVENTS.elementDragStart);
Línea 342... Línea 356...
342
    };
356
    };
343
 
357
 
344
    /**
358
    /**
Línea 390... Línea 404...
390
            dropped: false,
404
            dropped: false,
391
            type: evt.type,
405
            type: evt.type,
392
            startTime: new Date().getTime()
406
            startTime: new Date().getTime()
393
        };
407
        };
Línea 394... Línea 408...
394
 
408
 
395
        this.executeCallback(SortableList.EVENTS.DRAGSTART);
409
        this.executeCallback(SortableList.EVENTS.elementDragStart);
396
        this.displayMoveDialogue(clickedElement);
410
        this.displayMoveDialogue(clickedElement);
Línea 397... Línea 411...
397
    };
411
    };
398
 
412
 
Línea 511... Línea 525...
511
            this.info.endY = evt.pageY;
525
            this.info.endY = evt.pageY;
512
            this.info.endTime = new Date().getTime();
526
            this.info.endTime = new Date().getTime();
513
            this.info.dropped = true;
527
            this.info.dropped = true;
514
            this.info.positionChanged = this.hasPositionChanged(this.info);
528
            this.info.positionChanged = this.hasPositionChanged(this.info);
515
            var oldinfo = this.info;
529
            var oldinfo = this.info;
516
            this.executeCallback(SortableList.EVENTS.DROP);
530
            this.executeCallback(SortableList.EVENTS.elementDrop);
517
            this.finishDragging();
531
            this.finishDragging();
Línea 518... Línea 532...
518
 
532
 
519
            if (evt.type === 'touchend'
533
            if (evt.type === 'touchend'
520
                    && this.config.moveHandlerSelector !== null
534
                    && this.config.moveHandlerSelector !== null
Línea 575... Línea 589...
575
        }
589
        }
Línea 576... Línea 590...
576
 
590
 
577
        // Save the current position of the dragged element in the list.
591
        // Save the current position of the dragged element in the list.
578
        this.info.targetList = parentElement;
592
        this.info.targetList = parentElement;
579
        this.info.targetNextElement = beforeElement;
593
        this.info.targetNextElement = beforeElement;
580
        this.executeCallback(SortableList.EVENTS.DRAG);
594
        this.executeCallback(SortableList.EVENTS.elementDrag);
Línea 581... Línea 595...
581
    };
595
    };
582
 
596
 
583
    /**
597
    /**
Línea 589... Línea 603...
589
        if (this.config.autoScroll) {
603
        if (this.config.autoScroll) {
590
            autoScroll.stop();
604
            autoScroll.stop();
591
        }
605
        }
592
        $(window).off('mousemove touchmove.notPassive mouseup touchend.notPassive', $.proxy(this.dragHandler, this));
606
        $(window).off('mousemove touchmove.notPassive mouseup touchend.notPassive', $.proxy(this.dragHandler, this));
593
        $(window).off('keypress', $.proxy(this.dragcancelHandler, this));
607
        $(window).off('keypress', $.proxy(this.dragcancelHandler, this));
594
        this.executeCallback(SortableList.EVENTS.DRAGEND);
608
        this.executeCallback(SortableList.EVENTS.elementDragEnd);
595
        this.info = null;
609
        this.info = null;
596
    };
610
    };
Línea 597... Línea 611...
597
 
611
 
598
    /**
612
    /**
599
     * Executes callback specified in sortable list parameters
613
     * Executes callback specified in sortable list parameters
600
     *
614
     *
601
     * @private
615
     * @private
602
     * @param {String} eventName
616
     * @param {String} eventName
603
     */
617
     */
-
 
618
    SortableList.prototype.executeCallback = function(eventName) {
-
 
619
        EventDispatcher.dispatchEvent(eventName, this.info, this.info.element[0]);
-
 
620
 
-
 
621
        // The following event trigger is legacy and will be removed in the future.
-
 
622
        // This approach provides a backwards-compatibility layer for the new events.
-
 
623
        // Code should be updated to make use of native events.
-
 
624
        const legacyEventNamesMap = new Map([
-
 
625
            [SortableList.EVENTS.elementDragStart, SortableList.EVENTS.DRAGSTART],
-
 
626
            [SortableList.EVENTS.elementDrag, SortableList.EVENTS.DRAG],
-
 
627
            [SortableList.EVENTS.elementDrop, SortableList.EVENTS.DROP],
-
 
628
            [SortableList.EVENTS.elementDragEnd, SortableList.EVENTS.DRAGEND],
604
    SortableList.prototype.executeCallback = function(eventName) {
629
        ]);
605
        this.info.element.trigger(eventName, this.info);
630
        this.info.element.trigger(legacyEventNamesMap.get(eventName), this.info);
Línea 606... Línea 631...
606
    };
631
    };
607
 
632
 
608
    /**
633
    /**
Línea 740... Línea 765...
740
                this.moveElement($(e.currentTarget).data('parent-element'), $(e.currentTarget).data('before-element'));
765
                this.moveElement($(e.currentTarget).data('parent-element'), $(e.currentTarget).data('before-element'));
741
                this.info.endTime = new Date().getTime();
766
                this.info.endTime = new Date().getTime();
742
                this.info.positionChanged = this.hasPositionChanged(this.info);
767
                this.info.positionChanged = this.hasPositionChanged(this.info);
743
                this.info.dropped = true;
768
                this.info.dropped = true;
744
                clickedElement.focus();
769
                clickedElement.focus();
745
                this.executeCallback(SortableList.EVENTS.DROP);
770
                this.executeCallback(SortableList.EVENTS.elementDrop);
746
                modal.hide();
771
                modal.hide();
747
            }, this);
772
            }, this);
748
            modal.getRoot().on('click', '[data-core_sortable_list-quickmove]', quickMoveHandler);
773
            modal.getRoot().on('click', '[data-core_sortable_list-quickmove]', quickMoveHandler);
749
            modal.getRoot().on(ModalEvents.hidden, $.proxy(function() {
774
            modal.getRoot().on(ModalEvents.hidden, $.proxy(function() {
750
                // Always destroy when hidden, it is generated dynamically each time.
775
                // Always destroy when hidden, it is generated dynamically each time.