Adding commonly used scrollTo + cleaning up utils + cleaning up globals

This commit is contained in:
dominiclord
2016-07-19 10:21:09 -04:00
parent 64858642ef
commit bf0c7e148c
7 changed files with 420 additions and 218 deletions

View File

@@ -1,6 +1,5 @@
/* jshint esnext: true */
import svg from '../global/svg';
export default function() {
svg();
svg4everybody();
}

View 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, '&lt;')
.replace(/>/g, '&gt;');
}
/**
* Prepare HTML content that contains mustache characters for use with Ractive
* @param {string} str
* @return {string}
*/
export function unescapeHtml(str) {
return str
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&amp;/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;
}