/* global angular, module, utils, moduleName */
module.service('focusMouse', function (focusManager, focusQuery) {

    var scope = this;

    /**
     * Enable mouse functionality for focus manager
     */
    function enable() {
        scope.enabled = false;
        utils.addEvent(document, 'mousedown', onMouseDown);
    }

    /**
     * Disable mouse functionality for focus manager
     */
    function disable() {
        scope.enabled = false;
        utils.removeEvent(document, 'mousedown', onMouseDown);
    }

    /**
     * Listen to mousedown event. If there is FocusManager ID, enable FM otherwise disable FM.
     * @param evt
     */
    function onMouseDown(evt) {
        if (focusManager.canReceiveFocus(evt.target)) {
            focusManager.focus(evt.target);

            var parentId = focusQuery.getParentId(evt.target);
            if (parentId) {
                focusManager.enable();
            } else {
                focusManager.disable();
            }
        }
    }

    scope.enabled = false;
    scope.enable = enable;
    scope.disable = disable;

}).run(function (focusMouse) {
    // enable FM by default
    focusMouse.enable();
});


@@ -674,24 +674,150 @@
 Down(evt) %7B%0A
+        var el = evt.target;%0A        while(el.nodeName.toUpperCase() === 'SPAN') %7B%0A            el = el.parentNode;%0A        %7D%0A%0A
         if (
@@ -846,25 +846,17 @@
 eFocus(e
-vt.target
+l
 )) %7B%0A   
@@ -884,25 +884,17 @@
 .focus(e
-vt.target
+l
 );%0A%0A    
@@ -940,25 +940,17 @@
 rentId(e
-vt.target
+l
 );%0A     

fix to mouse.js for selectable element if click on element was a span.