src/utilities.js
function smartCoordinates(args) {
  var x = args.x,
    y = args.y;

  var paper = Origami.getPaper(),
    elmWidth = paper.element.width,
    elmHeight = paper.element.height,
    radius = (args.r || 0);

  var width = (args.width || radius),
    height = (args.height || width);

  var axis = {
    x: [ 'right', 'center', 'left' ],
    y: [ 'top', 'center', 'bottom' ]
  };

  if (axis.x.indexOf(x) !== -1) {
    if (x === 'right')
      x = Math.floor(elmWidth - width);
    else if (x === 'center')
      if (radius)
        x = Math.floor(elmWidth / 2)
      else
        x = Math.floor((elmWidth / 2) - (width / 2));
    else if (x === 'left')
      x = radius;
  } else if ((x + '').substr(-1) === '%') {
    x = (elmWidth * parseInt(x, 10)) / 100;
  } else {
    x = 0;
  }

  if (axis.y.indexOf(y) !== -1) {
    if (y === 'top')
      y = radius;
    else if (y === 'center')
      if (radius)
        y = Math.floor(elmHeight / 2);
      else
        y = Math.floor((elmHeight / 2) - (height / 2));
    else if (y === 'bottom')
      y = Math.floor(elmHeight - height);
  } else if ((y + '').substr(-1) === '%') {
    y = (elmHeight * parseInt(y, 10)) / 100;
  } else {
    y = 0;
  }

  args.y = y;
  args.x = x;
  return args;
}
function smartCoordinates(args) {
  var x = args.x,
    y = args.y;

  var paper = Origami.getPaper(),
    elmWidth = paper.element.width,
    elmHeight = paper.element.height,
    radius = (args.r || 0);

  var width = (args.width || radius),
    height = (args.height || width);

  var axis = {
    x: [ 'right', 'center', 'left' ],
    y: [ 'top', 'center', 'bottom' ]
  };

  if (axis.x.indexOf(x) !== -1) {
    if (x === 'right')
      x = Math.floor(elmWidth - width);
    else if (x === 'center')
      if (radius)
        x = Math.floor(elmWidth / 2)
      else
        x = Math.floor((elmWidth / 2) - (width / 2));
    else if (x === 'left')
      x = radius;
  } else if ((x + '').substr(-1) === '%') {
    x = (elmWidth * parseInt(x, 10)) / 100;
  } else {
    x = 0;
  }

  if (axis.y.indexOf(y) !== -1) {
    if (y === 'top')
      y = radius;
    else if (y === 'center')
      if (radius)
        y = Math.floor(elmHeight / 2);
      else
        y = Math.floor((elmHeight / 2) - (height / 2));
    else if (y === 'bottom')
      y = Math.floor(elmHeight - height);
  } else if ((y + '').substr(-1) === '%') {
    y = (elmHeight * parseInt(y, 10)) / 100;
  } else {
    y = 0;
  }

  args.y = y;
  args.x = x;
  return args;
}
function smartCoordinates ( args ) { var x = args . x , y = args . y ; var paper = Origami . getPaper ( ) , elmWidth = paper . element . width , elmHeight = paper . element . height , radius = ( args . r || 0 ) ; var width = ( args . width || radius ) , height = ( args . height || width ) ; var axis = { x : [ 'right' , 'center' , 'left' ] , y : [ 'top' , 'center' , 'bottom' ] } ; if ( axis . x . indexOf ( x ) !== - 1 ) { if ( x === 'right' ) x = Math . floor ( elmWidth - width ) ; else if ( x === 'center' ) if ( radius ) x = Math . floor ( elmWidth / 2 ) else x = Math . floor ( ( elmWidth / 2 ) - ( width / 2 ) ) ; else if ( x === 'left' ) x = radius ; } else if ( ( x + '' ) . substr ( - 1 ) === '%' ) { x = ( elmWidth * parseInt ( x , 10 ) ) / 100 ; } else { x = 0 ; } if ( axis . y . indexOf ( y ) !== - 1 ) { if ( y === 'top' ) y = radius ; else if ( y === 'center' ) if ( radius ) y = Math . floor ( elmHeight / 2 ) ; else y = Math . floor ( ( elmHeight / 2 ) - ( height / 2 ) ) ; else if ( y === 'bottom' ) y = Math . floor ( elmHeight - height ) ; } else if ( ( y + '' ) . substr ( - 1 ) === '%' ) { y = ( elmHeight * parseInt ( y , 10 ) ) / 100 ; } else { y = 0 ; } args . y = y ; args . x = x ; return args ; }
Return args object with new coordinates based on behavior
@returns {Object} args
Return args object with new coordinates based on behavior