Skip to content

Commit

Permalink
Remove coffee version of sort.
Browse files Browse the repository at this point in the history
  • Loading branch information
rstacruz committed Nov 4, 2012
1 parent 9876bcf commit 005544a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 48 deletions.
24 changes: 0 additions & 24 deletions sort/jquery.sort.coffee

This file was deleted.

56 changes: 32 additions & 24 deletions sort/jquery.sort.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
(function() {
jQuery.fn.sort = function(options) {
var list, order, parent, sel, via;
if (options == null) {
options = {};
}
via = options.via || function(el) {
return el.text();
};
sel = options.items || '*';
sel = "> " + sel;
order = options.order || 'asc';
parent = $(this);
list = [];
parent.find(sel).each(function() {
return list.push($(this).remove());
});
/*! jQuery.sort (c) 2012, Rico Sta. Cruz. MIT License.
* https://github.com/rstacruz/jquery-stuff/tree/master/sort */

// $.fn.sort()
// Sorts the insides of a given element.
// Requires underscore.js.
//
// Options:
//
// * `via` (function, required) - should return the value to be sorted.
// * `items` (string) - the selector of the children. defaults to '*'.
// * `order` (string) - the order ('desc' or 'asc'). defaults to 'asc'.

(function($, _) {
$.fn.sort = function(options) {
if (!options) options = {};

var via = options.via || function(el) { return el.text(); };
var sel = "> " + (options.items || '*');
var order = options.order || 'asc';
var parent = $(this);
var list = [];

// Build the list of elements while taking them out of the DOM.
parent.find(sel).each(function() { list.push($(this).remove()); });

// Sort that list then add them back in.
list = _.sortBy(list, via);
if (order === 'desc') {
list.reverse();
}
return _.each(list, function(element) {
return parent.append(element);
});
if (order === 'desc') list.reverse();
_.each(list, function(element) { parent.append(element); });

return this;
};
}).call(this);
})(jQuery, _);

0 comments on commit 005544a

Please sign in to comment.