Skip to content

Commit 8d1d99b

Browse files
committed
Improved table layout.
1 parent 21da881 commit 8d1d99b

File tree

2 files changed

+99
-10
lines changed

2 files changed

+99
-10
lines changed

jquery.syntax.layout.table.css

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ table.syntax {
1111
-webkit-box-shadow: 5px 5px 5px #eee;
1212
}
1313

14+
table.syntax tr.alt td.source {
15+
background-color: #f6f6f6;
16+
}
17+
1418
table.syntax td {
1519
padding-left: 0.4em;
1620
padding-right: 0.4em;
@@ -22,5 +26,14 @@ table.syntax td.number {
2226

2327
width: 2.5em;
2428
color: #555;
25-
background-color: #dadada;
29+
background-color: #e0e0e0;
30+
}
31+
32+
table.syntax .toolbar {
33+
float: right;
34+
}
35+
36+
table.syntax .toolbar a {
37+
margin-left: 1em;
38+
margin-right: 1em;
2639
}

jquery.syntax.layout.table.js

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,98 @@
1+
function createWindow (url, name, width, height, options) {
2+
var x = (screen.width - width) / 2, y = (screen.height - height) / 2;
3+
4+
//options += ',left=' + x +
5+
// ',top=' + y +
6+
// ',width=' + width +
7+
// ',height=' + height;
8+
//
9+
options = options.replace(/^,/, '');
10+
11+
var win = window.open(url, name, options);
12+
13+
win.focus();
14+
15+
return win;
16+
}
17+
118
Syntax.layouts.table = function(options, code, container) {
2-
var table = $('<table>'), tr = null, td = null;
19+
var table = $('<table>'), tr = null, td = null, a = null, toolbar = null
320
var line = 1;
421

522
table.addClass('syntax');
623

24+
// Toolbar
25+
toolbar = document.createElement('div');
26+
toolbar.className = "toolbar";
27+
28+
a = document.createElement('a');
29+
a.href = "#";
30+
a.innerHTML = "View Raw Code";
31+
32+
a.onclick = function() {
33+
var win = createWindow('#', '_blank', 700, 500, 'location=0, resizable=1, menubar=0, scrollbars=1, title=Raw');
34+
35+
win.document.write('<html><head></head><body><pre class="syntax">' + code.html() + '</pre></body></html>');
36+
37+
$('link').each(function(){
38+
if (this.rel != 'stylesheet') {
39+
return;
40+
}
41+
42+
window.console.log(this.href);
43+
var link = $('<link rel="stylesheet">', win.document);
44+
45+
link.attr('type', this.type);
46+
link.attr('href', this.href);
47+
link.attr('media', this.media);
48+
49+
$("head", win.document).append(link);
50+
});
51+
52+
debugger
53+
54+
win.document.close();
55+
win.document.title = "Raw Source Code";
56+
};
57+
58+
toolbar.appendChild(a);
59+
60+
a = document.createElement('a');
61+
a.href = "http://www.oriontransfer.co.nz/software/jquery-syntax/";
62+
a.innerHTML = "?";
63+
toolbar.appendChild(a);
64+
65+
// Source code
766
code.children().each(function() {
8-
tr = $('<tr>').addClass('line', 'line-' + line);
67+
tr = document.createElement('tr');
68+
tr.className = "line ln" + line;
69+
70+
if (line % 2) {
71+
tr.className += " alt";
72+
}
973

10-
td = $('<td>').addClass('number').text(line);
11-
tr.append(td);
74+
td = document.createElement('td');
75+
td.className = "number";
76+
td.innerHTML = line;
77+
tr.appendChild(td);
1278

13-
td = $('<td>').addClass('source');
14-
td.append(this);
15-
tr.append(td);
79+
td = document.createElement('td');
80+
td.className = "source " + this.className;
81+
td.innerHTML = this.innerHTML;
82+
tr.appendChild(td);
1683

17-
table.append(tr);
84+
if (toolbar) {
85+
td.appendChild(toolbar);
86+
toolbar = null;
87+
}
88+
89+
table[0].appendChild(tr);
1890
line = line + 1;
1991
});
2092

93+
$('.href', table).each(function(){
94+
$(this).replaceWith($('<a>').attr('href', this.innerHTML).text(this.innerHTML));
95+
});
96+
2197
return table;
22-
}
98+
};

0 commit comments

Comments
 (0)