#1: IT'S ALIVE!

This commit is contained in:
Peter Deltchev 2016-01-16 19:22:04 -08:00
parent 6b5d3f67a3
commit 8960d11869
4 changed files with 30 additions and 22 deletions

View file

@ -1,7 +1,7 @@
<div class="search" ng-blur="searchInProgress = false">
<input class="search-input" type="text" placeholder="Search&hellip;" ng-model="searchQuery" ng-keyup="quickSearch()" pfm-popup="search-results" />
<input class="search-input" type="text" placeholder="Search&hellip;" ng-model="searchQuery" pfm-popup="search-results" />
<div class="search-results pfm-popup" id="search-results" ng-show="searchInProgress">
<div class="search-results pfm-popup" id="search-results">
<h3 class="-section-header">Matching tracks</h3>
<pfm-tracks-list tracks="tracks"></pfm-tracks-list>

View file

@ -29,10 +29,11 @@ angular.module('ponyfm').directive 'pfmPopup', () ->
open = false
documentClickHandler = () ->
documentClickHandler = (event) ->
return if !open
$popup.removeClass 'open'
open = false
return true
calculatePosition = ->
$popup.parents().each () ->
@ -79,7 +80,7 @@ angular.module('ponyfm').directive 'pfmPopup', () ->
e.preventDefault()
e.stopPropagation()
if open
if open and not $element.is(':focus')
open = false
$popup.removeClass 'open'
return

View file

@ -24,7 +24,7 @@ angular.module('ponyfm').directive 'pfmSearch', () ->
controller: [
'$scope', 'search'
($scope, search) ->
$scope.searchQuery = null
$scope.searchQuery = ''
$scope.searchInProgress = false
$scope.tracks = []
@ -33,17 +33,21 @@ angular.module('ponyfm').directive 'pfmSearch', () ->
$scope.users = []
clearResults = ()->
$scope.tracks = []
$scope.albums = []
$scope.playlists = []
$scope.users = []
$scope.tracks.length = 0
$scope.albums.length = 0
$scope.playlists.length = 0
$scope.users.length = 0
$scope.quickSearch = ()->
$scope.$watch 'searchQuery', _.debounce((searchQuery)->
$scope.$apply ()->
clearResults()
return if searchQuery.length <3
$scope.searchInProgress = true
search.searchAllContent($scope.searchQuery)
.done (results)->
search.searchAllContent(searchQuery)
.then (results)->
for track in results.tracks
$scope.tracks.push(track)
@ -55,5 +59,5 @@ angular.module('ponyfm').directive 'pfmSearch', () ->
for user in results.users
$scope.users.push(user)
, 500)
]

View file

@ -26,6 +26,9 @@ angular.module('ponyfm').factory('search', [
.success (results)->
searchDef.resolve(results.results)
.error (response)->
searchDef.reject(response)
searchDef.promise()
self