2

How can I use an external jquery plugin with Script# 0.7? Is there a tool to convert any jquery plugin to equivalent c# code? Or we have to do it manually?

2 Answers 2

4

Depending on your exact code, the following might also be appropriate:

jQuery.Select("#myDiv").Plugin<jQueryWithFoo>().FooInit();

This is useful if you have multiple plugins you want to use, and use the fluent-API pattern that you would in regular jQuery. Example:

jQuery.Select("#myDiv").
    Plugin<jQueryFoo>().FooInit().
    Plugin<jQueryBar>().SomeBarMethod();
Sign up to request clarification or add additional context in comments.

Comments

2

In my opinion it's usually a better use of one's time to include the plugin as-is (in it's JavaScript form), and then prepare an imported type in Script# for exposing the plugin's functionality to the rest of Script#.

I don't know if there is a shortcut approach in Script# when dealing specifically with jQuery plugins, but what I've quickly done in the past is something like the following:

// Import my plugin "Foo"
[Imported]
[IgnoreNamespace]
public class jQueryWithFoo : jQueryObject
{
    private jQueryWithFoo () { }

    [ScriptName("foo")]
    public void FooInit() { }

    [ScriptName("foo")]
    public void FooMethod(string method) { }

    [ScriptName("foo")]
    public void FooMethodWithOptions(string method, Dictionary options) { }
}

Then to use the plugin on an object you just cast to your imported type:

// grab my div and cast to my plugin type
jQueryWithFoo myDiv = (jQueryWithFoo)jQuery.Select("#myDiv");

// use the plugin
myDiv.FooInit();
myDiv.FooMethod("toggle");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.