packages feed

battleships-1.0.0: templates/play.julius

function clickableInit(elem, target) {
    elem.click(function (event) {
        clickableEvent(event, target);
    });
}

function clickableEvent(event, target) {
    var form = document.createElement('form');
    form.setAttribute('method', 'post');
    form.setAttribute('action', target);

    var offset = $(event.target).offset();
    var x = event.pageX - offset.left;
    var y = event.pageY - offset.top;

    var hiddenField = document.createElement('input');
    hiddenField.setAttribute('type','hidden');
    hiddenField.setAttribute('name','X');
    hiddenField.setAttribute('value',x);
    form.appendChild(hiddenField);

    hiddenField = document.createElement('input');
    hiddenField.setAttribute('type','hidden');
    hiddenField.setAttribute('name','Y');
    hiddenField.setAttribute('value',-y);
    form.appendChild(hiddenField);

    document.body.appendChild(form);
    form.submit();
}

function playScriptInit(moveUrl, fireUrl) {
    clickableInit($(".actionMove"), moveUrl);
    clickableInit($(".actionFire"), fireUrl);
    if(alertCountdown == "True") {
        alert(alertMessage);
    }
}

function confirmReplay() {
    conf = window.confirm("#{rawJS (messageRender MsgConfirmReplay)}");
    if (conf == true) {
        document.location = replayUrl;
    }
}