Skip to content

Commit

Permalink
* pass table with get parameter using lzw comrpession
Browse files Browse the repository at this point in the history
  • Loading branch information
c0untd0wn committed Jun 1, 2012
1 parent 666fe12 commit 6787d1d
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 1 deletion.
1 change: 1 addition & 0 deletions iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<!--[if lt IE 9]><script language="javascript" type="text/javascript" src="http://c0untd0wn.snucse.org/graphify/js/excanvas.js"></script><![endif]-->
<script type="text/javascript" src="http://c0untd0wn.snucse.org/graphify/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="http://c0untd0wn.snucse.org/graphify/js/visualize.jQuery.js"></script>
<script type="text/javascript" src="http://c0untd0wn.snucse.org/graphify/js/lzw.js"></script>
<script type="text/javascript" src='http://c0untd0wn.snucse.org/graphify/js/example.js'></script>

<link href="http://c0untd0wn.snucse.org/graphify/css/basic.css" type="text/css" rel="stylesheet" />
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<script type="text/javascript" src="js/bootstrap-tooltip.js"></script>
<script type="text/javascript" src="js/bootstrap-popover.js"></script>
<script type="text/javascript" src="js/bootstrap-modal.js"></script>
<script type="text/javascript" src="js/lzw.js"></script>
<script type="text/javascript" src="js/main.js"></script>

<link rel="stylesheet" type="text/css" href="css/main.css">
Expand Down
5 changes: 4 additions & 1 deletion js/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ $(function(){
}

graph_or_table = 0;
table = $.getUrlVar('table');
alert(table);
$('body').prepend(unescape(LZW.decompress(table)));

$('#input_table', window.parent.document).clone().prependTo('body');
//$('#input_table', window.parent.document).clone().prependTo('body');
$('thead th:last-child').remove();
$('tbody td:last-child').remove();
$('tbody tr:last').remove();
Expand Down
74 changes: 74 additions & 0 deletions js/lzw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
var LZW = {
compress: function (uncompressed) {
"use strict";
// Build the dictionary.
var i,
dictionary = {},
c,
wc,
w = "",
result = [],
dictSize = 256;
for (i = 0; i < 256; i += 1) {
dictionary[String.fromCharCode(i)] = i;
}

for (i = 0; i < uncompressed.length; i += 1) {
c = uncompressed.charAt(i);
wc = w + c;
if (dictionary[wc]) {
w = wc;
} else {
result.push(dictionary[w]);
// Add wc to the dictionary.
dictionary[wc] = dictSize++;
w = String(c);
}
}

// Output the code for w.
if (w !== "") {
result.push(dictionary[w]);
}
return result;
},


decompress: function (compressed) {
"use strict";
// Build the dictionary.
var i,
dictionary = [],
w,
result,
k,
entry = "",
dictSize = 256;
for (i = 0; i < 256; i += 1) {
dictionary[i] = String.fromCharCode(i);
}

w = String.fromCharCode(compressed[0]);
result = w;
for (i = 1; i < compressed.length; i += 1) {
k = compressed[i];
if (dictionary[k]) {
entry = dictionary[k];
} else {
if (k === dictSize) {
entry = w + w.charAt(0);
} else {
return null;
}
}

result += entry;

// Add w+entry[0] to the dictionary.
dictionary[dictSize++] = w + entry.charAt(0);

w = entry;
}
return result;
}
}
1 change: 1 addition & 0 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ $('document').ready(function(){
});
var address = 'iframe.html';
address = address.concat('?', $.param(values));
address = address.concat('&table=', LZW.compress(escape($('#input_table').parent().html())));

$('<iframe />').attr('src', address).attr('id', 'table_iframe').attr('frameBorder', '0').attr('style', 'height:100%;').appendTo('#result .centered');
$('.alert').alert('close');
Expand Down

0 comments on commit 6787d1d

Please sign in to comment.