1

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 ?

4

1 回答 1

0

通过实际破解默认值以使其具有 getter 功能来解决问题,并在显示对话框后单击确定按钮:

(警告,咖啡)

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')

这里的技巧是toString每次默认值尝试转换为字符串时都会调用方法。当这个默认值被放入输入时,就会发生这种情况。

于 2013-11-04T05:59:15.847 回答