Browse files

Update prismic-helpers.js

Fix getDocument defaults parameters
  • Loading branch information...
1 parent af03414 commit c8f35d5b375c8101695693b7f6c0b32591b892c1 @guillaumebort guillaumebort committed Dec 6, 2013
Showing with 4 additions and 3 deletions.
  1. +4 −3 prismic-helpers.js
View
7 prismic-helpers.js
@@ -14,9 +14,10 @@ exports.getApiHome = function(accessToken, callback) {
exports.getDocument = function(ctx, id, slug, onSuccess, onNewSlug, onNotFound) {
ctx.api.forms('everything').ref(ctx.ref).query('[[:d = at(document.id, "' + id + '")]]').submit(function(results) {
var doc = results && results.length ? results[0] : undefined;
- if(doc && doc.slug == slug) onSuccess(doc)
- else if(doc && doc.slugs.indexOf('slug') > -1) onNewSlug(doc.slug)
- else onNotFound();
+ if(doc && (!slug || doc.slug == slug)) onSuccess(doc)
+ else if(doc && doc.slugs.indexOf(slug) > -1 && onNewSlug) onNewSlug(doc.slug)
+ else if(onNotFound) onNotFound()
+ else onSuccess();
});
};

0 comments on commit c8f35d5

Please sign in to comment.