@flourish/footer
Advanced tools
Comparing version 1.0.0-alpha to 1.0.0-alpha2
166
footer.js
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.footer = global.footer || {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.footer = factory()); | ||
}(this, (function () { 'use strict'; | ||
var source_el; | ||
var note_el; | ||
var has_footer; | ||
var state; | ||
var styles_appended = false; | ||
@@ -32,6 +29,31 @@ var DEFAULTS = { | ||
function appendStyles() { | ||
var css = document.createElement("style"); | ||
css.type = "text/css"; | ||
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.head.appendChild(css); | ||
styles_appended = true; | ||
} | ||
function initFooter(obj, el) { | ||
state = obj; | ||
function updateFooterMargin(state) { | ||
if (state.margin_advanced) { | ||
return state.margin_top + "px " + state.margin_right + "px " + state.margin_bottom + "px " + state.margin_left + "px"; | ||
} | ||
else return state.margin + "px " + state.margin + "px " + "0 " + state.margin + "px"; | ||
} | ||
function getFooterMarginHeight(state) { | ||
return state.margin_advanced ? state.margin_top + state.margin_bottom : +state.margin; | ||
} | ||
function addHttp(url) { | ||
if (url.indexOf("http://") !== 0 && url.indexOf("https://") !== 0) return "http://" + url; | ||
else return url; | ||
} | ||
function init(state) { | ||
if (!styles_appended) appendStyles(); | ||
var has_footer = false; | ||
for (var key in DEFAULTS) { | ||
@@ -41,94 +63,68 @@ if (state[key] === undefined) state[key] = DEFAULTS[key]; | ||
exports.footer_el = document.createElement("div"); | ||
exports.footer_el.className = "flourish-footer"; | ||
var footer_el = document.createElement("div"); | ||
footer_el.className = "flourish-footer"; | ||
source_el = document.createElement("p"); | ||
var source_el = document.createElement("p"); | ||
source_el.className = "flourish-footer-source"; | ||
note_el = document.createElement("p"); | ||
var note_el = document.createElement("p"); | ||
note_el.className = "flourish-footer-note"; | ||
exports.footer_el.appendChild(source_el); | ||
exports.footer_el.appendChild(note_el); | ||
footer_el.appendChild(source_el); | ||
footer_el.appendChild(note_el); | ||
if (el) el.appendChild(exports.footer_el); | ||
appendStyles(); | ||
} | ||
var update = function() { | ||
var sources = [ | ||
{ 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) { | ||
return source.name || source.url; | ||
}); | ||
function appendStyles() { | ||
var css = document.createElement("style"); | ||
css.type = "text/css"; | ||
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.head.appendChild(css); | ||
} | ||
has_footer = sources.length > 0 || state.note; | ||
footer_el.style.height = has_footer ? null : 0; | ||
footer_el.style.margin = has_footer ? updateFooterMargin(state) : 0; | ||
footer_el.style.fontSize = state.size + "px"; | ||
footer_el.style.textAlign = state.align; | ||
footer_el.style.color = state.color; | ||
function updateFooter() { | ||
var sources = [ | ||
{ 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) { | ||
return source.name || source.url; | ||
}); | ||
var source_container = document.createElement("span"); | ||
sources.forEach(function(source, i) { | ||
var link_container = document.createElement("p"); | ||
if (i > 0) link_container.innerText = ", "; | ||
if (source.url) { | ||
var link_el = document.createElement("a"); | ||
link_el.innerText = source.name || source.url; | ||
link_el.href = addHttp(source.url); | ||
link_el.target = "_blank"; | ||
link_container.appendChild(link_el); | ||
} | ||
else { | ||
link_container.innerText += source.name || source.url; | ||
} | ||
has_footer = sources.length > 0 || state.note; | ||
source_container.appendChild(link_container); | ||
}); | ||
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; | ||
source_el.innerHTML = source_container.innerHTML !== "" ? state.source_label + " " + source_container.outerHTML : ""; | ||
note_el.innerHTML = state.note ? (source_container.innerHTML !== "" ? "• " : "") + state.note : ""; | ||
}; | ||
var source_container = document.createElement("span"); | ||
sources.forEach(function(source, i) { | ||
var link_container = document.createElement("p"); | ||
if (i > 0) link_container.innerText = ", "; | ||
if (source.url) { | ||
var link_el = document.createElement("a"); | ||
link_el.innerText = source.name || source.url; | ||
link_el.href = addHttp(source.url); | ||
link_el.target = "_blank"; | ||
link_container.appendChild(link_el); | ||
} | ||
else { | ||
link_container.innerText += source.name || source.url; | ||
} | ||
var getHeight = function() { | ||
if (!has_footer) return 0; | ||
return footer_el.getBoundingClientRect().height + getFooterMarginHeight(state); | ||
}; | ||
source_container.appendChild(link_container); | ||
}); | ||
source_el.innerHTML = source_container.innerHTML !== "" ? state.source_label + " " + source_container.outerHTML : ""; | ||
note_el.innerHTML = state.note ? (source_container.innerHTML !== "" ? "• " : "") + state.note : ""; | ||
return { | ||
update: update, | ||
getHeight: getHeight, | ||
element: footer_el | ||
}; | ||
} | ||
function updateFooterMargin() { | ||
if (!has_footer) return 0; | ||
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.margin + "px " + state.margin + "px " + "0 " + state.margin + "px"; | ||
} | ||
return init; | ||
function getFooterHeight() { | ||
return exports.footer_el.getBoundingClientRect().height + getFooterMarginHeight(); | ||
} | ||
function getFooterMarginHeight() { | ||
if (!has_footer) return 0; | ||
return state.margin_advanced ? state.margin_top + state.margin_bottom : +state.margin; | ||
} | ||
function addHttp(url) { | ||
if (url.indexOf("http://") !== 0 && url.indexOf("https://") !== 0) return "http://" + url; | ||
else return url; | ||
} | ||
exports.initFooter = initFooter; | ||
exports.updateFooter = updateFooter; | ||
exports.getFooterHeight = getFooterHeight; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
{ | ||
"name": "@flourish/footer", | ||
"version": "1.0.0-alpha", | ||
"version": "1.0.0-alpha2", | ||
"description": "Add footer", | ||
@@ -5,0 +5,0 @@ "main": "footer.js", |
146
src/index.js
@@ -1,4 +0,2 @@ | ||
var footer_el, source_el, note_el; | ||
var has_footer; | ||
var state; | ||
var styles_appended = false; | ||
@@ -25,6 +23,31 @@ var DEFAULTS = { | ||
function appendStyles() { | ||
var css = document.createElement("style"); | ||
css.type = "text/css"; | ||
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.head.appendChild(css); | ||
styles_appended = true; | ||
} | ||
function initFooter(obj, el) { | ||
state = obj; | ||
function updateFooterMargin(state) { | ||
if (state.margin_advanced) { | ||
return state.margin_top + "px " + state.margin_right + "px " + state.margin_bottom + "px " + state.margin_left + "px"; | ||
} | ||
else return state.margin + "px " + state.margin + "px " + "0 " + state.margin + "px"; | ||
} | ||
function getFooterMarginHeight(state) { | ||
return state.margin_advanced ? state.margin_top + state.margin_bottom : +state.margin; | ||
} | ||
function addHttp(url) { | ||
if (url.indexOf("http://") !== 0 && url.indexOf("https://") !== 0) return "http://" + url; | ||
else return url; | ||
} | ||
function init(state) { | ||
if (!styles_appended) appendStyles(); | ||
var has_footer = false; | ||
for (var key in DEFAULTS) { | ||
@@ -34,9 +57,9 @@ if (state[key] === undefined) state[key] = DEFAULTS[key]; | ||
footer_el = document.createElement("div"); | ||
var footer_el = document.createElement("div"); | ||
footer_el.className = "flourish-footer"; | ||
source_el = document.createElement("p"); | ||
var source_el = document.createElement("p"); | ||
source_el.className = "flourish-footer-source"; | ||
note_el = document.createElement("p"); | ||
var note_el = document.createElement("p"); | ||
note_el.className = "flourish-footer-note"; | ||
@@ -47,76 +70,55 @@ | ||
if (el) el.appendChild(footer_el); | ||
appendStyles(); | ||
} | ||
var update = function() { | ||
var sources = [ | ||
{ 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) { | ||
return source.name || source.url; | ||
}); | ||
function appendStyles() { | ||
var css = document.createElement("style"); | ||
css.type = "text/css"; | ||
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.head.appendChild(css); | ||
} | ||
has_footer = sources.length > 0 || state.note; | ||
footer_el.style.height = has_footer ? null : 0; | ||
footer_el.style.margin = has_footer ? updateFooterMargin(state) : 0; | ||
footer_el.style.fontSize = state.size + "px"; | ||
footer_el.style.textAlign = state.align; | ||
footer_el.style.color = state.color; | ||
function updateFooter() { | ||
var sources = [ | ||
{ 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) { | ||
return source.name || source.url; | ||
}); | ||
var source_container = document.createElement("span"); | ||
sources.forEach(function(source, i) { | ||
var link_container = document.createElement("p"); | ||
if (i > 0) link_container.innerText = ", "; | ||
if (source.url) { | ||
var link_el = document.createElement("a"); | ||
link_el.innerText = source.name || source.url; | ||
link_el.href = addHttp(source.url); | ||
link_el.target = "_blank"; | ||
link_container.appendChild(link_el); | ||
} | ||
else { | ||
link_container.innerText += source.name || source.url; | ||
} | ||
has_footer = sources.length > 0 || state.note; | ||
source_container.appendChild(link_container); | ||
}); | ||
footer_el.style.height = has_footer ? null : 0; | ||
footer_el.style.margin = updateFooterMargin(); | ||
footer_el.style.fontSize = state.size + "px"; | ||
footer_el.style.textAlign = state.align; | ||
footer_el.style.color = state.color; | ||
source_el.innerHTML = source_container.innerHTML !== "" ? state.source_label + " " + source_container.outerHTML : ""; | ||
note_el.innerHTML = state.note ? (source_container.innerHTML !== "" ? "• " : "") + state.note : ""; | ||
}; | ||
var source_container = document.createElement("span"); | ||
sources.forEach(function(source, i) { | ||
var link_container = document.createElement("p"); | ||
if (i > 0) link_container.innerText = ", "; | ||
if (source.url) { | ||
var link_el = document.createElement("a"); | ||
link_el.innerText = source.name || source.url; | ||
link_el.href = addHttp(source.url); | ||
link_el.target = "_blank"; | ||
link_container.appendChild(link_el); | ||
} | ||
else { | ||
link_container.innerText += source.name || source.url; | ||
} | ||
var getHeight = function() { | ||
if (!has_footer) return 0; | ||
return footer_el.getBoundingClientRect().height + getFooterMarginHeight(state); | ||
}; | ||
source_container.appendChild(link_container); | ||
}); | ||
source_el.innerHTML = source_container.innerHTML !== "" ? state.source_label + " " + source_container.outerHTML : ""; | ||
note_el.innerHTML = state.note ? (source_container.innerHTML !== "" ? "• " : "") + state.note : ""; | ||
return { | ||
update: update, | ||
getHeight: getHeight, | ||
element: footer_el | ||
}; | ||
} | ||
function updateFooterMargin() { | ||
if (!has_footer) return 0; | ||
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.margin + "px " + state.margin + "px " + "0 " + state.margin + "px"; | ||
} | ||
function getFooterHeight() { | ||
return footer_el.getBoundingClientRect().height + getFooterMarginHeight(); | ||
} | ||
function getFooterMarginHeight() { | ||
if (!has_footer) return 0; | ||
return state.margin_advanced ? state.margin_top + state.margin_bottom : +state.margin; | ||
} | ||
function addHttp(url) { | ||
if (url.indexOf("http://") !== 0 && url.indexOf("https://") !== 0) return "http://" + url; | ||
else return url; | ||
} | ||
export { initFooter, updateFooter, getFooterHeight, footer_el }; | ||
export default init; |
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
0
10877