Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.17 to 1.0.18

dist/prismic.io.18.min.js

2

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

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

/*!
* prismic.io 1.0.16
* prismic.io 1.0.18
* 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){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"),f=(require("querystring"),require("../package.json"));return function(g,h){if(a[g])h(null,a[g]);else{var i=e.parse(g),j="https:"==i.protocol?d:c,k={hostname:i.hostname,path:i.path,query:i.query,headers:{Accept:"application/json","User-Agent":"Prismic-javascript-kit/"+f.version+" NodeJS/"+process.version}};j.get(k,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"],f=e&&/max-age=(\d+)/.test(e)?parseInt(/max-age=(\d+)/.exec(e)[1]):b,i=JSON.parse(d);f&&(a[g]=i),h(null,i,c)})}else h(new Error("Unexpected status code ["+c.statusCode+"] on URL "+g),null,c)})}}}};k.fn=k.prototype={AT:"at",ANY:"any",EVERYTHING:"everything",SIMILAR:"similar",FULLTEXT:"fulltext",NUMBER:{GT:"number.gt",LT:"number.lt"},DATE:{AFTER:"date.after",BEFORE:"date.before",BETWEEN:"date.between"},DOCUMENT:{ID:"document.id",TYPE:"document.type",TAGS:"document.tags"},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.access_token={},h.fields.access_token.type="string",h.fields.access_token["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){if("string"==typeof a)return this.set("q",a);var b="string"==typeof a[0]?[a]:a,c=[];return b.forEach(function(a){var b=0==a[1].indexOf("my.")||0==a[1].indexOf("document.")?a[1]:'"'+a[1]+'"';c.push("[:d = "+a[0]+"("+b+", "+function(){return a.slice(2).map(function(a){return"string"==typeof a?'"'+a+'"':Array.isArray(a)?"["+a.map(function(a){return'"'+a+'"'}).join(",")+"]":a}).join(",")}()+")]")}),this.query("["+c.join("")+"]")},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 void a(b,null,d);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];for(var e in c){var f=c[e];if("StructuredText"===f.type)for(var i in f.value){var j=f.value[i],k=[];for(var l in j.spans){var m=j.spans[l];m.start<m.end&&k.push(m)}j.spans=k}}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 d=this.get(b);if(d instanceof a.Prismic.Fragments.Image)return d.getView(c);if(d instanceof a.Prismic.Fragments.StructuredText)for(var e=0;e<d.blocks.length;e++)if("image"==d.blocks[e].type)return d.blocks[e];return null},getAllImageViews:function(a,b){return this.getAllImages(a).map(function(a){return a.getView(b)})},getDate:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Date?c.value:void 0},getBoolean:function(a){var b=this.get(a);return b.value&&("yes"==b.value.toLowerCase()||"on"==b.value.toLowerCase()||"true"==b.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 c=this.get(b);return c instanceof a.Prismic.Fragments.StructuredText?c:void 0},getNumber:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Number?c.value:void 0},getColor:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Color?c.value:void 0},getGeoPoint:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.GeoPoint?c:void 0},getGroup:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Group?c:void 0},getHtml:function(a,b){var c=this.get(a);return c&&c.asHtml?c.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,b){this.latitude=a,this.longitude=b}function j(a){this.value=a}function k(a){this.value=new Date(a)}function l(a){var b=24==a.length?a.substring(0,22)+":"+a.substring(22,24):a;this.value=new Date(b)}function m(a){this.value=a}function n(a,b){this.main=a,this.views=b||{}}function o(a,b,c,d){this.url=a,this.width=b,this.height=c,this.alt=d}function p(a){this.value=a}function q(a){this.blocks=a}function r(a,b,c,d){if(!b||!b.length)return a;var e={},f={};b.forEach(function(a){e[a.start]||(e[a.start]=[]),f[a.end]||(f[a.end]=[]),e[a.start].push(a),f[a.end].unshift(a)});for(var g,h="",i=[],j=0,k=a.length+1;k>j;j++)f[j]&&f[j].forEach(function(){var a=i.pop(),b=t(a.span,a.text,d);0==i.length?h+=b:i[i.length-1].text+=b}),e[j]&&(e[j].sort(function(a,b){return b.end-b.start-(a.end-a.start)}),e[j].forEach(function(a){var b=null;if("hyperlink"==a.type){var d=s(a.data);if(!d)return console&&console.error&&console.error("Impossible to convert span.data as a Fragment",a),"";b=d.url(c),a.url=b}var e={span:a,text:""};i.push(e)})),j<a.length&&(g=a[j],0==i.length?h+=g:i[i.length-1].text+=g);return h}function s(a){var r,t;switch(a.type){case"Color":r=new h(a.value);break;case"Number":r=new j(a.value);break;case"Date":r=new k(a.value);break;case"Timestamp":r=new l(a.value);break;case"Text":r=new b(a.value);break;case"Embed":r=new m(a.value);break;case"GeoPoint":r=new i(a.value.latitude,a.value.longitude);break;case"Select":r=new g(a.value);break;case"Image":t=a.value.main,r=new n(new o(t.url,t.dimensions.width,t.dimensions.height,t.alt),{});for(var u in a.value.views)t=a.value.views[u],r.views[u]=new o(t.url,t.dimensions.width,t.dimensions.height,t.alt);break;case"StructuredText":r=new q(a.value);break;case"Link.document":r=new c(a.value);break;case"Link.web":r=new d(a.value);break;case"Link.file":r=new e(a.value);break;case"Link.image":r=new f(a.value);break;case"Group":for(var v=[],w=0;w<a.value.length;w++){var x={};for(var y in a.value[w])x[y]=s(a.value[w][y]);v.push(x)}r=new p(v);break;default:console&&console.log&&console.log("Fragment type not supported: ",a.type)}return r}function t(a,b,c){if(c){var d=c(a,b);if(d)return d}var e={heading1:"h1",heading2:"h2",heading3:"h3",heading4:"h4",heading5:"h5",heading6:"h6",paragraph:"p",preformatted:"pre","list-item":"li","o-list-item":"li","group-list-item":"ul","group-o-list-item":"ol",strong:"strong",em:"em"};if(e[a.type]){var f=e[a.type],g=a.label?' class="'+a.label+'"':"";return"<"+f+g+">"+b+"</"+f+">"}if("image"==a.type){var h=a.label?" "+a.label:"",i='<img src="'+a.url+'" alt="'+a.alt+'">';return'<p class="block-img'+h+'">'+(a.linkUrl?'<a href="'+a.linkUrl+'">'+i+"</a>":i)+"</p>"}return"embed"==a.type?'<div data-oembed="'+a.embed_url+'" data-oembed-type="'+a.type+'" data-oembed-provider="'+a.provider_name+(a.label?'" class="'+h:"")+'">'+a.oembed.html+"</div>":"hyperlink"===a.type?'<a href="'+a.url+'">'+b+"</a>":"span"===a.type?'<span class="'+span.label+'">'+b+"</span>":"<!-- Warning: "+a.type+" not implemented. Upgrade the Developer Kit. -->"+b}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'<div class="geopoint"><span class="latitude">'+this.latitude+'</span><span class="longitude">'+this.longitude+"</span></div>"},asText:function(){return"("+this.latitude+","+this.longitude+")"}},j.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value.toString()}},k.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return this.value.toString()}},l.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return this.value.toString()}},m.prototype={asHtml:function(){return this.value.oembed.html},asText:function(){return""}},n.prototype={getView:function(a){return"main"===a?this.main:this.views[a]},asHtml:function(){return this.main.asHtml()},asText:function(){return""}},o.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""}},p.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}},q.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 o(b.url,b.dimensions.width,b.dimensions.height,b.alt)}},asHtml:function(a,b){var c,d,e=[],f=[];if(Array.isArray(this.blocks)){for(var g=0;g<this.blocks.length;g++){if(d=this.blocks[g],"image"==d.type&&d.linkTo){var h=s(d.linkTo);d.linkUrl=h.url(a)}"list-item"!=d.type&&"o-list-item"!=d.type?e.push(d):c&&c.type=="group-"+d.type?c.blocks.push(d):(c={type:"group-"+d.type,blocks:[d]},e.push(c))}var i=function(c){var d="";return c.blocks?c.blocks.forEach(function(a){d+=t(a,i(a),b)}):d=r(c.text,c.spans,a,b),d};e.forEach(function(a){f.push(t(a,i(a),b))})}return f.join("")},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:n,ImageView:o,Text:b,Number:j,Date:k,Timestamp:l,Select:g,Color:h,StructuredText:q,WebLink:d,DocumentLink:c,ImageLink:f,FileLink:e,Group:p,GeoPoint:i,initField:s,insertSpans:r}}("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"),f=(require("querystring"),require("../package.json"));return function(g,h){if(a[g])h(null,a[g]);else{var i=e.parse(g),j="https:"==i.protocol?d:c,k={hostname:i.hostname,path:i.path,query:i.query,headers:{Accept:"application/json","User-Agent":"Prismic-javascript-kit/"+f.version+" NodeJS/"+process.version}};j.get(k,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"],f=e&&/max-age=(\d+)/.test(e)?parseInt(/max-age=(\d+)/.exec(e)[1]):b,i=JSON.parse(d);f&&(a[g]=i),h(null,i,c)})}else h(new Error("Unexpected status code ["+c.statusCode+"] on URL "+g),null,c)})}}}};k.fn=k.prototype={AT:"at",ANY:"any",EVERYTHING:"everything",SIMILAR:"similar",FULLTEXT:"fulltext",NUMBER:{GT:"number.gt",LT:"number.lt"},DATE:{AFTER:"date.after",BEFORE:"date.before",BETWEEN:"date.between"},DOCUMENT:{ID:"document.id",TYPE:"document.type",TAGS:"document.tags"},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.access_token={},h.fields.access_token.type="string",h.fields.access_token["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){if("string"==typeof a)return this.set("q",a);var b="string"==typeof a[0]?[a]:a,c=[];return b.forEach(function(a){var b=0==a[1].indexOf("my.")||0==a[1].indexOf("document.")?a[1]:'"'+a[1]+'"';c.push("[:d = "+a[0]+"("+b+", "+function(){return a.slice(2).map(function(a){return"string"==typeof a?'"'+a+'"':Array.isArray(a)?"["+a.map(function(a){return'"'+a+'"'}).join(",")+"]":a}).join(",")}()+")]")}),this.query("["+c.join("")+"]")},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 void a(b,null,d);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];for(var e in c){var f=c[e];if("StructuredText"===f.type)for(var i in f.value){var j=f.value[i],k=[];for(var l in j.spans){var m=j.spans[l];m.start<m.end&&k.push(m)}j.spans=k}}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 d=this.get(b);if(d instanceof a.Prismic.Fragments.Image)return d.getView(c);if(d instanceof a.Prismic.Fragments.StructuredText)for(var e=0;e<d.blocks.length;e++)if("image"==d.blocks[e].type)return d.blocks[e];return null},getAllImageViews:function(a,b){return this.getAllImages(a).map(function(a){return a.getView(b)})},getDate:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Date?c.value:void 0},getBoolean:function(a){var b=this.get(a);return b.value&&("yes"==b.value.toLowerCase()||"on"==b.value.toLowerCase()||"true"==b.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 c=this.get(b);return c instanceof a.Prismic.Fragments.StructuredText?c:void 0},getNumber:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Number?c.value:void 0},getColor:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Color?c.value:void 0},getGeoPoint:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.GeoPoint?c:void 0},getGroup:function(b){var c=this.get(b);return c instanceof a.Prismic.Fragments.Group?c:void 0},getHtml:function(a,b){var c=this.get(a);return c&&c.asHtml?c.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,b){this.latitude=a,this.longitude=b}function j(a){this.value=a}function k(a){this.value=new Date(a)}function l(a){var b=24==a.length?a.substring(0,22)+":"+a.substring(22,24):a;this.value=new Date(b)}function m(a){this.value=a}function n(a,b){this.main=a,this.views=b||{}}function o(a,b,c,d){this.url=a,this.width=b,this.height=c,this.alt=d}function p(a){this.value=a}function q(a){this.blocks=a}function r(a){return a&&a.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function s(a,b,c,d){if(!b||!b.length)return r(a);var e={},f={};b.forEach(function(a){e[a.start]||(e[a.start]=[]),f[a.end]||(f[a.end]=[]),e[a.start].push(a),f[a.end].unshift(a)});for(var g,h="",i=[],j=0,k=a.length+1;k>j;j++)f[j]&&f[j].forEach(function(){var a=i.pop(),b=u(a.span,a.text,d);0==i.length?h+=b:i[i.length-1].text+=b}),e[j]&&(e[j].sort(function(a,b){return b.end-b.start-(a.end-a.start)}),e[j].forEach(function(a){var b=null;if("hyperlink"==a.type){var d=t(a.data);if(!d)return console&&console.error&&console.error("Impossible to convert span.data as a Fragment",a),"";b=d.url(c),a.url=b}var e={span:a,text:""};i.push(e)})),j<a.length&&(g=a[j],0==i.length?h+=r(g):i[i.length-1].text+=r(g));return h}function t(a){var r,s;switch(a.type){case"Color":r=new h(a.value);break;case"Number":r=new j(a.value);break;case"Date":r=new k(a.value);break;case"Timestamp":r=new l(a.value);break;case"Text":r=new b(a.value);break;case"Embed":r=new m(a.value);break;case"GeoPoint":r=new i(a.value.latitude,a.value.longitude);break;case"Select":r=new g(a.value);break;case"Image":s=a.value.main,r=new n(new o(s.url,s.dimensions.width,s.dimensions.height,s.alt),{});for(var u in a.value.views)s=a.value.views[u],r.views[u]=new o(s.url,s.dimensions.width,s.dimensions.height,s.alt);break;case"StructuredText":r=new q(a.value);break;case"Link.document":r=new c(a.value);break;case"Link.web":r=new d(a.value);break;case"Link.file":r=new e(a.value);break;case"Link.image":r=new f(a.value);break;case"Group":for(var v=[],w=0;w<a.value.length;w++){var x={};for(var y in a.value[w])x[y]=t(a.value[w][y]);v.push(x)}r=new p(v);break;default:console&&console.log&&console.log("Fragment type not supported: ",a.type)}return r}function u(a,b,c){if(c){var d=c(a,b);if(d)return d}var e={heading1:"h1",heading2:"h2",heading3:"h3",heading4:"h4",heading5:"h5",heading6:"h6",paragraph:"p",preformatted:"pre","list-item":"li","o-list-item":"li","group-list-item":"ul","group-o-list-item":"ol",strong:"strong",em:"em"};if(e[a.type]){var f=e[a.type],g=a.label?' class="'+a.label+'"':"";return"<"+f+g+">"+b+"</"+f+">"}if("image"==a.type){var h=a.label?" "+a.label:"",i='<img src="'+a.url+'" alt="'+a.alt+'">';return'<p class="block-img'+h+'">'+(a.linkUrl?'<a href="'+a.linkUrl+'">'+i+"</a>":i)+"</p>"}return"embed"==a.type?'<div data-oembed="'+a.embed_url+'" data-oembed-type="'+a.type+'" data-oembed-provider="'+a.provider_name+(a.label?'" class="'+h:"")+'">'+a.oembed.html+"</div>":"hyperlink"===a.type?'<a href="'+a.url+'">'+b+"</a>":"span"===a.type?'<span class="'+span.label+'">'+b+"</span>":"<!-- Warning: "+a.type+" not implemented. Upgrade the Developer Kit. -->"+b}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'<div class="geopoint"><span class="latitude">'+this.latitude+'</span><span class="longitude">'+this.longitude+"</span></div>"},asText:function(){return"("+this.latitude+","+this.longitude+")"}},j.prototype={asHtml:function(){return"<span>"+this.value+"</span>"},asText:function(){return this.value.toString()}},k.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return this.value.toString()}},l.prototype={asHtml:function(){return"<time>"+this.value+"</time>"},asText:function(){return this.value.toString()}},m.prototype={asHtml:function(){return this.value.oembed.html},asText:function(){return""}},n.prototype={getView:function(a){return"main"===a?this.main:this.views[a]},asHtml:function(){return this.main.asHtml()},asText:function(){return""}},o.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""}},p.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}},q.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 o(b.url,b.dimensions.width,b.dimensions.height,b.alt)}},asHtml:function(a,b){var c,d,e=[],f=[];if(Array.isArray(this.blocks)){for(var g=0;g<this.blocks.length;g++){if(d=this.blocks[g],"image"==d.type&&d.linkTo){var h=t(d.linkTo);d.linkUrl=h.url(a)}"list-item"!==d.type&&"o-list-item"!==d.type?(e.push(d),c=null):c&&c.type=="group-"+d.type?c.blocks.push(d):(c={type:"group-"+d.type,blocks:[d]},e.push(c))}var i=function(c){var d="";return c.blocks?c.blocks.forEach(function(a){d+=u(a,i(a),b)}):d=s(c.text,c.spans,a,b),d};e.forEach(function(a){f.push(u(a,i(a),b))})}return f.join("")},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:n,ImageView:o,Text:b,Number:j,Date:k,Timestamp:l,Select:g,Color:h,StructuredText:q,WebLink:d,DocumentLink:c,ImageLink:f,FileLink:e,Group:p,GeoPoint:i,initField:t,insertSpans:s}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window);

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

],
"version": "1.0.17",
"version": "1.0.18",
"devDependencies": {

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

@@ -693,3 +693,2 @@ (function (Global, undefined) {

html = [];
if (Array.isArray(this.blocks)) {

@@ -706,5 +705,6 @@

if (block.type != "list-item" && block.type != "o-list-item") {
if (block.type !== "list-item" && block.type !== "o-list-item") {
// it's not a type that groups
blockGroups.push(block);
blockGroup = null;
} else if (!blockGroup || blockGroup.type != ("group-" + block.type)) {

@@ -763,2 +763,5 @@ // it's a new type or no BlockGroup was set so far

function htmlEscape(input) {
return input && input.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}

@@ -776,3 +779,3 @@ /**

if (!spans || !spans.length) {
return text;
return htmlEscape(text);
}

@@ -838,6 +841,6 @@

// Top-level text
html += c;
html += htmlEscape(c);
} else {
// Inner text of a span
stack[stack.length - 1].text += c;
stack[stack.length - 1].text += htmlEscape(c);
}

@@ -844,0 +847,0 @@ }

@@ -368,3 +368,5 @@ (function(Prismic) {

if (err) { console.log(err); return; }
equal(documents.results[0].getStructuredText('doc.content').asHtml(ctx), '<p>Meta-micro gets installed pretty much like any javascript library:</p><ol><li><a href=\"/testing_url/U0w8OwEAACoAQEvB/download-meta-micro?ref=XXXXX\">download</a> the .js file: get the minified one, unless the framework you\'re using minifies your .js files automatically.</li><li>add a link towards the file in your webpage\'s head.</li></ol><p>The link might look like this, anywhere inside your head tag:</p><pre><script type=\"text/javascript\" src=\"meta-micro.min.js\"></script></pre><p>You\'re all set!</p>');
equal(
documents.results[0].getStructuredText('doc.content').asHtml(ctx),
'<p>Meta-micro gets installed pretty much like any javascript library:</p><ol><li><a href=\"/testing_url/U0w8OwEAACoAQEvB/download-meta-micro?ref=XXXXX\">download</a> the .js file: get the minified one, unless the framework you\'re using minifies your .js files automatically.</li><li>add a link towards the file in your webpage\'s head.</li></ol><p>The link might look like this, anywhere inside your head tag:</p><pre>&lt;script type=\"text/javascript\" src=\"meta-micro.min.js\"&gt;&lt;/script&gt;</pre><p>You\'re all set!</p>');
start();

@@ -479,6 +481,17 @@ });

var jsonObject = JSON.parse(jsonString);
equal(Prismic.Fragments.initField(jsonObject).asHtml(), '<p><a href=\"https://prismic-io.s3.amazonaws.com/annual.report.pdf\">2012 Annual Report</a></p><p><a href=\"https://prismic-io.s3.amazonaws.com/annual.budget.pdf\">2012 Annual Budget</a></p><p><a href=\"https://prismic-io.s3.amazonaws.com/vision.strategic.plan_.sm_.pdf\">2015 Vision & Strategic Plan</a></p>');
equal(Prismic.Fragments.initField(jsonObject).asHtml(), '<p><a href=\"https://prismic-io.s3.amazonaws.com/annual.report.pdf\">2012 Annual Report</a></p><p><a href=\"https://prismic-io.s3.amazonaws.com/annual.budget.pdf\">2012 Annual Budget</a></p><p><a href=\"https://prismic-io.s3.amazonaws.com/vision.strategic.plan_.sm_.pdf\">2015 Vision &amp; Strategic Plan</a></p>');
start();
});
asyncTest('Proper escaping in asHtml', 1, function() {
var jsonString = "{ \"type\": \"StructuredText\", \"value\": [ { \"type\": \"paragraph\", \"text\": \"<not a real tag>\", \"spans\": [] } ]}";
var jsonObject = JSON.parse(jsonString);
var text = Prismic.Fragments.initField(jsonObject);
equal(
text.asHtml(),
"<p>&lt;not a real tag&gt;</p>"
);
start();
});
asyncTest('Handles multiple fields', 1, function() {

@@ -519,2 +532,9 @@ Prismic.Api(testRepository, function(err, Api) {

test('List items are correctly grouped', function() {
var jsonString = '{ "type":"StructuredText", "value":[ { "spans":[], "text":"Here is some introductory text.", "type":"paragraph" }, { "spans":[], "text":"first item", "type":"list-item" }, { "spans":[], "text":"second item", "type":"list-item" }, { "spans":[], "text":"The following image is linked.", "type":"paragraph" }, { "spans":[], "text":"first item 2", "type":"list-item" }, { "spans":[], "text":"second item 2", "type":"list-item" } ] }';
var jsonObject = JSON.parse(jsonString);
var text = Prismic.Fragments.initField(jsonObject);
equal(text.asHtml(ctx), '<p>Here is some introductory text.</p><ul><li>first item</li><li>second item</li></ul><p>The following image is linked.</p><ul><li>first item 2</li><li>second item 2</li></ul>');
});
asyncTest('ImageViews are well retrieved', 2, function() {

@@ -521,0 +541,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