@@ -282,12 +282,16 @@ define(function() {
282
282
/**
283
283
* Parse the coordinates from the string representation.
284
284
*
285
- * @param {String } startcoordinates "x1,y1".
286
- * @param {String } endcoordinates "x1,y1".
285
+ * @param {String } startcoordinates "x1,y1;radius ".
286
+ * @param {String } endcoordinates "x1,y1;radius ".
287
287
* @param {float } ratio .
288
- * @return {Point } the point. Throws an exception if input is not valid.
288
+ * @return {boolean } True if the coordinates are parsed. False if the start and end coordinates are empty.
289
+ * * Throws an exception if input point is not valid.
289
290
*/
290
291
Line . prototype . parse = function ( startcoordinates , endcoordinates , ratio ) {
292
+ if ( startcoordinates === '' || endcoordinates === '' ) {
293
+ return false ;
294
+ }
291
295
var startcoordinatesbits = startcoordinates . split ( ';' ) ;
292
296
var endcoordinatesbits = endcoordinates . split ( ';' ) ;
293
297
this . centre1 = Point . parse ( startcoordinatesbits [ 0 ] ) ;
@@ -309,14 +313,14 @@ define(function() {
309
313
/**
310
314
* Move the entire shape by this offset.
311
315
*
312
- * @param {String } handleIndex which handle was moved.
316
+ * @param {String } whichHandle which circle handle was moved, i.e., startcircle or endcircle .
313
317
* @param {int } dx x offset.
314
318
* @param {int } dy y offset.
315
319
* @param {int } maxX ensure that after editing, the shape lies between 0 and maxX on the x-axis.
316
320
* @param {int } maxY ensure that after editing, the shape lies between 0 and maxX on the y-axis.
317
321
*/
318
- Line . prototype . move = function ( handleIndex , dx , dy , maxX , maxY ) {
319
- if ( handleIndex === '0 ' ) {
322
+ Line . prototype . move = function ( whichHandle , dx , dy , maxX , maxY ) {
323
+ if ( whichHandle === 'startcircle ' ) {
320
324
this . centre1 . move ( dx , dy ) ;
321
325
if ( this . centre1 . x < this . startRadius ) {
322
326
this . centre1 . x = this . startRadius ;
@@ -356,7 +360,7 @@ define(function() {
356
360
} ;
357
361
358
362
/**
359
- * Move the entire line by this offset.
363
+ * Move the line end points by this offset.
360
364
*
361
365
* @param {int } dx x offset.
362
366
* @param {int } dy y offset.
@@ -414,28 +418,36 @@ define(function() {
414
418
415
419
/**
416
420
* Move the g element between the dropzones and dragHomes.
417
- * @param {SVGElement } svgDragsHome Svg element containing the drags.
418
- * @param {SVGElement } svgDropZones Svg element containing the dropZone.
421
+ * @param {String } eventType Whether it's a mouse event or a keyboard event.
419
422
* @param {SVGElement } selectedElement The element selected for dragging.
420
- * @param {int } dropX
421
- * @param {int } dropY
423
+ * @param {int|null } dropX Used by mouse events to calculate the svg to which it belongs.
424
+ * @param {int|null } dropY
425
+ * @param {String|null } whichSVG
422
426
*/
423
- Line . prototype . addToDropZone = function ( svgDragsHome , svgDropZones , selectedElement , dropX , dropY ) {
424
- var maxY = 0 ;
425
- var dropzoneNo = selectedElement . getAttribute ( 'data-dropzone-no' ) ;
426
- var classattributes = '' ;
427
- if ( this . isInsideSVG ( svgDragsHome , dropX , dropY ) ) {
428
- // Append the element to the second SVG
429
- // Get the height of the dropZone SVG.
427
+ Line . prototype . addToDropZone = function ( eventType , selectedElement , dropX , dropY , whichSVG ) {
428
+ var maxY = 0 ,
429
+ dropzoneNo = selectedElement . getAttribute ( 'data-dropzone-no' ) ,
430
+ classattributes = '' ,
431
+ dropZone = false ;
432
+ var svgDragsHome = document . querySelector ( 'svg.dragshome' ) ;
433
+ var svgDropZones = document . querySelector ( 'svg.dropzones' ) ;
434
+ if ( eventType === 'mouse' ) {
435
+ dropZone = this . isInsideSVG ( svgDragsHome , dropX , dropY ) ;
436
+ } else {
437
+ dropZone = ( whichSVG === 'DragsSVG' ) ;
438
+ }
439
+ if ( dropZone ) {
440
+ // Append the element to the dropzone SVG.
441
+ // Get the height of the dropZone SVG, to decide the position to where to drop the line.
430
442
maxY = svgDropZones . height . baseVal . value ;
431
443
svgDropZones . appendChild ( selectedElement ) ;
432
444
selectedElement . getAttribute ( 'data-dropzone-no' ) ;
433
445
446
+ // Set tabindex to add keyevents to the circle movehandles.
447
+ selectedElement . childNodes [ 1 ] . setAttribute ( 'tabindex' , '0' ) ;
448
+ selectedElement . childNodes [ 2 ] . setAttribute ( 'tabindex' , '0' ) ;
449
+
434
450
// Caluculate the position of line drop.
435
- // this.centre1.y = maxY - (2 * this.startRadius) - (dropzoneNo * 50);
436
- // this.y1 = maxY - (2 * this.startRadius) - (dropzoneNo * 50);
437
- // this.centre2.y = maxY - (2 * this.endRadius) - (dropzoneNo * 50);
438
- // this.y2 = maxY - (2 * this.endRadius) - (dropzoneNo * 50);
439
451
this . centre1 . y = maxY - ( 2 * this . startRadius ) ;
440
452
this . y1 = maxY - ( 2 * this . startRadius ) ;
441
453
this . centre2 . y = maxY - ( 2 * this . endRadius ) ;
@@ -446,8 +458,8 @@ define(function() {
446
458
classattributes = classattributes . replace ( 'inactive' , 'placed' ) ;
447
459
selectedElement . setAttribute ( 'class' , classattributes ) ;
448
460
449
- } else if ( this . isInsideSVG ( svgDropZones , dropX , dropY ) ) {
450
- // Append the element to the first SVG (to ensure it stays in the same SVG if dropped there)
461
+ } else {
462
+ // Append the element to the draghmes SVG.
451
463
svgDragsHome . appendChild ( selectedElement ) ;
452
464
453
465
// We want to drop the lines from the top, depending on the line number.
@@ -463,6 +475,9 @@ define(function() {
463
475
classattributes = selectedElement . getAttribute ( 'class' ) ;
464
476
classattributes = classattributes . replace ( 'placed' , 'inactive' ) ;
465
477
selectedElement . setAttribute ( 'class' , classattributes ) ;
478
+ // Set tabindex = -1, so the circle movehandles aren't focusable when in draghomes svg.
479
+ selectedElement . childNodes [ 1 ] . setAttribute ( 'tabindex' , '-1' ) ;
480
+ selectedElement . childNodes [ 2 ] . setAttribute ( 'tabindex' , '-1' ) ;
466
481
}
467
482
return '' ;
468
483
} ;
@@ -583,9 +598,13 @@ define(function() {
583
598
*/
584
599
function createSvgShapeGroup ( svg , tagName ) {
585
600
var svgEl = createSvgElement ( svg , 'g' ) ;
586
- createSvgElement ( svgEl , tagName ) . setAttribute ( 'class' , 'shape' ) ;
587
- createSvgElement ( svgEl , 'circle' ) . setAttribute ( 'class' , 'startcircle shape' ) ;
588
- createSvgElement ( svgEl , 'circle' ) . setAttribute ( 'class' , 'endcircle shape' ) ;
601
+ var lineEl = createSvgElement ( svgEl , tagName ) ;
602
+ lineEl . setAttribute ( 'class' , 'shape' ) ;
603
+ lineEl . setAttribute ( 'tabindex' , '0' ) ;
604
+ var startcircleEl = createSvgElement ( svgEl , 'circle' ) ;
605
+ startcircleEl . setAttribute ( 'class' , 'startcircle shape' ) ;
606
+ var endcirleEl = createSvgElement ( svgEl , 'circle' ) ;
607
+ endcirleEl . setAttribute ( 'class' , 'endcircle shape' ) ;
589
608
createSvgElement ( svgEl , 'text' ) . setAttribute ( 'class' , 'labelstart shapeLabel' ) ;
590
609
createSvgElement ( svgEl , 'text' ) . setAttribute ( 'class' , 'labelend shapeLabel' ) ;
591
610
return svgEl ;
0 commit comments