First update : removed static class SimplePlugin, and moved static
Initialize inside plugin class (changes are marked in comment with
***)
public class Simple : jQuery
{
//** added static method to plugin itself
public static void Initialize()
{
jQuery.fn.extend(new Simple());
}
...
}
[IgnoreNamespace]
public static class InitAll
{
static InitAll()
{
Simple.Initialize(); //*** call static method on plugin
class ***
jqProxy.jQuery(typeof(Document)).ready((Callback)delegate
()
{
Script.Alert("wait");
Simple test = (Simple)jqProxy.jQuery("div");
SimplePluginOptions opt = new SimplePluginOptions();
opt.cssvalue = "1px solid blue"; //*** test for
overiding defaults ***
test.DoSimple(opt).css("backgroundColor", "red") ; //
*** test for chaining **
});
}
}
Remarks:
- I still have a feeling, that the plugins options are not defined the
way it should.
- The this keyword in javascript has different behaviour than this in
c#, sometimes it is not possible to write the code like you would in
javascript, eg inside the this.each construct, I am not sure what this
will refer to, as ScriptSharp translates
return this.each((EachCallback)delegate(int index, DOMElement elm)
{
jqProxy.jQuery(elm).css(opt.cssproperty,
opt.cssvalue);
});
into
return this.each(Delegate.create(this, function(index, elm) {
jQuery(elm).css(opt.cssproperty, opt.cssvalue);
}));
If I am not mistaken:
jQquery states that this inside the each delegate, refers to the
DOMelement being processed.
ScriptScharp Delegate.Create binds this inside the delegate to the
instance of the class
So I suspect they are not the same....