X-Git-Url: https://disinclined.org/git/?a=blobdiff_plain;f=js%2Fmatrix.js;fp=js%2Fmatrix.js;h=83e8e27707dce197443a158aea64a2e5f1dc05c4;hb=cf491ed085c7fb21ab8d94eb7f5c48c17504b525;hp=0000000000000000000000000000000000000000;hpb=b1182e5a62a5a690fc29589b2ac88ba96cd46c38;p=matrixnullspace.com.git diff --git a/js/matrix.js b/js/matrix.js new file mode 100644 index 0000000..83e8e27 --- /dev/null +++ b/js/matrix.js @@ -0,0 +1,43 @@ +$(document).ready(function(){ + $('#submit').click(function(event){ + if ($('#matrix').val() == '' + || $('#matrix').val().match(/[^.\-\d\s]/) != null) { + event.preventDefault(); + $('#results').fadeOut('slow', function() { + $('#results').html( + $('').attr('id', 'fail').text( + $('#matrix').val() == '' ? + 'Enter a matrix!' : 'Invalid character in matrix.' + )); + $('#results').fadeIn(); + }); + return; + } + $.post('/calculate', { 'matrix' : $('#matrix').val() }) + .done(function(data) { + $('#results').fadeOut('slow', function() { + $('#results').html('').append( + $('
  • ').text('eigenvalues').append( + $('
    ').text(data.eigenvalues)),
    +                    $('
  • ').text('determinant').append( + $('
    ').text(data.determinant)),
    +                    $('
  • ').text('nullspace').append( + $('
    ').text(data.nullspace))
    +                );
    +                $('#results').fadeIn();
    +            });
    +        })
    +        .fail(function(data) {
    +            $('#results').fadeOut('slow', function() {
    +                $('#results').html(
    +                    $('').attr('id', 'fail')
    +                        .text('Uh-oh, something\'s gone wrong!'));
    +                $('#results').fadeIn();
    +            });
    +        });
    +  });
    +  $('textarea').focus(function(e) {
    +      $(e.target).text('');
    +      $(e.target).css({ 'color' : 'black', 'font-style' : 'none' });
    +  });
    +});