File: get_block.js

package info (click to toggle)
pageedit 2.4.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,956 kB
  • sloc: ansic: 31,806; cpp: 15,036; python: 1,141; javascript: 87; sh: 13; makefile: 7
file content (20 lines) | stat: -rw-r--r-- 702 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var block_elements = ["address", "blockquote", "del", "div", "dl", "fieldset", "form", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "ins", "noscript", "ol", "p", "pre", "script", "table", "ul"];

// Obviously this assumes that the input is well-formed and there *is* a block node somewhere up the hierarchy
function get_block( node ) {
    var found = false;
    while( found == false && node != null ) {
        var i = 0;
        while( node.nodeName != block_elements[i] && i < block_elements.length ) {
            i++;
        }
        if( i == block_elements.length ) {
            node = node.parentNode;
        }
        else {
            found = true;
        }
    }
    
    return node;
};