Restore clickaway and typeahead functionality

This commit is contained in:
An Phan 2016-06-25 23:41:10 +08:00
parent ccf93c0890
commit 11c07bffff
No known key found for this signature in database
GPG key ID: 05536BB4BCDC02A2
7 changed files with 23 additions and 22 deletions

View file

@ -42,7 +42,6 @@
"rangetouch": "0.0.9", "rangetouch": "0.0.9",
"sinon": "^1.17.2", "sinon": "^1.17.2",
"vue": "^2.0.0-alpha.6", "vue": "^2.0.0-alpha.6",
"vue-clickaway": "^1.1.1",
"vue-hot-reload-api": "^1.3.2", "vue-hot-reload-api": "^1.3.2",
"vue-resource": "^0.7.0", "vue-resource": "^0.7.0",
"vueify": "^9.1.0", "vueify": "^9.1.0",

View file

@ -36,7 +36,7 @@
import { event, showOverlay, hideOverlay, loadMainView, forceReloadWindow } from './utils'; import { event, showOverlay, hideOverlay, loadMainView, forceReloadWindow } from './utils';
import { sharedStore, queueStore, songStore, userStore, preferenceStore as preferences } from './stores'; import { sharedStore, queueStore, songStore, userStore, preferenceStore as preferences } from './stores';
import { playback, ls } from './services'; import { playback, ls } from './services';
import focusDirective from './directives/focus'; import { focusDirective, clickawayDirective } from './directives';
export default { export default {
components: { siteHeader, siteFooter, mainWrapper, overlay, loginForm, editSongsForm }, components: { siteHeader, siteFooter, mainWrapper, overlay, loginForm, editSongsForm },
@ -196,6 +196,7 @@
// and the global directives // and the global directives
Vue.directive('koel-focus', focusDirective); Vue.directive('koel-focus', focusDirective);
Vue.directive('koel-clickaway',clickawayDirective);
</script> </script>
<style lang="sass"> <style lang="sass">

View file

@ -35,14 +35,14 @@
<typeahead <typeahead
:items="artistState.artists" :items="artistState.artists"
:options="artistTypeaheadOptions" :options="artistTypeaheadOptions"
:value.sync="formData.artistName"></typeahead> v-model="formData.artistName"></typeahead>
</div> </div>
<div class="form-row"> <div class="form-row">
<label>Album</label> <label>Album</label>
<typeahead <typeahead
:items="albumState.albums" :items="albumState.albums"
:options="albumTypeaheadOptions" :options="albumTypeaheadOptions"
:value.sync="formData.albumName"></typeahead> v-model="formData.albumName"></typeahead>
</div> </div>
<div class="form-row"> <div class="form-row">
<label class="small"> <label class="small">

View file

@ -1,5 +1,5 @@
<template> <template>
<div class="add-to-playlist" v-show="showing"> <div class="add-to" v-show="showing" v-koel-clickaway="close">
<p>Add {{ songs.length | pluralize('song') }} to</p> <p>Add {{ songs.length | pluralize('song') }} to</p>
<ul> <ul>
@ -81,11 +81,8 @@
this.close(); this.close();
}, },
/**
* Override the method from "songMenuMethods" mixin for this own logic.
*/
close() { close() {
event.emit('add-to-menu:close'); this.$parent.closeAddToMenu();
}, },
}, },
}; };
@ -95,7 +92,7 @@
@import "../../../sass/partials/_vars.scss"; @import "../../../sass/partials/_vars.scss";
@import "../../../sass/partials/_mixins.scss"; @import "../../../sass/partials/_mixins.scss";
.add-to-playlist { .add-to {
@include context-menu(); @include context-menu();
position: absolute; position: absolute;

View file

@ -2,13 +2,14 @@
<div> <div>
<input type="text" <input type="text"
:placeholder="options.placeholder || 'No change'" :placeholder="options.placeholder || 'No change'"
v-model="value" v-model="mutatedValue"
@keydown.down.prevent="down" @keydown.down.prevent="down"
@keydown.up.prevent="up" @keydown.up.prevent="up"
@keydown.enter.prevent.stop="enter" @keydown.enter.prevent.stop="enter"
@keydown.tab="enter" @keydown.tab="enter"
@keyup="keyup" @keyup="keyup"
@click="showingResult = true" @click="showingResult = true"
v-koel-clickaway="hideResults"
> >
<ul class="result" v-show="showingResult"> <ul class="result" v-show="showingResult">
<li v-for="item in displayedItems" @click.prevent="resultClick($event)"> <li v-for="item in displayedItems" @click.prevent="resultClick($event)">
@ -29,6 +30,7 @@
return { return {
filter: '', filter: '',
showingResult: false, showingResult: false,
mutatedValue: this.value,
}; };
}, },
@ -100,7 +102,7 @@
return; return;
} }
this.filter = this.value; this.filter = this.mutatedValue;
this.showingResult = true; this.showingResult = true;
}, },
@ -113,7 +115,10 @@
}, },
apply() { apply() {
this.value = $(this.$el).find('.result li.selected').text() || this.value; this.mutatedValue = $(this.$el).find('.result li.selected').text().trim() || this.mutatedValue;
// In Vue 2.0, we can use v-model on custom components like this.
// $emit an 'input' event in this format, and we're set.
this.$emit('input', { target: { value: this.mutatedValue } });
}, },
/** /**
@ -134,6 +139,10 @@
elem.scrollIntoView(alignTop); elem.scrollIntoView(alignTop);
} }
}, },
hideResults() {
this.showingResult = false;
},
}, },
}; };
</script> </script>

View file

@ -3,7 +3,7 @@ import Vue from 'vue';
/** /**
* A simple directive to set focus into an input field when it's shown. * A simple directive to set focus into an input field when it's shown.
*/ */
export default { export const focusDirective = {
update(el, { value }) { update(el, { value }) {
if (!value) { if (!value) {
return; return;

View file

@ -54,14 +54,9 @@ export default {
updateMeta(meta) { updateMeta(meta) {
this.meta = assign(this.meta, meta); this.meta = assign(this.meta, meta);
}, },
},
created() { closeAddToMenu() {
event.on({ this.showingAddToMenu = false;
/** },
* Listen to add-to-menu:close event to set showingAddToMenu to false (and subsequently close the menu).
*/
'add-to-menu:close': () => this.showingAddToMenu = false,
});
}, },
}; };