<commit_before>var pageData = {};

function buildQuizList (rows) {
    var commenterID = getParameterByName('commenter');
    var classID = getParameterByName('classid');
    if (!rows) {
        // if rows is nil, call the server.
        var rows = apiRequest(
            '/?commenter='
                + commenterID
                + '&page=class'
                + '&cmd=readquizzes'
            , {
                classid:classID
            }
        );
        if (false === rows) return;
    }
    rows.sort(function (a,b) {
        a = parseInt(a.number,10);
        b = parseInt(b.number,10);
        if (a>b) {
            return 1;
        } else if (a<b) {
            return -1;
        } else {
            return 0;
        }
    });
    // Delete children from container
    var container = document.getElementById('quiz-list');
    for (var i=0,ilen=container.childNodes.length;i<ilen;i+=1) {
        container.removeChild(container.childNodes[0]);
    }
    // Rebuild container content
    for (var i=0,ilen=rows.length;i<ilen;i+=1) {
        var nameText = document.createTextNode("Quiz "+rows[i].number);
        var idText = document.createTextNode(rows[i].number);
        var tr = document.createElement('tr');
        var nameAnchor = document.createElement('a');
        var nameTD = document.createElement('td');
        var idTD = document.createElement('td');
        nameAnchor.appendChild(nameText);

        nameAnchor.setAttribute('href', fixPath('/?commenter=' + commenterID + '&page=quiz&classid=' + classID + '&quizno=' + rows[i].number));

        nameTD.appendChild(nameAnchor);
        tr.appendChild(nameTD);
        idTD.appendChild(idText);
        idTD.style.display = 'none';
        tr.appendChild(idTD)
        if (rows[i].numberOfCommentsNeeded) {
            var markerText = document.createTextNode('(' + rows[i].numberOfCommentsNeeded + ')');
            var markerTD = document.createElement('td');
            markerTD.appendChild(markerText);
            tr.appendChild(markerTD);
        }
        container.appendChild(tr);
    }
}

function setRuleButtons () {
    var ruleLangButtons = document.getElementsByClassName('rule-lang-buttons');
    // API call
    var commenterKey = getParameterByName('commenter');
    var rows = apiRequest(
        '/?commenter='
            + commenterKey
            + '&page=class'
            + '&cmd=readrulelangs'
    );
    if (false === rows) return;
    var ruleLangButtons = document.getElementById('rule-lang-buttons');
    for (var i=0,ilen=ruleLangButtons.childNodes.length;i<ilen;i+=1) {
        ruleLangButtons.removeChild(ruleLangButtons.childNodes[0]);
    }
    for (var i=0,ilen=rows.length;i<ilen;i+=1) {
        var row = rows[i];
        var button = document.createElement('input');
        button.setAttribute('type', 'button');
        button.setAttribute('class', 'button rule-lang-buttons');
        button.setAttribute('onclick', 'setButtonMode("' + row.lang + '","' + row.langName + '")');
        button.value = 'Glosses: ' + row.langName;
        ruleLangButtons.appendChild(button);
    }
}

function setButtonMode (mode,langName) {
    var ruleLangButtons = document.getElementsByClassName('rule-lang-buttons');
    var returnToMainDisplayButton = document.getElementById('return-to-main-display-button');
    var mainDisplay = document.getElementById('main-display');
    var rulesDisplay = document.getElementById('rules-display');
    var mainDisplayTitle = document.getElementById('main-display-title');
    var rulesDisplayTitle = document.getElementById('rules-display-title');
    if (mode) {
        pageData.lang = mode;
        pageData.langName = langName;
        buildRulesList(mode,langName);
        for (var i=0,ilen=ruleLangButtons.length;i<ilen;i+=1) {
            ruleLangButtons[i].style.display = 'none';
        }
        returnToMainDisplayButton.style.display = 'inline';
        mainDisplay.style.display = 'none';
        mainDisplayTitle.style.display = 'none';
        rulesDisplay.style.display = 'table';
        rulesDisplayTitle.style.display = 'block';
    } else {
        for (var i=0,ilen=ruleLangButtons.length;i<ilen;i+=1) {
            ruleLangButtons[i].style.display = 'inline';
        }
        returnToMainDisplayButton.style.display = 'none';
        mainDisplay.style.display = 'table';
        mainDisplayTitle.style.display = 'block';
        rulesDisplay.style.display = 'none';
        rulesDisplayTitle.style.display = 'none';
    }
}

function buildRulesList () {
    var mode = pageData.lang;
    var langName = pageData.langName;
    var ruleLanguageName = document.getElementById('rule-language');
    ruleLanguageName.innerHTML = langName;
    // API call for list of rules (admin user + current commenter)
    var commenterKey = getParameterByName('commenter');
    var classID = getParameterByName('classid');
    var rulesForLang = document.getElementById('rules-for-lang');
    var rows = apiRequest(
        '/?commenter='
            + commenterKey
            + '&page=class'
            + '&cmd=readrules'
        , {
            lang:mode,
            classid:classID
        }
    );
    if (false === rows) return;
    for (var i=0,ilen=rulesForLang.childNodes.length;i<ilen;i+=1) {
        rulesForLang.removeChild(rulesForLang.childNodes[0]);
    }
    for (var i=0,ilen=rows.length;i<ilen;i+=1) {
        var row = rows[i];
        var tr = document.createElement('tr');
        tr.setAttribute('id','rule-' + row.ruleID);
        var needsGloss = ' needs-gloss';
        if (row.hasGloss) {
            needsGloss = '';
        }
        tr.innerHTML = '
' + markdown(row.ruleText) + '
	<input type="button" class="button float-right" value="Save" onclick="saveRule(this)" style="display:none;"/><input type="button" class="button float-right" value="Edit" onclick="editRule(this)" style="display:none;"/><input type="button" class="button no-float" value="Del" onclick="confirmDelete(this,\'deleteRule\')" style="display:none;"/>	';
        rulesForLang.appendChild(tr);
    }
};

function deleteRule (node) {
    // API call
    var rownode = node.parentNode.parentNode;
    var ruleID = rownode.id.split('-').slice(-1)[0];
    var commenterKey = getParameterByName('commenter');
    var row = apiRequest(
        '/?commenter='
            + commenterKey
            + '&page=class'
            + '&cmd=deleteonerule'
        ,{
            ruleid:ruleID,
            lang:pageData.lang
        }
    );
    if (false === row) return;
    var nextnode = rownode.nextSibling;
    nextnode.parentNode.removeChild(nextnode);
    rownode.parentNode.removeChild(rownode);
};

function setTexareaHeight (textarea) {
    var height = textarea.parentNode.offsetHeight;
    textarea.style.height = height;
}

function openRule (node) {
    var rownode = node.parentNode;
    var ruleID = rownode.id.split('-').slice(-1)[0];
    var saveButton = rownode.childNodes[1].childNodes[0];
    var deleteButton = rownode.childNodes[1].childNodes[2];
    saveButton.style.display = 'inline';
    // API call
    var commenterKey = getParameterByName('commenter');
    var row = apiRequest(
        '/?commenter='
            + commenterKey
            + '&page=class'
            + '&cmd=readonerule'
        ,{
            ruleid:ruleID,
            lang:pageData.lang
        }
    );
    if (false === row) return;
    if (row.ruleSource) {
        var renderedrule = rownode.childNodes[0].childNodes[0];
        var textarea = document.createElement('textarea');
        textarea.innerHTML = row.ruleSource;
        renderedrule.parentNode.replaceChild(textarea,renderedrule);
        deleteButton.style.display = 'inline';
    }
    var tr = document.createElement('tr');
    tr.innerHTML = '
' + markdown(row.stringOrig) + '
	<textarea>' + row.stringTrans + '</textarea>	'
    rownode.parentNode.insertBefore(tr,rownode.nextSibling);
    node.setAttribute('onclick','void(0);');
    setTextareaHeight(tr.childNodes[1].childNodes[0]);
};

function saveRule (node) {
    var rownode = node.parentNode.parentNode;
    var orignode = rownode.nextSibling.childNodes[0];
    var textnode = rownode.nextSibling.childNodes[1].childNodes[0];
    var rulenode = rownode.childNodes[0].childNodes[0];
    ruleText = rulenode.tagName === 'TEXTAREA' ? rulenode.value : null;
    var glossText = textnode.value;
    var ruleID = rownode.id.split('-').slice(-1)[0];
    var saveButton = rownode.childNodes[1].childNodes[0];
    var editButton = rownode.childNodes[1].childNodes[1];
    var deleteButton = rownode.childNodes[1].childNodes[2];
    // API call
    var commenterKey = getParameterByName('commenter');
    var row = apiRequest(
        '/?commenter='
            + commenterKey
            + '&page=class'
            + '&cmd=saveonerule'
        ,{
            ruleid:ruleID,
            lang:pageData.lang,
            glosstext:glossText,
            ruletext:ruleText
        }
    );
    if (false === row) return;
    if (ruleText) {
        var ruleTextNode = document.createElement('div');
        ruleTextNode.innerHTML = markdown(row.ruleText);
        rulenode.parentNode.replaceChild(ruleTextNode,rulenode);
        ruleTextNode.parentNode.setAttribute('onclick','closeRule(this);');
    }
    orignode.innerHTML = markdown(row.stringOrig);
    var renderedNode = document.createElement('div');
    renderedNode.innerHTML = markdown(row.stringTrans);
    textnode.parentNode.replaceChild(renderedNode,textnode);
    saveButton.style.display = 'none';
    editButton.style.display = 'inline';
    deleteButton.style.display = 'none';
    node.parentNode.previousSibling.setAttribute('onclick','closeRule(this);');
};

