morethanwords
4 years ago
12 changed files with 431 additions and 229 deletions
@ -0,0 +1,144 @@
@@ -0,0 +1,144 @@
|
||||
import InputField from "../inputField"; |
||||
import lottieLoader, { RLottiePlayer } from "../../lib/lottieLoader"; |
||||
|
||||
export default class TrackingMonkey { |
||||
public container: HTMLElement; |
||||
|
||||
protected max = 45; |
||||
protected needFrame = 0; |
||||
|
||||
protected animation: RLottiePlayer; |
||||
protected idleAnimation: RLottiePlayer; |
||||
|
||||
protected loadPromise: Promise<any>; |
||||
|
||||
constructor(protected inputField: InputField, protected size: number) { |
||||
this.container = document.createElement('div'); |
||||
this.container.classList.add('media-sticker-wrapper'); |
||||
|
||||
const input = inputField.input; |
||||
|
||||
input.addEventListener('blur', () => { |
||||
this.playAnimation(0); |
||||
}); |
||||
|
||||
input.addEventListener('input', (e) => { |
||||
this.playAnimation(inputField.value.length); |
||||
}); |
||||
|
||||
/* codeInput.addEventListener('focus', () => { |
||||
playAnimation(Math.max(codeInput.value.length, 1)); |
||||
}); */ |
||||
} |
||||
|
||||
// 1st symbol = frame 15
|
||||
// end symbol = frame 165
|
||||
public playAnimation(length: number) { |
||||
if(!this.animation) return; |
||||
|
||||
length = Math.min(length, 30); |
||||
let frame: number; |
||||
if(length) { |
||||
frame = Math.round(Math.min(this.max, length) * (165 / this.max) + 11.33); |
||||
|
||||
if(this.idleAnimation) { |
||||
this.idleAnimation.stop(true); |
||||
this.idleAnimation.canvas.style.display = 'none'; |
||||
} |
||||
|
||||
this.animation.canvas.style.display = ''; |
||||
} else { |
||||
/* const cb = (frameNo: number) => { |
||||
if(frameNo <= 1) { */ |
||||
/* idleAnimation.play(); |
||||
idleAnimation.canvas.style.display = ''; |
||||
animation.canvas.style.display = 'none'; */ |
||||
/* animation.removeListener('enterFrame', cb); |
||||
} |
||||
}; |
||||
animation.addListener('enterFrame', cb); */ |
||||
|
||||
frame = 0; |
||||
} |
||||
//animation.playSegments([1, 2]);
|
||||
|
||||
const direction = this.needFrame > frame ? -1 : 1; |
||||
//console.log('keydown', length, frame, direction);
|
||||
|
||||
this.animation.setDirection(direction); |
||||
if(this.needFrame !== 0 && frame === 0) { |
||||
this.animation.setSpeed(7); |
||||
} |
||||
/* let diff = Math.abs(needFrame - frame * direction); |
||||
if((diff / 20) > 1) animation.setSpeed(diff / 20 | 0); */ |
||||
this.needFrame = frame; |
||||
|
||||
this.animation.play(); |
||||
|
||||
/* animation.goToAndStop(15, true); */ |
||||
//animation.goToAndStop(length / max * );
|
||||
} |
||||
|
||||
public load() { |
||||
if(this.loadPromise) return this.loadPromise; |
||||
this.loadPromise = Promise.all([ |
||||
lottieLoader.loadAnimationFromURL({ |
||||
container: this.container, |
||||
loop: true, |
||||
autoplay: true, |
||||
width: this.size, |
||||
height: this.size |
||||
}, 'assets/img/TwoFactorSetupMonkeyIdle.tgs').then(animation => { |
||||
this.idleAnimation = animation; |
||||
|
||||
// ! animationIntersector will stop animation instantly
|
||||
if(!this.inputField.value.length) { |
||||
animation.play(); |
||||
} |
||||
}), |
||||
|
||||
lottieLoader.loadAnimationFromURL({ |
||||
container: this.container, |
||||
loop: false, |
||||
autoplay: false, |
||||
width: this.size, |
||||
height: this.size |
||||
}, 'assets/img/TwoFactorSetupMonkeyTracking.tgs').then(_animation => { |
||||
this.animation = _animation; |
||||
|
||||
if(!this.inputField.value.length) { |
||||
this.animation.canvas.style.display = 'none'; |
||||
} |
||||
|
||||
this.animation.addListener('enterFrame', currentFrame => { |
||||
//console.log('enterFrame', currentFrame, needFrame);
|
||||
//let currentFrame = Math.round(e.currentTime);
|
||||
|
||||
if((this.animation.direction === 1 && currentFrame >= this.needFrame) || |
||||
(this.animation.direction === -1 && currentFrame <= this.needFrame)) { |
||||
this.animation.setSpeed(1); |
||||
this.animation.pause(); |
||||
} |
||||
|
||||
if(currentFrame === 0 && this.needFrame === 0) { |
||||
//animation.curFrame = 0;
|
||||
|
||||
if(this.idleAnimation) { |
||||
this.idleAnimation.canvas.style.display = ''; |
||||
this.idleAnimation.play(); |
||||
this.animation.canvas.style.display = 'none'; |
||||
} |
||||
} |
||||
}); |
||||
//console.log(animation.getDuration(), animation.getDuration(true));
|
||||
}) |
||||
]); |
||||
} |
||||
|
||||
public remove() { |
||||
if(this.animation) this.animation.remove(); |
||||
if(this.idleAnimation) this.idleAnimation.remove(); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,100 @@
@@ -0,0 +1,100 @@
|
||||
import { SettingSection } from "../.."; |
||||
import { AccountPassword } from "../../../../layer"; |
||||
import appStickersManager from "../../../../lib/appManagers/appStickersManager"; |
||||
import Button from "../../../button"; |
||||
import SidebarSlider, { SliderSuperTab } from "../../../slider"; |
||||
import { wrapSticker } from "../../../wrappers"; |
||||
import InputField from "../../../inputField"; |
||||
import { attachClickEvent } from "../../../../helpers/dom"; |
||||
import PopupConfirmAction from "../../../popups/confirmAction"; |
||||
import { putPreloader } from "../../../misc"; |
||||
import passwordManager from "../../../../lib/mtproto/passwordManager"; |
||||
|
||||
export default class AppTwoStepVerificationEmailTab extends SliderSuperTab { |
||||
public inputField: InputField; |
||||
public state: AccountPassword; |
||||
public plainPassword: string; |
||||
public newPassword: string; |
||||
public hint: string; |
||||
|
||||
constructor(slider: SidebarSlider) { |
||||
super(slider, true); |
||||
} |
||||
|
||||
protected init() { |
||||
this.container.classList.add('two-step-verification-email'); |
||||
this.title.innerHTML = 'Recovery Email'; |
||||
|
||||
const section = new SettingSection({ |
||||
caption: ' ', |
||||
noDelimiter: true |
||||
}); |
||||
|
||||
const emoji = '💌'; |
||||
const doc = appStickersManager.getAnimatedEmojiSticker(emoji); |
||||
const stickerContainer = document.createElement('div'); |
||||
|
||||
wrapSticker({ |
||||
doc, |
||||
div: stickerContainer, |
||||
loop: false, |
||||
play: true, |
||||
width: 168, |
||||
height: 168, |
||||
emoji |
||||
}).then(() => { |
||||
// this.animation = player;
|
||||
}); |
||||
|
||||
section.content.append(stickerContainer); |
||||
|
||||
const inputContent = section.generateContentElement(); |
||||
|
||||
const inputWrapper = document.createElement('div'); |
||||
inputWrapper.classList.add('input-wrapper'); |
||||
|
||||
const inputField = this.inputField = new InputField({ |
||||
name: 'recovery-email', |
||||
label: 'Recovery Email' |
||||
}); |
||||
|
||||
const btnContinue = Button('btn-primary', {text: 'CONTINUE'}); |
||||
const btnSkip = Button('btn-primary btn-primary-transparent primary', {text: 'SKIP'}); |
||||
|
||||
attachClickEvent(btnSkip, (e) => { |
||||
const popup = new PopupConfirmAction('popup-skip-email', [{ |
||||
text: 'CANCEL', |
||||
isCancel: true |
||||
}, { |
||||
text: 'SKIP', |
||||
callback: () => { |
||||
inputContent.classList.add('sidebar-left-section-disabled'); |
||||
putPreloader(btnSkip); |
||||
passwordManager.updateSettings({ |
||||
hint: this.hint, |
||||
currentPassword: this.plainPassword, |
||||
newPassword: this.newPassword |
||||
}).then(() => { |
||||
|
||||
}); |
||||
}, |
||||
isDanger: true, |
||||
}], { |
||||
title: 'Warning', |
||||
text: 'No, seriously.<br/><br/>If you forget your password, you will<br/>lose access to your Telegram account.<br/>There will be no way to restore it.' |
||||
}); |
||||
|
||||
popup.show(); |
||||
}); |
||||
|
||||
inputWrapper.append(inputField.container, btnContinue, btnSkip); |
||||
|
||||
inputContent.append(inputWrapper); |
||||
|
||||
this.scrollable.container.append(section.container); |
||||
} |
||||
|
||||
onOpenAfterTimeout() { |
||||
this.inputField.input.focus(); |
||||
} |
||||
} |
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
import { SettingSection } from "../.."; |
||||
import { AccountPassword } from "../../../../layer"; |
||||
import appStickersManager from "../../../../lib/appManagers/appStickersManager"; |
||||
import Button from "../../../button"; |
||||
import SidebarSlider, { SliderSuperTab } from "../../../slider"; |
||||
import { wrapSticker } from "../../../wrappers"; |
||||
import InputField from "../../../inputField"; |
||||
import AppTwoStepVerificationEmailTab from "./email"; |
||||
import { attachClickEvent, cancelEvent } from "../../../../helpers/dom"; |
||||
|
||||
export default class AppTwoStepVerificationHintTab extends SliderSuperTab { |
||||
public inputField: InputField; |
||||
public state: AccountPassword; |
||||
public plainPassword: string; |
||||
public newPassword: string; |
||||
|
||||
constructor(slider: SidebarSlider) { |
||||
super(slider, true); |
||||
} |
||||
|
||||
protected init() { |
||||
this.container.classList.add('two-step-verification-hint'); |
||||
this.title.innerHTML = 'Password Hint'; |
||||
|
||||
const section = new SettingSection({ |
||||
caption: ' ', |
||||
noDelimiter: true |
||||
}); |
||||
|
||||
const emoji = '💡'; |
||||
const doc = appStickersManager.getAnimatedEmojiSticker(emoji); |
||||
const stickerContainer = document.createElement('div'); |
||||
|
||||
wrapSticker({ |
||||
doc, |
||||
div: stickerContainer, |
||||
loop: false, |
||||
play: true, |
||||
width: 168, |
||||
height: 168, |
||||
emoji |
||||
}).then(() => { |
||||
// this.animation = player;
|
||||
}); |
||||
|
||||
section.content.append(stickerContainer); |
||||
|
||||
const inputWrapper = document.createElement('div'); |
||||
inputWrapper.classList.add('input-wrapper'); |
||||
|
||||
const inputField = this.inputField = new InputField({ |
||||
name: 'hint', |
||||
label: 'Hint' |
||||
}); |
||||
|
||||
inputField.input.addEventListener('keypress', (e) => { |
||||
if(e.key === 'Enter') { |
||||
return (inputField.value ? btnContinue : btnSkip).click(); |
||||
} |
||||
}); |
||||
|
||||
const goNext = (e: Event, saveHint: boolean) => { |
||||
cancelEvent(e); |
||||
const tab = new AppTwoStepVerificationEmailTab(this.slider); |
||||
tab.state = this.state; |
||||
tab.plainPassword = this.plainPassword; |
||||
tab.newPassword = this.newPassword; |
||||
if(saveHint) { |
||||
tab.hint = inputField.value; |
||||
} |
||||
|
||||
tab.open(); |
||||
}; |
||||
|
||||
const btnContinue = Button('btn-primary', {text: 'CONTINUE'}); |
||||
const btnSkip = Button('btn-primary btn-primary-transparent primary', {text: 'SKIP'}); |
||||
|
||||
attachClickEvent(btnContinue, (e) => goNext(e, true)); |
||||
attachClickEvent(btnSkip, (e) => goNext(e, false)); |
||||
|
||||
inputWrapper.append(inputField.container, btnContinue, btnSkip); |
||||
|
||||
section.content.append(inputWrapper); |
||||
|
||||
this.scrollable.container.append(section.container); |
||||
} |
||||
|
||||
onOpenAfterTimeout() { |
||||
this.inputField.input.focus(); |
||||
} |
||||
} |
Loading…
Reference in new issue