jquery.page-it
Advanced tools
Comparing version 0.4.3 to 0.4.4
@@ -1,2 +0,2 @@ | ||
(function ($, window, document, undefined) { | ||
(function($, window, document, undefined) { | ||
@@ -6,12 +6,12 @@ var pluginName = 'pageIt'; | ||
var logger = { | ||
log: function () { | ||
log: function() { | ||
console.log(pluginName + ': ' + arguments[0], Array.prototype.slice.call(arguments, 1)); | ||
}, | ||
info: function () { | ||
info: function() { | ||
console.info(pluginName + ': ' + arguments[0], Array.prototype.slice.call(arguments, 1)); | ||
}, | ||
warn: function () { | ||
warn: function() { | ||
console.warn(pluginName + ': ' + arguments[0], Array.prototype.slice.call(arguments, 1)); | ||
}, | ||
error: function () { | ||
error: function() { | ||
console.error(pluginName + ': ' + arguments[0], Array.prototype.slice.call(arguments, 1)); | ||
@@ -38,3 +38,3 @@ }, | ||
/** | ||
* @var {bool} If should auto start loading the current page or not. | ||
* @var {bool} autoStart If should auto start loading the current page or not. | ||
*/ | ||
@@ -46,5 +46,4 @@ autoStart: false, | ||
cache: true, | ||
dataType: 'json', | ||
/** | ||
* @var {object} jQuery.AJAX configuration options. | ||
* @var {object} ajax jQuery.AJAX configuration options. | ||
*/ | ||
@@ -65,3 +64,3 @@ ajax: { | ||
/** | ||
* @var {object} | ||
* @var {object} meta | ||
*/ | ||
@@ -75,2 +74,3 @@ meta: metaSchema | ||
this.settings = $.extend(true, {}, defaults, options); | ||
this.events = { | ||
@@ -94,2 +94,3 @@ 'ready': [], | ||
}; | ||
this.pages = []; | ||
@@ -116,3 +117,3 @@ | ||
**/ | ||
init: function () { | ||
init: function() { | ||
@@ -128,3 +129,3 @@ this.trigger('ready'); | ||
**/ | ||
to: function (page) { | ||
to: function(page) { | ||
@@ -161,3 +162,3 @@ if (this.requesting === true) { | ||
// user can moddify the requestData here, before the AJAX call. | ||
this.trigger('page.load.before', this); | ||
this.trigger('page.load.before', this.requestData); | ||
@@ -172,6 +173,8 @@ var that = this; | ||
url: this.settings.ajax.url, | ||
data: this.requestData, | ||
data: Object.assign({ | ||
pageIt: true | ||
}, this.requestData), | ||
dataType: 'html', // expecting from the server | ||
method: 'GET', // get the page | ||
success: function (data, status, response) { | ||
success: function(data, status, response) { | ||
@@ -210,3 +213,3 @@ // retrieves the meta information from the HTTP headers | ||
}, | ||
error: function (response) { | ||
error: function(response) { | ||
logger.error('Erro ao carregar página.'); | ||
@@ -217,3 +220,3 @@ console.log(response); | ||
}, | ||
complete: function (response) { | ||
complete: function(response) { | ||
@@ -290,3 +293,3 @@ that.requesting = false; | ||
*/ | ||
first: function () { | ||
first: function() { | ||
this.trigger('page.first', this.meta.first); | ||
@@ -299,3 +302,3 @@ return this.to(this.meta.first); | ||
**/ | ||
prev: function () { | ||
prev: function() { | ||
this.trigger('page.prev', this.meta.next); | ||
@@ -308,3 +311,3 @@ return this.to(this.meta.prev); | ||
**/ | ||
next: function () { | ||
next: function() { | ||
this.trigger('page.next', this.meta.next); | ||
@@ -317,3 +320,3 @@ return this.to(this.meta.next); | ||
**/ | ||
last: function () { | ||
last: function() { | ||
this.trigger('page.last', this.meta.last); | ||
@@ -331,6 +334,6 @@ return this.to(this.meta.last); | ||
**/ | ||
on: function (eventName, fn) { | ||
on: function(eventName, fn) { | ||
if (eventName.match(' ')) { | ||
eventname.split(' ').forEach(function (eventName) { | ||
eventname.split(' ').forEach(function(eventName) { | ||
this.on(eventName, fn); | ||
@@ -359,6 +362,6 @@ }); | ||
**/ | ||
off: function (eventName, fn) { | ||
off: function(eventName, fn) { | ||
if (eventName.match(' ')) { | ||
eventname.split(' ').forEach(function (eventName) { | ||
eventname.split(' ').forEach(function(eventName) { | ||
this.off(eventName, fn); | ||
@@ -387,3 +390,3 @@ }); | ||
**/ | ||
trigger: function (eventName) { | ||
trigger: function(eventName) { | ||
@@ -395,3 +398,3 @@ if (this.events[eventName] && this.events[eventName].length) { | ||
this.events[eventName].map(function (fnName) { | ||
this.events[eventName].map(function(fnName) { | ||
@@ -410,3 +413,3 @@ fnName.apply(that, Array.prototype.slice.call(args, 1)); // Array.prototype.slice will convert the arguments object | ||
*/ | ||
setMeta: function (meta) { | ||
setMeta: function(meta) { | ||
// meta is not multilevel | ||
@@ -423,3 +426,3 @@ Object.assign(this.meta, meta); | ||
*/ | ||
setRequestData: function (requestData) { | ||
setRequestData: function(requestData) { | ||
// by default, request data is not multilevel | ||
@@ -434,3 +437,3 @@ Object.assign(this.requestData, requestData); | ||
*/ | ||
setCurrent: function (current) { | ||
setCurrent: function(current) { | ||
this.meta.current = current; | ||
@@ -437,0 +440,0 @@ this.meta.prev = current - 1; |
@@ -1,1 +0,11 @@ | ||
(function(e,t,a,r){var i="pageIt",s={log:function(){console.log(i+": "+arguments[0],Array.prototype.slice.call(arguments,1))},info:function(){console.info(i+": "+arguments[0],Array.prototype.slice.call(arguments,1))},warn:function(){console.warn(i+": "+arguments[0],Array.prototype.slice.call(arguments,1))},error:function(){console.error(i+": "+arguments[0],Array.prototype.slice.call(arguments,1))}};if(!e)return s.error("Não foi possível reconhecer o jQuery, inicialização cancelada!"),!1;var n={size:null,first:1,prev:null,current:null,next:null,last:null,total:null},o={autoStart:!1,cache:!0,dataType:"json",ajax:{url:"",cache:!1,global:!0},target:null,fillMode:"replace",meta:n};return t[i]=function(t){return this.settings=e.extend(!0,{},o,t),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={},this.init()},Object.assign(t[i].prototype,{init:function(){this.trigger("ready"),this.settings.autoStart&&this.to(this.meta.current)},to:function(t){if(this.requesting===!0)return s.warn("Uma requisição de página já está em andamento, esta requisição será ignorada."),!1;var a=this.meta.last||this.meta.total;if(!t||a&&t>a)return this.trigger("page.load.skipped",{}),this.trigger("page.load.last",{}),!1;if("string"==typeof t&&"next"===t||"prev"===t)return this[t]();if(this.settings.cache&&this.pages[t])this.pages[t]?(this.fillContainer(this.pages[t]),this.trigger("page.load.loaded",this.pages[t]),this.trigger("page.load.cache",this.pages[t])):this.trigger("page.load.empty",this.pages[t]);else{this.requestData={page:t},this.trigger("page.load.before",this);var r=this;this.requesting=!0,e.ajax({cache:this.settings.ajax.cache,global:this.settings.ajax.global,url:this.settings.ajax.url,data:this.requestData,dataType:"html",method:"GET",success:function(e,a,i){var s={current:i.getResponseHeader("X-Page-Current"),size:i.getResponseHeader("X-Page-Size"),total:i.getResponseHeader("X-Page-Total"),first:i.getResponseHeader("X-Page-First"),prev:i.getResponseHeader("X-Page-Prev"),next:i.getResponseHeader("X-Page-Next"),last:i.getResponseHeader("X-Page-Last")};r.setMeta(s),r.pages[t]=e,r.setCurrent(t),e?(r.trigger("page.load.loaded",e),r.fillContainer(e)):r.trigger("page.load.empty",e)},error:function(e){s.error("Erro ao carregar página."),console.log(e),r.trigger("page.load.error",e)},complete:function(e){r.requesting=!1,r.trigger("page.load.after",e),console.groupEnd()}})}return this},fillContainer:function(t){if(this.settings.target){var a=e(this.settings.target),r=!0;switch(this.settings.fillMode){case"append":r=a.append(t);break;default:case"replace":r=a.html(t)}r?this.trigger("page.load.autoupdated",t):this.trigger("page.load.error",t)}else s.info("No replacement target set, no DOM manipulation will be made.")},first:function(){return this.trigger("page.first",this.meta.first),this.to(this.meta.first)},prev:function(){return this.trigger("page.prev",this.meta.next),this.to(this.meta.prev)},next:function(){return this.trigger("page.next",this.meta.next),this.to(this.meta.next)},last:function(){return this.trigger("page.last",this.meta.last),this.to(this.meta.last)},on:function(e,t){if(e.match(" "))eventname.split(" ").forEach(function(e){this.on(e,t)});else{if(!this.events[e])throw s.warn("Evento indisponível."),new Error("Can't attach unrecognized event handler.");this.events[e].push(t)}return this},off:function(e,t){if(e.match(" "))eventname.split(" ").forEach(function(e){this.off(e,t)});else{if(!this.events[e])throw s.warn("Evento indisponível."),new Error("Can't remove unrecognized event handler.");this.events[e]=[]}return this},trigger:function(e){if(this.events[e]&&this.events[e].length){var t=this,a=arguments;this.events[e].map(function(e){e.apply(t,Array.prototype.slice.call(a,1))})}return this},setMeta:function(e){Object.assign(this.meta,e)},setRequestData:function(e){Object.assign(this.requestData,e)},setCurrent:function(e){this.meta.current=e,this.meta.prev=e-1,this.meta.next=e+1}}),t[i]})(window.jQuery||!1,window,document); | ||
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 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); |
{ | ||
"name": "jquery.page-it", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"description": "Lib for building paginations.", | ||
@@ -5,0 +5,0 @@ "main": "jquery.page-it.js", |
@@ -0,0 +0,0 @@ # Page it! |
21853
356