Skip to content

Add seletor at the beginning of the ruleset #3

@s1738berger

Description

@s1738berger

Hi, sometimes it is important to add a selector at the beginning of the css tree. In my case it is the universal seletor (_).
Here an idea to achieve this. This new sub routine _unshift_selector* is just a slightly modified version of the existing add_selector.
Would be nice to see this functionality in the next version of CSS::Simple
Regards, Stefan


=pod

=item unshift_selector( params )

Add a selector and associated properties to the stored rulesets on first place

In the event that this particular ruleset already exists, invoking this method will
simply replace the item. This is important - if you are modifying an existing rule
using this method than the previously existing selectivity will continue to persist.
Delete the selector first if you want to ignore the previous selectivity.

This method requires you to pass in a params hash that contains scalar
css data. For example:

$self->unshift_selector({selector => '.foo', properties => {color => 'red' }});

=cut

sub unshift_selector {
my ($self,$params) = @_;

$self->_check_object();

#if we existed already, invoke REPLACE to preserve selectivity
if ($self->check_selector({selector => $$params{selector}})) {
#we probably want to be doing this explicitely
my ($index) = $self->_ordered()->Indices( $$params{selector} );

$self->_ordered()->Replace($index,dclone($$params{properties}));

}
#new element, stick it onto the beginning of the rulesets
else {
#store the properties
$self->_ordered()->Unshift($$params{selector},dclone($$params{properties}));
}

return();
}


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions