Fixing html injection in data fileds
This commit is contained in:
+53
-27
@@ -188,9 +188,7 @@ function show_part_info(partID) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(function() {
|
function perform_query() {
|
||||||
$.ajaxSetup({ cache: false });
|
|
||||||
$('.search-bar').on('keyup', function() {
|
|
||||||
var query = $('.search-bar').val();
|
var query = $('.search-bar').val();
|
||||||
var filter = 0;
|
var filter = 0;
|
||||||
if($('#type').is(':checked'))
|
if($('#type').is(':checked'))
|
||||||
@@ -202,45 +200,70 @@ $(document).ready(function() {
|
|||||||
if($('#notes').is(':checked'))
|
if($('#notes').is(':checked'))
|
||||||
filter += 32;
|
filter += 32;
|
||||||
$.getJSON('https://www.elab.kth.se/parts/query/' + filter + '/' + query, function(data) {
|
$.getJSON('https://www.elab.kth.se/parts/query/' + filter + '/' + query, function(data) {
|
||||||
var newResults = '<div class="results">';
|
var newResults = $('<div class="results"></div>');
|
||||||
for(var i = 0; i < data.length; i++) { // Create new view for results
|
for(var i = 0; i < data.length; i++) { // Create new view for results
|
||||||
newResults += '<div class="results-row">';
|
var newRow = $('<div class="reults-row"></div>');
|
||||||
newResults += '<a href=# onclick="show_part_info(' + data[i].id + ')">'
|
var newClicker = $('<a href="#" onclick="show_part_info(' + data[i].id + ')"></a>');
|
||||||
|
|
||||||
newResults += '<div class="results-block">';
|
newClicker.append($('<div class="results-block"></div>').text(text_filter(data[i].block)));
|
||||||
|
newClicker.append($('<div class="results-type"></div>').text(text_filter(data[i].type)));
|
||||||
|
newClicker.append($('<div class="results-partno"></div>').text(text_filter(data[i].partno)));
|
||||||
|
newClicker.append($('<div class="results-description"></div>').text(text_filter(data[i].description)));
|
||||||
|
var notes = $('<div class="results-notes"></div>');
|
||||||
|
if (data[i].notes != null && data[i].notes.length > 0) {
|
||||||
|
var icon = $('<i class="fa fa-sticky-note"></i>');
|
||||||
|
var tooltipText = $('<div class="tooltiptext"');
|
||||||
|
var tooltip = $('<div class="tooltip"></div>');
|
||||||
|
tooltip.append(icon, tooltipText);
|
||||||
|
notes.append(tooltip);
|
||||||
|
}
|
||||||
|
newClicker.append(notes);
|
||||||
|
newClicker.append($('<div class="results-datasheet"></div>')
|
||||||
|
.html('<a href="https://www.elab.kth.se/parts/getfile/'
|
||||||
|
+ data[i].datasheet.substring(0, data[i].datasheet.length - 4)
|
||||||
|
+ '"><i class="fa fa-file-text" aria-hidden="true"></i></a>'));
|
||||||
|
|
||||||
|
newRow.append(newClicker);
|
||||||
|
newResults.append(newRow);
|
||||||
|
/*newResults += '<div class="results-datasheet">';
|
||||||
|
if (data[i].datasheet != null)
|
||||||
|
newResults += '<a href="https://www.elab.kth.se/parts/getfile/' + data[i].datasheet.substring(0, data[i].datasheet.length - 4) + '"><i class="fa fa-file-text" aria-hidden="true"></i></a>';
|
||||||
|
newResults += '</div>';*/
|
||||||
|
|
||||||
|
|
||||||
|
//newResults += '<div class="results-row">';
|
||||||
|
//newResults += '<a href=# onclick="show_part_info(' + data[i].id + ')">'
|
||||||
|
|
||||||
|
/*newResults += '<div class="results-block">';
|
||||||
if (data[i].block != null)
|
if (data[i].block != null)
|
||||||
newResults += data[i].block;
|
newResults += data[i].block;
|
||||||
newResults += '</div>';
|
newResults += '</div>';*/
|
||||||
|
|
||||||
newResults += '<div class="results-type">';
|
/*newResults += '<div class="results-type">';
|
||||||
if (data[i].type != null)
|
if (data[i].type != null)
|
||||||
newResults += data[i].type;
|
newResults += data[i].type;
|
||||||
newResults += '</div>';
|
newResults += '</div>';*/
|
||||||
|
|
||||||
newResults += '<div class="results-partno">';
|
/*newResults += '<div class="results-partno">';
|
||||||
if (data[i].partno != null)
|
if (data[i].partno != null)
|
||||||
newResults += data[i].partno;
|
newResults += data[i].partno;
|
||||||
newResults += '</div>';
|
newResults += '</div>';*/
|
||||||
|
|
||||||
newResults += '<div class="results-description">';
|
/*newResults += '<div class="results-description">';
|
||||||
if (data[i].description != null)
|
if (data[i].description != null)
|
||||||
newResults += data[i].description;
|
newResults += data[i].description;
|
||||||
newResults += '</div>';
|
newResults += '</div>';*/
|
||||||
|
|
||||||
newResults += '<div class="results-notes">';
|
/*newResults += '<div class="results-notes">';
|
||||||
if (data[i].notes != null && data[i].notes.length > 0)
|
if (data[i].notes != null && data[i].notes.length > 0)
|
||||||
newResults += '<div class="tooltip"><i class="fa fa-sticky-note"></i><span class="tooltiptext">' + data[i].notes + '</span></div>';
|
newResults += '<div class="tooltip"><i class="fa fa-sticky-note"></i><span class="tooltiptext">' + data[i].notes + '</span></div>';
|
||||||
//newResults += data[i].notes;
|
//newResults += data[i].notes;
|
||||||
newResults += '</div>';
|
newResults += '</div>';*/
|
||||||
|
|
||||||
newResults += '<div class="results-datasheet">';
|
//newResults += '</a>'
|
||||||
if (data[i].datasheet != null)
|
//newResults += '</div>';
|
||||||
newResults += '<a href="https://www.elab.kth.se/parts/getfile/' + data[i].datasheet.substring(0, data[i].datasheet.length - 4) + '"><i class="fa fa-file-text" aria-hidden="true"></i></a>';
|
|
||||||
newResults += '</div>';
|
|
||||||
newResults += '</a>'
|
|
||||||
newResults += '</div>';
|
|
||||||
}
|
}
|
||||||
newResults += '</div>';
|
//newResults += '</div>';
|
||||||
if(data.length == 0) {
|
if(data.length == 0) {
|
||||||
newResults = '<div class="results">';
|
newResults = '<div class="results">';
|
||||||
newResults += '<h3>No results.</h3>';
|
newResults += '<h3>No results.</h3>';
|
||||||
@@ -254,11 +277,14 @@ $(document).ready(function() {
|
|||||||
$('.results').replaceWith(newResults);
|
$('.results').replaceWith(newResults);
|
||||||
console.log( "Query failed" );
|
console.log( "Query failed" );
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
$.ajaxSetup({ cache: false });
|
||||||
|
$('.search-bar').on('keyup', function() {
|
||||||
|
perform_query();
|
||||||
|
});
|
||||||
$('.toggle-btn').on('change', function() {
|
$('.toggle-btn').on('change', function() {
|
||||||
// Re-perform query
|
perform_query();
|
||||||
});
|
});
|
||||||
|
|
||||||
//$('.results-row').on('click', );
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user