UNPKG

prismic.io

Version:

JavaScript development kit for prismic.io

2,938 lines (795 loc) 34.4 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Class: WithFragments</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Class: WithFragments</h1> <section> <header> <h2>WithFragments</h2> </header> <article> <div class="container-overview"> <h4 class="name" id="WithFragments"><span class="type-signature"></span>new WithFragments<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> Functions to access fragments: superclass for Document and Doc (from Group), not supposed to be created directly </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line9">line 9</a> </li></ul></dd> </dl> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="asHtml"><span class="type-signature"></span>asHtml<span class="signature">(linkResolver)</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> Transforms the whole document as an HTML output. Each fragment is separated by a &lt;section&gt; tag, with the attribute data-field="nameoffragment" Note that most of the time you will not use this method, but read fragment independently and generate HTML output for StructuredText fragment with that class' asHtml method. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>linkResolver</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line396">line 396</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - The HTML output </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="asText"><span class="type-signature"></span>asText<span class="signature">()</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> Turns the document into a useable text version of it. </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line417">line 417</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - basic text version of the fragment </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="get"><span class="type-signature"></span>get<span class="signature">(name)</span><span class="type-signature"> &rarr; {object}</span></h4> <div class="description"> Gets the fragment in the current Document object. Since you most likely know the type of this fragment, it is advised that you use a dedicated method, like get StructuredText() or getDate(), for instance. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of the fragment to get, with its type; for instance, "blog-post.author"</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line20">line 20</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - The JavaScript Fragment object to manipulate </div> <dl> <dt> Type </dt> <dd> <span class="param-type">object</span> </dd> </dl> <h4 class="name" id="getAll"><span class="type-signature"></span>getAll<span class="signature">(name)</span><span class="type-signature"> &rarr; {array}</span></h4> <div class="description"> Builds an array of all the fragments in case they are multiple. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of the multiple fragment to get, with its type; for instance, "blog-post.author"</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line31">line 31</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - An array of each JavaScript fragment object to manipulate. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">array</span> </dd> </dl> <h4 class="name" id="getBoolean"><span class="type-signature"></span>getBoolean<span class="signature">(name)</span><span class="type-signature"> &rarr; {boolean}</span></h4> <div class="description"> Gets a boolean value of the fragment in the current Document object, for further manipulation. This works great with a Select fragment. The Select values that are considered true are (lowercased before matching): 'yes', 'on', and 'true'. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of the fragment to get, with its type; for instance, "blog-post.enableComments"</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line204">line 204</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - The boolean value of the fragment </div> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>if(document.getBoolean('blog-post.enableComments')) { ... }</code></pre> <h4 class="name" id="getColor"><span class="type-signature"></span>getColor<span class="signature">(name)</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> Gets the Color fragment in the current Document object, for further manipulation. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of the fragment to get, with its type; for instance, "product.color"</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line319">line 319</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - The string value of the Color fragment. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>document.getColor('product.color')</code></pre> <h4 class="name" id="getDate"><span class="type-signature"></span>getDate<span class="signature">(name)</span><span class="type-signature"> &rarr; {Date}</span></h4> <div class="description"> Gets the date fragment in the current Document object, for further manipulation. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of the fragment to get, with its type; for instance, "blog-post.publicationdate"</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line185">line 185</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - The Date object to manipulate </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Date</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>document.getDate('blog-post.publicationdate').asHtml(linkResolver)</code></pre> <h4 class="name" id="getGeoPoint"><span class="type-signature"></span>getGeoPoint<span class="signature">(name)</span><span class="type-signature"> &rarr; {GeoPoint}</span></h4> <div class="description"> Gets the GeoPoint fragment in the current Document object, for further manipulation. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of the fragment to get, with its type; for instance, "blog-post.location"</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line336">line 336</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - The GeoPoint object to manipulate </div> <dl> <dt> Type </dt> <dd> <span class="param-type">GeoPoint</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>document.getGeoPoint('blog-post.location').asHtml(linkResolver)</code></pre> <h4 class="name" id="getGroup"><span class="type-signature"></span>getGroup<span class="signature">(name)</span><span class="type-signature"> &rarr; {Group}</span></h4> <div class="description"> Gets the Group fragment in the current Document object, for further manipulation. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of the fragment to get, with its type; for instance, "product.gallery"</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line354">line 354</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - The Group fragment to manipulate. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Group</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>document.getGroup('product.gallery').asHtml(linkResolver).</code></pre> <h4 class="name" id="getHtml"><span class="type-signature"></span>getHtml<span class="signature">(name, linkResolver)</span><span class="type-signature"> &rarr; {string}</span></h4> <div class="description"> Shortcut to get the HTML output of the fragment in the current document. This is the same as writing document.get(fragment).asHtml(linkResolver); </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of the fragment to get, with its type; for instance, "blog-post.body"</td> </tr> <tr> <td class="name"><code>linkResolver</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line371">line 371</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - The HTML output </div> <dl> <dt> Type </dt> <dd> <span class="param-type">string</span> </dd> </dl> <h4 class="name" id="getImage"><span class="type-signature"></span>getImage<span class="signature">(fragment)</span><span class="type-signature"> &rarr; {ImageEl}</span></h4> <div class="description"> Gets the image fragment in the current Document object, for further manipulation. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>fragment</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of the fragment to get, with its type; for instance, "blog-post.photo"</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line43">line 43</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - The Image object to manipulate </div> <dl> <dt> Type </dt> <dd> <span class="param-type">ImageEl</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>document.getImage('blog-post.photo').asHtml(linkResolver)</code></pre> <h4 class="name" id="getImageView"><span class="type-signature"></span>getImageView<span class="signature">(name-)</span><span class="type-signature"> &rarr; {ImageView}</span></h4> <div class="description"> Gets the view within the image fragment in the current Document object, for further manipulation. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name-</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of the fragment to get, with its type; for instance, "blog-post.photo"</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line136">line 136</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> view - The View object to manipulate </div> <dl> <dt> Type </dt> <dd> <span class="param-type">ImageView</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>document.getImageView('blog-post.photo', 'large').asHtml(linkResolver)</code></pre> <h4 class="name" id="getLink"><span class="type-signature"></span>getLink<span class="signature">(name)</span><span class="type-signature"> &rarr; {WebLink|DocumentLink|ImageLink}</span></h4> <div class="description"> Gets the Link fragment in the current Document object, for further manipulation. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of the fragment to get, with its type; for instance, "blog-post.link"</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line282">line 282</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - The Link fragment to manipulate. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">WebLink</span> | <span class="param-type">DocumentLink</span> | <span class="param-type">ImageLink</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>document.getLink('blog-post.link').url(resolver)</code></pre> <h4 class="name" id="getNumber"><span class="type-signature"></span>getNumber<span class="signature">(name)</span><span class="type-signature"> &rarr; {number}</span></h4> <div class="description"> Gets the Number fragment in the current Document object, for further manipulation. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of the fragment to get, with its type; for instance, "product.price"</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line302">line 302</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - The number value of the fragment. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">number</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>document.getNumber('product.price')</code></pre> <h4 class="name" id="getStructuredText"><span class="type-signature"></span>getStructuredText<span class="signature">(name)</span><span class="type-signature"> &rarr; {StructuredText}</span></h4> <div class="description"> Gets the StructuredText fragment in the current Document object, for further manipulation. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of the fragment to get, with its type; for instance, "blog-post.body"</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line266">line 266</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - The StructuredText fragment to manipulate. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">StructuredText</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>document.getStructuredText('blog-post.body').asHtml(linkResolver)</code></pre> <h4 class="name" id="getText"><span class="type-signature"></span>getText<span class="signature">(name, after)</span><span class="type-signature"> &rarr; {object}</span></h4> <div class="description"> Gets the text fragment in the current Document object, for further manipulation. The method works with StructuredText fragments, Text fragments, Number fragments, Select fragments and Color fragments. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of the fragment to get, with its type; for instance, "blog-post.label"</td> </tr> <tr> <td class="name"><code>after</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">a suffix that will be appended to the value</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line219">line 219</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - either StructuredText, or Text, or Number, or Select, or Color. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">object</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>document.getText('blog-post.label').asHtml(linkResolver).</code></pre> <h4 class="name" id="getTimestamp"><span class="type-signature"></span>getTimestamp<span class="signature">(name)</span><span class="type-signature"> &rarr; {Date}</span></h4> <div class="description"> Gets the timestamp fragment in the current Document object, for further manipulation. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>name</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">The name of the fragment to get, with its type; for instance, "blog-post.publicationdate"</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line167">line 167</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - The Date object to manipulate </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Date</span> </dd> </dl> <h5>Example</h5> <pre class="prettyprint"><code>document.getDate('blog-post.publicationdate').asHtml(linkResolver)</code></pre> <h4 class="name" id="linkedDocuments"><span class="type-signature"></span>linkedDocuments<span class="signature">()</span><span class="type-signature"> &rarr; {Array}</span></h4> <div class="description"> Linked documents, as an array of DocumentLink </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="documents.js.html">documents.js</a>, <a href="documents.js.html#line437">line 437</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">Array</span> </dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Api.html">Api</a></li><li><a href="Doc.html">Doc</a></li><li><a href="Experiments.html">Experiments</a></li><li><a href="Fragments_Color.html">Fragments:Color</a></li><li><a href="Fragments_CompositeSlice.html">Fragments:CompositeSlice</a></li><li><a href="Fragments_Date.html">Fragments:Date</a></li><li><a href="Fragments_DocumentLink.html">Fragments:DocumentLink</a></li><li><a href="Fragments_Embed.html">Fragments:Embed</a></li><li><a href="Fragments_FileLink.html">Fragments:FileLink</a></li><li><a href="Fragments_GeoPoint.html">Fragments:GeoPoint</a></li><li><a href="Fragments_Group.html">Fragments:Group</a></li><li><a href="Fragments_ImageEl.html">Fragments:ImageEl</a></li><li><a href="Fragments_ImageLink.html">Fragments:ImageLink</a></li><li><a href="Fragments_ImageView.html">Fragments:ImageView</a></li><li><a href="Fragments_Num.html">Fragments:Num</a></li><li><a href="Fragments_Select.html">Fragments:Select</a></li><li><a href="Fragments_Separator.html">Fragments:Separator</a></li><li><a href="Fragments_SimpleSlice.html">Fragments:SimpleSlice</a></li><li><a href="Fragments_SliceZone.html">Fragments:SliceZone</a></li><li><a href="Fragments_StructuredText.html">Fragments:StructuredText</a></li><li><a href="Fragments_Text.html">Fragments:Text</a></li><li><a href="Fragments_Timestamp.html">Fragments:Timestamp</a></li><li><a href="Fragments_WebLink.html">Fragments:WebLink</a></li><li><a href="Ref.html">Ref</a></li><li><a href="Response.html">Response</a></li><li><a href="SearchForm.html">SearchForm</a></li><li><a href="WithFragments.html">WithFragments</a></li></ul><h3>Namespaces</h3><ul><li><a href="Predicates.html">Predicates</a></li></ul><h3>Global</h3><ul><li><a href="global.html#ApiCache">ApiCache</a></li><li><a href="global.html#data">data</a></li><li><a href="global.html#fragments">fragments</a></li><li><a href="global.html#insertSpans">insertSpans</a></li><li><a href="global.html#LRUCache">LRUCache</a></li><li><a href="global.html#parseDoc">parseDoc</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Fri Apr 28 2017 17:29:54 GMT+0200 (CEST) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>