update the whole chain upon changes and also when the conversion method

changes
This commit is contained in:
Manuel Friedli 2015-03-25 20:20:40 +01:00
parent c2d9dc9e38
commit 0996aee7a7

View file

@ -56,8 +56,9 @@
} }
} }
]; ];
var optiontemplate = "<option name='{identifier}'>{name}</option>"; var optiontemplate = "<option name='{identifier}'>{name}</option>";
var template = "<div id='wrapper-{index}' class='wrapper'><textarea id='input-{index}' class='input'>{content}</textarea>" var template = "<div id='wrapper-{index}' class='wrapper'><textarea id='input-{index}' class='input' onchange='den.update(this);'>{content}</textarea>"
+ "<select id='type-{index}' class='conversion' onchange='den.convert(this);'>" + "<select id='type-{index}' class='conversion' onchange='den.convert(this);'>"
+ "{options}" + "{options}"
+ "</select></div>"; + "</select></div>";
@ -109,30 +110,26 @@
$output = $(template.replace(/\{index\}/g, "" + outputIndex).replace(/\{content\}/g, output)); $output = $(template.replace(/\{index\}/g, "" + outputIndex).replace(/\{content\}/g, output));
$("body").append($output); $("body").append($output);
} else { } else {
$output.val(output); $output.val(output);
update($output);
} }
clean(outputIndex);
} }
function clean(index) { function update(textarea) {
var found = true; var $textarea = $(textarea);
var $wrapper; var areaid = $textarea.attr("id");
$("#type-" + index + " option[name=CHOOSE]").prop("selected", true); var inputindex = +areaid.split("-")[1];
index++; var $select = $("#type-" + inputindex);
do { var conversion = $select.find(":selected").attr("name");
$wrapper = $("#wrapper-" + index); var plugin = getPluginById(conversion);
if ($wrapper.length > 0) { if (plugin !== null) {
$wrapper.remove(); convert($select);
index++; }
} else {
found = false;
}
} while (found);
} }
var den = {}; var den = {};
den.convert = convert; den.convert = convert;
den.update = update;
window.den = window.den || den; window.den = window.den || den;
})(jQuery); })(jQuery);