From 38283296471234e64d4d6a39581f637937511799 Mon Sep 17 00:00:00 2001 From: Mateus Giuliano Date: Fri, 4 Mar 2016 16:47:48 -0300 Subject: [PATCH 1/4] Convert inputs of entity HTML to simble To use the lib with reactJs is required to replace the HTML entity code to string, before replace the template. Ref #124 In JSX I can't use the "<%=" token, therefore I need convert to HTML entity code("<%=") and after convert again. --- dist/filter.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dist/filter.js b/dist/filter.js index bd222a7..941d8cb 100644 --- a/dist/filter.js +++ b/dist/filter.js @@ -824,7 +824,17 @@ .replace(/\//g, '/'); }; + var convertHtmlEntityToStr = function(string) { + return (''+string).replace(/&/g, '&') + .replace(/</g, '<') + .replace(/>/g, '>') + .replace(/"/g, '\"') + .replace(/'/g, '\'') + .replace(///g, '\/'); + }; + function templateBuilder(str, data) { + str = convertHtmlEntityToStr(str); var c = templateSettings; var tmpl = 'var __p=[],print=function(){__p.push.apply(__p,arguments);};' + 'with(obj||{}){__p.push(\'' + From ab15f4ee73a1ea6bc947dbe96b43c7b4720bd09e Mon Sep 17 00:00:00 2001 From: Mateus Giuliano Date: Thu, 17 Mar 2016 13:41:53 -0300 Subject: [PATCH 2/4] Callbacks to paginator Hi, I needed insert callbacks before and after to change page when clicked in paginator. After this I decided send the development to you and I hope that you add in project. --- dist/filter.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dist/filter.js b/dist/filter.js index 941d8cb..254901e 100644 --- a/dist/filter.js +++ b/dist/filter.js @@ -1430,7 +1430,7 @@ this.page = { currentPage: 1, perPage: opts.perPage.values }; - this.paginator = new Paginator(this.lastResult().length, this.opts.pagination, function(currentPage, perPage){ + this.paginator = new Paginator(this.execCallback, this.callbacks, this.lastResult().length, this.opts.pagination, function(currentPage, perPage){ self.page = { currentPage: currentPage, perPage: perPage } if(self.has_search){ @@ -1473,9 +1473,11 @@ - var Paginator = function(recordsCount, opts, onPagination) { + var Paginator = function(execCallback, callbacks, recordsCount, opts, onPagination) { var paginationView; - + + this.execCallback = execCallback; + this.callbacks = callbacks; this.recordsCount = recordsCount;; this.opts = opts; this.$container = $(this.opts.container); @@ -1501,7 +1503,9 @@ var self = this; $(this.opts.container).on('click', '[data-page]', function(e){ + self.execCallback('beforeChangePage'); self.setCurrentPage($(this).data('page')); + self.execCallback('afterChangePage'); e.preventDefault(); }); }; From 296fe9099f127c1aab16c341a9de1aac38bee47b Mon Sep 17 00:00:00 2001 From: Mateus Giuliano Date: Thu, 17 Mar 2016 13:52:49 -0300 Subject: [PATCH 3/4] Callback Paginator Hi, I needed insert callbacks before and after to change page when clicked in paginator. After this I decided send the development to you and I hope that you add in project. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 19c195a..498cc99 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,8 @@ Define callback in settings. Callbacks execute on different events. - `beforeRender` : Triggered before rendering going to call. - `beforeRecordRender` : Triggered for each JSON object record at time of rendering. - `afterFilter` : Triggered after filtering event. +- `beforeChangePage` : Triggered before change page of paginator. +- `afterChangePage` : Triggered after change page of paginator. i.e., @@ -189,6 +191,12 @@ i.e., }, afterFilter: function(result){ // i.e Update result counter, update google map markers. + }, + beforeChangePage: function(result) { + // i.e Delete a class to item. + }, + afterChangePage: function(result) { + // i.e Insert a class to item. } }; ``` From 88d08fcfdb19c9a87df654cd9afa628398cc211a Mon Sep 17 00:00:00 2001 From: Mateus Giuliano Date: Thu, 17 Mar 2016 14:09:30 -0300 Subject: [PATCH 4/4] Callback Paginator Minify JS --- dist/filter.min.js | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/dist/filter.min.js b/dist/filter.min.js index 4d3593d..ad68607 100644 --- a/dist/filter.min.js +++ b/dist/filter.min.js @@ -20,37 +20,4 @@ * Copyright 2011-2015 Jiren Patel[jirenpatel@gmail.com] * */ -!function(t){"use strict";var e=function(t,e){return new s(t,e||{})};t.JsonQuery=e,e.VERSION="0.0.2",e.Config={id:"id",latitude:"latitude",longitude:"longitude",date_regx:/^\d{4}-\d{2}-\d{2}$/},e.blankClone=function(t,e){return new s(e,{getterFns:t.getterFns,schema:t.schema,id:t.id,latitude:t.latitude,longitude:t.longitude})};var i=e.Config,r=function(t,e,i){if(t.length===+t.length)for(var r=0,n=t.length;n>r;r++)e.call(i,t[r],r);else for(var s in t)hasOwnProperty.call(t,s)&&e.call(i,t[s],s)},n=function(t,e,i){for(var r=0,n=t.length;n>r;r++)if(e.call(i,t[r],r)===!1)return},s=function(t,e){this.records=t||[],this.getterFns=e.getterFns||{},this.lat=e.latitude||i.latitude,this.lng=e.longitude||i.longitude,this.id=e.id,e.schema&&(this.schema=e.schema),this.records.length&&!this.schema&&h(this,t[0],e.schema)},a=s.prototype,h=function(t,e,r){t.schema={},t.id||(t.id=e._id?"_id":i.id),r||(o.call(t,e),l.call(t,e))},c=function(t){if(null==t)return"String";/* - * @info Fix for IE 10 & 11 - * @bug Invalid calling object - */ -var e=Object.prototype.toString.call(t).slice(8,-1);return"String"==e&&t.match(i.date_regx)?"Date":e},o=function(t,e){var i,r,n,s;for(i in t)s=t[i],r=c(s),n=e?e+"."+i:i,this.schema[n]=r,"Object"==r?o.call(this,s,n):"Array"==r&&(["Object","Array"].indexOf(c(s[0]))>-1?o.call(this,t[i][0],n):this.schema[n]=c(s[0]))},l=function(t){var e,i,r;for(e in this.schema){i=this.schema[e];try{this.getterFns[e]||(this.getterFns[e]=f.call(this,e,i)), -//Remap if it is array -r=this.getterFns[e](t),"Array"==c(r)&&(this.schema[e]="Array")}catch(n){console.log("Error while generating getter function for selector : "+e+" NOTE: Define manually")}}},u=function(t,e){for(var i,r=0,n=0,s=e.length-1,a=e.length-1;a>=0;a--)i=e.slice(0,a+1).join("."),"Array"==t[i]&&s>a&&(r=a,n+=1);return n>1?r+1:-1},f=function(t,e){for(var i,r,n,s="",a=t.split("."),h=u(this.schema,a),c=a.length-1;c>=0;c--)i=a.slice(0,c+1).join("."),r="['"+a[c]+"']",s="Array"==this.schema[i]?h==c?r+(s.length?".every(function(r"+c+"){ objs.push(r"+c+s+")})":""):r+(s.length?".map(function(r"+c+"){ return r"+c+s+"})":""):r+s;return n=h>-1?"var objs = []; obj"+s+";"+("Date"==this.schema.path?"return parseDate(objs)":"return objs;"):"return "+("Date"==this.schema.path?"parseDate(obj"+s+");":"obj"+s+";"),new Function("obj",n)};a.operators={eq:function(t,e){return t==e},ne:function(t,e){return t!=e},lt:function(t,e){return e>t},lte:function(t,e){return e>=t},gt:function(t,e){return t>e},gte:function(t,e){return t>=e},"in":function(t,e){return e.indexOf(t)>-1},ni:function(t,e){return-1==e.indexOf(t)},li:function(t,e){return e.test(t)},bt:function(t,e){return t>=e[0]&&t<=e[1]}},a.addOperator=function(t,e){this.operators[t]=e}; -// rVal = Record Value -// cVal = Condition Value -var p=function(t,e,i){var r=0,n=t.length;for(r;n>r;r++)if(i(t[r],e))return!0};a.addCondition=function(t,e){this.operators[t]=e},a.getCriteria=function(t){var e=t.split(".$");return{field:e[0],operator:e[1]||"eq"}},a.setGetterFn=function(t,e){this.getterFns[t]=e},a.addRecords=function(t){return t&&t.length?("Array"==c(t)?this.records=this.records.concat(t):this.records.push(t),this.schema||h(this,t[0]),!0):!1},a._findAll=function(t,e,i,n){var s,a,h,c=[],o=this.getterFns[e];return"li"==n&&"string"==typeof i&&(i=new RegExp(i)),s=this.operators[n],"Array"==this.schema[e]&&(h=s,s=p),r(t,function(t){a=o(t),s(a,i,h)&&c.push(t)}),c},a.find=function(t,e){var i,r;return e||(e=t,t=this.id),r=this.getterFns[t],n(this.records,function(t){return r(t)==e?(i=t,!1):void 0}),i},r(["where","or","groupBy","select","pluck","limit","offset","order","uniq","near"],function(t){a[t]=function(e){var i=new y(this,this.records);return i[t].apply(i,arguments),i}}),r(["update_all","destroy_all"],function(t){a[t]=function(e){var i=new y(this,this.records);return i[t].apply(i,arguments)}}),r(["count","first","last","all"],function(t){Object.defineProperty(a,t,{get:function(){return new y(this,this.records)[t]}})});var g=function(t,e,i){for(var r=0,n=i.length;n>r;r++)if(this.getterFns[i[r]](t)!==this.getterFns[i[r]](e))return!1;return!0},d=function(t,e){var i,r,n;for(i in t)r=this.jQ.getCriteria(i),n=this.jQ._findAll(n||e,r.field,t[i],r.operator);return n},v=function(t,e){var i,n=this.jQ.getterFns[t],s={};e.length;return r(e,function(t){i=n(t),(s[i]||(s[i]=[])).push(t)}),s},m=function(t,e){for(var i,r,n=e.slice(0),s=0,a=t.length;a>s;s++)i=this.jQ.getterFns[t[s].field],r="asc"==t[s].direction?1:-1,n.sort(function(t,e){var n=i(t),s=i(e);return(s>n?-1:n>s?1:0)*r});return n},_=function(t,e){var i,n=this,s=[];return r(t,function(t){i=n.jQ.getterFns[t],r(e,function(e,r){(s[r]||(s[r]={}))[t]=i(e)})}),s},P=function(t,e){var i=this.jQ.getterFns[t],n=[];return r(e,function(t){n.push(i(t))}),n},b=function(t,e){var i=[],n=this;return"Object"!=c(e[0])?(r(e,function(t){-1==i.indexOf(t)&&i.push(t)}),i):(i.push(e[0]),r(e,function(e){for(var r=!1,s=0,a=i.length;a>s;s++)g.call(n.jQ,i[s],e,t)&&(r=!0);r||i.push(e)}),i)},y=function(t,e){return this.jQ=t,this.records=e,this.criteria={},this},j=y.prototype;j.each=function(t,e){r(this.exec()||[],t,e)},j.exec=j.toArray=function(t){var e;return this.criteria.all&&(e=this.records),this.criteria.where&&(e=d.call(this,this.criteria.where,e||this.records)),this.criteria.or&&(e=e.concat(d.call(this,this.criteria.or,this.records)),e=b.call(this,[this.jQ.id],e)),this.criteria.order&&(e=m.call(this,this.criteria.order,e||this.records)),this.criteria.near&&(e=k.call(this,this.criteria.near,e||this.records)),this.criteria.uniq&&(e=b.call(this,this.criteria.uniq,e||this.records)),this.criteria.select&&(e=_.call(this,this.criteria.select,e||this.records)),this.criteria.pluck&&(e=P.call(this,this.criteria.pluck,e||this.records)),this.criteria.limit&&(e=(e||this.records).slice(this.criteria.offset||0,(this.criteria.offset||0)+this.criteria.limit)),this.criteria.group_by&&(e=v.call(this,this.criteria.group_by,e||this.records)),e||(e=this.records),t&&r(e,t),this.jQ.onResult&&this.jQ.onResult(e,this.criteria),e};var C=function(t,e){var i;this.criteria[t]||(this.criteria[t]={});for(i in e)this.criteria[t][i]=e[i];return this};j.where=function(t){return C.call(this,"where",t)},j.or=function(t){return C.call(this,"or",t)},j.groupBy=function(t){return this.criteria.group_by=t,this},j.select=function(){return this.criteria.select=arguments,this},j.pluck=function(t){return this.criteria.pluck=t,this},j.limit=function(t){return this.criteria.limit=t,this},j.offset=function(t){return this.criteria.offset=t,this},j.order=function(t){var e;this.criteria.order=this.criteria.order||[];for(e in t)this.criteria.order.push({field:e,direction:t[e].toLowerCase()});return this},j.uniq=function(){return this.criteria.uniq=arguments.length>0?arguments:!0,this},Object.defineProperty(j,"count",{get:function(){this.criteria.count=!0;var t=this.exec();return"Array"==c(t)?this.exec().length:Object.keys(t).length}}),Object.defineProperty(j,"all",{get:function(){return this.criteria.all=!0,this.exec()}}),Object.defineProperty(j,"first",{get:function(){return this.criteria.first=!0,this.exec()[0]}}),Object.defineProperty(j,"last",{get:function(){this.criteria.last=!0;var t=this.exec();return t[t.length-1]}}); -//Geocoding -var x={redius:6371,toRad:function(t){return t*Math.PI/180}},F=function(t,e,i,r){var n=x.toRad(e-t),s=x.toRad(r-i),t=x.toRad(t),e=x.toRad(e),a=Math.sin(n/2)*Math.sin(n/2)+Math.sin(s/2)*Math.sin(s/2)*Math.cos(t)*Math.cos(e);return 2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))*x.redius},k=function(t,e){var i=[],n=this,s="mile"==t.unit?.6214:1,a=n.jQ.getterFns[n.jQ.lat],h=n.jQ.getterFns[n.jQ.lng];return r(e,function(e){e._distance=F(a(e),t.lat,h(e),t.lng)*s,e._distance<=t.distance&&i.push(e)}),i.sort(function(t,e){return t._distancee._distance?1:0}),i};j.near=function(t,e,i,r){return this.criteria.near={lat:t,lng:e,distance:i,unit:r||"km"},this}, -//Helpers -j.map=j.collect=function(t){var e,i=[];return this.exec(function(r){(e=t(r))&&i.push(e)}),i},j.sum=function(t){var e,i=0,n=this.jQ.getterFns[t];return this.criteria.group_by&&(e=!0,i={}),this.exec(function(t,s){e?(i[s]=0,r(t,function(t){i[s]=i[s]+(n(t)||0)})):i+=n(t)||0}),i},j.toJQ=function(){var t=e(this.all,{schema:!0});return t.schema=this.jQ.schema,t.getterFns=this.jQ.getterFns,t},j.destroy_all=j.destroy=function(){var t=this.all;return r(t,function(t,e){t._destroy_=!0}),this.records=this.jQ.records=this.records.filter(function(t){return!t._destroy_}),t},j.update_all=j.update=function(t){if(!t)return!1;var e=0;return r(this.all,function(i){r(t,function(t,e){i[e]=t}),e+=1}),e}, -//In IE 8 indexOf method not define. -Array.prototype.indexOf||(Array.prototype.indexOf=function(t,e){for(var i=e||0,r=this.length;r>i;i++)if(this[i]===t)return i;return-1}),Object.defineProperty||(Object.defineProperty=function(t,e,i){t[e]=i.get})}(this),function(t,e,i){"use strict";function r(t,e){var i=a,r="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+t.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(i.escape,function(t,e){return"',escapeStr("+e.replace(/\\'/g,"'")+"),'"}).replace(i.interpolate,function(t,e){return"',"+e.replace(/\\'/g,"'")+",'"}).replace(i.evaluate||null,function(t,e){return"');"+e.replace(/\\'/g,"'").replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",n=new Function("obj",r);return e?n(e):function(t){return n(t)}}function n(t,e){var i=t,r=[];for(i;e>=i;i++)r.push(i);return r}/* - * Find html tag and parse options for filter - */ -function s(e,i){var r="fjs-"+e,n=t("["+r+"]"),s=[];return n.length?(t.each(n,function(){var e=t(this),i={ele:e},n=e.attr(r);return s.push(i),n?void t.each(n.split(","),function(t,e){var r=e.split("=");i[r[0]]=r[1]}):s}),i?s:s[0]):void 0} -//View Template -// Ref: Underscopre.js -//JavaScript micro-templating, similar to John Resig's implementation. -var a={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g},h=function(e,i,r){var n=this;this.opts=r||{},this.callbacks=this.opts.callbacks||{},this.$container=t(i),this.view=this.opts.view||o,this.criterias=[],this._index=1,this.appendToContainer=this.opts.appendToContainer||l,this.has_pagination=!!this.opts.pagination,this.search_text="",this.anyFilterSelected=!1,this.setTemplate(this.opts.template),t.each(this.opts.criterias||[],function(){n.addCriteria(this)}),this.Model=JsonQuery(),this.Model.getterFns._fid=function(t){return t._fid},this.addRecords(e,!1),this.has_pagination&&this.initPagination()},c=h.prototype;Object.defineProperty(c,"records",{get:function(){return this.Model.records}}),Object.defineProperty(c,"recordsCount",{get:function(){return this.Model.records.length}}),c.templateBuilder=r, -//Callback -c.execCallback=function(){var t=arguments[0];this.callbacks[t]&&this.callbacks[t].apply(this,Array.prototype.slice.call(arguments,1))},c.addCallback=function(t,e){t&&e&&(this.callbacks[t]=e)}, -//Add Data -c.addRecords=function(t,e){!!this.Model.schema;this.execCallback("beforeAddRecords",t),this.Model.addRecords(t)&&(this.has_scheme||this.initSearch(this.opts.search),this.render(t),e!==!1&&this.filter()),this.execCallback("afterAddRecords",t)},c.removeRecords=function(e){var i;if(t.isPlainObject(e)?i=this.Model.where(e).pluck("_fid").all:t.isArray(e)&&(i=this.Model.where({"id.$in":e}).pluck("_fid").all),!i)return!1;for(var r,n=this.Model.records,s=0,a=i.length,h=n.length-1;h>-1&&(r=n[h]._fid,i.indexOf(r)>-1&&(n.splice(h,1),s++,t("#fjs_"+r).remove()),s!=a);h--);return this.execCallback("afterRemove"),!0};var o=function(t,e){return this.templateFn(t)};c.render=function(e){var i,r=this;e.length&&(this.execCallback("beforeRender",e),i="beforeRecordRender",t.each(e,function(t){r.execCallback(i,this),this._fid=r._index++,r.has_pagination||r.renderItem(this,t)}))},c.renderItem=function(e,i){if(e){var r=this.view(e,i);"string"==typeof r&&(r=t(t.trim(r))),r.attr("id","fjs_"+e._fid).addClass("fjs_item"),this.appendToContainer(r,e)}};var l=function(t,e){this.$container.append(t)},u=function(t){var e=t.$ele,i=t.$ele.attr("type");return t.selector||("INPUT"==e.get(0).tagName?t.selector="checkbox"==i||"radio"==i?":checked":":input":"SELECT"==e.get(0).tagName&&(t.selector="select")),t.event||(t.event="checkbox"==i||"radio"==i?"click":"change"),t};c.addCriteria=function(e){var i=this;return e?(t.isArray(e)?t.each(e,function(){f.call(i,this)}):f.call(i,e),!0):!1}; -// Add Filter criteria -// criteria: { ele: '#name', event: 'check', field: 'name', type: 'range' } -var f=function(e){return e&&e.field&&e.ele?(e.$ele=t(e.ele),e.$ele.length?(e=u(e),this.bindEvent(e.ele,e.event),e._q=e.field+("range"==e.type?".$bt":""),e.active=!0,this.criterias.push(e),!0):!1):!1};c.removeCriteria=function(e){var i,r,n=this;t.each(n.criterias,function(t){this.field==e&&(r=t)}),null!=r&&(i=this.criterias.splice(r,1)[0],t("body").off(i.event,i.ele))};var p=function(e,i){var r=this;e&&(t.isArray(e)||(e=[e]),t.each(e,function(){var e=this;t.each(r.criterias,function(){this.field==e&&(this.active=i)})}))};c.deactivateCriteria=function(t){p.call(self,t,!1)},c.activateCriteria=function(t){p.call(this,t,!0)},c.getSelectedValues=function(e,i){var r=[];return e.$ele.filter(e.selector).each(function(){r.push(t(this).val())}),t.isArray(r[0])&&(r=[].concat.apply([],r)),e.all&&r.indexOf(e.all)>-1?void 0:("range"==e.type&&(r=r[0].split(e.delimiter||"-")),r=this.parseValues(e.field,r),i.execCallback("onFilterSelect",{criteria:e,values:r})||r)},c.lastResult=function(){return this.last_result||this.records},c.filter=function(){var e,i,r,n={},s=0,a=this;return t.each(this.criterias,function(){this.active&&(e=a.getSelectedValues(this,a),e&&e.length&&(i=t.isArray(e)&&!this.type?this._q+".$in":this._q,n[i]=e,s+=1))}),this.anyFilterSelected=s>0,r=s?this.Model.where(n):this.Model,this.execCallback("shortResult",r),this.last_result=r.all,this.searchFilter(this.last_result)?n:(this.show(this.last_result),this.renderPagination(this.last_result.length),this.execCallback("afterFilter",this.last_result,JsonQuery.blankClone(this.Model,this.last_result)),n)},c.show=function(e,i){var r=0,n=e.length;if(this.has_pagination)for(r=this.page.perPage*(this.page.currentPage-1),n=r+this.page.perPage,this.$container.html(""),r;n>r;r++)this.renderItem(e[r],r);else for(t(".fjs_item").hide(),r;n>r;r++)t("#fjs_"+e[r]._fid).show()},c.filterTimer=function(t){var e=this;this.filterTimeoutId&&clearTimeout(this.filterTimeoutId),this.filterTimeoutId=setTimeout(function(){e.filter()},t)},c.bindEvent=function(e,r){var n=this;t(i).on(r,e,function(t){n.filterTimer(n.opts.timeout||35)})},c.initSearch=function(e){e&&e.ele&&(e.start_length||(this.opts.search.start_length=2),this.$search_ele=t(this.opts.search.ele),this.$search_ele.length&&(this.has_search=!0,this.searchFn=this.buildSearchFn(e.fields),this.bindEvent(e.ele,"keyup")))},c.buildSearchFn=function(e){var i=this,r=[];return e?t.each(e,function(){r.push(i.Model.getterFns[this])}):t.each(i.Model.getterFns,function(t,e){r.push(e)}),function(t,e){t=t.toLocaleUpperCase();for(var i=0,n=r.length;n>i;i++)if((r[i](e)+"").toLocaleUpperCase().indexOf(t)>-1)return!0;return!1}},c.lastSearchResult=function(){return this.search_text.length>this.opts.search.start_length?this.search_result:this.lastResult()},c.searchFilter=function(e){if(this.has_search){var i;return this.search_text=t.trim(this.$search_ele.val()),this.search_text.lengthr;r++)this.searchFn(t,e[r])&&i.push(e[r]);return i}, -//Streaming -c.setStreaming=function(t){t&&(this.opts.streaming=t,t.data_url&&(t.stream_after=1e3*(t.stream_after||2),t.batch_size=t.batch_size||!1,this.streamData(t.stream_after)))};var g=function(){var e=this,i=this.opts.params||{},r=this.opts.streaming;i.offset=this.recordsCount,r.batch_size&&(i.limit=r.batch_size),this.has_search&&(i.q=t.trim(this.$search_ele.val())),t.getJSON(r.data_url,i).done(function(t){null==i.limit||t&&t.length?(e.setStreamInterval(),e.addRecords(t)):e.stopStreaming()}).fail(function(t){e.stopStreaming()})};c.setStreamInterval=function(){var t=this;1!=t.opts.streaming.stop&&(t.streamingTimer=setTimeout(function(){g.call(t)},t.opts.streaming.stream_after))},c.stopStreaming=function(){this.opts.streaming.stop=!0,this.streamingTimer&&clearTimeout(this.streamingTimer)},c.resumeStreaming=function(){this.opts.streaming.stop=!1,this.streamData(this.opts.streaming.stream_after)},c.streamData=function(t){this.setStreamInterval(),this.opts.streaming.batch_size||this.stopStreaming()},c.clear=function(){this.opts.streaming&&this.stopStreaming(),t.each(this.criterias,function(){t(i).off(this.event,this.ele)}),this.opts.search&&t(i).off("keyup",this.opts.search.ele),this.filterTimeoutId&&clearTimeout(this.filterTimeoutId)},c.initPagination=function(){var t=this,e=this.opts.pagination;e.perPage||(e.perPage={}),e.perPage.values||(e.perPage.values=[10,20,30]),this.page={currentPage:1,perPage:e.perPage.values},this.paginator=new d(this.lastResult().length,this.opts.pagination,function(e,i){t.page={currentPage:e,perPage:i},t.has_search?t.show(t.lastSearchResult()):t.show(t.lastResult())}),this.filter()},c.renderPagination=function(t){this.has_pagination&&this.paginator.setRecordCount(t)},c.parseValues=function(e,i){var r=this.Model.schema[e];return"Number"==r?t.map(i,function(t){return Number(t)}):"Boolean"==r?t.map(i,function(t){return"true"==t||1==t}):i},c.setTemplate=function(e,i){this.templateFn=r(t(e).html()),i===!0&&(this.$container.empty(),this.render(this.records),this.filter())};var d=function(e,i,n){var s;this.recordsCount=e,this.opts=i,this.$container=t(this.opts.container),s=this.opts.paginationView?t(this.opts.paginationView).html():_.pagination,this.paginationTmpl=r(s),this.currentPage=1,this.onPagination=n,this.initPerPage(),this.render(),this.bindEvents()},v=d.prototype;v.bindEvents=function(){var e=this;t(this.opts.container).on("click","[data-page]",function(i){e.setCurrentPage(t(this).data("page")),i.preventDefault()})},v.totalPages=function(){return Math.ceil(this.recordsCount/this.perPageCount)},v.setCurrentPage=function(t){t=this.toPage(t),this.prevCurrentPage=this.currentPage,this.currentPage=t,this.paginate(t)},v.setRecordCount=function(t){this.recordsCount=t,this.setCurrentPage(this.currentPage)},v.toPage=function(t){if("first"==t)return 1;if("last"==t)return this.totalPages();if("next"==t){var e=this.currentPage+1;return e>this.totalPages()?this.currentPage:e}if("prev"==t){var i=this.currentPage-1;return 0>=i?this.currentPage:i}return parseInt(t)},v.paginate=function(t){this.render(),this.onPagination(this.currentPage,this.perPageCount)},v.render=function(){var t=this.getPages();this.currentPage>t.totalPages&&(this.currentPage=t.totalPages),0==this.currentPage&&(this.currentPage=1),t.currentPage=this.currentPage,this.$container.html(this.paginationTmpl(t))},v.getPages=function(){var t=this.totalPages();if(!this.opts.visiblePages)return{totalPages:t,pages:n(0,t),self:this};var e=Math.floor(this.opts.visiblePages/2),i=this.currentPage-e+1-this.opts.visiblePages%2,r=this.currentPage+e; -// handle boundary case -return 0>=i&&(i=1,r=this.opts.visiblePages),r>t&&(i=t-this.opts.visiblePages,0>=i&&(i=1),r=t),{currentPage:this.currentPage,totalPages:t,pages:n(i,r),self:this}},v.initPerPage=function(){var e,i,n,s,a=this.opts.perPage,h=this;this.perPageCount=a.values[0],e=a.perPageView?t(a.perPageView).html():_.per_page,i=r(e)({values:a.values}),t(a.container).html(i),n=t(a.container).find("[data-perpage]"),s="SELECT"==n.get(0).tagName?"change":"click",t(a.container).on(s,"[data-perpage]",function(e){var i=parseInt(t(this).val()||t(this).data("value"));h.setPerPage(i),e.preventDefault()})},v.setPerPage=function(t){this.perPageCount=t,this.setCurrentPage(this.currentPage)},t.fn.filterjs=function(e,i){var r=t(this);r.data("fjs")||r.data("fjs",P(e,r,i))};var m=[],_=[],P=function(t,e,i){var r=new h(t,e,i);return m.push(r),r};P.list=m,P.templateBuilder=r,e.FilterJS=P,_.pagination='',_.per_page='',P.auto=function(t,e){var i,r,n,a={},h=s("items");return h&&h.template?(a.template=h.template,r=s("search"),r&&(r.fields&&(r.fields=r.fields.split(",")),a.search=r),e&&(a.callbacks=e),i=P(t,h.ele,a),n=s("criteria",!0),n&&i.addCriteria(n),i):void 0}}(jQuery,window,document); \ No newline at end of file +!function(t){"use strict";var e=function(t,e){return new s(t,e||{})};t.JsonQuery=e,e.VERSION="0.0.2",e.Config={id:"id",latitude:"latitude",longitude:"longitude",date_regx:/^\d{4}-\d{2}-\d{2}$/},e.blankClone=function(t,e){return new s(e,{getterFns:t.getterFns,schema:t.schema,id:t.id,latitude:t.latitude,longitude:t.longitude})};var i=e.Config,r=function(t,e,i){if(t.length===+t.length)for(var r=0,n=t.length;n>r;r++)e.call(i,t[r],r);else for(var s in t)hasOwnProperty.call(t,s)&&e.call(i,t[s],s)},n=function(t,e,i){for(var r=0,n=t.length;n>r;r++)if(e.call(i,t[r],r)===!1)return},s=function(t,e){this.records=t||[],this.getterFns=e.getterFns||{},this.lat=e.latitude||i.latitude,this.lng=e.longitude||i.longitude,this.id=e.id,e.schema&&(this.schema=e.schema),this.records.length&&!this.schema&&c(this,t[0],e.schema)},a=s.prototype,c=function(t,e,r){t.schema={},t.id||(t.id=e._id?"_id":i.id),r||(o.call(t,e),l.call(t,e))},h=function(t){if(null==t)return"String";var e=Object.prototype.toString.call(t).slice(8,-1);return"String"==e&&t.match(i.date_regx)?"Date":e},o=function(t,e){var i,r,n,s;for(i in t)s=t[i],r=h(s),n=e?e+"."+i:i,this.schema[n]=r,"Object"==r?o.call(this,s,n):"Array"==r&&(["Object","Array"].indexOf(h(s[0]))>-1?o.call(this,t[i][0],n):this.schema[n]=h(s[0]))},l=function(t){var e,i,r;for(e in this.schema){i=this.schema[e];try{this.getterFns[e]||(this.getterFns[e]=f.call(this,e,i)),r=this.getterFns[e](t),"Array"==h(r)&&(this.schema[e]="Array")}catch(n){console.log("Error while generating getter function for selector : "+e+" NOTE: Define manually")}}},u=function(t,e){for(var i,r=0,n=0,s=e.length-1,a=e.length-1;a>=0;a--)i=e.slice(0,a+1).join("."),"Array"==t[i]&&s>a&&(r=a,n+=1);return n>1?r+1:-1},f=function(t,e){for(var i,r,n,s="",a=t.split("."),c=u(this.schema,a),h=a.length-1;h>=0;h--)i=a.slice(0,h+1).join("."),r="['"+a[h]+"']",s="Array"==this.schema[i]?c==h?r+(s.length?".every(function(r"+h+"){ objs.push(r"+h+s+")})":""):r+(s.length?".map(function(r"+h+"){ return r"+h+s+"})":""):r+s;return n=c>-1?"var objs = []; obj"+s+";"+("Date"==this.schema.path?"return parseDate(objs)":"return objs;"):"return "+("Date"==this.schema.path?"parseDate(obj"+s+");":"obj"+s+";"),new Function("obj",n)};a.operators={eq:function(t,e){return t==e},ne:function(t,e){return t!=e},lt:function(t,e){return e>t},lte:function(t,e){return e>=t},gt:function(t,e){return t>e},gte:function(t,e){return t>=e},"in":function(t,e){return e.indexOf(t)>-1},ni:function(t,e){return-1==e.indexOf(t)},li:function(t,e){return e.test(t)},bt:function(t,e){return t>=e[0]&&t<=e[1]}},a.addOperator=function(t,e){this.operators[t]=e};var p=function(t,e,i){var r=0,n=t.length;for(r;n>r;r++)if(i(t[r],e))return!0};a.addCondition=function(t,e){this.operators[t]=e},a.getCriteria=function(t){var e=t.split(".$");return{field:e[0],operator:e[1]||"eq"}},a.setGetterFn=function(t,e){this.getterFns[t]=e},a.addRecords=function(t){return t&&t.length?("Array"==h(t)?this.records=this.records.concat(t):this.records.push(t),this.schema||c(this,t[0]),!0):!1},a._findAll=function(t,e,i,n){var s,a,c,h=[],o=this.getterFns[e];return"li"==n&&"string"==typeof i&&(i=new RegExp(i)),s=this.operators[n],"Array"==this.schema[e]&&(c=s,s=p),r(t,function(t){a=o(t),s(a,i,c)&&h.push(t)}),h},a.find=function(t,e){var i,r;return e||(e=t,t=this.id),r=this.getterFns[t],n(this.records,function(t){return r(t)==e?(i=t,!1):void 0}),i},r(["where","or","groupBy","select","pluck","limit","offset","order","uniq","near"],function(t){a[t]=function(e){var i=new y(this,this.records);return i[t].apply(i,arguments),i}}),r(["update_all","destroy_all"],function(t){a[t]=function(e){var i=new y(this,this.records);return i[t].apply(i,arguments)}}),r(["count","first","last","all"],function(t){Object.defineProperty(a,t,{get:function(){return new y(this,this.records)[t]}})});var g=function(t,e,i){for(var r=0,n=i.length;n>r;r++)if(this.getterFns[i[r]](t)!==this.getterFns[i[r]](e))return!1;return!0},d=function(t,e){var i,r,n;for(i in t)r=this.jQ.getCriteria(i),n=this.jQ._findAll(n||e,r.field,t[i],r.operator);return n},v=function(t,e){var i,n=this.jQ.getterFns[t],s={};e.length;return r(e,function(t){i=n(t),(s[i]||(s[i]=[])).push(t)}),s},m=function(t,e){for(var i,r,n=e.slice(0),s=0,a=t.length;a>s;s++)i=this.jQ.getterFns[t[s].field],r="asc"==t[s].direction?1:-1,n.sort(function(t,e){var n=i(t),s=i(e);return(s>n?-1:n>s?1:0)*r});return n},_=function(t,e){var i,n=this,s=[];return r(t,function(t){i=n.jQ.getterFns[t],r(e,function(e,r){(s[r]||(s[r]={}))[t]=i(e)})}),s},P=function(t,e){var i=this.jQ.getterFns[t],n=[];return r(e,function(t){n.push(i(t))}),n},b=function(t,e){var i=[],n=this;return"Object"!=h(e[0])?(r(e,function(t){-1==i.indexOf(t)&&i.push(t)}),i):(i.push(e[0]),r(e,function(e){for(var r=!1,s=0,a=i.length;a>s;s++)g.call(n.jQ,i[s],e,t)&&(r=!0);r||i.push(e)}),i)},y=function(t,e){return this.jQ=t,this.records=e,this.criteria={},this},j=y.prototype;j.each=function(t,e){r(this.exec()||[],t,e)},j.exec=j.toArray=function(t){var e;return this.criteria.all&&(e=this.records),this.criteria.where&&(e=d.call(this,this.criteria.where,e||this.records)),this.criteria.or&&(e=e.concat(d.call(this,this.criteria.or,this.records)),e=b.call(this,[this.jQ.id],e)),this.criteria.order&&(e=m.call(this,this.criteria.order,e||this.records)),this.criteria.near&&(e=F.call(this,this.criteria.near,e||this.records)),this.criteria.uniq&&(e=b.call(this,this.criteria.uniq,e||this.records)),this.criteria.select&&(e=_.call(this,this.criteria.select,e||this.records)),this.criteria.pluck&&(e=P.call(this,this.criteria.pluck,e||this.records)),this.criteria.limit&&(e=(e||this.records).slice(this.criteria.offset||0,(this.criteria.offset||0)+this.criteria.limit)),this.criteria.group_by&&(e=v.call(this,this.criteria.group_by,e||this.records)),e||(e=this.records),t&&r(e,t),this.jQ.onResult&&this.jQ.onResult(e,this.criteria),e};var C=function(t,e){var i;this.criteria[t]||(this.criteria[t]={});for(i in e)this.criteria[t][i]=e[i];return this};j.where=function(t){return C.call(this,"where",t)},j.or=function(t){return C.call(this,"or",t)},j.groupBy=function(t){return this.criteria.group_by=t,this},j.select=function(){return this.criteria.select=arguments,this},j.pluck=function(t){return this.criteria.pluck=t,this},j.limit=function(t){return this.criteria.limit=t,this},j.offset=function(t){return this.criteria.offset=t,this},j.order=function(t){var e;this.criteria.order=this.criteria.order||[];for(e in t)this.criteria.order.push({field:e,direction:t[e].toLowerCase()});return this},j.uniq=function(){return this.criteria.uniq=arguments.length>0?arguments:!0,this},Object.defineProperty(j,"count",{get:function(){this.criteria.count=!0;var t=this.exec();return"Array"==h(t)?this.exec().length:Object.keys(t).length}}),Object.defineProperty(j,"all",{get:function(){return this.criteria.all=!0,this.exec()}}),Object.defineProperty(j,"first",{get:function(){return this.criteria.first=!0,this.exec()[0]}}),Object.defineProperty(j,"last",{get:function(){this.criteria.last=!0;var t=this.exec();return t[t.length-1]}});var x={redius:6371,toRad:function(t){return t*Math.PI/180}},k=function(t,e,i,r){var n=x.toRad(e-t),s=x.toRad(r-i),t=x.toRad(t),e=x.toRad(e),a=Math.sin(n/2)*Math.sin(n/2)+Math.sin(s/2)*Math.sin(s/2)*Math.cos(t)*Math.cos(e);return 2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a))*x.redius},F=function(t,e){var i=[],n=this,s="mile"==t.unit?.6214:1,a=n.jQ.getterFns[n.jQ.lat],c=n.jQ.getterFns[n.jQ.lng];return r(e,function(e){e._distance=k(a(e),t.lat,c(e),t.lng)*s,e._distance<=t.distance&&i.push(e)}),i.sort(function(t,e){return t._distancee._distance?1:0}),i};j.near=function(t,e,i,r){return this.criteria.near={lat:t,lng:e,distance:i,unit:r||"km"},this},j.map=j.collect=function(t){var e,i=[];return this.exec(function(r){(e=t(r))&&i.push(e)}),i},j.sum=function(t){var e,i=0,n=this.jQ.getterFns[t];return this.criteria.group_by&&(e=!0,i={}),this.exec(function(t,s){e?(i[s]=0,r(t,function(t){i[s]=i[s]+(n(t)||0)})):i+=n(t)||0}),i},j.toJQ=function(){var t=e(this.all,{schema:!0});return t.schema=this.jQ.schema,t.getterFns=this.jQ.getterFns,t},j.destroy_all=j.destroy=function(){var t=this.all;return r(t,function(t,e){t._destroy_=!0}),this.records=this.jQ.records=this.records.filter(function(t){return!t._destroy_}),t},j.update_all=j.update=function(t){if(!t)return!1;var e=0;return r(this.all,function(i){r(t,function(t,e){i[e]=t}),e+=1}),e},Array.prototype.indexOf||(Array.prototype.indexOf=function(t,e){for(var i=e||0,r=this.length;r>i;i++)if(this[i]===t)return i;return-1}),Object.defineProperty||(Object.defineProperty=function(t,e,i){t[e]=i.get})}(this),function(t,e,i){"use strict";function r(t,e){var i=a;t=c(t);var r="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+t.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(i.escape,function(t,e){return"',escapeStr("+e.replace(/\\'/g,"'")+"),'"}).replace(i.interpolate,function(t,e){return"',"+e.replace(/\\'/g,"'")+",'"}).replace(i.evaluate||null,function(t,e){return"');"+e.replace(/\\'/g,"'").replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",n=new Function("obj",r);return e?n(e):function(t){return n(t)}}function n(t,e){var i=t,r=[];for(i;e>=i;i++)r.push(i);return r}function s(e,i){var r="fjs-"+e,n=t("["+r+"]"),s=[];return n.length?(t.each(n,function(){var e=t(this),i={ele:e},n=e.attr(r);return s.push(i),n?void t.each(n.split(","),function(t,e){var r=e.split("=");i[r[0]]=r[1]}):s}),i?s:s[0]):void 0}var a={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g},c=function(t){return(""+t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(///g,"/")},h=function(e,i,r){var n=this;this.opts=r||{},this.callbacks=this.opts.callbacks||{},this.$container=t(i),this.view=this.opts.view||l,this.criterias=[],this._index=1,this.appendToContainer=this.opts.appendToContainer||u,this.has_pagination=!!this.opts.pagination,this.search_text="",this.anyFilterSelected=!1,this.setTemplate(this.opts.template),t.each(this.opts.criterias||[],function(){n.addCriteria(this)}),this.Model=JsonQuery(),this.Model.getterFns._fid=function(t){return t._fid},this.addRecords(e,!1),this.has_pagination&&this.initPagination()},o=h.prototype;Object.defineProperty(o,"records",{get:function(){return this.Model.records}}),Object.defineProperty(o,"recordsCount",{get:function(){return this.Model.records.length}}),o.templateBuilder=r,o.execCallback=function(){var t=arguments[0];this.callbacks[t]&&this.callbacks[t].apply(this,Array.prototype.slice.call(arguments,1))},o.addCallback=function(t,e){t&&e&&(this.callbacks[t]=e)},o.addRecords=function(t,e){!!this.Model.schema;this.execCallback("beforeAddRecords",t),this.Model.addRecords(t)&&(this.has_scheme||this.initSearch(this.opts.search),this.render(t),e!==!1&&this.filter()),this.execCallback("afterAddRecords",t)},o.removeRecords=function(e){var i;if(t.isPlainObject(e)?i=this.Model.where(e).pluck("_fid").all:t.isArray(e)&&(i=this.Model.where({"id.$in":e}).pluck("_fid").all),!i)return!1;for(var r,n=this.Model.records,s=0,a=i.length,c=n.length-1;c>-1&&(r=n[c]._fid,i.indexOf(r)>-1&&(n.splice(c,1),s++,t("#fjs_"+r).remove()),s!=a);c--);return this.execCallback("afterRemove"),!0};var l=function(t,e){return this.templateFn(t)};o.render=function(e){var i,r=this;e.length&&(this.execCallback("beforeRender",e),i="beforeRecordRender",t.each(e,function(t){r.execCallback(i,this),this._fid=r._index++,r.has_pagination||r.renderItem(this,t)}))},o.renderItem=function(e,i){if(e){var r=this.view(e,i);"string"==typeof r&&(r=t(t.trim(r))),r.attr("id","fjs_"+e._fid).addClass("fjs_item"),this.appendToContainer(r,e)}};var u=function(t,e){this.$container.append(t)},f=function(t){var e=t.$ele,i=t.$ele.attr("type");return t.selector||("INPUT"==e.get(0).tagName?t.selector="checkbox"==i||"radio"==i?":checked":":input":"SELECT"==e.get(0).tagName&&(t.selector="select")),t.event||(t.event="checkbox"==i||"radio"==i?"click":"change"),t};o.addCriteria=function(e){var i=this;return e?(t.isArray(e)?t.each(e,function(){p.call(i,this)}):p.call(i,e),!0):!1};var p=function(e){return e&&e.field&&e.ele?(e.$ele=t(e.ele),e.$ele.length?(e=f(e),this.bindEvent(e.ele,e.event),e._q=e.field+("range"==e.type?".$bt":""),e.active=!0,this.criterias.push(e),!0):!1):!1};o.removeCriteria=function(e){var i,r,n=this;t.each(n.criterias,function(t){this.field==e&&(r=t)}),null!=r&&(i=this.criterias.splice(r,1)[0],t("body").off(i.event,i.ele))};var g=function(e,i){var r=this;e&&(t.isArray(e)||(e=[e]),t.each(e,function(){var e=this;t.each(r.criterias,function(){this.field==e&&(this.active=i)})}))};o.deactivateCriteria=function(t){g.call(self,t,!1)},o.activateCriteria=function(t){g.call(this,t,!0)},o.getSelectedValues=function(e,i){var r=[];return e.$ele.filter(e.selector).each(function(){r.push(t(this).val())}),t.isArray(r[0])&&(r=[].concat.apply([],r)),e.all&&r.indexOf(e.all)>-1?void 0:("range"==e.type&&(r=r[0].split(e.delimiter||"-")),r=this.parseValues(e.field,r),i.execCallback("onFilterSelect",{criteria:e,values:r})||r)},o.lastResult=function(){return this.last_result||this.records},o.filter=function(){var e,i,r,n={},s=0,a=this;return t.each(this.criterias,function(){this.active&&(e=a.getSelectedValues(this,a),e&&e.length&&(i=t.isArray(e)&&!this.type?this._q+".$in":this._q,n[i]=e,s+=1))}),this.anyFilterSelected=s>0,r=s?this.Model.where(n):this.Model,this.execCallback("shortResult",r),this.last_result=r.all,this.searchFilter(this.last_result)?n:(this.show(this.last_result),this.renderPagination(this.last_result.length),this.execCallback("afterFilter",this.last_result,JsonQuery.blankClone(this.Model,this.last_result)),n)},o.show=function(e,i){var r=0,n=e.length;if(this.has_pagination)for(r=this.page.perPage*(this.page.currentPage-1),n=r+this.page.perPage,this.$container.html(""),r;n>r;r++)this.renderItem(e[r],r);else for(t(".fjs_item").hide(),r;n>r;r++)t("#fjs_"+e[r]._fid).show()},o.filterTimer=function(t){var e=this;this.filterTimeoutId&&clearTimeout(this.filterTimeoutId),this.filterTimeoutId=setTimeout(function(){e.filter()},t)},o.bindEvent=function(e,r){var n=this;t(i).on(r,e,function(t){n.filterTimer(n.opts.timeout||35)})},o.initSearch=function(e){e&&e.ele&&(e.start_length||(this.opts.search.start_length=2),this.$search_ele=t(this.opts.search.ele),this.$search_ele.length&&(this.has_search=!0,this.searchFn=this.buildSearchFn(e.fields),this.bindEvent(e.ele,"keyup")))},o.buildSearchFn=function(e){var i=this,r=[];return e?t.each(e,function(){r.push(i.Model.getterFns[this])}):t.each(i.Model.getterFns,function(t,e){r.push(e)}),function(t,e){t=t.toLocaleUpperCase();for(var i=0,n=r.length;n>i;i++)if((r[i](e)+"").toLocaleUpperCase().indexOf(t)>-1)return!0;return!1}},o.lastSearchResult=function(){return this.search_text.length>this.opts.search.start_length?this.search_result:this.lastResult()},o.searchFilter=function(e){if(this.has_search){var i;return this.search_text=t.trim(this.$search_ele.val()),this.search_text.lengthr;r++)this.searchFn(t,e[r])&&i.push(e[r]);return i},o.setStreaming=function(t){t&&(this.opts.streaming=t,t.data_url&&(t.stream_after=1e3*(t.stream_after||2),t.batch_size=t.batch_size||!1,this.streamData(t.stream_after)))};var d=function(){var e=this,i=this.opts.params||{},r=this.opts.streaming;i.offset=this.recordsCount,r.batch_size&&(i.limit=r.batch_size),this.has_search&&(i.q=t.trim(this.$search_ele.val())),t.getJSON(r.data_url,i).done(function(t){null==i.limit||t&&t.length?(e.setStreamInterval(),e.addRecords(t)):e.stopStreaming()}).fail(function(t){e.stopStreaming()})};o.setStreamInterval=function(){var t=this;1!=t.opts.streaming.stop&&(t.streamingTimer=setTimeout(function(){d.call(t)},t.opts.streaming.stream_after))},o.stopStreaming=function(){this.opts.streaming.stop=!0,this.streamingTimer&&clearTimeout(this.streamingTimer)},o.resumeStreaming=function(){this.opts.streaming.stop=!1,this.streamData(this.opts.streaming.stream_after)},o.streamData=function(t){this.setStreamInterval(),this.opts.streaming.batch_size||this.stopStreaming()},o.clear=function(){this.opts.streaming&&this.stopStreaming(),t.each(this.criterias,function(){t(i).off(this.event,this.ele)}),this.opts.search&&t(i).off("keyup",this.opts.search.ele),this.filterTimeoutId&&clearTimeout(this.filterTimeoutId)},o.initPagination=function(){var t=this,e=this.opts.pagination;e.perPage||(e.perPage={}),e.perPage.values||(e.perPage.values=[10,20,30]),this.page={currentPage:1,perPage:e.perPage.values},this.paginator=new v(this.execCallback,this.callbacks,this.lastResult().length,this.opts.pagination,function(e,i){t.page={currentPage:e,perPage:i},t.has_search?t.show(t.lastSearchResult()):t.show(t.lastResult())}),this.filter()},o.renderPagination=function(t){this.has_pagination&&this.paginator.setRecordCount(t)},o.parseValues=function(e,i){var r=this.Model.schema[e];return"Number"==r?t.map(i,function(t){return Number(t)}):"Boolean"==r?t.map(i,function(t){return"true"==t||1==t}):i},o.setTemplate=function(e,i){this.templateFn=r(t(e).html()),i===!0&&(this.$container.empty(),this.render(this.records),this.filter())};var v=function(e,i,n,s,a){var c;this.execCallback=e,this.callbacks=i,this.recordsCount=n,this.opts=s,this.$container=t(this.opts.container),c=this.opts.paginationView?t(this.opts.paginationView).html():P.pagination,this.paginationTmpl=r(c),this.currentPage=1,this.onPagination=a,this.initPerPage(),this.render(),this.bindEvents()},m=v.prototype;m.bindEvents=function(){var e=this;t(this.opts.container).on("click","[data-page]",function(i){e.execCallback("beforeChangePage"),e.setCurrentPage(t(this).data("page")),e.execCallback("afterChangePage"),i.preventDefault()})},m.totalPages=function(){return Math.ceil(this.recordsCount/this.perPageCount)},m.setCurrentPage=function(t){t=this.toPage(t),this.prevCurrentPage=this.currentPage,this.currentPage=t,this.paginate(t)},m.setRecordCount=function(t){this.recordsCount=t,this.setCurrentPage(this.currentPage)},m.toPage=function(t){if("first"==t)return 1;if("last"==t)return this.totalPages();if("next"==t){var e=this.currentPage+1;return e>this.totalPages()?this.currentPage:e}if("prev"==t){var i=this.currentPage-1;return 0>=i?this.currentPage:i}return parseInt(t)},m.paginate=function(t){this.render(),this.onPagination(this.currentPage,this.perPageCount)},m.render=function(){var t=this.getPages();this.currentPage>t.totalPages&&(this.currentPage=t.totalPages),0==this.currentPage&&(this.currentPage=1),t.currentPage=this.currentPage,this.$container.html(this.paginationTmpl(t))},m.getPages=function(){var t=this.totalPages();if(!this.opts.visiblePages)return{totalPages:t,pages:n(0,t),self:this};var e=Math.floor(this.opts.visiblePages/2),i=this.currentPage-e+1-this.opts.visiblePages%2,r=this.currentPage+e;return 0>=i&&(i=1,r=this.opts.visiblePages),r>t&&(i=t-this.opts.visiblePages,0>=i&&(i=1),r=t),{currentPage:this.currentPage,totalPages:t,pages:n(i,r),self:this}},m.initPerPage=function(){var e,i,n,s,a=this.opts.perPage,c=this;this.perPageCount=a.values[0],e=a.perPageView?t(a.perPageView).html():P.per_page,i=r(e)({values:a.values}),t(a.container).html(i),n=t(a.container).find("[data-perpage]"),s="SELECT"==n.get(0).tagName?"change":"click",t(a.container).on(s,"[data-perpage]",function(e){var i=parseInt(t(this).val()||t(this).data("value"));c.setPerPage(i),e.preventDefault()})},m.setPerPage=function(t){this.perPageCount=t,this.setCurrentPage(this.currentPage)},t.fn.filterjs=function(e,i){var r=t(this);r.data("fjs")||r.data("fjs",b(e,r,i))};var _=[],P=[],b=function(t,e,i){var r=new h(t,e,i);return _.push(r),r};b.list=_,b.templateBuilder=r,e.FilterJS=b,P.pagination='',P.per_page='',b.auto=function(t,e){var i,r,n,a={},c=s("items");return c&&c.template?(a.template=c.template,r=s("search"),r&&(r.fields&&(r.fields=r.fields.split(",")),a.search=r),e&&(a.callbacks=e),i=b(t,c.ele,a),n=s("criteria",!0),n&&i.addCriteria(n),i):void 0}}(jQuery,window,document);