简体   繁体   English

如何从嵌套在对话框中的iframe中的ckeditor中获取所选元素

[英]How to get the selected element from ckeditor inside an iframe nested in the dialog box

I'm building a CKEditor 3 plugin that builds <dl> tables. 我正在构建一个构建<dl>表的CKEditor 3插件。 Using the iframedialog plugin, I created an IFrame inside the ckeditor dialog box that pops up. 使用iframedialog插件,我在弹出的ckeditor对话框中创建了一个IFrame。 I am able to create the <dl> tables with any number of <dt>/<dd> elements and edit them. 我可以用任意数量的<dt>/<dd>元素创建<dl>表并进行编辑。 However, this works for only one <dl> table, as when I have more than one, I am unable to find which one is selected, each have their own unique id. 但是,这仅适用于一个<dl>表,因为当我有多个表时,我无法找到所选的表,每个表都有自己的唯一ID。

I am able to access the selected <dl> table inside the plugin.js file. 我可以访问plugin.js文件中选定的<dl>表。 It is retrieved as follows, using a var declared 使用声明的var如下检索它

onShow: function () {
                var sel = editor.getSelection(),
                    element = sel.getStartElement();

                selectedDL = element.getAscendant('dl', true);
                if (selectedDL) {
                    alert(selectedAccordion.getAttribute('id'));
                }
            },

I cannot figure out how to get the id of the selected DT inside the dialog iframe however. 但是,我无法弄清楚如何在对话框iframe中获取所选DT的ID。 I based my plugin solution on the following link: 我的插件解决方案基于以下链接:

CKEditor 3.x - Dynamically add UI elements to plugin dialog CKEditor 3.x-将UI元素动态添加到插件对话框

My usual solution is to dynamically generate IDs via counter on page load and append them to the tag using DOM manipulation. 我通常的解决方案是在页面加载时通过计数器动态生成ID,然后使用DOM操作将其附加到标签中。 You can then push them to an array and either address them via array index or you can address them by unique ID by itself. 然后,您可以将它们推送到数组中,或者通过数组索引对其进行寻址,也可以通过唯一ID对其进行寻址。

var counter=1;
var dlarray = [];

$( "dl" ).each(function( index ) {
  var idname = "element" + counter.toString;
  $(this).attr('id', 'idname');
  dlarray.push(this);
  counter++;
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM