@dotdev/limelight
Advanced tools
Comparing version 2.1.25 to 2.1.26
@@ -0,1 +1,6 @@ | ||
## [2.1.26](https://github.com/ButsAndCats/limelight/compare/2.1.25...2.1.26) (2018-10-15) | ||
## [2.1.25](https://github.com/ButsAndCats/limelight/compare/2.1.24...2.1.25) (2018-10-15) | ||
@@ -2,0 +7,0 @@ |
392
limelight.js
@@ -0,1 +1,10 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
/* ===================================================================================== @preserve = | ||
@@ -13,6 +22,5 @@ | ||
*/ | ||
const Limelight = function LimelightVisibilityManager (target, config) { | ||
const settings = config || {} | ||
var Limelight = function LimelightVisibilityManager(target, config) { | ||
var settings = config || {}; // The default configuration | ||
// The default configuration | ||
/* | ||
@@ -32,3 +40,4 @@ visibleClass: The class that will be applied to the target element. | ||
*/ | ||
const defaultSettings = { | ||
var defaultSettings = { | ||
visibleClass: 'visible', | ||
@@ -49,70 +58,69 @@ bodyClass: null, | ||
error: null, | ||
group: null | ||
} | ||
group: null // Merge configs | ||
// Merge configs | ||
this.settings = Object.assign(defaultSettings, settings) | ||
}; | ||
this.settings = _extends(defaultSettings, settings); // Update current popup config | ||
// Update current popup config | ||
this.visible = this.settings.visible | ||
// The Dom element of the popup | ||
this.visible = this.settings.visible; // The Dom element of the popup | ||
this.element = document.querySelector(target) | ||
this.element = document.querySelector(target); | ||
if (!this.element) { | ||
return | ||
return; | ||
} | ||
this.outerElement = this.element.querySelector(`${this.settings.outerSelector}`) | ||
this.closeElements = this.element.querySelectorAll(`[data-close]`) | ||
this.target = target | ||
this.outerElement = this.element.querySelector("".concat(this.settings.outerSelector)); | ||
this.closeElements = this.element.querySelectorAll("[data-close]"); | ||
this.target = target; | ||
if (this.settings.slide) { | ||
if (this.settings.slideChild) { | ||
this.slideElement = this.element.querySelector(this.settings.slideChild) | ||
this.slideElement = this.element.querySelector(this.settings.slideChild); | ||
} else { | ||
this.slideElement = this.element | ||
this.slideElement = this.element; | ||
} | ||
const defaultDisplay = this.slideElement.style.display | ||
this.slideElement.style.display = 'block' | ||
this.maxHeight = this.slideElement.offsetHeight | ||
this.slideElement.style.display = defaultDisplay | ||
this.height = this.slideElement.offsetHeight | ||
this.counter = this.height | ||
} | ||
// Bind this into all of our prototype functions | ||
this.show = this.show.bind(this) | ||
this.hide = this.hide.bind(this) | ||
this.toggle = this.toggle.bind(this) | ||
this.detach = this.detach.bind(this) | ||
this.slideDown = this.slideDown.bind(this) | ||
this.slideUp = this.slideUp.bind(this) | ||
this.buildEventListeners = this.buildEventListeners.bind(this) | ||
this.eventHandler = this.eventHandler.bind(this) | ||
var defaultDisplay = this.slideElement.style.display; | ||
this.slideElement.style.display = 'block'; | ||
this.maxHeight = this.slideElement.offsetHeight; | ||
this.slideElement.style.display = defaultDisplay; | ||
this.height = this.slideElement.offsetHeight; | ||
this.counter = this.height; | ||
} // Bind this into all of our prototype functions | ||
// If detach is set to true move the popup to the end of the popup | ||
this.show = this.show.bind(this); | ||
this.hide = this.hide.bind(this); | ||
this.toggle = this.toggle.bind(this); | ||
this.detach = this.detach.bind(this); | ||
this.slideDown = this.slideDown.bind(this); | ||
this.slideUp = this.slideUp.bind(this); | ||
this.buildEventListeners = this.buildEventListeners.bind(this); | ||
this.eventHandler = this.eventHandler.bind(this); // If detach is set to true move the popup to the end of the popup | ||
if (this.settings.detach) { | ||
document.addEventListener('DOMContentLoaded', this.detach) | ||
} | ||
document.addEventListener('DOMContentLoaded', this.detach); | ||
} // Create a list of all of the currently active elements so that we can access them globally | ||
// Create a list of all of the currently active elements so that we can access them globally | ||
Limelight.elements[target] = this | ||
window.Limelight = Limelight || {} | ||
window.Limelight.elements[target] = this | ||
this.buildEventListeners() | ||
} | ||
// Create an empty object to store all of the elements in. | ||
Limelight.elements = Limelight.elements || {} | ||
Limelight.elements[target] = this; | ||
window.Limelight = Limelight || {}; | ||
window.Limelight.elements[target] = this; | ||
this.buildEventListeners(); | ||
}; // Create an empty object to store all of the elements in. | ||
// Prevent default if the element is a link and return the selector of the popup element | ||
Limelight.getTarget = function getTheLimelightElementRelatedToTheTarget (event) { | ||
const element = event.currentTarget | ||
Limelight.elements = Limelight.elements || {}; // Prevent default if the element is a link and return the selector of the popup element | ||
Limelight.getTarget = function getTheLimelightElementRelatedToTheTarget(event) { | ||
var element = event.currentTarget; | ||
if (element.tagName === 'A') { | ||
event.preventDefault() | ||
event.preventDefault(); | ||
} | ||
const selector = element.dataset.target | ||
const target = selector || null | ||
return target | ||
} | ||
var selector = element.dataset.target; | ||
var target = selector || null; | ||
return target; | ||
}; | ||
/* | ||
@@ -122,94 +130,115 @@ If the element does not exist then it is being fired directly from a data attribute. | ||
*/ | ||
Limelight.prototype.eventHandler = function hideOrShowTheElement (event, target, method) { | ||
let element = Limelight.elements[target] | ||
Limelight.prototype.eventHandler = function hideOrShowTheElement(event, target, method) { | ||
var element = Limelight.elements[target]; | ||
if (!element) { | ||
element = new Limelight(target) | ||
element = new Limelight(target); | ||
} | ||
if (method === 'hide') { | ||
return element.hide() | ||
return element.hide(); | ||
} | ||
if (method === 'show') { | ||
return element.show() | ||
return element.show(); | ||
} | ||
return element.toggle() | ||
} | ||
return element.toggle(); | ||
}; | ||
/* | ||
When clicking on a close button or out element | ||
*/ | ||
Limelight.closeEvent = function handleAnElementBeingClosed (event) { | ||
const target = Limelight.getTarget(event) | ||
Limelight.closeEvent = function handleAnElementBeingClosed(event) { | ||
var target = Limelight.getTarget(event); | ||
if (target) { | ||
this.eventHandler(event, target, 'hide') | ||
this.eventHandler(event, target, 'hide'); | ||
} else { | ||
this.hide() | ||
this.hide(); | ||
} | ||
} | ||
}; | ||
/* | ||
On key up event check if the user has pressed escape | ||
*/ | ||
Limelight.escEvent = function onKeyUpEscape (event) { | ||
Limelight.escEvent = function onKeyUpEscape(event) { | ||
if (event.keyCode === 27) { | ||
this.element.removeEventListener('keyup', Limelight.escEvent) | ||
this.hide() | ||
this.element.removeEventListener('keyup', Limelight.escEvent); | ||
this.hide(); | ||
} | ||
} | ||
}; | ||
/* | ||
Build the event listeners | ||
*/ | ||
Limelight.prototype.buildEventListeners = function bindLimelightEventListeners () { | ||
const allTriggers = document.querySelectorAll(`[data-trigger][data-target="${this.target}"]`) | ||
const clickFunction = function (event) { | ||
event.preventDefault() | ||
event.stopPropagation() | ||
this.triggerElement = event.currentTarget | ||
const { target } = this.triggerElement.dataset | ||
this.eventHandler(event, target) | ||
}.bind(this) | ||
const hoverFunction = function (event) { | ||
event.preventDefault() | ||
event.stopPropagation() | ||
const { target } = event.currentTarget.dataset | ||
this.eventHandler(event, target, 'show') | ||
}.bind(this) | ||
for (let trigger = 0; trigger < allTriggers.length; trigger += 1) { | ||
allTriggers[trigger].addEventListener('click', clickFunction) | ||
Limelight.prototype.buildEventListeners = function bindLimelightEventListeners() { | ||
var allTriggers = document.querySelectorAll("[data-trigger][data-target=\"".concat(this.target, "\"]")); | ||
var clickFunction = function (event) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
this.triggerElement = event.currentTarget; | ||
var target = this.triggerElement.dataset.target; | ||
this.eventHandler(event, target); | ||
}.bind(this); | ||
var hoverFunction = function (event) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
var target = event.currentTarget.dataset.target; | ||
this.eventHandler(event, target, 'show'); | ||
}.bind(this); | ||
for (var trigger = 0; trigger < allTriggers.length; trigger += 1) { | ||
allTriggers[trigger].addEventListener('click', clickFunction); | ||
if (this.settings.hover) { | ||
allTriggers[trigger].addEventListener('mouseenter', hoverFunction) | ||
allTriggers[trigger].addEventListener('mouseenter', hoverFunction); | ||
} | ||
} | ||
// If the element is intialized visible then create an event listener for closing | ||
} // If the element is intialized visible then create an event listener for closing | ||
if (this.closeElements && this.settings.visible) { | ||
// When someone clicks the [data-close] button then we should close the modal | ||
for (var elem = 0; elem < this.closeElements.length; elem += 1) { | ||
this.closeElements[elem].addEventListener('click', Limelight.closeEvent.bind(this)) | ||
this.closeElements[elem].addEventListener('click', Limelight.closeEvent.bind(this)); | ||
} | ||
} | ||
} | ||
}; | ||
/* | ||
Add a class to a given element | ||
*/ | ||
Limelight.addClass = function addAClassToAGivenElement (element, className) { | ||
const el = element | ||
Limelight.addClass = function addAClassToAGivenElement(element, className) { | ||
var el = element; | ||
if (el.classList) { | ||
el.classList.add(className) | ||
el.classList.add(className); | ||
} | ||
} | ||
}; | ||
/* | ||
Remove a class from a given element | ||
*/ | ||
Limelight.removeClass = function removeAClassFromAGivenElement (element, className) { | ||
const el = element | ||
Limelight.removeClass = function removeAClassFromAGivenElement(element, className) { | ||
var el = element; | ||
if (el.classList) { | ||
el.classList.remove(className) | ||
el.classList.remove(className); | ||
} | ||
} | ||
}; | ||
/* | ||
Show the popup element | ||
*/ | ||
Limelight.prototype.show = function showTheElement () { | ||
Limelight.prototype.show = function showTheElement() { | ||
// Check if the element is visible or not. | ||
@@ -219,86 +248,93 @@ if (!this.visible || !this.element.classList.contains(this.settings.visibleClass)) { | ||
if (this.settings.beforeShowCallback && typeof this.settings.beforeShowCallback === 'function') { | ||
this.settings.beforeShowCallback(this, Limelight.elements) | ||
} | ||
// Add the class to the trigger button if one is defined. | ||
this.settings.beforeShowCallback(this, Limelight.elements); | ||
} // Add the class to the trigger button if one is defined. | ||
if (this.settings.triggerClass) { | ||
const triggerElement = document.querySelector(`[data-target="${this.target}"]`) | ||
Limelight.addClass(triggerElement, this.settings.triggerClass) | ||
} | ||
// If slide is set to true slide the element down. | ||
var triggerElement = document.querySelector("[data-target=\"".concat(this.target, "\"]")); | ||
Limelight.addClass(triggerElement, this.settings.triggerClass); | ||
} // If slide is set to true slide the element down. | ||
if (this.settings.slide) { | ||
this.slideDown(this.settings.slideDuration) | ||
} | ||
// Add the visible class to the popup | ||
Limelight.addClass(this.element, this.settings.visibleClass) | ||
// Add the body class to the body | ||
this.slideDown(this.settings.slideDuration); | ||
} // Add the visible class to the popup | ||
Limelight.addClass(this.element, this.settings.visibleClass); // Add the body class to the body | ||
if (this.settings.bodyClass) { | ||
Limelight.addClass(document.body, this.settings.bodyClass) | ||
} | ||
Limelight.addClass(document.body, this.settings.bodyClass); | ||
} // Define that this element is visible | ||
// Define that this element is visible | ||
this.visible = true | ||
// Focus on an input field once the modal has opened | ||
const focusEl = document.querySelector(`${this.target} ${this.settings.autoFocusSelector}`) | ||
this.visible = true; // Focus on an input field once the modal has opened | ||
var focusEl = document.querySelector("".concat(this.target, " ").concat(this.settings.autoFocusSelector)); | ||
if (focusEl) { | ||
setTimeout(() => { | ||
focusEl.focus() | ||
}, 300) | ||
setTimeout(function () { | ||
focusEl.focus(); | ||
}, 300); | ||
} | ||
if (this.closeElements) { | ||
// When someone clicks the [data-close] button then we should close the modal | ||
for (let elem = 0; elem < this.closeElements.length; elem += 1) { | ||
this.closeElements[elem].addEventListener('click', Limelight.closeEvent.bind(this)) | ||
for (var elem = 0; elem < this.closeElements.length; elem += 1) { | ||
this.closeElements[elem].addEventListener('click', Limelight.closeEvent.bind(this)); | ||
} | ||
} | ||
if (this.outerElement) { | ||
// When someone clicks on the inner class hide the popup | ||
this.outerElement.addEventListener('click', Limelight.closeEvent.bind(this)) | ||
} | ||
// When someone presses esc hide the popup and unbind the event listener | ||
this.element.addEventListener('keyup', Limelight.escEvent.bind(this)) | ||
this.outerElement.addEventListener('click', Limelight.closeEvent.bind(this)); | ||
} // When someone presses esc hide the popup and unbind the event listener | ||
// Fire the success callback | ||
this.element.addEventListener('keyup', Limelight.escEvent.bind(this)); // Fire the success callback | ||
if (this.settings.showCallback && typeof this.settings.showCallback === 'function') { | ||
this.settings.showCallback(this, Limelight.elements) | ||
this.settings.showCallback(this, Limelight.elements); | ||
} | ||
} else if (this.settings.error && typeof this.settings.error === 'function') { | ||
this.settings.error('Limelight: Error this element is already visible', this) | ||
} | ||
// Return this so that we can chain functions together | ||
return this | ||
} | ||
this.settings.error('Limelight: Error this element is already visible', this); | ||
} // Return this so that we can chain functions together | ||
Limelight.prototype.slideDown = function slideDown () { | ||
const el = this.slideElement | ||
const height = `${el.scrollHeight}px` | ||
el.style.height = height | ||
} | ||
Limelight.prototype.slideUp = function slideUp () { | ||
const el = this.slideElement | ||
el.style.height = null | ||
} | ||
return this; | ||
}; | ||
Limelight.prototype.hide = function hideTheElement () { | ||
Limelight.prototype.slideDown = function slideDown() { | ||
var el = this.slideElement; | ||
var height = "".concat(el.scrollHeight, "px"); | ||
el.style.height = height; | ||
}; | ||
Limelight.prototype.slideUp = function slideUp() { | ||
var el = this.slideElement; | ||
el.style.height = null; | ||
}; | ||
Limelight.prototype.hide = function hideTheElement() { | ||
if (this.visible || this.element.classList.contains(this.settings.visibleClass)) { | ||
// Fire the before hide callback | ||
if (this.settings.beforeHideCallback && typeof this.settings.beforeHideCallback === 'function') { | ||
this.settings.beforeHideCallback(this, Limelight.elements) | ||
this.settings.beforeHideCallback(this, Limelight.elements); | ||
} | ||
this.visible = false | ||
this.visible = false; | ||
if (this.settings.bodyClass) { | ||
Limelight.removeClass(document.body, this.settings.bodyClass) | ||
Limelight.removeClass(document.body, this.settings.bodyClass); | ||
} | ||
Limelight.removeClass(this.element, this.settings.visibleClass) | ||
Limelight.removeClass(this.element, this.settings.visibleClass); | ||
if (this.settings.slide) { | ||
this.slideUp(this.settings.slideDuration) | ||
this.slideUp(this.settings.slideDuration); | ||
} | ||
if (this.settings.triggerClass) { | ||
const triggerElement = document.querySelector(`[data-target="${this.target}"]`) | ||
Limelight.removeClass(triggerElement, this.settings.triggerClass) | ||
var triggerElement = document.querySelector("[data-target=\"".concat(this.target, "\"]")); | ||
Limelight.removeClass(triggerElement, this.settings.triggerClass); | ||
} | ||
@@ -308,41 +344,47 @@ | ||
// When someone clicks the [data-close] button then we should close the modal | ||
for (let elem = 0; elem < this.closeElements.length; elem += 1) { | ||
this.closeElements[elem].addEventListener('click', Limelight.closeEvent.bind(this)) | ||
for (var elem = 0; elem < this.closeElements.length; elem += 1) { | ||
this.closeElements[elem].addEventListener('click', Limelight.closeEvent.bind(this)); | ||
} | ||
} | ||
if (this.outerElement) { | ||
// When someone clicks on the inner class hide the popup | ||
this.outerElement.removeEventListener('click', Limelight.closeEvent.bind(this)) | ||
} | ||
this.outerElement.removeEventListener('click', Limelight.closeEvent.bind(this)); | ||
} // Fire the success callback | ||
// Fire the success callback | ||
if (this.settings.hideCallback && typeof this.settings.hideCallback === 'function') { | ||
this.settings.hideCallback(this, Limelight.elements) | ||
this.settings.hideCallback(this, Limelight.elements); | ||
} | ||
} else if (this.settings.error && typeof this.settings.error === 'function') { | ||
this.settings.error('Limelight: Error this element is already hidden', this) | ||
this.settings.error('Limelight: Error this element is already hidden', this); | ||
} | ||
return this | ||
} | ||
return this; | ||
}; | ||
/* | ||
Show if hidden, hide if shown. | ||
*/ | ||
Limelight.prototype.toggle = function toggleLimelightVisibility () { | ||
Limelight.prototype.toggle = function toggleLimelightVisibility() { | ||
if (this.visible) { | ||
this.hide() | ||
this.hide(); | ||
} else { | ||
this.show() | ||
this.show(); | ||
} | ||
return this | ||
} | ||
return this; | ||
}; | ||
/* | ||
Move the element to the end of the body, sometime useful for popups. | ||
*/ | ||
Limelight.prototype.detach = function moveTheElementToTheEndOfTheBody () { | ||
document.body.appendChild(this.element) | ||
return this | ||
} | ||
export default Limelight | ||
Limelight.prototype.detach = function moveTheElementToTheEndOfTheBody() { | ||
document.body.appendChild(this.element); | ||
return this; | ||
}; | ||
var _default = Limelight; | ||
exports.default = _default; |
@@ -56,3 +56,3 @@ { | ||
}, | ||
"version": "2.1.25" | ||
"version": "2.1.26" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36336
742