<commit_before>

	var hr = new XMLHttpRequest();

	function httpRequestCreate(method,url){
	    hr.open(method,url,true);
	    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	}

	var questoes;
    var questCont=0;
    var estatisticas={mat: 0, geo: 0, hist: 0, port: 0, quim: 0};
    var estaAcertos={mat: 0, geo: 0, hist: 0, port: 0, quim: 0};
	var cont = 0;

	function ajaxSelectQuest(){

    var materias = [];
    materias = $('input:checkbox:checked.subjects').map(function () {
      switch (this.value){
        case "mat":
            return 1;
            break;
        case "geo":
            return 2;
            break;
        case "hist":
            return 3;
            break;
        case "port":
            return 4;
            break;
        case "quim":
            return 5;
            break;

      }
}).get();

    console.log("Materias: "+materias);

    var dific;
    dific = $("input:radio[name=dificulty]:checked").val();

    switch(dific){
        case "facil":
            dific=1;
            break;
        case "medio":
            dific=2;
            break;
        case "dificil":
            dific=3;
            break;
    }

    console.log("Dificuldade: "+dific);

    var nquest = Number($("#nQuest").val());

    tempo = nquest *(150);

    console.log("Numero de Questoes: "+nquest);

    //var vars = "materias="+JSON.stringify(materias);
    var vars = "dific="+dific+"&nquest="+nquest;
    //adicionando materias ao post se foram selecionadas
    if(materias.length>0){ vars+="&materias="+JSON.stringify(materias)}

    httpRequestCreate("POST","php/partida.php");
    // Access the onreadystatechange event for the XMLHttpRequest object
    hr.onreadystatechange = function()
    {
	    if(hr.readyState == 4 && hr.status == 200)
        {
		    var return_data = hr.responseText;
            return_data = $.parseJSON(return_data);
            questoes = return_data;
			$("#ilustracao").html(return_data[0].titulo); //gambiarra para contornar problema indescritivel com javascript

            //document.getElementById("site").innerHTML = return_data;

		   //return return_data;

            ajaxSelectOpt(return_data[0].id);
            startCountdown();

            // alert("Cadastro Concluido");
	    }
    }
    // Send the data to PHP now... and wait for response to update the status div
    hr.send(vars); // Actually execute the request
     $("#status").html("processing...");
}

// function ajaxInsereQuestao()
// {
//     var aux=document.getElementsByClass("questoes")[1];
//     alert(aux);
// }

function ajaxSelectOpt(id){

    httpRequestCreate("POST","php/opcoes.php");

    var vars = "id="+id;

    // Access the onreadystatechange event for the XMLHttpRequest object
    hr.onreadystatechange = function() {
	    if(hr.readyState == 4 && hr.status == 200) {

		    var return_data = hr.responseText;
            return_data = $.parseJSON(return_data);
            shuffle(return_data);
            var html = "
";

            for(var i=0;i<return_data.length;i++){
              html +=  '<input type="radio" name="answer" id="op'+i+'" value="'+return_data[i].right_answer+'">'+
                  ''+return_data[i].content+
                  '
';
            }
            html += '<button type="button" id="ans" onClick="checaQuestao()">responder</button>';
            html += '

';
			$("#ilustracao").append(html); //gambiarra para contornar problema indescritivel com javascript
		   // alert("Cadastro Concluido");
	    }
    }
    // Send the data to PHP now... and wait for response to update the status div
    hr.send(vars); // Actually execute the request
    //$("#status").html("processing...");
        }

	function shuffle(sourceArray) {
    for (var n = 0; n < sourceArray.length - 1; n++) {
        var k = n + Math.floor(Math.random() * (sourceArray.length - n));

        var temp = sourceArray[k];
        sourceArray[k] = sourceArray[n];
        sourceArray[n] = temp;
    }
}
function enviarQuestoesAcertos(esta,estaacertos,numquest,acertos)
{
	httpRequestCreate("POST","php/enviarQuestoesAcertos.php");
    var totalmat= JSON.stringify(esta);
    var acertosmat = JSON.stringify(estaacertos);
    var vars ="usuario="+localStorage.getItem("usuario")+"&totalQ="+numquest+"&totalAc="+acertos+
              "&totalmat="+totalmat+"&acertosmat="+acertosmat;

    // Access the onreadystatechange event for the XMLHttpRequest object
    hr.onreadystatechange = function() {
	    if(hr.readyState == 4 && hr.status == 200) {

		    var return_data = hr.responseText;

            window.location.href = "home.html";

			//console.log(return_data); //gambiarra para contornar problema indescritivel com javascript
	    }
    }
    // Send the data to PHP now... and wait for response to update the status div
    hr.send(vars); // Actually execute the request
    //$("#status").html("processing...");
        }

function checaQuestao() {

    //Criando variavel se não existir
    //if(!questCont){var questCont=0;}
    //if(!estatisticas){var estatisticas={mat: 0, geo: 0, hist: 0, port: 0, quim: 0};}
    //if(!estaAcertos){var estaAcertos={mat: 0, geo: 0, hist: 0, port: 0, quim: 0};}

      //Testando se ha uma opção selecionada
      if($('input:radio[name=answer]:checked').length>0){

            switch (questoes[cont].id_mate){
                case "1":
                    estatisticas.mat+=1;
                    break;
                case "2":
                    estatisticas.geo+=1;
                    break;
                case "3":
                    estatisticas.hist+=1;
                    break;
                case "4":
                    estatisticas.port+=1;
                    break;
                case "5":
                    estatisticas.quim+=1;
                    break;

          }

          //Testando se e certa
          if($('input:radio[name=answer]:checked').val()== 1){
            questCont++;
                switch (questoes[cont].id_mate){
                    case "1":
                        estaAcertos.mat+=1;
                        break;
                    case "2":
                        estaAcertos.geo+=1;
                        break;
                    case "3":
                        estaAcertos.hist+=1;
                        break;
                    case "4":
                        estaAcertos.port+=1;
                        break;
                    case "5":
                        estaAcertos.quim+=1;
                        break;
                    }
            console.log(estaAcertos.port);
            console.log(questCont);

          }

          cont++;

          //Caso uma proxima questao exista mostra a proxima
          if(questoes[cont] != undefined){
          $("#site").html(questoes[cont].titulo);
          ajaxSelectOpt(questoes[cont].id);

		  //Se ja não ha mais questões, a sessão acabou
		  }else{
				//É AQUI O LOCAL!!!!
				// o numero de questoes certas esta em localStorage.questCont , talvez isso mude
			enviarQuestoesAcertos(estatisticas,estaAcertos,cont,questCont);
                //VARIAVEIS IMPORTANTES

                //cont - Número de questões
                //questCont - Número toral de acertos

                //estatistica - Número de questoes de cada matéria
                //estaAcertos - Número de acertos de cada matéria

			}

      //Se nenhuma opção estiver selecionada alerta o usuario
      }else{
          $("#status").html("Selecione uma resposta");
      }

    }
<commit_msg>adicionando mais matérias no bancp<commit_after>

	var hr = new XMLHttpRequest();

	function httpRequestCreate(method,url){
	    hr.open(method,url,true);
	    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	}

	var questoes;
    var questCont=0;
    var estatisticas={mat: 0, geo: 0, hist: 0, port: 0, quim: 0, bio: 0,fis: 0};
    var estaAcertos={mat: 0, geo: 0, hist: 0, port: 0, quim: 0, bio: 0,fis: 0};
	var cont = 0;

	function ajaxSelectQuest(){

    var materias = [];
    materias = $('input:checkbox:checked.subjects').map(function () {
      switch (this.value){
        case "mat":
            return 1;
            break;
        case "geo":
            return 2;
            break;
        case "hist":
            return 3;
            break;
        case "port":
            return 4;
            break;
        case "quim":
            return 5;
            break;
        case "fis":
            return 11;
            break;
        case "bio":
            return 12;
            break;

      }
}).get();

    console.log("Materias: "+materias);

    var dific;
    dific = $("input:radio[name=dificulty]:checked").val();

    switch(dific){
        case "facil":
            dific=1;
            break;
        case "medio":
            dific=2;
            break;
        case "dificil":
            dific=3;
            break;
    }

    console.log("Dificuldade: "+dific);

    var nquest = Number($("#nQuest").val());

    tempo = nquest *(150);

    console.log("Numero de Questoes: "+nquest);

    //var vars = "materias="+JSON.stringify(materias);
    var vars = "dific="+dific+"&nquest="+nquest;
    //adicionando materias ao post se foram selecionadas
    if(materias.length>0){ vars+="&materias="+JSON.stringify(materias)}

    httpRequestCreate("POST","php/partida.php");
    // Access the onreadystatechange event for the XMLHttpRequest object
    hr.onreadystatechange = function()
    {
	    if(hr.readyState == 4 && hr.status == 200)
        {
		    var return_data = hr.responseText;
            return_data = $.parseJSON(return_data);
            questoes = return_data;
			$("#ilustracao").html(return_data[0].titulo); //gambiarra para contornar problema indescritivel com javascript

            //document.getElementById("site").innerHTML = return_data;

		   //return return_data;

            ajaxSelectOpt(return_data[0].id);
            startCountdown();

            // alert("Cadastro Concluido");
	    }
    }
    // Send the data to PHP now... and wait for response to update the status div
    hr.send(vars); // Actually execute the request
     $("#status").html("processing...");
}

// function ajaxInsereQuestao()
// {
//     var aux=document.getElementsByClass("questoes")[1];
//     alert(aux);
// }

function ajaxSelectOpt(id){

    httpRequestCreate("POST","php/opcoes.php");

    var vars = "id="+id;

    // Access the onreadystatechange event for the XMLHttpRequest object
    hr.onreadystatechange = function() {
	    if(hr.readyState == 4 && hr.status == 200) {

		    var return_data = hr.responseText;
            return_data = $.parseJSON(return_data);
            shuffle(return_data);
            var html = "
";

            for(var i=0;i<return_data.length;i++){
              html +=  '<input type="radio" name="answer" id="op'+i+'" value="'+return_data[i].right_answer+'">'+
                  ''+return_data[i].content+
                  '
';
            }
            html += '<button type="button" id="ans" onClick="checaQuestao()">responder</button>';
            html += '

';
			$("#ilustracao").append(html); //gambiarra para contornar problema indescritivel com javascript
		   // alert("Cadastro Concluido");
	    }
    }
    // Send the data to PHP now... and wait for response to update the status div
    hr.send(vars); // Actually execute the request
    //$("#status").html("processing...");
        }

	function shuffle(sourceArray) {
    for (var n = 0; n < sourceArray.length - 1; n++) {
        var k = n + Math.floor(Math.random() * (sourceArray.length - n));

        var temp = sourceArray[k];
        sourceArray[k] = sourceArray[n];
        sourceArray[n] = temp;
    }
}
function enviarQuestoesAcertos(esta,estaacertos,numquest,acertos)
{
	httpRequestCreate("POST","php/enviarQuestoesAcertos.php");
    var totalmat= JSON.stringify(esta);
    var acertosmat = JSON.stringify(estaacertos);
    var vars ="usuario="+localStorage.getItem("usuario")+"&totalQ="+numquest+"&totalAc="+acertos+
              "&totalmat="+totalmat+"&acertosmat="+acertosmat;

    // Access the onreadystatechange event for the XMLHttpRequest object
    hr.onreadystatechange = function() {
	    if(hr.readyState == 4 && hr.status == 200) {

		    var return_data = hr.responseText;

            window.location.href = "home.html";

			//console.log(return_data); //gambiarra para contornar problema indescritivel com javascript
	    }
    }
    // Send the data to PHP now... and wait for response to update the status div
    hr.send(vars); // Actually execute the request
    //$("#status").html("processing...");
        }

function checaQuestao() {

    //Criando variavel se não existir
    //if(!questCont){var questCont=0;}
    //if(!estatisticas){var estatisticas={mat: 0, geo: 0, hist: 0, port: 0, quim: 0};}
    //if(!estaAcertos){var estaAcertos={mat: 0, geo: 0, hist: 0, port: 0, quim: 0};}

      //Testando se ha uma opção selecionada
      if($('input:radio[name=answer]:checked').length>0){

            switch (questoes[cont].id_mate){
                case "1":
                    estatisticas.mat+=1;
                    break;
                case "2":
                    estatisticas.geo+=1;
                    break;
                case "3":
                    estatisticas.hist+=1;
                    break;
                case "4":
                    estatisticas.port+=1;
                    break;
                case "5":
                    estatisticas.quim+=1;
                    break;
                case "11":
                    estatisticas.fis+=1;
                    break;
                case "12":
                    estatisticas.bio+=1;
                    break;

          }

          //Testando se e certa
          if($('input:radio[name=answer]:checked').val()== 1){
            questCont++;
                switch (questoes[cont].id_mate){
                    case "1":
                        estaAcertos.mat+=1;
                        break;
                    case "2":
                        estaAcertos.geo+=1;
                        break;
                    case "3":
                        estaAcertos.hist+=1;
                        break;
                    case "4":
                        estaAcertos.port+=1;
                        break;
                    case "5":
                        estaAcertos.quim+=1;
                        break;
                    case "11":
                        estatisticas.fis+=1;
                        break;
                    case "12":
                        estatisticas.bio+=1;
                        break;

                    }

            console.log(estaAcertos.port);
            console.log(questCont);

          }

          cont++;

          //Caso uma proxima questao exista mostra a proxima
          if(questoes[cont] != undefined){
          $("#site").html(questoes[cont].titulo);
          ajaxSelectOpt(questoes[cont].id);

		  //Se ja não ha mais questões, a sessão acabou
		  }else{
				//É AQUI O LOCAL!!!!
				// o numero de questoes certas esta em localStorage.questCont , talvez isso mude
			enviarQuestoesAcertos(estatisticas,estaAcertos,cont,questCont);
                //VARIAVEIS IMPORTANTES

                //cont - Número de questões
                //questCont - Número toral de acertos

                //estatistica - Número de questoes de cada matéria
                //estaAcertos - Número de acertos de cada matéria

			}

      //Se nenhuma opção estiver selecionada alerta o usuario
      }else{
          $("#status").html("Selecione uma resposta");
      }

    }
<|endoftext|>


<commit_before>var STACK = (function () {
    var obj = {};

    var _stack = [];
    var _nextStack = null;
    var _currentSlide = 0;

    var _stackTimer = null;
    var _rotateTimer = null;
    var _mouseMoveTimer = null;

    var _stackRequest = null;
    var _rotateRequest = null;

    /*
     * Setup the stack display.
     */
    obj.start = function() {
        $stack.show();

        $('body').on('mousemove', onMoveMouse);
        $headerControls.hover(onControlsHover, offControlsHover);
        // $audioPlayer.jPlayer('play');

        updateStack();
    }

    /*
     * Stop running the stack.
     */
    obj.stop = function() {
        if (_stackTimer) {
            clearTimeout(_stackTimer);
            _stackTimer = null;
        }

        if (_stackRequest) {
            _stackRequest.abort();
            _stackRequest = null;
        }

        if (_rotateTimer) {
            clearTimeout(_rotateTimer);
            _rotateTimer = null;
        }

        if (_rotateRequest) {
            _rotateRequest.abort();
            _rotateRequest = null;
        }

        if (_mouseMoveTimer) {
            clearTimeout(_mouseMoveTimer);
            _mouseMoveTimer = null;
        }

        $audioPlayer.jPlayer('pause');

        $stack.hide();
    }

    /*
     * Show the header.
     */
    var onMoveMouse = function() {
        if (!($('body').data('mouse-moving'))) {
            $header.fadeOut(200, function() {
                $headerControls.fadeIn(200, function() {
                    $('body').data('mouse-moving', true);
                });
            });

        }

        if (_mouseMoveTimer) {
            clearTimeout(_mouseMoveTimer);
        }

        _mouseMoveTimer = setTimeout(onEndMouse, 500);
    }

    /*
     * Hide the header.
     */
    var onEndMouse = function() {

        if (!($headerControls.data('hover'))) {
            $headerControls.fadeOut(200, function() {
                $header.fadeIn(200, function() {
                    $('body').data('mouse-moving', false);
                });
            });
        }
    }

    /*
     * Rotate to the next slide in the stack.
     */
    var rotateSlide = function() {
        _currentSlide += 1;

        if (_currentSlide >= _stack.length) {
            if (_nextStack.length > 0) {
                _stack = _nextStack;
                _nextStack = [];
            }

            _currentSlide = 0;
        }

        var slug = _stack[_currentSlide]['slug'];

        if (slug === 'state') {
            // If no state selected, skip to next
            if (!state) {
                rotateSlide();
                return;
            }

            slide_path = 'slides/state-' + state + '.html';
        } else {
            slide_path = 'slides/' + slug + '.html';
        }

        console.log('Rotating to next slide:', slide_path);

        _rotateRequest = $.ajax({
            url: APP_CONFIG.S3_BASE_URL + '/' + slide_path,
            success: function(data) {
                var $oldSlide = $stack.find('.slide');
                var $newSlide = $(data);

                if ($oldSlide.length > 0) {
                    $oldSlide.fadeOut(800, function() {
                        $(this).remove();
                        $stack.append($newSlide);
                        resizeSlide($newSlide)
                        if ($newSlide.find('.results-header').length > 0) {
                            $header.find('.leaderboard').fadeOut();
                        }
                        else {
                            $header.find('.leaderboard').fadeIn();
                        }

                        $newSlide.fadeIn(800, function(){
                            _rotateTimer = setTimeout(rotateSlide, APP_CONFIG.SLIDE_ROTATE_INTERVAL * 1000);
                        });
                    });
                }

                else {
                    $stack.append($newSlide);
                    resizeSlide($newSlide)
                    if ($newSlide.find('.results-header').length > 0) {
                        $header.find('.leaderboard').fadeOut();
                    }
                    else {
                        $header.find('.leaderboard').fadeIn();
                    }
                    $newSlide.fadeIn(800, function(){
                        _rotateTimer = setTimeout(rotateSlide, APP_CONFIG.SLIDE_ROTATE_INTERVAL * 1000);
                    });
                }
            }
        });
    }

    /*
     * Update the slide stack.
     */
    function updateStack() {
        _stackRequest = $.ajax({
            url: APP_CONFIG.S3_BASE_URL + '/live-data/stack.json',
            dataType: 'json',
            success: function(data) {
                _nextStack = data;

                if (!_rotateTimer) {
                    rotateSlide();
                }

                _stackTimer = setTimeout(updateStack, APP_CONFIG.STACK_UPDATE_INTERVAL * 1000);
            }
        });
    }

    return obj;
}());
<commit_msg>only fade out senate bop if bop is on big board. closes #566<commit_after>var STACK = (function () {
    var obj = {};

    var _stack = [];
    var _nextStack = null;
    var _currentSlide = 0;

    var _stackTimer = null;
    var _rotateTimer = null;
    var _mouseMoveTimer = null;

    var _stackRequest = null;
    var _rotateRequest = null;

    /*
     * Setup the stack display.
     */
    obj.start = function() {
        $stack.show();

        $('body').on('mousemove', onMoveMouse);
        $headerControls.hover(onControlsHover, offControlsHover);
        // $audioPlayer.jPlayer('play');

        updateStack();
    }

    /*
     * Stop running the stack.
     */
    obj.stop = function() {
        if (_stackTimer) {
            clearTimeout(_stackTimer);
            _stackTimer = null;
        }

        if (_stackRequest) {
            _stackRequest.abort();
            _stackRequest = null;
        }

        if (_rotateTimer) {
            clearTimeout(_rotateTimer);
            _rotateTimer = null;
        }

        if (_rotateRequest) {
            _rotateRequest.abort();
            _rotateRequest = null;
        }

        if (_mouseMoveTimer) {
            clearTimeout(_mouseMoveTimer);
            _mouseMoveTimer = null;
        }

        $audioPlayer.jPlayer('pause');

        $stack.hide();
    }

    /*
     * Show the header.
     */
    var onMoveMouse = function() {
        if (!($('body').data('mouse-moving'))) {
            $header.fadeOut(200, function() {
                $headerControls.fadeIn(200, function() {
                    $('body').data('mouse-moving', true);
                });
            });

        }

        if (_mouseMoveTimer) {
            clearTimeout(_mouseMoveTimer);
        }

        _mouseMoveTimer = setTimeout(onEndMouse, 500);
    }

    /*
     * Hide the header.
     */
    var onEndMouse = function() {

        if (!($headerControls.data('hover'))) {
            $headerControls.fadeOut(200, function() {
                $header.fadeIn(200, function() {
                    $('body').data('mouse-moving', false);
                });
            });
        }
    }

    /*
     * Rotate to the next slide in the stack.
     */
    var rotateSlide = function() {
        _currentSlide += 1;

        if (_currentSlide >= _stack.length) {
            if (_nextStack.length > 0) {
                _stack = _nextStack;
                _nextStack = [];
            }

            _currentSlide = 0;
        }

        var slug = _stack[_currentSlide]['slug'];

        if (slug === 'state') {
            // If no state selected, skip to next
            if (!state) {
                rotateSlide();
                return;
            }

            slide_path = 'slides/state-' + state + '.html';
        } else {
            slide_path = 'slides/' + slug + '.html';
        }

        console.log('Rotating to next slide:', slide_path);

        _rotateRequest = $.ajax({
            url: APP_CONFIG.S3_BASE_URL + '/' + slide_path,
            success: function(data) {
                var $oldSlide = $stack.find('.slide');
                var $newSlide = $(data);

                if ($oldSlide.length > 0) {
                    $oldSlide.fadeOut(800, function() {
                        $(this).remove();
                        $stack.append($newSlide);
                        resizeSlide($newSlide)
                        if ($newSlide.find('.leaderboard').length > 0) {
                            $header.find('.leaderboard').fadeOut();
                        }
                        else {
                            $header.find('.leaderboard').fadeIn();
                        }

                        $newSlide.fadeIn(800, function(){
                            _rotateTimer = setTimeout(rotateSlide, APP_CONFIG.SLIDE_ROTATE_INTERVAL * 1000);
                        });
                    });
                }

                else {
                    $stack.append($newSlide);
                    resizeSlide($newSlide)
                    if ($newSlide.find('.results-header').length > 0) {
                        $header.find('.leaderboard').fadeOut();
                    }
                    else {
                        $header.find('.leaderboard').fadeIn();
                    }
                    $newSlide.fadeIn(800, function(){
                        _rotateTimer = setTimeout(rotateSlide, APP_CONFIG.SLIDE_ROTATE_INTERVAL * 1000);
                    });
                }
            }
        });
    }

    /*
     * Update the slide stack.
     */
    function updateStack() {
        _stackRequest = $.ajax({
            url: APP_CONFIG.S3_BASE_URL + '/live-data/stack.json',
            dataType: 'json',
            success: function(data) {
                _nextStack = data;

                if (!_rotateTimer) {
                    rotateSlide();
                }

                _stackTimer = setTimeout(updateStack, APP_CONFIG.STACK_UPDATE_INTERVAL * 1000);
            }
        });
    }

    return obj;
}());
<|endoftext|>


<commit_before>jaxon.dialogs.swal = {
    options: {
        allowEscapeKey: true,
        allowOutsideClick: true
    },
    success: function(content, title) {
        if(title == undefined) title = 'Success';
        swal({text: content, title: title, type: 'success'});
    },
    info: function(content, title) {
        if(title == undefined) title = 'Information';
        swal({text: content, title: title, type: 'info'});
    },
    warning: function(content, title) {
        if(title == undefined) title = 'Warning';
        swal({text: content, title: title, type: 'warning'});
    },
    error: function(content, title) {
        if(title == undefined) title = 'Error';
        swal({text: content, title: title, type: 'error'});
    },
    confirm: function(question, title, yesCallback, noCallback) {
        swal({
            type: "warning",
            title: title,
            confirmButtonText: "<?php echo $this->yes ?>",
            cancelButtonText: "<?php echo $this->no ?>",
            showCancelButton: true,
            text: question
        },
        function(res){
            if(res)
                yesCallback();
            else if(noCallback != undefined)
                noCallback();
        });
    }
};
<?php echo $this->options ?>

jaxon.command.handler.register("sweetalert.alert", function(args) {
    // Set user and default options into data only when they are missing
    for(key in jaxon.dialogs.sweetalert.options)
    {
        if(!(key in args.data))
        {
            args.data[key] = jaxon.dialogs.sweetalert.options[key];
        }
    }
    swal(args.data);
});

<?php if(($this->defaultForAlert)): ?>
jaxon.ajax.message.success = jaxon.dialogs.swal.success;
jaxon.ajax.message.info = jaxon.dialogs.swal.info;
jaxon.ajax.message.warning = jaxon.dialogs.swal.warning;
jaxon.ajax.message.error = jaxon.dialogs.swal.error;
<?php endif ?>
<?php if(($this->defaultForConfirm)): ?>
jaxon.ajax.message.confirm = jaxon.dialogs.swal.confirm;
<?php endif ?>
<commit_msg>Bugfix #7: Changed bad class name in js code.<commit_after>jaxon.dialogs.swal = {
    options: {
        allowEscapeKey: true,
        allowOutsideClick: true
    },
    success: function(content, title) {
        if(title == undefined) title = 'Success';
        swal({text: content, title: title, type: 'success'});
    },
    info: function(content, title) {
        if(title == undefined) title = 'Information';
        swal({text: content, title: title, type: 'info'});
    },
    warning: function(content, title) {
        if(title == undefined) title = 'Warning';
        swal({text: content, title: title, type: 'warning'});
    },
    error: function(content, title) {
        if(title == undefined) title = 'Error';
        swal({text: content, title: title, type: 'error'});
    },
    confirm: function(question, title, yesCallback, noCallback) {
        swal({
            type: "warning",
            title: title,
            confirmButtonText: "<?php echo $this->yes ?>",
            cancelButtonText: "<?php echo $this->no ?>",
            showCancelButton: true,
            text: question
        },
        function(res){
            if(res)
                yesCallback();
            else if(noCallback != undefined)
                noCallback();
        });
    }
};
<?php echo $this->options ?>

jaxon.command.handler.register("sweetalert.alert", function(args) {
    // Set user and default options into data only when they are missing
    for(key in jaxon.dialogs.swal.options)
    {
        if(!(key in args.data))
        {
            args.data[key] = jaxon.dialogs.swal.options[key];
        }
    }
    swal(args.data);
});

<?php if(($this->defaultForAlert)): ?>
jaxon.ajax.message.success = jaxon.dialogs.swal.success;
jaxon.ajax.message.info = jaxon.dialogs.swal.info;
jaxon.ajax.message.warning = jaxon.dialogs.swal.warning;
jaxon.ajax.message.error = jaxon.dialogs.swal.error;
<?php endif ?>
<?php if(($this->defaultForConfirm)): ?>
jaxon.ajax.message.confirm = jaxon.dialogs.swal.confirm;
<?php endif ?>
<|endoftext|>


<commit_before>'use strict';

var exec = require('cordova/exec'),
  mixpanel = {
    people: {}
  },
  errors = {
    invalid: function(paramName, value) {
      return 'invalid ' + paramName + ': ' + value;
    }
  };

// MIXPANEL API

/**
 * can be called in two ways:
 * - with 4 args, as function signature
 * - with 3 args `mixpanel.alias(alias, onSuccess, onFail)`
 */
mixpanel.alias = mixpanel.createAlias = function(alias, originalId, onSuccess, onFail) {
  if (!alias || typeof alias !== 'string') {
    return onFail(errors.invalid('alias', alias));
  }

  if (arguments.length === 3 && typeof originalId === 'function'){
    onFail = onSuccess;
    onSuccess = originalId;
    originalId = null;
  }

  if (!originalId || typeof originalId !== 'string'){
    mixpanel.distinctId(
      function(distinctId){
        exec(onSuccess, onFail, 'Mixpanel', 'alias', [alias, distinctId]);
      },
      onFail
    );
  } else {
    exec(onSuccess, onFail, 'Mixpanel', 'alias', [alias, originalId]);
  }
};

mixpanel.distinctId = function(onSuccess, onFail) {
  exec(onSuccess, onFail, 'Mixpanel', 'distinctId', []);
};

mixpanel.flush = function(onSuccess, onFail) {
  exec(onSuccess, onFail, 'Mixpanel', 'flush', []);
};

mixpanel.getSuperProperties = function(onSuccess, onFail) {
  exec(onSuccess, onFail, 'Mixpanel', 'getSuperProperties', []);
};

/**
 * can be called in two ways:
 * - with 3 args `mixpanel.alias(alias, onSuccess, onFail)`
 * - with 4 args, as function signature
 *     in this case, "usePeople" boolean will be passed to ios mixpanel sdk, as documented here:
 *     https://github.com/mixpanel/mixpanel-iphone/releases/tag/v3.2.0
 *     NOTE: usePeople has no effect on android
 */
mixpanel.identify = function(id, usePeople, onSuccess, onFail) {
  if (!id || typeof id !== 'string') {
    return onFail(errors.invalid('id', id));
  }

  if (arguments.length === 3 && typeof usePeople === 'function'){
    onFail = onSuccess;
    onSuccess = usePeople;
    usePeople = true;
  }

  exec(onSuccess, onFail, 'Mixpanel', 'identify', [id, !!usePeople]);
};

mixpanel.init = function(token, onSuccess, onFail) {
  if (!token || typeof token != 'string') {
    return onFail(errors.invalid('token', token));
  }

  var onSuccessWrapper = function(){
    mixpanel['__loaded'] = true;
    onSuccess.apply(onSuccess, arguments);
  }

  exec(onSuccessWrapper, onFail, 'Mixpanel', 'init', [token]);
};

mixpanel.registerSuperProperties = function(superProperties, onSuccess, onFail) {
  if (!superProperties || typeof superProperties !== 'object') {
    return onFail(errors.invalid('superProperties', superProperties));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'registerSuperProperties', [superProperties]);
};

mixpanel.registerSuperPropertiesOnce = function(superProperties, onSuccess, onFail) {
  if (!superProperties || typeof superProperties !== 'object') {
    return onFail(errors.invalid('superProperties', superProperties));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'registerSuperPropertiesOnce', [superProperties]);
};

mixpanel.reset = function(onSuccess, onFail) {
  exec(onSuccess, onFail, 'Mixpanel', 'reset', []);
};

mixpanel.timeEvent = function(eventName, onSuccess, onFail) {
  if (!eventName || typeof eventName != 'string') {
    return onFail(errors.invalid('event', eventName));
  }
  exec(onSuccess, onFail, 'Mixpanel', 'timeEvent', [eventName]);
};

mixpanel.track = function(eventName, eventProperties, onSuccess, onFail) {
  if (!eventName || typeof eventName != 'string') {
    return onFail(errors.invalid('event', eventName));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'track', [eventName, eventProperties]);
};

mixpanel.unregisterSuperProperty = function(superPropertyName, onSuccess, onFail) {
  if (!superPropertyName || typeof superPropertyName != 'string') {
    return onFail(errors.invalid('superPropertyName', superPropertyName));
  }
  exec(onSuccess, onFail, 'Mixpanel', 'unregisterSuperProperty', [superPropertyName]);
};

// PEOPLE API

/**
 * @param {*} appendObject example:
 *      {
 *        'key1': [values to append to key1],
 *        'key2': [values to append to key2]
 *      }
 */
mixpanel.people.append = function(appendObject, onSuccess, onFail) {
  if (!appendObject || typeof appendObject !== 'object') {
    return onFail(errors.invalid('appendObject', appendObject));
  }
  var keys = Object.keys(appendObject);
  for (var i=0; i < keys.length; i++) {
    if (!Array.isArray(appendObject[keys[i]])) {
      return onFail(errors.invalid('appendObject', appendObject));
    }
  }

  exec(onSuccess, onFail, 'Mixpanel', 'people_append', [appendObject]);
};

mixpanel.people.deleteUser = function(onSuccess, onFail) {
  exec(onSuccess, onFail, 'Mixpanel', 'people_deleteUser', []);
};

/** @deprecated 2016-11-21 mixpanel.identify will set id for both events and people */
mixpanel.people.identify = function(distinctId, onSuccess, onFail) {
  if (!distinctId) {
    return onFail(errors.invalid('distinctId', distinctId));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'identify', [distinctId]);
};

mixpanel.people.increment = function(peopleProperties, onSuccess, onFail) {
  if (!peopleProperties || (typeof peopleProperties === 'object' && Object.keys(peopleProperties).length === 0)) {
    return onFail(errors.invalid('properties', peopleProperties));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'people_increment', [peopleProperties]);
};

mixpanel.people.set = function(peopleProperties, onSuccess, onFail) {
  if (!peopleProperties || (typeof peopleProperties === 'object' && Object.keys(peopleProperties).length === 0)) {
    return onFail(errors.invalid('properties', peopleProperties));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'people_set', [peopleProperties]);
};

mixpanel.people.setOnce = function(peopleProperties, onSuccess, onFail) {
  if (!peopleProperties || (typeof peopleProperties === 'object' && Object.keys(peopleProperties).length === 0)) {
    return onFail(errors.invalid('properties', peopleProperties));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'people_set_once', [peopleProperties]);
};

/**
 * @param pushId is the token/id you get back when registering the device with the notification service
 *        for android - this is the FCM token
 *        for ios - this is the APN token
 */
mixpanel.people.setPushId = function(pushId, onSuccess, onFail) {
  if (!pushId || typeof pushId !== 'string') {
    return onFail(errors.invalid('pushId', pushId));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'people_setPushId', [pushId]);
};

mixpanel.people.trackCharge = function(amount, chargeProperties, onSuccess, onFail) {
  if (typeof amount !== 'number' || !isFinite(amount)) {
    return onFail(errors.invalid('amount', amount));
  }
  if (chargeProperties && typeof chargeProperties !== 'object') {
    return onFail(errors.invalid('chargeProperties', chargeProperties));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'people_track_charge', [amount, chargeProperties]);
};

/**
 * @param {*} unionObject example:
 *      {
 *        'key1': [values to union into key1],
 *        'key2': [values to union into key2]
 *      }
 */
mixpanel.people.union = function(unionObject, onSuccess, onFail) {
  if (!unionObject || typeof unionObject !== 'object') {
    return onFail(errors.invalid('unionObject', unionObject));
  }
  var keys = Object.keys(unionObject);
  for (var i=0; i < keys.length; i++) {
    if (!Array.isArray(unionObject[keys[i]])) {
      return onFail(errors.invalid('unionObject', unionObject));
    }
  }

  exec(onSuccess, onFail, 'Mixpanel', 'people_union', [unionObject]);
};

mixpanel.people.unset = function(propertiesArray, onSuccess, onFail) {
  if (!Array.isArray(propertiesArray)) {
    return onFail(errors.invalid('propertiesArray', propertiesArray));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'people_unset', [propertiesArray]);
};

// Exports

module.exports = mixpanel;
<commit_msg>Swap check of id's type and arguments number logic to avoid runtime error when id is not string<commit_after>'use strict';

var exec = require('cordova/exec'),
  mixpanel = {
    people: {}
  },
  errors = {
    invalid: function(paramName, value) {
      return 'invalid ' + paramName + ': ' + value;
    }
  };

// MIXPANEL API

/**
 * can be called in two ways:
 * - with 4 args, as function signature
 * - with 3 args `mixpanel.alias(alias, onSuccess, onFail)`
 */
mixpanel.alias = mixpanel.createAlias = function(alias, originalId, onSuccess, onFail) {
  if (!alias || typeof alias !== 'string') {
    return onFail(errors.invalid('alias', alias));
  }

  if (arguments.length === 3 && typeof originalId === 'function'){
    onFail = onSuccess;
    onSuccess = originalId;
    originalId = null;
  }

  if (!originalId || typeof originalId !== 'string'){
    mixpanel.distinctId(
      function(distinctId){
        exec(onSuccess, onFail, 'Mixpanel', 'alias', [alias, distinctId]);
      },
      onFail
    );
  } else {
    exec(onSuccess, onFail, 'Mixpanel', 'alias', [alias, originalId]);
  }
};

mixpanel.distinctId = function(onSuccess, onFail) {
  exec(onSuccess, onFail, 'Mixpanel', 'distinctId', []);
};

mixpanel.flush = function(onSuccess, onFail) {
  exec(onSuccess, onFail, 'Mixpanel', 'flush', []);
};

mixpanel.getSuperProperties = function(onSuccess, onFail) {
  exec(onSuccess, onFail, 'Mixpanel', 'getSuperProperties', []);
};

/**
 * can be called in two ways:
 * - with 3 args `mixpanel.alias(alias, onSuccess, onFail)`
 * - with 4 args, as function signature
 *     in this case, "usePeople" boolean will be passed to ios mixpanel sdk, as documented here:
 *     https://github.com/mixpanel/mixpanel-iphone/releases/tag/v3.2.0
 *     NOTE: usePeople has no effect on android
 */
mixpanel.identify = function(id, usePeople, onSuccess, onFail) {
  if (arguments.length === 3 && typeof usePeople === 'function'){
    onFail = onSuccess;
    onSuccess = usePeople;
    usePeople = true;
  }

  if (!id || typeof id !== 'string') {
    return onFail(errors.invalid('id', id));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'identify', [id, !!usePeople]);
};

mixpanel.init = function(token, onSuccess, onFail) {
  if (!token || typeof token != 'string') {
    return onFail(errors.invalid('token', token));
  }

  var onSuccessWrapper = function(){
    mixpanel['__loaded'] = true;
    onSuccess.apply(onSuccess, arguments);
  }

  exec(onSuccessWrapper, onFail, 'Mixpanel', 'init', [token]);
};

mixpanel.registerSuperProperties = function(superProperties, onSuccess, onFail) {
  if (!superProperties || typeof superProperties !== 'object') {
    return onFail(errors.invalid('superProperties', superProperties));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'registerSuperProperties', [superProperties]);
};

mixpanel.registerSuperPropertiesOnce = function(superProperties, onSuccess, onFail) {
  if (!superProperties || typeof superProperties !== 'object') {
    return onFail(errors.invalid('superProperties', superProperties));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'registerSuperPropertiesOnce', [superProperties]);
};

mixpanel.reset = function(onSuccess, onFail) {
  exec(onSuccess, onFail, 'Mixpanel', 'reset', []);
};

mixpanel.timeEvent = function(eventName, onSuccess, onFail) {
  if (!eventName || typeof eventName != 'string') {
    return onFail(errors.invalid('event', eventName));
  }
  exec(onSuccess, onFail, 'Mixpanel', 'timeEvent', [eventName]);
};

mixpanel.track = function(eventName, eventProperties, onSuccess, onFail) {
  if (!eventName || typeof eventName != 'string') {
    return onFail(errors.invalid('event', eventName));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'track', [eventName, eventProperties]);
};

mixpanel.unregisterSuperProperty = function(superPropertyName, onSuccess, onFail) {
  if (!superPropertyName || typeof superPropertyName != 'string') {
    return onFail(errors.invalid('superPropertyName', superPropertyName));
  }
  exec(onSuccess, onFail, 'Mixpanel', 'unregisterSuperProperty', [superPropertyName]);
};

// PEOPLE API

/**
 * @param {*} appendObject example:
 *      {
 *        'key1': [values to append to key1],
 *        'key2': [values to append to key2]
 *      }
 */
mixpanel.people.append = function(appendObject, onSuccess, onFail) {
  if (!appendObject || typeof appendObject !== 'object') {
    return onFail(errors.invalid('appendObject', appendObject));
  }
  var keys = Object.keys(appendObject);
  for (var i=0; i < keys.length; i++) {
    if (!Array.isArray(appendObject[keys[i]])) {
      return onFail(errors.invalid('appendObject', appendObject));
    }
  }

  exec(onSuccess, onFail, 'Mixpanel', 'people_append', [appendObject]);
};

mixpanel.people.deleteUser = function(onSuccess, onFail) {
  exec(onSuccess, onFail, 'Mixpanel', 'people_deleteUser', []);
};

/** @deprecated 2016-11-21 mixpanel.identify will set id for both events and people */
mixpanel.people.identify = function(distinctId, onSuccess, onFail) {
  if (!distinctId) {
    return onFail(errors.invalid('distinctId', distinctId));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'identify', [distinctId]);
};

mixpanel.people.increment = function(peopleProperties, onSuccess, onFail) {
  if (!peopleProperties || (typeof peopleProperties === 'object' && Object.keys(peopleProperties).length === 0)) {
    return onFail(errors.invalid('properties', peopleProperties));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'people_increment', [peopleProperties]);
};

mixpanel.people.set = function(peopleProperties, onSuccess, onFail) {
  if (!peopleProperties || (typeof peopleProperties === 'object' && Object.keys(peopleProperties).length === 0)) {
    return onFail(errors.invalid('properties', peopleProperties));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'people_set', [peopleProperties]);
};

mixpanel.people.setOnce = function(peopleProperties, onSuccess, onFail) {
  if (!peopleProperties || (typeof peopleProperties === 'object' && Object.keys(peopleProperties).length === 0)) {
    return onFail(errors.invalid('properties', peopleProperties));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'people_set_once', [peopleProperties]);
};

/**
 * @param pushId is the token/id you get back when registering the device with the notification service
 *        for android - this is the FCM token
 *        for ios - this is the APN token
 */
mixpanel.people.setPushId = function(pushId, onSuccess, onFail) {
  if (!pushId || typeof pushId !== 'string') {
    return onFail(errors.invalid('pushId', pushId));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'people_setPushId', [pushId]);
};

mixpanel.people.trackCharge = function(amount, chargeProperties, onSuccess, onFail) {
  if (typeof amount !== 'number' || !isFinite(amount)) {
    return onFail(errors.invalid('amount', amount));
  }
  if (chargeProperties && typeof chargeProperties !== 'object') {
    return onFail(errors.invalid('chargeProperties', chargeProperties));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'people_track_charge', [amount, chargeProperties]);
};

/**
 * @param {*} unionObject example:
 *      {
 *        'key1': [values to union into key1],
 *        'key2': [values to union into key2]
 *      }
 */
mixpanel.people.union = function(unionObject, onSuccess, onFail) {
  if (!unionObject || typeof unionObject !== 'object') {
    return onFail(errors.invalid('unionObject', unionObject));
  }
  var keys = Object.keys(unionObject);
  for (var i=0; i < keys.length; i++) {
    if (!Array.isArray(unionObject[keys[i]])) {
      return onFail(errors.invalid('unionObject', unionObject));
    }
  }

  exec(onSuccess, onFail, 'Mixpanel', 'people_union', [unionObject]);
};

mixpanel.people.unset = function(propertiesArray, onSuccess, onFail) {
  if (!Array.isArray(propertiesArray)) {
    return onFail(errors.invalid('propertiesArray', propertiesArray));
  }

  exec(onSuccess, onFail, 'Mixpanel', 'people_unset', [propertiesArray]);
};

// Exports

module.exports = mixpanel;
<|endoftext|>


<commit_before>var TMT = TMT || {};
var xloc;
var yloc;
var marker;
var currentTile = 0;
var blocks = [];

//Life system.
var life;
var dead = false;

//Time Elapsed variables
var timeStart;
var elapsed;
var text;

var emitter;

//title screen
TMT.Game = function () {};

TMT.Game.prototype = {
    create: function () {
		//Sets the beginning lives to three.
        life = 3;

        this.game.world.setBounds(0, 0, this.game.width, this.game.height);

		timeStart = new Date();

        //set grid init position
        xloc = ((this.game.world.width / 2) - 150);
        yloc = (this.game.world.height / 2) - (0.0625 * this.game.world.height);

        //background
        this.background = this.game.add.tileSprite(0, 0, this.game.world.width, this.game.world.height, 'gamebg');

        // Generate all the blocks
        this.generateBlocks();

		//adding the loading bar sprite
		this.progbar = this.game.add.sprite(this.game.world.width/2 - 200, this.game.height*0.9, 'progress');

        //sprites
        //plane is the object that is moving.
        this.plane = this.game.add.sprite(xloc - 500, blocks[0].y + 100, 'plane1', 2);
        this.plane.scale.setTo(1);
        this.plane.frame = 0;

        //add physics to the sprites
        this.game.physics.arcade.enable(this.plane);
        this.plane.body.overlapWorldBounds = true;

		//This will create text in the top left of the game screen.
		text = this.game.add.text(50, 50, 'Time: 0s' , { fontSize: '32px', fill: '#FFF' });

        emitter = this.game.add.emitter(0,0,10);
        emitter.makeParticles('fire');
        emitter.gravity = 200;
    },

    //Create a plane
    generatePlane: function () {

    },

    //Create a boat
    generateBoat: function () {

    },

    //Create a train
    generateTrain: function () {

    },

    // Generate all blocks
    generateBlocks: function () {
        this.blocks = this.game.add.group();

        //enable physics in them
        this.blocks.enableBody = true;

        //phaser's random number generator
        var numBlocks = 9;
        var current;

        for (var i = 0; i < numBlocks; i++) {
            //add sprite
            current = this.blocks.create(xloc, yloc, 'terrain');

            xloc += 100;
            if (xloc === ((this.game.world.width / 2) + 150)) {
                xloc = ((this.game.world.width / 2) - 150);
                yloc += 100;
            }

            current.scale.setTo(1);

            //physics properties

            current.body.velocity.x = 0;
            current.body.velocity.y = 0;
            current.body.immovable = true;
            current.body.collideWorldBounds = true;

            //THIS IS WHERE YOU ENABLE MOUSE CLICKS!!!!
            current.inputEnabled = true;
            current.events.onInputDown.add(this.onDown, this);
            blocks[i] = current;

            //Initializes blank map
            blocks[i].frame = 3;
        }
        current = blocks[0];
    },
    update: function() {
    	switch(elapsed) {
			case 0: this.progbar.frame = 10
			break;
			case 1: this.progbar.frame = 10
			break;
			case 2: this.progbar.frame = 10
			break;
			case 4: this.progbar.frame = 9
			break;
			case 6: this.progbar.frame = 8
			break;
			case 8: this.progbar.frame = 7
			break;
			case 10: this.progbar.frame = 6
			break;
			case 12: this.progbar.frame = 5
			break;
			case 14: this.progbar.frame = 4
			break;
			case 16: this.progbar.frame = 3
			break;
			case 18: this.progbar.frame = 2
			break;
			case 20: this.progbar.frame = 1
			break;
			case 22: this.progbar.frame = this.plane.kill();
			break;
		}
		//Timer for the top left of the swcreen.
		//text variable is the created on line 53
		var date = new Date();
		var time = timeStart.getSeconds();
		elapsed = date.getSeconds() - time;
		text.text = 'Time: ' + elapsed + 's';

		//Sounds must be called inside of this function either directly or with another function entirely (except create and preload)

		this.plane.body.velocity.x = 100;
		this.game.physics.arcade.overlap(this.plane, this.blocks, this.playSound, this.checkTile, this);

		if (life <= 0) {
            if(!dead)
                this.explosion(this.plane.body.x, this.plane.body.y);
                dead = true;
			this.plane.kill();
        }
    },

    /*
		This function is called by the game physics overlap.
        Takes a vehicle and a tile. Check to see if the vehicle matches the correct tile.
		Boat:  If tile.frame = 0 is true, false if otherwise.
		Plane: If tile.frame = 1 is true, false if otherwise.
		Train: If tile.frame = 2 is true, false if otherwise.
	*/
    checkTile: function (vehicle, tile) {
        if (vehicle.key === 'boat1'){
			if (tile.frame === 0)
				return false;
			else
				return true;
		}
		else if (vehicle.key === 'plane1'){
			if (tile.frame === 1)
				return false;
			else
				return true;
		}
		else if (vehicle.key === 'train1'){
			if (tile.frame === 2)
				return false;
			else
				return true;
		}
	},
    //This function allows the tiles to cycle between our spritesheet.
    onDown: function (sprite, pointer) {
        switchSound.play();
        if (sprite.frame < 2)
            sprite.frame++;
        else
            sprite.frame = 0;
    },
    //This takes no parameters, makes a sound.
    playSound: function () {
        explosionSound.play();
        this.plane.body.velocity.x = -6000;

        /*
        This is the life system. When a plane hits the bad tile, you lose a life.
        */
        life--;
    },

    //Particle explosion
    explosion: function (x, y) {
        emitter.x = x;
        emitter.y = y;

        //1) boolean for 'explode' (particles generate all at once)
        //2) particle lifespan (ms)
        //3) ignore
        //4) number of particles
        emitter.start(true, 1500, null, 8);
    },

};
<commit_msg>fixed timer, hopefully for the last time<commit_after>var TMT = TMT || {};
var xloc;
var yloc;
var marker;
var currentTile = 0;
var blocks = [];

//Life system.
var life;
var dead = false;

//Time Elapsed variables
var timeStart;
var elapsed;
var text;

var emitter;

//title screen
TMT.Game = function () {};