function editRule (node) {
    var rownode = node.parentNode.parentNode;
    var renderednode = rownode.nextSibling.childNodes[1].childNodes[0];
    var ruleID = rownode.id.split('-').slice(-1)[0];
    var saveButton = rownode.childNodes[1].childNodes[0];
    var editButton = rownode.childNodes[1].childNodes[1];
    var deleteButton = rownode.childNodes[1].childNodes[2];
    // API call
    var commenterKey = getParameterByName('commenter');
    var row = apiRequest(
        '/?commenter='
            + commenterKey
            + '&page=class'
            + '&cmd=readonerule'
        ,{
            ruleid:ruleID,
            lang:pageData.lang
        }
    );
    if (false === row) return;
    if (row.ruleSource) {
        var renderedrule = rownode.childNodes[0].childNodes[0];
        var textarea = document.createElement('textarea');
        textarea.innerHTML = row.ruleSource;
        renderedrule.parentNode.replaceChild(textarea,renderedrule);
        deleteButton.style.display = 'inline';
    }
    var textnode = document.createElement('textarea');
    textnode.innerHTML = row.stringTrans;
    renderednode.parentNode.replaceChild(textnode,renderednode);
    saveButton.style.display = 'inline';
    editButton.style.display = 'none';
    node.parentNode.previousSibling.setAttribute('onclick','void(0);');
};

function closeRule (node) {
    var rownode = node.parentNode;
    var saveButton = rownode.childNodes[1].childNodes[0];
    var editButton = rownode.childNodes[1].childNodes[1];
    var deleteButton = rownode.childNodes[1].childNodes[2];
    saveButton.style.display = 'none';
    editButton.style.display = 'none';
    deleteButton.style.display = 'none';
    var contentrownode = rownode.nextSibling;
    contentrownode.parentNode.removeChild(contentrownode);
    node.setAttribute('onclick', 'openRule(this);');
};
<commit_msg>Always use a child div on rendered content box<commit_after>var pageData = {};

function buildQuizList (rows) {
    var commenterID = getParameterByName('commenter');
    var classID = getParameterByName('classid');
    if (!rows) {
        // if rows is nil, call the server.
        var rows = apiRequest(
            '/?commenter='
                + commenterID
                + '&page=class'
                + '&cmd=readquizzes'
            , {
                classid:classID
            }
        );
        if (false === rows) return;
    }
    rows.sort(function (a,b) {
        a = parseInt(a.number,10);
        b = parseInt(b.number,10);
        if (a>b) {
            return 1;
        } else if (a<b) {
            return -1;
        } else {
            return 0;
        }
    });
    // Delete children from container
    var container = document.getElementById('quiz-list');
    for (var i=0,ilen=container.childNodes.length;i<ilen;i+=1) {
        container.removeChild(container.childNodes[0]);
    }
    // Rebuild container content
    for (var i=0,ilen=rows.length;i<ilen;i+=1) {
        var nameText = document.createTextNode("Quiz "+rows[i].number);
        var idText = document.createTextNode(rows[i].number);
        var tr = document.createElement('tr');
        var nameAnchor = document.createElement('a');
        var nameTD = document.createElement('td');
        var idTD = document.createElement('td');
        nameAnchor.appendChild(nameText);

        nameAnchor.setAttribute('href', fixPath('/?commenter=' + commenterID + '&page=quiz&classid=' + classID + '&quizno=' + rows[i].number));

        nameTD.appendChild(nameAnchor);
        tr.appendChild(nameTD);
        idTD.appendChild(idText);
        idTD.style.display = 'none';
        tr.appendChild(idTD)
        if (rows[i].numberOfCommentsNeeded) {
            var markerText = document.createTextNode('(' + rows[i].numberOfCommentsNeeded + ')');
            var markerTD = document.createElement('td');
            markerTD.appendChild(markerText);
            tr.appendChild(markerTD);
        }
        container.appendChild(tr);
    }
}

function setRuleButtons () {
    var ruleLangButtons = document.getElementsByClassName('rule-lang-buttons');
    // API call
    var commenterKey = getParameterByName('commenter');
    var rows = apiRequest(
        '/?commenter='
            + commenterKey
            + '&page=class'
            + '&cmd=readrulelangs'
    );
    if (false === rows) return;
    var ruleLangButtons = document.getElementById('rule-lang-buttons');
    for (var i=0,ilen=ruleLangButtons.childNodes.length;i<ilen;i+=1) {
        ruleLangButtons.removeChild(ruleLangButtons.childNodes[0]);
    }
    for (var i=0,ilen=rows.length;i<ilen;i+=1) {
        var row = rows[i];
        var button = document.createElement('input');
        button.setAttribute('type', 'button');
        button.setAttribute('class', 'button rule-lang-buttons');
        button.setAttribute('onclick', 'setButtonMode("' + row.lang + '","' + row.langName + '")');
        button.value = 'Glosses: ' + row.langName;
        ruleLangButtons.appendChild(button);
    }
}

function setButtonMode (mode,langName) {
    var ruleLangButtons = document.getElementsByClassName('rule-lang-buttons');
    var returnToMainDisplayButton = document.getElementById('return-to-main-display-button');
    var mainDisplay = document.getElementById('main-display');
    var rulesDisplay = document.getElementById('rules-display');
    var mainDisplayTitle = document.getElementById('main-display-title');
    var rulesDisplayTitle = document.getElementById('rules-display-title');
    if (mode) {
        pageData.lang = mode;
        pageData.langName = langName;
        buildRulesList(mode,langName);
        for (var i=0,ilen=ruleLangButtons.length;i<ilen;i+=1) {
            ruleLangButtons[i].style.display = 'none';
        }
        returnToMainDisplayButton.style.display = 'inline';
        mainDisplay.style.display = 'none';
        mainDisplayTitle.style.display = 'none';
        rulesDisplay.style.display = 'table';
        rulesDisplayTitle.style.display = 'block';
    } else {
        for (var i=0,ilen=ruleLangButtons.length;i<ilen;i+=1) {
            ruleLangButtons[i].style.display = 'inline';
        }
        returnToMainDisplayButton.style.display = 'none';
        mainDisplay.style.display = 'table';
        mainDisplayTitle.style.display = 'block';
        rulesDisplay.style.display = 'none';
        rulesDisplayTitle.style.display = 'none';
    }
}

function buildRulesList () {
    var mode = pageData.lang;
    var langName = pageData.langName;
    var ruleLanguageName = document.getElementById('rule-language');
    ruleLanguageName.innerHTML = langName;
    // API call for list of rules (admin user + current commenter)
    var commenterKey = getParameterByName('commenter');
    var classID = getParameterByName('classid');
    var rulesForLang = document.getElementById('rules-for-lang');
    var rows = apiRequest(
        '/?commenter='
            + commenterKey
            + '&page=class'
            + '&cmd=readrules'
        , {
            lang:mode,
            classid:classID
        }
    );
    if (false === rows) return;
    for (var i=0,ilen=rulesForLang.childNodes.length;i<ilen;i+=1) {
        rulesForLang.removeChild(rulesForLang.childNodes[0]);
    }
    for (var i=0,ilen=rows.length;i<ilen;i+=1) {
        var row = rows[i];
        var tr = document.createElement('tr');
        tr.setAttribute('id','rule-' + row.ruleID);
        var needsGloss = ' needs-gloss';
        if (row.hasGloss) {
            needsGloss = '';
        }
        tr.innerHTML = '
' + markdown(row.ruleText) + '
	<input type="button" class="button float-right" value="Save" onclick="saveRule(this)" style="display:none;"/><input type="button" class="button float-right" value="Edit" onclick="editRule(this)" style="display:none;"/><input type="button" class="button no-float" value="Del" onclick="confirmDelete(this,\'deleteRule\')" style="display:none;"/>	';
        rulesForLang.appendChild(tr);
    }
};

function deleteRule (node) {
    // API call
    var rownode = node.parentNode.parentNode;
    var ruleID = rownode.id.split('-').slice(-1)[0];
    var commenterKey = getParameterByName('commenter');
    var row = apiRequest(
        '/?commenter='
            + commenterKey
            + '&page=class'
            + '&cmd=deleteonerule'
        ,{
            ruleid:ruleID,
            lang:pageData.lang
        }
    );
    if (false === row) return;
    var nextnode = rownode.nextSibling;
    nextnode.parentNode.removeChild(nextnode);
    rownode.parentNode.removeChild(rownode);
};

function setTexareaHeight (textarea) {
    var height = textarea.parentNode.offsetHeight;
    textarea.style.height = height;
}

function openRule (node) {
    var rownode = node.parentNode;
    var ruleID = rownode.id.split('-').slice(-1)[0];
    var saveButton = rownode.childNodes[1].childNodes[0];
    var deleteButton = rownode.childNodes[1].childNodes[2];
    saveButton.style.display = 'inline';
    // API call
    var commenterKey = getParameterByName('commenter');
    var row = apiRequest(
        '/?commenter='
            + commenterKey
            + '&page=class'
            + '&cmd=readonerule'
        ,{
            ruleid:ruleID,
            lang:pageData.lang
        }
    );
    if (false === row) return;
    if (row.ruleSource) {
        var renderedrule = rownode.childNodes[0].childNodes[0];
        var textarea = document.createElement('textarea');
        textarea.innerHTML = row.ruleSource;
        renderedrule.parentNode.replaceChild(textarea,renderedrule);
        deleteButton.style.display = 'inline';
    }
    var tr = document.createElement('tr');
    tr.innerHTML = '
' + markdown(row.stringOrig) + '
	<textarea>' + row.stringTrans + '</textarea>	'
    rownode.parentNode.insertBefore(tr,rownode.nextSibling);
    node.setAttribute('onclick','void(0);');
    setTextareaHeight(tr.childNodes[1].childNodes[0]);
};

function saveRule (node) {
    var rownode = node.parentNode.parentNode;
    var orignode = rownode.nextSibling.childNodes[0];
    var textnode = rownode.nextSibling.childNodes[1].childNodes[0];
    var rulenode = rownode.childNodes[0].childNodes[0];
    ruleText = rulenode.tagName === 'TEXTAREA' ? rulenode.value : null;
    var glossText = textnode.value;
    var ruleID = rownode.id.split('-').slice(-1)[0];
    var saveButton = rownode.childNodes[1].childNodes[0];
    var editButton = rownode.childNodes[1].childNodes[1];
    var deleteButton = rownode.childNodes[1].childNodes[2];
    // API call
    var commenterKey = getParameterByName('commenter');
    var row = apiRequest(
        '/?commenter='
            + commenterKey
            + '&page=class'
            + '&cmd=saveonerule'
        ,{
            ruleid:ruleID,
            lang:pageData.lang,
            glosstext:glossText,
            ruletext:ruleText
        }
    );
    if (false === row) return;
    if (ruleText) {
        var ruleTextNode = document.createElement('div');
        ruleTextNode.innerHTML = markdown(row.ruleText);
        rulenode.parentNode.replaceChild(ruleTextNode,rulenode);
        ruleTextNode.parentNode.setAttribute('onclick','closeRule(this);');
    }
    orignode.innerHTML = '
' + markdown(row.stringOrig) + '
';
    var renderedNode = document.createElement('div');
    renderedNode.innerHTML = markdown(row.stringTrans);
    textnode.parentNode.replaceChild(renderedNode,textnode);
    saveButton.style.display = 'none';
    editButton.style.display = 'inline';
    deleteButton.style.display = 'none';
    node.parentNode.previousSibling.setAttribute('onclick','closeRule(this);');
};

function editRule (node) {
    var rownode = node.parentNode.parentNode;
    var renderednode = rownode.nextSibling.childNodes[1].childNodes[0];
    var ruleID = rownode.id.split('-').slice(-1)[0];
    var saveButton = rownode.childNodes[1].childNodes[0];
    var editButton = rownode.childNodes[1].childNodes[1];
    var deleteButton = rownode.childNodes[1].childNodes[2];
    // API call
    var commenterKey = getParameterByName('commenter');
    var row = apiRequest(
        '/?commenter='
            + commenterKey
            + '&page=class'
            + '&cmd=readonerule'
        ,{
            ruleid:ruleID,
            lang:pageData.lang
        }
    );
    if (false === row) return;
    if (row.ruleSource) {
        var renderedrule = rownode.childNodes[0].childNodes[0];
        var textarea = document.createElement('textarea');
        textarea.innerHTML = row.ruleSource;
        renderedrule.parentNode.replaceChild(textarea,renderedrule);
        deleteButton.style.display = 'inline';
    }
    var textnode = document.createElement('textarea');
    textnode.innerHTML = row.stringTrans;
    renderednode.parentNode.replaceChild(textnode,renderednode);
    saveButton.style.display = 'inline';
    editButton.style.display = 'none';
    node.parentNode.previousSibling.setAttribute('onclick','void(0);');
};

function closeRule (node) {
    var rownode = node.parentNode;
    var saveButton = rownode.childNodes[1].childNodes[0];
    var editButton = rownode.childNodes[1].childNodes[1];
    var deleteButton = rownode.childNodes[1].childNodes[2];
    saveButton.style.display = 'none';
    editButton.style.display = 'none';
    deleteButton.style.display = 'none';
    var contentrownode = rownode.nextSibling;
    contentrownode.parentNode.removeChild(contentrownode);
    node.setAttribute('onclick', 'openRule(this);');
};
<|endoftext|>


<commit_before>
var ContentIterator = function(input){
    this.input = input;
    this.index = 0;
};

ContentIterator.prototype = {

    getLetter: function(){
        var input = this.input.value;
        this.index = (++this.index) % input.length;
        return input.charAt(this.index);
    }

};
<commit_msg>fixing issue where first letter was not being shown<commit_after>
var ContentIterator = function(input){
    this.input = input;
    this.index = 0;
};

ContentIterator.prototype = {

    getLetter: function(){
        var input = this.input.value,
            letter = input.charAt(this.index);
        this.index = (++this.index) % input.length;
        return letter;
    }

};
<|endoftext|>


<commit_before>var Pac = function(state, x, y) {
   Phaser.Sprite.call(this, state.game, x, y, 'player');

   this.texture.baseTexture.scaleMode = PIXI.scaleModes.NEAREST;
   this.game.physics.arcade.enable(this);
   this.game.add.existing(this);

   this.body.collideWordlBounds = true;
   this.body.immovable = false;
   this.body.isCircle = true; // MAGIC !!!
   this.anchor.setTo(0.5);

   this.speed = 5;
   this.state = state;
   this.state.turnPoint.x = x;
   this.state.turnPoint.y = y;
   this.current = Phaser.NONE;
   this.turning = Phaser.NONE;
   this.threshold = 3;

   this.animations.add('chomp', [0,1,2,1],   12,true);
   this.animations.play('chomp');
}

Pac.prototype = Object.create(Phaser.Sprite.prototype);
Pac.prototype.constructor = Pac;

Pac.prototype.update = function() {
   this.game.physics.arcade.collide(this, this.state.layer);
   this.game.physics.arcade.overlap(this, this.state.dots, this.state.eatDot, null, this.state);

   if (this.state.cursors.up.isDown && this.current !== Phaser.UP) {
      this.checkDirection(Phaser.UP);
   } else if (this.state.cursors.down.isDown && this.current !== Phaser.DOWN) {
      this.checkDirection(Phaser.DOWN);
   } else if (this.state.cursors.left.isDown && this.current !== Phaser.LEFT) {
      this.checkDirection(Phaser.LEFT);
   } else if (this.state.cursors.right.isDown && this.current !== Phaser.RIGHT) {
      this.checkDirection(Phaser.RIGHT);
   }
   else {
      this.turning = Phaser.NONE;
   }

   if (this.turning !== Phaser.NONE) {
      this.turn();
   }
}

Pac.prototype.checkDirection = function(turnTo) {
   if (this.turning === turnTo || this.state.directions[turnTo] === null || this.state.directions[turnTo].index !== this.state.safeTile)
      return;

   if (this.current === this.state.opposites[turnTo])
      this.move(turnTo);
   else
   {
      this.turning = turnTo;

      this.state.turnPoint.x = (this.state.marker.x * TILE_SIZE) + (TILE_SIZE / 2);
      this.state.turnPoint.y = (this.state.marker.y * TILE_SIZE) + (TILE_SIZE / 2);
   }
}

Pac.prototype.turn = function () {

   var cx = Math.floor(this.x);
   var cy = Math.floor(this.y);

   //  This needs a threshold, because at high speeds you can't turn because the coordinates skip past
   if (!this.state.math.fuzzyEqual(cx, this.state.turnPoint.x, this.threshold) || !this.state.math.fuzzyEqual(cy, this.state.turnPoint.y, this.threshold))
      return false;

   //  Grid align before turning
   this.x = this.state.turnPoint.x;
   this.y = this.state.turnPoint.y;

   this.body.reset(this.x, this.y);

   this.move(this.turning);

   this.turning = Phaser.NONE;

   return true;

}

Pac.prototype.move = function(direction) {
   var speed = this.speed;
   this.scale.x = 1;
   this.angle = 0;

   if (direction === Phaser.LEFT || direction === Phaser.UP)
      speed = -speed;

   if (direction === Phaser.RIGHT || direction === Phaser.LEFT)
      this.body.velocity.x = speed;
   else
      this.body.velocity.y = speed;

   //  Reset the scale and angle (Pacman is facing to the right in the sprite sheet)

   if (direction === Phaser.LEFT)
      this.scale.x = -1;
   else if (direction === Phaser.UP)
      this.angle = 270;
   else if (direction === Phaser.DOWN)
      this.angle = 90;

   this.current = direction;
}
<commit_msg>forgot to fix speed<commit_after>var Pac = function(state, x, y) {
   Phaser.Sprite.call(this, state.game, x, y, 'player');

   this.texture.baseTexture.scaleMode = PIXI.scaleModes.NEAREST;
   this.game.physics.arcade.enable(this);
   this.game.add.existing(this);

   this.body.collideWordlBounds = true;
   this.body.immovable = false;
   this.body.isCircle = true; // MAGIC !!!
   this.anchor.setTo(0.5);

   this.speed = 75;
   this.state = state;
   this.state.turnPoint.x = x;
   this.state.turnPoint.y = y;
   this.current = Phaser.NONE;
   this.turning = Phaser.NONE;
   this.threshold = 3;

   this.animations.add('chomp', [0,1,2,1],   12,true);
   this.animations.play('chomp');
}

Pac.prototype = Object.create(Phaser.Sprite.prototype);
Pac.prototype.constructor = Pac;

Pac.prototype.update = function() {
   this.game.physics.arcade.collide(this, this.state.layer);
   this.game.physics.arcade.overlap(this, this.state.dots, this.state.eatDot, null, this.state);

   if (this.state.cursors.up.isDown && this.current !== Phaser.UP) {
      this.checkDirection(Phaser.UP);
   } else if (this.state.cursors.down.isDown && this.current !== Phaser.DOWN) {
      this.checkDirection(Phaser.DOWN);
   } else if (this.state.cursors.left.isDown && this.current !== Phaser.LEFT) {
      this.checkDirection(Phaser.LEFT);
   } else if (this.state.cursors.right.isDown && this.current !== Phaser.RIGHT) {
      this.checkDirection(Phaser.RIGHT);
   }
   else {
      this.turning = Phaser.NONE;
   }

   if (this.turning !== Phaser.NONE) {
      this.turn();
   }
}

