Skip to content

Commit 98dce9d

Browse files
authored
Merge pull request #750 from sillero/master
Fixes scrubbing issues with mouse and window
2 parents d54ac0c + 9014509 commit 98dce9d

File tree

5 files changed

+82
-17
lines changed

5 files changed

+82
-17
lines changed

app/index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ <h2 class="ui_title">Main</h2>
136136
<!-- now player -->
137137
<div class="player" ng-controller="PlayerCtrl">
138138
<div class="player_inner">
139-
<div class="player_progress">
140-
<span class="player_progress_bar" id="player-progress"></span>
139+
<div class="player_progress_wrapper">
140+
<div class="player_progress">
141+
<span class="player_progress_bar" id="player-progress"></span>
142+
</div>
141143
</div>
142144
<div class="player_details">
143145
<img id="playerThumb" src="public/img/song-placeholder.png" alt="" class="player_thumb" ng-click="goToSong($event)">

app/public/js/app.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,19 @@ app.run(function(
189189
window.addEventListener('online', updateOnlineStatus);
190190
window.addEventListener('offline', updateOnlineStatus);
191191

192+
// map blur and focus from the gui.window to jquery events on window
193+
var $window = $(window);
194+
var gui = require('nw.gui');
195+
var guiWindow = gui.Window.get();
196+
197+
guiWindow.on('blur', function () {
198+
$window.trigger('blur');
199+
});
200+
201+
guiWindow.on('focus', function() {
202+
$window.trigger('focus');
203+
});
204+
192205
});
193206

194207
angular.module('infinite-scroll').value('THROTTLE_MILLISECONDS', 200);

app/public/js/common/playerService.js

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,24 +363,55 @@ app.factory('playerService', function(
363363
}
364364
}
365365

366+
/**
367+
* Manage scrub interaction / event handling
368+
*/
369+
370+
var allowClick = true;
371+
366372
scrub.on('click', function(e) {
367373
var el = this;
368-
scrubTimeTrack(e, el);
374+
375+
// this stops the click event on window.blur
376+
if (allowClick) {
377+
scrubTimeTrack(e, el);
378+
}
369379
});
370380

381+
var $$window = $($window);
382+
383+
$$window.on({
384+
blur: function () { allowClick = false },
385+
focus: function () { allowClick = true }
386+
})
387+
388+
function releaseScrub (e) {
389+
// delay permission for text selection to allow some room for mouse release by the user
390+
setTimeout(function(){
391+
document.body.classList.remove('unselectable-text');
392+
}, 1000);
393+
394+
$$window.off('.scrubevents');
395+
scrub.off('.scrubevents');
396+
scrub.removeClass('mousetrap');
397+
}
398+
371399
scrub.on('mousedown', function (e) {
372-
scrub.on('mousemove', function (e) {
400+
// prevent undesired text select
401+
document.body.classList.add('unselectable-text');
402+
403+
// mouse movement threshold
404+
scrub.addClass('mousetrap');
405+
406+
scrub.on('mousemove.scrubevents', function (e) {
373407
var el = this;
408+
374409
scrubTimeTrack(e, el);
410+
$window.getSelection().empty();
375411
});
376-
});
377-
378-
scrub.on('mouseup', function (e) {
379-
scrub.unbind('mousemove');
380-
});
381412

382-
scrub.on('dragstart', function (e) {
383-
e.preventDefault();
413+
scrub.on('mouseup.scrubevents mouseleave.scrubevents', releaseScrub);
414+
$$window.on('blur.scrubevents', releaseScrub);
384415
});
385416

386417
return player;

app/public/stylesheets/sass/_components/_default.scss

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ input[type=range]:focus::-webkit-slider-runnable-track {
128128
-webkit-user-select: initial;
129129
}
130130

131+
.unselectable-text,
132+
.unselectable-text * {
133+
-webkit-user-select: none;
134+
}
135+
131136
body {
132137
#toast-container{
133138
& > div {
@@ -147,7 +152,7 @@ body {
147152
box-shadow: none;
148153
}
149154
}
150-
155+
151156
.toast-message a,
152157
.toast-message label {
153158
font-size: 0.900em;
@@ -157,7 +162,7 @@ body {
157162
.toast-message a:hover {
158163
color: #bdc3c7;
159164
}
160-
165+
161166
.toast {
162167
background-color: #333;
163168
}

app/public/stylesheets/sass/_components/_player.scss

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,17 @@
151151
}
152152
}
153153
}
154-
155-
.player_progress {
154+
.player_progress_wrapper {
156155
position: absolute;
157-
top: -20px;
156+
// 1px horizontal protection area for window mouseleave workaround
157+
padding: 0 1px;
158+
top: 0;
158159
left: 0;
159-
display: block;
160160
width: 100%;
161+
}
162+
.player_progress {
163+
position: relative;
164+
top: -20px;
161165
height: 4px;
162166
padding: 20px 0 10px;
163167
overflow: hidden;
@@ -207,6 +211,16 @@
207211
transition: $transitionInstantValue;
208212
}
209213
}
214+
215+
&.mousetrap {
216+
// reset scrub if mouse leaves this area
217+
$topThreshold: 100px;
218+
$bottomThreshold: 50px;
219+
220+
top: -$topThreshold;
221+
padding-top: $topThreshold;
222+
padding-bottom: $bottomThreshold;
223+
}
210224
}
211225

212226
.player_controls span {

0 commit comments

Comments
 (0)