Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix issue #2

  • Loading branch information...
commit 1aea20d06dd20dfa054ed4063ac8fc802f576ea0 1 parent 96e7dec
@guillaumebort guillaumebort authored
View
4 dist/prismic.io-1.0.3.min.js
@@ -1,2 +1,2 @@
-/*! prismic.io 1.0.3 2013-11-04 */
-!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){this.id=a,this.type=b,this.href=c,this.tags=d,this.slug=e?e[0]:"-",this.fragments=f}function g(a,b,c){this.ref=a,this.label=b,this.isMaster=c}var h=function(a,b,c,d){var e=new h.fn.init(a,c,d);return b&&e.get(b),e},i=function(){return"undefined"!=typeof XMLHttpRequest?function(a,b){var c=new XMLHttpRequest,d=function(){b(JSON.parse(c.responseText))},e=function(){var a=c.status;throw new Error("Unexpected status code ["+a+"]")};c.onreadystatechange=function(){4===c.readyState&&(c.status&&200==c.status?d(c):e(c))},c.open("GET",a+"#json",!0),c.setRequestHeader("Accept","application/json"),c.send()}:void 0},j=function(){if("function"==typeof require&&require("http")){var a={},c=require("http"),d=require("https"),e=require("url");return require("querystring"),function(f,g){if(a[f])g(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)throw new Error("Unexpected status code ["+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(i)})})}}}};h.fn=h.prototype={constructor:h,data:null,get:function(a){var b=this;this.requestHandler(this.url,function(c){b.data=b.parse(c),b.bookmarks=b.data.bookmarks,a&&a(b,this)})},parse:function(a){var b,d,e,f,h,i={};for(h in a.forms)a.forms.hasOwnProperty(h)&&(f=a.forms[h],this.accessToken&&(f.fields.accessToken={type:"string","default":this.accessToken}),e=new c(f.name,f.fields,f.form_method,f.rel,f.enctype,f.action),i[h]=e);if(b=a.refs.map(function(a){return new g(a.ref,a.label,a.isMasterRef)})||[],d=b.filter(function(a){return a.isMaster===!0}),0===d.length)throw"No master ref.";return{bookmarks:a.bookmarks||{},refs:b,forms:i,master:d[0],oauthInitiate:a.oauth_initiate,oauthToken:a.oauth_token}},init:function(a,b,c){return this.url=a+(b?(a.indexOf("?")>-1?"&":"?")+"access_token="+b:""),this.accessToken=b,this.requestHandler=c||i()||j()||function(){throw new Error("No request handler available (tried XMLHttpRequest & NodeJS)")}(),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}},h.fn.init.prototype=h.fn,c.prototype={},d.prototype={set:function(a,b){var c=this.form.fields[a];if(!c)throw new Error("Unknown field "+a);var d=this.data[a]||[];return c.multiple?d.push(b):d=[b],this.data[a]=d,this},ref:function(a){return this.set("ref",a)},query:function(a){return this.form.fields.q.multiple?this.set("q",a):(this.data.q=this.data.q||[],this.data.q.push(a),this)},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 g=0;g<e.length;g++)b+=c+d+"="+encodeURIComponent(e[g]),c="&"}}this.api.requestHandler(b,function(b){var c=b.results||b,d=c.map(function(a){var b={};for(var c in a.data[a.type])b[a.type+"."+c]=a.data[a.type][c];return new f(a.id,a.type,a.href,a.tags,a.slugs,b)});a&&d.length&&a(d)})}},f.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},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("")}},g.prototype={},a.Prismic={Api:h}}("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=new Date(a)}function h(a){this.value=a}function i(a,b){this.main=a,this.views=b||{}}function j(a,b,c){this.url=a,this.width=b,this.height=c}function k(a,b){this.tag=a,this.blocks=b}function l(a){this.blocks=a}function m(a){var b,c=[],d=[];return Array.isArray(a)?(a.forEach(function(a){c.length>0?(c[c.length-1],b=new k(null,[]),b.blocks.push(a),c.push(b)):(b=new k(null,[]),b.blocks.push(a),c.push(b))}),c.forEach(function(a){a.tag?(d.push("<"+a.tag+">"),a.blocks.forEach(function(a){d.push(m(a))}),d.push("</"+a.tag+">")):a.blocks.forEach(function(a){d.push(m(a))})})):("heading1"==a.type&&d.push("<h1>"+a.text+"</h1>"),"heading2"==a.type&&d.push("<h2>"+a.text+"</h2>"),"heading3"==a.type&&d.push("<h3>"+a.text+"</h3>"),"paragraph"==a.type&&d.push("<p>"+a.text+"</p>"),"image"==a.type&&d.push('<p><img src="'+a.url+'"></p>')),d.join("")}function n(a){var h,k;switch(a.type){case"Color":h=new e(a.value);break;case"Number":h=new f(a.value);break;case"Date":h=new g(a.value);break;case"Text":h=new b(a.value);break;case"Embed":throw new Error("not implemented");case"Select":h=new d(a.value);break;case"Image":var k=a.value.main;h=new i(new j(k.url,k.dimensions.width,k.dimensions.height),a.value.views);break;case"StructuredText":h=new l(a.value);break;case"Link.document":h=new c(a.value);break;case"Link.web":throw new Error("not implemented");default:console.log("Type not found:",a.type)}return h}b.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},c.prototype={asHtml:function(){return"<a></a>"}},d.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},e.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},f.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},g.prototype={asText:function(){throw new Error("not implemented")},asHtml:function(){return"<time>"+this.value+"</time>"}},h.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},i.prototype={getView:function(a){return"main"===a?this.main:this.views[a]},asHtml:function(){return this.main.asHtml()}},j.prototype={ratio:function(){return this.width/this.height},asHtml:function(){return"<img src="+this.url+" width="+this.width+" height="+this.height+">"}},l.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 j(b.data.url,b.data.dimensions.width,b.data.dimensions.height)}},asHtml:function(){return m.call(this,this.blocks)}},a.Prismic.Fragments={Image:i,ImageView:j,Text:b,Number:f,Date:g,Select:d,Color:e,StructuredText:l,initField:n}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window);
+/*! prismic.io 1.0.3 2013-11-19 */
+!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){this.id=a,this.type=b,this.href=c,this.tags=d,this.slug=e?e[0]:"-",this.fragments=f}function g(a,b,c){this.ref=a,this.label=b,this.isMaster=c}var h=function(a,b,c,d){var e=new h.fn.init(a,c,d);return b&&e.get(b),e},i=function(){return"undefined"!=typeof XMLHttpRequest?function(a,b){var c=new XMLHttpRequest,d=function(){b(JSON.parse(c.responseText))},e=function(){var a=c.status;throw new Error("Unexpected status code ["+a+"]")};c.onreadystatechange=function(){4===c.readyState&&(c.status&&200==c.status?d(c):e(c))},c.open("GET",a+"#json",!0),c.setRequestHeader("Accept","application/json"),c.send()}:void 0},j=function(){if("function"==typeof require&&require("http")){var a={},c=require("http"),d=require("https"),e=require("url");return require("querystring"),function(f,g){if(a[f])g(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)throw new Error("Unexpected status code ["+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(i)})})}}}};h.fn=h.prototype={constructor:h,data:null,get:function(a){var b=this;this.requestHandler(this.url,function(c){b.data=b.parse(c),b.bookmarks=b.data.bookmarks,a&&a(b,this)})},parse:function(a){var b,d,e,f,h,i={};for(h in a.forms)a.forms.hasOwnProperty(h)&&(f=a.forms[h],this.accessToken&&(f.fields.accessToken={type:"string","default":this.accessToken}),e=new c(f.name,f.fields,f.form_method,f.rel,f.enctype,f.action),i[h]=e);if(b=a.refs.map(function(a){return new g(a.ref,a.label,a.isMasterRef)})||[],d=b.filter(function(a){return a.isMaster===!0}),0===d.length)throw"No master ref.";return{bookmarks:a.bookmarks||{},refs:b,forms:i,master:d[0],oauthInitiate:a.oauth_initiate,oauthToken:a.oauth_token}},init:function(a,b,c){return this.url=a+(b?(a.indexOf("?")>-1?"&":"?")+"access_token="+b:""),this.accessToken=b,this.requestHandler=c||i()||j()||function(){throw new Error("No request handler available (tried XMLHttpRequest & NodeJS)")}(),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}},h.fn.init.prototype=h.fn,c.prototype={},d.prototype={set:function(a,b){var c=this.form.fields[a];if(!c)throw new Error("Unknown field "+a);var d=this.data[a]||[];return c.multiple?d.push(b):d=[b],this.data[a]=d,this},ref:function(a){return this.set("ref",a)},query:function(a){return this.form.fields.q.multiple?this.set("q",a):(this.data.q=this.data.q||[],this.data.q.push(a),this)},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 g=0;g<e.length;g++)b+=c+d+"="+encodeURIComponent(e[g]),c="&"}}this.api.requestHandler(b,function(b){var c=b.results||b,d=c.map(function(a){var b={};for(var c in a.data[a.type])b[a.type+"."+c]=a.data[a.type][c];return new f(a.id,a.type,a.href,a.tags,a.slugs,b)});a&&a(d||[])})}},f.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},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("")}},g.prototype={},a.Prismic={Api:h}}("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=new Date(a)}function h(a){this.value=a}function i(a,b){this.main=a,this.views=b||{}}function j(a,b,c){this.url=a,this.width=b,this.height=c}function k(a,b){this.tag=a,this.blocks=b}function l(a){this.blocks=a}function m(a){var b,c=[],d=[];return Array.isArray(a)?(a.forEach(function(a){c.length>0?(c[c.length-1],b=new k(null,[]),b.blocks.push(a),c.push(b)):(b=new k(null,[]),b.blocks.push(a),c.push(b))}),c.forEach(function(a){a.tag?(d.push("<"+a.tag+">"),a.blocks.forEach(function(a){d.push(m(a))}),d.push("</"+a.tag+">")):a.blocks.forEach(function(a){d.push(m(a))})})):("heading1"==a.type&&d.push("<h1>"+a.text+"</h1>"),"heading2"==a.type&&d.push("<h2>"+a.text+"</h2>"),"heading3"==a.type&&d.push("<h3>"+a.text+"</h3>"),"paragraph"==a.type&&d.push("<p>"+a.text+"</p>"),"image"==a.type&&d.push('<p><img src="'+a.url+'"></p>')),d.join("")}function n(a){var h,k;switch(a.type){case"Color":h=new e(a.value);break;case"Number":h=new f(a.value);break;case"Date":h=new g(a.value);break;case"Text":h=new b(a.value);break;case"Embed":throw new Error("not implemented");case"Select":h=new d(a.value);break;case"Image":var k=a.value.main;h=new i(new j(k.url,k.dimensions.width,k.dimensions.height),a.value.views);break;case"StructuredText":h=new l(a.value);break;case"Link.document":h=new c(a.value);break;case"Link.web":throw new Error("not implemented");default:console.log("Type not found:",a.type)}return h}b.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},c.prototype={asHtml:function(){return"<a></a>"}},d.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},e.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},f.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},g.prototype={asText:function(){throw new Error("not implemented")},asHtml:function(){return"<time>"+this.value+"</time>"}},h.prototype={asHtml:function(){return"<span>"+this.value+"</span>"}},i.prototype={getView:function(a){return"main"===a?this.main:this.views[a]},asHtml:function(){return this.main.asHtml()}},j.prototype={ratio:function(){return this.width/this.height},asHtml:function(){return"<img src="+this.url+" width="+this.width+" height="+this.height+">"}},l.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 j(b.data.url,b.data.dimensions.width,b.data.dimensions.height)}},asHtml:function(){return m.call(this,this.blocks)}},a.Prismic.Fragments={Image:i,ImageView:j,Text:b,Number:f,Date:g,Select:d,Color:e,StructuredText:l,initField:n}}("object"==typeof exports&&exports?exports:"object"==typeof module&&module&&"object"==typeof module.exports?module.exports:window);
View
4 dist/prismic.io.js
@@ -312,8 +312,8 @@
)
});
- if (cb && docs.length) {
- cb(docs);
+ if (cb) {
+ cb(docs || []);
}
});
View
4 src/api.js
@@ -312,8 +312,8 @@
)
});
- if (cb && docs.length) {
- cb(docs);
+ if (cb) {
+ cb(docs || []);
}
});
View
9 test/test.js
@@ -37,6 +37,15 @@
});
});
+ asyncTest('Submit the `everything` form with a predicate that give no results', 1, function() {
+ Prismic.Api(testRepository, function(Api) {
+ Api.forms('everything').ref(Api.master()).query('[[:d = at(document.type, "youhou")]]').submit(function(results) {
+ equal(results.length, 0);
+ start();
+ });
+ });
+ });
+
asyncTest('Submit the `products` form', 1, function() {
Prismic.Api(testRepository, function(Api) {
Api.forms('products').ref(Api.master()).submit(function(results) {
Please sign in to comment.
Something went wrong with that request. Please try again.