TMT.Game.prototype = {
    create: function () {
		//Sets the beginning lives to three.
        life = 3;

        this.game.world.setBounds(0, 0, this.game.width, this.game.height);

		timeStart = new Date();

        //set grid init position
        xloc = ((this.game.world.width / 2) - 150);
        yloc = (this.game.world.height / 2) - (0.0625 * this.game.world.height);

        //background
        this.background = this.game.add.tileSprite(0, 0, this.game.world.width, this.game.world.height, 'gamebg');

        // Generate all the blocks
        this.generateBlocks();

		//adding the loading bar sprite
		this.progbar = this.game.add.sprite(this.game.world.width/2 - 200, this.game.height-125, 'progress');

        //sprites
        //plane is the object that is moving.
        this.plane = this.game.add.sprite(xloc - 500, blocks[0].y + 100, 'plane1', 2);
        this.plane.scale.setTo(1);
        this.plane.frame = 0;

        //add physics to the sprites
        this.game.physics.arcade.enable(this.plane);
        this.plane.body.overlapWorldBounds = true;

		//This will create text in the top left of the game screen.
		text = this.game.add.text(50, 50, 'Time: 0s' , { fontSize: '32px', fill: '#FFF' });

        emitter = this.game.add.emitter(0,0,10);
        emitter.makeParticles('fire');
        emitter.gravity = 200;

		//timer function-starts at 60, decrements one every 1000 ms
		var count=60;
		var counter=setInterval(timer, 1000);
		function timer(){
		count--;
		text.text = 'Time remaining: ' + count + ' seconds';
		if(count<=0){
			text.text = 'Time\'s up!'
		}
}

    },

    //Create a plane
    generatePlane: function () {

    },

    //Create a boat
    generateBoat: function () {

    },

    //Create a train
    generateTrain: function () {

    },

    // Generate all blocks
    generateBlocks: function () {
        this.blocks = this.game.add.group();

        //enable physics in them
        this.blocks.enableBody = true;

        //phaser's random number generator
        var numBlocks = 9;
        var current;

        for (var i = 0; i < numBlocks; i++) {
            //add sprite
            current = this.blocks.create(xloc, yloc, 'terrain');

            xloc += 100;
            if (xloc === ((this.game.world.width / 2) + 150)) {
                xloc = ((this.game.world.width / 2) - 150);
                yloc += 100;
            }

            current.scale.setTo(1);

            //physics properties

            current.body.velocity.x = 0;
            current.body.velocity.y = 0;
            current.body.immovable = true;
            current.body.collideWorldBounds = true;

            //THIS IS WHERE YOU ENABLE MOUSE CLICKS!!!!
            current.inputEnabled = true;
            current.events.onInputDown.add(this.onDown, this);
            blocks[i] = current;

            //Initializes blank map
            blocks[i].frame = 3;
        }
        current = blocks[0];
    },
    update: function() {
    	switch(elapsed) {
			case 0: this.progbar.frame = 10
			break;
			case 1: this.progbar.frame = 10
			break;
			case 2: this.progbar.frame = 10
			break;
			case 4: this.progbar.frame = 9
			break;
			case 6: this.progbar.frame = 8
			break;
			case 8: this.progbar.frame = 7
			break;
			case 10: this.progbar.frame = 6
			break;
			case 12: this.progbar.frame = 5
			break;
			case 14: this.progbar.frame = 4
			break;
			case 16: this.progbar.frame = 3
			break;
			case 18: this.progbar.frame = 2
			break;
			case 20: this.progbar.frame = 1
			break;
			case 22: this.progbar.frame = this.plane.kill();
			break;
		}

		//Sounds must be called inside of this function either directly or with another function entirely (except create and preload)

		this.plane.body.velocity.x = 100;
		this.game.physics.arcade.overlap(this.plane, this.blocks, this.playSound, this.checkTile, this);

		if (life <= 0) {
            if(!dead)
                this.explosion(this.plane.body.x, this.plane.body.y);
                dead = true;
			this.plane.kill();
        }
    },

    /*
		This function is called by the game physics overlap.
        Takes a vehicle and a tile. Check to see if the vehicle matches the correct tile.
		Boat:  If tile.frame = 0 is true, false if otherwise.
		Plane: If tile.frame = 1 is true, false if otherwise.
		Train: If tile.frame = 2 is true, false if otherwise.
	*/
    checkTile: function (vehicle, tile) {
        if (vehicle.key === 'boat1'){
			if (tile.frame === 0)
				return false;
			else
				return true;
		}
		else if (vehicle.key === 'plane1'){
			if (tile.frame === 1)
				return false;
			else
				return true;
		}
		else if (vehicle.key === 'train1'){
			if (tile.frame === 2)
				return false;
			else
				return true;
		}
	},
    //This function allows the tiles to cycle between our spritesheet.
    onDown: function (sprite, pointer) {
        switchSound.play();
        if (sprite.frame < 2)
            sprite.frame++;
        else
            sprite.frame = 0;
    },
    //This takes no parameters, makes a sound.
    playSound: function () {
        explosionSound.play();
        this.plane.body.velocity.x = -6000;

        /*
        This is the life system. When a plane hits the bad tile, you lose a life.
        */
        life--;
    },

    //Particle explosion
    explosion: function (x, y) {
        emitter.x = x;
        emitter.y = y;

        //1) boolean for 'explode' (particles generate all at once)
        //2) particle lifespan (ms)
        //3) ignore
        //4) number of particles
        emitter.start(true, 1500, null, 8);
    },

};
<|endoftext|>


