app/assets/javascripts/livelist.min.js in livelist-rails-0.0.12 vs app/assets/javascripts/livelist.min.js in livelist-rails-0.0.14
- old
+ new
@@ -1 +1 @@
-((function(){var a=function(a,b){return function(){return a.apply(b,arguments)}},b=Object.prototype.hasOwnProperty,c=function(a,c){function e(){this.constructor=a}for(var d in c)b.call(c,d)&&(a[d]=c[d]);return e.prototype=c.prototype,a.prototype=new e,a.__super__=c.prototype,a};window.Utilities=function(){function b(){this.setOptions=a(this.setOptions,this)}return b.prototype.setOptions=function(a,b){var c=this;return b==null&&(b=this),_.each(a,function(a,c){return b[c]=a})},b}(),window.LiveList=function(a){function b(a){this.listSelector=a.list.renderTo,this.resourceName=a.global.resourceName,this.resourceNameSingular=a.global.resourceNameSingular,this.urlPrefix=a.global.urlPrefix||"/"+this.resourceName,this.httpMethod=a.global.httpMethod||"get",this.eventName="livelist:"+this.resourceName,this.search=new Search(a.search,this),this.filters=new Filters(a.filters,this),this.pagination=new Pagination(a.pagination,this),this.list=new List(a.list,this)}return c(b,a),b}(Utilities),window.List=function(b){function d(b,c){this.renderIndex=a(this.renderIndex,this),this.removeFetchingIndication=a(this.removeFetchingIndication,this),this.displayFetchingIndication=a(this.displayFetchingIndication,this);var d=this;this.fetchRequest=null,this.livelist=c,this.listTemplate="{{#"+this.livelist.resourceName+"}}{{>"+this.livelist.resourceNameSingular+"}}{{/"+this.livelist.resourceName+"}}",this.listItemTemplate="<li>{{id}}</li>",this.fetchingIndicationClass="updating",this.renderTo="ul#"+this.livelist.resourceName,this.setOptions(b),$(this.renderTo).bind(this.livelist.eventName,function(a,b){return d.fetch({presets:null,page:b!=null?b.page:void 0})}),this.fetch({presets:this.livelist.filters.getPresets()})}return c(d,b),d.prototype.displayFetchingIndication=function(){return $(this.renderTo).addClass(this.fetchingIndicationClass)},d.prototype.removeFetchingIndication=function(){return $(this.renderTo).removeClass(this.fetchingIndicationClass)},d.prototype.renderIndex=function(a,b,c){return this.livelist.data=a,this.render(),this.livelist.pagination.render(this.livelist.data),this.livelist.filters.render(this.livelist.data)},d.prototype.fetch=function(a){var b,c;return this.fetchRequest&&this.fetchRequest.abort(),c=this.livelist.search.searchTerm(),b={},b.filters=this.livelist.filters.setPresets(a.presets),c&&(b.q=c),a.page&&(b.page=a.page),this.fetchRequest=$.ajax({url:this.livelist.urlPrefix,type:this.livelist.httpMethod,dataType:"json",data:b,beforeSend:this.displayFetchingIndication,success:this.renderIndex})},d.prototype.render=function(){var a,b;return b={},b[this.livelist.resourceNameSingular]=this.listItemTemplate,a=Mustache.to_html(this.listTemplate,this.livelist.data,b),$(this.renderTo).html(a),this.removeFetchingIndication()},d}(Utilities),window.LiveList.version="0.0.7",window.Filters=function(b){function d(b,c){this.handleAdvancedOptionsClick=a(this.handleAdvancedOptionsClick,this);var d=this;this.livelist=c,this.filters=b.presets?_.keys(b.presets):[],this.initializeCookies(),this.setOptions(b),$("input.filter_option",this.renderTo).live("change",function(){return $(d.livelist.listSelector).trigger(d.livelist.eventName)}),$(this.advancedOptionsToggleSelector).click(this.handleAdvancedOptionsClick)}return c(d,b),d.prototype.initializeCookies=function(){if(jQuery.cookie&&this.useCookies&&this.cookieName)return this.cookieName="livelist_filter_presets"},d.prototype.getPresets=function(){var a;return jQuery.cookie&&this.useCookies&&(a=jQuery.cookie(this.cookieName)),this.useCookies&&a?JSON.parse(a):this.presets},d.prototype.setPresets=function(a){var b;return b={},jQuery.isEmptyObject(a)?(b=this.selections(),jQuery.cookie&&this.setCookie(b)):b=a,b},d.prototype.setCookie=function(a){if(!jQuery.isEmptyObject(a))return jQuery.cookie(this.cookieName,JSON.stringify(a))},d.prototype.template="{{#filters}}\n<div class='filter'>\n <h3>\n {{name}}\n </h3>\n <ul id='{{filter_slug}}_filter_options'>\n {{#options}}\n <label>\n <li>\n <input {{#selected}}checked='checked'{{/selected}}\n class='left filter_option'\n id='filter_{{slug}}'\n name='filters[]'\n type='checkbox'\n value='{{value}}' />\n <div class='left filter_name'>{{name}}</div>\n <div class='right filter_count'>{{count}}</div>\n <div class='clear'></div>\n </li>\n </label>\n {{/options}}\n </ul>\n</div>\n{{/filters}}",d.prototype.selections=function(){var a,b=this;return a={},_.each(this.filters,function(b){return a[b]=_.pluck($("#"+b+"_filter_options input.filter_option:checked"),"value")}),a},d.prototype.noFiltersSelected=function(a){return _.all(a.filters,function(a){return _.all(a.options,function(a){return!a.selected})})},d.prototype.sortOptions=function(a){return _.map(a,function(a){return a.options=_.sortBy(a.options,function(a){return a.name}),a})},d.prototype.sort=function(a){return _.sortBy(a,function(a){return a.name})},d.prototype.render=function(a){var b;this.filters=_.pluck(a.filters,"filter_slug"),this.sort(a.filters),this.sortOptions(a.filters),b=Mustache.to_html(this.template,a),$(this.renderTo).html(b);if(this.noFiltersSelected(a)&&a[this.livelist.resourceName].length>0)return $('input[type="checkbox"]',this.renderTo).attr("checked","checked")},d.prototype.handleAdvancedOptionsClick=function(a){return a.preventDefault(),$(this.renderTo).slideToggle()},d}(Utilities),window.Pagination=function(b){function d(b,c){this.handlePaginationLinkClick=a(this.handlePaginationLinkClick,this),this.livelist=c,this.pagination=null,this.maxPages=30,this.emptyListMessage="<p>No "+this.livelist.resourceName+" matched your filter criteria</p>",this.setOptions(b),$(""+this.renderTo+" a").live("click",function(a){return a.preventDefault()}),$(""+this.renderTo+" li:not(.disabled) a").live("click",this.handlePaginationLinkClick)}return c(d,b),d.prototype.template="{{#isEmpty}}\n {{{emptyListMessage}}}\n{{/isEmpty}}\n{{^isEmpty}}\n<div class=\"pagination\">\n <ul>\n <li class=\"{{^previousPage}}disabled{{/previousPage}}\">\n <a href='{{urlPrefix}}?page={{previousPage}}' data-page='{{previousPage}}'>← Previous</a>\n </li>\n\n {{#pages}}\n <li class=\"{{#currentPage}}active disabled{{/currentPage}}\">\n <a href='{{urlPrefix}}?page={{page}}' data-page='{{page}}'>{{page}}</a>\n </li>\n {{/pages}}\n\n <li class=\"{{^nextPage}}disabled{{/nextPage}}\">\n <a href='{{urlPrefix}}?page={{nextPage}}' data-page='{{nextPage}}'>Next →</a>\n </li>\n </ul>\n</div>\n{{/isEmpty}}",d.prototype.pagesJSON=function(a,b){var c,d,e,f,g,h;return d=Math.floor(this.maxPages/2),c=a<=d?1:a-d,f=c+d*2-1,e=f>=b?b:f,_.map(function(){h=[];for(var a=c;c<=e?a<=e:a>=e;c<=e?a++:a--)h.push(a);return h}.apply(this),function(b){return{page:b,currentPage:a===b}})},d.prototype.paginationJSON=function(a){return{isEmpty:a.total_pages===0,emptyListMessage:this.emptyListMessage,currentPage:a.current_page,nextPage:a.next_page,previousPage:a.previous_page,urlPrefix:this.livelist.urlPrefix,pages:this.pagesJSON(a.current_page,a.total_pages)}},d.prototype.render=function(a){var b;return this.pagination=this.paginationJSON(a.pagination),b=Mustache.to_html(this.template,this.pagination),$(this.renderTo).html(b)},d.prototype.handlePaginationLinkClick=function(a){return a.preventDefault(),$(this.livelist.listSelector).trigger(this.livelist.eventName,{page:$(a.target).data("page")})},d}(Utilities),window.Search=function(b){function d(b,c){this.handleSearchFormSubmit=a(this.handleSearchFormSubmit,this);var d=this;this.livelist=c,this.setOptions(b),$(this.formSelector).submit(function(a){return d.handleSearchFormSubmit(a)})}return c(d,b),d.prototype.searchTerm=function(){var a;return a=$(this.searchTextInputSelector).val(),!a||a===""?null:a},d.prototype.handleSearchFormSubmit=function(a){return a.preventDefault(),$(this.livelist.listSelector).trigger(this.livelist.eventName)},d}(Utilities)})).call(this);
+var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}};window.Utilities=function(){function Utilities(){this.setOptions=__bind(this.setOptions,this)}Utilities.prototype.setOptions=function(options,context){var _this=this;if(context==null){context=this}return _.each(options,function(value,option){return context[option]=value})};return Utilities}();var __hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};window.LiveList=function(_super){__extends(LiveList,_super);function LiveList(options){this.listSelector=options.list.renderTo;this.resourceName=options.global.resourceName;this.resourceNameSingular=options.global.resourceNameSingular;this.urlPrefix=options.global.urlPrefix||"/"+this.resourceName;this.httpMethod=options.global.httpMethod||"get";this.eventName="livelist:"+this.resourceName;this.search=new Search(options.search,this);this.filters=new Filters(options.filters,this);this.pagination=new Pagination(options.pagination,this);this.list=new List(options.list,this)}return LiveList}(Utilities);var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};window.List=function(_super){__extends(List,_super);function List(options,livelist){this.renderIndex=__bind(this.renderIndex,this);this.removeFetchingIndication=__bind(this.removeFetchingIndication,this);this.displayFetchingIndication=__bind(this.displayFetchingIndication,this);var _this=this;this.fetchRequest=null;this.livelist=livelist;this.listTemplate="{{#"+this.livelist.resourceName+"}}{{>"+this.livelist.resourceNameSingular+"}}{{/"+this.livelist.resourceName+"}}";this.listItemTemplate="<li>{{id}}</li>";this.fetchingIndicationClass="updating";this.renderTo="ul#"+this.livelist.resourceName;this.setOptions(options);$(this.renderTo).bind(this.livelist.eventName,function(event,params){return _this.fetch({presets:null,page:params!=null?params.page:void 0})});this.fetch({presets:this.livelist.filters.getPresets()})}List.prototype.displayFetchingIndication=function(){return $(this.renderTo).addClass(this.fetchingIndicationClass)};List.prototype.removeFetchingIndication=function(){return $(this.renderTo).removeClass(this.fetchingIndicationClass)};List.prototype.renderIndex=function(data,textStatus,jqXHR){this.livelist.data=data;this.render();this.livelist.pagination.render(this.livelist.data);return this.livelist.filters.render(this.livelist.data)};List.prototype.fetch=function(options){var params,searchTerm;if(this.fetchRequest){this.fetchRequest.abort()}searchTerm=this.livelist.search.searchTerm();params={};params.filters=this.livelist.filters.setPresets(options.presets);if(searchTerm){params.q=searchTerm}if(options.page){params.page=options.page}return this.fetchRequest=$.ajax({url:this.livelist.urlPrefix,type:this.livelist.httpMethod,dataType:"json",data:params,beforeSend:this.displayFetchingIndication,success:this.renderIndex})};List.prototype.render=function(){var listHTML,partials;partials={};partials[this.livelist.resourceNameSingular]=this.listItemTemplate;listHTML=Mustache.to_html(this.listTemplate,this.livelist.data,partials);$(this.renderTo).html(listHTML);return this.removeFetchingIndication()};return List}(Utilities);window.LiveList.version="0.0.9";var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};window.Filters=function(_super){__extends(Filters,_super);function Filters(options,livelist){this.handleAdvancedOptionsClick=__bind(this.handleAdvancedOptionsClick,this);var _this=this;this.livelist=livelist;this.filters=options.presets?_.keys(options.presets):[];this.initializeCookies();this.setOptions(options);$("input.filter_option",this.renderTo).live("change",function(){return $(_this.livelist.listSelector).trigger(_this.livelist.eventName)});$(this.advancedOptionsToggleSelector).click(this.handleAdvancedOptionsClick)}Filters.prototype.initializeCookies=function(){if(jQuery.cookie&&this.useCookies&&this.cookieName){return this.cookieName="livelist_filter_presets"}};Filters.prototype.getPresets=function(){var cookie;if(jQuery.cookie&&this.useCookies){cookie=jQuery.cookie(this.cookieName)}if(this.useCookies&&cookie){return JSON.parse(cookie)}else{return this.presets}};Filters.prototype.setPresets=function(presets){var filters;filters={};if(jQuery.isEmptyObject(presets)){filters=this.selections();if(jQuery.cookie){this.setCookie(filters)}}else{filters=presets}return filters};Filters.prototype.setCookie=function(params_filters){if(!jQuery.isEmptyObject(params_filters)){return jQuery.cookie(this.cookieName,JSON.stringify(params_filters))}};Filters.prototype.template="{{#filters}}\n<div class='filter'>\n <h3>\n {{name}}\n </h3>\n <ul id='{{filter_slug}}_filter_options'>\n {{#options}}\n <label>\n <li>\n <input {{#selected}}checked='checked'{{/selected}}\n class='left filter_option'\n id='filter_{{slug}}'\n name='filters[]'\n type='checkbox'\n value='{{value}}' />\n <div class='left filter_name'>{{name}}</div>\n <div class='right filter_count'>{{count}}</div>\n <div class='clear'></div>\n </li>\n </label>\n {{/options}}\n </ul>\n</div>\n{{/filters}}";Filters.prototype.selections=function(){var filters,_this=this;filters={};_.each(this.filters,function(filter){return filters[filter]=_.pluck($("#"+filter+"_filter_options input.filter_option:checked"),"value")});return filters};Filters.prototype.noFiltersSelected=function(data){return _.all(data.filters,function(filter){return _.all(filter.options,function(option){return!option.selected})})};Filters.prototype.sortOptions=function(filters){return _.map(filters,function(filter){filter.options=_.sortBy(filter.options,function(option){return option.name});return filter})};Filters.prototype.sort=function(filters){return _.sortBy(filters,function(filter){return filter.name})};Filters.prototype.render=function(data){var filtersHTML;this.filters=_.pluck(data.filters,"filter_slug");this.sort(data.filters);this.sortOptions(data.filters);filtersHTML=Mustache.to_html(this.template,data);$(this.renderTo).html(filtersHTML);if(this.noFiltersSelected(data)&&data[this.livelist.resourceName].length>0){return $('input[type="checkbox"]',this.renderTo).attr("checked","checked")}};Filters.prototype.handleAdvancedOptionsClick=function(event){event.preventDefault();return $(this.renderTo).slideToggle()};return Filters}(Utilities);var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};window.Pagination=function(_super){__extends(Pagination,_super);function Pagination(options,livelist){this.handlePaginationLinkClick=__bind(this.handlePaginationLinkClick,this);this.livelist=livelist;this.pagination=null;this.maxPages=30;this.emptyListMessage="<p>No "+this.livelist.resourceName+" matched your filter criteria</p>";this.setOptions(options);$(""+this.renderTo+" a").live("click",function(event){return event.preventDefault()});$(""+this.renderTo+" li:not(.disabled) a").live("click",this.handlePaginationLinkClick)}Pagination.prototype.template="{{#isEmpty}}\n {{{emptyListMessage}}}\n{{/isEmpty}}\n{{^isEmpty}}\n<div class=\"pagination\">\n <ul>\n <li class=\"{{^previousPage}}disabled{{/previousPage}}\">\n <a href='{{urlPrefix}}?page={{previousPage}}' data-page='{{previousPage}}'>← Previous</a>\n </li>\n\n {{#pages}}\n <li class=\"{{#currentPage}}active disabled{{/currentPage}}\">\n <a href='{{urlPrefix}}?page={{page}}' data-page='{{page}}'>{{page}}</a>\n </li>\n {{/pages}}\n\n <li class=\"{{^nextPage}}disabled{{/nextPage}}\">\n <a href='{{urlPrefix}}?page={{nextPage}}' data-page='{{nextPage}}'>Next →</a>\n </li>\n </ul>\n</div>\n{{/isEmpty}}";Pagination.prototype.pagesJSON=function(currentPage,totalPages){var firstPage,groupSize,lastPage,previousPage,_i,_results;groupSize=Math.floor(this.maxPages/2);firstPage=currentPage<=groupSize?1:currentPage-groupSize;previousPage=firstPage+groupSize*2-1;lastPage=previousPage>=totalPages?totalPages:previousPage;return _.map(function(){_results=[];for(var _i=firstPage;firstPage<=lastPage?_i<=lastPage:_i>=lastPage;firstPage<=lastPage?_i++:_i--){_results.push(_i)}return _results}.apply(this),function(page){return{page:page,currentPage:currentPage===page}})};Pagination.prototype.paginationJSON=function(pagination){return{isEmpty:pagination.total_pages===0,emptyListMessage:this.emptyListMessage,currentPage:pagination.current_page,nextPage:pagination.next_page,previousPage:pagination.previous_page,urlPrefix:this.livelist.urlPrefix,pages:this.pagesJSON(pagination.current_page,pagination.total_pages)}};Pagination.prototype.render=function(data){var paginationHTML;this.pagination=this.paginationJSON(data.pagination);paginationHTML=Mustache.to_html(this.template,this.pagination);return $(this.renderTo).html(paginationHTML)};Pagination.prototype.handlePaginationLinkClick=function(event){event.preventDefault();return $(this.livelist.listSelector).trigger(this.livelist.eventName,{page:$(event.target).data("page")})};return Pagination}(Utilities);var __bind=function(fn,me){return function(){return fn.apply(me,arguments)}},__hasProp={}.hasOwnProperty,__extends=function(child,parent){for(var key in parent){if(__hasProp.call(parent,key))child[key]=parent[key]}function ctor(){this.constructor=child}ctor.prototype=parent.prototype;child.prototype=new ctor;child.__super__=parent.prototype;return child};window.Search=function(_super){__extends(Search,_super);function Search(options,livelist){this.handleSearchFormSubmit=__bind(this.handleSearchFormSubmit,this);var _this=this;this.livelist=livelist;this.setOptions(options);$(this.formSelector).submit(function(event){return _this.handleSearchFormSubmit(event)})}Search.prototype.searchTerm=function(){var q;q=$(this.searchTextInputSelector).val();if(!q||q===""){return null}else{return q}};Search.prototype.handleSearchFormSubmit=function(event){event.preventDefault();return $(this.livelist.listSelector).trigger(this.livelist.eventName)};return Search}(Utilities);
\ No newline at end of file