Commit 18dabc33 by Andy Armstrong

Upgrade draggabilly.js to fix Firefox iframe bug

TNL-3627
parent dd5a6acf
...@@ -109,13 +109,18 @@ ...@@ -109,13 +109,18 @@
// The parameter "predef" should remain empty for this configuration file // The parameter "predef" should remain empty for this configuration file
// to remain as general as possible. // to remain as general as possible.
"predef": [ "predef": [
// jQuery library. // jQuery globals
"jQuery", "$", "jQuery", "$",
// Underscore.js library. // Underscore.js globals
"_", "_",
// Jasmine library. // RequireJS globals
"define",
"require",
"RequireJS",
// Jasmine globals
"jasmine", "jasmine",
"describe", "xdescribe", "describe", "xdescribe",
"it", "xit", "it", "xit",
...@@ -126,12 +131,15 @@ ...@@ -126,12 +131,15 @@
"waitsFor", "waitsFor",
"runs", "runs",
// jQuery-Jasmine library. // jQuery-Jasmine globals
"loadFixtures", "loadFixtures",
"appendLoadFixtures", "appendLoadFixtures",
"readFixtures", "readFixtures",
"setFixtures", "setFixtures",
"appendSetFixtures", "appendSetFixtures",
"spyOnEvent" "spyOnEvent",
// Miscellaneous globals
"JSON"
] ]
} }
...@@ -17,6 +17,7 @@ require.config({ ...@@ -17,6 +17,7 @@ require.config({
paths: { paths: {
"domReady": "js/vendor/domReady", "domReady": "js/vendor/domReady",
"gettext": "/i18n", "gettext": "/i18n",
"json2": "js/vendor/json2",
"mustache": "js/vendor/mustache", "mustache": "js/vendor/mustache",
"codemirror": "js/vendor/codemirror-compressed", "codemirror": "js/vendor/codemirror-compressed",
"codemirror/stex": "js/vendor/CodeMirror/stex", "codemirror/stex": "js/vendor/CodeMirror/stex",
...@@ -95,6 +96,9 @@ require.config({ ...@@ -95,6 +96,9 @@ require.config({
] ]
}, },
shim: { shim: {
"json2": {
exports: "JSON"
},
"gettext": { "gettext": {
exports: "gettext" exports: "gettext"
}, },
......
...@@ -23,6 +23,7 @@ requirejs.config({ ...@@ -23,6 +23,7 @@ requirejs.config({
"jquery.simulate": "xmodule_js/common_static/js/vendor/jquery.simulate", "jquery.simulate": "xmodule_js/common_static/js/vendor/jquery.simulate",
"datepair": "xmodule_js/common_static/js/vendor/timepicker/datepair", "datepair": "xmodule_js/common_static/js/vendor/timepicker/datepair",
"date": "xmodule_js/common_static/js/vendor/date", "date": "xmodule_js/common_static/js/vendor/date",
"json2": "xmodule_js/common_static/js/vendor/json2",
"moment": "xmodule_js/common_static/js/vendor/moment.min", "moment": "xmodule_js/common_static/js/vendor/moment.min",
"moment-with-locales": "xmodule_js/common_static/js/vendor/moment-with-locales.min", "moment-with-locales": "xmodule_js/common_static/js/vendor/moment-with-locales.min",
"text": "xmodule_js/common_static/js/vendor/requirejs/text", "text": "xmodule_js/common_static/js/vendor/requirejs/text",
...@@ -58,6 +59,9 @@ requirejs.config({ ...@@ -58,6 +59,9 @@ requirejs.config({
"js/spec/test_utils": "js/spec/test_utils", "js/spec/test_utils": "js/spec/test_utils",
} }
shim: { shim: {
"json2": {
exports: "JSON"
},
"gettext": { "gettext": {
exports: "gettext" exports: "gettext"
}, },
......
define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/views/feedback_notification", "draggabilly", define(["jquery", "jquery.ui", "underscore", "json2", "gettext", "draggabilly",
"js/utils/module"], "js/utils/module", "common/js/components/views/feedback_notification"],
function ($, ui, _, gettext, NotificationView, Draggabilly, ModuleUtils) { function ($, ui, _, JSON, gettext, Draggabilly, ModuleUtils, NotificationView) {
'use strict';
var contentDragger = { var contentDragger = {
droppableClasses: 'drop-target drop-target-prepend drop-target-before drop-target-after', droppableClasses: 'drop-target drop-target-prepend drop-target-before drop-target-after',
validDropClass: "valid-drop", validDropClass: "valid-drop",
expandOnDropClass: "expand-on-drop", expandOnDropClass: "expand-on-drop",
...@@ -17,14 +18,15 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi ...@@ -17,14 +18,15 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi
var eleY = ele.offset().top; var eleY = ele.offset().top;
var eleYEnd = eleY + ele.outerHeight(); var eleYEnd = eleY + ele.outerHeight();
var containers = $(ele.data('droppable-class')); var containers = $(ele.data('droppable-class'));
var isSibling = function () {
return $(this).data('locator') !== undefined && !$(this).is(ele);
};
for (var i = 0; i < containers.length; i++) { for (var i = 0; i < containers.length; i++) {
var container = $(containers[i]); var container = $(containers[i]);
// Exclude the 'new unit' buttons, and make sure we don't // Exclude the 'new unit' buttons, and make sure we don't
// prepend an element to itself // prepend an element to itself
var siblings = container.children().filter(function () { var siblings = container.children().filter(isSibling);
return $(this).data('locator') !== undefined && !$(this).is(ele);
});
// If the container is collapsed, check to see if the // If the container is collapsed, check to see if the
// element is on top of its parent list -- don't check the // element is on top of its parent list -- don't check the
// position of the container // position of the container
...@@ -37,8 +39,8 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi ...@@ -37,8 +39,8 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi
var collapseFudge = 10; var collapseFudge = 10;
if (Math.abs(eleY - parentListTop) < collapseFudge || if (Math.abs(eleY - parentListTop) < collapseFudge ||
(eleY > parentListTop && (eleY > parentListTop &&
eleYEnd - collapseFudge <= parentListTop + parentList.outerHeight()) eleYEnd - collapseFudge <= parentListTop + parentList.outerHeight())
) { ) {
return { return {
ele: container, ele: container,
attachMethod: 'prepend', attachMethod: 'prepend',
...@@ -101,11 +103,12 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi ...@@ -101,11 +103,12 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi
} }
else { else {
// Dragging up into end of list. // Dragging up into end of list.
if (j === siblings.length - 1 && yChange < 0 && Math.abs(eleY - siblingYEnd) <= fudge) { if (j === siblings.length - 1 && yChange < 0 &&
Math.abs(eleY - siblingYEnd) <= fudge) {
return { return {
ele: $sibling, ele: $sibling,
attachMethod: 'after' attachMethod: 'after'
}; };
} }
// Dragging up or down into beginning of list. // Dragging up or down into beginning of list.
else if (j === 0 && Math.abs(eleY - siblingY) <= fudge) { else if (j === 0 && Math.abs(eleY - siblingY) <= fudge) {
...@@ -145,8 +148,8 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi ...@@ -145,8 +148,8 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi
// Information about the current drag. // Information about the current drag.
dragState: {}, dragState: {},
onDragStart: function (draggie, event, pointer) { onDragStart: function (draggable) {
var ele = $(draggie.element); var ele = $(draggable.element);
this.dragState = { this.dragState = {
// Which element will be dropped into/onto on success // Which element will be dropped into/onto on success
dropDestination: null, dropDestination: null,
...@@ -162,7 +165,9 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi ...@@ -162,7 +165,9 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi
if (!ele.hasClass(this.collapsedClass)) { if (!ele.hasClass(this.collapsedClass)) {
ele.addClass(this.collapsedClass); ele.addClass(this.collapsedClass);
ele.find('.expand-collapse').first().addClass('expand').removeClass('collapse'); ele.find('.expand-collapse').first().addClass('expand').removeClass('collapse');
// onDragStart gets called again after the collapse, so we can't just store a variable in the dragState.
// onDragStart gets called again after the collapse, so we can't
// just store a variable in the dragState.
ele.addClass(this.expandOnDropClass); ele.addClass(this.expandOnDropClass);
} }
...@@ -171,7 +176,7 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi ...@@ -171,7 +176,7 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi
ele.removeClass('was-dragging'); ele.removeClass('was-dragging');
}, },
onDragMove: function (draggie, event, pointer) { onDragMove: function (draggable, event, pointer) {
// Handle scrolling of the browser. // Handle scrolling of the browser.
var scrollAmount = 0; var scrollAmount = 0;
var dragBuffer = 10; var dragBuffer = 10;
...@@ -186,13 +191,13 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi ...@@ -186,13 +191,13 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi
return; return;
} }
var yChange = draggie.dragPoint.y - this.dragState.lastY; var yChange = draggable.dragPoint.y - this.dragState.lastY;
if (yChange !== 0) { if (yChange !== 0) {
this.dragState.direction = yChange; this.dragState.direction = yChange;
} }
this.dragState.lastY = draggie.dragPoint.y; this.dragState.lastY = draggable.dragPoint.y;
var ele = $(draggie.element); var ele = $(draggable.element);
var destinationInfo = this.findDestination(ele, this.dragState.direction); var destinationInfo = this.findDestination(ele, this.dragState.direction);
var destinationEle = destinationInfo.ele; var destinationEle = destinationInfo.ele;
this.dragState.parentList = destinationInfo.parentList; this.dragState.parentList = destinationInfo.parentList;
...@@ -215,8 +220,8 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi ...@@ -215,8 +220,8 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi
} }
}, },
onDragEnd: function (draggie, event, pointer) { onDragEnd: function (draggable, event, pointer) {
var ele = $(draggie.element); var ele = $(draggable.element);
var destination = this.dragState.dropDestination; var destination = this.dragState.dropDestination;
// Clear dragging state in preparation for the next event. // Clear dragging state in preparation for the next event.
...@@ -284,7 +289,7 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi ...@@ -284,7 +289,7 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi
// If drop was into a collapsed parent, the parent will have been // If drop was into a collapsed parent, the parent will have been
// expanded. Views using this class may need to track the // expanded. Views using this class may need to track the
// collapse/expand state, so send it with the refresh callback. // collapse/expand state, so send it with the refresh callback.
var collapsed = element.hasClass(this.collapsedClass); var collapsed = element.hasClass(contentDragger.collapsedClass);
if (_.isFunction(refresh)) { refresh(collapsed); } if (_.isFunction(refresh)) { refresh(collapsed); }
}; };
...@@ -364,20 +369,20 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi ...@@ -364,20 +369,20 @@ define(["jquery", "jquery.ui", "underscore", "gettext", "common/js/components/vi
if ($(element).data('droppable-class') !== options.droppableClass) { if ($(element).data('droppable-class') !== options.droppableClass) {
$(element).data({ $(element).data({
'droppable-class': options.droppableClass, 'droppable-class': options.droppableClass,
'parent-location-selector': options.parentLocationSelector, 'parent-location-selector': options.parentLocationSelector,
'child-selector': options.type, 'child-selector': options.type,
'refresh': options.refresh, 'refresh': options.refresh,
'ensureChildrenRendered': options.ensureChildrenRendered 'ensureChildrenRendered': options.ensureChildrenRendered
}); });
draggable = new Draggabilly(element, { draggable = new Draggabilly(element, {
handle: options.handleClass, handle: options.handleClass,
containment: '.wrapper-dnd' containment: '.wrapper-dnd'
}); });
draggable.on('dragStart', _.bind(contentDragger.onDragStart, contentDragger)); draggable.on('dragStart', _.bind(contentDragger.onDragStart, contentDragger, draggable));
draggable.on('dragMove', _.bind(contentDragger.onDragMove, contentDragger)); draggable.on('dragMove', _.bind(contentDragger.onDragMove, contentDragger, draggable));
draggable.on('dragEnd', _.bind(contentDragger.onDragEnd, contentDragger)); draggable.on('dragEnd', _.bind(contentDragger.onDragEnd, contentDragger, draggable));
} }
} }
}; };
......
...@@ -59,6 +59,7 @@ lib_paths: ...@@ -59,6 +59,7 @@ lib_paths:
- xmodule_js/common_static/js/vendor/draggabilly.pkgd.js - xmodule_js/common_static/js/vendor/draggabilly.pkgd.js
- xmodule_js/common_static/js/vendor/date.js - xmodule_js/common_static/js/vendor/date.js
- xmodule_js/common_static/js/vendor/domReady.js - xmodule_js/common_static/js/vendor/domReady.js
- xmodule_js/common_static/js/vendor/json2.js
- xmodule_js/common_static/js/vendor/URI.min.js - xmodule_js/common_static/js/vendor/URI.min.js
- xmodule_js/common_static/js/vendor/jquery.smooth-scroll.min.js - xmodule_js/common_static/js/vendor/jquery.smooth-scroll.min.js
- xmodule_js/common_static/coffee/src/jquery.immediateDescendents.js - xmodule_js/common_static/coffee/src/jquery.immediateDescendents.js
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment