Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is one of the more elaborate boilerplates. He talks about following the guidelines, but then complicates things by implementing one <code>foobar</code> plugin, with delegates things to multiple <code>methods</code>. This obscures what is returned and how chaining is supposed to work. I don't see this level of complexity in the 'Advanced Plugin' page that he references (<a href="http://learn.jquery.com/plugins/advanced-plugin-concepts/" rel="nofollow noreferrer">http://learn.jquery.com/plugins/advanced-plugin-concepts/</a>)</p> <p>It might help to compare it with simpler ones</p> <p><a href="http://coffeescriptcookbook.com/chapters/jquery/plugin" rel="nofollow noreferrer">http://coffeescriptcookbook.com/chapters/jquery/plugin</a></p> <p><a href="https://github.com/jquery-boilerplate/jquery-boilerplate/blob/master/src/jquery.boilerplate.coffee" rel="nofollow noreferrer">https://github.com/jquery-boilerplate/jquery-boilerplate/blob/master/src/jquery.boilerplate.coffee</a></p> <p><a href="https://stackoverflow.com/a/18049128/901925">https://stackoverflow.com/a/18049128/901925</a> a coffeescript script that creates 2 plugins, and connects them to a <code>flot</code> plot. It is an adaptation of a <code>flot</code> javascript example. Note the use of <code>$ -&gt;</code>, <code>$.fn.pluginname -&gt;</code>, and <code>$('element').plugin()</code>. Those are the key jQuery pieces.</p> <p>A coffeescript function just returns the last item. The fact that it returns the function is not important if the caller does not use the return value. What matters when creating a plugin is that $.fn gets a new attribute (some use <code>extend</code> to add several attributes).</p> <p>If the plugin uses <code>@each</code>, and is called with something like <code>$("li").myplugin()</code> then each element is used</p> <pre><code>$.fn.myplugin = (options) -&gt; @each ()-&gt; console.log 'adding plugin to ',@ </code></pre> <p>The boilerplate mentions this in a comment</p> <pre><code># $this.each (index, el) -&gt; # # do something with el </code></pre> <p>A better way to integrate these ideas might be to go through the learn.jquery pages, and write the scripts in Coffeescript. They are short enough that you can use the browser based interpreter that shows coffeescript and javascript side by side.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload