import { IgniteTemplate } from "../ignite-html/ignite-template.js";
/**
* Generates a series of years from the starting to the ending point.
* @param {Number} from Starting year.
* @param {Number} to Ending year.
* @param {String} placeholder The placeholder option, it's value will be 0, if set this text will be shown.
* @param {Boolean} descending Whether or not the to year is first and the from year is last.
* @returns {IgniteTemplate} This ignite template.
*
* @example
* .years(1950, 2021, true) //Generates a select descending, 2021, 2020, 2019.. ect.
*/
IgniteTemplate.prototype.years = function(from, to, placeholder = null, descending = false) {
//Generate html and populate the template with it.
var html = '';
//If to is 0, null, or undefined, use the current year.
if (to == 0 || !to) {
to = new Date().getFullYear();
}
//If from is negative, adjust it with the to year.
if (from < 0) {
from += to;
}
if (placeholder) {
html += ``;
}
if (descending) {
for (var i = to; i >= from; i--) {
html += ``;
}
} else {
for (var i = from; i <= to; i++) {
html += ``;
}
}
return this.innerHTML(html);
};
/**
* Generates a series of months.
* @param {String} placeholder The placeholder option, it's value will be 0, if set this text will be shown.
* @param {Boolean} shorthand If true the option text will be the shorthand version of the month.
* @returns {IgniteTemplate} This ignite template.
*/
IgniteTemplate.prototype.months = function(placeholder = null, shorthand = true) {
//Generate html and populate the template with it.
var html = '';
if (placeholder) {
html += ``;
}
if (shorthand) {
html += `
`;
} else {
html += `
`;
}
return this.innerHTML(html);
}
/**
* Generates a series of days.
* @param {Number} from The starting day.
* @param {Number} to The ending day.
* @param {String} placeholder The placeholder option if set, it's value will be 0, this will be the text displayed.
* @param {Boolean} descending Whether or not the to day is first and the from year is last.
* @returns {IgniteTemplate} This ignite template.
*/
IgniteTemplate.prototype.days = function(from = 1, to = 31, placeholder = null, descending = false) {
//Generate html and populate the template with it.
var html = '';
if (placeholder) {
html += ``;
}
if (descending) {
for (var i = to; i >= from; i--) {
html += ``;
}
} else {
for (var i = from; i <= to; i++) {
html += ``;
}
}
return this.innerHTML(html);
}
/**
* Generates a list of US States.
* @param {String} placeholder If set, outputs a placeholder option with a value of 0.
* @param {Boolean} shorthand If true, outputs the states in the two letter form.
* @returns {IgniteTemplate} This ignite template
*/
IgniteTemplate.prototype.states = function(placeholder = null, shorthand = true) {
//Generate html and populate the template with it.
var html = '';
if (placeholder) {
html += ``;
}
if (shorthand) {
html += `
`;
} else {
html += `
`;
}
return this.innerHTML(html);
}
/**
* Generates a list of countries.
* @param {String} placeholder If set, outputs a placeholder option with a value of 0.
* @returns {IgniteTemplate} This ignite template
*/
IgniteTemplate.prototype.countries = function(placeholder = null) {
//Generate html and populate the template with it.
var html = '';
if (placeholder) {
html += ``;
}
html += `
`;
return this.innerHTML(html);
}
/**
* Generates a series of numbers.
* @param {Number} from The starting number.
* @param {Number} to The ending number.
* @param {String} placeholder The placeholder option if set, it's value will be -1, this will be the text displayed.
* @param {Number} placeholderValue The value of the placeholder option if the placeholder is set. Default is -1.
* @param {Boolean} descending Whether or not the from number if first and the to number is last.
* @returns {IgniteTemplate} This ignite template.
*/
IgniteTemplate.prototype.numbers = function(from = 0, to = 100, placeholder = null, placeholderValue = -1, descending = false) {
//Generate html and populate the template with it.
var html = '';
if (placeholder) {
html += ``;
}
if (descending) {
for (var i = to; i >= from; i--) {
html += ``;
}
} else {
for (var i = from; i <= to; i++) {
html += ``;
}
}
return this.innerHTML(html);
}