summaryrefslogtreecommitdiffstats
path: root/toolkit/components/microformats/test/static/javascript/count.js
blob: 56a64c05ea924c7010e87011cb97abebfbc7d94b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*!
    parse
    Used by http://localhost:3000/
    Copyright (C) 2010 - 2015 Glenn Jones. All Rights Reserved.
    MIT License: https://raw.github.com/glennjones/microformat-shiv/master/license.txt
*/

window.onload = function() {

    var form;
    form= document.getElementById('mf-form');

    form.onsubmit = function(e){
        e.preventDefault();

        var html,
            doc,
            node,
            options,
            mfJSON,
            parserJSONElt;

        // get data from html
        html = document.getElementById('html').value;
        parserJSONElt = document.querySelector('#parser-json pre code')

        // createHTMLDocument is not well support below ie9
        doc = document.implementation.createHTMLDocument("New Document");
        node =  document.createElement('div');
        node.innerHTML = html;
        doc.body.appendChild(node);

        options ={
            'node': node
        };

        // parse direct into Modules to help debugging
        if(window.Modules){
            var parser = new Modules.Parser();
            mfJSON = parser.count(options);
        }else if(window.Microformats){
            mfJSON = Microformats.count(options);
        }


        // format output
        parserJSONElt.innerHTML = htmlEscape( js_beautify( JSON.stringify(mfJSON) ) );
        //prettyPrint();

    }

    function htmlEscape(str) {
        return String(str)
                .replace(/&/g, '&')
                .replace(/"/g, '"')
                .replace(/'/g, ''')
                .replace(/</g, '&lt;')
                .replace(/>/g, '&gt;');
    }


};