Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to customize update method for attributes #212

Closed
generalov opened this issue Mar 11, 2014 · 2 comments · May be fixed by #275
Closed

Ability to customize update method for attributes #212

generalov opened this issue Mar 11, 2014 · 2 comments · May be fixed by #275

Comments

@generalov
Copy link

It would be useful ability to set dom element attributes with custom method.

The current implementation uses $.attr() which has issues with case sensitive attributes.

I have HTML with embedded SVG:

<div>
  <svg viewBox="0 0 100 100"></svg>
</div>

And I want to bind attribute viewBox on svg element with stickit:

   bindings: {
        ':el': {
            attributes: [{
                name: 'viewBox',
                observe: ['width', 'height'],
                onGet: function(val) {
                    return '0 0 ' + val[0] + ' ' + val[1];
                }
            }]
        }
    }

This does not work as expected beacause it adds another attribute with name in lowcase:

 <svg viewBox="0 0 100 100" viewbox="0 0 100 100"></svg>

The name viewbox is meanless for SVG. The issue due method which jQuery.attr() function handles case sensitivity for attributes and this is "won't fix" http://bugs.jquery.com/ticket/11166

There is workaround to add attrHook to jQuery:

$.attrHooks.viewbox = {
    set: function(elem, value, name) {
        elem.setAttributeNS(null, 'viewBox', value + '');
        return value;
    }
};

But it seems to me that it is not too obvious. It would be nice abilty to customize DOM access methods at stickit binding level.

@bisrael
Copy link

bisrael commented Mar 28, 2014

this looks like a dupe of #204

@akre54
Copy link
Contributor

akre54 commented May 6, 2014

Yeah unfortunately if jQuery has it marked as a wontfix there's not a whole lot we can do about it. It's best if you add the changes to jQuery directly rather than through Stickit.

Getting Stickit involved in messing with attribute handlers opens a whole can of worms that are outside the project scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants