Index: lams_central/web/includes/javascript/authoring/authoringActivity.js =================================================================== diff -u -r070fb3365c9a8186b44a1b442da4866577954cb1 -r240f31b379582c5cef0b7db0280c1c052de1b527 --- lams_central/web/includes/javascript/authoring/authoringActivity.js (.../authoringActivity.js) (revision 070fb3365c9a8186b44a1b442da4866577954cb1) +++ lams_central/web/includes/javascript/authoring/authoringActivity.js (.../authoringActivity.js) (revision 240f31b379582c5cef0b7db0280c1c052de1b527) @@ -85,10 +85,6 @@ 'Forum and Scribe' : 5 }, -/* - - */ - ActivityDefs = { /** @@ -240,6 +236,7 @@ if (!isReadOnlyMode){ this.loadPropertiesDialogContent = PropertyDefs.groupingProperties; } + this.draw = ActivityDraw.grouping; this.draw(x, y); }, @@ -264,6 +261,7 @@ if (!isReadOnlyMode){ this.loadPropertiesDialogContent = PropertyDefs.optionalActivityProperties; } + this.draw = ActivityDraw.optionalActivity; this.draw(x, y); }, @@ -380,6 +378,9 @@ this.items.remove(); } + x = Snap.snapTo(layout.conf.snapGridX, x, layout.conf.snapGridX / 2); + y = Snap.snapTo(layout.conf.snapGridY, y, layout.conf.snapGridY / 2); + // create activity SVG elements var shape = paper.path(Snap.format('M {x} {y} a 8 8 0 1 0 16 0 a 8 8 0 1 0 -16 0', { @@ -421,6 +422,9 @@ y = this.items.getBBox().y; } + x = Snap.snapTo(layout.conf.snapGridX, x, layout.conf.snapGridX / 2); + y = Snap.snapTo(layout.conf.snapGridY, y, layout.conf.snapGridY / 2); + // either check what children are on canvas or use the priovided parameter if (childActivities) { this.childActivities = childActivities; @@ -436,7 +440,7 @@ this.parentActivity = floatingActivity; this.orderID = orderID; var childBox = this.items.shape.getBBox(); - this.draw(activityX, y + Math.max(layout.conf.containerActivityPadding + 10, (box.height - childBox.height)/2)); + this.draw(activityX, y + Math.max(layout.conf.containerActivityPadding + 10, (box.height - childBox.height)/2), true); childBox = this.items.shape.getBBox(); activityX = childBox.x2 + layout.conf.containerActivityChildrenPadding; allElements.push(this.items.shape); @@ -472,6 +476,9 @@ this.items.remove(); } + x = Snap.snapTo(layout.conf.snapGridX, x, layout.conf.snapGridX / 2); + y = Snap.snapTo(layout.conf.snapGridY, y, layout.conf.snapGridY / 2); + // create activity SVG elements var shape = paper.path(Snap.format('M {x} {y} l-9 9 v16 l9 9 h16 l9 -9 v-16 l-9 -9 z', { @@ -514,6 +521,9 @@ this.items.remove(); } + x = Snap.snapTo(layout.conf.snapGridX, x, layout.conf.snapGridX / 2); + y = Snap.snapTo(layout.conf.snapGridY, y, layout.conf.snapGridY / 2); + // create activity SVG elements var shape = paper.path(Snap.format('M {x} {y} h 125 v 50 h -125 z', { @@ -553,6 +563,9 @@ y = this.items.getBBox().y; } + x = Snap.snapTo(layout.conf.snapGridX, x, layout.conf.snapGridX / 2); + y = Snap.snapTo(layout.conf.snapGridY, y, layout.conf.snapGridY / 2); + // either check what children are on canvas or use the priovided parameter if (childActivities) { this.childActivities = childActivities; @@ -570,7 +583,7 @@ this.orderID = orderID + 1; // for some reason, this.items.getBBox() can't be used here var childBox = this.items.shape.getBBox(); - this.draw(x + Math.max(layout.conf.containerActivityPadding, (boxWidth - childBox.width)/2), activityY); + this.draw(x + Math.max(layout.conf.containerActivityPadding, (boxWidth - childBox.width)/2), activityY, true); childBox = this.items.shape.getBBox(); activityY = childBox.y2 + layout.conf.containerActivityChildrenPadding; allElements.push(this.items.shape); @@ -610,6 +623,9 @@ y = this.items ? this.items.getBBox().y : 0; } + x = Snap.snapTo(layout.conf.snapGridX, x, layout.conf.snapGridX / 2); + y = Snap.snapTo(layout.conf.snapGridY, y, layout.conf.snapGridY / 2); + if (this.childActivities && this.childActivities.length > 0) { // draw one by one, vertically var activityY = y + layout.conf.containerActivityPadding + 10, @@ -618,7 +634,7 @@ $.each(this.childActivities, function(orderID){ this.parentActivity = optionalActivity; this.orderID = orderID + 1; - this.draw(x + layout.conf.containerActivityPadding, activityY); + this.draw(x + layout.conf.containerActivityPadding, activityY, true); activityY = this.items.getBBox().y2 + layout.conf.containerActivityChildrenPadding; allElements.push(this.items.shape); }); @@ -652,7 +668,7 @@ /** * Draws a Tool activity */ - tool : function(x, y) { + tool : function(x, y, skipSnapToGrid) { if (x == undefined || y == undefined) { // if no new coordinates are given, just redraw the activity x = this.items.getBBox().x; @@ -663,6 +679,11 @@ this.items.remove(); } + if (!skipSnapToGrid) { + x = Snap.snapTo(layout.conf.snapGridX, x, layout.conf.snapGridX / 2); + y = Snap.snapTo(layout.conf.snapGridY, y, layout.conf.snapGridY / 2); + } + // create activity SVG elements var shape = paper.path(Snap.format('M {x} {y} h 125 v 50 h -125 z', { @@ -716,7 +737,7 @@ this.items = paper.g(); var points = ActivityLib.findTransitionPoints(this.fromActivity, this.toActivity), - curve = layout.transition.curve, + curve = layout.conf.transitionCurve, threshold = 2 * curve + 2; if (points) { @@ -1352,8 +1373,10 @@ toActivityBox = toActivity.items.getBBox(), // vertical direction takes priority // horizontal is used only if activities are in the same line - direction = (fromActivityBox.y > toActivityBox.y && fromActivityBox.y < toActivityBox.y2) - || (fromActivityBox.y2 > toActivityBox.y && fromActivityBox.y2 < toActivityBox.y2) + direction = (fromActivityBox.y >= toActivityBox.y && fromActivityBox.y <= toActivityBox.y2) + || (fromActivityBox.y2 >= toActivityBox.y && fromActivityBox.y2 <= toActivityBox.y2) + || (toActivityBox.y >= fromActivityBox.y && toActivityBox.y <= fromActivityBox.y2) + || (toActivityBox.y2 >= fromActivityBox.y && toActivityBox.y2 <= fromActivityBox.y2) ? 'horizontal' : 'vertical', points = null; @@ -1378,6 +1401,7 @@ } else { if (fromActivityBox.cx < toActivityBox.cx) { // right + points = { 'startX' : fromActivityBox.x2, 'startY' : fromActivityBox.y + fromActivityBox.height / 2, Index: lams_central/web/includes/javascript/authoring/authoringGeneral.js =================================================================== diff -u -rcbde480a02664277c52274b4f591cd291cc578d3 -r240f31b379582c5cef0b7db0280c1c052de1b527 --- lams_central/web/includes/javascript/authoring/authoringGeneral.js (.../authoringGeneral.js) (revision cbde480a02664277c52274b4f591cd291cc578d3) +++ lams_central/web/includes/javascript/authoring/authoringGeneral.js (.../authoringGeneral.js) (revision 240f31b379582c5cef0b7db0280c1c052de1b527) @@ -42,7 +42,7 @@ } }, - // graphics contants + // graphics constants 'conf' : { 'arrangeHorizontalSpace' : 200, 'arrangeVerticalSpace' : 100, @@ -74,7 +74,14 @@ 'supportsDownloadAttribute' : typeof $('')[0].download != 'undefined', // will be initialised when paper gets created - 'readOnlyFilter' : null + 'readOnlyFilter' : null, + + // the bigger this number, the larger bezier curves will be + 'transitionCurve' : 15, + + // snapping grid step when dragging an activity + 'snapGridX' : 100, + 'snapGridY' : 100 }, 'colors' : { @@ -125,11 +132,6 @@ 'text-anchor' : 'middle', 'font-size' : 10, 'font-family' : 'sans-serif' - }, - - 'transition' : { - // the bigger this number, the larger bezier curves will be - 'curve' : 15 } }, @@ -1440,7 +1442,7 @@ // learn where a tall Optional Activity has its end // and later start drawing activities lower than in the next row if (activity instanceof DecorationDefs.Container && activity.childActivities.length > 1) { - var activityEndY = activity.items.shape.getBBox().y2; + var activityEndY = activity.items.getBBox().y2; if (!forceRowY || activityEndY > forceRowY) { forceRowY = activityEndY; }