forked from plone/mockup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
2448 lines (2290 loc) · 118 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>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Plone Mockup(s)</title>
<style type="text/less">@import "less/docs.less";@isBrowser: true;</style>
<script src="node_modules/grunt-contrib-less/node_modules/less/dist/less-1.4.1.js"></script>
<script src="bower_components/jquery/jquery.js"></script>
<script src="bower_components/underscore/underscore.js"></script>
<script src="bower_components/requirejs/require.js"></script>
<script src="js/config.js"></script>
<script>
// helper utilities
var pages = [];
var patterns = [];
addPattern = function(page) {
patterns.push(page);
};
addPage = function(page) {
pages.push(page);
};
//
require([
'mockup-docsapp'
], function(DocsApp) {
DocsApp.patterns.add(patterns);
DocsApp.pages.add(pages);
DocsApp.initialize();
});
</script>
<script type="text/x-ajax-respond" id="something-html">
<html>
<head></head>
<body>
<div id="content">
<div class="pull-right">
Button that triggers "hide" event ->
<a class="btn" onclick="$(this).trigger('destroy.modal.patterns')">Close</a>
</div>
<h1>Content from AJAX</h1>
<p>Ah, it is a rock, though. Should beat everything. Gob: There's not a lot
of logic to it. A flower in my garden, a mystery in my panties. [climbing
under trampoline] This shall keep me safe from the hot Mexican sun. This is
not me encouraging you to go here and write a review. No. So, what do you
say? We got a basket full of father-son fun here. What\'s Kama Sutra oil?
Maybe it's not for us.</p>
</body>
</html>
</script>
<script type="text/x-ajax-respond" id="select2-json">
{
"more": "false",
"results": [
{"id": "Red", "text": "Red"},
{"id": "Blue", "text": "Blue"},
{"id": "Green", "text": "Green"}
]
}
</script>
<!-- TEMPLATES -->
<script type="text/template" id="tpl_page">
<div class="page-header">
<h1><%= title %> <small><%= description %></small></h1>
</div>
<div><%= content %></div>
</script>
<script type="text/template" id="tpl_pattern">
<ul class="breadcrumb">
<li><a href="#">Home</a> <span class="divider">/</span></li>
<li><a href="#patterns">Patterns</a> <span class="divider">/</span></li>
<li class="active"><%= title %></li>
</ul>
<div class="page-header">
<h1><%= title %> <small><%= description %></small></h1>
</div>
<div><%= content %></div>
<div class="docs-examples">
<h2>Examples</h2>
<%= examples %>
</div>
<% if (attributes.length > 0) { %>
<div class="docs-attributes" id="data-options">
<h2>Data Options</h2>
</div>
<% } %>
</script>
<script type="text/template" id="tpl_attribute">
<% if (type === 'Object' && attrs !== '') { %>
<td colspan="4" class="docs-attrs">
<%= attribute %> {
<% if (description !== '') { %> <p><%= description %></p> <% } %>
<%= attrs %>
}
</td>
<% } else { %>
<td class="attr-name"><%= attribute %></td>
<td class="attr-type"><%= type %></td>
<td class="attr-default"><%= defaultValue %></td>
<td class="attr-description"><%= description %></td>
<% } %>
</script>
<script type="text/template" id="tpl_attributes">
<thead>
<tr>
<th>Option</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
</tbody>
</script>
<script type="text/template" id="tpl_example">
<% if (title !== '') { %>
<h3><%= title %></h3>
<% } %>
<div>
<%= html %>
</div>
<div>
<pre class="brush: html;toolbar: false;"><%= pre %></pre>
</div>
</script>
<script type="text/template" id="tpl_patterns_list">
<div class="page-header">
<h1>Patterns <small>The complete list</small></h1>
</div>
</script>
<script type="text/template" id="tpl_patterns_list_item">
<div class="media-body">
<h4><a href="#patterns/<%= id %>" title="<%= title %>"><%= title %></a></h4>
<%= description %>
</div>
</script>
<!-- ** DOCS CONTENT ** -->
<!-- * Reused * -->
<script>
var backdropAttributes = [
{attribute: 'zIndex', type: 'String', description: 'Value for <code>z-index</code> to be applied to backdrop.'},
{attribute: 'opacity', type: 'String', description: 'This property allows you to control the transparency or opacity of the backdrop.'},
{attribute: 'className', type: 'String', description: 'Set the CSS class applied to the backdrop. Useful if you want to apply your own styling to the backdrop.'},
{attribute: 'classActiveName', type: 'String', description: 'Set the CSS class which is applied when the backdrop is made active.'},
{attribute: 'closeOnEsc', type: 'Boolean', description: 'Whether or not to close the backdrop (and modal) when the "Escape" key is pressed.'},
{attribute: 'closeOnClick', type: 'Boolean', description: 'Whether or not to close the backdrop (and modal) when the backdrop is clicked.'},
];
</script>
<script>
addPage({
id: 'getting-started',
title: 'Getting Started',
requiredPatterns: ['autotoc']
});
</script>
<script type="text/template" id="page_getting-started">
<style type='text/css'>
.getting-started .autotoc-nav {
background-color: white;
}
</style>
<div class='getting-started pat-autotoc' data-pat-autotoc="levels:h2,h3,h4">
<h2>Quick-start </h2>
<pre>
Install Git
Install Node (v0.10.20) / NPM
$ git clone git://github.com/plone/mockup.git
$ cd mockup
$ make bootstrap</pre>
<p>
And your environment is ready to start working on testable, modular, JavaScript!
</p>
<p>
If you're interested in developing in mockup, then seeing its use
directly in Plone, check out the <a href='https://github.com/plone/buildout.deco'>buildout.deco</a>
project on GitHub.
</p>
<h2>Slower-start</h2>
<h3>Step 1: Get the tools</h3>
<p>
Download and install the latest versions of <a href='http://git-scm.org' title='git'>git</a> and
<a href='http://www.nodejs.org/' title='node and npm'>Node/<abbr title="Node Package Manager">NPM</abbr></a>.
</p>
<p>
Also make certain your system supports the <code>make</code> command.
Right now development of this project is being done primarily on Linux
and OS X, so setting up the tooling on MS Windows might be an
adventure for you to explore -- though, all of the tools used have equivalent
versions for that platform, so with a little effort, it should work!
</p>
<h3>Step 2: Checkout the Mockup project from GitHub</h3>
<p>
This will give you a starting point, and a lot of example code. It's used
to build <em>bundles</em> which are then added to various Plone products.
You do not need to develop code for the existing Plone products when you
use the Mockup project.
</p>
<pre>
git clone git://github.com/plone/mockup.git</pre>
<h3>Step 3: Bootstrap the environment</h3>
<p>
Run the following commands:
</p>
<pre>
cd mockup
make bootstrap</pre>
<p>
This will use Node/NPM to download and install all the requirements for
building and bundling, as well as all the external libraries needed to
build the patterns developed within the framework of the mockup project.
</p>
<h3>Step 4: Get hacking!</h3>
<h4>Mockup Project Structure</h4>
<p class='alert alert-info'>
<strong>NOTE</strong>: The project is under heavy development, so expect
things to move around a bit.
</p>
<ul>
<li><strong>build/</strong> All combined, optimized, and minimized JavaScript code, as well as compiled less and media are copied and placed here</li>
<li><strong>docs/</strong> Documentation files built with <code>make docs</code></li>
<li><strong>js/</strong> This directory contains all of the modularized JavaScript code</li>
<li><strong>js/config.js</strong> This file contains the RequireJS configuration</li>
<li><strong>js/fakeserver.js</strong> This file is useful for development -- it contains the code for setting up fake responses to XHR</li>
<li><strong>js/bundles</strong> This is where a bundle is defined -- it is a set of requirements and code that provide the features being packaged into a Plone product</li>
<li><strong>js/patterns</strong> This is a directory that contains all individual, encapsulated patterns (i.e. widgets/JavaScript)</li>
<li><strong>less/</strong> This directory contains all the <a href='http://lesscss.org/'>less</a> code for all the patterns and bundles</li>
<li><strong>lib/</strong> This directory contains external libraries not necessarily found in the bower repositories</li>
<li><strong>tests/</strong> This directory contains all tests for patterns and bundles, including general setup and configuration code</li>
<li><strong>Gruntfile.js</strong> This file contains the directives for compiling less, and combining/optimizing/minimizing JavaScript for the defined bundles</li>
<li><strong>index.html</strong> This is the main source of documentation for the mockup project.</li>
<li><strong>Makefile</strong> This is the Makefile used to define what tasks should run when you want to build a bundle, or bootstrap the environment</li>
</ul>
<h4>What's a Pattern? What Are Bundles? How do they relate?</h4>
<p>
<em>Patterns</em> are units of JavaScript, defined by a RequireJS/AMD style module.
Patterns may require other patterns to operate, and may require third
party libraries. Think of patterns as a module -- encapsulated and
separate, and providing a widget or tool to use by other patterns or
in html.
</p>
<p>
<em>Bundles</em> are defined similar to <em>Patterns</em> -- they are
encapsulated bits of JavaScript that define requirements for a bundle,
and have some extra code in them that's useful for integrating the
required patterns into Plone products.
</p>
<p>
So, the end result is that a front-end developer might spend their time
creating patterns, while a Plone developer might create a bundle and
integrate it into a Plone product.
</p>
<p>
<em>plone.app.widgets</em> is a good example of a bundle. The
<strong>js/bundles/widgets.js</strong> file contains a RequireJS module
that defines all the requirements for plone.app.widgets, and
adds some specific code to make the requirements work nicely in the
<em>plone.app.widgets</em> Plone module.
</p>
<h4>What's up with this documentation?</h4>
<p>
Most of the documentation found outside of code comments is in the
single <em>index.html</em> file. Take a look at it, and if you want to
contribute, hack away!
</p>
<p>
To update the pages
at <a href="http://plone.github.io/mockup/dev/">http://plone.github.io/mockup/dev/</a>,
run <code>$ make docs</code>, then switch into the <em>docs/</em>
directory. If you then do <code>$ git branch</code> you'll notice that
the <em>docs/</em> directory is another clone of the mockup repo,
checked out on the <em>gh-pages</em> branch. Yes, this site
is <a href="http://pages.github.com/">Github magic</a>. Commit the
changes, then <code>$ git push origin gh-pages</code> to update the
site.
</p>
<p>
Why is it done this way? It's convenient for the time being.
</p>
<h4>How are patterns created that DON'T belong to plone.app.*?</h4>
<p>
Check out some of the other patterns in <strong>js/patterns/</strong>,
then check out the bundle code in <strong>js/bundles</strong>. Once
you have a bundle, and maybe some patterns created for your own product,
you'll want to add some configuration directives to the <strong>Gruntfile.js</strong>
file. Then, you can run <code>$ make</code> to build your bundle into
the <strong>build/</strong> directory, and from there, copy over the
releasable code into your Plone product.
</p>
<h4>Tutorials?</h4>
<p>
Currently there are no tutorials for using this project, but they will
be forth coming -- <em>Especially</em> if you decide to contribute to the
project!
</p>
<p>
For now, the best way to learn is to dig into the patterns, bundles,
and less code, then join the <code>#plone</code> IRC channel on
freenode, and start asking questions!
</p>
<h3>Step 5: Bundling</h3>
<p>To build bundles:</p>
<pre>make</pre>
<h3>Step 6: Testing</h3>
<h4>
Right now tests are
<a href="https://travis-ci.org/plone/mockup"><img src="https://api.travis-ci.org/plone/mockup.png?branch=master" alt="Build Status" /></a>
and coverage is
<a href='https://coveralls.io/r/plone/mockup?branch=master'><img src='https://coveralls.io/repos/plone/mockup/badge.png?branch=master' alt='Coverage Status' /></a> .
</h4>
<h4>Running tests</h4>
<p>And you can run tests with:</p>
<pre>make test</pre>
<p>This will start a continuous process that will rerun the tests when you change any of
the js files.</p>
<p>If you have Chrome installed you can alternatively run your tests with:</p>
<pre>make test-chrome</pre>
<p>If you want to just run the tests for the pattern you are working on you can run tests with:</p>
<pre>make test pattern=foobar</pre>
<p>Or:</p>
<pre>make test-chrome pattern=foobar</pre>
<p>These will run only the tests in patterns-foobar-test.js</p>
<h4>Adding new tests</h4>
<p>To add new tests, you can add them into the <tt>tests</tt> directory.
They will automatically be picked up by the test runner if they are named
with a suffix of:</p>
<pre>-test.js</pre>
<p>For example, to add a new test for the <tt>foobar</tt> pattern,
you should name your test file like so:</p>
<pre>pattern-foobar-test.js</pre>
</p>
<h4>Debugging tests</h4>
<p>While the tests are running you can connect debug console on
<a href="http://localhost:9876/">http://localhost:9876</a></p>
<p>if you add the <strong>"debugger;"</strong> statement into your code or test while your browsers JS window is
open (for example right-click > inspect element > sources) then the debugger will be activated
and you can step through the code.</p>
<h4>Test coverage</h4>
<p>In the <strong>./coverage</strong> directory find the index.html file under the folder for the browser you are using. This will tell you
the current coverage from the last test run</p>
<h3>Step 7: Releasing/Passing bundles on to Plone developers</h3>
<p>
This is the part that developers in the Plone community are currently
familiar with, and the step that purely front-end developers will have to
pass off their products. This step is all about taking the bundled
JavaScript and adding it to Plone products in the ways JavaScript has
always been added.
</p>
</div>
</script>
<script>
addPage({
id: 'about',
title: 'About the Mockup Project',
requiredPatterns: ['autotoc']
});
</script>
<script type='text/template' id='page_about'>
<style type='text/css'>
.autotoc-nav {
width: 100%;
float: none;
}
.about h2 {
font-size: 1.5em;
}
</style>
<div class='alert alert-block'>
<h3>
**WORKING DRAFT** Please Contribute!
</h3>
<p>
Things are almost guaranteed to
be misspelled, grammatically incorrect, missing, wrong and misleading.
Please help to improve it!
</p>
</div>
<div class='about pat-autotoc' data-pat-autotoc="levels:h2">
<div>
<h2>What's the purpose of this project?</h2>
<p>
The <em>mockup</em> project intends to improve the testing and modularization
story of the JavaScript used inside Plone. Further, it aims to make developing
client-side widgets and tools more approachable for developers who are
familiar with JavaScript and related tooling.
</p>
<h2>How does this project achieve better modularization of JavaScript, and what kind of benefits come from it?</h2>
<p>
Specifically, this project uses
<a href='http://requirejs.org/' target='_blank'>RequireJS</a>, a library
that adheres to the
<a href='http://en.wikipedia.org/wiki/Asynchronous_module_definition' target='_blank'>AMD</a>
concept of JavaScript modularization.
</p>
<p>
Here's a great page outlining the motivations for AMD:
<a href="http://requirejs.org/docs/whyamd.html" target="_blank">Why AMD?</a>.
</p>
<p>
Basically, it gives us a standard way to encapsulate JavaScript, and a
mechanism for combining, optimizing, and minimizing code when it's bundled.
On top of that, the overall process involved is known to developers outside
the plone community.
</p>
<p>
In practice, however, <em>RequireJS</em> itself is really only used during
the development of this project. When the code here is packaged and released,
it's combined into bundles of code, and a library called
<a href='https://github.com/jrburke/almond' target='_blank'>Almond</a> is
used in place of <em>RequireJS</em>.
</p>
<p>
<em>Almond</em> is a small shim loader for the <em>AMD</em> specification.
It completely replaces <em>RequireJS</em> for production use, providing
the interface, but not all the dynamic loading capabilities -- which
aren't needed since all the JavaScript is bundled up into single files.
<em>Almond</em> comes in at right around <strong>1kb</strong>
when all is said and done, which makes for very light overhead.
</p>
<h2>How does this project achieve better testing of JavaScript, and why should anyone care?</h2>
<p>
Currently JavaScript in Plone is <em>not tested at all</em>. So, to begin,
*any* testing is an improvement. Beyond that, it's a nightmare to upgrade
a JavaScript library -- there is no way of understanding all the
ramifications of such a change. With tests, you can know immediately
what parts of your code fail, and what parts you need to update.
</p>
<p>
Complex JavaScript becomes more reliable!
</p>
<h2>How does this project make developing widgets and front-end tooling more approachable?</h2>
<p>
There are two big things that make this project really approachable
for front-end developers: using tools commonly used for JavaScript
development, and no need to install and understand Plone.
</p>
<p>
If front-end developers already have a suite of awesome tools to use,
why bother creating custom ones that are only used in the Plone
community? Certainly there is a time and place for specialized tools,
but people who specialize in JavaScript and front-end development
can be more effective with tools they're familiar with if they don't
have to mix Plone into their process.
</p>
<p>
This also allows contribution back to the JavaScript community -- if
Plone takes advantage of the products that come out of the JavaScript
community, we can contribute back, and maybe even garner interest
in members of the JavaScript community contributing to Plone.
</p>
<p>
Second, this project only needs <em>git</em> and <em>npm/node</em>.
There is no reason to download and install Plone to start developing
widgets and front-end tooling. This makes starting development on
the front-end really fast!
</p>
<p>
The point at which Plone needs to be installed is when a bundle needs
to be integrated into a Plone product. And then, a front-end developer
might be able to just pass along their code to someone with more
Plone knowledge.
</p>
<h2>Why is this better than the status quo?</h2>
<p>
Plone has zero tests for JavaScript, people are scared to poke it, and
knowledge of Plone development is required. This means that only people
who are both knowledgable with Plone and JavaScript add to Plone's
JavaScript story, and even then tend to tread lightly.
</p>
<p>
This project aims to make developers be capable of being bold and
innovative when it comes to JavaScript.
</p>
<h2>Isn't this a lot of work and code just to hack some JavaScript?</h2>
<p>
Yes, this process does break things up a bit -- but think of the
advantages. Testable code, more potential developers, and a better
front-end workflow.
</p>
<h2>What's this projects relation to the Patternslib project?</h2>
<p>
This project draws heavy inspiration from
<a href='http://patternslib.com/' target='_blank'>PatternsLib</a>,
but does not share any code.
</p>
<h2>Can I use this in Plone right now?</h2>
<p>
Sort of. It's in heavy development, so installing the related Plone
packages are on the edge of what this project aims to become.
</p>
<p>
The Plone products to take a look at are:
<a href='https://github.com/plone/plone.app.widgets' target='_blank'>plone.app.widgets</a>
and/or
<a href='https://github.com/plone/plone.app.toolbar' target='_blank'>plone.app.toolbar</a>.
</p>
<h2>How can I contribute?</h2>
<p>
Checkout the
<a href='https://github.com/plone/mockup' target='_blank'>mockup</a>
project on github.
</p>
<h2>What's the relation to plone.app.toolbar? plone.app.widgets?</h2>
<p>
They provide Plone integration with the JavaScript developed
and tested in the <em>mockup</em> project. JavaScript is bundled,
optimized, compressed, then packaged within the products. In the package
itself, views and other integrations are made to override existing
aspects with their newer equivalents.
</p>
<h2>What about plone.app.tiles, plone.app.deco, etc?</h2>
<p>
These are a much larger topic, and need a lot of work. The core of
this initiative is found within <em>plone.app.widgets</em> and
<em>plone.app.toolbar</em>. Once these are done, tiles, deco, and more
won't be far behind.
</p>
<h2>I just want add a custom widget, but I don't want to contribute it to this project, what do I do?</h2>
<p>
Check out the <a href='#getting-started'>getting started</a> page to
learn how to get started with developing your own custom patterns!
</p>
<h2>What is a bundle?</h2>
<p>
A bundle is a combination of JavaScript, CSS, and other media that
are meant to be delivered into a specific Plone product.
</p>
<p>
For instance,
the <em>plone.app.widgets</em> product is a bundle consisting of the
combined, optimized, and minimized JavaScript, the compiled CSS (from
less), and other resourcese (such as images).
</p>
<p>
In practice, developers will only add to the widgets and toolbar
bundles if they are contributing to the <em>plone.app.widgets</em>
or <em>plone.app.toolbar</em> projects. Normally developers creating
code for new products will create new bundles for their specific
product.
</p>
</div>
</div>
</script>
<!-- ** Patterns ** -->
<!-- **** Adjust Text Size (accessibility) **** -->
<script>
addPattern({
id: 'accessibility',
title: 'Adjust Text Size',
description: 'Easily change <strong>text size</strong> on a page.',
attributes: [
{attribute: 'smallbtn', type: 'String', description: 'Selector used to activate small text on click.'},
{attribute: 'normalbtn', type: 'String', description: 'Selector used to activate normal text on click.'},
{attribute: 'largebtn', type: 'String', description: 'Selector used to activate large text on click.'}
]
});
</script>
<script type="text/template" id="page_accessibility">
</script>
<script type="text/example" class="example-accessibility" data-title="Default">
<ul id="textAdjust" class="pat-accessibility"
data-pat-accessibility="smallbtn:.decrease-text;
normalbtn:.normal-text;
largebtn:.increase-text;">
<li>
<a href="." class="decrease-text"><i class="icon-minus-sign"></i>Decrease Text Size</a>
</li>
<li>
<a href="." class="normal-text"><i class="icon-circle"></i>Normal Text Size</a>
</li>
<li>
<a href="." class="increase-text"><i class="icon-plus-sign"></i>Increase Text Size</a>
</li>
</ul>
</script>
<!-- **** Cookie Directive **** -->
<script>
addPattern({
id: 'cookiedirective',
title: 'Cookie Directive',
description: 'A pattern that <strong>checks cookies</strong> enabled and asks permission for the user to allow cookies or not.',
attributes: [
{attribute: 'allowMsg', type: 'String', defaultValue: 'Allow', description: 'Text on button used to allow cookies.'},
{attribute: 'askPermissionMsg', type: 'String', defaultValue: 'This site uses cookies to provide additional functionality, do you accept?', description: 'A message about allowing cookies.'},
{attribute: 'cookieName', type: 'String', description: 'Name of cookie used to store the value of this setting.'},
{attribute: 'denyMsg', type: 'String', defaultValue: 'Deny', description: 'Text on button used to deny cookies.'},
{attribute: 'shouldAsk', type: 'Boolean', description: 'Should user be prompted about cookies?'},
{attribute: 'shouldEnable', type: 'Boolean', description: 'Display a message about enabling cookies if they are disabled.'},
{attribute: 'shouldEnableMsg', type: 'String', defaultValue: 'You should enable cookies to be able to login.', description: 'A message about enabling cookies if they are disabled, which will be displayed if shouldEnable is true.'},
{attribute: 'shouldEnableSelector', type: 'String', description: '<code>shouldEnable</code> message selector.'}
]
});
</script>
<script type="text/template" id="page_cookiedirective">
</script>
<script type="text/example" class="example-cookiedirective" data-title="Default">
<div class="pat-cookiedirective">
<div class="login">
</div>
</div>
</script>
<!-- **** Expose **** -->
<script>
addPattern({
id: 'expose',
title: 'Expose',
description: 'Exposes the focused element by <strong>darkening everything else on the page</strong>. Useful to focus the user attention on a particular area.',
attributes: [
{attribute: 'backdrop', type: 'String', description: 'Selector of parent element to use as backdrop.'},
{attribute: 'backdropCloseOnClick', type: 'Boolean', description: 'Cancel expose on click if true.'},
{attribute: 'backdropCloseOnEsc', type: 'Boolean', description: 'Cancel expose on escape if true.'},
{attribute: 'backdropClassName', type: 'String', description: 'TODO'},
{attribute: 'backdropClassActiveName', type: 'String', description: 'TODO'},
{attribute: 'backdropOpacity', type: 'Float', description: 'Backdrop opacity value between 0 and 1.'},
{attribute: 'backdropZIndex', type: 'Integer', description: 'Z-index of backdrop overlay.'},
{attribute: 'classActiveName', type: 'String', description: 'TODO'},
{attribute: 'triggers', type: 'String', description: 'Events that cause the expose feature to be triggered.'}
]
});
</script>
<script type="text/template" id="page_expose">
</script>
<script type="text/example" class="example-expose" data-title="Expose on focus event (default)">
<form id="mockup-expose" class="form-horizontal pat-expose">
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="text" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input type="password" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
<button type="submit" class="btn">Sign in</button>
</div>
</div>
</form>
</script>
<script type="text/example" class="example-expose" data-title="Expose on hover">
<button type="submit"
class="btn btn-large pat-expose"
data-pat-expose="triggers:hover">Hover over this button</button>
</script>
<!-- **** Form Unload Alert **** -->
<script>
addPattern({
id: 'formunloadalert',
title: 'Form Unload Alert',
description: 'A pattern to <strong>warn user when changes are unsaved</strong> and they try to navigate away from page.',
attributes: [
{attribute: 'changingEvents', type: 'String', description: 'Events on which to check for changes (space-separated).'},
{attribute: 'changingFields', type: 'String', description: 'Fields on which to check for changes (comma-separated).'},
{attribute: 'message', type: 'String', defaultValue: 'Discard changes? If you click OK, any changes you have made will be lost.', description: 'Confirmation message to display when dirty form is being unloaded.'}
]
});
</script>
<script type="text/template" id="page_formunloadalert">
</script>
<script type="text/example" class="example-formunloadalert">
<form class="pat-formunloadalert" onsubmit="javascript:return false;">
<input
type="text"
value=""
/>
<select>
<option value="1">value 1</option>
<option value="2">value 2</option>
</select>
<input
class="btn btn-large btn-primary"
type="submit"
value="Submit"
/>
<br />
<a href="/">Click here to go somewhere else</a>
</form>
</script>
<!-- **** Livesearch **** -->
<script type="text/example" id="ls_attr_resultTemplate">
<pre>
'<li class="pat-livesearch-result pat-livesearch-type-<%= Type %>">' +
'<a class="pat-livesearch-result-title" href="<%= getURL %>">' +
'<%= Title %>' +
'</a>' +
'<p class="pat-livesearch-result-desc"><%= Description %></p>' +
'</li>'</pre></script>
<script>
addPattern({
id: 'livesearch',
title: 'Live Search',
description: 'Dynamically query the server and display results.',
attributes: [
{attribute: 'url', type: 'String', description: 'The server-side url that will be queried.'},
{attribute: 'delay', type: 'Integer', description: 'Delay in ms after user types before searching.'},
{attribute: 'highlight', type: 'String', description: 'CSS class that will be used to highlight items on keyboard navigation.'},
{attribute: 'minimumInputLength', type: 'Integer', description: 'Number of characters user must type before search begins.'},
{attribute: 'input', type: 'String', description: 'Selector for element that will be used for the livesearch input.'},
{attribute: 'toggleTarget', type: 'String', description: 'Selector for element that will be shown when results are found.'},
{attribute: 'toggleClass', type: 'String', description: 'CSS class that will be added to target toggle element when results are found.'},
{attribute: 'positionToggleWithInput', type: 'Boolean', description: 'Whether or not the toggle element should be positioned relative to the input element. If set to false setPosition() will not be called.'},
{attribute: 'setPosition', type: 'Function', defaultValue: '<em>Refer to source</em>', description: 'Function which will be used to set the position of the toggle element.'},
{attribute: 'resultsTarget', type: 'String', description: 'Selector for element where results from the server will be inserted.'},
{attribute: 'resultsContainerTemplate', type: 'String', description: 'Template for the element that will contain results. If <code>resultContainerTemplateSelector</code> is set, this will not be used.'},
{attribute: 'resultsContainerTemplateSelector', type: 'String', description: 'Selector for an element in the DOM to use in place of <code>resultContainerTemplate</code>.'},
{attribute: 'resultsAppendTo', type: 'String', description: 'Selector for element within results to append to'},
{attribute: 'resultSelector', type: 'String', description: 'Will be used to select result items from within the result container.'},
{attribute: 'resultTemplate', type: 'String', defaultValue: $('#ls_attr_resultTemplate').html(), description: 'Will be used to select result items from within the result container.'},
{attribute: 'resultTemplateSelector', type: 'String', description: 'Selector for element to be used in place of <code>resultTemplate</code>.'},
{attribute: 'helpTemplate', type: 'String', description: "Template for the element that will contain help messages, such as '<i>No results found.</i>' or '<i>Type 3 more characters to search.</i>'"},
{attribute: 'helpTemplateSelector', type: 'String', description: "Element in the DOM to be used instead of <code>helpTemplate</code>."},
{attribute: 'typeMoreTemplate', type: 'String', description: "Template for message which is displayed if the current input length is less than <code>minimumInputLength</code>."},
{attribute: 'typeMoreTemplateSelector', type: 'String', description: "Element in the DOM to be used instead of <code>typeMoreTemplate</code>."},
{attribute: 'noResultsTemplate', type: 'String', defaultValue: 'No results found.', description: "Template for message that is displayed after a search when no results were found."},
{attribute: 'noResultsTemplateSelector', type: 'String', description: "Element in the DOM to be used instead of <code>noResultsTemplate</code>."},
{attribute: 'searchingTemplate', type: 'String', defaultValue: 'Searching...', description: "Template for message which will be displayed after a search has started and before it has ended."},
{attribute: 'searchingTemplateSelector', type: 'String', description: "Element in the DOM to be used instead of <code>searchingTemplate</code>."}
]
});
</script>
<script type="text/template" id="page_livesearch">
</script>
<script type="text/example" class="example-livesearch" data-title="Default">
<div class="pat-livesearch"
data-pat-livesearch="url: /search.json;">
<input type="text" class="pat-livesearch-input" placeholder="Search" />
<div class="pat-livesearch-container">
<div class="pat-livesearch-results">
</div>
</div>
</div>
</script>
<!-- **** Modal **** -->
<script type="text/example" id="example_template">
<div class="<%= options.className %>">
<div class="<%= options.classHeaderName %>">
<a class="close">×</a>
<% if (title) { %><h3><%= title %></h3><% } %>
</div>
<div class="<%= options.classBodyName %>">
<div class="<%= options.classPrependName %>"><%= prepend %></div>
<div class="<%= options.classContentName %>"><%= content %></div>
</div>
<div class="options.classFooterName">
<%= buttons %>
</div>
</div>
</script>
<div style="display: none" id="example_redirectToUrl">
function($action, response, options) { ... }
</div>
<script>
addPattern({
id: 'modal',
extras: ['tinymce'],
title: 'Modal',
description: 'Creates a modal dialog (also called <strong>overlay</strong>).',
attributes: [
{attribute: 'height', type: 'String', description: 'Set the height of the modal, for example: <code>250px</code>.'},
{attribute: 'width', type: 'String', description: 'Set the width of the modal, for example: <code>80%</code> or <code>500px</code>.'},
{attribute: 'margin', type: 'Function, Integer', description: 'A function or Integer which will be used to set the margin of the modal in pixels. If a function is passed it must return an Integer.'},
{attribute: 'position', type: 'String', description: 'Position the modal relative to the window with the format: "<horizontal> <vertical>" -- allowed values: top, bottom, left, right, center, middle.'},
{attribute: 'triggers', type: 'Array', defaultValue: '<code>[]</code>', description: 'Add event listeners to elements on the page which will open the modal when triggered. Pass an <code>Array</code> of strings with the format <code>["<event> <selector>"]</code> or <code>["<event>"]</code>. For example, <code>["click .someButton"]</code>. If you pass in only an event such as, <code>["change"]</code>, the event listener will be added to the element on which the modal was initiated, usually a link or button.'},
{attribute: 'title', type: 'String', description: 'A string to place in the modal header. If title is provided, <code>titleSelector</code> is not used.'},
{attribute: 'titleSelector', type: 'Selector', description: 'Selector for an element to extract from the content provided to the modal and place in the modal header.'},
{attribute: 'content', type: 'Selector', description: 'Selector for an element within the content provided to the modal to use as the modal body.'},
{attribute: 'prependContent', type: 'Selector', description: 'Selector for elements within the content provided to the modal which will be collected and inserted, by default above, the modal content. This is useful for extracting things like alerts or status messages on forms and displaying them to the user after an AJAX response.'},
{attribute: 'backdrop', type: 'Selector', description: 'Selector for the element upon which the Backdrop pattern should be initiated. The Backdrop is a full width mask that will be apply above the content behind the modal which is useful for highlighting the modal dialog to the user.'},
{
attribute: 'backdropOptions',
type: 'Object',
default: null,
description: null,
attributes: backdropAttributes
},
{attribute: 'buttons', type: 'String', description: 'Selector for matching elements, usually buttons, inputs or links, from the modal content to place in the modal footer. The original elements in the content will be hidden.'},
{attribute: 'automaticallyAddButtonActions', type: 'Boolean', description: 'Automatically create actions for elements matched with the <code>buttons</code> selector. They will use the options provided in <code>actionOptions</code>.'},
{attribute: 'loadLinksWithinModal', type: 'Boolean', description: 'Automatically load links (<code><a></code>) inside of the modal using AJAX.'},
{attribute: 'actions', type: 'Object', description: 'A hash of selector to options. Where options can include any of the defaults from <code>actionOptions</code>. Allows for the binding of events to elements in the content and provides options for handling ajax requests and displaying them in the modal.'},
{
attribute: 'templateOptions',
type: 'Object',
description: 'Options for the classes and templates used when rendering the modal.',
attributes: [
{attribute: 'className', type: 'String', description: 'CSS class applied to the modal element.'},
{attribute: 'classHeaderName', type: 'String', description: 'CSS class applied to the modal header element.'},
{attribute: 'classBodyName', type: 'String', description: 'CSS class applied to the modal body element.'},
{attribute: 'classFooterName', type: 'String', description: 'CSS class applied to the modal footer element.'},
{attribute: 'classWrapperName', type: 'String', description: 'CSS class applied to the invisible by default element that contains the modal. This element is used for precise styling of the modal and to capture links. During modal initialization, if an existing element is found with this class it will be used as the wrapper and the modal will be appended to it. This allows for multiple modals to share the same wrapper. If no element is found a new element will be created with this class applied.'},
{attribute: 'classWrapperInnerName', type: 'String', description: 'CSS class applied to an element that is created within the wrapper. Like the wrapper element the wrapperInner element will be matched with an existing item in the DOM or created during initial modal setup.'},
{attribute: 'classPrependName', type: 'String', description: 'This CSS class will be applied to the wrapper around the content merged into the modal using the prependContent selector.'},
{attribute: 'classContentName', type: 'String', description: 'This CSS class will be applied to the element where content matched using the <code>content</code> selector will be merged into the template.'},
{attribute: 'template', type: 'String', defaultValue: '<pre>'+_.escape($('#example_template').html())+'</pre>', description: 'An <a href="http://underscorejs.org">underscore</a> template which will be used during render. Options passed to the template are: title (either the string set using <code>title</code>, or html matched from the content using <code>titleSelector</code>), prepend (html extracted from the content matching <code>prependContent</code> selector), content (extracted from the content using the <code>content</code> option), options (all of the <code>templateOptions</code> set on the modal).'}
]
},
{
attribute: 'actionOptions',
type: 'Object',
defaultValue: '',
description: 'Configure the defaults for how actions will be handled. Any variables from the pattern defaults can also be set here which will allow the actions to override any options such as width, height, etc.',
attributes: [
{attribute: 'eventType', type: 'String', description: 'The event to bind to the element matched for the action.'},
{attribute: 'target', type: 'String', description: 'Select an element in the DOM from which to load content for the modal. For example, when you want to display content from another div inside of the modal.'},
{attribute: 'ajaxUrl', type: 'String, Function', description: 'A URL string or a <code>function($actionElement, actionOptions)</code> that returns a string.'},
{attribute: 'modalFunction', type: 'String', description: 'Instead of loading a URL you can instead have the action call a function of the modal pattern. For example, <code>hide</code>.'},
{attribute: 'redirectOnResponse', type: 'Boolean', description: 'Whether or not to redirect the window to <code>redirectToUrl</code> after a succesful AJAX response.'},
{attribute: 'redirectToUrl', type: 'String, Function', defaultValue: $('#example_redirectToUrl').text(), description: 'After a successful ajax request, if <code>redirectOnResponse</code> is true, redirect to a specified URL. The default function extracts the URL from a <code><base></code> in the response content.'},
{attribute: 'isForm', type: 'Boolean', description: 'Specify that an action should use an <code>ajaxSubmit</code> call. Otherwise, whether or not it is a form action will be determined by the element type.'},
{attribute: 'timeout', type: 'Integer', description: 'Number of milliseconds to wait for a response before it should be considered timed out.'},
{attribute: 'displayInModal', type: 'Boolean', description: 'Whether or not the response of an AJAX call should be displayed in the modal.'},
{attribute: 'reloadWindowOnClose', type: 'Boolean', description: 'Whether or not to reload the window when the modal is closed due to this action.'},
{attribute: 'error', type: 'String', description: 'Match content from an <code>ajaxSubmit</code> that indicates an error. If content is found, <code>onFormError</code> is called.'},
{attribute: 'formFieldError', type: 'String', description: 'Match content from an <code>ajaxSubmit</code> that indicates a specific form field error (e.g. validation error). If content is found, <code>onFormError</code> is called.'},
{attribute: 'onSuccess', type: 'Function', description: 'Function is called after a successful AJAX request. Arguments: <code>response, state, xhr, form</code>.'},
{attribute: 'onError', type: 'Function', description: 'Function is called if an AJAX request results in an error. Arguments: <code>response, state, xhr, form</code>.'},
{attribute: 'onFormError', type: 'Function', description: 'Function is called if an AJAX request is successful, but content in the response matches the <code>error</code> selector. Arguments: <code>response, state, xhr, form</code>.'},
{attribute: 'onTimeout', type: 'Function', description: 'Function is called if an AJAX request takes longer in than <code>timeout</code> to complete. Arguments: <code>response, state, xhr, form</code>.'},
{attribute: 'templateOptions', type: 'Object', defaultValue: '<em>See <code>templateOptions</code> above</em>', description: 'Options for the template that will be used when this action is rendered. Shares the same defaults, and will be merged with, the <code>templateOptions</code> set above on the pattern.'}
]
},
{attribute: 'form', type: 'Function', defaultValue: '<em>Refer to source</em>', description: 'Function called during render, setup actions and bind events to elements. Arguments: <code>actions, defaultOptions</code> (from <code>actionOptions</code>)'},
{attribute: 'handleFormAction', type: 'Function', defaultValue: '<em>Refer to source</em>', description: 'If <code>action.isForm</code> is <code>true</code>, or if <code>form()</code> determines that the action is a form action, this method will be called when the event is triggered.'},
{attribute: 'handleLinkAction', type: 'Function', defaultValue: '<em>Refer to source</em>', description: 'If <code>action.isForm</code> is <code>false</code>, or if <code>form()</code> determines that the action is a link action this method will be called when the event is triggered.'},
{attribute: 'render', type: 'Function', defaultValue: '<em>Refer to source</em>', description: 'Called when modal is shown, and after a successful response if <code>displayInModal</code> is <code>true</code>.'}
,
{
attribute: 'routerOptions',
type: 'Object',
defaultValue: '',
description: 'Configure URL redirect and showing of modal on hash change.',
attributes: [
{attribute: 'id', type: 'String', description: 'For launching the modal on hash change this will be used by the Router to match this modal. For example, if the `id` is <code>"login"</code>, hashes containing "modal:login" will be matched.'},
{attribute: 'pathExp', type: 'String', description: 'A Regular Expression compatible string which will be used to match path segments in order to redirect to a hash. For example, with `id` <code>"edit"</code> and `pathExp` as <code>"/edit$"</code> a URL with a path of <code>/animals/edit</code> will redirect to <code>/animals#!/modal:edit</code>.'}
]
}
]
});
</script>
<script type="text/example" class="example-modal" title="">
<a href="#modal1"
class="btn btn-large btn-primary pat-modal">Modal basic</a>
<div id="modal1" style="display: none">
<h1>Basic modal!</h1>
<p>Indeed. Whoa whoa whoa whoa. Wait.</p>
</div>
</script>
<script type="text/example" class="example-modal" title="">
<a href="something.html#content" id="modal2"
class="btn btn-large btn-primary pat-modal">
Modal with remote content (AJAX)</a>
</script>
<script type="text/example" class="example-modal" title="">
<a href="something-link.html#content" id="modal2"
class="btn btn-large btn-primary pat-modal">
Modal with links (AJAX)</a>
</script>
<script type="text/example" class="example-modal" title="">
<a href="/modal-form.html"
class="btn btn-large btn-primary pat-modal">
Modal with form (AJAX)</a>
</script>
<script type="text/example" class="example-modal" title="">
<a href="#modal3"
class="btn btn-large btn-primary pat-modal"
data-pat-modal="position:center bottom;
height:30%;
width:80%">
Modal with custom position</a>
</script>
<script type="text/example" class="example-modal" title="Modal with tinymce">
<a href="#modaltinymce"
class="btn btn-large btn-primary pat-modal"
data-pat-modal="height: 600px;
width: 80%">
Modal with TinyMCE</a>
</script>
<script type="text/template" id="modaltinymce">
<div>
<textarea class="pat-tinymce"></textarea>
</div>
</script>
<script type="text/example" class="example-modal" title="">
<a href="#modalBackdrop"
class="btn btn-large btn-primary pat-modal"
data-pat-modal='{"backdrop": "#content",
"backdropOptions": {
"opacity": "0.2",
"closeOnClick": false
}
}'>
Custom Backdrop</a>
<div id="modalBackdrop" style="display: none">
<h1>Custom Backdrop</h1>
<ul>
<li>Less opaque</li>
<li>Modal doesn't close when Backdrop is clicked</li>
</ul>
</div>
</div>
</script>
<script type="text/example" class="example-modal" title="">
<a href="#modal4"
class="btn btn-large btn-primary pat-modal">
Modal with long text</a>
</script>
<script type="text/template" id="page_modal">
<div style="display:none">
<div id="modal3">
<h1>This modal is positioned</h1>
<p>The end is near, do not jump the bunny.</p>
</div>
<div id="modal4">
<p>Did you know that more frozen bananas are sold right here on
this boardwalk than anywhere on the OC? You stay on top of
her, Buddy. Don't be afraid to ride her. Hard. Are you aware
of this? Coming soon. Indeed. Whoa whoa whoa whoa. Wait. Are
you telling me you have a multi-stage trick with hidden
identities? That coat costs more than your house! Well,
obviously, I'm not a big guy. I'm not a Carl Weathers, par
example. You burn down the storage unit? Oh, most definitely.
Oh…yeah…the guy in the…the $4,000 suit is holding the
elevator for a guy who doesn't make that in three months.
Come on!</p>
<p>No! These are just strippers! Look how hot they are! Michael
was having brunch with Sally Sitwell at a restaurant called
Skip Church's Bistro. In addition to brunch, the restaurant
was known for an item on the menu called the "Skip's
Scramble", an omelet that contained everything on the menu.
Do not order the Skip's Scramble. Look, you are playing