Pac.prototype.checkDirection = function(turnTo) {
   if (this.turning === turnTo || this.state.directions[turnTo] === null || this.state.directions[turnTo].index !== this.state.safeTile)
      return;

   if (this.current === this.state.opposites[turnTo])
      this.move(turnTo);
   else
   {
      this.turning = turnTo;

      this.state.turnPoint.x = (this.state.marker.x * TILE_SIZE) + (TILE_SIZE / 2);
      this.state.turnPoint.y = (this.state.marker.y * TILE_SIZE) + (TILE_SIZE / 2);
   }
}

Pac.prototype.turn = function () {

   var cx = Math.floor(this.x);
   var cy = Math.floor(this.y);

   //  This needs a threshold, because at high speeds you can't turn because the coordinates skip past
   if (!this.state.math.fuzzyEqual(cx, this.state.turnPoint.x, this.threshold) || !this.state.math.fuzzyEqual(cy, this.state.turnPoint.y, this.threshold))
      return false;

   //  Grid align before turning
   this.x = this.state.turnPoint.x;
   this.y = this.state.turnPoint.y;

   this.body.reset(this.x, this.y);

   this.move(this.turning);

   this.turning = Phaser.NONE;

   return true;

}

Pac.prototype.move = function(direction) {
   var speed = this.speed;
   this.scale.x = 1;
   this.angle = 0;

   if (direction === Phaser.LEFT || direction === Phaser.UP)
      speed = -speed;

   if (direction === Phaser.RIGHT || direction === Phaser.LEFT)
      this.body.velocity.x = speed;
   else
      this.body.velocity.y = speed;

   //  Reset the scale and angle (Pacman is facing to the right in the sprite sheet)

   if (direction === Phaser.LEFT)
      this.scale.x = -1;
   else if (direction === Phaser.UP)
      this.angle = 270;
   else if (direction === Phaser.DOWN)
      this.angle = 90;

   this.current = direction;
}
<|endoftext|>


<commit_before>HAL.Http.Client = function(opts) {
  this.vent = opts.vent;
  $.ajaxSetup({ headers: { 'Accept': 'application/hal+json, application/json, */*; q=0.01' } });
};

HAL.Http.Client.prototype.get = function(url) {
  var self = this;
  this.vent.trigger('location-change', { url: url });
  var jqxhr = $.ajax({
    url: url,
    dataType: 'json',
    success: function(resource, textStatus, jqXHR) {
      self.vent.trigger('response', {
        resource: resource,
        jqxhr: jqXHR,
        headers: jqXHR.getAllResponseHeaders()
      });
    }
  }).error(function() {
    self.vent.trigger('fail-response', { jqxhr: jqxhr });
  });
};

HAL.Http.Client.prototype.request = function(opts) {
  var self = this;
  opts.dataType = 'json';
  self.vent.trigger('location-change', { url: opts.url });
  return jqxhr = $.ajax(opts);
};

HAL.Http.Client.prototype.updateDefaultHeaders = function(headers) {
  this.defaultHeaders = headers;
  $.ajaxSetup({ headers: headers });
};

HAL.Http.Client.prototype.getDefaultHeaders = function() {
  return this.defaultHeaders;
};
<commit_msg>Fix for $.ajaxSetup not working in Chrome. Usage is not recommended. This caused changes to custom request headers to be ignored. Calling ajaxSetup wasn't updating the headers used by the next AJAX call. The jQuery docs recommend not using ajaxSetup.<commit_after>HAL.Http.Client = function(opts) {
  this.vent = opts.vent;
  this.defaultHeaders = { 'Accept': 'application/hal+json, application/json, */*; q=0.01' };
};

HAL.Http.Client.prototype.get = function(url) {
  var self = this;
  this.vent.trigger('location-change', { url: url });
  var jqxhr = $.ajax({
    url: url,
    dataType: 'json',
    headers: this.defaultHeaders,
    success: function(resource, textStatus, jqXHR) {
      self.vent.trigger('response', {
        resource: resource,
        jqxhr: jqXHR,
        headers: jqXHR.getAllResponseHeaders()
      });
    }
  }).error(function() {
    self.vent.trigger('fail-response', { jqxhr: jqxhr });
  });
};

HAL.Http.Client.prototype.request = function(opts) {
  var self = this;
  opts.dataType = 'json';
  self.vent.trigger('location-change', { url: opts.url });
  return jqxhr = $.ajax(opts);
};

HAL.Http.Client.prototype.updateDefaultHeaders = function(headers) {
  this.defaultHeaders = headers;
};

HAL.Http.Client.prototype.getDefaultHeaders = function() {
  return this.defaultHeaders;
};
<|endoftext|>


<commit_before>define(["js/core/Component", "js/core/Content", "js/core/Binding", "inherit", "underscore"], function (Component, Content, Binding, inherit, _) {

        var rspace = /\s+/;
        var domEvents = ['click', 'dblclick', 'keyup', 'keydown' , 'change'];

        var DomElementFunctions = {
            defaults: {
                selected: undefined,
                selectable: undefined
            },
            $behavesAsDomElement: true,
            ctor: function (attributes, descriptor, systemManager, parentScope, rootScope) {
                this.$renderMap = {};
                this.$childViews = [];
                this.$contentChildren = [];
                this.callBase();

                if (descriptor) {
                    if (!this.$tagName) {
                        this.$tagName = descriptor.tagName;
                    }
                    if (!this.$namespace) {
                        this.$namespace = descriptor.namespaceURI;
                    }
                }
            },
            _initializeAttributes: function (attributes) {
                this.callBase();

                if (attributes.tagName) {
                    this.$tagName = attributes.tagName;
                    delete(attributes.tagName);
                }
            },
            addChild: function (child) {
                this.callBase();
                if (child instanceof DomElement || child.render) {
                    this.$childViews.push(child);
                    if (this.isRendered()) {
                        this._renderChild(child);
                    }
                } else if (child instanceof Content) {
                    this.$contentChildren.push(child);
                }
            },

            getPlaceHolder: function (name) {

                for (var i = 0; i < this.$children.length; i++) {
                    if (this.$children[i].$.name === name) {
                        return this.$children[i];
                    }
                }
                var placeholder;
                for (i = 0; i < this.$children.length; i++) {
                    if (this.$children[i].getPlaceHolder) {
                        placeholder = this.$children[i].getPlaceHolder(name);
                        if (placeholder) {
                            return placeholder;
                        }
                    }

                }
                return null;
            },

            getContentPlaceHolders: function () {

                var ret = [];

                var child;
                for (var i = 0; i < this.$children.length; i++) {
                    child = this.$children[i];

                    if (child.className === "js.ui.ContentPlaceHolder") {
                        ret.push(child);
                    } else if (child instanceof DomElement) {
                        ret = ret.concat(child.getContentPlaceHolders());
                    }
                }

                return ret;

            },

            findContent: function (name) {

                var child,
                    content;

                for (var i = 0; i < this.$children.length; i++) {
                    child = this.$children[i];
                    if (child instanceof Content && child.$.name === name) {
                        return child;
                    }
                }

                for (i = 0; i < this.$children.length; i++) {
                    child = this.$children[i];
                    if (child.findContent) {
                        content = child.findContent(name);
                        if (content) {
                            return content;
                        }
                    }

                }

                return null;
            },

            render: function () {

                if (!this.$initialized) {
                    this._initialize(this.$creationPolicy);
                }
                // check if it is already rendered
                if (this.isRendered()) {
                    return this.$el;
                }

                this.$renderedChildren = [];

                this.$el = this.$systemManager.$document.createElement(this.$tagName);
                this.$el.owner = this;

                // TODO: read layout and create renderMAP
                /**
                 * <js:Template name="layout"><placeholder cid="icon"/><placeholder cid="label"/></js:Template>
                 */

                this._renderChildren(this.$childViews);
                this._renderContentChildren(this.$contentChildren);
                this._renderAttributes(this.$);
                this._bindDomEvents(this.$el);

                return this.$el;
            },
            _bindDomEvents: function (el) {
                var self = this, domEvent;

                function bindDomEvent(eventName, scope, fncName) {
                    self.bind(eventName, scope[fncName], scope);
                    domEvent = eventName.substr(2);
                    self.addEventListener(domEvent, function (e) {
                        self.trigger(eventName, e, self);
                    });
                }

                var eventDef;
                for (var i = 0; i < this.$eventDefinitions.length; i++) {
                    eventDef = this.$eventDefinitions[i];
                    if (!this._isComponentEvent(eventDef.name.substr(2))) {
                        bindDomEvent(eventDef.name, eventDef.scope, eventDef.fncName);
                    }

                }
            },
            _renderChildren: function (children) {
                // for all children
                var child;
                for (var i = 0; i < children.length; i++) {
                    child = children[i];
                    this._renderChild(child);
                }
            },
            _renderContentChildren: function (children) {
                var child;
                for (var i = 0; i < children.length; i++) {
                    child = children[i];
                    var ref = child.get('ref');
                    var placeHolder = this.getPlaceHolder(ref);
                    if (placeHolder) {
                        placeHolder.set({content: child});
                    }
                }
            },
            _renderChild: function (child) {
                if (_.isFunction(child.render)) {
                    var el = child.render();
                    this.$renderedChildren.push(child);
                    if (el) {
                        this.$el.appendChild(el);
                    }
                }
            },
            _removeRenderedChild: function (child) {
                if (this.isRendered()) {
                    var rc;
                    for (var i = this.$renderedChildren.length - 1; i >= 0; i--) {
                        rc = this.$renderedChildren[i];
                        if (child === rc) {
                            this.$el.removeChild(rc.$el);
                            this.$renderedChildren.splice(i, 1);
                            return;
                        }
                    }
                }
            },
            _clearRenderedChildren: function () {
                if (this.isRendered()) {
                    var rc;
                    for (var i = this.$renderedChildren.length - 1; i >= 0; i--) {
                        rc = this.$renderedChildren[i];
                        this.$el.removeChild(rc.$el);
                    }
                }
                this.$renderedChildren = [];
            },
            _getIndexOfPlaceHolder: function (placeHolder) {
                if (this.$layoutTpl) {
                    var child;
                    for (var i = 0; i < this.$layoutTpl.$children.length; i++) {
                        child = this.$layoutTpl.$children[i];
                        if (placeHolderId == child.$cid) {
                            return i;
                        }
                    }
                }
                return -1;
            },
            isRendered: function () {
                return typeof (this.$el) !== "undefined";
            },
            _renderAttributes: function (attributes) {
                var attr;
                for (var key in attributes) {
                    if (attributes.hasOwnProperty(key) && key.indexOf("$") !== 0 && key.indexOf("data") !== 0) {
                        attr = attributes[key];
                        this._renderAttribute(key, attr);
                    }
                }
            },
            _renderAttribute: function (key, attr) {
                var method = this.$renderMap[key];
                var prev = this.$previousAttributes[key];

                if (_.isUndefined(method)) {
                    // generic call of render functions
                    var k = key[0].toUpperCase() + key.substr(1);
                    var methodName = "_render" + k;
                    method = this[methodName];

                    if (!_.isFunction(method)) {
                        method = false;
                    }

                    this.$renderMap[key] = method;
                }
                if (method !== false) {
                    method.call(this, attr, prev);
                } else if (this.$behavesAsDomElement) {
                    this.$el.setAttribute(key, attr);
                }
            },

            _renderVisible: function (visible) {
                if (visible === true) {
                    this.removeClass('hidden');
                } else if (visible === false) {
                    this.addClass('hidden');
                }
            },
            _renderHidden: function (hidden) {
                if (typeof(hidden) !== "undefined") {
                    this.set({visible: !hidden});
                }
            },
            _renderSelected: function (selected) {
                if (selected === true) {
                    this.addClass('active');
                } else if (selected === false) {
                    this.removeClass('active');
                }
            },
            _renderSelectable: function (selectable) {
                if (selectable === true) {
                    var self = this;
                    this.addEventListener('click', function (e) {
                        // e.preventDefault();
                        self.set({selected: !self.$.selected});
                    });
                } else {
                    this.set({selected: false});
                }
            },
            _renderWidth: function (width) {
                if (width) {
                    if (typeof(width) !== "string") {
                        width += "px";
                    }
                    this.$el.style.width = width;
                }
            },
            _renderHeight: function (height) {
                if (height) {
                    if (typeof(height) !== "string") {
                        height += "px";
                    }
                    this.$el.style.height = height;
                }
            },
            _commitChangedAttributes: function (attributes) {
                if (this.isRendered()) {
                    this._renderAttributes(attributes);
                }
            },
            html: function () {
                if (!this.isRendered()) {
                    this.render();
                }
                return this.$el.innerHTML;

            }.on('change'),
            dom: function (element) {
                return new DomManipulation(element || this);
            }

        };

        var DomManipulationFunctions = {
            hasClass: function (value) {
                // var classes = this.$el.className.split(" "+value+" ");

            },
            addClass: function (value) {
                var classNames = value.split(rspace);

                if (!this.$el.className && classNames.length === 1) {
                    this.$el.className = value;
                } else {
                    var setClasses = this.$el.className.split(rspace);

                    for (var i = 0; i < classNames.length; i++) {
                        if (setClasses.indexOf(classNames[i]) == -1) {
                            setClasses.push(classNames[i]);
                        }
                    }

                    this.$el.className = setClasses.join(" ");

                }
            },
            removeClass: function (value) {
                if (this.$el.className.length === 0) {
                    return;
                }
                var removeClasses = value.split(rspace);

                var classes = this.$el.className.split(rspace);

                for (var i = 0; i < removeClasses.length; i++) {
                    var index = classes.indexOf(removeClasses[i]);
                    if (index != -1) {
                        classes.splice(index, 1);
                    }
                }

                if (classes.length === 0) {
                    this.$el.removeAttribute('class');
                } else {
                    this.$el.className = classes.join(" ");
                }
            },
            addEventListener: function (type, eventHandle) {
                if (this.$el.addEventListener) {
                    this.$el.addEventListener(type, eventHandle, false);

                } else if (this.$el.attachEvent) {
                    this.$el.attachEvent("on" + type, eventHandle);
                }
            },
            removeEvent: function (type, handle) {
                if (this.$el.removeEventListener) {
                    this.$el.removeEventListener(type, handle, false);
                } else if (this.$el.detachEvent) {
                    this.$el.detachEvent("on" + type, handle);
                }

            }
        };

        var DomManipulation = inherit.Base.inherit(_.extend({
            ctor: function (elm) {
                this.$el = elm;
            }
        }, DomManipulationFunctions));
        var DomElement = Component.inherit("js.html.DomElement",
            _.extend(DomElementFunctions, DomManipulationFunctions));
        return DomElement;
    }
);<commit_msg>fixed domelement getContentPLaceHolders<commit_after>define(["js/core/Component", "js/core/Content", "js/core/Binding", "inherit", "underscore"], function (Component, Content, Binding, inherit, _) {

        var rspace = /\s+/;
        var domEvents = ['click', 'dblclick', 'keyup', 'keydown' , 'change'];

        var DomElementFunctions = {
            defaults: {
                selected: undefined,
                selectable: undefined
            },
            $behavesAsDomElement: true,
            ctor: function (attributes, descriptor, systemManager, parentScope, rootScope) {
                this.$renderMap = {};
                this.$childViews = [];
                this.$contentChildren = [];
                this.callBase();

                if (descriptor) {
                    if (!this.$tagName) {
                        this.$tagName = descriptor.tagName;
                    }
                    if (!this.$namespace) {
                        this.$namespace = descriptor.namespaceURI;
                    }
                }
            },
            _initializeAttributes: function (attributes) {
                this.callBase();

                if (attributes.tagName) {
                    this.$tagName = attributes.tagName;
                    delete(attributes.tagName);
                }
            },
            addChild: function (child) {
                this.callBase();
                if (child instanceof DomElement || child.render) {
                    this.$childViews.push(child);
                    if (this.isRendered()) {
                        this._renderChild(child);
                    }
                } else if (child instanceof Content) {
                    this.$contentChildren.push(child);
                }
            },

            getPlaceHolder: function (name) {

                for (var i = 0; i < this.$children.length; i++) {
                    if (this.$children[i].$.name === name) {
                        return this.$children[i];
                    }
                }
                var placeholder;
                for (i = 0; i < this.$children.length; i++) {
                    if (this.$children[i].getPlaceHolder) {
                        placeholder = this.$children[i].getPlaceHolder(name);
                        if (placeholder) {
                            return placeholder;
                        }
                    }

                }
                return null;
            },

            getContentPlaceHolders: function () {

                var ret = [];

                var child;
                for (var i = 0; i < this.$children.length; i++) {
                    child = this.$children[i];

                    if (child instanceof require("js/ui/ContentPlaceHolder")) {
                        ret.push(child);
                    } else if (child instanceof DomElement) {
                        ret = ret.concat(child.getContentPlaceHolders());
                    }
                }

                return ret;

            },

            findContent: function (name) {

                var child,
                    content;

                for (var i = 0; i < this.$children.length; i++) {
                    child = this.$children[i];
                    if (child instanceof Content && child.$.name === name) {
                        return child;
                    }
                }

                for (i = 0; i < this.$children.length; i++) {
                    child = this.$children[i];
                    if (child.findContent) {
                        content = child.findContent(name);
                        if (content) {
                            return content;
                        }
                    }

                }

                return null;
            },

            render: function () {

                if (!this.$initialized) {
                    this._initialize(this.$creationPolicy);
                }
                // check if it is already rendered
                if (this.isRendered()) {
                    return this.$el;
                }

                this.$renderedChildren = [];

                this.$el = this.$systemManager.$document.createElement(this.$tagName);
                this.$el.owner = this;

                // TODO: read layout and create renderMAP
                /**
                 * <js:Template name="layout"><placeholder cid="icon"/><placeholder cid="label"/></js:Template>
                 */

                this._renderChildren(this.$childViews);
                this._renderContentChildren(this.$contentChildren);
                this._renderAttributes(this.$);
                this._bindDomEvents(this.$el);

                return this.$el;
            },
            _bindDomEvents: function (el) {
                var self = this, domEvent;

                function bindDomEvent(eventName, scope, fncName) {
                    self.bind(eventName, scope[fncName], scope);
                    domEvent = eventName.substr(2);
                    self.addEventListener(domEvent, function (e) {
                        self.trigger(eventName, e, self);
                    });
                }

                var eventDef;
                for (var i = 0; i < this.$eventDefinitions.length; i++) {
                    eventDef = this.$eventDefinitions[i];
                    if (!this._isComponentEvent(eventDef.name.substr(2))) {
                        bindDomEvent(eventDef.name, eventDef.scope, eventDef.fncName);
                    }

                }
            },
            _renderChildren: function (children) {
                // for all children
                var child;
                for (var i = 0; i < children.length; i++) {
                    child = children[i];
                    this._renderChild(child);
                }
            },
            _renderContentChildren: function (children) {
                var child;
                for (var i = 0; i < children.length; i++) {
                    child = children[i];
                    var ref = child.get('ref');
                    var placeHolder = this.getPlaceHolder(ref);
                    if (placeHolder) {
                        placeHolder.set({content: child});
                    }
                }
            },
            _renderChild: function (child) {
                if (_.isFunction(child.render)) {
                    var el = child.render();
                    this.$renderedChildren.push(child);
                    if (el) {
                        this.$el.appendChild(el);
                    }
                }
            },
            _removeRenderedChild: function (child) {
                if (this.isRendered()) {
                    var rc;
                    for (var i = this.$renderedChildren.length - 1; i >= 0; i--) {
                        rc = this.$renderedChildren[i];
                        if (child === rc) {
                            this.$el.removeChild(rc.$el);
                            this.$renderedChildren.splice(i, 1);
                            return;
                        }
                    }
                }
            },
            _clearRenderedChildren: function () {
                if (this.isRendered()) {
                    var rc;
                    for (var i = this.$renderedChildren.length - 1; i >= 0; i--) {
                        rc = this.$renderedChildren[i];
                        this.$el.removeChild(rc.$el);
                    }
                }
                this.$renderedChildren = [];
            },
            _getIndexOfPlaceHolder: function (placeHolder) {
                if (this.$layoutTpl) {
                    var child;
                    for (var i = 0; i < this.$layoutTpl.$children.length; i++) {
                        child = this.$layoutTpl.$children[i];
                        if (placeHolderId == child.$cid) {
                            return i;
                        }
                    }
                }
                return -1;
            },
            isRendered: function () {
                return typeof (this.$el) !== "undefined";
            },
            _renderAttributes: function (attributes) {
                var attr;
                for (var key in attributes) {
                    if (attributes.hasOwnProperty(key) && key.indexOf("$") !== 0 && key.indexOf("data") !== 0) {
                        attr = attributes[key];
                        this._renderAttribute(key, attr);
                    }
                }
            },
            _renderAttribute: function (key, attr) {
                var method = this.$renderMap[key];
                var prev = this.$previousAttributes[key];

                if (_.isUndefined(method)) {
                    // generic call of render functions
                    var k = key[0].toUpperCase() + key.substr(1);
                    var methodName = "_render" + k;
                    method = this[methodName];

                    if (!_.isFunction(method)) {
                        method = false;
                    }

                    this.$renderMap[key] = method;
                }
                if (method !== false) {
                    method.call(this, attr, prev);
                } else if (this.$behavesAsDomElement) {
                    this.$el.setAttribute(key, attr);
                }
            },

            _renderVisible: function (visible) {
                if (visible === true) {
                    this.removeClass('hidden');
                } else if (visible === false) {
                    this.addClass('hidden');
                }
            },
            _renderHidden: function (hidden) {
                if (typeof(hidden) !== "undefined") {
                    this.set({visible: !hidden});
                }
            },
            _renderSelected: function (selected) {
                if (selected === true) {
                    this.addClass('active');
                } else if (selected === false) {
                    this.removeClass('active');
                }
            },
            _renderSelectable: function (selectable) {
                if (selectable === true) {
                    var self = this;
                    this.addEventListener('click', function (e) {
                        // e.preventDefault();
                        self.set({selected: !self.$.selected});
                    });
                } else {
                    this.set({selected: false});
                }
            },
            _renderWidth: function (width) {
                if (width) {
                    if (typeof(width) !== "string") {
                        width += "px";
                    }
                    this.$el.style.width = width;
                }
            },
            _renderHeight: function (height) {
                if (height) {
                    if (typeof(height) !== "string") {
                        height += "px";
                    }
                    this.$el.style.height = height;
                }
            },
            _commitChangedAttributes: function (attributes) {
                if (this.isRendered()) {
                    this._renderAttributes(attributes);
                }
            },
            html: function () {
                if (!this.isRendered()) {
                    this.render();
                }
                return this.$el.innerHTML;

            }.on('change'),
            dom: function (element) {
                return new DomManipulation(element || this);
            }

        };

        var DomManipulationFunctions = {
            hasClass: function (value) {
                // var classes = this.$el.className.split(" "+value+" ");

            },
            addClass: function (value) {
                var classNames = value.split(rspace);

                if (!this.$el.className && classNames.length === 1) {
                    this.$el.className = value;
                } else {
                    var setClasses = this.$el.className.split(rspace);

                    for (var i = 0; i < classNames.length; i++) {
                        if (setClasses.indexOf(classNames[i]) == -1) {
                            setClasses.push(classNames[i]);
                        }
                    }

                    this.$el.className = setClasses.join(" ");

                }
            },
            removeClass: function (value) {
                if (this.$el.className.length === 0) {
                    return;
                }
                var removeClasses = value.split(rspace);

                var classes = this.$el.className.split(rspace);

                for (var i = 0; i < removeClasses.length; i++) {
                    var index = classes.indexOf(removeClasses[i]);
                    if (index != -1) {
                        classes.splice(index, 1);
                    }
                }

                if (classes.length === 0) {
                    this.$el.removeAttribute('class');
                } else {
                    this.$el.className = classes.join(" ");
                }
            },
            addEventListener: function (type, eventHandle) {
                if (this.$el.addEventListener) {
                    this.$el.addEventListener(type, eventHandle, false);

                } else if (this.$el.attachEvent) {
                    this.$el.attachEvent("on" + type, eventHandle);
                }
            },
            removeEvent: function (type, handle) {
                if (this.$el.removeEventListener) {
                    this.$el.removeEventListener(type, handle, false);
                } else if (this.$el.detachEvent) {
                    this.$el.detachEvent("on" + type, handle);
                }

            }
        };

        var DomManipulation = inherit.Base.inherit(_.extend({
            ctor: function (elm) {
                this.$el = elm;
            }
        }, DomManipulationFunctions));
        var DomElement = Component.inherit("js.html.DomElement",
            _.extend(DomElementFunctions, DomManipulationFunctions));
        return DomElement;
    }
);<|endoftext|>


