[fix] Clean javascript. Empty value when cloning inputs.

This commit is contained in:
opi 2014-05-14 11:14:45 +02:00
parent 26455fbdb4
commit ed5c8908cf

View file

@ -1,26 +1,35 @@
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
var liMenu = document.querySelectorAll('#apps a'),
colors = ['bluebg','purplebg','redbg','orangebg','greenbg','darkbluebg','lightbluebg','yellowbg','lightpinkbg'], // Variables
addMailAlias = document.getElementById('add-mailalias'), var liMenu = document.querySelectorAll('#apps a')
addMaildrop = document.getElementById('add-maildrop'), , colors = ['bluebg','purplebg','redbg','orangebg','greenbg','darkbluebg','lightbluebg','yellowbg','lightpinkbg']
formMailAlias = document.getElementById('form-add-mail-alias'), , addMailAlias = document.getElementById('add-mailalias')
formMailDrop = document.getElementById('form-add-mail-drop'); , addMaildrop = document.getElementById('add-maildrop')
;
[].forEach.call(liMenu, function(el, i) { [].forEach.call(liMenu, function(el, i) {
var text = el.textContent, // Add color class.
splitText = text.split("");
el.classList.add(colors[i]); el.classList.add(colors[i]);
el.querySelector('.first-letter').setAttribute('data-first-letter',splitText[0]+splitText[1]); // Set first-letter data attribute.
el.querySelector('.first-letter').setAttribute('data-first-letter',el.textContent.substring(0, 2));
}); });
addMailAlias.addEventListener('click', function(){ addMailAlias.addEventListener('click', function(){
var inputAlias = document.querySelector('.mailalias-input'); // Clone last input.
formMailAlias.insertBefore(inputAlias.cloneNode(true), addMailAlias); var inputAliasClone = document.querySelector('.mailalias-input').cloneNode(true);
// Empty value.
inputAliasClone.value = '';
// Append to form-group.
addMailAlias.parentNode.insertBefore(inputAliasClone, addMailAlias);
}); });
addMaildrop.addEventListener('click', function(){ addMaildrop.addEventListener('click', function(){
var inputDrop = document.querySelector('.maildrop-input'); // Clone last input.
formMailDrop.insertBefore(inputDrop.cloneNode(true), addMaildrop); var inputDropClone = document.querySelector('.maildrop-input').cloneNode(true);
// Empty value.
inputDropClone.value = '';
// Append to form-group.
addMaildrop.parentNode.insertBefore(inputDropClone, addMaildrop);
}); });
}); });