<commit_before>$( document ).ready(function() {
    var html_escape = function(str) {
        return $('
').text(str).html();
    };

    var update_command = function(command_id, command_description, command_text, title, success_button_label, on_success_callback) {
        bootbox.dialog({
            title: title,
            message:
                    '
  ' +
                        '
 ' +
                            '<form class="form-horizontal"> ' +
                                '
 ' +
                                    'Description ' +
                                    '
 ' +
                                        '<input id="pbf-description-' + command_id + '" name="pbf-description-' + command_id + '" type="text" placeholder="Description(can be empty)" value="' + command_description + '" class="form-control input-md"> ' +
                                    '
' +
                                '
' +
                                '
 ' +
                                    'Command ' +
                                    '
 ' +
                                        '<input id="pbf-command-' + command_id + '" name="pbf-command-' + command_id + '" type="text" placeholder="Command" class="form-control input-md" value="' + command_text + '"> ' +
                                    '
' +
                                '
' +
                            '</form>' +
                        '
' +
                    '
',
            buttons: {
                cancel: {
                    label: "Cancel",
                    className: "btn-default"
                },
                success: {
                    label: success_button_label,
                    className: "btn-success",
                    callback: on_success_callback
                }
            }
        });
    };

    var get_command_description = function(command_id) {
        var command_description_elem = $('.command-description-' + command_id);
        return command_description_elem.length > 0 ? command_description = command_description_elem.html().trim() : "";
    };

    var get_command_text = function(command_id) {
         return $('.pre-command-' + command_id).html().substring(3);
    };

    $.notifyDefaults({
        animate: {
            enter: 'animated fadeInDown',
            exit: 'animated fadeOutUp'
        }
    });
    $("#show-api-key").click(function() {
        $("#show-api-key").hide();
        $("#hide-api-key").show();
        $("#api-key").show();
    });
    $("#hide-api-key").click(function() {
        $("#show-api-key").show();
        $("#hide-api-key").hide();
        $("#api-key").hide();
    });
    $("#regenerate-api-key").click(function() {
        $.ajax("/_regenerate_api_key").done(function(data){
            $('#api-key-value').html(data.api_key);
        });
    });
    $(".btn-delete-command").click(function() {
        var command_id = $(this).data('command-id');
        $(this).hide();
        var that = this;
        $.post("/_delete_command/" + command_id).done(function(done){
            $("#command-row-" + command_id).remove();
            $.notify("Succesfully removed the command!");
        }).fail(function() {
            $(that).show();
            $.notify("Failed to remove the command!");
        });
    });
    $(".btn-star-command").click(function() {
        var command_id = $(this).data('command-id');
        var that = this;
        $.post("/_star_command/" + command_id).done(function(done){
            $(that).hide();
            $(".btn-unstar-command-" + command_id).show();
            $.notify("Succesfully starred the command!");
        }).fail(function() {
            $(that).show();
            $.notify("Failed to star the command!");
        });
    });

    $(".btn-publish-command").click(function() {
        var command_id = $(this).data('command-id');
        var that = this;
        var command_description = get_command_description(command_id);
        var command_text = get_command_text(command_id);
        update_command(command_id, command_description, command_text, "Publish command", "Publish", function() {
            var command_text = $('#pbf-command-' + command_id).val();
            var command_description = $('#pbf-description-' + command_id).val();
            $.post("/_publish_command/" + command_id,
                    {
                        description: command_description,
                        command: command_text
                    }
                  ).done(function(done){
                $(that).hide();
                $(".btn-unpublish-command-" + command_id).show();
                $(".public-title-" + command_id).show();
                $(".private-title-" + command_id).hide();
                $(".pre-command-" + command_id).html(" $ " + html_escape(command_text));
                $(".command-description-" + command_id).html(html_escape(command_description));
                $.notify("Succesfully published the command!");
            }).fail(function() {
                $(that).show();
                $.notify("Failed to publish the command!");
            });
        });
    });

    $(".btn-edit-command").click(function() {
        var command_id = $(this).data('command-id');
        var that = this;
        var command_description = get_command_description(command_id);
        var command_text = get_command_text(command_id);
        update_command(command_id, command_description, command_text, "Edit command", "Update", function() {
            var command_text = $('#pbf-command-' + command_id).val();
            var command_description = $('#pbf-description-' + command_id).val();
            $.post("/_edit_command/" + command_id,
                    {
                        description: command_description,
                        command: command_text
                    }
                  ).done(function(done){
                    $(".pre-command-" + command_id).html(" $ " + html_escape(command_text));
                    $(".command-description-" + command_id).html(html_escape(command_description));
                    $.notify("Succesfully updated the command!");
                  }).fail(function() {
                    $.notify("Failed to update the command!");
                  });
        });
    });

    $(".btn-unpublish-command").click(function() {
        var command_id = $(this).data('command-id');
        var that = this;
        bootbox.confirm("Are you sure to unpublish the command?", function(result) {
            if (result) {
                $.post("/_unpublish_command/" + command_id).done(function(done){
                    $(that).hide();
                    $(".btn-publish-command-" + command_id).show();
                    $(".public-title-" + command_id).hide();
                    $(".private-title-" + command_id).show();
                    $.notify("Succesfully made the command private!");
                }).fail(function() {
                    $(that).show();
                    $.notify("Failed make the command private!");
                });
            }
        });
    });

    $(".command-compact").click(function() {
        var command_id = $(this).data('command-id');
        $(".command-controls-" + command_id).toggle();
        var row = $(".command-row-" + command_id);
        if (row.hasClass('command-row-clicked')) {
            row.removeClass('command-row-clicked');
            row.find('pre').removeClass('code-compact-clicked');
        } else {
            row.addClass('command-row-clicked');
            row.find('pre').addClass('code-compact-clicked');
        }
    });
});
<commit_msg>Fix #23 (issues with quotes)<commit_after>$( document ).ready(function() {
    var html_escape = function(str) {
        return $('
').text(str).html();
    };

    var quot_escape = function(str) {
        return str.replace(/"/g, """);
    };

    var update_command = function(command_id, command_description, command_text, title, success_button_label, on_success_callback) {
        bootbox.dialog({
            title: title,
            message:
                    '
  ' +
                        '
 ' +
                            '<form class="form-horizontal"> ' +
                                '
 ' +
                                    'Description ' +
                                    '
 ' +
                                        '<input id="pbf-description-' + command_id + '" name="pbf-description-' + command_id + '" type="text" placeholder="Description(can be empty)" value="' + quot_escape(command_description) + '" class="form-control input-md"> ' +
                                    '
' +
                                '
' +
                                '
 ' +
                                    'Command ' +
                                    '
 ' +
                                        '<input id="pbf-command-' + command_id + '" name="pbf-command-' + command_id + '" type="text" placeholder="Command" class="form-control input-md" value="' + quot_escape(command_text) + '"> ' +
                                    '
' +
                                '
' +
                            '</form>' +
                        '
' +
                    '
',
            buttons: {
                cancel: {
                    label: "Cancel",
                    className: "btn-default"
                },
                success: {
                    label: success_button_label,
                    className: "btn-success",
                    callback: on_success_callback
                }
            }
        });
    };

    var get_command_description = function(command_id) {
        var command_description_elem = $('.command-description-' + command_id);
        return command_description_elem.length > 0 ? command_description = command_description_elem.html().trim() : "";
    };

    var get_command_text = function(command_id) {
         return $('.pre-command-' + command_id).html().substring(3);
    };

    $.notifyDefaults({
        animate: {
            enter: 'animated fadeInDown',
            exit: 'animated fadeOutUp'
        }
    });
    $("#show-api-key").click(function() {
        $("#show-api-key").hide();
        $("#hide-api-key").show();
        $("#api-key").show();
    });
    $("#hide-api-key").click(function() {
        $("#show-api-key").show();
        $("#hide-api-key").hide();
        $("#api-key").hide();
    });
    $("#regenerate-api-key").click(function() {
        $.ajax("/_regenerate_api_key").done(function(data){
            $('#api-key-value').html(data.api_key);
        });
    });
    $(".btn-delete-command").click(function() {
        var command_id = $(this).data('command-id');
        $(this).hide();
        var that = this;
        $.post("/_delete_command/" + command_id).done(function(done){
            $("#command-row-" + command_id).remove();
            $.notify("Succesfully removed the command!");
        }).fail(function() {
            $(that).show();
            $.notify("Failed to remove the command!");
        });
    });
    $(".btn-star-command").click(function() {
        var command_id = $(this).data('command-id');
        var that = this;
        $.post("/_star_command/" + command_id).done(function(done){
            $(that).hide();
            $(".btn-unstar-command-" + command_id).show();
            $.notify("Succesfully starred the command!");
        }).fail(function() {
            $(that).show();
            $.notify("Failed to star the command!");
        });
    });

    $(".btn-publish-command").click(function() {
        var command_id = $(this).data('command-id');
        var that = this;
        var command_description = get_command_description(command_id);
        var command_text = get_command_text(command_id);
        update_command(command_id, command_description, command_text, "Publish command", "Publish", function() {
            var command_text = $('#pbf-command-' + command_id).val();
            var command_description = $('#pbf-description-' + command_id).val();
            $.post("/_publish_command/" + command_id,
                    {
                        description: command_description,
                        command: command_text
                    }
                  ).done(function(done){
                $(that).hide();
                $(".btn-unpublish-command-" + command_id).show();
                $(".public-title-" + command_id).show();
                $(".private-title-" + command_id).hide();
                $(".pre-command-" + command_id).html(" $ " + html_escape(command_text));
                $(".command-description-" + command_id).html(html_escape(command_description));
                $.notify("Succesfully published the command!");
            }).fail(function() {
                $(that).show();
                $.notify("Failed to publish the command!");
            });
        });
    });

    $(".btn-edit-command").click(function() {
        var command_id = $(this).data('command-id');
        var that = this;
        var command_description = get_command_description(command_id);
        var command_text = get_command_text(command_id);
        update_command(command_id, command_description, command_text, "Edit command", "Update", function() {
            var command_text = $('#pbf-command-' + command_id).val();
            var command_description = $('#pbf-description-' + command_id).val();
            $.post("/_edit_command/" + command_id,
                    {
                        description: command_description,
                        command: command_text
                    }
                  ).done(function(done){
                    $(".pre-command-" + command_id).html(" $ " + html_escape(command_text));
                    $(".command-description-" + command_id).html(html_escape(command_description));
                    $.notify("Succesfully updated the command!");
                  }).fail(function() {
                    $.notify("Failed to update the command!");
                  });
        });
    });

    $(".btn-unpublish-command").click(function() {
        var command_id = $(this).data('command-id');
        var that = this;
        bootbox.confirm("Are you sure to unpublish the command?", function(result) {
            if (result) {
                $.post("/_unpublish_command/" + command_id).done(function(done){
                    $(that).hide();
                    $(".btn-publish-command-" + command_id).show();
                    $(".public-title-" + command_id).hide();
                    $(".private-title-" + command_id).show();
                    $.notify("Succesfully made the command private!");
                }).fail(function() {
                    $(that).show();
                    $.notify("Failed make the command private!");
                });
            }
        });
    });

    $(".command-compact").click(function() {
        var command_id = $(this).data('command-id');
        $(".command-controls-" + command_id).toggle();
        var row = $(".command-row-" + command_id);
        if (row.hasClass('command-row-clicked')) {
            row.removeClass('command-row-clicked');
            row.find('pre').removeClass('code-compact-clicked');
        } else {
            row.addClass('command-row-clicked');
            row.find('pre').addClass('code-compact-clicked');
        }
    });
});
<|endoftext|>