#4: Keep the dropdown menu open after selecting a track or album download in a cacheable format.

This commit is contained in:
Peter Deltchev 2015-11-02 20:15:26 -08:00
parent b2408e3d84
commit b441a58819
5 changed files with 32 additions and 13 deletions

View file

@ -1,7 +1,7 @@
<div class="resource-details album-details" bindonce="album"> <div class="resource-details album-details" bindonce="album">
<ul class="dropdowns"> <ul class="dropdowns">
<li class="dropdown"> <li class="dropdown">
<a href="#" class="btn btn-small btn-info dropdown-toggle" ng-disabled="album.is_downloadable == 0"> <a href="#" class="btn btn-small btn-info dropdown-toggle" ng-disabled="album.is_downloadable == 0" auto-close="outsideClick">
Downloads Downloads
</a> </a>
<ul class="dropdown-menu" ng-show="album.is_downloadable == 1"> <ul class="dropdown-menu" ng-show="album.is_downloadable == 1">

View file

@ -1,7 +1,7 @@
<div class="resource-details track-details" bindonce="track"> <div class="resource-details track-details" bindonce="track">
<ul class="dropdowns"> <ul class="dropdowns">
<li class="dropdown"> <li class="dropdown">
<a href="#" class="btn btn-small btn-info dropdown-toggle" ng-disabled="track.is_downloadable == 0"> <a href="#" class="btn btn-small btn-info dropdown-toggle" ng-disabled="track.is_downloadable == 0" auto-close="outsideClick">
Downloads Downloads
</a> </a>
<ul class="dropdown-menu" ng-show="track.is_downloadable == 1"> <ul class="dropdown-menu" ng-show="track.is_downloadable == 1">

View file

@ -52,5 +52,5 @@ angular.module('ponyfm').controller "album", [
$timeout $scope.getCachedAlbum(id, format), 5000 $timeout $scope.getCachedAlbum(id, format), 5000
else else
$scope.isInProgress = false $scope.isInProgress = false
$window.open $scope.albumUrl, '_blank' $window.open $scope.albumUrl
] ]

View file

@ -74,15 +74,15 @@ angular.module('ponyfm').controller "track", [
playlist.message = res.message playlist.message = res.message
$scope.getCachedTrack = (id, format) -> $scope.getCachedTrack = (id, format) ->
$scope.isInProgress = true $scope.isInProgress = true
cachedTrack.download('tracks', id, format).then (response) -> cachedTrack.download('tracks', id, format).then (response) ->
$scope.trackUrl = response $scope.trackUrl = response
if $scope.trackUrl == 'error' if $scope.trackUrl == 'error'
$scope.isInProgress = false $scope.isInProgress = false
else if $scope.trackUrl == 'pending' else if $scope.trackUrl == 'pending'
$timeout $scope.getCachedTrack(id, format), 5000 $timeout $scope.getCachedTrack(id, format), 5000
else else
$scope.isInProgress = false $scope.isInProgress = false
$window.open $scope.trackUrl, '_blank' $window.location = $scope.trackUrl#, '_blank'
] ]

View file

@ -1269,10 +1269,29 @@ angular.module('ui.bootstrap.dropdownToggle', []).directive('dropdownToggle', ['
element.parent().addClass('open'); element.parent().addClass('open');
openElement = element; openElement = element;
closeMenu = function (event) { closeMenu = function (event) {
// Dropdowns with with the `auto-close="outsideClick"` attribute are handled differently.
// They will only close if the user clicks somewhere outside of the dropdown menu.
//
// => Partially backported from: https://github.com/angular-ui/bootstrap/pull/3045/files
if ('autoClose' in attrs && attrs.autoClose === 'outsideClick') {
if (typeof event !== 'undefined' && !element.parent()[0].contains(event.target)) {
// Only close the menu if we detect a click outside the element.
$document.unbind('click', closeMenu);
element.parent().removeClass('open');
closeMenu = angular.noop;
openElement = null;
}
return;
}
// If this isn't an "outside click", handle it as usual.
if (event) { if (event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
} }
$document.unbind('click', closeMenu); $document.unbind('click', closeMenu);
element.parent().removeClass('open'); element.parent().removeClass('open');
closeMenu = angular.noop; closeMenu = angular.noop;