onemsdk
Version:
ONEm developer library for NodeJS
255 lines (193 loc) • 12.1 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
tag/section.js - Documentation
</title>
<link href="https://www.braintreepayments.com/images/favicon-ccda0b14.png" rel="icon" type="image/png">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
<!-- start Mixpanel -->
<script type="text/javascript">(function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=([^&]*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,
0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(h=0;h<k.length;h++)e(d,k[h]);a._i.push([b,c,f])};a.__SV=1.2;b=e.createElement("script");b.type="text/javascript";b.async=!0;b.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";c=e.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c)}})(document,window.mixpanel||[]);
mixpanel.init("1919205b2da72e4da3b9b6639b444d59");</script>
<!-- end Mixpanel -->
</head>
<body>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<div class="top-nav-wrapper">
<ul>
<li >
<a href="index.html">
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>
</a>
</li>
</ul>
</div>
<nav>
<h3 class="reference-title">
ONEm Node.js SDK
</h3>
<h3>Classes</h3><ul><li id="ATag-nav"><a href="global.html#ATag">ATag</a><ul class='methods'><li data-type="method" id="ATag-getAttributes-nav"><a href="global.html#ATag#.getAttributes">getAttributes</a></li></ul></li><li id="ATagAttrs-nav"><a href="ATagAttrs.html">ATagAttrs</a></li><li id="BrTag-nav"><a href="global.html#BrTag">BrTag</a></li><li id="FooterTag-nav"><a href="global.html#FooterTag">FooterTag</a></li><li id="Form-nav"><a href="global.html#Form">Form</a><ul class='methods'><li data-type="method" id="Form-fromTag-nav"><a href="global.html#Form#.fromTag">fromTag</a></li></ul></li><li id="FormItemContent-nav"><a href="global.html#FormItemContent">FormItemContent</a><ul class='methods'><li data-type="method" id="FormItemContent-fromTag-nav"><a href="global.html#FormItemContent#.fromTag">fromTag</a></li></ul></li><li id="FormItemMenu-nav"><a href="global.html#FormItemMenu">FormItemMenu</a><ul class='methods'><li data-type="method" id="FormItemMenu-fromTag-nav"><a href="global.html#FormItemMenu#.fromTag">fromTag</a></li></ul></li><li id="FormItemMenuItem-nav"><a href="global.html#FormItemMenuItem">FormItemMenuItem</a><ul class='methods'><li data-type="method" id="FormItemMenuItem-fromTag-nav"><a href="global.html#FormItemMenuItem#.fromTag">fromTag</a></li></ul></li><li id="FormItemMenuMeta-nav"><a href="global.html#FormItemMenuMeta">FormItemMenuMeta</a></li><li id="FormMeta-nav"><a href="global.html#FormMeta">FormMeta</a></li><li id="FormTag-nav"><a href="global.html#FormTag">FormTag</a></li><li id="FormTagAttrs-nav"><a href="FormTagAttrs.html">FormTagAttrs</a></li><li id="HeaderTag-nav"><a href="global.html#HeaderTag">HeaderTag</a></li><li id="InputTag-nav"><a href="global.html#InputTag">InputTag</a><ul class='methods'><li data-type="method" id="InputTag-getAttributes-nav"><a href="global.html#InputTag#.getAttributes">getAttributes</a></li></ul></li><li id="InputTagAttrs-nav"><a href="InputTagAttrs.html">InputTagAttrs</a></li><li id="LiTag-nav"><a href="global.html#LiTag">LiTag</a></li><li id="LiTagAttrs-nav"><a href="LiTagAttrs.html">LiTagAttrs</a></li><li id="Menu-nav"><a href="global.html#Menu">Menu</a><ul class='methods'><li data-type="method" id="Menu-fromTag-nav"><a href="global.html#Menu#.fromTag">fromTag</a></li></ul></li><li id="MenuItem-nav"><a href="global.html#MenuItem">MenuItem</a><ul class='methods'><li data-type="method" id="MenuItem-fromTag-nav"><a href="global.html#MenuItem#.fromTag">fromTag</a></li></ul></li><li id="MenuMeta-nav"><a href="global.html#MenuMeta">MenuMeta</a></li><li id="PTag-nav"><a href="global.html#PTag">PTag</a></li><li id="Response-nav"><a href="global.html#Response">Response</a><ul class='methods'><li data-type="method" id="Response-fromTag-nav"><a href="global.html#Response#.fromTag">fromTag</a></li></ul></li><li id="SectionTag-nav"><a href="global.html#SectionTag">SectionTag</a></li><li id="SectionTagAttrs-nav"><a href="SectionTagAttrs.html">SectionTagAttrs</a></li><li id="Tag-nav"><a href="global.html#Tag">Tag</a><ul class='methods'><li data-type="method" id="Tag-fromNode-nav"><a href="global.html#Tag#.fromNode">fromNode</a></li><li data-type="method" id="Tag-getAttributes-nav"><a href="global.html#Tag#.getAttributes">getAttributes</a></li></ul></li><li id="UlTag-nav"><a href="global.html#UlTag">UlTag</a></li></ul><h3 id="global-nav">Global</h3><ul><li><a href="global.html#loadHtml">loadHtml</a></li><li><a href="global.html#loadTemplate">loadTemplate</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">
tag/section.js
</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const Tag = require('./tag').Tag;
const BrTag = require("./br").BrTag;
const FooterTag = require("./footer").FooterTag;
const HeaderTag = require("./header").HeaderTag;
const InputTag = require("./input").InputTag;
const LabelTag = require("./label").LabelTag;
const PTag = require("./p").PTag;
const UlTag = require("./ul").UlTag;
/**
* @typedef SectionTag
* @extends Tag
* @property {Array<HeaderTag|FooterTag|UlTag|PTag|BrTag|InputTag|LabelTag>} children
* @property {SectionTagAttrs} attrs
*/
/**
* Instantiates a new SectionTagAttrs
* @param {string|undefined} name this attribute is relevant only if the
* SectionTag is part of a FormTag
* @param {string|undefined} header text that will be included in header
* @param {string|undefined} footer text that will be included in footer
* @param {boolean|undefined} autoSelect
* @param {boolean|undefined} multiSelect
* @param {boolean|undefined} numbered
* @constructor
*/
function SectionTagAttrs(name, header, footer, autoSelect, multiSelect, numbered) {
this.header = header || null;
this.footer = footer || null;
this.name = name || null;
this.autoSelect = autoSelect;
this.multiSelect = multiSelect;
this.numbered = numbered;
}
/**
* Instantiates a new SectionTag. A SectionTag may represent a step in a form,
* a menu or a block of text. A user will always receive the content of a
* SectionTag at a time.
* @param {Array<PTag | BrTag | UlTag | LabelTag | HeaderTag | FooterTag | InputTag>} children
* @param {SectionTagAttrs} attrs
* @constructor
*/
function SectionTag(children, attrs) {
if (children.length === 0) {
throw Error('<section> must have at least 1 child');
}
children.forEach(function (child) {
switch (child.constructor.tagName) {
case 'p':
case 'br':
case 'ul':
case 'input':
case 'label':
case 'header':
case 'footer':
break;
default:
if (typeof child !== 'string') {
throw Error(`<section> cannot have <${child.constructor.tagName}> child`);
}
}
});
this.children = children;
this.attrs = attrs;
}
SectionTag.__proto__ = Tag;
SectionTag.tagName = 'section';
SectionTag.getAttributes = function (node) {
// Note that boolean attributes in HTML are evaluated to true if they are
// present (their actual value does not matter). They are evaluated to false
// only when they are missing
const autoSelect = node.attributes.hasOwnProperty('auto-select') ||
node.attributes.hasOwnProperty('autoSelect');
const multiSelect = node.attributes.hasOwnProperty('multi-select') ||
node.attributes.hasOwnProperty('multiSelect');
const numbered = node.attributes.hasOwnProperty('numbered');
return new SectionTagAttrs(
node.attributes.name,
node.attributes.header,
node.attributes.footer,
autoSelect,
multiSelect,
numbered
);
};
SectionTag.prototype.toString = function sectionTagToString(excludeHeader, excludeFooter) {
// Add a temporary \n for help
let renderedChildren = ['\n'];
this.children.forEach(function (child) {
let text;
if (child instanceof HeaderTag && excludeHeader) {
// Do not include the header
return;
}
if (child instanceof FooterTag && excludeFooter) {
// Do not include the footer
return;
}
if (typeof child === 'string') {
text = child;
} else {
text = child.toString();
}
if (text) {
if (child instanceof PTag || child instanceof UlTag) {
if (renderedChildren[renderedChildren.length - 1] !== '\n') {
renderedChildren.push('\n');
}
renderedChildren.push(child.toString());
renderedChildren.push('\n');
} else {
renderedChildren.push(child.toString());
}
}
});
if (renderedChildren[renderedChildren.length - 1] === '\n') {
renderedChildren = renderedChildren.slice(0, renderedChildren.length - 1);
}
// Remove the temporary \n
return renderedChildren.slice(1, undefined).join('');
};
exports.SectionTag = SectionTag;
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
</body>
</html>