|
| 1 | +// Delay loading any function until the html dom has loaded. All functions are |
| 2 | +// defined in this top level function to ensure private scope. |
| 3 | +jQuery(document).ready(function () { |
| 4 | + |
| 5 | + // Installs error handling. |
| 6 | + jQuery.ajaxSetup({ |
| 7 | + error: function(resp, e) { |
| 8 | + if (resp.status == 0){ |
| 9 | + alert('You are offline!!\n Please Check Your Network.'); |
| 10 | + } else if (resp.status == 404){ |
| 11 | + alert('Requested URL not found.'); |
| 12 | + } else if (resp.status == 500){ |
| 13 | + alert('Internel Server Error:\n\t' + resp.responseText); |
| 14 | + } else if (e == 'parsererror') { |
| 15 | + alert('Error.\nParsing JSON Request failed.'); |
| 16 | + } else if (e == 'timeout') { |
| 17 | + alert('Request timeout.'); |
| 18 | + } else { |
| 19 | + alert('Unknown Error.\n' + resp.responseText); |
| 20 | + } |
| 21 | + } |
| 22 | + }); // error:function() |
| 23 | + |
| 24 | + |
| 25 | + var generate_btn = jQuery('#generate_btn'); |
| 26 | + var sample_1_btn = jQuery('#sample_1_btn'); |
| 27 | + var sample_2_btn = jQuery('#sample_2_btn'); |
| 28 | + var sample_3_btn = jQuery('#sample_3_btn'); |
| 29 | + var sample_4_btn = jQuery('#sample_4_btn'); |
| 30 | + var sample_5_btn = jQuery('#sample_5_btn'); |
| 31 | + |
| 32 | + var svg_div = jQuery('#graphviz_svg_div'); |
| 33 | + var graphviz_data_textarea = jQuery('#graphviz_data'); |
| 34 | + |
| 35 | + function InsertGraphvizText(text) { |
| 36 | + graphviz_data_textarea.val(text); |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | + function UpdateGraphviz() { |
| 41 | + svg_div.html(""); |
| 42 | + var data = graphviz_data_textarea.val(); |
| 43 | + // Generate the Visualization of the Graph into "svg". |
| 44 | + var svg = Viz(data, "svg"); |
| 45 | + svg_div.html("<hr>"+svg); |
| 46 | + } |
| 47 | + |
| 48 | + // Startup function: call UpdateGraphviz |
| 49 | + jQuery(function() { |
| 50 | + // The buttons are disabled, enable them now that this script |
| 51 | + // has loaded. |
| 52 | + generate_btn.removeAttr("disabled") |
| 53 | + .text("Generate Graph!"); |
| 54 | + |
| 55 | + sample_1_btn.removeAttr("disabled"); |
| 56 | + sample_2_btn.removeAttr("disabled"); |
| 57 | + sample_3_btn.removeAttr("disabled"); |
| 58 | + sample_4_btn.removeAttr("disabled"); |
| 59 | + sample_5_btn.removeAttr("disabled"); |
| 60 | + }); |
| 61 | + |
| 62 | + // Bind actions to form buttons. |
| 63 | + generate_btn.click(UpdateGraphviz); |
| 64 | + |
| 65 | + sample_1_btn.click(function(){ |
| 66 | + InsertGraphvizText(jQuery("#sample1_text").html().trim()); |
| 67 | + }); |
| 68 | + |
| 69 | + sample_2_btn.click(function(){ |
| 70 | + InsertGraphvizText(jQuery("#sample2_text").html().trim()); |
| 71 | + }); |
| 72 | + |
| 73 | + sample_3_btn.click(function(){ |
| 74 | + InsertGraphvizText(jQuery("#sample3_text").html().trim()); |
| 75 | + }); |
| 76 | + |
| 77 | + sample_4_btn.click(function(){ |
| 78 | + InsertGraphvizText(jQuery("#sample4_text").html().trim()); |
| 79 | + }); |
| 80 | + |
| 81 | + sample_5_btn.click(function(){ |
| 82 | + InsertGraphvizText(jQuery("#sample5_text").html().trim()); |
| 83 | + }); |
| 84 | + |
| 85 | +}); |
0 commit comments