|
|
@ -9,6 +9,10 @@ import { findUpTag } from "../helpers/dom"; |
|
|
|
import Page from "./page"; |
|
|
|
import Page from "./page"; |
|
|
|
import pageAuthCode from "./pageAuthCode"; |
|
|
|
import pageAuthCode from "./pageAuthCode"; |
|
|
|
import pageSignQR from './pageSignQR'; |
|
|
|
import pageSignQR from './pageSignQR'; |
|
|
|
|
|
|
|
import InputField from "../components/inputField"; |
|
|
|
|
|
|
|
import CheckboxField from "../components/checkbox"; |
|
|
|
|
|
|
|
import Button from "../components/button"; |
|
|
|
|
|
|
|
import { isAppleMobile } from "../helpers/userAgent"; |
|
|
|
|
|
|
|
|
|
|
|
type Country = _Country & { |
|
|
|
type Country = _Country & { |
|
|
|
li?: HTMLLIElement[] |
|
|
|
li?: HTMLLIElement[] |
|
|
@ -35,23 +39,33 @@ let onFirstMount = () => { |
|
|
|
|
|
|
|
|
|
|
|
let lastCountrySelected: Country = null; |
|
|
|
let lastCountrySelected: Country = null; |
|
|
|
|
|
|
|
|
|
|
|
var selectCountryCode = page.pageEl.querySelector('input[name="countryCode"]')! as HTMLInputElement; |
|
|
|
const inputWrapper = document.createElement('div'); |
|
|
|
var parent = selectCountryCode.parentElement; |
|
|
|
inputWrapper.classList.add('input-wrapper'); |
|
|
|
|
|
|
|
|
|
|
|
var wrapper = document.createElement('div'); |
|
|
|
const countryInputField = new InputField({ |
|
|
|
wrapper.classList.add('select-wrapper', 'z-depth-3', 'hide'); |
|
|
|
label: 'Country', |
|
|
|
|
|
|
|
name: 'countryCode', |
|
|
|
|
|
|
|
plainText: true |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var list = document.createElement('ul'); |
|
|
|
countryInputField.container.classList.add('input-select'); |
|
|
|
wrapper.appendChild(list); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//let wrapperScroll = OverlayScrollbars(wrapper, (window as any).scrollbarOptions);
|
|
|
|
const countryInput = countryInputField.input as HTMLInputElement; |
|
|
|
let scroll = new Scrollable(wrapper); |
|
|
|
countryInput.autocomplete = 'rrRandomRR'; |
|
|
|
|
|
|
|
|
|
|
|
let initedSelect = false; |
|
|
|
const selectWrapper = document.createElement('div'); |
|
|
|
|
|
|
|
selectWrapper.classList.add('select-wrapper', 'z-depth-3', 'hide'); |
|
|
|
|
|
|
|
|
|
|
|
page.pageEl.querySelector('.a-qr').addEventListener('click', () => { |
|
|
|
const arrowDown = document.createElement('span'); |
|
|
|
pageSignQR.mount(); |
|
|
|
arrowDown.classList.add('arrow', 'arrow-down'); |
|
|
|
}); |
|
|
|
countryInputField.container.append(arrowDown); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const selectList = document.createElement('ul'); |
|
|
|
|
|
|
|
selectWrapper.appendChild(selectList); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const scroll = new Scrollable(selectWrapper); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let initedSelect = false; |
|
|
|
|
|
|
|
|
|
|
|
let initSelect = () => { |
|
|
|
let initSelect = () => { |
|
|
|
initSelect = null; |
|
|
|
initSelect = null; |
|
|
@ -88,20 +102,20 @@ let onFirstMount = () => { |
|
|
|
li.appendChild(span); |
|
|
|
li.appendChild(span); |
|
|
|
|
|
|
|
|
|
|
|
liArr.push(li); |
|
|
|
liArr.push(li); |
|
|
|
list.append(li); |
|
|
|
selectList.append(li); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
c.li = liArr; |
|
|
|
c.li = liArr; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
list.addEventListener('mousedown', function(e) { |
|
|
|
selectList.addEventListener('mousedown', function(e) { |
|
|
|
let target = e.target as HTMLElement; |
|
|
|
let target = e.target as HTMLElement; |
|
|
|
if(target.tagName != 'LI') target = findUpTag(target, 'LI'); |
|
|
|
if(target.tagName != 'LI') target = findUpTag(target, 'LI'); |
|
|
|
|
|
|
|
|
|
|
|
let countryName = target.childNodes[1].textContent;//target.innerText.split('\n').shift();
|
|
|
|
let countryName = target.childNodes[1].textContent;//target.innerText.split('\n').shift();
|
|
|
|
let phoneCode = target.querySelector<HTMLElement>('.phone-code').innerText; |
|
|
|
let phoneCode = target.querySelector<HTMLElement>('.phone-code').innerText; |
|
|
|
|
|
|
|
|
|
|
|
selectCountryCode.value = countryName; |
|
|
|
countryInput.value = countryName; |
|
|
|
lastCountrySelected = countries.find(c => c.name == countryName); |
|
|
|
lastCountrySelected = countries.find(c => c.name == countryName); |
|
|
|
|
|
|
|
|
|
|
|
telEl.value = lastValue = phoneCode; |
|
|
|
telEl.value = lastValue = phoneCode; |
|
|
@ -109,14 +123,14 @@ let onFirstMount = () => { |
|
|
|
//console.log('clicked', e, countryName, phoneCode);
|
|
|
|
//console.log('clicked', e, countryName, phoneCode);
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
parent.appendChild(wrapper); |
|
|
|
countryInputField.container.appendChild(selectWrapper); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
initSelect(); |
|
|
|
initSelect(); |
|
|
|
|
|
|
|
|
|
|
|
let hideTimeout: number; |
|
|
|
let hideTimeout: number; |
|
|
|
|
|
|
|
|
|
|
|
selectCountryCode.addEventListener('focus', function(this: typeof selectCountryCode, e) { |
|
|
|
countryInput.addEventListener('focus', function(this: typeof countryInput, e) { |
|
|
|
if(initSelect) { |
|
|
|
if(initSelect) { |
|
|
|
initSelect(); |
|
|
|
initSelect(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -127,20 +141,20 @@ let onFirstMount = () => { |
|
|
|
|
|
|
|
|
|
|
|
clearTimeout(hideTimeout); |
|
|
|
clearTimeout(hideTimeout); |
|
|
|
|
|
|
|
|
|
|
|
wrapper.classList.remove('hide'); |
|
|
|
selectWrapper.classList.remove('hide'); |
|
|
|
void wrapper.offsetWidth; // reflow
|
|
|
|
void selectWrapper.offsetWidth; // reflow
|
|
|
|
wrapper.classList.add('active'); |
|
|
|
selectWrapper.classList.add('active'); |
|
|
|
}); |
|
|
|
}); |
|
|
|
selectCountryCode.addEventListener('blur', function(this: typeof selectCountryCode, e) { |
|
|
|
countryInput.addEventListener('blur', function(this: typeof countryInput, e) { |
|
|
|
wrapper.classList.remove('active'); |
|
|
|
selectWrapper.classList.remove('active'); |
|
|
|
hideTimeout = window.setTimeout(() => { |
|
|
|
hideTimeout = window.setTimeout(() => { |
|
|
|
wrapper.classList.add('hide'); |
|
|
|
selectWrapper.classList.add('hide'); |
|
|
|
}, 200); |
|
|
|
}, 200); |
|
|
|
|
|
|
|
|
|
|
|
e.cancelBubble = true; |
|
|
|
e.cancelBubble = true; |
|
|
|
}, {capture: true}); |
|
|
|
}, {capture: true}); |
|
|
|
|
|
|
|
|
|
|
|
selectCountryCode.addEventListener('keyup', function(this: typeof selectCountryCode, e) { |
|
|
|
countryInput.addEventListener('keyup', function(this: typeof countryInput, e) { |
|
|
|
if(e.ctrlKey || e.key == 'Control') return false; |
|
|
|
if(e.ctrlKey || e.key == 'Control') return false; |
|
|
|
|
|
|
|
|
|
|
|
//let i = new RegExp('^' + this.value, 'i');
|
|
|
|
//let i = new RegExp('^' + this.value, 'i');
|
|
|
@ -169,24 +183,31 @@ let onFirstMount = () => { |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
let arrowDown = page.pageEl.querySelector('.arrow-down') as HTMLSpanElement; |
|
|
|
|
|
|
|
arrowDown.addEventListener('mousedown', function(this: typeof arrowDown, e) { |
|
|
|
arrowDown.addEventListener('mousedown', function(this: typeof arrowDown, e) { |
|
|
|
e.cancelBubble = true; |
|
|
|
e.cancelBubble = true; |
|
|
|
e.preventDefault(); |
|
|
|
e.preventDefault(); |
|
|
|
if(selectCountryCode.matches(':focus')) selectCountryCode.blur(); |
|
|
|
if(countryInput.matches(':focus')) countryInput.blur(); |
|
|
|
else selectCountryCode.focus(); |
|
|
|
else countryInput.focus(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
let pasted = false; |
|
|
|
let pasted = false; |
|
|
|
let lastValue = ''; |
|
|
|
let lastValue = ''; |
|
|
|
let telEl = page.pageEl.querySelector('input[name="phone"]') as HTMLInputElement; |
|
|
|
|
|
|
|
|
|
|
|
const telInputField = new InputField({ |
|
|
|
|
|
|
|
label: 'Phone Number', |
|
|
|
|
|
|
|
plainText: true, |
|
|
|
|
|
|
|
name: 'phone' |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
let telEl = telInputField.input as HTMLInputElement; |
|
|
|
|
|
|
|
telEl.type = 'tel'; |
|
|
|
|
|
|
|
telEl.autocomplete = 'rr55RandomRR55'; |
|
|
|
const telLabel = telEl.nextElementSibling as HTMLLabelElement; |
|
|
|
const telLabel = telEl.nextElementSibling as HTMLLabelElement; |
|
|
|
telEl.addEventListener('input', function(this: typeof telEl, e) { |
|
|
|
telEl.addEventListener('input', function(this: typeof telEl, e) { |
|
|
|
//console.log('input', this.value);
|
|
|
|
//console.log('input', this.value);
|
|
|
|
this.classList.remove('error'); |
|
|
|
this.classList.remove('error'); |
|
|
|
|
|
|
|
|
|
|
|
const diff = Math.abs(this.value.length - lastValue.length); |
|
|
|
const diff = Math.abs(this.value.length - lastValue.length); |
|
|
|
if(diff > 1 && !pasted) { |
|
|
|
if(diff > 1 && !pasted && isAppleMobile) { |
|
|
|
this.value = lastValue + this.value; |
|
|
|
this.value = lastValue + this.value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -200,8 +221,8 @@ let onFirstMount = () => { |
|
|
|
//console.log(formatted, country);
|
|
|
|
//console.log(formatted, country);
|
|
|
|
|
|
|
|
|
|
|
|
let countryName = country ? country.name : ''/* 'Unknown' */; |
|
|
|
let countryName = country ? country.name : ''/* 'Unknown' */; |
|
|
|
if(countryName != selectCountryCode.value && (!lastCountrySelected || !country || lastCountrySelected.phoneCode != country.phoneCode)) { |
|
|
|
if(countryName != countryInput.value && (!lastCountrySelected || !country || lastCountrySelected.phoneCode != country.phoneCode)) { |
|
|
|
selectCountryCode.value = countryName; |
|
|
|
countryInput.value = countryName; |
|
|
|
lastCountrySelected = country; |
|
|
|
lastCountrySelected = country; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -226,7 +247,7 @@ let onFirstMount = () => { |
|
|
|
//console.log('keypress', this.value);
|
|
|
|
//console.log('keypress', this.value);
|
|
|
|
if(!btnNext.style.visibility &&/* this.value.length >= 9 && */ e.key == 'Enter') { |
|
|
|
if(!btnNext.style.visibility &&/* this.value.length >= 9 && */ e.key == 'Enter') { |
|
|
|
return btnNext.click(); |
|
|
|
return btnNext.click(); |
|
|
|
} else if(/\D/.test(e.key)) { |
|
|
|
} else if(/\D/.test(e.key) && !(e.metaKey || e.ctrlKey)) { |
|
|
|
e.preventDefault(); |
|
|
|
e.preventDefault(); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
@ -236,8 +257,11 @@ let onFirstMount = () => { |
|
|
|
this.removeAttribute('readonly'); // fix autocomplete
|
|
|
|
this.removeAttribute('readonly'); // fix autocomplete
|
|
|
|
});*/ |
|
|
|
});*/ |
|
|
|
|
|
|
|
|
|
|
|
/* authorizer.auth(2); |
|
|
|
const signedCheckboxField = CheckboxField('Keep me signed in', 'keepSession'); |
|
|
|
networkerFactory.startAll(); */ |
|
|
|
signedCheckboxField.input.checked = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
btnNext = Button('btn-primary', {text: 'NEXT'}); |
|
|
|
|
|
|
|
btnNext.style.visibility = 'hidden'; |
|
|
|
|
|
|
|
|
|
|
|
btnNext.addEventListener('click', function(this: HTMLElement, e) { |
|
|
|
btnNext.addEventListener('click', function(this: HTMLElement, e) { |
|
|
|
this.setAttribute('disabled', 'true'); |
|
|
|
this.setAttribute('disabled', 'true'); |
|
|
@ -278,32 +302,55 @@ let onFirstMount = () => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const qrDiv = document.createElement('div'); |
|
|
|
|
|
|
|
qrDiv.classList.add('qr'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const qrLink = document.createElement('a'); |
|
|
|
|
|
|
|
qrLink.href = '#'; |
|
|
|
|
|
|
|
qrLink.classList.add('a-qr'); |
|
|
|
|
|
|
|
qrLink.innerText = 'Quick log in using QR code'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qrDiv.append(qrLink); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qrLink.addEventListener('click', () => { |
|
|
|
|
|
|
|
pageSignQR.mount(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inputWrapper.append(countryInputField.container, telInputField.container, signedCheckboxField.label, btnNext, qrDiv); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
page.pageEl.querySelector('.container').append(inputWrapper); |
|
|
|
|
|
|
|
|
|
|
|
let tryAgain = () => { |
|
|
|
let tryAgain = () => { |
|
|
|
apiManager.invokeApi('help.getNearestDc').then((nearestDcResult) => { |
|
|
|
apiManager.invokeApi('help.getNearestDc').then((nearestDcResult) => { |
|
|
|
const dcs = [1, 2, 3, 4, 5]; |
|
|
|
const dcs = [1, 2, 3, 4, 5]; |
|
|
|
//dcs.splice(nearestDcResult.this_dc - 1, 1);
|
|
|
|
const done: number[] = [nearestDcResult.this_dc]; |
|
|
|
|
|
|
|
|
|
|
|
let promise: Promise<any>; |
|
|
|
let promise: Promise<any>; |
|
|
|
if(nearestDcResult.nearest_dc != nearestDcResult.this_dc) { |
|
|
|
if(nearestDcResult.nearest_dc != nearestDcResult.this_dc) { |
|
|
|
//MTProto.apiManager.baseDcID = nearestDcResult.nearest_dc;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
promise = apiManager.getNetworker(nearestDcResult.nearest_dc).then(() => { |
|
|
|
promise = apiManager.getNetworker(nearestDcResult.nearest_dc).then(() => { |
|
|
|
|
|
|
|
done.push(nearestDcResult.nearest_dc) |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
(promise || Promise.resolve()).then(() => { |
|
|
|
(promise || Promise.resolve()).then(() => { |
|
|
|
dcs.forEach(dcId => { |
|
|
|
const g = () => { |
|
|
|
apiManager.getNetworker(dcId, {fileDownload: true}); |
|
|
|
const dcId = dcs.shift(); |
|
|
|
}); |
|
|
|
if(!dcId) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(() => { // * если одновременно запросить все нетворкеры, не будет проходить запрос на код
|
|
|
|
|
|
|
|
apiManager.getNetworker(dcId, {fileDownload: true}).finally(g); |
|
|
|
|
|
|
|
}, done.includes(dcId) ? 0 : 3000); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return nearestDcResult; |
|
|
|
return nearestDcResult; |
|
|
|
}).then((nearestDcResult) => { |
|
|
|
}).then((nearestDcResult) => { |
|
|
|
let country = countries.find((c) => c.code == nearestDcResult.country); |
|
|
|
let country = countries.find((c) => c.code === nearestDcResult.country); |
|
|
|
if(country) { |
|
|
|
if(country) { |
|
|
|
if(!selectCountryCode.value.length && !telEl.value.length) { |
|
|
|
if(!countryInput.value.length && !telEl.value.length) { |
|
|
|
selectCountryCode.value = country.name; |
|
|
|
countryInput.value = country.name; |
|
|
|
lastCountrySelected = country; |
|
|
|
lastCountrySelected = country; |
|
|
|
telEl.value = lastValue = '+' + country.phoneCode.split(' and ').shift(); |
|
|
|
telEl.value = lastValue = '+' + country.phoneCode.split(' and ').shift(); |
|
|
|
} |
|
|
|
} |
|
|
@ -317,12 +364,10 @@ let onFirstMount = () => { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const page = new Page('page-sign', true, onFirstMount, () => { |
|
|
|
const page = new Page('page-sign', true, onFirstMount, () => { |
|
|
|
if(!btnNext) { |
|
|
|
if(btnNext) { |
|
|
|
btnNext = page.pageEl.querySelector('button'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
btnNext.textContent = 'NEXT'; |
|
|
|
btnNext.textContent = 'NEXT'; |
|
|
|
btnNext.removeAttribute('disabled'); |
|
|
|
btnNext.removeAttribute('disabled'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
appStateManager.pushToState('authState', {_: 'authStateSignIn'}); |
|
|
|
appStateManager.pushToState('authState', {_: 'authStateSignIn'}); |
|
|
|
appStateManager.saveState(); |
|
|
|
appStateManager.saveState(); |
|
|
|