forked from extern/the-glorious-startpage
Use insertAdjacentHTML instead of createElement (#21)
* web menu * weather-screen forecast * search engine selection, change some to beforeend
This commit is contained in:
parent
84727755db
commit
7c8ece1d5e
@ -44,9 +44,14 @@ class SearchEngineSettings {
|
|||||||
const seValue = key;
|
const seValue = key;
|
||||||
const seData = this._searchEngines[key];
|
const seData = this._searchEngines[key];
|
||||||
const seOption = document.createElement('option');
|
const seOption = document.createElement('option');
|
||||||
seOption.value = seValue;
|
|
||||||
seOption.innerText = seData.name;
|
// Generate search engine suggestions
|
||||||
this._selectSearchEngine.appendChild(seOption);
|
this._selectSearchEngine.insertAdjacentHTML(
|
||||||
|
'beforeend',
|
||||||
|
`
|
||||||
|
<option value='${seValue}'>${seData.name}</option>
|
||||||
|
`
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Call to update query string and placeholder
|
// Call to update query string and placeholder
|
||||||
|
@ -80,62 +80,24 @@ class WeatherScreen {
|
|||||||
|
|
||||||
_createForecastBody = (fIcon, forecastTemp, foreDescription, fHour, fDate) => {
|
_createForecastBody = (fIcon, forecastTemp, foreDescription, fHour, fDate) => {
|
||||||
|
|
||||||
// Main Div
|
// Generate forecast
|
||||||
const forecastDay = document.createElement('div');
|
this._forecastContainer.insertAdjacentHTML(
|
||||||
forecastDay.className = 'weatherForecastDay';
|
'beforeend',
|
||||||
|
`
|
||||||
// Icon Container Div
|
<div class='weatherForecastDay'>
|
||||||
const forecastIconContainer = document.createElement('div');
|
<div class='weatherForecastDayIconContainer'>
|
||||||
forecastIconContainer.className = 'weatherForecastDayIconContainer';
|
<div class='weatherForecastDayIcon' style='background: url("assets/weather-icons/${fIcon}"); background-size: cover;'></div>
|
||||||
|
</div>
|
||||||
// Icon Div
|
<div class='weatherForecastDayDetails'>
|
||||||
const forecastIcon = document.createElement('div');
|
<div class='weatherForecastDayDetailsTemperature'>${forecastTemp}</div>
|
||||||
forecastIcon.className = 'weatherForecastDayIcon';
|
<div class='weatherForecastDayDetailsDescription'>${foreDescription}</div>
|
||||||
forecastIcon.style.background = `url('assets/weather-icons/${fIcon}')`;
|
</div><div class='weatherForecastDayDate'>
|
||||||
forecastIcon.style.backgroundSize = 'cover';
|
<div class='weatherForecastDayDateHour'>${fHour}</div>
|
||||||
|
<div class='weatherForecastDayDateDate'>${fDate}</div>
|
||||||
// Details Div
|
</div>
|
||||||
const forecastDetails = document.createElement('div');
|
</div>
|
||||||
forecastDetails.className = 'weatherForecastDayDetails';
|
`
|
||||||
|
)
|
||||||
const forecastTemperature = document.createElement('div');
|
|
||||||
forecastTemperature.className = 'weatherForecastDayDetailsTemperature';
|
|
||||||
forecastTemperature.innerHTML = forecastTemp;
|
|
||||||
|
|
||||||
const forecastDescription = document.createElement('div');
|
|
||||||
forecastDescription.className = 'weatherForecastDayDetailsDescription';
|
|
||||||
forecastDescription.innerHTML = foreDescription;
|
|
||||||
|
|
||||||
// Append details to div container
|
|
||||||
forecastDetails.appendChild(forecastTemperature);
|
|
||||||
forecastDetails.appendChild(forecastDescription);
|
|
||||||
|
|
||||||
// Date Div
|
|
||||||
const forecastDayDate = document.createElement('div');
|
|
||||||
forecastDayDate.className = 'weatherForecastDayDate';
|
|
||||||
|
|
||||||
const forecastHour = document.createElement('div');
|
|
||||||
forecastHour.className = 'weatherForecastDayDateHour';
|
|
||||||
forecastHour.innerHTML = fHour;
|
|
||||||
|
|
||||||
const forecastDate = document.createElement('div');
|
|
||||||
forecastDate.className = 'weatherForecastDayDateDate';
|
|
||||||
forecastDate.innerHTML = fDate;
|
|
||||||
|
|
||||||
// Append icon image to div container
|
|
||||||
forecastIconContainer.appendChild(forecastIcon);
|
|
||||||
|
|
||||||
// Append details to div container
|
|
||||||
forecastDayDate.appendChild(forecastHour);
|
|
||||||
forecastDayDate.appendChild(forecastDate);
|
|
||||||
|
|
||||||
// Append to main div
|
|
||||||
forecastDay.appendChild(forecastIconContainer);
|
|
||||||
forecastDay.appendChild(forecastDetails);
|
|
||||||
forecastDay.appendChild(forecastDayDate);
|
|
||||||
|
|
||||||
// Append to the main container
|
|
||||||
this._forecastContainer.appendChild(forecastDay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,53 +72,28 @@ class WebMenu {
|
|||||||
|
|
||||||
const li = document.createElement('li');
|
const li = document.createElement('li');
|
||||||
|
|
||||||
|
// Generate web item/li child
|
||||||
|
li.insertAdjacentHTML(
|
||||||
|
'afterbegin',
|
||||||
|
`
|
||||||
|
<a class='webMenuLink' href='${url}' tabindex='-1'>
|
||||||
|
<div class='webItem' id='${'id' + site}'>
|
||||||
|
<div class='webItemContainer'>
|
||||||
|
<div class='webItemBody'>
|
||||||
|
<div class='webItemIconContainer'>
|
||||||
|
<div class='webItemIcon' style='background: url("assets/webcons/${icon}.svg"); background-size: cover;'></div>
|
||||||
|
</div>
|
||||||
|
<div class='webItemName'>${site}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
`
|
||||||
|
)
|
||||||
|
|
||||||
// Create callback property
|
// Create callback property
|
||||||
this._createWebItemCallback(li, url);
|
this._createWebItemCallback(li, url);
|
||||||
|
|
||||||
// Create a href
|
|
||||||
const aWebLink = document.createElement('a');
|
|
||||||
aWebLink.className = 'webMenuLink';
|
|
||||||
aWebLink.href = url;
|
|
||||||
aWebLink.tabIndex = '-1';
|
|
||||||
|
|
||||||
// Create an outer div, child of li
|
|
||||||
let webItemDiv = document.createElement('div')
|
|
||||||
webItemDiv.className = 'webItem';
|
|
||||||
webItemDiv.id = 'id' + site;
|
|
||||||
|
|
||||||
// Create a second div, webItemContainer
|
|
||||||
const webItemContainer = document.createElement('div');
|
|
||||||
webItemContainer.className = 'webItemContainer';
|
|
||||||
|
|
||||||
// Create the innermost div, contains icon and label
|
|
||||||
const webItemBody = document.createElement('div');
|
|
||||||
webItemBody.className = 'webItemBody';
|
|
||||||
|
|
||||||
// Create div for webItemIcon
|
|
||||||
const webItemIconContainer = document.createElement('div');
|
|
||||||
webItemIconContainer.className = 'webItemIconContainer';
|
|
||||||
|
|
||||||
const webItemIcon = document.createElement('div');
|
|
||||||
webItemIcon.className = 'webItemIcon';
|
|
||||||
webItemIcon.style.background = `url('assets/webcons/${icon}.svg')`;
|
|
||||||
webItemIcon.style.backgroundSize = 'cover';
|
|
||||||
|
|
||||||
// Create webItemName
|
|
||||||
const webItemName = document.createElement('div');
|
|
||||||
webItemName.className = 'webItemName';
|
|
||||||
webItemName.innerHTML = site;
|
|
||||||
|
|
||||||
// Append divs with heirarchy
|
|
||||||
webItemDiv.appendChild(webItemContainer);
|
|
||||||
webItemContainer.appendChild(webItemBody);
|
|
||||||
|
|
||||||
webItemIconContainer.appendChild(webItemIcon);
|
|
||||||
webItemBody.appendChild(webItemIconContainer);
|
|
||||||
webItemBody.appendChild(webItemName);
|
|
||||||
|
|
||||||
aWebLink.appendChild(webItemDiv);
|
|
||||||
|
|
||||||
li.appendChild(aWebLink);
|
|
||||||
this._webMenuList.appendChild(li);
|
this._webMenuList.appendChild(li);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user