Advertisement
Guest User

Untitled

a guest
May 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export class  loadForm  {
  2.         private readonly REGISTRATION:string ='registration';
  3.         private readonly REGIBUTTON:string ='reg-button';
  4.         private readonly EMAILREGEXP:any = /^[\w\.\d-_]+@[\w\.\d-_]+\.\w{2,4}$/i;
  5.         private  inputArray;
  6.         private  ReigsterFormCollections;
  7.         private  deathStar;
  8.         private  deathOnAudio;
  9.         private  topList;
  10.         private  ModalsWindow;
  11.  
  12.     constructor() {
  13.             this.findWitchClicked();
  14.         }
  15.         addMusic(url:string):void {
  16.             this.deathOnAudio = new Audio();
  17.             this.deathOnAudio.src = url;
  18.             this.deathOnAudio.play();
  19.         };
  20.          setUser(UserData):void {
  21.             this.topList = JSON.parse(localStorage.getItem('topList')||'[]');
  22.             let currentUser = {
  23.                 firstName:UserData[0],
  24.                 secondName:UserData[1],
  25.                 email:UserData[2]
  26.             };
  27.             this.topList.push(currentUser);
  28.             localStorage.setItem('topList',JSON.stringify(this.topList));
  29.         }
  30.          CreateAjaxRequest(UrlName,background){
  31.             $(document).ready(function () {
  32.                 $.ajax({
  33.                     url: UrlName,
  34.                     type:'GET',
  35.                     dataType:'text',
  36.                     async: false,
  37.                     success:function (response) {
  38.                         $('body').html(response);
  39.                         $('body').css('background-image', 'url('+'"'+ background + '"' +')');
  40.                     }
  41.                 })
  42.             });
  43.         }
  44.     ShowModal(ErrorFlag):void {
  45.         if (ErrorFlag === 0) {
  46.             this.ModalsWindow = document.querySelector('.modal-window');
  47.             this.ModalsWindow.style.display = 'block';
  48.         }
  49.     }
  50.         CreateMyRequered():boolean{//Has Error with red boarder
  51.             this.ReigsterFormCollections = document.querySelectorAll('.register');
  52.             for(let i=0;i<this.ReigsterFormCollections.length;i++){
  53.                 if(this.ReigsterFormCollections[i].value ==='' || (!this.EMAILREGEXP.test(this.ReigsterFormCollections[2].value)))
  54.                 {
  55.                     if(this.ReigsterFormCollections.type='email' && (!this.EMAILREGEXP.test(this.ReigsterFormCollections[2].value)))
  56.                         this.ReigsterFormCollections[2].style.borderColor='red';
  57.                     this.ReigsterFormCollections[i].style.borderColor='red';
  58.                     return false;
  59.                 }
  60.             }
  61.             return true;
  62.         }
  63.           findWitchClicked():void {
  64.            this.inputArray = document.querySelectorAll('.register');
  65.             this.deathStar = document.querySelector('.death-star-button');
  66.             document.querySelector('.login-form').addEventListener('click', (event)=> {
  67.                 switch (event.target.id) {
  68.                     case this.REGISTRATION: {
  69.                         for (let i = 0; i <  this.inputArray.length; i++) {this.inputArray[i].style.display = 'block'}
  70.                         this.deathStar.style.display = 'block';
  71.                         this.addMusic('starwars-help/stick-on.mp3');
  72.                         break;
  73.                     }
  74.                     case this.REGIBUTTON:{
  75.                         if(this.CreateMyRequered() === true){
  76.                            // history.pushState('game','Game','http://localhost:63342/FinalGame/game.html'); //роутинг
  77.                             this.setUser(this.inputArray);
  78.                             this.ShowModal(0);
  79.                             this.addMusic('sounds/R2D2.mp3');
  80.                             setTimeout(this.CreateAjaxRequest.bind(null,'game.html','images/registration/backround.jpg'),100); //таймаут
  81.                             break;
  82.                         }
  83.                         else
  84.                             this.addMusic('sounds/R2D2-Error.mp3');
  85.                     }
  86.                 }
  87.             });
  88.     }}
  89. let loader = new loadForm();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement