(function(window,undefined){'use strict';function WP_API(){this.models={};this.collections={};this.views={};}
window.wp=window.wp||{};wp.api=wp.api||new WP_API();wp.api.versionString=wp.api.versionString||'wp/v2/';if(!_.isFunction(_.includes)&&_.isFunction(_.contains)){_.includes=_.contains;}})(window);(function(window,undefined){'use strict';var pad,r;window.wp=window.wp||{};wp.api=wp.api||{};wp.api.utils=wp.api.utils||{};wp.api.getModelByRoute=function(route){return _.find(wp.api.models,function(model){return model.prototype.route&&route===model.prototype.route.index;});};wp.api.getCollectionByRoute=function(route){return _.find(wp.api.collections,function(collection){return collection.prototype.route&&route===collection.prototype.route.index;});};if(!Date.prototype.toISOString){pad=function(number){r=String(number);if(1===r.length){r='0'+r;}
return r;};Date.prototype.toISOString=function(){return this.getUTCFullYear()+'-'+pad(this.getUTCMonth()+1)+'-'+pad(this.getUTCDate())+'T'+pad(this.getUTCHours())+':'+pad(this.getUTCMinutes())+':'+pad(this.getUTCSeconds())+'.'+String((this.getUTCMilliseconds()/ 1000).toFixed(3)).slice(2,5)+'Z';};}
wp.api.utils.parseISO8601=function(date){var timestamp,struct,i,k,minutesOffset=0,numericKeys=[1,4,5,6,7,10,11];if((struct=/^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/.exec(date))){for(i=0;(k=numericKeys[i]);++i){struct[k]=+struct[k]||0;}
struct[2]=(+struct[2]||1)-1;struct[3]=+struct[3]||1;if('Z'!==struct[8]&&undefined!==struct[9]){minutesOffset=struct[10]*60+struct[11];if('+'===struct[9]){minutesOffset=0-minutesOffset;}}
timestamp=Date.UTC(struct[1],struct[2],struct[3],struct[4],struct[5]+minutesOffset,struct[6],struct[7]);}else{timestamp=Date.parse?Date.parse(date):NaN;}
return timestamp;};wp.api.utils.getRootUrl=function(){return window.location.origin?window.location.origin+'/':window.location.protocol+'//'+window.location.host+'/';};wp.api.utils.capitalize=function(str){if(_.isUndefined(str)){return str;}
return str.charAt(0).toUpperCase()+str.slice(1);};wp.api.utils.capitalizeAndCamelCaseDashes=function(str){if(_.isUndefined(str)){return str;}
str=wp.api.utils.capitalize(str);return wp.api.utils.camelCaseDashes(str);};wp.api.utils.camelCaseDashes=function(str){return str.replace(/-([a-z])/g,function(g){return g[1].toUpperCase();});};wp.api.utils.extractRoutePart=function(route,part,versionString,reverse){var routeParts;part=part||1;versionString=versionString||wp.api.versionString;if(0===route.indexOf('/'+versionString)){route=route.substr(versionString.length+1);}
routeParts=route.split('/');if(reverse){routeParts=routeParts.reverse();}
if(_.isUndefined(routeParts[--part])){return'';}
return routeParts[part];};wp.api.utils.extractParentName=function(route){var name,lastSlash=route.lastIndexOf('_id>[\\d]+)/');if(lastSlash<0){return'';}
name=route.substr(0,lastSlash-1);name=name.split('/');name.pop();name=name.pop();return name;};wp.api.utils.decorateFromRoute=function(routeEndpoints,modelInstance){_.each(routeEndpoints,function(routeEndpoint){if(_.includes(routeEndpoint.methods,'POST')||_.includes(routeEndpoint.methods,'PUT')){if(!_.isEmpty(routeEndpoint.args)){if(_.isEmpty(modelInstance.prototype.args)){modelInstance.prototype.args=routeEndpoint.args;}else{modelInstance.prototype.args=_.extend(modelInstance.prototype.args,routeEndpoint.args);}}}else{if(_.includes(routeEndpoint.methods,'GET')){if(!_.isEmpty(routeEndpoint.args)){if(_.isEmpty(modelInstance.prototype.options)){modelInstance.prototype.options=routeEndpoint.args;}else{modelInstance.prototype.options=_.extend(modelInstance.prototype.options,routeEndpoint.args);}}}}});};wp.api.utils.addMixinsAndHelpers=function(model,modelClassName,loadingObjects){var hasDate=false,parseableDates=['date','modified','date_gmt','modified_gmt'],TimeStampedMixin={setDate:function(date,field){var theField=field||'date';if(_.indexOf(parseableDates,theField)<0){return false;}
this.set(theField,date.toISOString());},getDate:function(field){var theField=field||'date',theISODate=this.get(theField);if(_.indexOf(parseableDates,theField)<0||_.isNull(theISODate)){return false;}
return new Date(wp.api.utils.parseISO8601(theISODate));}},buildModelGetter=function(parentModel,modelId,modelName,embedSourcePoint,embedCheckField){var getModel,embeddedObjects,attributes,deferred;deferred=jQuery.Deferred();embeddedObjects=parentModel.get('_embedded')||{};if(!_.isNumber(modelId)||0===modelId){deferred.reject();return deferred;}
if(embeddedObjects[embedSourcePoint]){attributes=_.findWhere(embeddedObjects[embedSourcePoint],{id:modelId});}
if(!attributes){attributes={id:modelId};}
getModel=new wp.api.models[modelName](attributes);if(!getModel.get(embedCheckField)){getModel.fetch({success:function(getModel){deferred.resolve(getModel);},error:function(getModel,response){deferred.reject(response);}});}else{deferred.resolve(getModel);}
return deferred.promise();},buildCollectionGetter=function(parentModel,collectionName,embedSourcePoint,embedIndex){var postId,embeddedObjects,getObjects,classProperties='',properties='',deferred=jQuery.Deferred();postId=parentModel.get('id');embeddedObjects=parentModel.get('_embedded')||{};if(!_.isNumber(postId)||0===postId){deferred.reject();return deferred;}
if(!_.isUndefined(embedSourcePoint)&&!_.isUndefined(embeddedObjects[embedSourcePoint])){if(_.isUndefined(embedIndex)){properties=embeddedObjects[embedSourcePoint];}else{properties=embeddedObjects[embedSourcePoint][embedIndex];}}else{classProperties={parent:postId};}
getObjects=new wp.api.collections[collectionName](properties,classProperties);if(_.isUndefined(getObjects.models[0])){getObjects.fetch({success:function(getObjects){setHelperParentPost(getObjects,postId);deferred.resolve(getObjects);},error:function(getModel,response){deferred.reject(response);}});}else{setHelperParentPost(getObjects,postId);deferred.resolve(getObjects);}
return deferred.promise();},setHelperParentPost=function(collection,postId){_.each(collection.models,function(model){model.set('parent_post',postId);});},MetaMixin={getMeta:function(key){var metas=this.get('meta');return metas[key];},getMetas:function(){return this.get('meta');},setMetas:function(meta){var metas=this.get('meta');_.extend(metas,meta);this.set('meta',metas);},setMeta:function(key,value){var metas=this.get('meta');metas[key]=value;this.set('meta',metas);}},RevisionsMixin={getRevisions:function(){return buildCollectionGetter(this,'PostRevisions');}},TagsMixin={getTags:function(){var tagIds=this.get('tags'),tags=new wp.api.collections.Tags();if(_.isEmpty(tagIds)){return jQuery.Deferred().resolve([]);}
return tags.fetch({data:{include:tagIds}});},setTags:function(tags){var allTags,newTag,self=this,newTags=[];if(_.isString(tags)){return false;}
if(_.isArray(tags)){allTags=new wp.api.collections.Tags();allTags.fetch({data:{per_page:100},success:function(alltags){_.each(tags,function(tag){newTag=new wp.api.models.Tag(alltags.findWhere({slug:tag}));newTag.set('parent_post',self.get('id'));newTags.push(newTag);});tags=new wp.api.collections.Tags(newTags);self.setTagsWithCollection(tags);}});}else{this.setTagsWithCollection(tags);}},setTagsWithCollection:function(tags){this.set('tags',tags.pluck('id'));return this.save();}},CategoriesMixin={getCategories:function(){var categoryIds=this.get('categories'),categories=new wp.api.collections.Categories();if(_.isEmpty(categoryIds)){return jQuery.Deferred().resolve([]);}
return categories.fetch({data:{include:categoryIds}});},setCategories:function(categories){var allCategories,newCategory,self=this,newCategories=[];if(_.isString(categories)){return false;}
if(_.isArray(categories)){allCategories=new wp.api.collections.Categories();allCategories.fetch({data:{per_page:100},success:function(allcats){_.each(categories,function(category){newCategory=new wp.api.models.Category(allcats.findWhere({slug:category}));newCategory.set('parent_post',self.get('id'));newCategories.push(newCategory);});categories=new wp.api.collections.Categories(newCategories);self.setCategoriesWithCollection(categories);}});}else{this.setCategoriesWithCollection(categories);}},setCategoriesWithCollection:function(categories){this.set('categories',categories.pluck('id'));return this.save();}},AuthorMixin={getAuthorUser:function(){return buildModelGetter(this,this.get('author'),'User','author','name');}},FeaturedMediaMixin={getFeaturedMedia:function(){return buildModelGetter(this,this.get('featured_media'),'Media','wp:featuredmedia','source_url');}};if(_.isUndefined(model.prototype.args)){return model;}
_.each(parseableDates,function(theDateKey){if(!_.isUndefined(model.prototype.args[theDateKey])){hasDate=true;}});if(hasDate){model=model.extend(TimeStampedMixin);}
if(!_.isUndefined(model.prototype.args.author)){model=model.extend(AuthorMixin);}
if(!_.isUndefined(model.prototype.args.featured_media)){model=model.extend(FeaturedMediaMixin);}
if(!_.isUndefined(model.prototype.args.categories)){model=model.extend(CategoriesMixin);}
if(!_.isUndefined(model.prototype.args.meta)){model=model.extend(MetaMixin);}
if(!_.isUndefined(model.prototype.args.tags)){model=model.extend(TagsMixin);}
if(!_.isUndefined(loadingObjects.collections[modelClassName+'Revisions'])){model=model.extend(RevisionsMixin);}
return model;};})(window);(function(){'use strict';var wpApiSettings=window.wpApiSettings||{},trashableTypes=['Comment','Media','Comment','Post','Page','Status','Taxonomy','Type'];wp.api.WPApiBaseModel=Backbone.Model.extend({initialize:function(){if(-1===_.indexOf(trashableTypes,this.name)){this.requireForceForDelete=true;}},sync:function(method,model,options){var beforeSend;options=options||{};if(_.isNull(model.get('date_gmt'))){model.unset('date_gmt');}
if(_.isEmpty(model.get('slug'))){model.unset('slug');}
if(_.isFunction(model.nonce)&&!_.isEmpty(model.nonce())){beforeSend=options.beforeSend;options.beforeSend=function(xhr){xhr.setRequestHeader('X-WP-Nonce',model.nonce());if(beforeSend){return beforeSend.apply(this,arguments);}};options.complete=function(xhr){var returnedNonce=xhr.getResponseHeader('X-WP-Nonce');if(returnedNonce&&_.isFunction(model.nonce)&&model.nonce()!==returnedNonce){model.endpointModel.set('nonce',returnedNonce);}};}
if(this.requireForceForDelete&&'delete'===method){model.url=model.url()+'?force=true';}
return Backbone.sync(method,model,options);},save:function(attrs,options){if(_.includes(this.methods,'PUT')||_.includes(this.methods,'POST')){return Backbone.Model.prototype.save.call(this,attrs,options);}else{return false;}},destroy:function(options){if(_.includes(this.methods,'DELETE')){return Backbone.Model.prototype.destroy.call(this,options);}else{return false;}}});wp.api.models.Schema=wp.api.WPApiBaseModel.extend({defaults:{_links:{},namespace:null,routes:{}},initialize:function(attributes,options){var model=this;options=options||{};wp.api.WPApiBaseModel.prototype.initialize.call(model,attributes,options);model.apiRoot=options.apiRoot||wpApiSettings.root;model.versionString=options.versionString||wpApiSettings.versionString;},url:function(){return this.apiRoot+this.versionString;}});})();(function(){'use strict';var wpApiSettings=window.wpApiSettings||{};wp.api.WPApiBaseCollection=Backbone.Collection.extend({initialize:function(models,options){this.state={data:{},currentPage:null,totalPages:null,totalObjects:null};if(_.isUndefined(options)){this.parent='';}else{this.parent=options.parent;}},sync:function(method,model,options){var beforeSend,success,self=this;options=options||{};if(_.isFunction(model.nonce)&&!_.isEmpty(model.nonce())){beforeSend=options.beforeSend;options.beforeSend=function(xhr){xhr.setRequestHeader('X-WP-Nonce',model.nonce());if(beforeSend){return beforeSend.apply(self,arguments);}};options.complete=function(xhr){var returnedNonce=xhr.getResponseHeader('X-WP-Nonce');if(returnedNonce&&_.isFunction(model.nonce)&&model.nonce()!==returnedNonce){model.endpointModel.set('nonce',returnedNonce);}};}
if('read'===method){if(options.data){self.state.data=_.clone(options.data);delete self.state.data.page;}else{self.state.data=options.data={};}
if('undefined'===typeof options.data.page){self.state.currentPage=null;self.state.totalPages=null;self.state.totalObjects=null;}else{self.state.currentPage=options.data.page-1;}
success=options.success;options.success=function(data,textStatus,request){if(!_.isUndefined(request)){self.state.totalPages=parseInt(request.getResponseHeader('x-wp-totalpages'),10);self.state.totalObjects=parseInt(request.getResponseHeader('x-wp-total'),10);}
if(null===self.state.currentPage){self.state.currentPage=1;}else{self.state.currentPage++;}
if(success){return success.apply(this,arguments);}};}
return Backbone.sync(method,model,options);},more:function(options){options=options||{};options.data=options.data||{};_.extend(options.data,this.state.data);if('undefined'===typeof options.data.page){if(!this.hasMore()){return false;}
if(null===this.state.currentPage||this.state.currentPage<=1){options.data.page=2;}else{options.data.page=this.state.currentPage+1;}}
return this.fetch(options);},hasMore:function(){if(null===this.state.totalPages||null===this.state.totalObjects||null===this.state.currentPage){return null;}else{return(this.state.currentPage<this.state.totalPages);}}});})();(function(){'use strict';var Endpoint,initializedDeferreds={},wpApiSettings=window.wpApiSettings||{};window.wp=window.wp||{};wp.api=wp.api||{};if(_.isEmpty(wpApiSettings)){wpApiSettings.root=window.location.origin+'/wp-json/';}
Endpoint=Backbone.Model.extend({defaults:{apiRoot:wpApiSettings.root,versionString:wp.api.versionString,nonce:null,schema:null,models:{},collections:{}},initialize:function(){var model=this,deferred;Backbone.Model.prototype.initialize.apply(model,arguments);deferred=jQuery.Deferred();model.schemaConstructed=deferred.promise();model.schemaModel=new wp.api.models.Schema(null,{apiRoot:model.get('apiRoot'),versionString:model.get('versionString'),nonce:model.get('nonce')});model.schemaModel.once('change',function(){model.constructFromSchema();deferred.resolve(model);});if(model.get('schema')){model.schemaModel.set(model.schemaModel.parse(model.get('schema')));}else if(!_.isUndefined(sessionStorage)&&(_.isUndefined(wpApiSettings.cacheSchema)||wpApiSettings.cacheSchema)&&sessionStorage.getItem('wp-api-schema-model'+model.get('apiRoot')+model.get('versionString'))){model.schemaModel.set(model.schemaModel.parse(JSON.parse(sessionStorage.getItem('wp-api-schema-model'+model.get('apiRoot')+model.get('versionString')))));}else{model.schemaModel.fetch({success:function(newSchemaModel){if(!_.isUndefined(sessionStorage)&&(_.isUndefined(wpApiSettings.cacheSchema)||wpApiSettings.cacheSchema)){try{sessionStorage.setItem('wp-api-schema-model'+model.get('apiRoot')+model.get('versionString'),JSON.stringify(newSchemaModel));}catch(error){}}},error:function(err){window.console.log(err);}});}},constructFromSchema:function(){var routeModel=this,modelRoutes,collectionRoutes,schemaRoot,loadingObjects,mapping=wpApiSettings.mapping||{models:{'Categories':'Category','Comments':'Comment','Pages':'Page','PagesMeta':'PageMeta','PagesRevisions':'PageRevision','Posts':'Post','PostsCategories':'PostCategory','PostsRevisions':'PostRevision','PostsTags':'PostTag','Schema':'Schema','Statuses':'Status','Tags':'Tag','Taxonomies':'Taxonomy','Types':'Type','Users':'User'},collections:{'PagesMeta':'PageMeta','PagesRevisions':'PageRevisions','PostsCategories':'PostCategories','PostsMeta':'PostMeta','PostsRevisions':'PostRevisions','PostsTags':'PostTags'}},modelEndpoints=routeModel.get('modelEndpoints'),modelRegex=new RegExp('(?:.*[+)]|\/('+modelEndpoints.join('|')+'))$');modelRoutes=[];collectionRoutes=[];schemaRoot=routeModel.get('apiRoot').replace(wp.api.utils.getRootUrl(),'');loadingObjects={};loadingObjects.models={};loadingObjects.collections={};_.each(routeModel.schemaModel.get('routes'),function(route,index){if(index!==routeModel.get(' versionString')&&index!==schemaRoot&&index!==('/'+routeModel.get('versionString').slice(0,-1))){if(modelRegex.test(index)){modelRoutes.push({index:index,route:route});}else{collectionRoutes.push({index:index,route:route});}}});_.each(modelRoutes,function(modelRoute){var modelClassName,routeName=wp.api.utils.extractRoutePart(modelRoute.index,2,routeModel.get('versionString'),true),parentName=wp.api.utils.extractRoutePart(modelRoute.index,1,routeModel.get('versionString'),false),routeEnd=wp.api.utils.extractRoutePart(modelRoute.index,1,routeModel.get('versionString'),true);if(parentName===routeModel.get('versionString')){parentName='';}
if('me'===routeEnd){routeName='me';}
if(''!==parentName&&parentName!==routeName){modelClassName=wp.api.utils.capitalizeAndCamelCaseDashes(parentName)+wp.api.utils.capitalizeAndCamelCaseDashes(routeName);modelClassName=mapping.models[modelClassName]||modelClassName;loadingObjects.models[modelClassName]=wp.api.WPApiBaseModel.extend({url:function(){var url=routeModel.get('apiRoot')+
routeModel.get('versionString')+
parentName+'/'+
((_.isUndefined(this.get('parent'))||0===this.get('parent'))?(_.isUndefined(this.get('parent_post'))?'':this.get('parent_post')+'/'):this.get('parent')+'/')+
routeName;if(!_.isUndefined(this.get('id'))){url+='/'+this.get('id');}
return url;},nonce:function(){return routeModel.get('nonce');},endpointModel:routeModel,route:modelRoute,name:modelClassName,methods:modelRoute.route.methods,endpoints:modelRoute.route.endpoints});}else{modelClassName=wp.api.utils.capitalizeAndCamelCaseDashes(routeName);modelClassName=mapping.models[modelClassName]||modelClassName;loadingObjects.models[modelClassName]=wp.api.WPApiBaseModel.extend({url:function(){var url=routeModel.get('apiRoot')+
routeModel.get('versionString')+
(('me'===routeName)?'users/me':routeName);if(!_.isUndefined(this.get('id'))){url+='/'+this.get('id');}
return url;},nonce:function(){return routeModel.get('nonce');},endpointModel:routeModel,route:modelRoute,name:modelClassName,methods:modelRoute.route.methods,endpoints:modelRoute.route.endpoints});}
wp.api.utils.decorateFromRoute(modelRoute.route.endpoints,loadingObjects.models[modelClassName],routeModel.get('versionString'));});_.each(collectionRoutes,function(collectionRoute){var collectionClassName,modelClassName,routeName=collectionRoute.index.slice(collectionRoute.index.lastIndexOf('/')+1),parentName=wp.api.utils.extractRoutePart(collectionRoute.index,1,routeModel.get('versionString'),false);if(''!==parentName&&parentName!==routeName&&routeModel.get('versionString')!==parentName){collectionClassName=wp.api.utils.capitalizeAndCamelCaseDashes(parentName)+wp.api.utils.capitalizeAndCamelCaseDashes(routeName);modelClassName=mapping.models[collectionClassName]||collectionClassName;collectionClassName=mapping.collections[collectionClassName]||collectionClassName;loadingObjects.collections[collectionClassName]=wp.api.WPApiBaseCollection.extend({url:function(){return routeModel.get('apiRoot')+routeModel.get('versionString')+
parentName+'/'+
((_.isUndefined(this.parent)||''===this.parent)?(_.isUndefined(this.get('parent_post'))?'':this.get('parent_post')+'/'):this.parent+'/')+
routeName;},model:function(attrs,options){return new loadingObjects.models[modelClassName](attrs,options);},nonce:function(){return routeModel.get('nonce');},endpointModel:routeModel,name:collectionClassName,route:collectionRoute,methods:collectionRoute.route.methods});}else{collectionClassName=wp.api.utils.capitalizeAndCamelCaseDashes(routeName);modelClassName=mapping.models[collectionClassName]||collectionClassName;collectionClassName=mapping.collections[collectionClassName]||collectionClassName;loadingObjects.collections[collectionClassName]=wp.api.WPApiBaseCollection.extend({url:function(){return routeModel.get('apiRoot')+routeModel.get('versionString')+routeName;},model:function(attrs,options){return new loadingObjects.models[modelClassName](attrs,options);},nonce:function(){return routeModel.get('nonce');},endpointModel:routeModel,name:collectionClassName,route:collectionRoute,methods:collectionRoute.route.methods});}
wp.api.utils.decorateFromRoute(collectionRoute.route.endpoints,loadingObjects.collections[collectionClassName]);});_.each(loadingObjects.models,function(model,index){loadingObjects.models[index]=wp.api.utils.addMixinsAndHelpers(model,index,loadingObjects);});routeModel.set('models',loadingObjects.models);routeModel.set('collections',loadingObjects.collections);}});wp.api.endpoints=new Backbone.Collection();wp.api.init=function(args){var endpoint,attributes={},deferred,promise;args=args||{};attributes.nonce=_.isString(args.nonce)?args.nonce:(wpApiSettings.nonce||'');attributes.apiRoot=args.apiRoot||wpApiSettings.root||'/wp-json';attributes.versionString=args.versionString||wpApiSettings.versionString||'wp/v2/';attributes.schema=args.schema||null;attributes.modelEndpoints=args.modelEndpoints||['me','settings'];if(!attributes.schema&&attributes.apiRoot===wpApiSettings.root&&attributes.versionString===wpApiSettings.versionString){attributes.schema=wpApiSettings.schema;}
if(!initializedDeferreds[attributes.apiRoot+attributes.versionString]){endpoint=wp.api.endpoints.findWhere({'apiRoot':attributes.apiRoot,'versionString':attributes.versionString});if(!endpoint){endpoint=new Endpoint(attributes);}
deferred=jQuery.Deferred();promise=deferred.promise();endpoint.schemaConstructed.done(function(resolvedEndpoint){wp.api.endpoints.add(resolvedEndpoint);wp.api.models=_.extend(wp.api.models,resolvedEndpoint.get('models'));wp.api.collections=_.extend(wp.api.collections,resolvedEndpoint.get('collections'));deferred.resolve(resolvedEndpoint);});initializedDeferreds[attributes.apiRoot+attributes.versionString]=promise;}
return initializedDeferreds[attributes.apiRoot+attributes.versionString];};wp.api.loadPromise=wp.api.init();})();