From 61693ac1926c8770f0b662ae5a6839a44afb2197 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 24 Mar 2014 16:56:15 +0000 Subject: [PATCH] Abstract record-element ID generation to new recordElementId function This is used by promoteRecords and onRecord Sanitised ID into a form that can be used in a jQuery selector. --- tools/htdocs/mkws.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 809fc18..b4a52b2 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -348,9 +348,8 @@ function widget($, team, type, node) { var html = []; for (var i = 0; i < data.hits.length; i++) { var hit = data.hits[i]; - html.push('
', - renderSummary(hit), - '
'); + var divId = team.recordElementId(hit.recid[0]); + html.push('
', renderSummary(hit), '
'); // ### At some point, we may be able to move the // m_currentRecordId and m_currentRecordData members // from the team object into this widget. @@ -543,12 +542,19 @@ function team($, teamName) { if (detRecordDiv) return; m_currentRecordData = data; // Can't use jQuery's $('#x') syntax to find this ID, because it contains spaces. - var recordDiv = document.getElementById('mkwsRecdiv_' + teamName + '_' + m_currentRecordData.recid); + var recordDiv = document.getElementById(recordElementId(m_currentRecordData.recid[0])); var html = renderDetails(m_currentRecordData); $(recordDiv).append(html); } + // Used by promoteRecords() and onRecord() + function recordElementId(s) { + return 'mkwsRec_' + m_teamName + '_' + s.replace(/[^a-z0-9]/ig, '_'); + } + that.recordElementId = recordElementId; + + that.targetFiltered = function(id) { for (var i = 0; i < m_filters.length; i++) { if (m_filters[i].id === id || -- 1.7.10.4