9
9
10
10
11
11
< link rel ="stylesheet " href ="css/example.css " />
12
+ < link rel ="stylesheet " href ="css/pygments.css " />
12
13
< link rel ="stylesheet " href ="css/modal.css " />
13
14
14
15
<!--
21
22
22
23
< div id ="container ">
23
24
24
- < section class ="introduction ">
25
+ < section id ="introduction ">
25
26
< h1 > jQuery Modal</ h1 >
26
27
< p >
27
28
Every front-end developer needs their own < a href ="http://github.com/i-like-robots/jQuery-Modal "> modal
28
- window</ a > . The plugin is optimised and customisable and even supports multiple, nestable instances.
29
- Less than 3KB minified and 1KB with gzip compression.
29
+ window</ a > . The plugin is performant, customisable and easy to integrate. Less than 3KB minified and
30
+ 1KB with gzip compression.
30
31
</ p >
32
+
33
+ < div id ="example ">
34
+ < p >
35
+ < button class ="js-open "> See an example</ button >
36
+ </ p >
37
+ < p id ="example-content " style ="display:none; ">
38
+ Rump sausage ham short loin pork. Pig venison boudin bresaola, frankfurter sirloin filet mignon pork shankle
39
+ capicola. Leberkas jerky ground round short loin bacon. Capicola strip steak flank meatball pork loin beef
40
+ ribs turducken, biltong jowl kielbasa rump shank short ribs. Beef beef ribs filet mignon frankfurter,
41
+ prosciutto pork chop chicken ground round short ribs tenderloin sirloin fatback brisket.
42
+ </ p >
43
+ </ div >
31
44
</ section >
32
45
33
46
< hr />
34
47
35
- < section class ="examples ">
36
- < h2 > Example</ h2 >
48
+ < section id ="setup ">
49
+ < h2 > Setup</ h2 >
50
+ < p >
51
+ This isn't a copy and paste plugin, it's just an outline. The plugin is instantiated in the usual
52
+ manner and an instances API can be accessed via element data.
53
+ </ p >
54
+
55
+ < figure >
56
+ < pre class ="syntax "> < span class ="c1 "> // Create a modal instance.</ span >
57
+ < span class ="kd "> var</ span > < span class ="nx "> $m</ span > < span class ="o "> =</ span > < span class ="nx "> $</ span > < span class ="p "> (</ span > < span class ="s1 "> 'body'</ span > < span class ="p "> ).</ span > < span class ="nx "> modal</ span > < span class ="p "> (),</ span >
58
+
59
+ < span class ="c1 "> // Access an instance API</ span >
60
+ < span class ="nx "> api</ span > < span class ="o "> =</ span > < span class ="nx "> $m</ span > < span class ="p "> .</ span > < span class ="nx "> data</ span > < span class ="p "> (</ span > < span class ="s1 "> 'modal'</ span > < span class ="p "> );</ span >
61
+ </ pre >
62
+ </ figure >
63
+
64
+ < p >
65
+ The simplest example is to open a modal window instance with basic HTML content:
66
+ </ p >
67
+
68
+ < figure >
69
+ < pre class ="syntax "> < span class ="c1 "> // Open the modal with some content</ span >
70
+ < span class ="nx "> api</ span > < span class ="p "> .</ span > < span class ="nx "> open</ span > < span class ="p "> (</ span > < span class ="s2 "> "<p>Hello, is it me you're looking for?"</ span > < span class ="p "> );</ span >
71
+ </ pre >
72
+ </ figure >
73
+
37
74
< p >
38
- < button class ="js-open " rel ="example "> Open the modal</ button >
75
+ The API is flexible enough to do any common task such as confirmation boxes, displaying images and
76
+ external content.
39
77
</ p >
40
- < pre > < code > < span class ="comment "> // Create an instance</ span >
41
- var m = $('body').modal(opts).data('modal');
42
-
43
- < span class ="comment "> // Do whatever</ span >
44
- $.ajax({
45
- success: function(data)
46
- {
47
- m.open(data);
48
- }
49
- });</ code > </ pre >
78
+
79
+ < figure >
80
+ < pre class ="syntax "> < span class ="nx "> $</ span > < span class ="p "> .</ span > < span class ="nx "> ajax</ span > < span class ="p "> ({</ span >
81
+ < span class ="nx "> url</ span > < span class ="o "> :</ span > < span class ="s1 "> 'http://localhost/api?foo=bar'</ span > < span class ="p "> ,</ span >
82
+ < span class ="nx "> success</ span > < span class ="o "> :</ span > < span class ="kd "> function</ span > < span class ="p "> (</ span > < span class ="nx "> data</ span > < span class ="p "> )</ span >
83
+ < span class ="p "> {</ span >
84
+ < span class ="k "> if</ span > < span class ="p "> (</ span > < span class ="nx "> api</ span > < span class ="p "> .</ span > < span class ="nx "> isOpen</ span > < span class ="p "> )</ span >
85
+ < span class ="p "> {</ span >
86
+ < span class ="nx "> api</ span > < span class ="p "> .</ span > < span class ="nx "> update</ span > < span class ="p "> (</ span > < span class ="nx "> data</ span > < span class ="p "> );</ span >
87
+ < span class ="p "> }</ span >
88
+ < span class ="k "> else</ span >
89
+ < span class ="p "> {</ span >
90
+ < span class ="nx "> api</ span > < span class ="p "> .</ span > < span class ="nx "> open</ span > < span class ="p "> (</ span > < span class ="nx "> data</ span > < span class ="p "> );</ span >
91
+ < span class ="p "> }</ span >
92
+ < span class ="p "> },</ span >
93
+ < span class ="nx "> error</ span > < span class ="o "> :</ span > < span class ="kd "> function</ span > < span class ="p "> (</ span > < span class ="nx "> xhr</ span > < span class ="p "> ,</ span > < span class ="nx "> error</ span > < span class ="p "> )</ span >
94
+ < span class ="p "> {</ span >
95
+ < span class ="nx "> console</ span > < span class ="p "> .</ span > < span class ="nx "> log</ span > < span class ="p "> (</ span > < span class ="nx "> error</ span > < span class ="p "> );</ span >
96
+ < span class ="p "> }</ span >
97
+ < span class ="p "> });</ span >
98
+ </ pre >
99
+ </ figure >
100
+
50
101
</ section >
51
102
52
103
< hr />
53
104
54
- < section class ="options ">
55
- < h3 > Options</ h3 >
105
+ < section id ="options ">
106
+ < h2 > Options</ h2 >
107
+ < p >
108
+ Global options can be specified via the standard jQuery plugin interface.
109
+ </ p >
56
110
< dl >
57
111
< dt > onopen</ dt >
58
112
< dd >
@@ -74,7 +128,7 @@ <h3>Options</h3>
74
128
< dt > maxWidth</ dt >
75
129
< dd >
76
130
Set CSS < code > max-width</ code > relative to the modal windows parent. Set to < code > none</ code > to
77
- set no maximum width. Default: < code > 95%'</ code > .
131
+ set no maximum width. Default: < code > ' 95%'</ code > .
78
132
</ dd >
79
133
< dt > height</ dt >
80
134
< dd >
@@ -84,7 +138,7 @@ <h3>Options</h3>
84
138
< dt > maxHeight</ dt >
85
139
< dd >
86
140
Set CSS < code > max-height</ code > relative to the modal windows parent. Set to < code > none</ code > to
87
- set no maximum height. Default: < code > 95%'</ code > .
141
+ set no maximum height. Default: < code > ' 95%'</ code > .
88
142
</ dd >
89
143
< dt > fixed</ dt >
90
144
< dd >
@@ -108,8 +162,8 @@ <h3>Options</h3>
108
162
109
163
< hr />
110
164
111
- < section class ="api ">
112
- < h4 > Public methods</ h4 >
165
+ < section id ="api ">
166
+ < h2 > Public methods</ h2 >
113
167
< dl >
114
168
< dt > .open([content][, callback])</ dt >
115
169
< dd >
@@ -132,41 +186,44 @@ <h4>Public methods</h4>
132
186
< dd >
133
187
Repositions the window to the center of the modal window parent.
134
188
</ dd >
189
+ < dt > .resize(width, height)</ dt >
190
+ < dd >
191
+ Resizes the modal window content area. < var > Width</ var > and < var > Height</ var > can be any unit
192
+ compatible with the < a href ="http://api.jquery.com/category/dimensions/ "> jQuery Dimensions</ a > API.
193
+ </ dd >
135
194
< dt > A note on callbacks:</ dt >
136
195
< dd >
137
196
All callbacks will be called from the scope of the modal instance, so that < code > this</ code > will
138
- refer to the modal instance. Callbacks provided as arguments to the public methods will be executed
139
- in addition to those specified as options.
197
+ refer to the modal instance. Callbacks provided as arguments to the public methods above will be
198
+ executed in addition to those specified as instance options.
140
199
</ dd >
141
200
</ dl >
142
201
</ section >
143
202
144
203
</ div >
145
204
146
- < p id ="example ">
147
- Rump sausage ham short loin pork. Pig venison boudin bresaola, frankfurter sirloin filet mignon pork shankle
148
- capicola. Leberkas jerky ground round short loin bacon. Capicola strip steak flank meatball pork loin beef
149
- ribs turducken, biltong jowl kielbasa rump shank short ribs. Beef beef ribs filet mignon frankfurter,
150
- prosciutto pork chop chicken ground round short ribs tenderloin sirloin fatback brisket.
151
- </ p >
152
-
153
- < a href ="https://github.com/i-like-robots/jQuery-Modal ">
154
- < img style ="position:absolute;top:0;right:0;border:0; " src ="https://a248.e.akamai.net/assets.github.com/img/30f550e0d38ceb6ef5b81500c64d970b7fb0f028/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6f72616e67655f6666373630302e706e67 " alt ="Fork me on GitHub " />
205
+ < a href ="http://github.com/i-like-robots/jQuery-Modal ">
206
+ < img style ="position:absolute; top:0; right:0; border:0; " src ="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png " alt ="Fork me on GitHub " />
155
207
</ a >
156
208
157
- < script src ="http://ajax.aspnetcdn .com/ajax/jQuery /jquery-1.7.2.min.js "> </ script >
209
+ < script src ="//code.jquery .com/jquery-1.7.2.min.js "> </ script >
158
210
< script src ="js/modal.js "> </ script >
159
211
< script >
160
212
$ ( function ( )
161
213
{
162
- // Create a modal instance. Use the document body as target to create a modal window for the entire document.
163
- window . m = $ ( 'body' ) . modal ( ) . data ( 'modal' ) ;
214
+ // Create a modal instance.
215
+ var $m = $ ( 'body' ) . modal ( ) ,
216
+
217
+ // Access an instance API
218
+ api = $m . data ( 'modal' ) ;
164
219
165
220
// Bind a click event to copy a hidden elements content into the modal window
166
221
$ ( document ) . on ( 'click' , '.js-open' , function ( )
167
222
{
168
- m . open ( document . getElementById ( this . getAttribute ( 'rel' ) ) . innerHTML ) ;
223
+ api . open ( document . getElementById ( 'example-content' ) . innerHTML ) ;
169
224
} ) ;
225
+
226
+ window . $m = $m ;
170
227
} ) ;
171
228
</ script >
172
229
0 commit comments