突出显示文本,然后将其发送到弹出窗口小部件javascript
我正试图在EmberJS中实现类似的目标 如您所见,在上图中,用户可以突出显示一些文本,当突出显示文本,然后将其发送到弹出窗口小部件javascript,javascript,ember.js,widget,highlight,Javascript,Ember.js,Widget,Highlight,我正试图在EmberJS中实现类似的目标 如您所见,在上图中,用户可以突出显示一些文本,当mouseup事件发生时,小部件会弹出一些图标。我希望通过显示突出显示文本的小部件实现同样的效果 到目前为止,我得到的是: export default Component.extend({ classNames: ['widgetText'], didDrag: false, startDragPosition: null, endDragPosition: null, getSe
mouseup
事件发生时,小部件会弹出一些图标。我希望通过显示突出显示文本的小部件实现同样的效果
到目前为止,我得到的是:
export default Component.extend({
classNames: ['widgetText'],
didDrag: false,
startDragPosition: null,
endDragPosition: null,
getSelected() {
if (window.getSelection) {
return window.getSelection().toString();
} else if (document.selection) {
return document.selection.createRange().text;
}
return '';
},
mouseUp(e) {
if (this.get('startDragPosition') && this.get('didDrag')) {
this.set('endDragPosition', { left: e.pageX, top: e.pageY });
const selection = this.getSelected();
console.log(selection); //I'm able to print my selection, I want this to be sent to a widget and position the widget...?
}
this.setProperties({ didDrag: false, startDragPosition: null, endDragPosition: null });
},
mouseMove() {
this.set('didDrag', true);
},
mouseDown(e) {
this.set('startDragPosition', { left: e.pageX, top: e.pageY });
},
我可以得到
isShowing():{
this.togglePropety('isShowingComponent');
}
{{#if isShowingComponent}}
{{social-buttons close="isShowing" text='the text you already can console.log'}}
{{/if}}
这将观察变量isShowingComponent
,因此您可以在中这样处理.hbs
{{#if isShowingComponent}}
{{social-buttons close="isShowing"}}
{{/if}}
剩下的唯一一件事就是像那样显示的样式,如果您想发送文本来处理它,您可以这样做:
isShowing():{
this.togglePropety('isShowingComponent');
}
{{#if isShowingComponent}}
{{social-buttons close="isShowing" text='the text you already can console.log'}}
{{/if}}
希望这对你有帮助