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

Extending Rye functions #33

Closed
ghost opened this issue Nov 8, 2014 · 1 comment
Closed

Extending Rye functions #33

ghost opened this issue Nov 8, 2014 · 1 comment

Comments

@ghost
Copy link

ghost commented Nov 8, 2014

I've been reading Rye's documentation for 2 hours but can't manage to extend Rye functions as I would with JQuery. For example, what would be Rye's equivalent of this JQuery function?

$.fn.blueBorder = function(){
    this.css({border-color:'blue'})
    return this;
};
@ricardobeat
Copy link
Member

There are two (or more) ways to extend Rye. One is to use Rye's Style module as a building block:

Rye.define('blueBorder', function () {
    var style = Rye.require('Style')
    return function (element) {
        style.setCss(element, 'border-color', 'blue')
    }
})

And then use it as a utility method in your code:

var blueBorder = Rye.require('blueBorder')
$('.my-elements').each(blueBorder)
// or
blueBorder(myelement.get(0))

Two, and the equivalent of jQuery's fn shortcut, is to define a new module. It runs with Rye.prototype as it's context, you can look at any of the source files in https://github.com/ryejs/rye/tree/master/lib and use the same pattern. E.g:

Rye.define('blueBorder', function () {
    this.blueBorder = function () {
        this.css({ 'border-color': 'blue' })
        return this
    }
})

$('.elements').blueBorder()

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

No branches or pull requests

1 participant