Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

timbles

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timbles - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

examples/timbles-id-free.html

2

package.json
{
"name": "timbles",
"version": "1.0.8",
"version": "1.0.9",
"description": "a p chill jQuery table plugin, made by someone who literally did not invent tables",

@@ -5,0 +5,0 @@ "main": "timbles",

@@ -97,3 +97,3 @@ timbles.js

In order for sorting to work, the `<th>` cells need to have an `id` attribute and the parent `<tr>` of the header rows needs to be within a `<thead>` tag. Again, view the source above for the example.
In order for sorting to work, the parent `<tr>` of the header rows needs to be within a `<thead>` tag. The `<th>` cells should to have an `id` attribute, like in the example above, but if they are left out then Timbles will assign some ugly id attribute values for you.

@@ -100,0 +100,0 @@ If you want to initially sort your table on load, there are `sorting` properties you can set:

@@ -6,3 +6,3 @@ /**

*
* @version 1.0.8
* @version 1.0.9
* @author jenn schiffer http://jennmoney.biz

@@ -84,3 +84,9 @@ */

data.$headerRow.find('th').each(function(i){
// ensure all header cells have a legit id
var headerId = $(this).attr('id');
if ( !headerId ) {
headerId = 'timbles-anon-' + $.timblesAnonCount++;
$(this).attr('id',headerId);
}
data.$records.each(function(j){

@@ -206,70 +212,45 @@ $(this).find('td').eq(i).addClass(headerId);

var $headers = $this.find('th');
// determine order and update header sort classes
var $sortHeader = $this.find('#' + key);
// determine order and clear header sort classes
if ( !order ) {
order = $sortHeader.hasClass(classes.sortASC) ? 'desc' : 'asc';
}
$headers.removeClass(classes.sortASC).removeClass(classes.sortDESC);
data.$headerRow.find('th')
.removeClass(classes.sortASC)
.removeClass(classes.sortDESC);
$sortHeader.addClass((order === 'asc') ? classes.sortASC : classes.sortDESC);
// literally sort non-header-row records
var $recordsToSort = data.$records;
var $sortedRecords;
// determine column values to actually sort by
var sortMap = data.$records.map(function(index) {
var $cell = $(this).find('td.' + key);
return {
index: index,
value: $cell.data('value') || $cell.text()
};
});
if (order === 'asc') {
$sortHeader.addClass(classes.sortASC);
// sort the mapping by the extract column values
sortMap.sort(function(a, b) {
if (a.value > b.value) {
return (order === 'asc') ? 1 : -1;
}
if (a.value < b.value) {
return (order === 'asc') ? -1 : 1;
}
return 0;
});
var alpha, beta;
$sortedRecords = $recordsToSort.sort( function(a, b) {
alpha = $(a).find('td.' + key).data('value');
beta = $(b).find('td.' + key).data('value');
alpha = (alpha) ? alpha : $(a).find('td.' + key).text();
beta = (beta) ? beta : $(b).find('td.' + key).text();
if ( alpha < beta ) {
return -1;
}
else {
if ( alpha > beta ) {
return 1;
}
else {
return 0;
}
}
});
// use sortMap to shuffle table rows to the correct order
// work on detached DOM for improved performance on large tables
var tableBody = $this.find('tbody').detach().get(0);
for (var i = 0; i < sortMap.length; i++) {
tableBody.appendChild(data.$records[sortMap[i].index]);
}
else {
$sortHeader.addClass(classes.sortDESC);
$sortedRecords = $recordsToSort.sort( function(a, b) {
alpha = $(a).find('td.' + key).data('value');
beta = $(b).find('td.' + key).data('value');
$(tableBody).appendTo($this);
data.$allRows = $this.find('tr');
data.$records = data.$allRows.not('.' + classes.headerRow);
$this.data(pluginName, data);
alpha = (alpha) ? alpha : $(a).find('td.' + key).text();
beta = (beta) ? beta : $(b).find('td.' + key).text();
if ( beta < alpha ) {
return -1;
}
else {
if ( beta > alpha ) {
return 1;
}
else {
return 0;
}
}
});
}
// remove current unsorted records
if ( $recordsToSort ) {
$recordsToSort.remove();
}
// append sorted records
$this.append($sortedRecords);
// if table was paginated, reenable

@@ -418,4 +399,2 @@ if ( data.pagination ) {

console.log(data.$pointerThisPage, data.$pointerLastPage);
// save it all

@@ -447,3 +426,3 @@ $this.data(pluginName, data);

var newRowCount = $(this).text();
if ( newRowCount.toLowerCase() == 'all' ) {
if ( newRowCount.toLowerCase() === 'all' ) {
newRowCount = data.$records.length;

@@ -536,2 +515,3 @@ }

/** module definition */
$.timblesAnonCount = 0;
$.fn[pluginName] = function (method) {

@@ -551,2 +531,2 @@ if ( methods[method] ) {

})( jQuery );
})( jQuery );
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