!function(){var moduleFactory=function($){var module=this;$.require().script("mvc/lang.object","mvc/lang.string").done(function(){var exports=function(){$.ajaxPrefilter(function(settings,originalOptions){if($.fixture.on){var data=overwrite(settings);if(!settings.fixture)return"file:"===window.location.protocol,void 0;if("string"==typeof settings.fixture&&$.fixture[settings.fixture]&&(settings.fixture=$.fixture[settings.fixture]),"string"==typeof settings.fixture){var url=settings.fixture;/^\/\//.test(url)&&(url=steal.root.mapJoin(settings.fixture.substr(2))+""),settings.url=url,settings.data=null,settings.type="GET",settings.error||(settings.error=function(xhr,error,message){throw"fixtures.js Error "+error+" "+message
})}else settings.dataTypes.splice(0,0,"fixture"),data&&$.extend(originalOptions.data,data)}}),$.ajaxTransport("fixture",function(s,original){s.dataTypes.shift();var timeout,next=s.dataTypes[0];return{send:function(headers,callback){timeout=setTimeout(function(){var response=s.fixture(original,s,headers);if(!$.isArray(response)){var tmp=[{}];tmp[0][next]=response,response=tmp}if("number"!=typeof response[0]&&response.unshift(200,"success"),!response[2]||!response[2][next]){var tmp={};tmp[next]=response[2],response[2]=tmp
}callback.apply(null,response)},$.fixture.delay)},abort:function(){clearTimeout(timeout)}}});var overwrites=[],find=function(settings,exact){for(var i=0;i<overwrites.length;i++)if($fixture._similar(settings,overwrites[i],exact))return i;return-1},overwrite=function(settings){var index=find(settings);return index>-1?(settings.fixture=overwrites[index].fixture,$fixture._getData(overwrites[index].url,settings.url)):void 0},getId=function(settings){var id=settings.data.id;return void 0===id&&"number"==typeof settings.data&&(id=settings.data),void 0===id&&settings.url.replace(/\/(\d+)(\/|$|\.)/g,function(all,num){id=num
}),void 0===id&&(id=settings.url.replace(/\/(\w+)(\/|$|\.)/g,function(all,num){"update"!=num&&(id=num)})),void 0===id&&(id=Math.round(1e3*Math.random())),id},$fixture=$.fixture=function(settings,fixture){if(void 0!==fixture){if("string"==typeof settings){var matches=settings.match(/(GET|POST|PUT|DELETE) (.+)/i);settings=matches?{url:matches[2],type:matches[1]}:{url:settings}}var index=find(settings,!!fixture);if(index>-1&&overwrites.splice(index,1),null==fixture)return;settings.fixture=fixture,overwrites.push(settings)
}},replacer=$.String._regs.replacer;$.extend($.fixture,{_similar:function(settings,overwrite,exact){return exact?$.Object.same(settings,overwrite,{fixture:null}):$.Object.subset(settings,overwrite,$.fixture._compare)},_compare:{url:function(a,b){return!!$fixture._getData(b,a)},fixture:null,type:"i"},_getData:function(fixtureUrl,url){var order=[],fixtureUrlAdjusted=fixtureUrl.replace(".","\\.").replace("?","\\?"),res=new RegExp(fixtureUrlAdjusted.replace(replacer,function(whole,part){return order.push(part),"([^/]+)"
})+"$").exec(url),data={};return res?(res.shift(),$.each(order,function(i,name){data[name]=res.shift()}),data):null},"-restUpdate":function(settings){return[200,"succes",{id:getId(settings)},{location:settings.url+"/"+getId(settings)}]},"-restDestroy":function(){return{}},"-restCreate":function(settings,cbType,nul,id){var id=id||parseInt(1e5*Math.random(),10);return[200,"succes",{id:id},{location:settings.url+"/"+id}]},make:function(types,count,make,filter){"string"==typeof types&&(types=[types+"s",types]);for(var items=$.fixture["~"+types[0]]=[],findOne=function(id){for(var i=0;i<items.length;i++)if(id==items[i].id)return items[i]
},i=0;count>i;i++){var item=make(i,items);item.id||(item.id=i),items.push(item)}return $.fixture["-"+types[0]]=function(settings){var retArr=items.slice(0);settings.data=settings.data||{},$.each((settings.data.order||[]).slice(0).reverse(),function(i,name){var split=name.split(" ");retArr=retArr.sort(function(a,b){return"ASC"!==split[1].toUpperCase()?a[split[0]]<b[split[0]]?1:a[split[0]]==b[split[0]]?0:-1:a[split[0]]<b[split[0]]?-1:a[split[0]]==b[split[0]]?0:1})}),$.each((settings.data.group||[]).slice(0).reverse(),function(i,name){var split=name.split(" ");
retArr=retArr.sort(function(a,b){return a[split[0]]>b[split[0]]})});var offset=parseInt(settings.data.offset,10)||0,limit=parseInt(settings.data.limit,10)||items.length-offset,i=0;for(var param in settings.data)if(i=0,void 0!==settings.data[param]&&(-1!=param.indexOf("Id")||-1!=param.indexOf("_id")))for(;i<retArr.length;)settings.data[param]!=retArr[i][param]?retArr.splice(i,1):i++;if(filter)for(i=0;i<retArr.length;)filter(retArr[i],settings)?i++:retArr.splice(i,1);return[{count:retArr.length,limit:settings.data.limit,offset:settings.data.offset,data:retArr.slice(offset,offset+limit)}]
},$.fixture["-"+types[1]]=function(settings){var item=findOne(getId(settings));return item?[item]:[]},$.fixture["-"+types[1]+"Update"]=function(settings,cbType){var id=getId(settings);return $.extend(findOne(id),settings.data),$.fixture["-restUpdate"](settings,cbType)},$.fixture["-"+types[1]+"Destroy"]=function(settings,cbType){for(var id=getId(settings),i=0;i<items.length;i++)if(items[i].id==id){items.splice(i,1);break}return $.extend(findOne(id),settings.data),$.fixture["-restDestroy"](settings,cbType)},$.fixture["-"+types[1]+"Create"]=function(settings,cbType){var item=make(items.length,items);
return $.extend(item,settings.data),item.id||(item.id=items.length),items.push(item),$.fixture["-restCreate"](settings,cbType,void 0,item.id)},{getId:getId,findOne:findOne,find:function(settings){return findOne(getId(settings))}}},rand:function(arr,min,max){if("number"==typeof arr)return"number"==typeof min?arr+Math.floor(Math.random()*(min-arr)):Math.floor(Math.random()*arr);var rand=arguments.callee;if(void 0===min)return rand(arr,rand(arr.length+1));var res=[];arr=arr.slice(0),max||(max=min),max=min+Math.round(rand(max-min));
for(var i=0;max>i;i++)res.push(arr.splice(rand(arr.length),1)[0]);return res},xhr:function(xhr){return $.extend({},{abort:$.noop,getAllResponseHeaders:function(){return""},getResponseHeader:function(){return""},open:$.noop,overrideMimeType:$.noop,readyState:4,responseText:"",responseXML:null,send:$.noop,setRequestHeader:$.noop,status:200,statusText:"OK"},xhr)},on:!0}),$.fixture.delay=200,$.fixture["-handleFunction"]=function(settings){return"string"==typeof settings.fixture&&$.fixture[settings.fixture]&&(settings.fixture=$.fixture[settings.fixture]),"function"==typeof settings.fixture?(setTimeout(function(){settings.success&&settings.success.apply(null,settings.fixture(settings,"success")),settings.complete&&settings.complete.apply(null,settings.fixture(settings,"complete"))
},$.fixture.delay),!0):!1},$.fixture.overwrites=overwrites};exports(),module.resolveWith(exports)})};dispatch("mvc/dom.fixture").containing(moduleFactory).to("Foundry/2.1 Modules")}();