Template:HSNU-TAIPEI/members js

var generateHeading2 = function(headingContent) { var h2 = document.createElement('h2'); var content = document.createTextNode(headingContent); h2.appendChild(content); return h2; };

var generatePersonName = function(personName) {

return "
" + personName + "
";

};

var generatePersonRole = function(personRole) {

return "
" + personRole + "
";

};

var justifyPersonName = function(personName) { var length = personName.length; var justifiedName = ""; for(var i = 0; i < length; i++) { if(personName[i] !== ' ' && personName[i] !== '-') { justifiedName += personName[i]; } } return justifiedName; };

var generatePersonImg = function(personName) { var justifiedName = justifyPersonName(personName); var source = "../image/members/HSNU-TAIPEI_" + justifiedName + ".jpg"; return '<img src="' + source + '">'; };

var generatePersonFigure = function(personName, personRole) { var figure = "<figure>"; figure += generatePersonName(personName); figure += generatePersonRole(personRole); figure += "</figure>"; return figure; };

var generateProfile = function(person) { var personName = person["Name"], personRole = person["Role"]; var profile = document.createElement('div'); var content = generatePersonImg(personName); content += generatePersonFigure(personName, personRole); profile.setAttribute('class', 'profile'); profile.innerHTML = content; return profile; };

var generatePersonSection = function(sectionData) { var section = document.createElement('div'); var br = document.createElement('br'); var heading2 = generateHeading2(sectionData["sectionName"]); var length = sectionData["persons"].length; section.setAttribute('class', 'section members'); section.appendChild(heading2); for(var i = 0; i < length; i++) { var person = sectionData["persons"][i]; var profile = generateProfile(person); section.appendChild(profile); } section.appendChild(br); return section; };

var addSection = function(sectionData) { var mainContent = document.getElementsByClassName('mc-container')[0]; var newSection = generatePersonSection(sectionData); mainContent.appendChild(newSection); };


// ------------- Data --------------- //

var section_teacher = { sectionName: "Teacher", persons: [ { Name:"Su Shu-Ching", Role:"Teacher" }, { Name:"Wu Tzu-Yun", Role:"Teacher" } ] };

var section_experiment = { sectionName: "Experiment", persons: [ { Name:"Chang Ko-Yu", Role:"Student" }, { Name:"Lin Sheng", Role:"Student" }, { Name:"Shen Yu-Chun", Role:"Student" }, { Name:"Chu Yi-Chia", Role:"Student" }, { Name:"Zhao Ming-Cheng", Role:"Student" } ] };

var section_human_practice = { sectionName: "Human Practice", persons: [ ] };

var section_modeling = { sectionName: "Modeling", persons: [ ] };

var section_wiki = { sectionName: "Wiki", persons: [ { Name:"Hung Chi-Heng", Role:"Student" }, { Name:"Wang Yen-Jen", Role:"Student" }, { Name:"Shi Cheng-Yu", Role:"Student" }, { Name:"Yu Hsiu-Ting", Role:"Student" } ] };


addSection(section_teacher); addSection(section_experiment); addSection(section_wiki);