Browse Source

add a filtering logic, halfway

pull/14/head
desandro 15 years ago
parent
commit
efec3222db
  1. 137
      jquery.mercutio.js

137
jquery.mercutio.js

@ -51,16 +51,36 @@
var mercutioMethods = { var mercutioMethods = {
// gets all current children ( filtered if necessary ) in the pool
getCards : function() {
// var props = this.data('mercutio');
//
// props.
// console.log( this, props )
},
filter : function() { filter : function() {
var props = this.data('mercutio'),
filter = props.opts.filter,
$cards = props.$cards.all;
if ( !filter ) {
props.$cards.filtered = $cards;
} else {
var hiddenClass = props.opts.hiddenClass,
hiddenSelector = '.' + hiddenClass,
$visibleCards = $cards.not( hiddenSelector ),
$hiddenCards = $cards.filter( hiddenSelector ),
$cardsToShow = $hiddenCards;
props.$cards.filtered = $cards.filter( filter );
if ( filter === '*' ) {
// $visibleCards = this;
} else {
$cardsToShow = $hiddenCards.filter( filter );
$cardsToHide = $visibleCards.not( filter );
props.styleQueue.push({ $el: $cardsToHide, style: props.opts.hiddenStyle });
}
props.styleQueue.push({ $el: $cardsToShow, style: props.opts.visibleStyle });
}
return this;
}, },
// used on all the filtered cards, $cards.filtered // used on all the filtered cards, $cards.filtered
@ -96,9 +116,8 @@
}; };
// position the brick // position the brick
this[ props.applyStyle ]( position, animOpts ); props.styleQueue.push({ $el: this, style: position });
// this[ props.applyStyle ]( position, animOpts );
// console.log( props.colY )
// apply setHeight to necessary columns // apply setHeight to necessary columns
for ( i=0; i < setSpan; i++ ) { for ( i=0; i < setSpan; i++ ) {
@ -144,16 +163,39 @@
}); });
}, },
// used on collection of cards (should be filtered, and sorted before )
// accepts cards-to-be-laid-out and colYs to start with
layout : function( $cards, colYs ) {
var props = this.data('mercutio'); complete : function( props ) {
// are we animating the layout arrangement? // are we animating the layout arrangement?
// use plugin-ish syntax for css or animate // use plugin-ish syntax for css or animate
props.applyStyle = ( props.initiated && props.opts.animate ) ? 'animate' : 'css'; var styleFn = ( props.initiated && props.opts.animate ) ? 'animate' : 'css',
animOpts = props.opts.animationOptions;
// process styleQueue
$.each( props.styleQueue, function( i, obj ){
// have to extend animation to play nice with jQuery
obj.$el[ styleFn ]( obj.style, $.extend( {}, animOpts ) );
});
// clear out queue for next time
props.styleQueue = [];
// provide props.bricks as context for the callback
// callback = callback || function(){};
// callback.call( props.$bricks );
// set all data so we can retrieve it for appended appendedContent
// or anyone else's crazy jquery fun
this.data( 'mercutio', props );
return this;
},
// used on collection of cards (should be filtered, and sorted before )
// accepts cards-to-be-laid-out and colYs to start with
layout : function( $cards, colYs ) {
var props = this.data('mercutio');
// layout logic // layout logic
var layoutMode = props.opts.singleMode ? 'singleColumn' : 'multiColumn'; var layoutMode = props.opts.singleMode ? 'singleColumn' : 'multiColumn';
@ -162,45 +204,40 @@
// set the height of the container to the tallest column // set the height of the container to the tallest column
props.containerHeight = Math.max.apply( Math, props.colYs ); props.containerHeight = Math.max.apply( Math, props.colYs );
var containerStyle = { height: props.containerHeight - props.posTop }, var containerStyle = { height: props.containerHeight - props.posTop };
animOpts = $.extend( {}, props.opts.animationOptions ); props.styleQueue.push({ $el: this, style: containerStyle });
this[ props.applyStyle ]( containerStyle, animOpts );
// add masoned class first time around // this[ props.applyStyle ]( containerStyle, animOpts ).mercutio( 'complete', props );
if ( !props.initiated ) {
// wait 1 millisec for quell transitions
var $container = this;
setTimeout(function(){
$container.addClass('mercutio');
}, 1 );
}
// provide props.bricks as context for the callback
// callback = callback || function(){};
// callback.call( props.$bricks );
// set all data so we can retrieve it for appended appendedContent this.mercutio( 'complete', props );
// or anyone else's crazy jquery fun
this.data( 'mercutio', props );
return this; return this;
}, },
resetColYs : function( props ) {
var colYs = [],
i = props.colCount;
while (i--) {
colYs.push( props.posTop );
}
props.colYs = colYs;
return colYs
},
resize : function() { resize : function() {
// console.log( this.data('mercutio') , this[0].id ) // console.log( this.data('mercutio') , this[0].id )
var props = this.data('mercutio'), var props = this.data('mercutio'),
prevColCount = props.colCount; prevColCount = props.colCount;
props.initiated = true; props.initiated = true;
// get updated colCount // get updated colCount
// console.log('resize')
this.mercutio( 'getColCount', props ); this.mercutio( 'getColCount', props );
// console.log( props.colCount, prevColCount )
if ( props.colCount !== prevColCount ) { if ( props.colCount !== prevColCount ) {
// if column count has changed, do a new column cound // if column count has changed, do a new column cound
var colYs = this.mercutio( 'resetColYs', props ); var colYs = this.mercutio( 'resetColYs', props );
this.mercutio( 'layout', props.$cards.all, colYs ); this.mercutio( 'layout', props.$cards.filtered, colYs );
} }
return this; return this;
@ -220,6 +257,7 @@
setup : function() { setup : function() {
var props = this.data('mercutio'); var props = this.data('mercutio');
props.$cards = {}; props.$cards = {};
props.styleQueue = [];
// need to get cards // need to get cards
props.$cards.all = props.opts.selector ? props.$cards.all = props.opts.selector ?
this.find( props.opts.selector ) : this.find( props.opts.selector ) :
@ -244,18 +282,16 @@
props.posLeft = Math.round( $cursor.position().left ); props.posLeft = Math.round( $cursor.position().left );
$cursor.remove(); $cursor.remove();
// add mercutio class first time around
var $container = this;
setTimeout(function(){
$container.addClass('mercutio');
}, 1 );
return this; return this;
}, },
resetColYs : function( props ) {
var colYs = [],
i = props.colCount;
while (i--) {
colYs.push( props.posTop );
}
props.colYs = colYs;
return colYs
},
init : function( options ) { init : function( options ) {
@ -284,7 +320,9 @@
} }
var colYs = $this.mercutio( 'resetColYs', props ); var colYs = $this.mercutio( 'resetColYs', props );
$this.mercutio( 'layout', props.$cards.all, colYs ); $this
.mercutio( 'filter' )
.mercutio( 'layout', props.$cards.filtered, colYs );
// binding window resizing // binding window resizing
@ -327,6 +365,13 @@
// appendedContent: undefined, // appendedContent: undefined,
// saveOptions: true, // saveOptions: true,
resizeable: true, resizeable: true,
hiddenClass : 'mercutio-hidden',
hiddenStyle : {
opacity : 0
},
visibleStyle : {
opacity : 1
}
// animate: false, // animate: false,
// animationOptions: {} // animationOptions: {}
}; };

Loading…
Cancel
Save