changed encode and decode to be 2 seperate buttons instead of 'go' and a setting.

This commit is contained in:
Kevin Froman 2017-03-30 09:53:52 -05:00
parent 2c146fef1a
commit 546900bcdb
No known key found for this signature in database
GPG Key ID: 36698DB39DA54065
2 changed files with 19 additions and 25 deletions

View File

@ -55,14 +55,19 @@
<br><br> <br><br>
<label>Use Encryption <input type='checkbox' id='useEncrypt' checked></label> <label>Use Encryption <input type='checkbox' id='useEncrypt' checked></label>
<br><br> <br><br>
<div id='one'><button id='toggle' class='btn btn-primary'>Encode Mode <i class='fa fa-lock'></i></button></div>
<span id='encryptArea'> <span id='encryptArea'>
<input type='password' id='password' placeholder='Encryption password' class='dataItem'> <input type='password' id='password' placeholder='Encryption password' class='dataItem'>
<br> <br>
<input type='password' id='confirmPass' placeholder='Confirm password' class='dataItem'> <input type='password' id='confirmPass' placeholder='Confirm password' class='dataItem'>
<br> <br>
</span> </span>
<button id='go' class='btn btn-success btn-lg dataItem'>Go</button> <!--<div id='one'><button id='toggle' class='btn btn-primary'>Encode Mode <i class='fa fa-lock'></i></button></div>-->
<div class="btn-group" role="group" aria-label="...">
<button type="button" class="btn btn-primary" id="encode">Encode <i class='fa fa-lock'></i></button>
<button type="button" class="btn btn-primary" id="decode">Decode <i class='fa fa-unlock'></i></button>
</div>
<br>
<!--<button id='go' class='btn btn-success btn-lg dataItem'>Go</button>-->
</div> </div>
</div> </div>
<footer class='center'>made with <i class='fa fa-heart'></i> by <a href='https://chaoswebs.net/'>Beardog</a></footer> <footer class='center'>made with <i class='fa fa-heart'></i> by <a href='https://chaoswebs.net/'>Beardog</a></footer>

35
main.js
View File

@ -43,29 +43,11 @@ $('#modalClose').click(function(){
$('#copyFeedback').css('display', 'none'); $('#copyFeedback').css('display', 'none');
}); });
window.snowMode = 'encode';
$("#output").on("click", function () { $("#output").on("click", function () {
$(this).select(); $(this).select();
}); });
$('#toggle').click(function(){
if (window.snowMode == 'encode')
{
window.snowMode = 'decode';
$('#toggle').html("Decode Mode <i class='fa fa-unlock'></i>");
$('#confirmPass').css('display', 'none');
}
else
{
window.snowMode = 'encode';
$('#toggle').html("Encode Mode <i class='fa fa-lock'></i>");
$('#confirmPass').css('display', 'inline');
}
});
$('#useZeroWidthCharacters').click(function(){ $('#useZeroWidthCharacters').click(function(){
if (zero == w_zero) if (zero == w_zero)
@ -100,7 +82,7 @@ function textToBin(text) {
for (var i = 0;i < length; i++) { for (var i = 0;i < length; i++) {
var bin = text[i].charCodeAt().toString(2); var bin = text[i].charCodeAt().toString(2);
output.push(Array(8-bin.length+1).join("0") + bin); output.push(Array(8-bin.length+1).join("0") + bin);
} }
return output.join(''); return output.join('');
} }
@ -134,7 +116,14 @@ function verifyPass(mode)
return true; return true;
} }
$('#go').click(function(){ $('#encode').click(function(){
go('encode');
});
$('#decode').click(function(){
go('decode');
});
function go(mode) {
var output = ''; var output = '';
var input = $('#text').val(); var input = $('#text').val();
@ -142,8 +131,8 @@ $('#go').click(function(){
if (input == '') { return false; } if (input == '') { return false; }
// If we're encoding: // If we're encoding:
if (window.snowMode == 'encode') if (mode == 'encode')
{ {
// If we should use encryption, encrypt first: // If we should use encryption, encrypt first:
if ($('#useEncrypt').is(':checked')) if ($('#useEncrypt').is(':checked'))
@ -184,7 +173,7 @@ $('#go').click(function(){
$('#output').val(output.toString()); $('#output').val(output.toString());
} }
$('#outputModal').modal(); $('#outputModal').modal();
}); }
$('#clearInputButton').click(function(){ $('#clearInputButton').click(function(){
$('#text').val(''); $('#text').val('');