File tree Expand file tree Collapse file tree 3 files changed +31
-2
lines changed Expand file tree Collapse file tree 3 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,34 @@ A modal panel is a panel that requires users to interact with it before they can
55
66## Documentation
77
8- A basic modal example:
8+ Case 1: Any `` <div class="pat-modal"> `` will be displayed as modal immediately:
9+
10+ <div class="pat-modal">
11+ <h2>Modal title</h2>
12+ <div>Modal content</div>
13+ </div>
14+
15+
16+ Case 2a: Anchors, forms and subforms would use pat-inject to retrieve remote (or local) contents and display that as modal.
17+ The remote content should return a `` div `` but not contain the `` pat-modal `` class - this is set automatically.
918
1019 <a href="/status/server1#content" class="pat-modal">Show server status</a>
1120
1221This will load the page at ` /status/server1 ` , extract the element with id ` content ` and display its content in a panel.
1322
23+ Case 2b: Loading a modal form a local `` <template> `` which is within the current page:
24+
25+ <a href="#modal-source" class="pat-modal">Open modal</a>
26+
27+ <template id="modal-source">
28+ <h1>Example modal</h1>
29+ <p>Hello.</p>
30+ </template>
31+
32+
33+ For more examples, see the [ demo page] ( ./index.html ) .
34+
35+
1436### Options reference
1537
1638You can customise the behaviour of modals through options in the ` data-pat-modal ` attribute.
Original file line number Diff line number Diff line change 1111 > </ script >
1212 </ head >
1313 < body >
14- < div id ="pat-modal " class =" pat-modal " >
14+ < div id ="pat-modal ">
1515 < h1 > Example modal</ h1 >
1616 < div class ="container ">
1717 < p >
Original file line number Diff line number Diff line change @@ -42,6 +42,10 @@ export default Base.extend({
4242 } ,
4343
4444 _init_inject1 ( ) {
45+ // This will get remote content via pat-inject, add the pat-modal class
46+ // to the result and pat-inject's pattern scanning will then call
47+ // ``_init_div1``.
48+
4549 const opts = {
4650 ...( this . options . source && { source : this . options . source } ) ,
4751 target : this . options . target ,
@@ -54,6 +58,7 @@ export default Base.extend({
5458 if ( this . options . trigger ) {
5559 opts . trigger = this . options . trigger ;
5660 }
61+
5762 // if $el is already inside a modal, do not detach #pat-modal,
5863 // because this would unnecessarily close the modal itself
5964 if ( ! this . $el . closest ( "#pat-modal" ) ) {
@@ -67,6 +72,8 @@ export default Base.extend({
6772 } ,
6873
6974 _init_div1 ( ) {
75+ // This is always called and will inject the modal in the page.
76+
7077 const header = document . createElement ( "div" ) ;
7178 header . setAttribute ( "class" , "header" ) ;
7279
You can’t perform that action at this time.
0 commit comments