TinySort Test

by Robert Dodd

HTML

<button id="sort">Sort</button>
<table id="results">
    <tbody>
        <tr class="result" data-sort="1">
            <td>Result 1</td>
        </tr>
        <tr class="result" data-sort="3">
            <td>Result 3</td>
        </tr>
        <tr class="result" data-sort="2">
            <td>Result 2</td>
        </tr>
    </tbody>
</table>

JavaScript

$(function() {
    $('#sort').click(function() {
        $('table#results>tbody>tr').tsort({data:'sort'}); 
    });
});



/* TinySort 1.5.0
* Copyright (c) 2008-2013 Ron Valstar http://tinysort.sjeiti.com/
*
* Dual licensed under the MIT and GPL licenses:
*   http://www.opensource.org/licenses/mit-license.php
*   http://www.gnu.org/licenses/gpl.html
*/
(function(e,c){var g=!1,h=null,n=parseFloat,i=Math.min,l=/(-?\d+\.?\d*)$/g,k=[],f=[],b=function(p){return typeof p=="string"},m=Array.prototype.indexOf||function(q){var o=this.length,p=Number(arguments[1])||0;p=p<0?Math.ceil(p):Math.floor(p);if(p<0){p+=o}for(;p<o;p++){if(p in this&&this[p]===q){return p}}return -1};e.tinysort={id:"TinySort",version:"1.5.0",copyright:"Copyright (c) 2008-2013 Ron Valstar",uri:"http://tinysort.sjeiti.com/",licensed:{MIT:"http://www.opensource.org/licenses/mit-license.php",GPL:"http://www.gnu.org/licenses/gpl.html"},plugin:function(o,p){k.push(o);f.push(p)},defaults:{order:"asc",attr:h,data:h,useVal:g,place:"start",returns:g,cases:g,forceStrings:g,sortFunction:h}};e.fn.extend({tinysort:function(){var I,E,K=this,G=e(K).length,s=[],r=[],L=[],N=[],w=0,q,D=[],A=[],B=function(o){e.each(k,function(O,P){P.call(P,o)})},x=function(X,V){var o=0;if(w!==0){w=0}while(o===0&&w<q){var U=N[w],R=U.oSettings;B(R);if(R.sortFunction){o=R.sortFunction(X,V)}else{if(R.order=="rand"){o=Math.random()<0.5?1:-1}else{var W=g,Q=!R.cases?a(X.s[w]):X.s[w],P=!R.cases?a(V.s[w]):V.s[w];if(!t.forceStrings){var O=b(Q)?Q&&Q.match(l):g,Y=b(P)?P&&P.match(l):g;if(O&&Y){var T=Q.substr(0,Q.length-O[0].length),S=P.substr(0,P.length-Y[0].length);if(T==S){W=!g;Q=n(O[0]);P=n(Y[0])}}}o=U.iAsc*(Q<P?-1:(Q>P?1:0))}}e.each(f,function(Z,aa){o=aa.call(aa,W,Q,P,o)});if(o===0){w++}}return o};for(I=0,E=arguments.length;I<E;I++){var...