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:
49
code/boot.js
49
code/boot.js
@ -201,37 +201,7 @@ window.setupTooltips = function(element) {
|
||||
},
|
||||
content: function() {
|
||||
var title = $(this).attr('title');
|
||||
|
||||
// check if it should be converted to a table
|
||||
if(!title.match(/\t/)) {
|
||||
return title.replace(/\n/g, '<br />');
|
||||
}
|
||||
|
||||
var data = [];
|
||||
var columnCount = 0;
|
||||
|
||||
// parse data
|
||||
var rows = title.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 tooltip = '<table>';
|
||||
$.each(data, function(i, row) {
|
||||
tooltip += '<tr>';
|
||||
$.each(data[i], function(k, cell) {
|
||||
var attributes = '';
|
||||
if(k === 0 && data[i].length < columnCount) {
|
||||
attributes = ' colspan="'+(columnCount - data[i].length + 1)+'"';
|
||||
}
|
||||
tooltip += '<td'+attributes+'>'+cell+'</td>';
|
||||
});
|
||||
tooltip += '</tr>';
|
||||
});
|
||||
tooltip += '</table>';
|
||||
return tooltip;
|
||||
return window.convertTextToTableMagic(title);
|
||||
}
|
||||
});
|
||||
|
||||
@ -241,6 +211,22 @@ window.setupTooltips = function(element) {
|
||||
}
|
||||
}
|
||||
|
||||
window.setupDialogs = function() {
|
||||
$('#dialog').dialog({
|
||||
autoOpen: false,
|
||||
modal: true,
|
||||
buttons: [
|
||||
{ text: 'OK', click: function() { $(this).dialog('close'); } }
|
||||
]
|
||||
});
|
||||
|
||||
window.alert = function(text, isHTML) {
|
||||
var h = isHTML ? text : window.convertTextToTableMagic(text);
|
||||
$('#dialog').html(h).dialog('open');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// BOOTING ///////////////////////////////////////////////////////////
|
||||
|
||||
@ -258,6 +244,7 @@ function boot() {
|
||||
window.iconRes = L.Icon.Default.extend({options: { iconUrl: base + 'marker-blue.png' } });
|
||||
|
||||
window.setupStyles();
|
||||
window.setupDialogs();
|
||||
window.setupMap();
|
||||
window.setupGeosearch();
|
||||
window.setupRedeem();
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user