implement jqueryui dialog replacements.

For now only alert windows are converted automatically. You can alert custom
HTML code like so: alert('<strong>herp a derp</strong>', true);

Main can use this feature immediately, all plugins that are advertized to be
stable may only use this once 0.7 is released.
This commit is contained in:
Stefan Breunig
2013-02-22 11:23:44 +01:00
parent 3377c81728
commit d644ef64bd
4 changed files with 100 additions and 34 deletions

View File

@ -233,3 +233,37 @@ window.genFourColumnTable = function(blocks) {
if(t.length % 2 === 1) t + '<td></td><td></td></tr>';
return t;
}
// converts given text with newlines (\n) and tabs (\t) to a HTML
// table automatically.
window.convertTextToTableMagic = function(text) {
// check if it should be converted to a table
if(!text.match(/\t/)) return text.replace(/\n/g, '<br>');
var data = [];
var columnCount = 0;
// parse data
var rows = text.split('\n');
$.each(rows, function(i, row) {
data[i] = row.split('\t');
if(data[i].length > columnCount) columnCount = data[i].length;
});
// build the table
var table = '<table>';
$.each(data, function(i, row) {
table += '<tr>';
$.each(data[i], function(k, cell) {
var attributes = '';
if(k === 0 && data[i].length < columnCount) {
attributes = ' colspan="'+(columnCount - data[i].length + 1)+'"';
}
table += '<td'+attributes+'>'+cell+'</td>';
});
table += '</tr>';
});
table += '</table>';
return table;
}