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
31
dencoder.js
31
dencoder.js
|
@ -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>";
|
||||||
|
@ -110,29 +111,25 @@
|
||||||
$("body").append($output);
|
$("body").append($output);
|
||||||
} else {
|
} else {
|
||||||
$output.val(output);
|
$output.val(output);
|
||||||
|
update($output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clean(outputIndex);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
Loading…
Reference in a new issue