Avoid HTML collisions. Inspired by the code from rfc2616. This fixes #6.

This commit is contained in:
nathanvda 2011-04-25 00:21:13 +02:00
parent 6da1069680
commit 630a88a704
1 changed files with 12 additions and 0 deletions

View File

@ -1,5 +1,11 @@
$(document).ready(function() { $(document).ready(function() {
function replace_in_content(content, regexp_str, with_str) {
reg_exp = new RegExp(regexp_str);
content.replace(reg_exp, with_str)
}
$('.add_fields').live('click', function() { $('.add_fields').live('click', function() {
var assoc = $(this).attr('data-association'); var assoc = $(this).attr('data-association');
var assocs = $(this).attr('data-associations'); var assocs = $(this).attr('data-associations');
@ -7,12 +13,18 @@ $(document).ready(function() {
var insertionPosition = $(this).attr('data-association-insertion-position'); var insertionPosition = $(this).attr('data-association-insertion-position');
var insertionNode = $(this).attr('data-association-insertion-node'); var insertionNode = $(this).attr('data-association-insertion-node');
var regexp_braced = new RegExp('\\[new_' + assoc + '\\]', 'g'); var regexp_braced = new RegExp('\\[new_' + assoc + '\\]', 'g');
var regexp_underscord = new RegExp('_new_' + assoc + '_', 'g');
var new_id = new Date().getTime(); var new_id = new Date().getTime();
var newcontent_braced = '[' + new_id + ']';
var newcontent_underscord = '_' + new_id + '_';
var new_content = content.replace(regexp_braced, '[' + new_id + ']'); var new_content = content.replace(regexp_braced, '[' + new_id + ']');
if (new_content == content) { if (new_content == content) {
regexp_braced = new RegExp('\\[new_' + assocs + '\\]', 'g'); regexp_braced = new RegExp('\\[new_' + assocs + '\\]', 'g');
regexp_underscord = new RegExp('_new_' + assocs + '_', 'g');
new_content = content.replace(regexp_braced, '[' + new_id + ']'); new_content = content.replace(regexp_braced, '[' + new_id + ']');
} }
new_content = new_content.replace(regexp_underscord, newcontent_underscord);
if (insertionNode) { if (insertionNode) {
insertionNode = $(insertionNode); insertionNode = $(insertionNode);
} }