update the whole chain upon changes and also when the conversion method
changes
This commit is contained in:
parent
c2d9dc9e38
commit
0996aee7a7
1 changed files with 15 additions and 18 deletions
33
dencoder.js
33
dencoder.js
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue