Socket
Socket
Sign inDemoInstall

prismic.io

Package Overview
Dependencies
Maintainers
3
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prismic.io - npm Package Compare versions

Comparing version 1.0.11 to 1.0.12

dist/prismic.io-1.0.12.min.js

2

bower.json
{
"name": "prismic-js-SDK",
"version": "1.0.11",
"version": "1.0.12",
"homepage": "https://github.com/prismicio/javascript-kit",

@@ -5,0 +5,0 @@ "authors": [

/*!
* prismic.io 1.0.11
* prismic.io 1.0.12
* See release notes: https://github.com/prismicio/javascript-kit/releases
*/
!function(a,b){"use strict";function c(a,b,c,d,e,f){this.name=a,this.fields=b,this.form_method=c,this.rel=d,this.enctype=e,this.action=f}function d(a,b,c){this.api=a,this.form=b,this.data=c||{};for(var d in b.fields)b.fields[d].default&&(this.data[d]=[b.fields[d].default])}function e(a){return this.fragments&&this.fragments[a]?Array.isArray(this.fragments[a])?this.fragments[a]:[this.fragments[a]]:[]}function f(a,b,c,d,e,f,g,h){this.page=a,this.results_per_page=b,this.results_size=c,this.total_results_size=d,this.total_pages=e,this.next_page=f,this.prev_page=g,this.results=h}function g(a,b,c,d,e,f){this.id=a,this.type=b,this.href=c,this.tags=d,this.slug=e?e[0]:"-",this.slugs=e,this.fragments=f}function h(a,b,c,d){this.ref=a,this.label=b,this.isMaster=c,this.scheduledAt=d}function i(){this.cache={},this.states={}}var j=function(a,b,c,d,e){var f=new j.fn.init(a,c,d,e);return b&&f.get(b),f},k=function(){return"undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?function(a,b){var c=new XMLHttpRequest,d=function(){b(null,JSON.parse(c.responseText),c)},e=function(){var d=c.status;b(new Error("Unexpected status code ["+d+"] on URL "+a),null,c)};c.onreadystatechange=function(){4===c.readyState&&(c.status&&200==c.status?d():e())},c.open("GET",a,!0),c.setRequestHeader("Accept","application/json"),c.send()}:void 0},l=function(){return"undefined"!=typeof XDomainRequest?function(a,b){var c=new XDomainRequest,d=function(){b(null,JSON.parse(c.responseText),c)},e=function(a){b(new Error(a),null,c)};c.onload=function(){d(c)},c.onerror=function(){e("Unexpected status code on URL "+a)},c.open("GET",a,!0),c.ontimeout=function(){e("Request timeout")},c.onprogress=function(){},c.send()}:void 0},m=function(){if("function"==typeof require&&require("http")){{var a={},c=require("http"),d=require("https"),e=require("url");require("querystring")}return function(f,g){if(a[f])g(null,a[f]);else{var h=e.parse(f),i="https:"==h.protocol?d:c,j={hostname:h.hostname,path:h.path,query:h.query,headers:{Accept:"application/json"}};i.get(j,function(c){if(c.statusCode&&200==c.statusCode){var d="";c.setEncoding("utf8"),c.on("data",function(a){d+=a}),c.on("end",function(){var e=c.headers["cache-control"],h=e&&/max-age=(\d+)/.test(e)?parseInt(/max-age=(\d+)/.exec(e)[1]):b,i=JSON.parse(d);h&&(a[f]=i),g(null,i,c)})}else g(new Error("Unexpected status code ["+c.statusCode+"] on URL "+f),null,c)})}}}};j.fn=j.prototype={constructor:j,data:null,get:function(a){var b=this,c=this.url+(this.accessToken?"#"+this.accessToken:"");this.apiCache.getOrSet(c,5,function(a){b.requestHandler(b.url,function(c,d,e){c?a&&a(c,null,e):a&&a(null,b.parse(d),e)})},function(c,d,e){c?a&&a(c,null,e):(b.data=d,b.bookmarks=d.bookmarks,a&&a(null,b,e))})},parse:function(a){var b,d,e,f,g,i,j,k={};for(j in a.forms)a.forms.hasOwnProperty(j)&&(i=a.forms[j],this.accessToken&&(i.fields.accessToken={type:"string","default":this.accessToken}),e=new c(i.name,i.fields,i.form_method,i.rel,i.enctype,i.action),k[j]=e);if(b=a.refs.map(function(a){return new h(a.ref,a.label,a.isMasterRef,a.scheduledAt)})||[],d=b.filter(function(a){return a.isMaster===!0}),f=a.types,g=a.tags,0===d.length)throw"No master ref.";return{bookmarks:a.bookmarks||{},refs:b,forms:k,master:d[0],types:f,tags:g,oauthInitiate:a.oauth_initiate,oauthToken:a.oauth_token}},init:function(a,b,c,d){return this.url=a+(b?(a.indexOf("?")>-1?"&":"?")+"access_token="+b:""),this.accessToken=b,this.requestHandler=c||k()||l()||m()||function(){throw new Error("No request handler available (tried XMLHttpRequest & NodeJS)")}(),this.apiCache=d||new i,this},forms:function(a){return this.form(a)},form:function(a){var b=this.data.forms[a];return b?new d(this,b,{}):void 0},master:function(){return this.data.master.ref},ref:function(a){for(var b=0;b<this.data.refs.length;b++)if(this.data.refs[b].label==a)return this.data.refs[b].ref}},j.fn.init.prototype=j.fn,c.prototype={},d.prototype={set:function(a,c){var d=this.form.fields[a];if(!d)throw new Error("Unknown field "+a);var e=this.data[a]||[];return(""===c||c===b)&&(c=null),d.multiple?null!=c&&e.push(c):e=null!=c&&[c],this.data[a]=e,this},ref:function(a){return this.set("ref",a)},query:function(a){return this.set("q",a)},pageSize:function(a){return this.set("pageSize",a)},page:function(a){return this.set("page",a)},orderings:function(a){return this.set("orderings",a)},submit:function(a){var b=this.form.action;if(this.data){var c=b.indexOf("?")>-1?"&":"?";for(var d in this.data){var e=this.data[d];if(e)for(var h=0;h<e.length;h++)b+=c+d+"="+encodeURIComponent(e[h]),c="&"}}this.api.requestHandler(b,function(b,c,d){if(b)return a(b,null,d),void 0;var e=c.results.map(function(a){var b={};for(var c in a.data[a.type])b[a.type+"."+c]=a.data[a.type][c];return new g(a.id,a.type,a.href,a.tags,a.slugs,b)});a(null,new f(c.page,c.results_per_page,c.results_size,c.total_results_size,c.total_pages,c.next_page,c.prev_page,e||[]),d)})}},g.prototype={get:function(b){var c=e.call(this,b);return c.length?a.Prismic.Fragments.initField(c[0]):null},getAll:function(b){return e.call(this,b).map(function(b){return a.Prismic.Fragments.initField(b)},this)},getImage:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Image?c:c instanceof a.Prismic.Fragments.StructuredText?c:null},getAllImages:function(b){var c=this.getAll(b);return c.map(function(b){if(b instanceof a.Prismic.Fragments.Image)return b;if(b instanceof a.Prismic.Fragments.StructuredText)throw new Error("Not done.");return null})},getImageView:function(b,c){var b=this.get(b);if(b instanceof a.Prismic.Fragments.Image)return b.getView(c);if(b instanceof a.Prismic.Fragments.StructuredText)for(var d=0;d<b.blocks.length;d++)if("image"==b.blocks[d].type)return b.blocks[d];return null},getAllImageViews:function(a,b){return this.getAllImages(a).map(function(a){return a.getView(b)})},getDate:function(b){var b=this.get(b);return b instanceof a.Prismic.Fragments.Date?b.value:void 0},getBoolean:function(a){var a=this.get(a);return a.value&&("yes"==a.value.toLowerCase()||"on"==a.value.toLowerCase()||"true"==a.value.toLowerCase())},getText:function(b,c){var d=this.get(b);return d instanceof a.Prismic.Fragments.StructuredText?d.blocks.map(function(a){return a.text?a.text+(c?c:""):void 0}).join("\n"):d instanceof a.Prismic.Fragments.Text&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Number&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Select&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Color&&d.value?d.value+(c?c:""):void 0},getStructuredText:function(b){var b=this.get(b);return b instanceof a.Prismic.Fragments.StructuredText?b:void 0},getNumber:function(b){var b=this.get(b);return b instanceof a.Prismic.Fragments.Number?b.value:void 0},getColor:function(b){var b=this.get(b);return b instanceof a.Prismic.Fragments.Color?b.value:void 0},getGroup:function(b){var b=this.get(b);return b instanceof a.Prismic.Fragments.Group?b:void 0},getHtml:function(a,b){var a=this.get(a);return a&&a.asHtml?a.asHtml(b):void 0},asHtml:function(a){var b=[];for(var c in this.fragments){var d=this.get(c);b.push(d&&d.asHtml?'<section data-field="'+c+'">'+d.asHtml(a)+"</section>":"")}return b.join("")},asText:function(a){var b=[];for(var c in this.fragments){var d=this.get(c);b.push(d&&d.asText?d.asText(a):"")}return b.join("")}},h.prototype={},i.prototype={get:function(a){var b=this.cache[a];return b&&(!this.isExpired(a)||this.isExpired(a)&&this.isInProgress(a))?b.data:null},set:function(a,b,c){this.cache[a]={data:b,expiredIn:c?Date.now()+1e3*c:0}},getOrSet:function(a,b,c,d){var e=this.get(a),f=this;if(e)d&&d(null,e);else{this.states[a]="progress";{c(function(c,e,g){f.set(a,e,b),delete f.states[a],d&&d(c,e,g)})}}},isExpired:function(a){var b=this.cache[a];return b?0!=b.expiredIn&&b.expiredIn<Date.now():!1},isInProgress:function(a){return"progress"==this.states[a]},exists:function(a){return!!this.cache[a]},remove:function(a){return delete this.cache[a]},clear:function(){this.cache={}}},a.Prismic={Api:j}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(a){"use strict";function b(a){this.value=a}function c(a){this.value=a,this.document=a.document,this.isBroken=a.isBroken}function d(a){this.value=a}function e(a){this.value=a}function f(a){this.value=a}function g(a){this.value=a}function h(a){this.value=a}function i(a){this.value=a}function j(a){this.value=new Date(a)}function k(a){this.value=a}function l(a,b){this.main=a,this.views=b||{}}function m(a,b,c,d){this.url=a,this.width=b,this.height=c,this.alt=d}function n(a){this.value=a}function o(a,b){this.tag=a,this.blocks=b}function p(a){this.blocks=a}function q(a,b){var c,d,e=[],f=[];if(Array.isArray(a)){for(var g=0;g<a.length;g++)d=a[g],"list-item"!=d.type&&"o-list-item"!=d.type?(c=new o(d.type,[]),e.push(c)):c&&c.tag==d.type||(c=new o(d.type,[]),e.push(c)),c.blocks.push(d);e.forEach(function(a){if("heading1"==a.tag)f.push("<h1>"+r(a.blocks[0].text,a.blocks[0].spans,b)+"</h1>");else if("heading2"==a.tag)f.push("<h2>"+r(a.blocks[0].text,a.blocks[0].spans,b)+"</h2>");else if("heading3"==a.tag)f.push("<h3>"+r(a.blocks[0].text,a.blocks[0].spans,b)+"</h3>");else if("paragraph"==a.tag)f.push("<p>"+r(a.blocks[0].text,a.blocks[0].spans,b)+"</p>");else if("preformatted"==a.tag)f.push("<pre>"+a.blocks[0].text+"</pre>");else if("image"==a.tag)f.push('<p><img src="'+a.blocks[0].url+'" alt="'+a.blocks[0].alt+'"></p>');else if("embed"==a.tag)f.push('<div data-oembed="'+a.blocks[0].embed_url+'" data-oembed-type="'+a.blocks[0].type+'" data-oembed-provider="'+a.blocks[0].provider_name+'">'+a.blocks[0].oembed.html+"</div>");else{if("list-item"!=a.tag&&"o-list-item"!=a.tag)throw new Error(a.tag+" not implemented");f.push("list-item"==a.tag?"<ul>":"<ol>"),a.blocks.forEach(function(a){f.push("<li>"+r(a.text,a.spans,b)+"</li>")}),f.push("list-item"==a.tag?"</ul>":"</ol>")}})}return f.join("")}function r(a,b,c){var d=[],e=[],f=0,g=[];return b.forEach(function(b){return b.end<b.start?a:b.start<f?a:(f=b.end,void 0)}),f=0,b.forEach(function(b){d.push(a.substring(0,b.start-f)),a=a.substring(b.start-f),f=b.start,d.push(a.substring(0,b.end-f)),a=a.substring(b.end-f),e.push(b),f=b.end}),d.push(a),e.forEach(function(a){g.push(d.shift()),"hyperlink"==a.type?(g.push('<a href="'+s(a.data).url(c)+'">'),g.push(d.shift()),g.push("</a>")):(g.push("<"+a.type+">"),g.push(d.shift()),g.push("</"+a.type+">"))}),g.push(d.shift()),g.join("")}function s(a){var o,q;switch(a.type){case"Color":o=new h(a.value);break;case"Number":o=new i(a.value);break;case"Date":o=new j(a.value);break;case"Text":o=new b(a.value);break;case"Embed":o=new k(a.value);break;case"Select":o=new g(a.value);break;case"Image":var q=a.value.main;o=new l(new m(q.url,q.dimensions.width,q.dimensions.height,q.alt),{});for(var r in a.value.views){var q=a.value.views[r];o.views[r]=new m(q.url,q.dimensions.width,q.dimensions.height,q.alt)}break;case"StructuredText":o=new p(a.value);break;case"Link.document":o=new c(a.value);break;case"Link.web":o=new d(a.value);break;case"Link.file":o=new e(a.value);break;case"Link.image":o=new f(a.value);break;case"Group":for(var t=[],u=0;u<a.value.length;u++){var v={};for(var w in a.value[u])v[w]=s(a.value[u][w]);t.push(v)}o=new n(t);break;default:console.log("Fragment type not supported: ",a.type)}return o}b.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},c.prototype={asHtml:function(a){return'<a href="'+this.url(a)+'">'+this.url(a)+"</a>"},url:function(a){return a.linkResolver(a,this.document,this.isBroken)},asText:function(a){return this.url(a)}},d.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.url()+"</a>"},url:function(){return this.value.url},asText:function(){return this.url()}},e.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.value.file.name+"</a>"},url:function(){return this.value.file.url},asText:function(){return this.url()}},f.prototype={asHtml:function(){return'<a href="'+this.url()+'"><img src="'+this.url()+'" alt="'+this.alt+'"></a>'},url:function(){return this.value.image.url},asText:function(){return this.url()}},g.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},h.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},i.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value.toString()}},j.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return this.value.toString()}},k.prototype={asHtml:function(){return this.value.oembed.html},asText:function(){return""}},l.prototype={getView:function(a){return"main"===a?this.main:this.views[a]},asHtml:function(){return this.main.asHtml()},asText:function(){return""}},m.prototype={ratio:function(){return this.width/this.height},asHtml:function(){return"<img src="+this.url+" width="+this.width+" height="+this.height+' alt="'+this.alt+'">'},asText:function(){return""}},n.prototype={asHtml:function(a){for(var b="",c=0;c<this.value.length;c++)for(var d in this.value[c])b+='<section data-field="'+d+'">',b+=this.value[c][d].asHtml(a),b+="</section>";return b},toArray:function(){return this.value},asText:function(a){for(var b="",c=0;c<this.value.length;c++)for(var d in this.value[c])b+=this.value[c][d].asText(a);return b}},p.prototype={getTitle:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if(0==b.type.indexOf("heading"))return b}},getFirstParagraph:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if("paragraph"==b.type)return b}},getParagraphs:function(){for(var a=[],b=0;b<this.blocks.length;b++){var c=this.blocks[b];"paragraph"==c.type&&a.push(c)}return a},getParagraph:function(a){return this.getParagraphs()[a]},getFirstImage:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if("image"==b.type)return new m(b.url,b.dimensions.width,b.dimensions.height,b.alt)}},asHtml:function(a){return q.call(this,this.blocks,a)},asText:function(){for(var a=[],b=0;b<this.blocks.length;b++){var c=this.blocks[b];c.text&&a.push(c.text)}return a.join(" ")}},a.Prismic.Fragments={Image:l,ImageView:m,Text:b,Number:i,Date:j,Select:g,Color:h,StructuredText:p,WebLink:d,DocumentLink:c,ImageLink:f,FileLink:e,Group:n,initField:s}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window);
!function(a,b){"use strict";function c(a,b,c,d,e,f){this.name=a,this.fields=b,this.form_method=c,this.rel=d,this.enctype=e,this.action=f}function d(a,b,c){this.api=a,this.form=b,this.data=c||{};for(var d in b.fields)b.fields[d].default&&(this.data[d]=[b.fields[d].default])}function e(a){return this.fragments&&this.fragments[a]?Array.isArray(this.fragments[a])?this.fragments[a]:[this.fragments[a]]:[]}function f(a,b,c,d,e,f,g,h){this.page=a,this.results_per_page=b,this.results_size=c,this.total_results_size=d,this.total_pages=e,this.next_page=f,this.prev_page=g,this.results=h}function g(a,b,c,d){this.id=a,this.slug=b,this.type=c,this.tags=d}function h(a,b,c,d,e,f,g){this.id=a,this.type=b,this.href=c,this.tags=d,this.slug=e?e[0]:"-",this.slugs=e,this.linkedDocuments=f,this.fragments=g}function i(a,b,c,d,e){this.ref=a,this.label=b,this.isMaster=c,this.scheduledAt=d,this.id=e}function j(){this.cache={},this.states={}}var k=function(a,b,c,d,e){var f=new k.fn.init(a,c,d,e);return b&&f.get(b),f},l=function(){return"undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?function(a,b){var c=new XMLHttpRequest,d=function(){b(null,JSON.parse(c.responseText),c)},e=function(){var d=c.status;b(new Error("Unexpected status code ["+d+"] on URL "+a),null,c)};c.onreadystatechange=function(){4===c.readyState&&(c.status&&200==c.status?d():e())},c.open("GET",a,!0),c.setRequestHeader("Accept","application/json"),c.send()}:void 0},m=function(){return"undefined"!=typeof XDomainRequest?function(a,b){var c=new XDomainRequest,d=function(){b(null,JSON.parse(c.responseText),c)},e=function(a){b(new Error(a),null,c)};c.onload=function(){d(c)},c.onerror=function(){e("Unexpected status code on URL "+a)},c.open("GET",a,!0),c.ontimeout=function(){e("Request timeout")},c.onprogress=function(){},c.send()}:void 0},n=function(){if("function"==typeof require&&require("http")){{var a={},c=require("http"),d=require("https"),e=require("url");require("querystring")}return function(f,g){if(a[f])g(null,a[f]);else{var h=e.parse(f),i="https:"==h.protocol?d:c,j={hostname:h.hostname,path:h.path,query:h.query,headers:{Accept:"application/json"}};i.get(j,function(c){if(c.statusCode&&200==c.statusCode){var d="";c.setEncoding("utf8"),c.on("data",function(a){d+=a}),c.on("end",function(){var e=c.headers["cache-control"],h=e&&/max-age=(\d+)/.test(e)?parseInt(/max-age=(\d+)/.exec(e)[1]):b,i=JSON.parse(d);h&&(a[f]=i),g(null,i,c)})}else g(new Error("Unexpected status code ["+c.statusCode+"] on URL "+f),null,c)})}}}};k.fn=k.prototype={constructor:k,data:null,get:function(a){var b=this,c=this.url+(this.accessToken?"#"+this.accessToken:"");this.apiCache.getOrSet(c,5,function(a){b.requestHandler(b.url,function(c,d,e){c?a&&a(c,null,e):a&&a(null,b.parse(d),e)})},function(c,d,e){c?a&&a(c,null,e):(b.data=d,b.bookmarks=d.bookmarks,a&&a(null,b,e))})},parse:function(a){var b,d,e,f,g,h,j,k={};for(j in a.forms)a.forms.hasOwnProperty(j)&&(h=a.forms[j],this.accessToken&&(h.fields.accessToken={type:"string","default":this.accessToken}),e=new c(h.name,h.fields,h.form_method,h.rel,h.enctype,h.action),k[j]=e);if(b=a.refs.map(function(a){return new i(a.ref,a.label,a.isMasterRef,a.scheduledAt,a.id)})||[],d=b.filter(function(a){return a.isMaster===!0}),f=a.types,g=a.tags,0===d.length)throw"No master ref.";return{bookmarks:a.bookmarks||{},refs:b,forms:k,master:d[0],types:f,tags:g,oauthInitiate:a.oauth_initiate,oauthToken:a.oauth_token}},init:function(a,b,c,d){return this.url=a+(b?(a.indexOf("?")>-1?"&":"?")+"access_token="+b:""),this.accessToken=b,this.requestHandler=c||l()||m()||n()||function(){throw new Error("No request handler available (tried XMLHttpRequest & NodeJS)")}(),this.apiCache=d||new j,this},forms:function(a){return this.form(a)},form:function(a){var b=this.data.forms[a];return b?new d(this,b,{}):void 0},master:function(){return this.data.master.ref},ref:function(a){for(var b=0;b<this.data.refs.length;b++)if(this.data.refs[b].label==a)return this.data.refs[b].ref}},k.fn.init.prototype=k.fn,c.prototype={},d.prototype={set:function(a,c){var d=this.form.fields[a];if(!d)throw new Error("Unknown field "+a);var e=this.data[a]||[];return(""===c||c===b)&&(c=null),d.multiple?null!=c&&e.push(c):e=null!=c&&[c],this.data[a]=e,this},ref:function(a){return this.set("ref",a)},query:function(a){return this.set("q",a)},pageSize:function(a){return this.set("pageSize",a)},page:function(a){return this.set("page",a)},orderings:function(a){return this.set("orderings",a)},submit:function(a){var b=this.form.action;if(this.data){var c=b.indexOf("?")>-1?"&":"?";for(var d in this.data){var e=this.data[d];if(e)for(var i=0;i<e.length;i++)b+=c+d+"="+encodeURIComponent(e[i]),c="&"}}this.api.requestHandler(b,function(b,c,d){if(b)return a(b,null,d),void 0;var e=c.results.map(function(a){var b=[];a.linked_documents&&(b=a.linked_documents.map(function(a){return new g(a.id,a.slug,a.type,a.tags)}));var c={};for(var d in a.data[a.type])c[a.type+"."+d]=a.data[a.type][d];return new h(a.id,a.type,a.href,a.tags,a.slugs,b,c)});a(null,new f(c.page,c.results_per_page,c.results_size,c.total_results_size,c.total_pages,c.next_page,c.prev_page,e||[]),d)})}},h.prototype={get:function(b){var c=e.call(this,b);return c.length?a.Prismic.Fragments.initField(c[0]):null},getAll:function(b){return e.call(this,b).map(function(b){return a.Prismic.Fragments.initField(b)},this)},getImage:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Image?c:c instanceof a.Prismic.Fragments.StructuredText?c:null},getAllImages:function(b){var c=this.getAll(b);return c.map(function(b){if(b instanceof a.Prismic.Fragments.Image)return b;if(b instanceof a.Prismic.Fragments.StructuredText)throw new Error("Not done.");return null})},getImageView:function(b,c){var b=this.get(b);if(b instanceof a.Prismic.Fragments.Image)return b.getView(c);if(b instanceof a.Prismic.Fragments.StructuredText)for(var d=0;d<b.blocks.length;d++)if("image"==b.blocks[d].type)return b.blocks[d];return null},getAllImageViews:function(a,b){return this.getAllImages(a).map(function(a){return a.getView(b)})},getDate:function(b){var b=this.get(b);return b instanceof a.Prismic.Fragments.Date?b.value:void 0},getBoolean:function(a){var a=this.get(a);return a.value&&("yes"==a.value.toLowerCase()||"on"==a.value.toLowerCase()||"true"==a.value.toLowerCase())},getText:function(b,c){var d=this.get(b);return d instanceof a.Prismic.Fragments.StructuredText?d.blocks.map(function(a){return a.text?a.text+(c?c:""):void 0}).join("\n"):d instanceof a.Prismic.Fragments.Text&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Number&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Select&&d.value?d.value+(c?c:""):d instanceof a.Prismic.Fragments.Color&&d.value?d.value+(c?c:""):void 0},getStructuredText:function(b){var b=this.get(b);return b instanceof a.Prismic.Fragments.StructuredText?b:void 0},getNumber:function(b){var b=this.get(b);return b instanceof a.Prismic.Fragments.Number?b.value:void 0},getColor:function(b){var b=this.get(b);return b instanceof a.Prismic.Fragments.Color?b.value:void 0},getGroup:function(b){var b=this.get(b);return b instanceof a.Prismic.Fragments.Group?b:void 0},getHtml:function(a,b){var a=this.get(a);return a&&a.asHtml?a.asHtml(b):void 0},asHtml:function(a){var b=[];for(var c in this.fragments){var d=this.get(c);b.push(d&&d.asHtml?'<section data-field="'+c+'">'+d.asHtml(a)+"</section>":"")}return b.join("")},asText:function(a){var b=[];for(var c in this.fragments){var d=this.get(c);b.push(d&&d.asText?d.asText(a):"")}return b.join("")}},i.prototype={},j.prototype={get:function(a){var b=this.cache[a];return b&&(!this.isExpired(a)||this.isExpired(a)&&this.isInProgress(a))?b.data:null},set:function(a,b,c){this.cache[a]={data:b,expiredIn:c?Date.now()+1e3*c:0}},getOrSet:function(a,b,c,d){var e=this.get(a),f=this;if(e)d&&d(null,e);else{this.states[a]="progress";{c(function(c,e,g){f.set(a,e,b),delete f.states[a],d&&d(c,e,g)})}}},isExpired:function(a){var b=this.cache[a];return b?0!=b.expiredIn&&b.expiredIn<Date.now():!1},isInProgress:function(a){return"progress"==this.states[a]},exists:function(a){return!!this.cache[a]},remove:function(a){return delete this.cache[a]},clear:function(){this.cache={}}},a.Prismic={Api:k}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window),function(a){"use strict";function b(a){this.value=a}function c(a){this.value=a,this.document=a.document,this.isBroken=a.isBroken}function d(a){this.value=a}function e(a){this.value=a}function f(a){this.value=a}function g(a){this.value=a}function h(a){this.value=a}function i(a){this.value=a}function j(a){this.value=new Date(a)}function k(a){this.value=a}function l(a,b){this.main=a,this.views=b||{}}function m(a,b,c,d){this.url=a,this.width=b,this.height=c,this.alt=d}function n(a){this.value=a}function o(a,b){this.tag=a,this.blocks=b}function p(a){this.blocks=a}function q(a,b){var c,d,e=[],f=[];if(Array.isArray(a)){for(var g=0;g<a.length;g++)d=a[g],"list-item"!=d.type&&"o-list-item"!=d.type?(c=new o(d.type,[]),e.push(c)):c&&c.tag==d.type||(c=new o(d.type,[]),e.push(c)),c.blocks.push(d);e.forEach(function(a){if("heading1"==a.tag)f.push("<h1>"+r(a.blocks[0].text,a.blocks[0].spans,b)+"</h1>");else if("heading2"==a.tag)f.push("<h2>"+r(a.blocks[0].text,a.blocks[0].spans,b)+"</h2>");else if("heading3"==a.tag)f.push("<h3>"+r(a.blocks[0].text,a.blocks[0].spans,b)+"</h3>");else if("paragraph"==a.tag)f.push("<p>"+r(a.blocks[0].text,a.blocks[0].spans,b)+"</p>");else if("preformatted"==a.tag)f.push("<pre>"+a.blocks[0].text+"</pre>");else if("image"==a.tag)f.push('<p><img src="'+a.blocks[0].url+'" alt="'+a.blocks[0].alt+'"></p>');else if("embed"==a.tag)f.push('<div data-oembed="'+a.blocks[0].embed_url+'" data-oembed-type="'+a.blocks[0].type+'" data-oembed-provider="'+a.blocks[0].provider_name+'">'+a.blocks[0].oembed.html+"</div>");else{if("list-item"!=a.tag&&"o-list-item"!=a.tag)throw new Error(a.tag+" not implemented");f.push("list-item"==a.tag?"<ul>":"<ol>"),a.blocks.forEach(function(a){f.push("<li>"+r(a.text,a.spans,b)+"</li>")}),f.push("list-item"==a.tag?"</ul>":"</ol>")}})}return f.join("")}function r(a,b,c){var d=[],e=[],f=0,g=[];return b.forEach(function(b){return b.end<b.start?a:b.start<f?a:(f=b.end,void 0)}),f=0,b.forEach(function(b){d.push(a.substring(0,b.start-f)),a=a.substring(b.start-f),f=b.start,d.push(a.substring(0,b.end-f)),a=a.substring(b.end-f),e.push(b),f=b.end}),d.push(a),e.forEach(function(a){g.push(d.shift()),"hyperlink"==a.type?(g.push('<a href="'+s(a.data).url(c)+'">'),g.push(d.shift()),g.push("</a>")):(g.push("<"+a.type+">"),g.push(d.shift()),g.push("</"+a.type+">"))}),g.push(d.shift()),g.join("")}function s(a){var o,q;switch(a.type){case"Color":o=new h(a.value);break;case"Number":o=new i(a.value);break;case"Date":o=new j(a.value);break;case"Text":o=new b(a.value);break;case"Embed":o=new k(a.value);break;case"Select":o=new g(a.value);break;case"Image":var q=a.value.main;o=new l(new m(q.url,q.dimensions.width,q.dimensions.height,q.alt),{});for(var r in a.value.views){var q=a.value.views[r];o.views[r]=new m(q.url,q.dimensions.width,q.dimensions.height,q.alt)}break;case"StructuredText":o=new p(a.value);break;case"Link.document":o=new c(a.value);break;case"Link.web":o=new d(a.value);break;case"Link.file":o=new e(a.value);break;case"Link.image":o=new f(a.value);break;case"Group":for(var t=[],u=0;u<a.value.length;u++){var v={};for(var w in a.value[u])v[w]=s(a.value[u][w]);t.push(v)}o=new n(t);break;default:console.log("Fragment type not supported: ",a.type)}return o}b.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},c.prototype={asHtml:function(a){return'<a href="'+this.url(a)+'">'+this.url(a)+"</a>"},url:function(a){return a.linkResolver(a,this.document,this.isBroken)},asText:function(a){return this.url(a)}},d.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.url()+"</a>"},url:function(){return this.value.url},asText:function(){return this.url()}},e.prototype={asHtml:function(){return'<a href="'+this.url()+'">'+this.value.file.name+"</a>"},url:function(){return this.value.file.url},asText:function(){return this.url()}},f.prototype={asHtml:function(){return'<a href="'+this.url()+'"><img src="'+this.url()+'" alt="'+this.alt+'"></a>'},url:function(){return this.value.image.url},asText:function(){return this.url()}},g.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},h.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value}},i.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value.toString()}},j.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return this.value.toString()}},k.prototype={asHtml:function(){return this.value.oembed.html},asText:function(){return""}},l.prototype={getView:function(a){return"main"===a?this.main:this.views[a]},asHtml:function(){return this.main.asHtml()},asText:function(){return""}},m.prototype={ratio:function(){return this.width/this.height},asHtml:function(){return"<img src="+this.url+" width="+this.width+" height="+this.height+' alt="'+this.alt+'">'},asText:function(){return""}},n.prototype={asHtml:function(a){for(var b="",c=0;c<this.value.length;c++)for(var d in this.value[c])b+='<section data-field="'+d+'">',b+=this.value[c][d].asHtml(a),b+="</section>";return b},toArray:function(){return this.value},asText:function(a){for(var b="",c=0;c<this.value.length;c++)for(var d in this.value[c])b+=this.value[c][d].asText(a);return b}},p.prototype={getTitle:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if(0==b.type.indexOf("heading"))return b}},getFirstParagraph:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if("paragraph"==b.type)return b}},getParagraphs:function(){for(var a=[],b=0;b<this.blocks.length;b++){var c=this.blocks[b];"paragraph"==c.type&&a.push(c)}return a},getParagraph:function(a){return this.getParagraphs()[a]},getFirstImage:function(){for(var a=0;a<this.blocks.length;a++){var b=this.blocks[a];if("image"==b.type)return new m(b.url,b.dimensions.width,b.dimensions.height,b.alt)}},asHtml:function(a){return q.call(this,this.blocks,a)},asText:function(){for(var a=[],b=0;b<this.blocks.length;b++){var c=this.blocks[b];c.text&&a.push(c.text)}return a.join(" ")}},a.Prismic.Fragments={Image:l,ImageView:m,Text:b,Number:i,Date:j,Select:g,Color:h,StructuredText:p,WebLink:d,DocumentLink:c,ImageLink:f,FileLink:e,Group:n,initField:s}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window);

@@ -12,3 +12,3 @@ {

],
"version": "1.0.11",
"version": "1.0.12",
"devDependencies": {

@@ -15,0 +15,0 @@ "grunt": "~0.4.1",

@@ -96,3 +96,3 @@ (function (Global, undefined) {

// Bind the XDR timeout callback
xdr.ontimeout = function () {
xdr.ontimeout = function () {
reject("Request timeout");

@@ -251,3 +251,4 @@ };

r.isMasterRef,
r.scheduledAt
r.scheduledAt,
r.id
);

@@ -471,3 +472,3 @@ }) || [];

* to which you may pass three parameters: a potential error (null if no problem),
* a Documents object (containing all the pagination specifics + the array of Docs),
* a Response object (containing all the pagination specifics + the array of Docs),
* and the XMLHttpRequest

@@ -497,4 +498,11 @@ */

var results = documents.results.map(function (doc) {
var linkedDocuments = [];
if(doc.linked_documents) {
linkedDocuments = doc.linked_documents.map(function(linkedDoc) {
return new LinkedDocument(linkedDoc['id'], linkedDoc['slug'], linkedDoc['type'], linkedDoc['tags']);
});
}
var fragments = {};
for(var field in doc.data[doc.type]) {

@@ -510,2 +518,3 @@ fragments[doc.type + '.' + field] = doc.data[doc.type][field];

doc.slugs,
linkedDocuments,
fragments

@@ -515,3 +524,3 @@ );

callback(null, new Documents(
callback(null, new Response(
documents.page,

@@ -551,3 +560,3 @@ documents.results_per_page,

/**
* Embodies the result of a SearchForm query as returned by the API.
* Embodies the response of a SearchForm query as returned by the API.
* It includes all the fields that are useful for pagination (page, total_pages, total_results_size, ...),

@@ -558,3 +567,3 @@ * as well as the field "results", which is an array of Doc objects, the documents themselves.

*/
function Documents(page, results_per_page, results_size, total_results_size, total_pages, next_page, prev_page, results) {
function Response(page, results_per_page, results_size, total_results_size, total_pages, next_page, prev_page, results) {
/**

@@ -602,2 +611,9 @@ * @field

function LinkedDocument(id, slug, type, tags) {
this.id = id;
this.slug = slug;
this.type = type;
this.tags = tags;
}
/**

@@ -610,3 +626,3 @@ * Embodies a document as returned by the API.

*/
function Doc(id, type, href, tags, slugs, fragments) {
function Doc(id, type, href, tags, slugs, linkedDocuments, fragments) {

@@ -643,2 +659,3 @@ /**

this.slugs = slugs;
this.linkedDocuments = linkedDocuments;
this.fragments = fragments;

@@ -923,3 +940,3 @@ }

*/
function Ref(ref, label, isMaster, scheduledAt) {
function Ref(ref, label, isMaster, scheduledAt, id) {
/**

@@ -945,2 +962,7 @@ * @field

this.scheduledAt = scheduledAt;
/**
* @field
* @description the name of the ref
*/
this.id = id;
}

@@ -947,0 +969,0 @@ Ref.prototype = {};

@@ -90,2 +90,15 @@ (function(Prismic) {

asyncTest('Get linked documents', 2, function() {
Prismic.Api("https://micro.prismic.io/api", function(err, Api) {
if (err) { console.log(err); return; }
Api.form('everything').query('[[:d = any(document.type, ["doc","docchapter"])]]').ref(Api.master()).submit(function(err, response) {
if (err) { console.log(err); return; }
var document = response.results[0];
equal(document.linkedDocuments.length, 1);
equal(document.linkedDocuments[0].id, 'U0w8OwEAACoAQEvB');
start();
});
});
});
asyncTest('Submit the `everything` form with an ordering', 2, function() {

@@ -92,0 +105,0 @@ Prismic.Api(testRepository, function(err, Api) {

Sorry, the diff of this file is too big to display

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