@flourish/footer
Advanced tools
Comparing version 0.1.6 to 1.0.0-alpha
102
footer.js
@@ -7,3 +7,2 @@ (function (global, factory) { | ||
var footer_el; | ||
var source_el; | ||
@@ -14,31 +13,33 @@ var note_el; | ||
var FOOTER_DEFAULTS = { | ||
footer_source_label_other: false, | ||
footer_source_label: "Source: ", | ||
footer_source_name: "", | ||
footer_source_url: "", | ||
footer_source_name_2: "", | ||
footer_source_url_2: "", | ||
footer_source_name_3: "", | ||
footer_source_url_3: "", | ||
footer_note: "", | ||
footer_size: "12", | ||
footer_color: "#aaaaaa", | ||
footer_align: "left", | ||
footer_margin: "10", | ||
footer_margin_advanced: false, | ||
footer_margin_top: 10, | ||
footer_margin_right: 10, | ||
footer_margin_bottom: 0, | ||
footer_margin_left: 10 | ||
var DEFAULTS = { | ||
source_label: "Source: ", | ||
source_name: "", | ||
source_url: "", | ||
source_name_2: "", | ||
source_url_2: "", | ||
source_name_3: "", | ||
source_url_3: "", | ||
note: "", | ||
size: "12", | ||
color: "#aaaaaa", | ||
align: "left", | ||
margin: "10", | ||
margin_advanced: false, | ||
margin_top: 10, | ||
margin_right: 10, | ||
margin_bottom: 0, | ||
margin_left: 10 | ||
}; | ||
function createFooter(el, project_state) { | ||
state = project_state; | ||
appendState(); | ||
function initFooter(obj, el) { | ||
state = obj; | ||
footer_el = document.createElement("div"); | ||
footer_el.className = "flourish-footer"; | ||
for (var key in DEFAULTS) { | ||
if (state[key] === undefined) state[key] = DEFAULTS[key]; | ||
} | ||
exports.footer_el = document.createElement("div"); | ||
exports.footer_el.className = "flourish-footer"; | ||
source_el = document.createElement("p"); | ||
@@ -50,9 +51,10 @@ source_el.className = "flourish-footer-source"; | ||
footer_el.appendChild(source_el); | ||
footer_el.appendChild(note_el); | ||
exports.footer_el.appendChild(source_el); | ||
exports.footer_el.appendChild(note_el); | ||
el.appendChild(footer_el); | ||
if (el) el.appendChild(exports.footer_el); | ||
appendStyles(); | ||
} | ||
function appendStyles() { | ||
@@ -62,18 +64,11 @@ var css = document.createElement("style"); | ||
css.innerHTML = ".flourish-footer { margin: 0; } .flourish-footer p { margin: 0; display: inline; } .flourish-footer p:empty { height: 0; } .flourish-footer a {color: inherit; } .flourish-footer .flourish-footer-note {margin-left: 3px; }"; | ||
document.body.appendChild(css); | ||
document.head.appendChild(css); | ||
} | ||
function appendState() { | ||
for (var key in FOOTER_DEFAULTS) { | ||
if (!state[key]) { | ||
state[key] = FOOTER_DEFAULTS[key]; | ||
} | ||
} | ||
} | ||
function updateFooter() { | ||
var sources = [ | ||
{ name: state.footer_source_name, url: state.footer_source_url }, | ||
{ name: state.footer_multiple_sources ? state.footer_source_name_2 : "", url: state.footer_multiple_sources ? state.footer_source_url_2 : "" }, | ||
{ name: state.footer_multiple_sources ? state.footer_source_name_3 : "", url: state.footer_multiple_sources ? state.footer_source_url_3 : "" } | ||
{ name: state.source_name, url: state.source_url }, | ||
{ name: state.multiple_sources ? state.source_name_2 : "", url: state.multiple_sources ? state.source_url_2 : "" }, | ||
{ name: state.multiple_sources ? state.source_name_3 : "", url: state.multiple_sources ? state.source_url_3 : "" } | ||
].filter(function(source) { | ||
@@ -83,9 +78,9 @@ return source.name || source.url; | ||
has_footer = sources.length > 0; | ||
has_footer = sources.length > 0 || state.note; | ||
footer_el.style.height = has_footer ? null : 0; | ||
footer_el.style.margin = updateFooterMargin(); | ||
footer_el.style.fontSize = state.footer_size + "px"; | ||
footer_el.style.textAlign = state.footer_align; | ||
footer_el.style.color = state.footer_color; | ||
exports.footer_el.style.height = has_footer ? null : 0; | ||
exports.footer_el.style.margin = updateFooterMargin(); | ||
exports.footer_el.style.fontSize = state.size + "px"; | ||
exports.footer_el.style.textAlign = state.align; | ||
exports.footer_el.style.color = state.color; | ||
@@ -110,4 +105,4 @@ var source_container = document.createElement("span"); | ||
source_el.innerHTML = source_container.innerHTML !== "" ? state.footer_source_label + " " + source_container.outerHTML : ""; | ||
note_el.innerHTML = state.footer_note ? (source_container.innerHTML !== "" ? "• " : "") + state.footer_note : ""; | ||
source_el.innerHTML = source_container.innerHTML !== "" ? state.source_label + " " + source_container.outerHTML : ""; | ||
note_el.innerHTML = state.note ? (source_container.innerHTML !== "" ? "• " : "") + state.note : ""; | ||
} | ||
@@ -117,10 +112,10 @@ | ||
if (!has_footer) return 0; | ||
else if (state.footer_margin_advanced) { | ||
return state.footer_margin_top + "px " + state.footer_margin_right + "px " + state.footer_margin_bottom + "px " + state.footer_margin_left + "px"; | ||
else if (state.margin_advanced) { | ||
return state.margin_top + "px " + state.margin_right + "px " + state.margin_bottom + "px " + state.margin_left + "px"; | ||
} | ||
else return state.footer_margin + "px " + state.footer_margin + "px " + "0 " + state.footer_margin + "px"; | ||
else return state.margin + "px " + state.margin + "px " + "0 " + state.margin + "px"; | ||
} | ||
function getFooterHeight() { | ||
return footer_el.getBoundingClientRect().height + getFooterMarginHeight(); | ||
return exports.footer_el.getBoundingClientRect().height + getFooterMarginHeight(); | ||
} | ||
@@ -130,3 +125,3 @@ | ||
if (!has_footer) return 0; | ||
return state.footer_margin_advanced ? state.footer_margin_top + state.footer_margin_bottom : +state.footer_margin; | ||
return state.margin_advanced ? state.margin_top + state.margin_bottom : +state.margin; | ||
} | ||
@@ -139,6 +134,5 @@ | ||
exports.createFooter = createFooter; | ||
exports.initFooter = initFooter; | ||
exports.updateFooter = updateFooter; | ||
exports.getFooterHeight = getFooterHeight; | ||
exports.FOOTER_DEFAULTS = FOOTER_DEFAULTS; | ||
@@ -145,0 +139,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
{ | ||
"name": "@flourish/footer", | ||
"version": "0.1.6", | ||
"version": "1.0.0-alpha", | ||
"description": "Add footer", | ||
@@ -5,0 +5,0 @@ "main": "footer.js", |
@@ -13,3 +13,3 @@ # Flourish footer | ||
`createFooter(target_el, state)` appends a div in the target element, and adds footer state properties | ||
`initFooter(obj[, target_el])` creates a footer element (appended to `target_el` if provided) and adds missing footer properties to `obj` | ||
@@ -19,1 +19,5 @@ `updateFooter()` updates the footer contents and styles | ||
`getFooterHeight()` returns the total footer height (including margins) | ||
`footer_el` is the footer node element | ||
Also, settings.yml file can be imported into your template's template.yml file. |
@@ -5,28 +5,30 @@ var footer_el, source_el, note_el; | ||
var FOOTER_DEFAULTS = { | ||
footer_source_label_other: false, | ||
footer_source_label: "Source: ", | ||
footer_source_name: "", | ||
footer_source_url: "", | ||
footer_source_name_2: "", | ||
footer_source_url_2: "", | ||
footer_source_name_3: "", | ||
footer_source_url_3: "", | ||
footer_note: "", | ||
footer_size: "12", | ||
footer_color: "#aaaaaa", | ||
footer_align: "left", | ||
footer_margin: "10", | ||
footer_margin_advanced: false, | ||
footer_margin_top: 10, | ||
footer_margin_right: 10, | ||
footer_margin_bottom: 0, | ||
footer_margin_left: 10 | ||
var DEFAULTS = { | ||
source_label: "Source: ", | ||
source_name: "", | ||
source_url: "", | ||
source_name_2: "", | ||
source_url_2: "", | ||
source_name_3: "", | ||
source_url_3: "", | ||
note: "", | ||
size: "12", | ||
color: "#aaaaaa", | ||
align: "left", | ||
margin: "10", | ||
margin_advanced: false, | ||
margin_top: 10, | ||
margin_right: 10, | ||
margin_bottom: 0, | ||
margin_left: 10 | ||
}; | ||
function createFooter(el, project_state) { | ||
state = project_state; | ||
appendState(); | ||
function initFooter(obj, el) { | ||
state = obj; | ||
for (var key in DEFAULTS) { | ||
if (state[key] === undefined) state[key] = DEFAULTS[key]; | ||
} | ||
footer_el = document.createElement("div"); | ||
@@ -44,6 +46,7 @@ footer_el.className = "flourish-footer"; | ||
el.appendChild(footer_el); | ||
if (el) el.appendChild(footer_el); | ||
appendStyles(); | ||
} | ||
function appendStyles() { | ||
@@ -53,18 +56,11 @@ var css = document.createElement("style"); | ||
css.innerHTML = ".flourish-footer { margin: 0; } .flourish-footer p { margin: 0; display: inline; } .flourish-footer p:empty { height: 0; } .flourish-footer a {color: inherit; } .flourish-footer .flourish-footer-note {margin-left: 3px; }"; | ||
document.body.appendChild(css); | ||
document.head.appendChild(css); | ||
} | ||
function appendState() { | ||
for (var key in FOOTER_DEFAULTS) { | ||
if (!state[key]) { | ||
state[key] = FOOTER_DEFAULTS[key]; | ||
} | ||
} | ||
} | ||
function updateFooter() { | ||
var sources = [ | ||
{ name: state.footer_source_name, url: state.footer_source_url }, | ||
{ name: state.footer_multiple_sources ? state.footer_source_name_2 : "", url: state.footer_multiple_sources ? state.footer_source_url_2 : "" }, | ||
{ name: state.footer_multiple_sources ? state.footer_source_name_3 : "", url: state.footer_multiple_sources ? state.footer_source_url_3 : "" } | ||
{ name: state.source_name, url: state.source_url }, | ||
{ name: state.multiple_sources ? state.source_name_2 : "", url: state.multiple_sources ? state.source_url_2 : "" }, | ||
{ name: state.multiple_sources ? state.source_name_3 : "", url: state.multiple_sources ? state.source_url_3 : "" } | ||
].filter(function(source) { | ||
@@ -74,9 +70,9 @@ return source.name || source.url; | ||
has_footer = sources.length > 0; | ||
has_footer = sources.length > 0 || state.note; | ||
footer_el.style.height = has_footer ? null : 0; | ||
footer_el.style.margin = updateFooterMargin(); | ||
footer_el.style.fontSize = state.footer_size + "px"; | ||
footer_el.style.textAlign = state.footer_align; | ||
footer_el.style.color = state.footer_color; | ||
footer_el.style.fontSize = state.size + "px"; | ||
footer_el.style.textAlign = state.align; | ||
footer_el.style.color = state.color; | ||
@@ -101,4 +97,4 @@ var source_container = document.createElement("span"); | ||
source_el.innerHTML = source_container.innerHTML !== "" ? state.footer_source_label + " " + source_container.outerHTML : ""; | ||
note_el.innerHTML = state.footer_note ? (source_container.innerHTML !== "" ? "• " : "") + state.footer_note : ""; | ||
source_el.innerHTML = source_container.innerHTML !== "" ? state.source_label + " " + source_container.outerHTML : ""; | ||
note_el.innerHTML = state.note ? (source_container.innerHTML !== "" ? "• " : "") + state.note : ""; | ||
} | ||
@@ -108,6 +104,6 @@ | ||
if (!has_footer) return 0; | ||
else if (state.footer_margin_advanced) { | ||
return state.footer_margin_top + "px " + state.footer_margin_right + "px " + state.footer_margin_bottom + "px " + state.footer_margin_left + "px"; | ||
else if (state.margin_advanced) { | ||
return state.margin_top + "px " + state.margin_right + "px " + state.margin_bottom + "px " + state.margin_left + "px"; | ||
} | ||
else return state.footer_margin + "px " + state.footer_margin + "px " + "0 " + state.footer_margin + "px"; | ||
else return state.margin + "px " + state.margin + "px " + "0 " + state.margin + "px"; | ||
} | ||
@@ -121,3 +117,3 @@ | ||
if (!has_footer) return 0; | ||
return state.footer_margin_advanced ? state.footer_margin_top + state.footer_margin_bottom : +state.footer_margin; | ||
return state.margin_advanced ? state.margin_top + state.margin_bottom : +state.margin; | ||
} | ||
@@ -130,2 +126,2 @@ | ||
export { createFooter, updateFooter, getFooterHeight, FOOTER_DEFAULTS }; | ||
export { initFooter, updateFooter, getFooterHeight, footer_el }; |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
8
21
10971
217
1