Project

General

Profile

1
function syntaxHighlight(json) {
2
        if (typeof json != 'string') {
3
            json = JSON.stringify(json, undefined, 4);
4
        }
5
        json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
6
        return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
7

    
8
            var cls = 'number';
9
            if (/^"/.test(match)) {
10
                if (/:$/.test(match)) {
11
                    if (match=='"doi":'){
12
                        cls="key doi"
13
                    } else {
14
                        cls = 'key';
15
                    }
16
                } else {
17
                    cls = 'string';
18
                }
19
            } else if (/true|false/.test(match)) {
20
                cls = 'boolean';
21
            } else if (/null/.test(match)) {
22
                cls = 'null';
23
            }
24

    
25
            return '<span class="' + cls + '">' + match + '</span>';
26

    
27
        });
28
    }
29

    
30
function addExample(example,input) {
31
        input.val(example)
32
        input.addClass("green-border").delay(500).queue(function(next){
33
            $(this).removeClass("green-border");
34
            next();
35
        })
36
    }
37

    
38

    
39

    
40
function restService(type,url,data,elem){
41

    
42
    return $.ajax({
43
        url: url,
44
        type: type,
45
        crossDomain: true,
46
        data: JSON.stringify(data),
47
        contentType: "application/json",
48
        dataType: "text",
49
//        success: function (response) {
50
//            respe = response
51
//            console.log(response)
52
//            elem.html(syntaxHighlight(JSON.stringify(JSON.parse(response),null,4)) )
53
//            addLinkToDoi()
54
//            return respe
55
//        },
56
//        error: function (xhr, status) {
57
//            console.log("error");
58
//        }
59
    });
60

    
61
}
62

    
63
function addLinkToDoiNext() {
64
    $(".doi").next().each(function(){
65
        var text = $(this).text()
66
        $(this).html('<a href=http://dx.doi.org/'+text.replace(/"/g,'')+' target=_blank>'+text+'</a>')
67
    })
68
}     function addLinkToDoi() {
69
    $(".doi").each(function(){
70
        var text = $(this).text()
71
        $(this).html('<a href=http://dx.doi.org/'+text.replace(/"/g,'')+' target=_blank>'+text+'</a>')
72
    })
73
}
74

    
(1-1/2)