New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jquery.page-it

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jquery.page-it - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

312

jquery.page-it.js

@@ -1,27 +0,94 @@

(function($, window, document, undefined) {
(function ($, window, document, undefined) {
var pluginName = 'pageIt';
var logger = {
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));
},
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));
},
};
if (!$) {
console.error(pluginName + ': Não foi possível reconhecer o jQuery, inicialização cancelada!');
logger.error(pluginName + ': 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 = {
size: null,
first: 1,
prev: null,
current: null,
next: null,
last: null,
total: null
};
var defaults = {
/**
* @var {int?} The page where the plugin should start.
*/
initPage: null,
/**
* @var {bool} cache : if should store loaded pages (and load'em from) in a local storage or not
*/
cache: true,
url: '',
method: 'get',
dataType: 'html',
initPage: 1,
cacheAjax: false,
cachePagination: true,
dataType: 'json',
/**
* @var {object} jQuery.AJAX configuration options.
*/
ajax: {
cache: false,
global: true,
},
/**
* @var {HTMLElement} contentView : if you define this, you will have auto page content updates
*/
contentView: null,
urlMeta: '',
pageMeta: {
first: 1,
prev: undefined,
current: undefined,
next: undefined,
last: undefined,
total: undefined
}
/**
* @var {object}
*/
meta: metaSchema
};

@@ -33,10 +100,29 @@

this.settings = $.extend(true, {}, defaults, options);
this.events = {};
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.pageMeta = this.settings.pageMeta;
this.pageMeta.prev = this.settings.initPage - 1;
this.pageMeta.current = this.settings.initPage;
this.pageMeta.next = this.settings.initPage + 1;
this.requesting = false;
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 = {};

@@ -53,8 +139,8 @@

**/
init: function() {
init: function () {
this.trigger('ready');
if (!!this.settings.initPage)
this.to(this.settings.initPage);
this.trigger(pluginName + '.ready');
},

@@ -65,7 +151,15 @@

**/
to: function(pageIndex) {
to: function (pageIndex) {
if (!pageIndex || pageIndex > this.pageMeta.last)
return this;
if (this.requesting === true) {
logger.warn('Uma requisição de página já está em andamento, esta requisição será ignorada.');
return false;
}
if (!pageIndex || (this.meta.last && pageIndex > this.meta.last)) {
this.trigger('page.load.skipped', {});
this.trigger('page.load.last', {});
return false;
}
// if index is a string like 'next' or 'prev', it will be translated by calling it's manager

@@ -76,3 +170,3 @@ if (typeof pageIndex === 'string' && pageIndex === 'next' || pageIndex === 'prev') {

if (!this.settings.cachePagination || !this.pages[pageIndex]) {
if (!this.settings.cache || !this.pages[pageIndex]) {

@@ -91,4 +185,7 @@ /*

this.requesting = true;
$.ajax({
cache: this.settings.cache,
cache: this.settings.ajax.cache,
global: this.settings.ajax.global,
url: this.settings.url,

@@ -98,24 +195,35 @@ method: this.settings.method,

dataType: this.settings.dataType,
success: function(data) {
success: function (data, status, response) {
that.pages[pageIndex] = data;
/*
data: {
meta: {...}
content: [HTML String]
}
*/
that.pageMeta.prev = pageIndex - 1;
that.pageMeta.current = pageIndex;
that.pageMeta.next = pageIndex + 1;
that.pages[pageIndex] = data.content;
that.trigger('page.content.loaded', data);
that.meta.prev = pageIndex - 1;
that.meta.current = pageIndex;
that.meta.next = pageIndex + 1;
if (!!data) {
if (data.meta) {
that.setMeta(data.meta);
}
if (!!data.content) {
that.trigger('page.load.loaded', data);
// se tem um container de conteúdo definido e a resposta é em HTML, insere o conteúdo nele
if (that.settings.dataType === 'html' && !!that.settings.contentView) {
if (!!that.settings.contentView) {
if ($(that.settings.contentView).html(data)) {
if ($(that.settings.contentView).html(data.content)) {
// plugin .trigger method
that.trigger('page.filled', data);
that.trigger('page.load.autoupdated', data);
}
} else {
console.warn('No container set, no data will be auto inserted.');
logger.warn('No container set, no data will be auto inserted.');
}

@@ -125,3 +233,3 @@

that.trigger('page.content.empty', data);
that.trigger('page.load.empty', data);

@@ -131,8 +239,12 @@ }

},
error: function(response) {
console.error('Erro ao carregar página.');
error: function (response) {
logger.error('Erro ao carregar página.');
console.log(response);
that.trigger('page.load.error', response);
},
complete: function(response) {
complete: function (response) {
that.requesting = false;
// plugin .trigger method

@@ -156,8 +268,8 @@ that.trigger('page.load.after', response);

this.trigger('page.content.loaded', this.pages[pageIndex]);
this.trigger('page.loaded.cache', this.pages[pageIndex]);
this.trigger('page.load.loaded', this.pages[pageIndex]);
this.trigger('page.load.cache', this.pages[pageIndex]);
} else {
this.trigger('page.content.empty', this.pages[pageIndex]);
this.trigger('page.load.empty', this.pages[pageIndex]);

@@ -172,31 +284,31 @@ }

/**
* Calls .to() with page number pageMeta.first as parameter.
* Calls .to() with page number meta.first as parameter.
**/
first: function() {
this.trigger('page.first', this.pageMeta.first);
return this.to(this.pageMeta.first);
first: function () {
this.trigger('page.first', this.meta.first);
return this.to(this.meta.first);
},
/**
* Calls .to() with page number pageMeta.current - 1 as parameter.
* Calls .to() with page number meta.current - 1 as parameter.
**/
prev: function() {
this.trigger('page.prev', this.pageMeta.next);
return this.to(this.pageMeta.prev);
prev: function () {
this.trigger('page.prev', this.meta.next);
return this.to(this.meta.prev);
},
/**
* Calls .to() with page number pageMeta.current + 1 as parameter.
* Calls .to() with page number meta.current + 1 as parameter.
**/
next: function() {
this.trigger('page.next', this.pageMeta.next);
return this.to(this.pageMeta.next);
next: function () {
this.trigger('page.next', this.meta.next);
return this.to(this.meta.next);
},
/**
* Calls .to() with page number pageMeta.last as parameter.
* Calls .to() with page number meta.last as parameter.
**/
last: function() {
this.trigger('page.last', this.pageMeta.last);
return this.to(this.pageMeta.last);
last: function () {
this.trigger('page.last', this.meta.last);
return this.to(this.meta.last);
},

@@ -210,8 +322,25 @@

**/
on: function(eventName, fn) {
on: function (eventName, fn) {
if (this.events[eventName]) {
this.events[eventName].push(fn);
if (eventName.match(' ')) {
eventname.split(' ').forEach(function (eventName) {
this.on(eventName, fn);
});
} else {
this.events[eventName] = [fn];
//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 (x > -1) return this;
this.events[eventName].push(fn);
//} else {
// throw new Error('Funções anônimas não são permitidas.');
//}
}

@@ -228,3 +357,3 @@

**/
trigger: function(eventName) {
trigger: function (eventName) {

@@ -236,3 +365,3 @@ if (this.events[eventName] && this.events[eventName].length) {

this.events[eventName].map(function(fnName) {
this.events[eventName].map(function (fnName) {

@@ -248,49 +377,10 @@ fnName.apply(that, Array.prototype.slice.call(args, 1)); // Array.prototype.slice will convert the arguments object

/**
* Method to get some updated details about pagination.
**/
updateMeta: function() {
setData: function (object) {
var that = this;
$.extend(this.requestData, object);
$.ajax({
cache: false,
url: this.settings.urlMeta,
method: this.settings.method,
data: this.pageMeta,
dataType: 'json',
success: function(data) {
that.trigger('page.meta.loaded', data);
if (data) {
$.extend(true, that.pageMeta, data);
that.trigger('page.meta.updated', data);
} else {
that.trigger('page.meta.empty', data);
console.warn('Page meta update found no data.');
}
},
error: function(response) {
console.error('Erro ao carregar meta dados.');
console.log(response);
},
complete: function(response) {
console.groupEnd();
}
});
return this;
},
setData: function(object) {
$.extend(this.requestData, object);
setMeta: function (meta) {
$.extend(this.meta, meta);
}

@@ -297,0 +387,0 @@

@@ -1,7 +0,9 @@

(function(c,f,h,e){if(!c)return console.error("pageIt: N\u00e3o foi poss\u00edvel reconhecer o jQuery, inicializa\u00e7\u00e3o cancelada!"),!1;var g={url:"",method:"get",dataType:"html",initPage:1,cacheAjax:!1,cachePagination:!0,contentView:null,urlMeta:"",pageMeta:{first:1,prev:e,current:e,next:e,last:e,total:e}};f.pageIt=function(a){this.settings=c.extend(!0,{},g,a);this.events={};this.pages=[];this.pageMeta=this.settings.pageMeta;this.pageMeta.prev=this.settings.initPage-1;this.pageMeta.current=
this.settings.initPage;this.pageMeta.next=this.settings.initPage+1;this.requestData={};return this.init()};c.extend(f.pageIt.prototype,{init:function(){this.settings.initPage&&this.to(this.settings.initPage);this.trigger("pageIt.ready")},to:function(a){if(!a||a>this.pageMeta.last)return this;if("string"===typeof a&&"next"===a||"prev"===a)return this[a]();if(this.settings.cachePagination&&this.pages[a])this.pages[a].content?(this.settings.contentView&&(this.settings.contentView.innerHTML=this.pages[a].content,
this.trigger("page.filled",this.pages[a])),this.trigger("page.content.loaded",this.pages[a]),this.trigger("page.loaded.cache",this.pages[a])):this.trigger("page.content.empty",this.pages[a]);else{this.requestData={};this.requestData.pageIndex=a;this.trigger("page.load.before",this.requestData);var b=this;c.ajax({cache:this.settings.cache,url:this.settings.url,method:this.settings.method,data:this.requestData,dataType:this.settings.dataType,success:function(d){b.pages[a]=d;b.pageMeta.prev=a-1;b.pageMeta.current=
a;b.pageMeta.next=a+1;b.trigger("page.content.loaded",d);d?"html"===b.settings.dataType&&b.settings.contentView?c(b.settings.contentView).html(d)&&b.trigger("page.filled",d):console.warn("No container set, no data will be auto inserted."):b.trigger("page.content.empty",d)},error:function(a){console.error("Erro ao carregar p\u00e1gina.");console.log(a)},complete:function(a){b.trigger("page.load.after",a);console.groupEnd()}})}return this},first:function(){this.trigger("page.first",this.pageMeta.first);
return this.to(this.pageMeta.first)},prev:function(){this.trigger("page.prev",this.pageMeta.next);return this.to(this.pageMeta.prev)},next:function(){this.trigger("page.next",this.pageMeta.next);return this.to(this.pageMeta.next)},last:function(){this.trigger("page.last",this.pageMeta.last);return this.to(this.pageMeta.last)},on:function(a,b){this.events[a]?this.events[a].push(b):this.events[a]=[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},updateMeta:function(){var a=this;c.ajax({cache:!1,url:this.settings.urlMeta,method:this.settings.method,data:this.pageMeta,dataType:"json",success:function(b){a.trigger("page.meta.loaded",b);b?(c.extend(!0,a.pageMeta,b),a.trigger("page.meta.updated",b)):(a.trigger("page.meta.empty",b),console.warn("Page meta update found no data."))},error:function(a){console.error("Erro ao carregar meta dados.");console.log(a)},complete:function(a){console.groupEnd()}});
return this},setData:function(a){c.extend(this.requestData,a)}});return f.pageIt})(window.jQuery||!1,window,document);
(function(d,g,k,l){var f={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 f.error("pageIt: N\u00e3o foi poss\u00edvel reconhecer o jQuery, inicializa\u00e7\u00e3o cancelada!"),
!1;Array.prototype.some||(Array.prototype.some=function(a){if(null==this)throw new TypeError("Array.prototype.some called on null or undefined");if("function"!==typeof a)throw new TypeError;for(var b=Object(this),c=b.length>>>0,d=2<=arguments.length?arguments[1]:void 0,e=0;e<c;e++)if(e in b&&a.call(d,b[e],e,b))return!0;return!1});var h={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}};g.pageIt=function(a){this.settings=d.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.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(g.pageIt.prototype,{init:function(){this.trigger("ready");this.settings.initPage&&this.to(this.settings.initPage)},to:function(a){if(!0===this.requesting)return f.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.settings.contentView&&(this.settings.contentView.innerHTML=this.pages[a].content,this.trigger("page.filled",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={};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,g,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.settings.contentView?d(b.settings.contentView).html(c.content)&&b.trigger("page.load.autoupdated",c):f.warn("No container set, no data will be auto inserted.")):
b.trigger("page.load.empty",c)},error:function(a){f.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},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 f.warn("Evento indispon\u00edvel."),Error("Can't attach unrecognized event handler.");this.events[a].some(function(a){return a===b})||this.events[a].indexOf(b);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},setData:function(a){d.extend(this.requestData,a)},setMeta:function(a){d.extend(this.meta,a)}});return g.pageIt})(window.jQuery||!1,window,document);
{
"name": "jquery.page-it",
"version": "0.1.2",
"description": "Lib for build paginations.",
"version": "0.2.0",
"description": "Lib for building paginations.",
"main": "jquery.page-it.js",

@@ -21,3 +21,6 @@ "scripts": {

},
"homepage": "https://github.com/odahcam/jquery.page-it#readme"
"homepage": "https://github.com/odahcam/jquery.page-it#readme",
"dependencies": {
"jquery": "2.x"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc