Hacked By AnonymousFox

Current Path : /home/missmand/public_html/js/lightbox/
Upload File :
Current File : /home/missmand/public_html/js/lightbox/AskName.js.tar

home/missmand/public_html/gameapp/js/AskName.js000064400000011066152002072130015510 0ustar00function AskForName()
{
    document.body.style.zoom = 1.4;//1 / window.devicePixelRatio;
    //Get dom elements
    this.container = $('.game_container');
    this.container.show();
    this.message = this.container.find('.message').hide();
    this.answer = this.container.find('.answer');

    this.messageContainer = this.container.find('.message_container');
    this.answerContainer = this.container.find('.answer_container').hide();
    this.inputContainer = this.container.find('.input_container').hide();

    this.messages = [
        "Hello ! Bienvenue dans l'application Miss Mandarine !",
        "Es-tu prêt à commencer cette aventure ?",
        "Super ! C'est parti !",
        "D'abord, quel est ton prénom ?"
    ];

    this.answerIndex = 2;
    this.currentIndex = 0;

    this.WAIT_MESSAGE = 2000;
    this.WAIT_ANSWER = 1000;

    this.input = true;

    //INIT
	this.init = function()
    { 
        var oThis = this;
        this.inputContainer.find('form').submit(function(e)
        {
            e.preventDefault();
            oThis.input = false;

            var val = $(this).find('[name=name]').val();
            $(this).find('[name=name]').val('');
            console.log(oThis.currentIndex);

            if (oThis.currentIndex < oThis.messages.length)
            {
                oThis.chooseAnswer(val);
                return;
            }

            var player = JSON.parse(window.localStorage.getItem('player'));
            player.name = val;
            window.localStorage.setItem('player', JSON.stringify(player));

            document.location.href = 'select.html';
        });


        //Show first message
        this.showMessage(this.messages[0]);
    }
    

    //Show message 
    this.showMessage = function(text)
    {
        this.appendMessage(text);
        this.currentIndex++;

        setTimeout(this.endMessage.bind(this), this.WAIT_MESSAGE);
    }

    this.appendMessage = function(text, isPlayer)
    {
        var message = MakeClone(this.message, '', this.message);
        message.html(text).show();
        if (isPlayer)
            message.addClass('message_player');
        else
        {
            var prev = message.prev();
            while(prev.length > 0)
            {
                if (prev.hasClass('message_player'))
                    break;
                if (prev.is('img'))
                {
                    prev.remove();
                    break;
                }
                else
                    prev.addClass('message_top');
                prev = prev.prev();
            }
            message.before('<img src="img/logo-mini.png">');
        }
        return message;
    }

    //End timeout
    this.endMessage = function(mess)
    {
        if (this.currentIndex == this.answerIndex || this.currentIndex == this.messages.length)
        {
             //Show answers
            this.answerContainer.children(':not(:last)').remove();
            this.answerContainer.show();
            if (this.currentIndex == this.answerIndex)
            {
                this.showAnswer("Entrez votre réponse");
                this.currentIndex++;
                //this.showAnswer("<span>Oui !</span><img src='img/smiley.png'>");
            }
            else
            {
                this.showAnswer("Entrez votre prénom");
                this.currentIndex++;
            }
        }
        else //Go next
            this.showMessage(this.messages[this.currentIndex]);
    }


    //Show answer
    this.showAnswer = function(text)
    {
        var answer = MakeClone(this.answer, '', this.answer);
        answer.html(text).css('display', 'inline-block');

        this.input = true;
        //if (this.currentIndex != this.answerIndex)
            answer.click(this.chooseAnswer.bind(this, text));
        //else
          //  setTimeout(this.chooseAnswer.bind(this, text), this.WAIT_ANSWER);
    }

    this.chooseAnswer = function(text)
    {
        this.answerContainer.hide();
        
        if (this.input && (this.currentIndex == this.answerIndex+1 || this.currentIndex >= this.messages.length))
        {
            //Type name
            this.inputContainer.show();
            this.inputContainer.find('[name=name]').focus();
        }
        else
        {
            this.inputContainer.hide();
            this.appendMessage(text, true);
            this.message.before('<div class="clear"></div>');
            setTimeout(this.showMessage.bind(this, this.messages[this.currentIndex]), this.WAIT_ANSWER);
        }
    }

}

$(document).ready(function() { var controller = new AskForName(); controller.init(); });

Hacked By AnonymousFox1.0, Coded By AnonymousFox