1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import util from '../../ons/util.js';
|
18 | import animit from '../../ons/animit.js';
|
19 | import BaseAnimator from '../../ons/base-animator.js';
|
20 |
|
21 | export class PopoverAnimator extends BaseAnimator {
|
22 |
|
23 | |
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | constructor({timing = 'cubic-bezier(.1, .7, .4, 1)', delay = 0, duration = 0.2} = {}) {
|
30 | super({ timing, delay, duration });
|
31 | }
|
32 |
|
33 | show(popover, callback) {
|
34 | callback();
|
35 | }
|
36 |
|
37 | hide(popover, callback) {
|
38 | callback();
|
39 | }
|
40 |
|
41 | _animate(element, {from, to, options, callback, restore = false, animation}) {
|
42 | options = util.extend({}, this.options, options);
|
43 |
|
44 | if (animation) {
|
45 | from = animation.from;
|
46 | to = animation.to;
|
47 | }
|
48 |
|
49 | animation = animit(element);
|
50 | if (restore) {
|
51 | animation = animation.saveStyle();
|
52 | }
|
53 | animation = animation.queue(from).wait(this.delay).queue({
|
54 | css: to,
|
55 | duration: this.duration,
|
56 | timing: this.timing
|
57 | });
|
58 | if (restore) {
|
59 | animation = animation.restoreStyle();
|
60 | }
|
61 | if (callback) {
|
62 | animation = animation.queue((done) => {
|
63 | callback();
|
64 | done();
|
65 | });
|
66 | }
|
67 | return animation;
|
68 | }
|
69 |
|
70 | _animateAll(element, animations) {
|
71 | Object.keys(animations).forEach(key => this._animate(element[key], animations[key]).play());
|
72 | }
|
73 |
|
74 | }
|
75 |
|
76 | const fade = {
|
77 | out: {
|
78 | from: {opacity: 1.0},
|
79 | to: {opacity: 0}
|
80 | },
|
81 | in: {
|
82 | from: {opacity: 0},
|
83 | to: {opacity: 1.0}
|
84 | }
|
85 | };
|
86 |
|
87 | export class MDFadePopoverAnimator extends PopoverAnimator {
|
88 | show(popover, callback) {
|
89 | this._animateAll(popover, {
|
90 | _mask: fade.in,
|
91 | _popover: {animation: fade.in, restore: true, callback}
|
92 | });
|
93 | }
|
94 |
|
95 | hide(popover, callback) {
|
96 | this._animateAll(popover, {
|
97 | _mask: fade.out,
|
98 | _popover: {animation: fade.out, restore: true, callback}
|
99 | });
|
100 | }
|
101 | }
|
102 |
|
103 | export class IOSFadePopoverAnimator extends MDFadePopoverAnimator {
|
104 | show(popover, callback) {
|
105 | this._animateAll(popover, {
|
106 | _mask: fade.in,
|
107 | _popover: {
|
108 | from: {
|
109 | transform: 'scale3d(1.3, 1.3, 1.0)',
|
110 | opacity: 0
|
111 | },
|
112 | to: {
|
113 | transform: 'scale3d(1.0, 1.0, 1.0)',
|
114 | opacity: 1.0
|
115 | },
|
116 | restore: true,
|
117 | callback
|
118 | }
|
119 | });
|
120 | }
|
121 | }
|