From 945c6843d1f7105314629f8c63875abd152dc662 Mon Sep 17 00:00:00 2001 From: Oliver Merkel Date: Tue, 7 Oct 2014 12:25:22 +0200 Subject: [PATCH] Minor refactoring: Get rid of unnecessary expensive getElementById calls. Images don't need any id then. Closer to initial code from Douglas this way again. --- src/display.js | 1 - src/resolutionawareness.js | 11 +++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/display.js b/src/display.js index b87f06d..4acc249 100644 --- a/src/display.js +++ b/src/display.js @@ -267,7 +267,6 @@ _p4d_proto.write_board_html = function(){ img.src = P4WN_IMAGE_DIR + '/' + P4WN_IMAGE_NAMES[0]; img.width= P4WN_SQUARE_WIDTH; img.height= P4WN_SQUARE_HEIGHT; - img.id= 'field' + (((y-2) << 3) + x-1); } } }; diff --git a/src/resolutionawareness.js b/src/resolutionawareness.js index 6a0e692..ce5fd41 100644 --- a/src/resolutionawareness.js +++ b/src/resolutionawareness.js @@ -24,10 +24,13 @@ function displayResize(evt) { P4WN_SQUARE_WIDTH = tmp_square; P4WN_SQUARE_HEIGHT = tmp_square; game.render_elements(); - for (var i=0; i<64; ++i) { - var element = this.document.getElementById('field' + i) - element.height = tmp_square; - element.width = tmp_square; + var pieces = game.elements.pieces; + for (var y = 9; y > 1; y--){ + for(var x = 1; x < 9; x++){ + var i = y * 10 + x; + pieces[i].height = tmp_square; + pieces[i].width = tmp_square; + } } }