|
|
@ -91,29 +91,28 @@ |
|
|
|
return ( props.opts[ property ] !== previousProp ); |
|
|
|
return ( props.opts[ property ] !== previousProp ); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// used on all the filtered cards, $cards.filtered
|
|
|
|
getSortFn : function( sortBy, sortDir ) { |
|
|
|
sort : function( props ) { |
|
|
|
|
|
|
|
var sortBy = props.opts.sortBy, |
|
|
|
|
|
|
|
sortDir = props.opts.sortDir; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// don't proceed if there is nothing to sort by
|
|
|
|
|
|
|
|
// or if previousFilter == filter AND sortBy == previous Sort by
|
|
|
|
|
|
|
|
if ( !sortBy || ( !props.isNew.filter && !props.isNew.sortBy && !props.isNew.sortDir ) ) { |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// console.log('sorting...', sortBy, sortDir);
|
|
|
|
|
|
|
|
var getSorter = function( elem ) { |
|
|
|
var getSorter = function( elem ) { |
|
|
|
return $(elem).data('molequul-sort-data')[ sortBy ]; |
|
|
|
return $(elem).data('molequul-sort-data')[ sortBy ]; |
|
|
|
}; |
|
|
|
}; |
|
|
|
// console.log( sortBy );
|
|
|
|
return function( alpha, beta ) { |
|
|
|
|
|
|
|
|
|
|
|
// var sortDir = props.opts.sortDir;
|
|
|
|
|
|
|
|
props.atoms.$filtered.sort( function( alpha, beta ) { |
|
|
|
|
|
|
|
var a = getSorter( alpha ), |
|
|
|
var a = getSorter( alpha ), |
|
|
|
b = getSorter( beta ); |
|
|
|
b = getSorter( beta ); |
|
|
|
return ( a > b ) ? 1 * sortDir : ( a < b ) ? -1 * sortDir : 0; |
|
|
|
return ( a > b ) ? 1 * sortDir : ( a < b ) ? -1 * sortDir : 0; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
randomSortFn : function() { |
|
|
|
|
|
|
|
return Math.random() > 5 ? 1 : -1; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// used on all the filtered cards, $cards.filtered
|
|
|
|
|
|
|
|
sort : function( props ) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sortFn = props.opts.sortBy === 'random' ? $.molequul.randomSortFn : |
|
|
|
|
|
|
|
$.molequul.getSortFn( props.opts.sortBy, props.opts.sortDir ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
props.atoms.$filtered.sort( sortFn ); |
|
|
|
|
|
|
|
|
|
|
|
return this; |
|
|
|
return this; |
|
|
|
}, |
|
|
|
}, |
|
|
@ -449,7 +448,7 @@ |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
watchedProps : [ 'filter', 'sortBy', 'sortDir' ], |
|
|
|
watchedProps : [ 'filter', 'sortBy', 'sortDir', 'layoutMode' ], |
|
|
|
|
|
|
|
|
|
|
|
init : function( options, callback ) { |
|
|
|
init : function( options, callback ) { |
|
|
|
|
|
|
|
|
|
|
@ -474,30 +473,25 @@ |
|
|
|
if ( !props.initialized ) { |
|
|
|
if ( !props.initialized ) { |
|
|
|
$this.molequul( 'setup', props ); |
|
|
|
$this.molequul( 'setup', props ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( props.prevOpts.layoutMode && props.prevOpts.layoutMode !== props.opts.layoutMode ) { |
|
|
|
|
|
|
|
$this.molequul( props.opts.layoutMode + 'Setup', props ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check if watched properties are new
|
|
|
|
// check if watched properties are new
|
|
|
|
$.each( $.molequul.watchedProps, function( i, propName ){ |
|
|
|
$.each( $.molequul.watchedProps, function( i, propName ){ |
|
|
|
props.isNew[ propName ] = $.molequul.isNewProp( propName, props ) |
|
|
|
props.isNew[ propName ] = $.molequul.isNewProp( propName, props ) |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( props.isNew.layoutMode ) { |
|
|
|
// console.log( props.isNew )
|
|
|
|
$this.molequul( props.opts.layoutMode + 'Setup', props ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( props.isNew.filter ) { |
|
|
|
if ( props.isNew.filter ) { |
|
|
|
$this.molequul( 'filter', props.atoms.$all ); |
|
|
|
$this.molequul( 'filter', props.atoms.$all ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( props.isNew.filter || props.isNew.sortBy || props.isNew.sortDir ) { |
|
|
|
|
|
|
|
$this.molequul( 'sort', props ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$this |
|
|
|
$this.molequul( props.opts.layoutMode + 'ResetLayoutProps', props ) |
|
|
|
.molequul( 'sort', props ) |
|
|
|
|
|
|
|
.molequul( props.opts.layoutMode + 'ResetLayoutProps', props ) |
|
|
|
|
|
|
|
.molequul( 'layout', props.atoms.$filtered, callback ); |
|
|
|
.molequul( 'layout', props.atoms.$filtered, callback ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|