Building Robust jQuery Plugins

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Notes on slide 1

    Goal is to show to how build a robust jQuery plugin, way beyond just coding. Your take-away should be an understanding of the surrounding infrastructure, both to be able to use and to help improve it. We've got about 50 minutes. My talk should take about 30 minutes, giving us 20 minutes for open discussion. Please ask questions whenever you want to, though I may defer some answers to the end. To start, lets look at the most important question.

    7 Favorites & 1 Event

    Building Robust jQuery Plugins - Presentation Transcript

    1. Building Robust jQuery Plugins
    2. Why bother?
      • $.each({
      • focus: 'focusin',
      • blur: 'focusout'
      • }, function( original, fix ){
      • $.event.special[fix] = {
      • setup:function() {
      • if ( $.browser.msie ) return false;
      • this.addEventListener( original, $.event.special[fix].handler, true );
      • },
      • teardown:function() {
      • if ( $.browser.msie ) return false;
      • this.removeEventListener( original,
      • $.event.special[fix].handler, true );
      • },
      • handler: function(e) {
      • arguments[0] = $.event.fix(e);
      • arguments[0].type = fix;
      • return $.event.handle.apply(this, arguments);
      • }
      • };
      • });
    3. Don't reinvent the wheel
    4. “ Given enough eyeballs, all bugs are shallow ” -- Eric S. Raymond
    5. Infrastructure
    6. Design
    7. Consider the audience
    8.  
    9.  
    10.  
      • jQuery.validator. addMethod ("domain", function(value) {
      • return /^http://mycorporatedomain.com/.test(value); }
      • , "Please specify the correct domain");
      • jQuery.validator.addMethod("nowhite", function(value) {
      • return /^S+$/.test(value);
      • }, "No white space please");
      • jQuery.validator.addMethod("nowhite", function(value) {
      • return /^d+$/.test(value);
      • }, "Please enter only digits");
    11.  
    12. Test-driven development
    13.  
    14.  
    15. Tests first
    16. Behaviour-driven developement
    17. Why bother?
    18. QUnit
    19. test("my ajax code", function() { expect(1); stop(); $.get("myurl", function(response) { equals(response, "expected response"); start(); }); });
    20. Implementing
    21. (function($) { $.fn.plugin = function() { return this.each(function() { // your code here }); }; })(jQuery);
    22. (function($) { $.fn.delegate = function(type, delegate, handler) { return this.bind(type, function(event) { var target = $(event.target); if (target.is(delegate)) { return handler.apply(target, arguments); } }); }; })(jQuery);
    23. (function($) { $.fn.plugin = function(settings) { settings = $.extend({}, $.plugin.defaults, settings); return this.each(function() { // your code here }); }; $.plugin = { defaults: {} }; })(jQuery);
    24. Document
      • /**
      • * The number of elements currently matched.
      • *
      • * @example $("img").length;
      • * @before <img src=&quot;test1.jpg&quot;/> <img src=&quot;test2.jpg&quot;/>
      • * @result 2
      • *
      • * @property
      • * @name length
      • * @type Number
      • * @cat Core
      • */
      • /**
      • * The number of elements currently matched.
      • *
      • * @example $(&quot;img&quot;).size();
      • * @before <img src=&quot;test1.jpg&quot;/> <img src=&quot;test2.jpg&quot;/>
      • * @result 2
      • *
      • * @name size
      • * @type Number
      • * @cat Core
      • */
      • size: function() {
      • return this.length;
      • },
      • length: 0,
    25. Purpose
    26. Dependencies
    27. Pulic API
    28. Options
    29. Examples
    30. Browsing
    31.  
    32. Release
    33. jquery.plugin-1.2.3.zip - jquery-plugin-1.2.3 jquery.plugin.js jquery.plugin.min.js jquery.plugin.pack.js - demo [-docs] [-test]
    34. <target name=&quot;tooltip&quot;> <antcall target=&quot;generic&quot;> <param name=&quot;name&quot; value=&quot;tooltip&quot; /> </antcall> </target> ant tooltip
    35. 1.3 --- * Added fade option (duration in ms) for fading in/out tooltips; IE <= 6 is excluded when bgiframe plugin is included * Fixed imagemaps in IE, added back example * Added positionLeft-option - positions the tooltip to the left of the cursor * Remove deprecated $.fn.Tooltip in favor of $.fn.tooltip 1.2 --- * Improved bodyHandler option to accept HTML strings, DOM elements and jQuery objects as the return value * Fixed bug in Safari 3 where to tooltip is initially visible, by first appending to DOM then hiding it * Improvement for viewport-border-positioning: Add the classes &quot;viewport-right&quot; and &quot;viewport-bottom&quot; when the element is moved at the viewport border. * Moved and enhanced documentation to docs.jquery.com * Added examples for bodyHandler: footnote-tooltip and thumbnail * Added id option, defaults to &quot;tooltip&quot;, override to use a different id in your stylesheet * Moved demo tooltip style to screen.css * Moved demo files to demo folder and dependencies to lib folder * Dropped image map example - completely incompatible with IE; image maps aren't supported anymore
    36.  
    37.  
    38. Maintain
    39. Avoid Blog Comments
    40.  
    41.  
    42.  
    43.  
    44.  
    45. Mailing list
    46.  
    47.  
    48. General questions
    49. Tracking
    50. Thank you
    51. Questions?
    52. Bon appétit!

    + Jörn ZaeffererJörn Zaefferer, 2 years ago

    custom

    3569 views, 7 favs, 3 embeds more stats

    Presented at jQuery Conference 2008

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 3569
      • 3562 on SlideShare
      • 7 from embeds
    • Comments 0
    • Favorites 7
    • Downloads 114
    Most viewed embeds
    • 4 views on http://iurzelai.wordpress.com
    • 2 views on http://wildfire.gigya.com
    • 1 views on http://www.slideshare.net

    more

    All embeds
    • 4 views on http://iurzelai.wordpress.com
    • 2 views on http://wildfire.gigya.com
    • 1 views on http://www.slideshare.net

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Groups / Events