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