English 中文(简体)
引文突出。
原标题:loop through highlighted text.
  • 时间:2012-05-14 06:32:44
  •  标签:
  • javascript

I have a question on a javascript i need to loop through user selection(highlighted text) and change the text direction from trl or ltr . here what i did :

this._execCom("FormatBlock", <div> );
var node = null;
if (this.area.contentWindow.getSelection) {
    node = this.area.contentWindow.getSelection().anchorNode.parentNode;

}
else if (this.area.contentWindow.document.selection) {
    var range = this.area.contentWindow.document.selection.createRange();
    if (range) {
        node = range.parentElement();
    }
    var walker=this.area.contentWindow.document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT, null, false);
    while (walker.nextNode())
    {
        x=walker.currentNode.tagName;
        if( x ==  DIV )
            walker.currentNode.style.direction="ltr";
    }

这就改变了所有四舍五入者的方向,即使这些四舍五入到突出案文中,而且我只需要改动用户选择。

请帮助我。

很多人

问题回答

Edit: I misunderstood your question. So you just want the user to be able to click and drag to select which elements should have the direction toggled between ltr and rtl. I have an alternative to using selection ranges, which will be quite painful to use in this solution.

在这里,我利用“ j”来聆听摩擦事件,检查左 mo子是否被压抑。 如果是的话,我要谈谈方向。 我也使用一个习俗数据旗来防止在你拖拉时 elements弄这些元素。

There is also a bit in there to prevent the paragraphs from being selected, which may have been your intention but I found annoying. You can just comment out/remove that part if you want them to be able to select the text.

http://jsfiddle.net/nbWYK/8/“rel=“nofollow” http://jsfiddle.net/nbWYK/8/。

TL;DNR:

$(document).on("mousemove",  p , function(e) {
    var $this = $(this);

    if ($this.data( ignore-direction-toggle )) return;

    if (e.which == 1) {
        $this.data( ignore-direction-toggle , true);
        $this.css({
             direction : ($this.css( direction ) ==  ltr  ?  rtl  :  ltr )
        });
    }
}).on( mouseleave ,  p , function(e) {
    var $this = $(this);
    if ($this.data( ignore-direction-toggle )) $this.data( ignore-direction-toggle , null);
});




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签