<commit_before>define(["require","js/core/Component", "js/core/Content", "js/core/Binding", "inherit", "underscore"],
    function (require,Component, Content, Binding, inherit, _) {

        var rspace = /\s+/;
        var domEvents = ['click', 'dblclick', 'keyup', 'keydown' , 'change'];

        var ContentPlaceHolder;

        var DomElementFunctions = {
            defaults: {
                selected: undefined,
                selectable: undefined
            },
            $behavesAsDomElement: true,
            ctor: function (attributes, descriptor, systemManager, parentScope, rootScope) {
                ContentPlaceHolder = require("js/ui/ContentPlaceHolder");
                this.$renderMap = {};
                this.$childViews = [];
                this.$contentChildren = [];
                this.callBase();

                if (descriptor) {
                    if (!this.$tagName) {
                        this.$tagName = descriptor.tagName;
                    }
                    if (!this.$namespace) {
                        this.$namespace = descriptor.namespaceURI;
                    }
                }
            },
            _initializeAttributes: function (attributes) {
                this.callBase();

                if (attributes.tagName) {
                    this.$tagName = attributes.tagName;
                    delete(attributes.tagName);
                }
            },
            addChild: function (child) {
                this.callBase();
                if (child instanceof DomElement || child.render) {
                    this.$childViews.push(child);
                    if (this.isRendered()) {
                        this._renderChild(child);
                    }
                } else if (child instanceof Content) {
                    this.$contentChildren.push(child);
                }
            },

            getPlaceHolder: function (name) {

                for (var i = 0; i < this.$children.length; i++) {
                    if (this.$children[i].$.name === name) {
                        return this.$children[i];
                    }
                }
                var placeholder;
                for (i = 0; i < this.$children.length; i++) {
                    if (this.$children[i].getPlaceHolder) {
                        placeholder = this.$children[i].getPlaceHolder(name);
                        if (placeholder) {
                            return placeholder;
                        }
                    }

                }
                return null;
            },

            getContentPlaceHolders: function () {

                var ret = [];

                var child;
                for (var i = 0; i < this.$children.length; i++) {
                    child = this.$children[i];

                    if (child instanceof ContentPlaceHolder) {
                        ret.push(child);
                    } else if (child instanceof DomElement) {
                        ret = ret.concat(child.getContentPlaceHolders());
                    }
                }

                return ret;

            },

            findContent: function (name) {

                var child,
                    content;

                for (var i = 0; i < this.$children.length; i++) {
                    child = this.$children[i];
                    if (child instanceof Content && child.$.name === name) {
                        return child;
                    }
                }

                for (i = 0; i < this.$children.length; i++) {
                    child = this.$children[i];
                    if (child.findContent) {
                        content = child.findContent(name);
                        if (content) {
                            return content;
                        }
                    }

                }

                return null;
            },

            render: function () {

                if (!this.$initialized) {
                    this._initialize(this.$creationPolicy);
                }
                // check if it is already rendered
                if (this.isRendered()) {
                    return this.$el;
                }

                this.$renderedChildren = [];

                this.$el = this.$systemManager.$document.createElement(this.$tagName);
                this.$el.owner = this;

                // TODO: read layout and create renderMAP
                /**
                 * <js:Template name="layout"><placeholder cid="icon"/><placeholder cid="label"/></js:Template>
                 */

                this._renderChildren(this.$childViews);
                this._renderContentChildren(this.$contentChildren);
                this._renderAttributes(this.$);
                this._bindDomEvents(this.$el);

                return this.$el;
            },
            _bindDomEvents: function (el) {
                var self = this, domEvent;

                function bindDomEvent(eventName, scope, fncName) {
                    self.bind(eventName, scope[fncName], scope);
                    domEvent = eventName.substr(2);
                    self.addEventListener(domEvent, function (e) {
                        self.trigger(eventName, e, self);
                    });
                }

                var eventDef;
                for (var i = 0; i < this.$eventDefinitions.length; i++) {
                    eventDef = this.$eventDefinitions[i];
                    if (!this._isComponentEvent(eventDef.name.substr(2))) {
                        bindDomEvent(eventDef.name, eventDef.scope, eventDef.fncName);
                    }

                }
            },
            _renderChildren: function (children) {
                // for all children
                var child;
                for (var i = 0; i < children.length; i++) {
                    child = children[i];
                    this._renderChild(child);
                }
            },
            _renderContentChildren: function (children) {
                var child;
                for (var i = 0; i < children.length; i++) {
                    child = children[i];
                    var ref = child.get('ref');
                    var placeHolder = this.getPlaceHolder(ref);
                    if (placeHolder) {
                        placeHolder.set({content: child});
                    }
                }
            },
            _renderChild: function (child) {
                if (_.isFunction(child.render)) {
                    var el = child.render();
                    this.$renderedChildren.push(child);
                    if (el) {
                        this.$el.appendChild(el);
                    }
                }
            },
            _removeRenderedChild: function (child) {
                if (this.isRendered()) {
                    var rc;
                    for (var i = this.$renderedChildren.length - 1; i >= 0; i--) {
                        rc = this.$renderedChildren[i];
                        if (child === rc) {
                            this.$el.removeChild(rc.$el);
                            this.$renderedChildren.splice(i, 1);
                            return;
                        }
                    }
                }
            },
            _clearRenderedChildren: function () {
                if (this.isRendered()) {
                    var rc;
                    for (var i = this.$renderedChildren.length - 1; i >= 0; i--) {
                        rc = this.$renderedChildren[i];
                        this.$el.removeChild(rc.$el);
                    }
                }
                this.$renderedChildren = [];
            },
            _getIndexOfPlaceHolder: function (placeHolder) {
                if (this.$layoutTpl) {
                    var child;
                    for (var i = 0; i < this.$layoutTpl.$children.length; i++) {
                        child = this.$layoutTpl.$children[i];
                        if (placeHolderId == child.$cid) {
                            return i;
                        }
                    }
                }
                return -1;
            },
            isRendered: function () {
                return typeof (this.$el) !== "undefined";
            },
            _renderAttributes: function (attributes) {
                var attr;
                for (var key in attributes) {
                    if (attributes.hasOwnProperty(key) && key.indexOf("$") !== 0 && key.indexOf("data") !== 0) {
                        attr = attributes[key];
                        this._renderAttribute(key, attr);
                    }
                }
            },
            _renderAttribute: function (key, attr) {
                var method = this.$renderMap[key];
                var prev = this.$previousAttributes[key];

                if (_.isUndefined(method)) {
                    // generic call of render functions
                    var k = key[0].toUpperCase() + key.substr(1);
                    var methodName = "_render" + k;
                    method = this[methodName];

                    if (!_.isFunction(method)) {
                        method = false;
                    }

                    this.$renderMap[key] = method;
                }
                if (method !== false) {
                    method.call(this, attr, prev);
                } else if (this.$behavesAsDomElement) {
                    this.$el.setAttribute(key, attr);
                }
            },

            _renderVisible: function (visible) {
                if (visible === true) {
                    this.removeClass('hidden');
                } else if (visible === false) {
                    this.addClass('hidden');
                }
            },
            _renderHidden: function (hidden) {
                if (typeof(hidden) !== "undefined") {
                    this.set({visible: !hidden});
                }
            },
            _renderSelected: function (selected) {
                if (selected === true) {
                    this.addClass('active');
                } else if (selected === false) {
                    this.removeClass('active');
                }
            },
            _renderSelectable: function (selectable) {
                if (selectable === true) {
                    var self = this;
                    this.addEventListener('click', function (e) {
                        // e.preventDefault();
                        self.set({selected: !self.$.selected});
                    });
                } else {
                    this.set({selected: false});
                }
            },
            _renderWidth: function (width) {
                if (width) {
                    if (typeof(width) !== "string") {
                        width += "px";
                    }
                    this.$el.style.width = width;
                }
            },
            _renderHeight: function (height) {
                if (height) {
                    if (typeof(height) !== "string") {
                        height += "px";
                    }
                    this.$el.style.height = height;
                }
            },
            _commitChangedAttributes: function (attributes) {
                if (this.isRendered()) {
                    this._renderAttributes(attributes);
                }
            },
            html: function () {
                if (!this.isRendered()) {
                    this.render();
                }
                return this.$el.innerHTML;

            }.on('change'),
            dom: function (element) {
                return new DomManipulation(element || this);
            }

        };

        var DomManipulationFunctions = {
            hasClass: function (value) {
                // var classes = this.$el.className.split(" "+value+" ");

            },
            addClass: function (value) {
                var classNames = value.split(rspace);

                if (!this.$el.className && classNames.length === 1) {
                    this.$el.className = value;
                } else {
                    var setClasses = this.$el.className.split(rspace);

                    for (var i = 0; i < classNames.length; i++) {
                        if (setClasses.indexOf(classNames[i]) == -1) {
                            setClasses.push(classNames[i]);
                        }
                    }

                    this.$el.className = setClasses.join(" ");

                }
            },
            removeClass: function (value) {
                if (this.$el.className.length === 0) {
                    return;
                }
                var removeClasses = value.split(rspace);

                var classes = this.$el.className.split(rspace);

                for (var i = 0; i < removeClasses.length; i++) {
                    var index = classes.indexOf(removeClasses[i]);
                    if (index != -1) {
                        classes.splice(index, 1);
                    }
                }

                if (classes.length === 0) {
                    this.$el.removeAttribute('class');
                } else {
                    this.$el.className = classes.join(" ");
                }
            },
            addEventListener: function (type, eventHandle) {
                if (this.$el.addEventListener) {
                    this.$el.addEventListener(type, eventHandle, false);

                } else if (this.$el.attachEvent) {
                    this.$el.attachEvent("on" + type, eventHandle);
                }
            },
            removeEvent: function (type, handle) {
                if (this.$el.removeEventListener) {
                    this.$el.removeEventListener(type, handle, false);
                } else if (this.$el.detachEvent) {
                    this.$el.detachEvent("on" + type, handle);
                }

            }
        };

        var DomManipulation = inherit.Base.inherit(_.extend({
            ctor: function (elm) {
                this.$el = elm;
            }
        }, DomManipulationFunctions));
        var DomElement = Component.inherit("js.html.DomElement",
            _.extend(DomElementFunctions, DomManipulationFunctions));
        return DomElement;
    }
);<commit_msg>optimized late requireing of ContentPlaceHolder<commit_after>define(["require","js/core/Component", "js/core/Content", "js/core/Binding", "inherit", "underscore"],
    function (require,Component, Content, Binding, inherit, _) {

        var rspace = /\s+/;
        var domEvents = ['click', 'dblclick', 'keyup', 'keydown' , 'change'];

        var ContentPlaceHolder;

        var DomElementFunctions = {
            defaults: {
                selected: undefined,
                selectable: undefined
            },
            $behavesAsDomElement: true,
            ctor: function (attributes, descriptor, systemManager, parentScope, rootScope) {
                ContentPlaceHolder = ContentPlaceHolder || require("js/ui/ContentPlaceHolder");
                this.$renderMap = {};
                this.$childViews = [];
                this.$contentChildren = [];
                this.callBase();

                if (descriptor) {
                    if (!this.$tagName) {
                        this.$tagName = descriptor.tagName;
                    }
                    if (!this.$namespace) {
                        this.$namespace = descriptor.namespaceURI;
                    }
                }
            },
            _initializeAttributes: function (attributes) {
                this.callBase();

                if (attributes.tagName) {
                    this.$tagName = attributes.tagName;
                    delete(attributes.tagName);
                }
            },
            addChild: function (child) {
                this.callBase();
                if (child instanceof DomElement || child.render) {
                    this.$childViews.push(child);
                    if (this.isRendered()) {
                        this._renderChild(child);
                    }
                } else if (child instanceof Content) {
                    this.$contentChildren.push(child);
                }
            },

            getPlaceHolder: function (name) {

                for (var i = 0; i < this.$children.length; i++) {
                    if (this.$children[i].$.name === name) {
                        return this.$children[i];
                    }
                }
                var placeholder;
                for (i = 0; i < this.$children.length; i++) {
                    if (this.$children[i].getPlaceHolder) {
                        placeholder = this.$children[i].getPlaceHolder(name);
                        if (placeholder) {
                            return placeholder;
                        }
                    }

                }
                return null;
            },

            getContentPlaceHolders: function () {

                var ret = [];

                var child;
                for (var i = 0; i < this.$children.length; i++) {
                    child = this.$children[i];

                    if (child instanceof ContentPlaceHolder) {
                        ret.push(child);
                    } else if (child instanceof DomElement) {
                        ret = ret.concat(child.getContentPlaceHolders());
                    }
                }

                return ret;

            },

            findContent: function (name) {

                var child,
                    content;

                for (var i = 0; i < this.$children.length; i++) {
                    child = this.$children[i];
                    if (child instanceof Content && child.$.name === name) {
                        return child;
                    }
                }

                for (i = 0; i < this.$children.length; i++) {
                    child = this.$children[i];
                    if (child.findContent) {
                        content = child.findContent(name);
                        if (content) {
                            return content;
                        }
                    }

                }

                return null;
            },

            render: function () {

                if (!this.$initialized) {
                    this._initialize(this.$creationPolicy);
                }
                // check if it is already rendered
                if (this.isRendered()) {
                    return this.$el;
                }

                this.$renderedChildren = [];

                this.$el = this.$systemManager.$document.createElement(this.$tagName);
                this.$el.owner = this;

                // TODO: read layout and create renderMAP
                /**
                 * <js:Template name="layout"><placeholder cid="icon"/><placeholder cid="label"/></js:Template>
                 */

                this._renderChildren(this.$childViews);
                this._renderContentChildren(this.$contentChildren);
                this._renderAttributes(this.$);
                this._bindDomEvents(this.$el);

                return this.$el;
            },
            _bindDomEvents: function (el) {
                var self = this, domEvent;

                function bindDomEvent(eventName, scope, fncName) {
                    self.bind(eventName, scope[fncName], scope);
                    domEvent = eventName.substr(2);
                    self.addEventListener(domEvent, function (e) {
                        self.trigger(eventName, e, self);
                    });
                }

                var eventDef;
                for (var i = 0; i < this.$eventDefinitions.length; i++) {
                    eventDef = this.$eventDefinitions[i];
                    if (!this._isComponentEvent(eventDef.name.substr(2))) {
                        bindDomEvent(eventDef.name, eventDef.scope, eventDef.fncName);
                    }

                }
            },
            _renderChildren: function (children) {
                // for all children
                var child;
                for (var i = 0; i < children.length; i++) {
                    child = children[i];
                    this._renderChild(child);
                }
            },
            _renderContentChildren: function (children) {
                var child;
                for (var i = 0; i < children.length; i++) {
                    child = children[i];
                    var ref = child.get('ref');
                    var placeHolder = this.getPlaceHolder(ref);
                    if (placeHolder) {
                        placeHolder.set({content: child});
                    }
                }
            },
            _renderChild: function (child) {
                if (_.isFunction(child.render)) {
                    var el = child.render();
                    this.$renderedChildren.push(child);
                    if (el) {
                        this.$el.appendChild(el);
                    }
                }
            },
            _removeRenderedChild: function (child) {
                if (this.isRendered()) {
                    var rc;
                    for (var i = this.$renderedChildren.length - 1; i >= 0; i--) {
                        rc = this.$renderedChildren[i];
                        if (child === rc) {
                            this.$el.removeChild(rc.$el);
                            this.$renderedChildren.splice(i, 1);
                            return;
                        }
                    }
                }
            },
            _clearRenderedChildren: function () {
                if (this.isRendered()) {
                    var rc;
                    for (var i = this.$renderedChildren.length - 1; i >= 0; i--) {
                        rc = this.$renderedChildren[i];
                        this.$el.removeChild(rc.$el);
                    }
                }
                this.$renderedChildren = [];
            },
            _getIndexOfPlaceHolder: function (placeHolder) {
                if (this.$layoutTpl) {
                    var child;
                    for (var i = 0; i < this.$layoutTpl.$children.length; i++) {
                        child = this.$layoutTpl.$children[i];
                        if (placeHolderId == child.$cid) {
                            return i;
                        }
                    }
                }
                return -1;
            },
            isRendered: function () {
                return typeof (this.$el) !== "undefined";
            },
            _renderAttributes: function (attributes) {
                var attr;
                for (var key in attributes) {
                    if (attributes.hasOwnProperty(key) && key.indexOf("$") !== 0 && key.indexOf("data") !== 0) {
                        attr = attributes[key];
                        this._renderAttribute(key, attr);
                    }
                }
            },
            _renderAttribute: function (key, attr) {
                var method = this.$renderMap[key];
                var prev = this.$previousAttributes[key];

                if (_.isUndefined(method)) {
                    // generic call of render functions
                    var k = key[0].toUpperCase() + key.substr(1);
                    var methodName = "_render" + k;
                    method = this[methodName];

                    if (!_.isFunction(method)) {
                        method = false;
                    }

                    this.$renderMap[key] = method;
                }
                if (method !== false) {
                    method.call(this, attr, prev);
                } else if (this.$behavesAsDomElement) {
                    this.$el.setAttribute(key, attr);
                }
            },

            _renderVisible: function (visible) {
                if (visible === true) {
                    this.removeClass('hidden');
                } else if (visible === false) {
                    this.addClass('hidden');
                }
            },
            _renderHidden: function (hidden) {
                if (typeof(hidden) !== "undefined") {
                    this.set({visible: !hidden});
                }
            },
            _renderSelected: function (selected) {
                if (selected === true) {
                    this.addClass('active');
                } else if (selected === false) {
                    this.removeClass('active');
                }
            },
            _renderSelectable: function (selectable) {
                if (selectable === true) {
                    var self = this;
                    this.addEventListener('click', function (e) {
                        // e.preventDefault();
                        self.set({selected: !self.$.selected});
                    });
                } else {
                    this.set({selected: false});
                }
            },
            _renderWidth: function (width) {
                if (width) {
                    if (typeof(width) !== "string") {
                        width += "px";
                    }
                    this.$el.style.width = width;
                }
            },
            _renderHeight: function (height) {
                if (height) {
                    if (typeof(height) !== "string") {
                        height += "px";
                    }
                    this.$el.style.height = height;
                }
            },
            _commitChangedAttributes: function (attributes) {
                if (this.isRendered()) {
                    this._renderAttributes(attributes);
                }
            },
            html: function () {
                if (!this.isRendered()) {
                    this.render();
                }
                return this.$el.innerHTML;

            }.on('change'),
            dom: function (element) {
                return new DomManipulation(element || this);
            }

        };

        var DomManipulationFunctions = {
            hasClass: function (value) {
                // var classes = this.$el.className.split(" "+value+" ");

            },
            addClass: function (value) {
                var classNames = value.split(rspace);

                if (!this.$el.className && classNames.length === 1) {
                    this.$el.className = value;
                } else {
                    var setClasses = this.$el.className.split(rspace);

                    for (var i = 0; i < classNames.length; i++) {
                        if (setClasses.indexOf(classNames[i]) == -1) {
                            setClasses.push(classNames[i]);
                        }
                    }

                    this.$el.className = setClasses.join(" ");

                }
            },
            removeClass: function (value) {
                if (this.$el.className.length === 0) {
                    return;
                }
                var removeClasses = value.split(rspace);

                var classes = this.$el.className.split(rspace);

                for (var i = 0; i < removeClasses.length; i++) {
                    var index = classes.indexOf(removeClasses[i]);
                    if (index != -1) {
                        classes.splice(index, 1);
                    }
                }

                if (classes.length === 0) {
                    this.$el.removeAttribute('class');
                } else {
                    this.$el.className = classes.join(" ");
                }
            },
            addEventListener: function (type, eventHandle) {
                if (this.$el.addEventListener) {
                    this.$el.addEventListener(type, eventHandle, false);

                } else if (this.$el.attachEvent) {
                    this.$el.attachEvent("on" + type, eventHandle);
                }
            },
            removeEvent: function (type, handle) {
                if (this.$el.removeEventListener) {
                    this.$el.removeEventListener(type, handle, false);
                } else if (this.$el.detachEvent) {
                    this.$el.detachEvent("on" + type, handle);
                }

            }
        };

        var DomManipulation = inherit.Base.inherit(_.extend({
            ctor: function (elm) {
                this.$el = elm;
            }
        }, DomManipulationFunctions));
        var DomElement = Component.inherit("js.html.DomElement",
            _.extend(DomElementFunctions, DomManipulationFunctions));
        return DomElement;
    }
);<|endoftext|>


<commit_before>iD.Entity = function(a, b, c) {
    if (!(this instanceof iD.Entity)) return new iD.Entity(a, b, c);

    _.extend(this, {tags: {}}, a, b, c);

    if (!this.id) {
        this.id = iD.util.id(this.type);
        this._updated = true;
    }
    delete this._extent;

    if (iD.debug) {
        Object.freeze(this);
        Object.freeze(this.tags);
    }
};

iD.Entity.prototype = {
    update: function(attrs) {
        return iD.Entity(this, attrs, {_updated: true});
    },

    created: function() {
        return this._updated && +this.id.slice(1) < 0;
    },

    modified: function() {
        return this._updated && +this.id.slice(1) > 0;
    }
};

iD.Node = function(attrs) {
    return iD.Entity(attrs || {}, {type: 'node'});
};

iD.Way = function(attrs) {
    return iD.Entity({nodes: []}, attrs || {}, {type: 'way'});
};

iD.Way.isOneWay = function(d) {
    return !!(d.tags.oneway && d.tags.oneway === 'yes');
};

iD.Way.isClosed = function(d) {
    return (!d.nodes.length) || d.nodes[d.nodes.length - 1].id === d.nodes[0].id;
};

iD.Way.isArea = function(d) {
    return iD.Way.isClosed(d) || (d.tags.area && d.tags.area === 'yes');
};

iD.Relation = function(attrs) {
    return iD.Entity({members: []}, attrs || {}, {type: 'relation'});
};
<commit_msg>Freeze nodes/members too<commit_after>iD.Entity = function(a, b, c) {
    if (!(this instanceof iD.Entity)) return new iD.Entity(a, b, c);

    _.extend(this, {tags: {}}, a, b, c);

    if (!this.id) {
        this.id = iD.util.id(this.type);
        this._updated = true;
    }
    delete this._extent;

    if (iD.debug) {
        Object.freeze(this);
        Object.freeze(this.tags);

        if (this.nodes) Object.freeze(this.nodes);
        if (this.members) Object.freeze(this.members);
    }
};

iD.Entity.prototype = {
    update: function(attrs) {
        return iD.Entity(this, attrs, {_updated: true});
    },

    created: function() {
        return this._updated && +this.id.slice(1) < 0;
    },

    modified: function() {
        return this._updated && +this.id.slice(1) > 0;
    }
};

iD.Node = function(attrs) {
    return iD.Entity(attrs || {}, {type: 'node'});
};

iD.Way = function(attrs) {
    return iD.Entity({nodes: []}, attrs || {}, {type: 'way'});
};

iD.Way.isOneWay = function(d) {
    return !!(d.tags.oneway && d.tags.oneway === 'yes');
};

iD.Way.isClosed = function(d) {
    return (!d.nodes.length) || d.nodes[d.nodes.length - 1].id === d.nodes[0].id;
};

iD.Way.isArea = function(d) {
    return iD.Way.isClosed(d) || (d.tags.area && d.tags.area === 'yes');
};

iD.Relation = function(attrs) {
    return iD.Entity({members: []}, attrs || {}, {type: 'relation'});
};
<|endoftext|>