Skip to content

Commit

Permalink
Merge pull request #639 from taye/fix-style-cursor
Browse files Browse the repository at this point in the history
autoStart: set cursor on both target and <html>
  • Loading branch information
taye authored Jun 4, 2018
2 parents ff30f9c + 65ef914 commit 8543104
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/autoStart/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function init (scope) {
const target = interaction.target;

if (target && target.options.styleCursor) {
target._doc.documentElement.style.cursor = '';
setCursor(interaction.element, '', scope);
}
});

Expand Down Expand Up @@ -97,6 +97,7 @@ function init (scope) {
// Allow this many interactions to happen simultaneously
maxInteractions: Infinity,
withinInteractionLimit,
cursorElement: null,
signals: new Signals(),
};
}
Expand Down Expand Up @@ -171,7 +172,7 @@ function prepare (interaction, { action, target, element }, scope) {
action = action || {};

if (interaction.target && interaction.target.options.styleCursor) {
interaction.target._doc.documentElement.style.cursor = '';
setCursor(interaction.element, '', scope);
}

interaction.target = target;
Expand All @@ -180,7 +181,7 @@ function prepare (interaction, { action, target, element }, scope) {

if (target && target.options.styleCursor) {
const cursor = action? scope.actions[action.name].getCursor(action) : '';
interaction.target._doc.documentElement.style.cursor = cursor;
setCursor(interaction.element, cursor, scope);
}

scope.autoStart.signals.fire('prepared', { interaction: interaction });
Expand Down Expand Up @@ -239,6 +240,16 @@ function maxInteractions (newValue, scope) {
return scope.autoStart.maxInteractions;
}

function setCursor (element, cursor, scope) {
if (scope.autoStart.cursorElement) {
scope.autoStart.cursorElement.style.cursor = '';
}

element.ownerDocument.documentElement.style.cursor = cursor;
element.style.cursor = cursor;
scope.autoStart.cursorElement = cursor ? element : null;
}

export default {
init,
maxInteractions,
Expand Down

0 comments on commit 8543104

Please sign in to comment.