问题
I have already all required properties of table (i.e. rows, cols counts, style, class, header style, etc.).
I need to add table with this properties when user clicks on my custom button, without going through any dialog.
I thought about showing dialog and substituting required fields with my data and triggering OK click. But this.. kinda ugly solution.
Please tell me, is there any elegant solution for this task ?
回答1:
Solved problem by actually hack on default values to make them getter-function like, and clicking ok button once dialog is shown:
(warning, coffee)
CKEDITOR.on 'dialogDefinition', (ev) ->
if ev.data.name is 'table'
info = ev.data.definition.getContents 'info'
advanced = ev.data.definition.getContents 'advanced'
# HACK: default value now returns always value I have control on
info.get('txtRows')['default'] = { toString: -> self.ckeditor_table_rows }
info.get('txtCols')['default'] = { toString: -> self.ckeditor_table_cols }
# setup some normal defaults
info.get('txtWidth')['default'] = ''
info.get('txtBorder')['default'] = '0'
info.get('selHeaders')['default'] = 'row'
advanced.get('advCSSClasses')['default'] = 'table table-striped'
ev.data.definition.dialog.on 'show', ->
# make it create table, once dialog shown
this.getButton('ok').click()
# hide my own popover-like dialog
$('.has-popover').popover('hide')
Trick here is toString
method will be called each time default value will try to convert to string. And exactly this happens when this default value being put down to inputs.
来源:https://stackoverflow.com/questions/19761733/ckeditor-4-how-to-add-table-without-user-interaction-i-e-without-dialog