Textangular:向工具栏添加下拉列表

时间:2015-11-10 13:29:30

标签: javascript angularjs textangular

我正在使用Textangular 1.4.6和Angular 1.4.7。我需要在工具栏中添加一个下拉菜单,所以我写了这段代码:

$provide.decorator('taOptions', [
            'taRegisterTool',
            '$delegate',
            function (taRegisterTool, taOptions) {
                // $delegate is the taOptions we are decorating
                // register the tool with textAngular
                taRegisterTool('parameterscombo', {
                    display: '<button class="btn" type="button" data-animation="am-fade" bs-dropdown="content" aria-haspopup="true" aria-expanded="false">Select parameter</button>',
                    content: [
                        {
                            text: 1,
                            click: 'action(item)'
                        },
                        {
                            text: 2,
                            click: 'action(item)'
                        },
                        {
                            text: 3,
                            click: 'action(item)'
                        },
                        {
                            text: 4,
                            click: 'action(item)'
                        }
                    ],
                    action: function (item) {
                        if (item.text) {
                            this.$editor().wrapSelection('insertHtml', item.text + '***');
                        }
                    }
                });
                // add the button to the default toolbar definition
                taOptions.toolbar[1].push('parameterscombo');
                return taOptions;
            }
        ]);

显示下拉列表,我可以选择一个值并将其插入到textarea中。问题是我第一次选择一个值时,它被插入到正确的位置(光标所在的位置),但第二次,它总是将值放在文本的开头。

这是一个傻瓜:http://plnkr.co/edit/UZQk3jQ5xEpMJdNLonBO?p=preview

0 个答案:

没有答案
相关问题