jquery.page-it
Advanced tools
Comparing version 0.4.4 to 0.4.5
@@ -26,8 +26,29 @@ (function($, window, document, undefined) { | ||
var metaSchema = { | ||
/** | ||
* @var {int} size : Items per page. | ||
*/ | ||
size: null, | ||
/** | ||
* @var {int} first : Whats the first page of the collection. | ||
*/ | ||
first: 1, | ||
/** | ||
* @var {int} prev : Whats the previous page behind current. | ||
*/ | ||
prev: null, | ||
/** | ||
* @var {int} current : Current page number. | ||
*/ | ||
current: null, | ||
/** | ||
* @var {int} next : Whats the next page from current. | ||
*/ | ||
next: null, | ||
/** | ||
* @var {int} last : Whats the last page of the collection. | ||
*/ | ||
last: null, | ||
/** | ||
* @var {int} total : The total quantity of pages. | ||
*/ | ||
total: null | ||
@@ -38,11 +59,11 @@ }; | ||
/** | ||
* @var {bool} autoStart If should auto start loading the current page or not. | ||
* @var {bool} autoStart : If should auto start loading the current page or not. | ||
*/ | ||
autoStart: false, | ||
/** | ||
* @var {bool} cache : if should store loaded pages (and load'em from) in a local storage or not | ||
* @var {bool} cache : If should store loaded pages (and load'em from) in a local storage or not | ||
*/ | ||
cache: true, | ||
/** | ||
* @var {object} ajax jQuery.AJAX configuration options. | ||
* @var {object} ajax : jQuery.AJAX configuration options. | ||
*/ | ||
@@ -53,5 +74,6 @@ ajax: { | ||
global: true, | ||
method: 'get', | ||
}, | ||
/** | ||
* @var {HTMLElement} target : if you define this, you will have auto page content updates | ||
* @var {HTMLElement} target : If you define this, you will have auto page content updates | ||
*/ | ||
@@ -64,3 +86,3 @@ target: null, | ||
/** | ||
* @var {object} meta | ||
* @var {object} meta : The meta information used for controlling the things. | ||
*/ | ||
@@ -168,2 +190,3 @@ meta: metaSchema | ||
url: this.settings.ajax.url, | ||
method: this.settings.ajax.method, // http method | ||
data: Object.assign({ | ||
@@ -173,3 +196,2 @@ pageIt: true | ||
dataType: 'html', // expecting from the server | ||
method: 'GET', // get the page | ||
success: function(data, status, response) { | ||
@@ -176,0 +198,0 @@ |
var $jscomp={scope:{},owns:function(b,c){return Object.prototype.hasOwnProperty.call(b,c)}};$jscomp.defineProperty="function"==typeof Object.defineProperties?Object.defineProperty:function(b,c,e){if(e.get||e.set)throw new TypeError("ES3 does not support getters and setters.");b!=Array.prototype&&b!=Object.prototype&&(b[c]=e.value)};$jscomp.getGlobal=function(b){return"undefined"!=typeof window&&window===b?b:"undefined"!=typeof global&&null!=global?global:b};$jscomp.global=$jscomp.getGlobal(this); | ||
$jscomp.polyfill=function(b,c,e,g){if(c){e=$jscomp.global;b=b.split(".");for(g=0;g<b.length-1;g++){var d=b[g];d in e||(e[d]={});e=e[d]}b=b[b.length-1];g=e[b];c=c(g);c!=g&&null!=c&&$jscomp.defineProperty(e,b,{configurable:!0,writable:!0,value:c})}};$jscomp.polyfill("Object.assign",function(b){return b?b:function(b,e){for(var c=1;c<arguments.length;c++){var d=arguments[c];if(d)for(var h in d)$jscomp.owns(d,h)&&(b[h]=d[h])}return b}},"es6-impl","es3"); | ||
(function(b,c,e,g){var d={log:function(){console.log("pageIt: "+arguments[0],Array.prototype.slice.call(arguments,1))},info:function(){console.info("pageIt: "+arguments[0],Array.prototype.slice.call(arguments,1))},warn:function(){console.warn("pageIt: "+arguments[0],Array.prototype.slice.call(arguments,1))},error:function(){console.error("pageIt: "+arguments[0],Array.prototype.slice.call(arguments,1))}};if(!b)return d.error("N\u00e3o foi poss\u00edvel reconhecer o jQuery, inicializa\u00e7\u00e3o cancelada!"), | ||
!1;var h={autoStart:!1,cache:!0,ajax:{url:"",cache:!1,global:!0},target:null,fillMode:"replace",meta:{size:null,first:1,prev:null,current:null,next:null,last:null,total:null}};c.pageIt=function(a){this.settings=b.extend(!0,{},h,a);this.events={ready:[],"page.load.empty":[],"page.load.loaded":[],"page.load.autoupdated":[],"page.load.skipped":[],"page.load.first":[],"page.load.last":[],"page.load.error":[],"page.load.before":[],"page.load.after":[],"page.load.cache":[],"page.filled":[],"page.first":[], | ||
"page.prev":[],"page.next":[],"page.last":[]};this.pages=[];this.requesting=!1;this.meta=this.settings.meta;this.meta.current&&this.setCurrent(this.meta.current);this.requestData={};return this.init()};Object.assign(c.pageIt.prototype,{init:function(){this.trigger("ready");this.settings.autoStart&&this.to(this.meta.current)},to:function(a){if(!0===this.requesting)return d.warn("Uma requisi\u00e7\u00e3o de p\u00e1gina j\u00e1 est\u00e1 em andamento, esta requisi\u00e7\u00e3o ser\u00e1 ignorada."), | ||
!1;var h={autoStart:!1,cache:!0,ajax:{url:"",cache:!1,global:!0,method:"get"},target:null,fillMode:"replace",meta:{size:null,first:1,prev:null,current:null,next:null,last:null,total:null}};c.pageIt=function(a){this.settings=b.extend(!0,{},h,a);this.events={ready:[],"page.load.empty":[],"page.load.loaded":[],"page.load.autoupdated":[],"page.load.skipped":[],"page.load.first":[],"page.load.last":[],"page.load.error":[],"page.load.before":[],"page.load.after":[],"page.load.cache":[],"page.filled":[], | ||
"page.first":[],"page.prev":[],"page.next":[],"page.last":[]};this.pages=[];this.requesting=!1;this.meta=this.settings.meta;this.meta.current&&this.setCurrent(this.meta.current);this.requestData={};return this.init()};Object.assign(c.pageIt.prototype,{init:function(){this.trigger("ready");this.settings.autoStart&&this.to(this.meta.current)},to:function(a){if(!0===this.requesting)return d.warn("Uma requisi\u00e7\u00e3o de p\u00e1gina j\u00e1 est\u00e1 em andamento, esta requisi\u00e7\u00e3o ser\u00e1 ignorada."), | ||
!1;var c=this.meta.last||this.meta.total;if(!a||c&&a>c)return this.trigger("page.load.skipped",{}),this.trigger("page.load.last",{}),!1;if("string"===typeof a&&"next"===a||"prev"===a)return this[a]();if(this.settings.cache&&this.pages[a])this.pages[a]?(this.fillContainer(this.pages[a]),this.trigger("page.load.loaded",this.pages[a]),this.trigger("page.load.cache",this.pages[a])):this.trigger("page.load.empty",this.pages[a]);else{this.requestData={page:a};this.trigger("page.load.before",this.requestData); | ||
var f=this;this.requesting=!0;b.ajax({cache:this.settings.ajax.cache,global:this.settings.ajax.global,url:this.settings.ajax.url,data:Object.assign({pageIt:!0},this.requestData),dataType:"html",method:"GET",success:function(b,c,d){c={current:d.getResponseHeader("X-Page-Current"),size:d.getResponseHeader("X-Page-Size"),total:d.getResponseHeader("X-Page-Total"),first:d.getResponseHeader("X-Page-First"),prev:d.getResponseHeader("X-Page-Prev"),next:d.getResponseHeader("X-Page-Next"),last:d.getResponseHeader("X-Page-Last")}; | ||
f.setMeta(c);f.pages[a]=b;f.setCurrent(a);b?(f.trigger("page.load.loaded",b),f.fillContainer(b)):f.trigger("page.load.empty",b)},error:function(a){d.error("Erro ao carregar p\u00e1gina.");console.log(a);f.trigger("page.load.error",a)},complete:function(a){f.requesting=!1;f.trigger("page.load.after",a);console.groupEnd()}})}return this},fillContainer:function(a){if(this.settings.target){var c=b(this.settings.target);switch(this.settings.fillMode){case "append":c=c.append(a);break;default:case "replace":c= | ||
c.html(a)}c?this.trigger("page.load.autoupdated",a):this.trigger("page.load.error",a)}else d.info("No replacement target set, no DOM manipulation will be made.")},first:function(){this.trigger("page.first",this.meta.first);return this.to(this.meta.first)},prev:function(){this.trigger("page.prev",this.meta.next);return this.to(this.meta.prev)},next:function(){this.trigger("page.next",this.meta.next);return this.to(this.meta.next)},last:function(){this.trigger("page.last",this.meta.last);return this.to(this.meta.last)}, | ||
on:function(a,b){if(a.match(" "))eventname.split(" ").forEach(function(a){this.on(a,b)});else{if(!this.events[a])throw d.warn("Evento indispon\u00edvel."),Error("Can't attach unrecognized event handler.");this.events[a].push(b)}return this},off:function(a,b){if(a.match(" "))eventname.split(" ").forEach(function(a){this.off(a,b)});else{if(!this.events[a])throw d.warn("Evento indispon\u00edvel."),Error("Can't remove unrecognized event handler.");this.events[a]=[]}return this},trigger:function(a){if(this.events[a]&& | ||
this.events[a].length){var b=this,c=arguments;this.events[a].map(function(a){a.apply(b,Array.prototype.slice.call(c,1))})}return this},setMeta:function(a){Object.assign(this.meta,a)},setRequestData:function(a){Object.assign(this.requestData,a)},setCurrent:function(a){this.meta.current=a;this.meta.prev=a-1;this.meta.next=a+1}});return c.pageIt})(window.jQuery||!1,window,document); | ||
var f=this;this.requesting=!0;b.ajax({cache:this.settings.ajax.cache,global:this.settings.ajax.global,url:this.settings.ajax.url,method:this.settings.ajax.method,data:Object.assign({pageIt:!0},this.requestData),dataType:"html",success:function(b,c,d){c={current:d.getResponseHeader("X-Page-Current"),size:d.getResponseHeader("X-Page-Size"),total:d.getResponseHeader("X-Page-Total"),first:d.getResponseHeader("X-Page-First"),prev:d.getResponseHeader("X-Page-Prev"),next:d.getResponseHeader("X-Page-Next"), | ||
last:d.getResponseHeader("X-Page-Last")};f.setMeta(c);f.pages[a]=b;f.setCurrent(a);b?(f.trigger("page.load.loaded",b),f.fillContainer(b)):f.trigger("page.load.empty",b)},error:function(a){d.error("Erro ao carregar p\u00e1gina.");console.log(a);f.trigger("page.load.error",a)},complete:function(a){f.requesting=!1;f.trigger("page.load.after",a);console.groupEnd()}})}return this},fillContainer:function(a){if(this.settings.target){var c=b(this.settings.target);switch(this.settings.fillMode){case "append":c= | ||
c.append(a);break;default:case "replace":c=c.html(a)}c?this.trigger("page.load.autoupdated",a):this.trigger("page.load.error",a)}else d.info("No replacement target set, no DOM manipulation will be made.")},first:function(){this.trigger("page.first",this.meta.first);return this.to(this.meta.first)},prev:function(){this.trigger("page.prev",this.meta.next);return this.to(this.meta.prev)},next:function(){this.trigger("page.next",this.meta.next);return this.to(this.meta.next)},last:function(){this.trigger("page.last", | ||
this.meta.last);return this.to(this.meta.last)},on:function(a,b){if(a.match(" "))eventname.split(" ").forEach(function(a){this.on(a,b)});else{if(!this.events[a])throw d.warn("Evento indispon\u00edvel."),Error("Can't attach unrecognized event handler.");this.events[a].push(b)}return this},off:function(a,b){if(a.match(" "))eventname.split(" ").forEach(function(a){this.off(a,b)});else{if(!this.events[a])throw d.warn("Evento indispon\u00edvel."),Error("Can't remove unrecognized event handler.");this.events[a]= | ||
[]}return this},trigger:function(a){if(this.events[a]&&this.events[a].length){var b=this,c=arguments;this.events[a].map(function(a){a.apply(b,Array.prototype.slice.call(c,1))})}return this},setMeta:function(a){Object.assign(this.meta,a)},setRequestData:function(a){Object.assign(this.requestData,a)},setCurrent:function(a){this.meta.current=a;this.meta.prev=a-1;this.meta.next=a+1}});return c.pageIt})(window.jQuery||!1,window,document); |
{ | ||
"name": "jquery.page-it", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"description": "Lib for building paginations.", | ||
@@ -5,0 +5,0 @@ "main": "jquery.page-it.js", |
@@ -24,6 +24,6 @@ # Page it! | ||
| `on` | `{string} eventName, {callable} callback` | Registers an event listener. | | ||
| `trigger` | `{string} eventName, {object} data` | Triggers an event. | | ||
| `setMeta` | `{object} meta` | Sets the `meta` property, this property is used to control pagination numbers. | | ||
| `setCurrent` | `{object} requestData` | Accepts a callback to update the request data. | | ||
| `setRequestData` | `{int} current` | Sets the current page and updates dependent meta. | | ||
| `trigger` | `{string} eventName, {array} params` | Triggers an event. | | ||
| `setMeta` | `{object} meta` (see meta schema) | Sets the `meta` property, this property is used to control pagination numbers. | | ||
| `setCurrent` | `{int} current` | Sets the current page and updates dependent meta. | | ||
| `setRequestData` | `{object} requestData` | Accepts a callback to update the request data. | | ||
@@ -37,11 +37,11 @@ ## Options | ||
/** | ||
* @var {bool} autoStart If should auto start loading the current page or not. | ||
* @var {bool} autoStart : If should auto start loading the current page or not. | ||
*/ | ||
autoStart: false, | ||
/** | ||
* @var {bool} cache : if should store loaded pages (and load'em from) in a local storage or not | ||
* @var {bool} cache : If should store loaded pages (and load'em from) in a local storage or not | ||
*/ | ||
cache: true, | ||
/** | ||
* @var {object} ajax jQuery.AJAX configuration options. | ||
* @var {object} ajax : jQuery.AJAX configuration options. | ||
*/ | ||
@@ -52,12 +52,52 @@ ajax: { | ||
global: true, | ||
method: 'get', | ||
}, | ||
/** | ||
* @var {HTMLElement} replace If you define this, you will have auto page content updates in the desired element. | ||
* @var {HTMLElement} target : If you define this, you will have auto page content updates | ||
*/ | ||
replace: null, | ||
target: null, | ||
/** | ||
* @var {object} meta The initial meta information for controlling the pages. | ||
* @var {string} fillMode : The fill mode to use when pagrIt will do something with the target. | ||
*/ | ||
fillMode: 'replace', | ||
/** | ||
* @var {object} meta : The meta information used for controlling the things. | ||
*/ | ||
meta: metaSchema | ||
} | ||
``` | ||
## Meta Schema | ||
```javascript | ||
{ | ||
/** | ||
* @var {int} size : Items per page. | ||
*/ | ||
size: null, | ||
/** | ||
* @var {int} first : Whats the first page of the collection. | ||
*/ | ||
first: 1, | ||
/** | ||
* @var {int} prev : Whats the previous page behind current. | ||
*/ | ||
prev: null, | ||
/** | ||
* @var {int} current : Current page number. | ||
*/ | ||
current: null, | ||
/** | ||
* @var {int} next : Whats the next page from current. | ||
*/ | ||
next: null, | ||
/** | ||
* @var {int} last : Whats the last page of the collection. | ||
*/ | ||
last: null, | ||
/** | ||
* @var {int} total : The total quantity of pages. | ||
*/ | ||
total: null | ||
} | ||
``` |
23370
377
101