Adding commonly used scrollTo + cleaning up utils + cleaning up globals
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
/* jshint esnext: true */
|
||||
import svg from '../global/svg';
|
||||
|
||||
export default function() {
|
||||
svg();
|
||||
svg4everybody();
|
||||
}
|
||||
|
||||
62
assets/scripts/utils/html.js
Normal file
62
assets/scripts/utils/html.js
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* @see https://github.com/ractivejs/ractive/blob/dev/src/utils/html.js
|
||||
*/
|
||||
export function escapeHtml(str) {
|
||||
return str
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare HTML content that contains mustache characters for use with Ractive
|
||||
* @param {string} str
|
||||
* @return {string}
|
||||
*/
|
||||
export function unescapeHtml(str) {
|
||||
return str
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/&/g, '&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element data attributes
|
||||
* @param {DOMElement} node
|
||||
* @return {Array} data
|
||||
*/
|
||||
export function getNodeData(node) {
|
||||
// All attributes
|
||||
var attributes = node.attributes;
|
||||
|
||||
// Regex Pattern
|
||||
var pattern = /^data\-(.+)$/;
|
||||
|
||||
// Output
|
||||
var data = {};
|
||||
|
||||
for (let i in attributes) {
|
||||
if (!attributes[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Attributes name (ex: data-module)
|
||||
let name = attributes[i].name;
|
||||
|
||||
// This happens.
|
||||
if (!name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let match = name.match(pattern);
|
||||
if (!match) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If this throws an error, you have some
|
||||
// serious problems in your HTML.
|
||||
data[match[1]] = node.getAttribute(name);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user