├── .gitignore ├── img └── cover.png ├── .editorconfig ├── README.md ├── css ├── style.css └── prism.css ├── js ├── app.js ├── prism.js └── prism-highlight.js └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /img/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/willianjusten/dumb-codepen/HEAD/img/cover.png -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Simple Live Editor - [DEMO](https://willianjusten.com.br/dumb-codepen/) 2 | 3 |  4 | 5 | > A simple live editor with very few lines of code. Created to study purposes. 6 | -------------------------------------------------------------------------------- /css/style.css: -------------------------------------------------------------------------------- 1 | * { 2 | margin: 0; 3 | padding: 0; 4 | box-sizing: border-box; 5 | } 6 | 7 | iframe { 8 | width: 100%; 9 | height: 50vh; 10 | border: none; 11 | } 12 | 13 | 14 | .editor { 15 | display: flex; 16 | } 17 | 18 | .editor pre { 19 | background: #1E1F20; 20 | border: 1px solid rgb(211, 211, 211); 21 | color: rgb(211, 211, 211); 22 | flex: 1; 23 | font-size: 16px; 24 | height: 50vh; 25 | padding: 30px 10px; 26 | margin: 0; 27 | position: relative; 28 | } 29 | 30 | .editor pre:before { 31 | display: block; 32 | font-size: 12px; 33 | position: absolute; 34 | top: 10px; 35 | left: 10px; 36 | } 37 | 38 | #html:before { 39 | content: 'HTML'; 40 | } 41 | 42 | #css:before { 43 | content: 'CSS'; 44 | } 45 | 46 | #js:before { 47 | content: 'JS'; 48 | } 49 | -------------------------------------------------------------------------------- /js/app.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | /** 3 | * Components to our editor 4 | */ 5 | const htmlField = document.getElementById("html"); 6 | const cssField = document.getElementById("css"); 7 | const jsField = document.getElementById("js"); 8 | const preview = document.getElementById("preview"); 9 | 10 | /** 11 | * Method that gets the values from the textareas 12 | * and insert to an iframe 13 | */ 14 | function render() { 15 | let iframeComponent = preview.contentWindow.document; 16 | 17 | iframeComponent.open(); 18 | iframeComponent.writeln(` 19 | ${htmlField.innerText} 20 | 21 | `); 22 | iframeComponent.close(); 23 | } 24 | 25 | /** 26 | * Create listener to call the render 27 | * always after a keypress. 28 | */ 29 | function compile() { 30 | document.addEventListener('keyup', function() { 31 | render(); 32 | }); 33 | }; 34 | 35 | /** 36 | * Create the listener 37 | * and render the first values 38 | */ 39 | compile(); 40 | render(); 41 | })(); 42 | -------------------------------------------------------------------------------- /css/prism.css: -------------------------------------------------------------------------------- 1 | /* PrismJS 1.14.0 2 | http://prismjs.com/download.html#themes=prism-tomorrow&languages=markup+css+clike+javascript */ 3 | /** 4 | * prism.js tomorrow night eighties for JavaScript, CoffeeScript, CSS and HTML 5 | * Based on https://github.com/chriskempson/tomorrow-theme 6 | * @author Rose Pritchard 7 | */ 8 | 9 | code[class*="language-"], 10 | pre[class*="language-"], 11 | textarea { 12 | color: #ccc; 13 | background: none; 14 | font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; 15 | text-align: left; 16 | white-space: pre; 17 | word-spacing: normal; 18 | word-break: normal; 19 | word-wrap: normal; 20 | line-height: 1.5; 21 | 22 | -moz-tab-size: 4; 23 | -o-tab-size: 4; 24 | tab-size: 4; 25 | 26 | -webkit-hyphens: none; 27 | -moz-hyphens: none; 28 | -ms-hyphens: none; 29 | hyphens: none; 30 | 31 | } 32 | 33 | /* Code blocks */ 34 | pre[class*="language-"], 35 | textarea { 36 | padding: 1em; 37 | margin: .5em 0; 38 | overflow: auto; 39 | } 40 | 41 | :not(pre) > code[class*="language-"], 42 | pre[class*="language-"], 43 | textarea { 44 | background: #2d2d2d; 45 | } 46 | 47 | /* Inline code */ 48 | :not(pre) > code[class*="language-"] { 49 | padding: .1em; 50 | border-radius: .3em; 51 | white-space: normal; 52 | } 53 | 54 | .token.comment, 55 | .token.block-comment, 56 | .token.prolog, 57 | .token.doctype, 58 | .token.cdata { 59 | color: #999; 60 | } 61 | 62 | .token.punctuation { 63 | color: #ccc; 64 | } 65 | 66 | .token.tag, 67 | .token.attr-name, 68 | .token.namespace, 69 | .token.deleted { 70 | color: #e2777a; 71 | } 72 | 73 | .token.function-name { 74 | color: #6196cc; 75 | } 76 | 77 | .token.boolean, 78 | .token.number, 79 | .token.function { 80 | color: #f08d49; 81 | } 82 | 83 | .token.property, 84 | .token.class-name, 85 | .token.constant, 86 | .token.symbol { 87 | color: #f8c555; 88 | } 89 | 90 | .token.selector, 91 | .token.important, 92 | .token.atrule, 93 | .token.keyword, 94 | .token.builtin { 95 | color: #cc99cd; 96 | } 97 | 98 | .token.string, 99 | .token.char, 100 | .token.attr-value, 101 | .token.regex, 102 | .token.variable { 103 | color: #7ec699; 104 | } 105 | 106 | .token.operator, 107 | .token.entity, 108 | .token.url { 109 | color: #67cdcc; 110 | } 111 | 112 | .token.important, 113 | .token.bold { 114 | font-weight: bold; 115 | } 116 | .token.italic { 117 | font-style: italic; 118 | } 119 | 120 | .token.entity { 121 | cursor: help; 122 | } 123 | 124 | .token.inserted { 125 | color: green; 126 | } 127 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 |