jquery.page-it
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -1,2 +0,2 @@ | ||
(function ($, window, document, undefined) { | ||
(function($, window, document, undefined) { | ||
@@ -6,13 +6,13 @@ var pluginName = 'pageIt'; | ||
var logger = { | ||
log: function () { | ||
console.log(pluginName + ": " + arguments[0], Array.prototype.slice.call(arguments, 1)); | ||
log: function() { | ||
console.log(pluginName + ': ' + arguments[0], Array.prototype.slice.call(arguments, 1)); | ||
}, | ||
info: function () { | ||
console.info(pluginName + ": " + arguments[0], Array.prototype.slice.call(arguments, 1)); | ||
info: function() { | ||
console.info(pluginName + ': ' + arguments[0], Array.prototype.slice.call(arguments, 1)); | ||
}, | ||
warn: function () { | ||
console.warn(pluginName + ": " + arguments[0], Array.prototype.slice.call(arguments, 1)); | ||
warn: function() { | ||
console.warn(pluginName + ': ' + arguments[0], Array.prototype.slice.call(arguments, 1)); | ||
}, | ||
error: function () { | ||
console.error(pluginName + ": " + arguments[0], Array.prototype.slice.call(arguments, 1)); | ||
error: function() { | ||
console.error(pluginName + ': ' + arguments[0], Array.prototype.slice.call(arguments, 1)); | ||
}, | ||
@@ -22,38 +22,7 @@ }; | ||
if (!$) { | ||
logger.error(pluginName + ': Não foi possível reconhecer o jQuery, inicialização cancelada!'); | ||
logger.error('Não foi possível reconhecer o jQuery, inicialização cancelada!'); | ||
return false; | ||
} | ||
/* | ||
* Polyfill | ||
*/ | ||
// Production steps of ECMA-262, Edition 5, 15.4.4.17 | ||
// Reference: http://es5.github.io/#x15.4.4.17 | ||
if (!Array.prototype.some) { | ||
Array.prototype.some = function (fun/*, thisArg*/) { | ||
'use strict'; | ||
if (this == null) { | ||
throw new TypeError('Array.prototype.some called on null or undefined'); | ||
} | ||
if (typeof fun !== 'function') { | ||
throw new TypeError(); | ||
} | ||
var t = Object(this); | ||
var len = t.length >>> 0; | ||
var thisArg = arguments.length >= 2 ? arguments[1] : void 0; | ||
for (var i = 0; i < len; i++) { | ||
if (i in t && fun.call(thisArg, t[i], i, t)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
} | ||
var metaSchema = { | ||
@@ -140,3 +109,3 @@ size: null, | ||
**/ | ||
init: function () { | ||
init: function() { | ||
@@ -152,3 +121,3 @@ this.trigger('ready'); | ||
**/ | ||
to: function (pageIndex) { | ||
to: function(pageIndex) { | ||
@@ -181,2 +150,3 @@ if (this.requesting === true) { | ||
// user can moddify the requestData here, before the AJAX call. | ||
this.trigger('page.load.before', this.requestData); | ||
@@ -195,3 +165,3 @@ | ||
dataType: this.settings.dataType, | ||
success: function (data, status, response) { | ||
success: function(data, status, response) { | ||
@@ -219,14 +189,4 @@ /* | ||
// se tem um container de conteúdo definido e a resposta é em HTML, insere o conteúdo nele | ||
if (!!that.settings.contentView) { | ||
that.fillContainer(data.content); | ||
if ($(that.settings.contentView).html(data.content)) { | ||
// plugin .trigger method | ||
that.trigger('page.load.autoupdated', data); | ||
} | ||
} else { | ||
logger.warn('No container set, no data will be auto inserted.'); | ||
} | ||
} else { | ||
@@ -239,3 +199,3 @@ | ||
}, | ||
error: function (response) { | ||
error: function(response) { | ||
logger.error('Erro ao carregar página.'); | ||
@@ -246,3 +206,3 @@ console.log(response); | ||
}, | ||
complete: function (response) { | ||
complete: function(response) { | ||
@@ -263,7 +223,3 @@ that.requesting = false; | ||
// se tem um container de conteúdo definido, insere o conteúdo nele | ||
if (!!this.settings.contentView) { | ||
this.settings.contentView.innerHTML = this.pages[pageIndex].content; | ||
this.trigger('page.filled', this.pages[pageIndex]); | ||
} | ||
this.fillContainer(this.pages[pageIndex].content); | ||
@@ -285,5 +241,23 @@ this.trigger('page.load.loaded', this.pages[pageIndex]); | ||
/** | ||
* Se tem um container de conteúdo definido e a resposta é em HTML, insere o conteúdo nele | ||
*/ | ||
fillContainer: function fillContainer(data) { | ||
if (!!this.settings.contentView) { | ||
if ($(this.settings.contentView).html(data.content)) { | ||
// plugin .trigger method | ||
this.trigger('page.load.autoupdated', data); | ||
} | ||
} else { | ||
logger.warn('No container set, no data will be auto inserted.'); | ||
} | ||
}, | ||
/** | ||
* Calls .to() with page number meta.first as parameter. | ||
**/ | ||
first: function () { | ||
first: function() { | ||
this.trigger('page.first', this.meta.first); | ||
@@ -296,3 +270,3 @@ return this.to(this.meta.first); | ||
**/ | ||
prev: function () { | ||
prev: function() { | ||
this.trigger('page.prev', this.meta.next); | ||
@@ -305,3 +279,3 @@ return this.to(this.meta.prev); | ||
**/ | ||
next: function () { | ||
next: function() { | ||
this.trigger('page.next', this.meta.next); | ||
@@ -314,3 +288,3 @@ return this.to(this.meta.next); | ||
**/ | ||
last: function () { | ||
last: function() { | ||
this.trigger('page.last', this.meta.last); | ||
@@ -326,25 +300,16 @@ 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); | ||
}); | ||
} else { | ||
//if (fn.name) { | ||
if (!this.events[eventName]) { | ||
logger.warn('Evento indisponível.'); | ||
throw new Error('Can\'t attach unrecognized event handler.'); | ||
} | ||
var x = this.events[eventName].some(function (t) { | ||
return t === fn; | ||
}) || this.events[eventName].indexOf(fn); | ||
if (!this.events[eventName]) { | ||
logger.warn('Evento indisponível.'); | ||
throw new Error('Can\'t attach unrecognized event handler.'); | ||
} | ||
//if (x > -1) return this; | ||
this.events[eventName].push(fn); | ||
//} else { | ||
// throw new Error('Funções anônimas não são permitidas.'); | ||
//} | ||
this.events[eventName].push(fn); | ||
} | ||
@@ -361,3 +326,3 @@ | ||
**/ | ||
trigger: function (eventName) { | ||
trigger: function(eventName) { | ||
@@ -369,3 +334,3 @@ if (this.events[eventName] && this.events[eventName].length) { | ||
this.events[eventName].map(function (fnName) { | ||
this.events[eventName].map(function(fnName) { | ||
@@ -381,9 +346,4 @@ fnName.apply(that, Array.prototype.slice.call(args, 1)); // Array.prototype.slice will convert the arguments object | ||
setData: function (object) { | ||
$.extend(this.requestData, object); | ||
}, | ||
setMeta: function (meta) { | ||
setMeta: function(meta) { | ||
// meta is not multilevel | ||
$.extend(this.meta, meta); | ||
@@ -390,0 +350,0 @@ } |
@@ -1,1 +0,8 @@ | ||
!function(t,e,i,a){var n={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(!t)return n.error("pageIt: Não foi possível reconhecer o jQuery, inicialização cancelada!"),!1;Array.prototype.some||(Array.prototype.some=function(t){"use strict";if(null==this)throw new TypeError("Array.prototype.some called on null or undefined");if("function"!=typeof t)throw new TypeError;for(var e=Object(this),i=e.length>>>0,a=arguments.length>=2?arguments[1]:void 0,n=0;n<i;n++)if(n in e&&t.call(a,e[n],n,e))return!0;return!1});var s={size:null,first:1,prev:null,current:null,next:null,last:null,total:null},r={initPage:null,cache:!0,url:"",method:"get",dataType:"json",ajax:{cache:!1,global:!0},contentView:null,meta:s};e.pageIt=function(e){return this.settings=t.extend(!0,{},r,e),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.prev=this.settings.initPage-1,this.meta.current=this.settings.initPage,this.meta.next=this.settings.initPage+1,this.requestData={},this.init()},t.extend(e.pageIt.prototype,{init:function(){this.trigger("ready"),this.settings.initPage&&this.to(this.settings.initPage)},to:function(e){if(!0===this.requesting)return n.warn("Uma requisição de página já está em andamento, esta requisição será ignorada."),!1;if(!e||this.meta.last&&e>this.meta.last)return this.trigger("page.load.skipped",{}),this.trigger("page.load.last",{}),!1;if("string"==typeof e&&"next"===e||"prev"===e)return this[e]();if(this.settings.cache&&this.pages[e])this.pages[e].content?(this.settings.contentView&&(this.settings.contentView.innerHTML=this.pages[e].content,this.trigger("page.filled",this.pages[e])),this.trigger("page.load.loaded",this.pages[e]),this.trigger("page.load.cache",this.pages[e])):this.trigger("page.load.empty",this.pages[e]);else{this.requestData={},this.requestData.pageIndex=e,this.trigger("page.load.before",this.requestData);var i=this;this.requesting=!0,t.ajax({cache:this.settings.ajax.cache,global:this.settings.ajax.global,url:this.settings.url,method:this.settings.method,data:this.requestData,dataType:this.settings.dataType,success:function(a,s,r){i.pages[e]=a.content,i.meta.prev=e-1,i.meta.current=e,i.meta.next=e+1,a.meta&&i.setMeta(a.meta),a.content?(i.trigger("page.load.loaded",a),i.settings.contentView?t(i.settings.contentView).html(a.content)&&i.trigger("page.load.autoupdated",a):n.warn("No container set, no data will be auto inserted.")):i.trigger("page.load.empty",a)},error:function(t){n.error("Erro ao carregar página."),console.log(t),i.trigger("page.load.error",t)},complete:function(t){i.requesting=!1,i.trigger("page.load.after",t),console.groupEnd()}})}return this},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(t,e){if(t.match(" "))eventname.split(" ").forEach(function(t){this.on(t,e)});else{if(!this.events[t])throw n.warn("Evento indisponível."),new Error("Can't attach unrecognized event handler.");this.events[t].some(function(t){return t===e})||this.events[t].indexOf(e);this.events[t].push(e)}return this},trigger:function(t){if(this.events[t]&&this.events[t].length){var e=this,i=arguments;this.events[t].map(function(t){t.apply(e,Array.prototype.slice.call(i,1))})}return this},setData:function(e){t.extend(this.requestData,e)},setMeta:function(e){t.extend(this.meta,e)}}),e.pageIt}(window.jQuery||!1,window,document); | ||
(function(d,f,h,k){var e={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(!d)return e.error("N\u00e3o foi poss\u00edvel reconhecer o jQuery, inicializa\u00e7\u00e3o cancelada!"), | ||
!1;var g={initPage:null,cache:!0,url:"",method:"get",dataType:"json",ajax:{cache:!1,global:!0},contentView:null,meta:{size:null,first:1,prev:null,current:null,next:null,last:null,total:null}};f.pageIt=function(a){this.settings=d.extend(!0,{},g,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.prev=this.settings.initPage-1;this.meta.current=this.settings.initPage;this.meta.next=this.settings.initPage+1;this.requestData={};return this.init()};d.extend(f.pageIt.prototype,{init:function(){this.trigger("ready");this.settings.initPage&&this.to(this.settings.initPage)},to:function(a){if(!0===this.requesting)return e.warn("Uma requisi\u00e7\u00e3o de p\u00e1gina j\u00e1 est\u00e1 em andamento, esta requisi\u00e7\u00e3o ser\u00e1 ignorada."), | ||
!1;if(!a||this.meta.last&&a>this.meta.last)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].content?(this.fillContainer(this.pages[a].content),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={};this.requestData.pageIndex=a;this.trigger("page.load.before", | ||
this.requestData);var b=this;this.requesting=!0;d.ajax({cache:this.settings.ajax.cache,global:this.settings.ajax.global,url:this.settings.url,method:this.settings.method,data:this.requestData,dataType:this.settings.dataType,success:function(c,d,e){b.pages[a]=c.content;b.meta.prev=a-1;b.meta.current=a;b.meta.next=a+1;c.meta&&b.setMeta(c.meta);c.content?(b.trigger("page.load.loaded",c),b.fillContainer(c.content)):b.trigger("page.load.empty",c)},error:function(a){e.error("Erro ao carregar p\u00e1gina."); | ||
console.log(a);b.trigger("page.load.error",a)},complete:function(a){b.requesting=!1;b.trigger("page.load.after",a);console.groupEnd()}})}return this},fillContainer:function(a){this.settings.contentView?d(this.settings.contentView).html(a.content)&&this.trigger("page.load.autoupdated",a):e.warn("No container set, no data will be auto inserted.")},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 e.warn("Evento indispon\u00edvel."),Error("Can't attach unrecognized event handler.");this.events[a].push(b)}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){d.extend(this.meta,a)}});return f.pageIt})(window.jQuery||!1,window,document); |
{ | ||
"name": "jquery.page-it", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Lib for building paginations.", | ||
@@ -5,0 +5,0 @@ "main": "jquery.page-it.js", |
14680
279