Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get text in CSS3 column?

I'm using CSS3's support for columns support in a project (so far I've found it much more robust and dependable than most JavaScript solutions out there).

Question: Is it possible to get the text that is in a specific column, in any way?

like image 407
mattsven Avatar asked Mar 18 '13 16:03

mattsven


2 Answers

And...what, two months later? I finally found the answer to this question. It's reliant on document.caretRangeFromPoint (Webkit) or document.caretPositionFromPoint.

var getAllTextInColumn = function(rect){
    /*
        rect should be the size and x,y of the column
        { top, left, width, height }
    */

    if(document.caretRangeFromPoint){
        var caretRangeStart = document.caretRangeFromPoint(rect.left, rect.top);
        var caretRangeEnd = document.caretRangeFromPoint(rect.left+rect.width-1, rect.top+rect.height-1);
    } else {
        return null;
    }

    if(caretRangeStart == null || caretRangeEnd == null) return null;

    var range = document.createRange();
    range.setStart(caretRangeStart.startContainer, caretRangeStart.startOffset);
    range.setEnd(caretRangeEnd.endContainer, caretRangeEnd.endOffset);

    return range.toString();
};
like image 71
mattsven Avatar answered Sep 18 '22 23:09

mattsven


My only guess is to start replacing spaces with a SPAN, then detecting when the vertical position of that SPAN gets smaller, then you know you're in the next column. This last SPAN becomes a column marker.

You can then copy the text that is between the beginning/end and/or a column maker.

like image 20
Diodeus - James MacFarlane Avatar answered Sep 21 '22 23:09

Diodeus - James MacFarlane