'use strict';

// Declare app level module which depends on filters, and services
angular.module('WebsocketClient',[])
.directive('bbbTwoAxisControl', function() {
  return {
    restrict: 'A',
    link: function (scope, $elem, attrs) {
      var pos = {x:0,y:0};
      var config = {
        width: $elem.width(),
        height: $elem.height(),
        minOutput: -100,
        maxOutput: 100,
      };
      var trigger = false;

      var posXToOutput = function(x) {
        // o = (y * (maxO-minO) / width + minO 
        return Math.floor(x*(config.maxOutput-config.minOutput) / config.width)+config.minOutput;
      };

      var posYToOutput = function(y) {
        // o = (y * (maxO-minO) / height + minO 
        return Math.floor(y*(config.maxOutput-config.minOutput) / config.height)+config.minOutput;
      };

      var reset = function () {
        pos.x = 0;
        pos.y = 0;
        $elem.html("(0,0)");
        scope.resetYaw();
        scope.resetRoll();
        scope.resetPitch();
        scope.$apply();
      };

      $("body").on("mouseup",function () {
        trigger = false;
        reset();
      });

      var setPosition = function () {
        var parentOffset = $(this).offset();
        pos.x = posXToOutput(e.pageX - parentOffset.left);
        pos.y = posYToOutput(e.pageY - parentOffset.top);
        $elem.html("("+pos.x+","+pos.y+")");
        if (trigger) {
          scope.sliderYaw = pos.x;
          scope.sliderPitch = pos.y;
          scope.$apply();
        }
      };

      $elem.on("mousemove", setPosition)
      .on("mousedown", function () {
        trigger = true;
        setPosition();
      })
      .on("mouseup", function () {
        trigger = false;
        reset();
      })
      .on("mouseout", function () {
        if (!trigger) {
          reset();
        }
      });
    },
  };
});

@@ -1154,32 +1154,38 @@
 ion = function (
+elem,e
 ) %7B%0A        var 
@@ -1205,12 +1205,12 @@
 = $(
-this
+elem
 ).of
@@ -1548,27 +1548,59 @@
 emove%22, 
-setPosition
+function(e) %7B%0A%09setPosition(this,e);%0A      %7D
 )%0A      
@@ -1618,32 +1618,33 @@
 own%22, function (
+e
 ) %7B%0A        trig
@@ -1675,16 +1675,22 @@
 osition(
+this,e
 );%0A     

Fix ui bug