main.js 1.34 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
// Generated by CoffeeScript 1.3.3
(function() {

  jQuery.postWithPrefix = function(url, data, callback, type) {
    return $.post("" + Courseware.prefix + url, data, callback, type);
  };

  jQuery.getWithPrefix = function(url, data, callback, type) {
    return $.get("" + Courseware.prefix + url, data, callback, type);
  };

  $(function() {
    $.ajaxSetup({
      headers: {
        'X-CSRFToken': $.cookie('csrftoken')
      },
      dataType: 'json'
    });
    window.onTouchBasedDevice = function() {
      return navigator.userAgent.match(/iPhone|iPod|iPad/i);
    };
    $("a[rel*=leanModal]").leanModal();
    $('#csrfmiddlewaretoken').attr('value', $.cookie('csrftoken'));
    if ($('body').hasClass('courseware')) {
      Courseware.start();
    }
    window.submit_circuit = function(circuit_id) {
      $("input.schematic").each(function(index, element) {
        return element.schematic.update_value();
      });
      schematic_value($("#schematic_" + circuit_id).attr("value"));
      return $.postWithPrefix("/save_circuit/" + circuit_id, {
        schematic: schematic_value
      }, function(data) {
        if (data.results === 'success') {
          return alert('Saved');
        }
      });
    };
    return window.postJSON = function(url, data, callback) {
      return $.postWithPrefix(url, data, callback);
    };
  });

}).call(this);