summaryrefslogtreecommitdiff
path: root/src/web/app/common
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-03-02 18:46:08 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-03-02 18:46:08 +0900
commitd10be711613a897e0c4356993ea98af81b1c0c0e (patch)
treef15fa90ac5647c7076e2b4fcc36e27cd00f424c8 /src/web/app/common
parentoops (diff)
downloadmisskey-d10be711613a897e0c4356993ea98af81b1c0c0e.tar.gz
misskey-d10be711613a897e0c4356993ea98af81b1c0c0e.tar.bz2
misskey-d10be711613a897e0c4356993ea98af81b1c0c0e.zip
#1161, #1163
Diffstat (limited to 'src/web/app/common')
-rw-r--r--src/web/app/common/mios.ts2
-rw-r--r--src/web/app/common/scripts/check-for-update.ts12
-rw-r--r--src/web/app/common/views/components/index.ts2
-rw-r--r--src/web/app/common/views/components/switch.vue170
4 files changed, 182 insertions, 4 deletions
diff --git a/src/web/app/common/mios.ts b/src/web/app/common/mios.ts
index 6cc441cd1d..3701a24c30 100644
--- a/src/web/app/common/mios.ts
+++ b/src/web/app/common/mios.ts
@@ -27,7 +27,7 @@ export type API = {
dialog: (opts: {
title: string;
text: string;
- actions: Array<{
+ actions?: Array<{
text: string;
id?: string;
}>;
diff --git a/src/web/app/common/scripts/check-for-update.ts b/src/web/app/common/scripts/check-for-update.ts
index fe539407da..3e7eb79d8b 100644
--- a/src/web/app/common/scripts/check-for-update.ts
+++ b/src/web/app/common/scripts/check-for-update.ts
@@ -1,8 +1,8 @@
import MiOS from '../mios';
import { version } from '../../config';
-export default async function(mios: MiOS) {
- const meta = await mios.getMeta();
+export default async function(mios: MiOS, force = false, silent = false) {
+ const meta = await mios.getMeta(force);
if (meta.version != version) {
localStorage.setItem('should-refresh', 'true');
@@ -20,6 +20,12 @@ export default async function(mios: MiOS) {
console.error(e);
}
- alert('%i18n:common.update-available%'.replace('{newer}', meta.version).replace('{current}', version));
+ if (!silent) {
+ alert('%i18n:common.update-available%'.replace('{newer}', meta.version).replace('{current}', version));
+ }
+
+ return meta.version;
+ } else {
+ return null;
}
}
diff --git a/src/web/app/common/views/components/index.ts b/src/web/app/common/views/components/index.ts
index ab0f1767d4..5274920228 100644
--- a/src/web/app/common/views/components/index.ts
+++ b/src/web/app/common/views/components/index.ts
@@ -20,6 +20,7 @@ import messagingRoom from './messaging-room.vue';
import urlPreview from './url-preview.vue';
import twitterSetting from './twitter-setting.vue';
import fileTypeIcon from './file-type-icon.vue';
+import Switch from './switch.vue';
Vue.component('mk-signin', signin);
Vue.component('mk-signup', signup);
@@ -41,3 +42,4 @@ Vue.component('mk-messaging-room', messagingRoom);
Vue.component('mk-url-preview', urlPreview);
Vue.component('mk-twitter-setting', twitterSetting);
Vue.component('mk-file-type-icon', fileTypeIcon);
+Vue.component('mk-switch', Switch);
diff --git a/src/web/app/common/views/components/switch.vue b/src/web/app/common/views/components/switch.vue
new file mode 100644
index 0000000000..fc12e00540
--- /dev/null
+++ b/src/web/app/common/views/components/switch.vue
@@ -0,0 +1,170 @@
+<template>
+<div
+ class="mk-switch"
+ :class="{ disabled, checked }"
+ role="switch"
+ :aria-checked="checked"
+ :aria-disabled="disabled"
+ @click="switchValue"
+ @mouseover="mouseenter"
+>
+ <input
+ type="checkbox"
+ @change="handleChange"
+ ref="input"
+ :disabled="disabled"
+ @keydown.enter="switchValue"
+ >
+ <span class="button">
+ <span :style="{ transform }"></span>
+ </span>
+ <span class="label">
+ <span :aria-hidden="!checked">{{ text }}</span>
+ <p :aria-hidden="!checked">
+ <slot></slot>
+ </p>
+ </span>
+</div>
+</template>
+
+<script lang="ts">
+import Vue from 'vue';
+export default Vue.extend({
+ props: {
+ value: {
+ type: Boolean,
+ default: false
+ },
+ disabled: {
+ type: Boolean,
+ default: false
+ },
+ text: String
+ },/*
+ created() {
+ if (!~[true, false].indexOf(this.value)) {
+ this.$emit('input', false);
+ }
+ },*/
+ computed: {
+ checked(): boolean {
+ return this.value;
+ },
+ transform(): string {
+ return this.checked ? 'translate3d(20px, 0, 0)' : '';
+ }
+ },
+ watch: {
+ value() {
+ (this.$refs.input as any).checked = this.checked;
+ }
+ },
+ mounted() {
+ (this.$refs.input as any).checked = this.checked;
+ },
+ methods: {
+ mouseenter() {
+ (this.$el).style.transition = 'all 0s';
+ },
+ handleChange() {
+ (this.$el).style.transition = 'all 0.3s';
+ this.$emit('input', !this.checked);
+ this.$emit('change', !this.checked);
+ this.$nextTick(() => {
+ // set input's checked property
+ // in case parent refuses to change component's value
+ (this.$refs.input as any).checked = this.checked;
+ });
+ },
+ switchValue() {
+ !this.disabled && this.handleChange();
+ }
+ }
+});
+</script>
+
+<style lang="stylus" scoped>
+.mk-switch
+ display flex
+ cursor pointer
+ transition all 0.3s
+
+ > *
+ user-select none
+
+ &.disabled
+ opacity 0.6
+ cursor not-allowed
+
+ &.checked
+ > .button
+ background-color $theme-color
+ border-color $theme-color
+
+ > .label
+ > span
+ color $theme-color
+
+ &:hover
+ > .label
+ > span
+ color darken($theme-color, 10%)
+
+ > .button
+ background darken($theme-color, 10%)
+ border-color darken($theme-color, 10%)
+
+ &:hover
+ > .label
+ > span
+ color #2e3338
+
+ > .button
+ background #ced2da
+ border-color #ced2da
+
+ > input
+ position absolute
+ width 0
+ height 0
+ opacity 0
+ margin 0
+
+ > .button
+ display inline-block
+ margin 0
+ width 40px
+ height 20px
+ background #dcdfe6
+ border 1px solid #dcdfe6
+ outline none
+ border-radius 10px
+ transition inherit
+
+ > *
+ position absolute
+ top 1px
+ left 1px
+ border-radius 100%
+ transition transform 0.3s
+ width 16px
+ height 16px
+ background-color #fff
+
+ > .label
+ margin-left 8px
+ display block
+ font-size 14px
+ cursor pointer
+ transition inherit
+
+ > span
+ line-height 20px
+ color #4a535a
+ transition inherit
+
+ > p
+ margin 0
+ color #9daab3
+
+</style>