Created
March 8, 2019 18:53
-
-
Save diogosouza/e01554e8a71b1f04431be98a522f5d86 to your computer and use it in GitHub Desktop.
Note structure in JavaScript as a official Google Closure Compiler sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2009 Google Inc. All Rights Reserved. | |
/** | |
* Creates the DOM structure for the note and adds it to the document. | |
*/ | |
function makeNoteDom(noteTitle, noteContent, noteContainer) { | |
// Create DOM structure to represent the note. | |
var headerElement = document.createElement('div'); | |
var headerText = document.createTextNode(noteTitle); | |
headerElement.appendChild(headerText); | |
var contentElement = document.createElement('div'); | |
var contentText = document.createTextNode(noteContent); | |
contentElement.appendChild(contentText); | |
var newNote = document.createElement('div'); | |
newNote.appendChild(headerElement); | |
newNote.appendChild(contentElement); | |
// Add the note's DOM structure to the document. | |
noteContainer.appendChild(newNote); | |
} | |
/** | |
* Iterates over a list of note data objects and creates a DOM | |
*/ | |
function makeNotes(data, noteContainer) { | |
for (var i = 0; i < data.length; i++) { | |
makeNoteDom(data[i].title, data[i].content, noteContainer); | |
} | |
} | |
function main() { | |
var noteData = [ | |
{title: 'Note 1', content: 'Content of Note 1'}, | |
{title: 'Note 2', content: 'Content of Note 2'}]; | |
var noteListElement = document.getElementById('notes'); | |
makeNotes(noteData, noteListElement); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment