-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
1162 lines (1060 loc) · 59.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!--
The jQuery UI Widget Factory: WAT?
by adam j. sontag
updated by corey frang
WTFPL License
If you want the cool kid fonts for this preso:
http://www.fontsquirrel.com/fontfacedemo/ChunkFive
http://www.fontsquirrel.com/fontfacedemo/CartoGothic-Std
This all refers to the Presentation slides or whatever.
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
Copyright 2010 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Original slides: Marcin Wichary ([email protected])
Modifications: Ernest Delgado ([email protected])
Alex Russell ([email protected])
Brad Neuberg
-->
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge;chrome=1" />
<title>jQuery UI Widget Factory</title>
<link rel="shortcut icon" href="images/favicon.ico" />
<link rel="icon" href="images/favicon.ico" type="image/x-icon" />
<link href="css/fonts.css" rel="stylesheet" type="text/css" />
<link href="css/main.css" rel="stylesheet" type="text/css" />
<link href="css/syntax.css" rel="stylesheet" type="text/css" />
<link href="css/ui-lightness/jquery-ui-1.10.0.custom.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="presentation">
<div id="presentation-counter"></div>
<div class="slides">
<div class="slide" id="intro">
<div class="bg">
<section class="middle landing">
<h1>The jQuery UI Widget Factory<br/><span class='subtitle'>WAT?</span></h1>
<h4>adam j. sontag</h4>
<h4>corey frang</h4>
</section>
</div>
<div id="welcome">
<p>
<strong>Thanks for coming!</strong></p>
<p><em>The jQuery UI Widget Factory</em> is an HTML5 presentation designed to familiarise developers with basic approaches to debugging
jQuery and JavaScript code. It also introduces many of the common pitfalls most people encounter at some point on their jQuery journey.
It is always a work in progress!
</p>
<p>Use the left <span class='key'>←</span> and right <span class='key'>→</span> arrow keys or your mouse wheel to navigate.</p>
</div>
</div>
<div class="slide">
<header class="moreLegit">
<h1 class="middleGuy">ajpiano.com/widgetfactory</h1>
</header>
</div>
<div class="slide">
<header>
<h1>Easy Plugins Are Easy</h1>
</header>
<section class="text smallerCode">
<p>It's easy to extend the jQuery prototype (<code>jQuery.fn</code>) to make a <a href="http://docs.jquery.com/Plugins/Authoring">“plugin”</a> that operates on sets of elements.</p>
<pre class="brush: js; toolbar: false;">
(function( $ ) {
$.fn.redman = function() {
return this.each( function() {
$( this ).addClass( "wu-tang" )
.css( "color", "red" );
});
};
})( jQuery );
</pre>
</section>
</div>
<div class="slide">
<header>
<h1>State of Confusion</h1>
</header>
<section class="text">
<p><a href="http://en.wikipedia.org/wiki/State_(computer_science)">Stateful</a> plugins are not as straightforward, but really useful.</p>
<ul>
<li>Reverse the plugin's effect?</li>
<li>Allow plugin users to react to events triggered by the plugin?</li>
<li>Change the plugin's effect after it has been applied?</li>
<li><em>Remember: only one function in the <code>$.fn</code> namespace!</em></li>
<li>Fine! But how can I even invoke "sub-methods?"</li>
</ul>
<p>But that <a href="http://jqueryui.com">jQuery UI</a> thing has lots of plugins that let users do all that stuff! <strong>How?</strong></p>
</section>
</div>
<div class="slide">
<header>
<h1>You down with OOP?</h1>
</header>
<section class="text muchMuchSmallerCode">
<p>Objects are a good way to organise code and maintain state</p>
<pre class="brush: js; toolbar: false;">
( function( $ ) {
function Redman( elem ) {
this.init( elem );
}
Redman.prototype.init = function( elem ) {
this.element = $( elem ).addClass( "wu-tang" ).css( "color", "red" );
};
Redman.prototype.destroy = function() {
this.element.removeClass( "wu-tang" ).removeAttr( "style" ).removeData( "redman" );
};
$.fn.redman = function() {
return this.each( function() {
// Instantiate a new Redman, storing the instance in the element's data cache
$.data( this, "redman", new Redman( this ) );
});
};
})( jQuery );
$( function() {
var r = $( "#foo" ).redman().data( "redman" );
setTimeout( function() { r.destroy(); }, 2000 );
});</pre>
<p>Works, but is not <a href="http://benalman.com/talks/idiomatic-jquery.html#13">idiomatic</a>,
nor does it abstract common plugin tasks</p>
</section>
</div>
<div class="slide">
<header>
<h1>The Manufacturing Business</h1>
</header>
<section class="text smallerCode">
<figure class="floaty-figure ffright ui-widget-content">
<img src="images/introduceafactory.jpg"/>
<figcaption>
A factory is for making things.
</figcaption>
</figure>
<p>The <a href="http://gsraj.tripod.com/design/creational/factory/factory.html">factory pattern</a> is a way to
generate different objects with a common interface.</p>
<p>The <strong>jQuery UI Widget Factory</strong> is simply a function (<code>$.widget</code>) that takes a string name and an object
as arguments and creates a jQuery plugin and a "Class" to encapsulate its functionality.</p>
<pre class="brush: js; toolbar: false;">
$.widget( "aj.filterable" , { /* snip */ });
</pre>
<p>Powers all the jQuery UI widgets, but it can stand alone</p>
</section>
</div>
<div class="slide">
<header>
<h1>SWAG</h1>
</header>
<section class="text muchSmallerCode">
<p>The widget factory provides a number of plugin conveniences</p>
<ul class="lots-of-bullets">
<li>Creates your namespace, if necessary (<code>jQuery.aj</code>)</li>
<li>Encapsulated class (<code>jQuery.aj.filterable.prototype</code>)</li>
<li>Extends jQuery prototype (<code>jQuery.fn.filterable</code>)</li>
<li>Merges defaults with user-supplied options</li>
<li>Stores plugin instance in <code>.data()</code></li>
<li>Methods accessible via string - <code>plugin( "foo" )</code> - or directly - <code>.foo()</code></li>
<li>Prevents against multiple instantiation</li>
<li>Evented structure for handling setup, teardown, option changes</li>
<li>Easily expose callbacks: <code>._trigger( "event" )</code></li>
<li>Sane default scoping (What is <code>this</code>?</code>)</li>
<li>Free pseudoselector! <code>$( ":aj-filterable" )</code></li>
<li>Inheritance! Widgets can extend from other widgets
<pre class="brush: js; toolbar: false;">
$.widget( "aj.electricAccordion", $.ui.accordion, { /* snip */ });
</pre>
</li>
</ul>
</section>
</div>
<div class="slide">
<header>
<h1>Let's Rotate These Tires</h1>
<section>
<p class="quoteThing ui-widget-header">Building a simple filtering widget in almost no time flat</p>
</section>
</header>
</div>
<div class="slide">
<header>
<h1>How do I use this thing?</h1>
</header>
<section class="text muchMuchSmallerCode" style="margin-top:100px">
<pre class="brush: js; toolbar: false;">
( function( $ ) {
// The jQuery.aj namespace will automatically be created if it doesn't exist
$.widget( "aj.filterable", {
// These options will be used as defaults
options: { className : "" },
_create: function() {
// The _create method is where you set up the widget
},
// Keep various pieces of logic in separate methods
filter: function() {
// Methods without an underscore are "public"
},
_hover: function() {
// Methods with an underscore are "private"
},
_setOption: function( key, value ) {
// Use the _setOption method to respond to changes to options
switch( key ) {
case "length":
break;
}
// and call the parent function too!
return this._superApply( arguments );
}
_destroy: function() {
// Use the destroy method to reverse everything your plugin has applied
return this._super();
},
});
})( jQuery );
</pre>
</section>
</div>
<div class="slide">
<header>
<h1>I Can See Your Privates</h1>
</header>
<section class="text smallerCode">
<p>Methods prefixed with an underscore are, <em>by convention only</em>, private.</p>
<ul>
<li>These methods cannot be accessed via a plugin's public API:</li>
<li><code>$( "#foo" ).filterable( "_hover" )</code> will not work</li>
<li>They are, however, accessible directly from the widget instance:</li>
<li><code>$( "#foo" ).data( "aj-filterable" )._hover()</code> will
<ul>
<li><strong>(1.9)</strong> <code>$( "#foo" ).data( "filterable" )</code> widget name.</li>
<li><strong>(1.10)</strong> <code>$( "#foo" ).data( "aj-filterable" )</code> namespace-widget name</li>
<li><strong>(1.11)</strong> <code>$( "#foo" ).filterable( "instance" )</code> no more confusion</li>
</ul>
</li>
<li>They are also accessible on the widget's prototype</li>
<li><code style="font-size:90%;">$.aj.filterable.prototype._hover = function() { /* snip */ };</code>
</ul>
</section>
</div>
<div class="slide">
<header>
<h1>Clothing Optional</h1>
</header>
<section class="text smallerCode">
<p>
Provide an object at the <code>options</code> key to provide defaults.</br>
</p>
<pre class="brush: js; toolbar: false;">
// Parameters that must be initialised,
// but are optional for the plugin user
options: {
delay: 250,
className: ""
}
</pre>
<p>This is akin to a familiar step from basic jQuery plugin authoring</p>
<pre class="brush: js; toolbar: false;">
$.fn.foo = function( opts ) {
var defaults = { bar: "baz" },
options = $.extend( {}, defaults, opts );
};
</pre>
</section>
</div>
<div class="slide">
<header>
<h1>In The Beginning...</h1>
</header>
<section class="text muchMuchSmallerCode">
<p>
Use the <code>_create</code> method to set up your widget.
It is called the first time that the plugin is invoked on an element.
</p>
<pre class="brush: js; toolbar: false;">
_create: function() {
// this.element -- a jQuery object of the element the widget was invoked on.
// this.options -- the merged options hash
// Cache references to collections the widget needs to access regularly
this.filterElems = this.element.children()
.addClass( "ui-widget-content " + this.options.className );
this.filterInput = $( "<input type='text'>" )
.insertBefore( this.element )
.wrap( "<div class='ui-widget-header " + this.options.className + "'>" );
// bind events on elements:
this._on( this.filterElems, {
mouseenter: "_hover",
mouseleave: "_hover"
});
// toggles ui-state-focus for you:
this._focusable( this.filterInput );
// _hoverable works for ui-state-hover, but we will do something slighty different in our hover
this._on( this.filterInput, {
"keyup": "filter"
});
this.timeout = false;
}</pre>
</section>
</div>
<div class="slide">
<header>
<h1><code>_trigger( "finger" )</code></h1>
</header>
<section class="text muchSmallerCode">
<p>
The <code>_trigger</code> method fires an event the plugin user can...use.
</p>
<pre class="brush: js; toolbar: false;">
// Signature
this._trigger( "callbackName", [eventObject], [uiObject] )
// Example
this._trigger( "hover", e /* e.type == "mouseenter" */, { hovered: $( e.target )});
// The user can subscribe using an option during initalization
$( "#elem" ).filterable({ hover: function( event, ui ) { } });
// Or with traditional event binding/delegation
$( "#elem" ).bind( "filterablehover" , function( event, ui ) { } );
</pre>
<dl>
<dt><code>callbackName</code></dt>
<dd>The name of the event you want to dispatch</dd>
<dt><code>eventObject</code> (Optional)</dt>
<dd>An event object (or null). <code>_trigger</code> wraps this object and stores it in <code>event.originalEvent</code></dd>
<dd>The user receives an object with event.type == <code>this.widgetEventPrefix + "eventname"</code></dd>
<dt><code>uiObject</code> (Optional)</dt>
<dd>An object containing useful properties the user may need to access.</dd>
<dd><strong>Protip:</strong> Use a method like <code>._ui</code> to generate objects with a consistent schema.</dd>
</dl>
</section>
</div>
<div class="slide">
<header>
<h1>Getting Organised</h1>
</header>
<section class="text muchMuchSmallerCode">
<p>Store distinct pieces of functionality as separate methods.<br/>
If the user may need to invoke a function programmatically, expose it!</p>
<pre class="brush: js; toolbar: false;">
filter: function( event ) {
// Debounce the keyup event with a timeout, using the specified delay
clearTimeout( this.timeout );
// like setTimeout, only better!
this.timeout = this._delay( function() {
var re = new RegExp( this.filterInput.val(), "i" ),
visible = this.filterElems.filter( function() {
var $t = $( this ), matches = re.test( $t.text() );
// Leverage the CSS Framework to handle visual state changes
$t.toggleClass( "ui-helper-hidden", !matches );
return matches;
});
// Trigger a callback so the user can respond to filtering being complete
// Supply an object of useful parameters with the second argument to _trigger
this._trigger( "filtered", event, {
visible: visible
});
}, this.options.delay );
},
_hover: function( event ) {
$( event.target ).toggleClass( "ui-state-active", e.type === "mouseenter" );
this._trigger( "hover", event, {
hovered: $( e.target )
});
},
</pre>
<p></p>
</section>
</div>
<div class="slide">
<header>
<h1>Ch-ch-ch-ch-changes</h1>
</header>
<section class="text muchMuchSmallerCode" style="line-height:30px;">
<p>Plugin users can change options after a plugin has been invoked using
<code>$("elem").filterable("option","className","newName");</code>.</p>
<p>If modifiying a particular option requires an immediate state change, use the <code>_setOption</code>
method to listen for the change and act on it.</p>
<pre class="brush: js; toolbar: false; highlight:[3,4]">
_setOption: function( key, value ) {
var oldValue = this.options[ key ];
// Check for a particular option being set
if ( key === "className" ) {
// Gather all the elements we applied the className to
this.filterInput.parent().add( this.filterElems )
// Wwitch the new className in for the old
.toggleClass( oldValue + " " + value );
}
// Call the base _setOption method
this._superApply( argruments );
// The widget factory doesn't fire an callback for options changes by default
// In order to allow the user to respond, fire our own callback
this._trigger( "setOption", null, {
option: key,
original: oldValue,
current: value
});
},
</pre>
</section>
</div>
<div class="slide">
<header>
<h1>Control-Z</h1>
</header>
<section class="text muchSmallerCode">
<p>
Use the <code>destroy</code> method to revert an element back to its state from before plugin invocation.
</p>
<pre class="brush: js; toolbar: false;">
_destroy: function() {
// Remove any new elements that you created
this.filterInput.parent().remove();
// Remove any classes, including CSS framework classes, that you applied
this.filterElems.removeClass( "ui-widget-content ui-helper-hidden ui-state-active " + this.options.className );
this._super();
}
</pre>
</section>
</div>
<div class="slide">
<header>
<h1>A Cheesy Example</h1>
</header>
<section class="text muchMuchSmallerCode" style="margin-top:100px">
<pre class="brush: html; toolbar: false;">
<ul id="cheeses">
<li data-price="17.99">Gruyere</li>
<li data-price="16.99">Comte</li>
<li data-price="4.99">Provolone</li>
<li data-price="8.99">Cheddar</li>
<li data-price="18.99">Parmigiano Reggiano</li>
<li data-price=".99">Government</li>
</ul>
<div id="register">
One pound of each would cost $<span id="total"></span>
</div>
</pre>
<div style="font-size:70%">
<button type="button" id="activation">Toggle Filterable</button>
<ul id="cheeses">
<li data-price="17.99">Gruyere</li>
<li data-price="16.99">Comte</li>
<li data-price="4.99">Provolone</li>
<li data-price="8.99">Cheddar</li>
<li data-price="18.99">Parmigiano Reggiano</li>
<li data-price=".99">Government</li>
</ul>
<div id="register">
One pound of each would cost $<span id="total"></span>
</div>
</div>
</section>
</div>
<div class="slide">
<header>
<h1>State + Events = Extensibility</h1>
</header>
<section class="text muchMuchSmallerCode">
<p>A good widget provides a solid base with callbacks for customisation.</p>
<pre class="brush: js; toolbar: false;">
var total = $("#total"), cheeses = $("#cheeses"), register = $("#register"), price = $("<span>"),
activation = $("#activation").button({icons:{primary:"ui-icon-search"}});
activation.click(function() {
if ( cheeses.is(":aj-filterable") ) {
return cheeses.filterable("destroy");
}
cheeses.filterable({
className: "cheese",
create: function() { register.addClass("ui-widget-header cheese").show(); },
filtered: function(e, ui) {
var t = 0;
ui.visible.each(function() { t = t + parseFloat( $(this).data("price") ); });
total.text( t.toFixed( 2 ) );
},
setOption: function(e, ui) {
ui.option === "className" && register.toggleClass([ui.original, ui.current].join(" "));
},
hover: function(e, ui) {
if (e.originalEvent.type === "mouseenter") {
price.text(" - " + ui.hovered.data("price") + " per lb").appendTo(ui.hovered);
} else {
price.detach();
}
}
}).on("filterabledestroy", function(e,ui) {
register.removeClass("ui-widget-header "+ui.options.className).hide();
}).filterable("filter");
setTimeout(function() { cheeses.filterable("option", "className", "cheesePlease"); },3000);
});
</pre>
</section>
</div>
<div class="slide">
<header>
<h1>It's <code>.widget()</code> all the way down</h1>
</header>
<section class="text smallerCode">
<ul>
<li>In 1.9, a widget can "inherit" from itself</li>
<li>This is the ideal way to extend widgets</li>
</ul>
<pre class="brush: js; toolbar: false;">
// An incredibly contrived example
$.widget( "ui.dialog", $.ui.dialog, {
close: function() {
if ( confirm( "Is it closing time?" ) ) {
this._super();
}
}
});</pre>
</section>
</div>
<div class="slide">
<header>
<h1>I've got a <code>bridge</code> to sell you</h1>
</header>
<section class="text smallerCode">
<ul>
<li><a href="https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.widget.js#L96"><code>$.widget.bridge</code></a> is the mechanism that actually creates the plugin</li>
<li>Set/change which widget prototype exists on <code>jQuery.fn</code></li>
</ul>
<pre class="brush: js; toolbar: false;">
// Create a brand new dialog widget from scratch
$.widget( "my.awesomeDialog", {/* snip */});
// Use the bridge to assign it to jQuery.fn.dialog
$.widget.bridge( "dialog", $.my.awesomeDialog );
</pre>
</section>
</div>
<div class="slide">
<header>
<h1>U and I can be friends</h1>
</header>
<section class="text smallerCode">
<h2>But not roommates</h2>
<ul>
<li>The <code>ui</code> namespace is reserved for official jQuery UI plugins</li>
<li>Just because you're using the widget factory doesn't mean you have to use <code>ui</code></li>
<li>We'd kinda prefer if you didn't :)</li>
</ul>
</section>
</div>
<div class="slide">
<header>
<h1>More Resources</h1>
</header>
<section class="text">
<ul>
<li><a href="http://learn.jquery.com/jquery-ui/widget-factory/">Learning Center: Widget Factory</a></li>
<li><a href="http://api.jqueryui.com/jQuery.widget/">jQuery UI API: Widget Factory</a></li>
<li><a href="http://learn.jquery.com/jquery-ui/theming/api/">jQuery UI CSS Framework</a></li>
<li><a href="http://www.erichynds.com/jquery/tips-for-developing-jquery-ui-widgets/">Tips for Developing UI Widgets</a></li>
<li><a href="http://net.tutsplus.com/tutorials/javascript-ajax/coding-your-first-jquery-ui-plugin/">Coding Your First jQuery UI Plugin</a></li>
<li><a href="http://wiki.jqueryui.com/">jQuery UI Planning Wiki</a></li>
<li><a href="http://github.com/ajpiano.com/widgetfactory">These slides and our filterable plugin on GitHub</a></li>
</ul>
</section>
</div>
<div class="slide">
<header>
<h1>No problem, enjoy</h1>
</header>
<section class="text">
<ul>
<li><strong>adam j. sontag</strong></li>
<li>ajpiano at ajpiano dot com</li>
<li><a href="http://twitter.com/ajpiano">@ajpiano</a></li>
<li>I'm ajpiano on freenode IRC (#jquery) and everywhere</li>
<li><a href="http://ajpiano.com/">my blog</a></li>
<li><a href="http://yayquery.com/">yayQuery</a></li>
</ul>
</section>
</div>
<div class="slide">
<header>
<h1>Revisionist History</h1>
</header>
<section class="text">
<ul>
<li><strong>corey frang</strong></li>
<li>gnarf37 at gmail dot com</li>
<li><a href="http://twitter.com/gnarf37">@gnarf37</a></li>
<li>I'm gnarf on freenode IRC (#jquery) and everywhere</li>
<li><a href="http://gnarf.net/">my blog</a></li>
</ul>
</section>
</div>
</div>
<!-- slides -->
</div> <!-- presentation -->
<script>
(function() {
var doc = document;
var disableBuilds = true;
var ctr = 0;
var spaces = /\s+/, a1 = [''];
var toArray = function(list) {
return Array.prototype.slice.call(list || [], 0);
};
var byId = function(id) {
if (typeof id == 'string') { return doc.getElementById(id); }
return id;
};
var query = function(query, root) {
if (!query) { return []; }
if (typeof query != 'string') { return toArray(query); }
if (typeof root == 'string') {
root = byId(root);
if(!root){ return []; }
}
root = root || document;
var rootIsDoc = (root.nodeType == 9);
var doc = rootIsDoc ? root : (root.ownerDocument || document);
// rewrite the query to be ID rooted
if (!rootIsDoc || ('>~+'.indexOf(query.charAt(0)) >= 0)) {
root.id = root.id || ('qUnique' + (ctr++));
query = '#' + root.id + ' ' + query;
}
// don't choke on something like ".yada.yada >"
if ('>~+'.indexOf(query.slice(-1)) >= 0) { query += ' *'; }
return toArray(doc.querySelectorAll(query));
};
var strToArray = function(s) {
if (typeof s == 'string' || s instanceof String) {
if (s.indexOf(' ') < 0) {
a1[0] = s;
return a1;
} else {
return s.split(spaces);
}
}
return s;
};
var addClass = function(node, classStr) {
classStr = strToArray(classStr);
var cls = ' ' + node.className + ' ';
for (var i = 0, len = classStr.length, c; i < len; ++i) {
c = classStr[i];
if (c && cls.indexOf(' ' + c + ' ') < 0) {
cls += c + ' ';
}
}
node.className = cls.trim();
};
var removeClass = function(node, classStr) {
var cls;
if (classStr !== undefined) {
classStr = strToArray(classStr);
cls = ' ' + node.className + ' ';
for (var i = 0, len = classStr.length; i < len; ++i) {
cls = cls.replace(' ' + classStr[i] + ' ', ' ');
}
cls = cls.trim();
} else {
cls = '';
}
if (node.className != cls) {
node.className = cls;
}
};
var toggleClass = function(node, classStr) {
var cls = ' ' + node.className + ' ';
if (cls.indexOf(' ' + classStr.trim() + ' ') >= 0) {
removeClass(node, classStr);
} else {
addClass(node, classStr);
}
};
var ua = navigator.userAgent;
var isFF = parseFloat(ua.split('Firefox/')[1]) || undefined;
var isWK = parseFloat(ua.split('WebKit/')[1]) || undefined;
var isOpera = parseFloat(ua.split('Opera/')[1]) || undefined;
var canTransition = (function() {
var ver = parseFloat(ua.split('Version/')[1]) || undefined;
// test to determine if this browser can handle CSS transitions.
var cachedCanTransition =
(isWK || (isFF && isFF > 3.6 ) || (isOpera && ver >= 10.5));
return function() { return cachedCanTransition; }
})();
//
// Slide class
//
var Slide = function(node, idx) {
this._node = node;
if (idx >= 0) {
this._count = idx + 1;
}
if (this._node) {
addClass(this._node, 'slide distant-slide');
}
this._makeCounter();
this._makeBuildList();
};
Slide.prototype = {
_node: null,
_count: 0,
_buildList: [],
_visited: false,
_currentState: '',
_states: [ 'distant-slide', 'far-past',
'past', 'current', 'future',
'far-future', 'distant-slide' ],
setState: function(state) {
if (typeof state != 'string') {
state = this._states[state];
}
if (state == 'current' && !this._visited) {
this._visited = true;
this._makeBuildList();
}
removeClass(this._node, this._states);
addClass(this._node, state);
this._currentState = state;
// delay first auto run. Really wish this were in CSS.
/*
this._runAutos();
*/
var _t = this;
setTimeout(function(){ _t._runAutos(); } , 400);
},
_makeCounter: function() {
if(!this._count || !this._node) { return; }
var c = doc.createElement('span');
c.innerHTML = this._count;
c.className = 'counter';
this._node.appendChild(c);
},
_makeBuildList: function() {
this._buildList = [];
if (disableBuilds) { return; }
if (this._node) {
this._buildList = query('[data-build] > *', this._node);
}
this._buildList.forEach(function(el) {
addClass(el, 'to-build');
});
},
_runAutos: function() {
if (this._currentState != 'current') {
return;
}
// find the next auto, slice it out of the list, and run it
var idx = -1;
this._buildList.some(function(n, i) {
if (n.hasAttribute('data-auto')) {
idx = i;
return true;
}
return false;
});
if (idx >= 0) {
var elem = this._buildList.splice(idx, 1)[0];
var transitionEnd = isWK ? 'webkitTransitionEnd' : (isFF ? 'mozTransitionEnd' : 'oTransitionEnd');
var _t = this;
if (canTransition()) {
var l = function(evt) {
elem.parentNode.removeEventListener(transitionEnd, l, false);
_t._runAutos();
};
elem.parentNode.addEventListener(transitionEnd, l, false);
removeClass(elem, 'to-build');
} else {
setTimeout(function() {
removeClass(elem, 'to-build');
_t._runAutos();
}, 400);
}
}
},
buildNext: function() {
if (!this._buildList.length) {
return false;
}
removeClass(this._buildList.shift(), 'to-build');
return true;
},
};
//
// SlideShow class
//
var SlideShow = function(slides) {
this._slides = (slides || []).map(function(el, idx) {
return new Slide(el, idx);
});
var h = window.location.hash;
try {
this.current = parseInt(h.split('#slide')[1], 10);
} catch (e) { /* squeltch */ }
this.current = isNaN(this.current) ? 1 : this.current;
var _t = this;
doc.addEventListener('keydown',
function(e) { _t.handleKeys(e); }, false);
doc.addEventListener('mousewheel',
function(e) { _t.handleWheel(e); }, false);
doc.addEventListener('DOMMouseScroll',
function(e) { _t.handleWheel(e); }, false);
doc.addEventListener('touchstart',
function(e) { _t.handleTouchStart(e); }, false);
doc.addEventListener('touchend',
function(e) { _t.handleTouchEnd(e); }, false);
window.addEventListener('popstate',
function(e) { if (e.state) { _t.go(e.state); } }, false);
this._update();
};
SlideShow.prototype = {
_slides: [],
_update: function(dontPush) {
document.querySelector('#presentation-counter').innerText = this.current;
if (history.pushState) {
if (!dontPush) {
history.replaceState(this.current, 'Slide ' + this.current, '#slide' + this.current);
}
} else {
window.location.hash = 'slide' + this.current;
}
for (var x = this.current-1; x < this.current + 7; x++) {
if (this._slides[x-4]) {
this._slides[x-4].setState(Math.max(0, x-this.current));
}
}
},
current: 0,
next: function() {
if (!this._slides[this.current-1].buildNext()) {
this.current = Math.min(this.current + 1, this._slides.length);
this._update();
}
},
prev: function() {
this.current = Math.max(this.current-1, 1);
this._update();
},
go: function(num) {
this.current = num;
this._update(true);
},
_notesOn: false,
showNotes: function() {
var isOn = this._notesOn = !this._notesOn;
query('.notes').forEach(function(el) {
el.style.display = (notesOn) ? 'block' : 'none';
});
},
switch3D: function() {
toggleClass(document.body, 'three-d');
},
handleWheel: function(e) {
var delta = 0;
if (e.wheelDelta) {
delta = e.wheelDelta/120;
if (isOpera) {
delta = -delta;
}
} else if (e.detail) {
delta = -e.detail/3;
}
if (delta > 0 ) {
this.prev();
return;
}
if (delta < 0 ) {
this.next();
return;
}
},
handleKeys: function(e) {
if (/^(input|textarea)$/i.test(e.target.nodeName)) return;
switch (e.keyCode) {
case 37: // left arrow
this.prev(); break;
case 39: // right arrow
case 32: // space
this.next(); break;
case 50: // 2
this.showNotes(); break;
case 51: // 3
this.switch3D(); break;
}
},
_touchStartX: 0,
handleTouchStart: function(e) {
this._touchStartX = e.touches[0].pageX;
},
handleTouchEnd: function(e) {
var delta = this._touchStartX - e.changedTouches[0].pageX;
var SWIPE_SIZE = 150;
if (delta > SWIPE_SIZE) {
this.next();
} else if (delta< -SWIPE_SIZE) {
this.prev();
}
},
};
// Initialize
var slideshow = new SlideShow(query('.slide'));
})();
</script>
<!--[if lt IE 9]>
<script
src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js">
</script>
<script>CFInstall.check({ mode: "overlay" });</script>
<![endif]-->
<script src="js/jquery-1.9.0.js"></script>
<script>
/*
Syntax Highlighter: Dual licensed under the MIT and GPL licenses.
Syntax Highlighter shBrushJScript: Dual licensed under the MIT and GPL licenses.