Участник:Js/instable.js

Материал из Википедии — свободной энциклопедии
//custom edit button that opens a dialog window to insert a table; see talk page

function insTablePopup(){
var popup = window.open('','name','height=190,width=300,scrollbars=yes')
popup.document.write('\
<html><head><title>Создание таблицы</title>\
<script>function it(){\
window.opener.insTableAdd(\
parseInt(document.f.inputCol.value),\
parseInt(document.f.inputRow.value),\
0,false,false,false,\
document.f.inputAlign.value,false);\
window.close()}<\/script>\
</head><body>\
<p>Введите параметры таблицы: </p>\
<form name=f>\
Выравнивание: <input type=text name=inputAlign value=center><p>\
Строк: <input type=text name=inputRow value=3><p>\
Столбцов: <input type=text name=inputCol value=3><p>\
</form>\
<p><a href="javascript:it()">Вставить таблицу</a> | \
<a href="javascript:self.close()">Отмена</a>\
</body></html>')
popup.document.close()
}

function insTableAdd(nbCol, nbRow, border, styleHeader, styleLine, exfield, align){
 var s = '\n{| align="' + align + '" class="standard"\n|+\n'
 for (var i=1;i<nbCol+1;i++) s += '! |Столбец ' + i + '\n'
 for (var i=0;i<nbRow;i++) {
   s += '|-----\n'
   for (var j=0;j<nbCol;j++) s += '| ячейка\n'
 }
 insertTags('', '', s + '|+\n|}\n') 
}

$(function(){
addFuncBtn('insTable', insTablePopup, 'commons/0/04/Button_array.png', 'Добавить таблицу (диалоговое окно)')
})