Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ndla/article-scripts

Package Overview
Dependencies
Maintainers
5
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ndla/article-scripts - npm Package Compare versions

Comparing version 0.5.3 to 0.5.4

71

es/figureScripts.js

@@ -1,9 +0,1 @@

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
/**

@@ -17,3 +9,3 @@ * Copyright (c) 2016-present, NDLA.

import { copyTextToClipboard } from '@ndla/util';
import { forEachElement, getElementOffset } from './domHelpers';
import { forEachElement } from './domHelpers';
export var toggleLicenseInfoBox = function toggleLicenseInfoBox() {

@@ -40,42 +32,2 @@ forEachElement('.c-dialog', function (el) {

};
var panEventHandler = function panEventHandler(event) {
var target = event.currentTarget;
var image = target.querySelector('img');
var offset = getElementOffset(target);
var touch;
if (event.touches) {
var _event$touches = _slicedToArray(event.touches, 1);
touch = _event$touches[0];
}
var posX = event.pageX || touch.pageX;
var posY = event.pageY || touch.pageY;
var transformOrigin = "".concat((posX - offset.left) / image.clientWidth * 100, "% ").concat((posY - offset.top) / image.clientHeight * 100, "%");
image.style.transformOrigin = transformOrigin;
};
var toggleZoomImage = function toggleZoomImage(event) {
var target = event.currentTarget;
var zoomClass = 'c-figure-license__image-wrapper--zoom';
var zoomed = target.classList.contains(zoomClass);
if (zoomed) {
target.classList.remove(zoomClass);
target.removeEventListener('mousemove', panEventHandler);
target.removeEventListener('touchmove', panEventHandler);
} else {
target.classList.add(zoomClass);
target.addEventListener('mousemove', panEventHandler);
target.addEventListener('touchmove', panEventHandler);
}
};
export var addZoomImageListeners = function addZoomImageListeners() {
forEachElement('.c-figure-license__image-wrapper', function (el) {
el.addEventListener('click', toggleZoomImage);
});
};
export var addCopyToClipboardListeners = function addCopyToClipboardListeners() {

@@ -136,3 +88,24 @@ forEachElement('button[data-copy-string]', function (el) {

};
export var addEventListenerForFigureZoomButton = function addEventListenerForFigureZoomButton() {
forEachElement('button[data-figure-button]', function (el) {
var target = el;
target.onclick = function () {
var parentFigure = target.closest('figure');
if (target.dataset.expanded) {
target.setAttribute('aria-label', target.dataset.aria);
target.classList.remove('c-figure__fullscreen-btn--expanded');
parentFigure.classList.add(target.dataset.classtype);
delete target.dataset.expanded;
} else {
target.setAttribute('aria-label', target.dataset.ariaexpanded);
parentFigure.classList.remove(target.dataset.classtype);
target.classList.add('c-figure__fullscreen-btn--expanded');
target.dataset.expanded = true;
}
};
});
};
var handler = function handler() {

@@ -139,0 +112,0 @@ return updateIFrameDimensions(false);

@@ -10,3 +10,3 @@ /**

import { addFilelistTooltipListners } from './fileListScript';
import { addCopyToClipboardListeners, updateIFrameDimensions, addEventListenerForResize, removeEventListenerForResize, toggleLicenseInfoBox, addZoomImageListeners } from './figureScripts';
import { addCopyToClipboardListeners, updateIFrameDimensions, addEventListenerForResize, removeEventListenerForResize, toggleLicenseInfoBox, addEventListenerForFigureZoomButton } from './figureScripts';
import { addShowDialogClickListeners, removeShowDialogClickListeners, addCloseDialogClickListeners } from './dialogScripts';

@@ -35,6 +35,6 @@ import { initTableScript, removeTableEventListeners } from './tableScripts';

initTableScript();
addZoomImageListeners();
addFilelistTooltipListners();
initArticleTabs();
addEventListenerForFigureZoomButton();
};
export { initTableScript, removeTableEventListeners, updateIFrameDimensions, addFactBoxClickListener, removeFactBoxClickListener, addEventListenerForResize, removeEventListenerForResize, addCloseDialogClickListeners, addCopyToClipboardListeners, addShowConceptDefinitionClickListeners, addShowDialogClickListeners, removeShowDialogClickListeners, addDetailsEventListeners, removeDetailsEventListeners, initAudioPlayers, addFootnoteClickListeners, toggleLicenseInfoBox, toggleRelatedArticles, addZoomImageListeners, addFilelistTooltipListners, initArticleTabs };
export { initTableScript, removeTableEventListeners, updateIFrameDimensions, addFactBoxClickListener, removeFactBoxClickListener, addEventListenerForResize, removeEventListenerForResize, addCloseDialogClickListeners, addCopyToClipboardListeners, addShowConceptDefinitionClickListeners, addShowDialogClickListeners, removeShowDialogClickListeners, addDetailsEventListeners, removeDetailsEventListeners, initAudioPlayers, addFootnoteClickListeners, toggleLicenseInfoBox, toggleRelatedArticles, addFilelistTooltipListners, initArticleTabs, addEventListenerForFigureZoomButton };

@@ -6,3 +6,3 @@ "use strict";

});
exports.removeEventListenerForResize = exports.addEventListenerForResize = exports.updateIFrameDimensions = exports.addCopyToClipboardListeners = exports.addZoomImageListeners = exports.toggleLicenseInfoBox = undefined;
exports.removeEventListenerForResize = exports.addEventListenerForResize = exports.addEventListenerForFigureZoomButton = exports.updateIFrameDimensions = exports.addCopyToClipboardListeners = exports.toggleLicenseInfoBox = undefined;

@@ -13,10 +13,9 @@ var _util = require("@ndla/util");

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
/**
* Copyright (c) 2016-present, NDLA.
*
* This source code is licensed under the GPLv3 license found in the
* LICENSE file in the root directory of this source tree.
*
*/
var toggleLicenseInfoBox = exports.toggleLicenseInfoBox = function toggleLicenseInfoBox() {

@@ -44,42 +43,2 @@ (0, _domHelpers.forEachElement)('.c-dialog', function (el) {

var panEventHandler = function panEventHandler(event) {
var target = event.currentTarget;
var image = target.querySelector('img');
var offset = (0, _domHelpers.getElementOffset)(target);
var touch;
if (event.touches) {
var _event$touches = _slicedToArray(event.touches, 1);
touch = _event$touches[0];
}
var posX = event.pageX || touch.pageX;
var posY = event.pageY || touch.pageY;
var transformOrigin = "".concat((posX - offset.left) / image.clientWidth * 100, "% ").concat((posY - offset.top) / image.clientHeight * 100, "%");
image.style.transformOrigin = transformOrigin;
};
var toggleZoomImage = function toggleZoomImage(event) {
var target = event.currentTarget;
var zoomClass = 'c-figure-license__image-wrapper--zoom';
var zoomed = target.classList.contains(zoomClass);
if (zoomed) {
target.classList.remove(zoomClass);
target.removeEventListener('mousemove', panEventHandler);
target.removeEventListener('touchmove', panEventHandler);
} else {
target.classList.add(zoomClass);
target.addEventListener('mousemove', panEventHandler);
target.addEventListener('touchmove', panEventHandler);
}
};
var addZoomImageListeners = exports.addZoomImageListeners = function addZoomImageListeners() {
(0, _domHelpers.forEachElement)('.c-figure-license__image-wrapper', function (el) {
el.addEventListener('click', toggleZoomImage);
});
};
var addCopyToClipboardListeners = exports.addCopyToClipboardListeners = function addCopyToClipboardListeners() {

@@ -142,2 +101,24 @@ (0, _domHelpers.forEachElement)('button[data-copy-string]', function (el) {

var addEventListenerForFigureZoomButton = exports.addEventListenerForFigureZoomButton = function addEventListenerForFigureZoomButton() {
(0, _domHelpers.forEachElement)('button[data-figure-button]', function (el) {
var target = el;
target.onclick = function () {
var parentFigure = target.closest('figure');
if (target.dataset.expanded) {
target.setAttribute('aria-label', target.dataset.aria);
target.classList.remove('c-figure__fullscreen-btn--expanded');
parentFigure.classList.add(target.dataset.classtype);
delete target.dataset.expanded;
} else {
target.setAttribute('aria-label', target.dataset.ariaexpanded);
parentFigure.classList.remove(target.dataset.classtype);
target.classList.add('c-figure__fullscreen-btn--expanded');
target.dataset.expanded = true;
}
};
});
};
var handler = function handler() {

@@ -144,0 +125,0 @@ return updateIFrameDimensions(false);

@@ -6,3 +6,3 @@ "use strict";

});
exports.initArticleTabs = exports.addFilelistTooltipListners = exports.addZoomImageListeners = exports.toggleRelatedArticles = exports.toggleLicenseInfoBox = exports.addFootnoteClickListeners = exports.initAudioPlayers = exports.removeDetailsEventListeners = exports.addDetailsEventListeners = exports.removeShowDialogClickListeners = exports.addShowDialogClickListeners = exports.addShowConceptDefinitionClickListeners = exports.addCopyToClipboardListeners = exports.addCloseDialogClickListeners = exports.removeEventListenerForResize = exports.addEventListenerForResize = exports.removeFactBoxClickListener = exports.addFactBoxClickListener = exports.updateIFrameDimensions = exports.removeTableEventListeners = exports.initTableScript = exports.initArticleScripts = exports.getElementOffset = exports.findAncestorByClass = exports.forEachElement = undefined;
exports.addEventListenerForFigureZoomButton = exports.initArticleTabs = exports.addFilelistTooltipListners = exports.toggleRelatedArticles = exports.toggleLicenseInfoBox = exports.addFootnoteClickListeners = exports.initAudioPlayers = exports.removeDetailsEventListeners = exports.addDetailsEventListeners = exports.removeShowDialogClickListeners = exports.addShowDialogClickListeners = exports.addShowConceptDefinitionClickListeners = exports.addCopyToClipboardListeners = exports.addCloseDialogClickListeners = exports.removeEventListenerForResize = exports.addEventListenerForResize = exports.removeFactBoxClickListener = exports.addFactBoxClickListener = exports.updateIFrameDimensions = exports.removeTableEventListeners = exports.initTableScript = exports.initArticleScripts = exports.getElementOffset = exports.findAncestorByClass = exports.forEachElement = undefined;

@@ -66,5 +66,5 @@ var _domHelpers = require("./domHelpers");

(0, _tableScripts.initTableScript)();
(0, _figureScripts.addZoomImageListeners)();
(0, _fileListScript.addFilelistTooltipListners)();
(0, _articleTabScripts.initArticleTabs)();
(0, _figureScripts.addEventListenerForFigureZoomButton)();
};

@@ -90,4 +90,4 @@

exports.toggleRelatedArticles = _relatedArticlesToggle.toggleRelatedArticles;
exports.addZoomImageListeners = _figureScripts.addZoomImageListeners;
exports.addFilelistTooltipListners = _fileListScript.addFilelistTooltipListners;
exports.initArticleTabs = _articleTabScripts.initArticleTabs;
exports.initArticleTabs = _articleTabScripts.initArticleTabs;
exports.addEventListenerForFigureZoomButton = _figureScripts.addEventListenerForFigureZoomButton;
{
"name": "@ndla/article-scripts",
"version": "0.5.3",
"version": "0.5.4",
"description": "A collection of functions for making article content responsive (and interactive)",

@@ -22,4 +22,4 @@ "license": "GPL-3.0",

"dependencies": {
"@ndla/util": "^0.3.1",
"focus-trap": "^3.0.0",
"@ndla/util": "^0.3.2",
"focus-trap": "^4.0.2",
"jump.js": "^1.0.2",

@@ -31,3 +31,3 @@ "lodash": "^4.17.5"

},
"gitHead": "2e43362af4f1553fd063bcdf3405a7b79795faea"
"gitHead": "a56d9c5a7f76a201f5848081b6df0a8b79e2fd1f"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc