dist/backbone.select.js
function triggerMultiSelectEvents ( collection, prevSelected, options, reselected ) {
        function mapCidsToModels ( cids, collection, previousSelection ) {
            function mapper ( cid ) {
                // Find the model in the collection. If not found, it has been removed, so get it from the array of
                // previously selected models.
                return collection.get( cid ) || previousSelection[cid];
            }

            return _.map( cids, mapper );
        }

        if ( options.silent || options["@bbs:silentLocally"] ) return;

        var diff,
            label = getLabel( options, collection ),

            selectionSize = getSelectionSize( collection, label ),
            length = collection.length,

            prevSelectedCids = _.keys( prevSelected ),
            selectedCids = _.keys( collection[label] ),
            addedCids = _.difference( selectedCids, prevSelectedCids ),
            removedCids = _.difference( prevSelectedCids, selectedCids ),

            unchanged = (selectionSize === prevSelectedCids.length && addedCids.length === 0 && removedCids.length === 0);

        if ( reselected && reselected.length && !options["@bbs:silentReselect"] ) {
            queueEventSet( "reselect:any", label, [ reselected, collection, toEventOptions( options, label, collection ) ], collection, options );
        }

        if ( unchanged ) return;

        diff = {
            selected: mapCidsToModels( addedCids, collection, prevSelected ),
            deselected: mapCidsToModels( removedCids, collection, prevSelected )
        };

        if ( selectionSize === 0 ) {
            queueEventSet( "select:none", label, [ diff, collection, toEventOptions( options, label, collection ) ], collection, options );
            return;
        }

        if ( selectionSize === length ) {
            queueEventSet( "select:all", label, [ diff, collection, toEventOptions( options, label, collection ) ], collection, options );
            return;
        }

        if ( selectionSize > 0 && selectionSize < length ) {
            queueEventSet( "select:some", label, [ diff, collection, toEventOptions( options, label, collection ) ], collection, options );
            return;
        }
    }
function triggerMultiSelectEvents ( collection, prevSelected, options, reselected ) {
        function mapCidsToModels ( cids, collection, previousSelection ) {
            function mapper ( cid ) {
                // Find the model in the collection. If not found, it has been removed, so get it from the array of
                // previously selected models.
                return collection.get( cid ) || previousSelection[cid];
            }

            return _.map( cids, mapper );
        }

        if ( options.silent || options["@bbs:silentLocally"] ) return;

        var diff,
            label = getLabel( options, collection ),

            selectionSize = getSelectionSize( collection, label ),
            length = collection.length,

            prevSelectedCids = _.keys( prevSelected ),
            selectedCids = _.keys( collection[label] ),
            addedCids = _.difference( selectedCids, prevSelectedCids ),
            removedCids = _.difference( prevSelectedCids, selectedCids ),

            unchanged = (selectionSize === prevSelectedCids.length && addedCids.length === 0 && removedCids.length === 0);

        if ( reselected && reselected.length && !options["@bbs:silentReselect"] ) {
            queueEventSet( "reselect:any", label, [ reselected, collection, toEventOptions( options, label, collection ) ], collection, options );
        }

        if ( unchanged ) return;

        diff = {
            selected: mapCidsToModels( addedCids, collection, prevSelected ),
            deselected: mapCidsToModels( removedCids, collection, prevSelected )
        };

        if ( selectionSize === 0 ) {
            queueEventSet( "select:none", label, [ diff, collection, toEventOptions( options, label, collection ) ], collection, options );
            return;
        }

        if ( selectionSize === length ) {
            queueEventSet( "select:all", label, [ diff, collection, toEventOptions( options, label, collection ) ], collection, options );
            return;
        }

        if ( selectionSize > 0 && selectionSize < length ) {
            queueEventSet( "select:some", label, [ diff, collection, toEventOptions( options, label, collection ) ], collection, options );
            return;
        }
    }
function triggerMultiSelectEvents ( collection , prevSelected , options , reselected ) { function mapCidsToModels ( cids , collection , previousSelection ) { function mapper ( cid ) { // Find the model in the collection. If not found, it has been removed, so get it from the array of // previously selected models. return collection . get ( cid ) || previousSelection [ cid ] ; } return _ . map ( cids , mapper ) ; } if ( options . silent || options [ "@bbs:silentLocally" ] ) return ; var diff , label = getLabel ( options , collection ) , selectionSize = getSelectionSize ( collection , label ) , length = collection . length , prevSelectedCids = _ . keys ( prevSelected ) , selectedCids = _ . keys ( collection [ label ] ) , addedCids = _ . difference ( selectedCids , prevSelectedCids ) , removedCids = _ . difference ( prevSelectedCids , selectedCids ) , unchanged = ( selectionSize === prevSelectedCids . length && addedCids . length === 0 && removedCids . length === 0 ) ; if ( reselected && reselected . length && ! options [ "@bbs:silentReselect" ] ) { queueEventSet ( "reselect:any" , label , [ reselected , collection , toEventOptions ( options , label , collection ) ] , collection , options ) ; } if ( unchanged ) return ; diff = { selected : mapCidsToModels ( addedCids , collection , prevSelected ) , deselected : mapCidsToModels ( removedCids , collection , prevSelected ) } ; if ( selectionSize === 0 ) { queueEventSet ( "select:none" , label , [ diff , collection , toEventOptions ( options , label , collection ) ] , collection , options ) ; return ; } if ( selectionSize === length ) { queueEventSet ( "select:all" , label , [ diff , collection , toEventOptions ( options , label , collection ) ] , collection , options ) ; return ; } if ( selectionSize > 0 && selectionSize < length ) { queueEventSet ( "select:some" , label , [ diff , collection , toEventOptions ( options , label , collection ) ] , collection , options ) ; return ; } }
Trigger events from a multi-select collection, based on the number of selected items.
Trigger events from a multi - select collection based on the number of selected items .