This project is archived and is in readonly mode.

#472 ✓invalid
Chris the Developer

Array.exclude

Reported by Chris the Developer | November 14th, 2008 @ 10:34 AM | in 2.0 (closed)

I realise this may be blurring the line between the Array native and the Element [array] native, but I was looking for a way to exclude elements from and array by using a selector, so this is what I came up with...


Array.implement({
	exclude: function(selector) {
		return this.filter(function(item, index, array) {
			return !item.match(selector);
		});
	}
});

It could probably use a less ambiguous name, but is perhaps a useful addition to core.

I found it useful in the following instance:


<li class="paragraph-block">
            <div class="paragraph-title"></div>
            <div class="paragraph-text"></div>
            <a href="#" class="paragraph-delete">Delete</a>
            <a href="#" class="paragraph-move">Move</a>
            <input type="hidden" name="paragraph_id_[replace]" value="0" />
            <input type="hidden" name="paragraph_delete_[replace]" value="" />
        </li>

$(document.body).delegateEvent('click', {
		'a.paragraph-delete': function() {
			this.getParent().getChildren().exclude('input[type=hidden]').destroy();
		}
	});

Comments and changes to this ticket

  • Chris the Developer

    Chris the Developer November 14th, 2008 @ 10:37 AM

    • Assigned user cleared.

    The important bit in the example is:

    
    this.getParent().getChildren().exclude('input[type=hidden]').destroy();
    

    The rest is just usual event delegation...

  • Jan Kassens

    Jan Kassens November 14th, 2008 @ 11:30 AM

    • State changed from “new” to “invalid”
    • Assigned user set to “Jan Kassens”

    I don't think its needed as you can invert the behaviour of .filter with the :not pseudo selector.

    
    elements.filter(':not(input[type=hidden])');
    

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Pages