Issues (121)

src/js/components/live-preview.js (6 issues)

1
Mivhak.component('live-preview', {
0 ignored issues
show
The variable Mivhak seems to be never declared. If this is a global, consider adding a /** global: Mivhak */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2
    template: '<iframe class="mivhak-live-preview" allowtransparency="true" sandbox="allow-scripts allow-pointer-lock allow-same-origin allow-popups allow-modals allow-forms" frameborder="0"></iframe>',
3
    props: {
4
        resources: []
5
    },
6
    methods: {
7
        renderHTML: function() {
8
            var html = '<html>',
9
                head = '<head>',
10
                body = '<body>';
11
            
12
            head += '<meta http-equiv="content-type" content="text/html; charset=UTF-8">';
13
            head += '<meta name="robots" content="noindex, nofollow">';
14
            head += '<meta name="googlebot" content="noindex, nofollow">';
15
            
16
            for(var i = 0; i < this.resources.count(); i++)
17
            {
18
                var source = this.resources.get(i);
19
                if('markup' === source.runAs) body += source.content;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
20
                if('style' === source.runAs) head += this.createStyle(source.content, source.visible ? false : source.source);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
21
                if('script' === source.runAs) head += this.createScript(source.content, source.visible ? false : source.source);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
22
            }
23
            
24
            html += head+'</head>'+body+'</body></html>';
25
            
26
            return html;
27
        },
28
        createScript: function(content,src) {
29
            if(src) return '<script src="'+src+'" type="text/javascript"></script>';
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
30
            return '<script>\n//<![CDATA[\nwindow.onload = function(){'+content+'};//]]>\n</script>'; // @see http://stackoverflow.com/questions/66837/when-is-a-cdata-section-necessary-within-a-script-tag
31
        },
32
        createStyle: function(content,href) {
33
            if(href) return '<link href="'+href+'" rel="stylesheet">';
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
34
            return '<style>'+content+'</style>';
35
        },
36
        show: function() {
37
            this.$el.addClass('mivhak-active');
38
            this.run();
39
        },
40
        hide: function() {
41
            this.$el.removeClass('mivhak-active');
42
        },
43
        run: function() {
44
            var contents = this.$el.contents(),
45
                doc = contents[0];
46
        
47
            doc.open();
48
            doc.writeln(this.renderHTML());
49
            doc.close();
50
        }
51
    }
52
});