| 1 |
function update_preview(command, element) {
|
| 2 |
switch (command) {
|
| 3 |
case 'total' :
|
| 4 |
table_total_ads = element.options[element.selectedIndex].value;
|
| 5 |
redraw_table();
|
| 6 |
break;
|
| 7 |
case 'rows' :
|
| 8 |
table_rows = element.options[element.selectedIndex].value;
|
| 9 |
redraw_table();
|
| 10 |
break;
|
| 11 |
case 'font' :
|
| 12 |
update_font_size(element.options[element.selectedIndex].value);
|
| 13 |
break;
|
| 14 |
case 'link_color' :
|
| 15 |
update_link_color(element.value);
|
| 16 |
break;
|
| 17 |
}
|
| 18 |
}
|
| 19 |
|
| 20 |
function update_link_color(value) {
|
| 21 |
if (typeof(value) == 'undefined') {
|
| 22 |
value = document.getElementById('edit-textlinkads_link_color').value;
|
| 23 |
}
|
| 24 |
var spans = document.getElementsByTagName('span');
|
| 25 |
for (var i = 0, arr_length = spans.length; i < arr_length; ++i) {
|
| 26 |
if (spans[i].className == 'textlinkads-example-link') {
|
| 27 |
spans[i].style.color = value;
|
| 28 |
}
|
| 29 |
}
|
| 30 |
link_color = value;
|
| 31 |
}
|
| 32 |
|
| 33 |
function update_bg_color(value) {
|
| 34 |
if (typeof(value) == 'undefined') {
|
| 35 |
value = document.getElementById('edit-textlinkads-bg-color').value;
|
| 36 |
}
|
| 37 |
if (!document.getElementById('edit-textlinkads-no-bg').checked) {
|
| 38 |
no_bg = 0;
|
| 39 |
document.getElementById('textlinkads_preview_table').style.backgroundColor = value;
|
| 40 |
}
|
| 41 |
else {
|
| 42 |
no_bg = 1;
|
| 43 |
document.getElementById('textlinkads_preview_table').style.backgroundColor = 'transparent';
|
| 44 |
}
|
| 45 |
bg_color = value;
|
| 46 |
}
|
| 47 |
function update_border_color(value) {
|
| 48 |
if (typeof(value) == 'undefined') {
|
| 49 |
value = document.getElementById('edit-textlinkads-border-color').value;
|
| 50 |
}
|
| 51 |
border_color = value;
|
| 52 |
if (!document.getElementById('edit-textlinkads-no-border').checked) {
|
| 53 |
no_border = 0;
|
| 54 |
document.getElementById('textlinkads_preview_table').style.border = '1px solid ' + value;
|
| 55 |
// FireFox bug fix ... weird
|
| 56 |
redraw_table();
|
| 57 |
}
|
| 58 |
else {
|
| 59 |
no_border = 1;
|
| 60 |
document.getElementById('textlinkads_preview_table').style.border = 'none';
|
| 61 |
}
|
| 62 |
}
|
| 63 |
|
| 64 |
function update_font_size(size) {
|
| 65 |
if (typeof(size) == 'undefined') {
|
| 66 |
size = document.getElementById('edit-textlinkads-font').options[document.getElementById('edit-textlinkads-font').selectedIndex].value;
|
| 67 |
}
|
| 68 |
var spans = document.getElementsByTagName('span');
|
| 69 |
for (var i = 0, arr_length = spans.length; i < arr_length; ++i) {
|
| 70 |
if (spans[i].className == 'textlinkads-example-link') {
|
| 71 |
spans[i].style.fontSize = size + 'px';
|
| 72 |
}
|
| 73 |
}
|
| 74 |
font_size = size;
|
| 75 |
}
|
| 76 |
|
| 77 |
function redraw_table() {
|
| 78 |
//alert('total: ' + table_total_ads + ' rows ' + table_rows);
|
| 79 |
var table = '<table id="textlinkads_preview_table" style="border: ' + (no_border == 1 ? 'none' : '1px solid' + border_color) + '; border-spacing: 0px; background-color: '+ (no_bg == 1 ? 'transparent' : bg_color) +';" cellpadding="5" cellspacing="0"><tbody>';
|
| 80 |
var k;
|
| 81 |
var columns = Math.ceil(table_total_ads / table_rows)
|
| 82 |
for (var i = 0; i < table_total_ads;) {
|
| 83 |
table += "<tr>";
|
| 84 |
for (k = 0; k < columns; k++) {
|
| 85 |
if (i < table_total_ads) {
|
| 86 |
table += "<td><span class='textlinkads-example-link' style='cursor: pointer;text-decoration: underline;font-size:"+ font_size +"px; color:"+ link_color +";'>" + example_link + "</span></td>";
|
| 87 |
} else {
|
| 88 |
table += "<td> </td>";
|
| 89 |
}
|
| 90 |
i++;
|
| 91 |
}
|
| 92 |
table += "</tr>";
|
| 93 |
}
|
| 94 |
table += '</tbody></table>';
|
| 95 |
|
| 96 |
document.getElementById('preview').innerHTML = table;
|
| 97 |
}
|
| 98 |
|
| 99 |
function addLoadEvent(func) {
|
| 100 |
var oldOnload = window.onload;
|
| 101 |
if (typeof window.onload != 'function') {
|
| 102 |
window.onload = func;
|
| 103 |
}
|
| 104 |
else {
|
| 105 |
window.onload = function() {
|
| 106 |
oldOnload();
|
| 107 |
func();
|
| 108 |
}
|
| 109 |
}
|
| 110 |
}
|
| 111 |
|
| 112 |
function init() {
|
| 113 |
redraw_table();
|
| 114 |
update_bg_color();
|
| 115 |
update_border_color();
|
| 116 |
document.getElementById('edit-textlinkads-total').onchange = function() {update_preview('total', this)};
|
| 117 |
document.getElementById('edit-textlinkads-font').onchange = function() {update_preview('font', this)};
|
| 118 |
document.getElementById('edit-textlinkads-rows').onchange = function() {update_preview('rows', this)};
|
| 119 |
}
|
| 120 |
|
| 121 |
addLoadEvent(init);
|