Skip to content
This repository was archived by the owner on Mar 20, 2018. It is now read-only.

Commit 06b738c

Browse files
committed
Added namespace option and Grunt build file
1 parent 2f8e5e4 commit 06b738c

File tree

6 files changed

+92
-66
lines changed

6 files changed

+92
-66
lines changed

README.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# jQuery Modal
2-
Every front-end developer needs their own [modal window][1]. The plugin is performant, customisable and easy to integrate. Less than 3KB minified and 1KB with gzip compression.
2+
Every front-end developer needs their own [modal window][1]. The plugin is performant, tested, customisable and easy to integrate. Less than 3KB minified and 1KB gzipped.
33

44
## Dependencies
55

grunt.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = function(grunt) {
2+
3+
grunt.initConfig({
4+
min: {
5+
dist: {
6+
src: ['js/modal.js'],
7+
dest: 'js/modal.min.js'
8+
}
9+
},
10+
lint: {
11+
files: ['grunt.js', 'js/modal.js']
12+
},
13+
jshint: {
14+
options: {
15+
trailing: true,
16+
browser: true
17+
},
18+
globals: {
19+
jQuery: true
20+
}
21+
}
22+
});
23+
24+
grunt.registerTask('default', 'lint min');
25+
26+
};

index.html

+23-18
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
<h1>jQuery Modal</h1>
2727
<p>
2828
Every front-end developer needs their own <a href="http://github.com/i-like-robots/jQuery-Modal">modal
29-
window</a>. The plugin is performant, customisable and easy to integrate. Less than 3KB minified and
30-
1KB with gzip compression.
29+
window</a>. jQuery modal is performant, tested, customisable and easy to integrate. Less than 2.5KB
30+
minified and 1KB gzipped.
3131
</p>
3232

3333
<div id="example">
@@ -107,19 +107,37 @@ <h2>Options</h2>
107107
<p>
108108
Global options can be specified via the standard jQuery plugin interface.
109109
</p>
110+
110111
<dl>
111112
<dt>onopen</dt>
112113
<dd>
113114
Callback function to execute after modal window has opened. Default: <code>undefined</code>.
114115
</dd>
115-
<dt>onclose</dt>
116+
<dt>onhide</dt>
116117
<dd>
117118
Callback function to execute after modal window has closed. Default: <code>undefined</code>.
118119
</dd>
119120
<dt>onupdate</dt>
120121
<dd>
121122
Callback function to execute when modal window content is changed. Default: <code>undefined</code>.
122123
</dd>
124+
<dt>fixed</dt>
125+
<dd>
126+
Use CSS <code>fixed</code> positioning for the modal window instead of <code>absolute</code>.
127+
Default: <code>false</code>.
128+
</dd>
129+
<dt>overlay</dt>
130+
<dd>
131+
Create an overlay beneath the modal window and over the target. Default: <code>true</code>.
132+
</dd>
133+
<dt>blur</dt>
134+
<dd>
135+
Close the modal window when overlay is clicked. Default: <code>true</code>.
136+
</dd>
137+
<dt>escape</dt>
138+
<dd>
139+
Close the modal window when the escape key is pressed. Default: <code>true</code>.
140+
</dd>
123141
<dt>width</dt>
124142
<dd>
125143
Predefined width for modal window. Set to <code>auto</code> for the contents automatic flow width.
@@ -140,22 +158,9 @@ <h2>Options</h2>
140158
Set CSS <code>max-height</code> relative to the modal windows parent. Set to <code>none</code> to
141159
set no maximum height. Default: <code>'95%'</code>.
142160
</dd>
143-
<dt>fixed</dt>
144-
<dd>
145-
Use CSS <code>fixed</code> positioning for the modal window instead of <code>absolute</code>.
146-
Default: <code>false</code>.
147-
</dd>
148-
<dt>overlay</dt>
149-
<dd>
150-
Create an overlay beneath the modal window and over the target. Default: <code>true</code>.
151-
</dd>
152-
<dt>blur</dt>
153-
<dd>
154-
Close the modal window when overlay is clicked. Default: <code>true</code>.
155-
</dd>
156-
<dt>escape</dt>
161+
<dt>namespace</dt>
157162
<dd>
158-
Close the modal window when the escape key is pressed. Default: <code>true</code>.
163+
Data attribute and event binding namespace. Default: <code>'modal'</code>.
159164
</dd>
160165
</dl>
161166
</section>

js/modal.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* @name jQuery Modal
33
* @author Matt Hinchliffe <https://github.com/i-like-robots/jQuery-Modal>
4-
* @modified 10/12/2012
4+
* @modified 2012-12-10
55
* @version 1.0.0
66
*/
77
(function( $, undefined ) {
@@ -21,7 +21,8 @@
2121
width: 640,
2222
maxWidth: '95%',
2323
height: 480,
24-
maxHeight: '95%'
24+
maxHeight: '95%',
25+
namespace: 'modal'
2526
}, options);
2627

2728
this.target = target;
@@ -49,7 +50,7 @@
4950
display: 'none'
5051
});
5152

52-
this.close = $('<span class="modal-close" data-toggle="modal">Close</span>').appendTo(this.wrapper);
53+
this.close = $('<span class="modal-close" data-' + this.opts.namespace + '-close>Close</span>').appendTo(this.wrapper);
5354
this.content = $('<div class="modal-content">').appendTo(this.wrapper);
5455

5556
this.wrapper.appendTo(this.target);
@@ -58,7 +59,7 @@
5859
this.overlay = false;
5960

6061
if ( this.opts.overlay ) {
61-
this.overlay = $('<div class="modal-overlay"' + (this.opts.blur ? 'data-toggle="modal"' : '') + '>')
62+
this.overlay = $('<div class="modal-overlay"' + (this.opts.blur ? 'data-' + this.opts.namespace + '-close' : '') + '>')
6263
.css({
6364
position: 'absolute',
6465
top: 0,
@@ -113,18 +114,18 @@
113114
var self = this;
114115

115116
if ( this.isBody ) {
116-
this.context.on('resize.modal', function() {
117+
this.context.on('resize.' + this.opts.namespace, function() {
117118
self.align();
118119
});
119120

120-
this.doc.on('keyup.modal', function( e ) {
121+
this.doc.on('keyup.' + this.opts.namespace, function( e ) {
121122
if ( e.keyCode === 27 ) {
122123
self.hide();
123124
}
124125
});
125126
}
126127

127-
this.doc.on('click.modal', '[data-toggle="modal"]', function( e ) {
128+
this.doc.on('click.modal', '[data-' + this.opts.namespace + '-close]', function( e ) {
128129
e.preventDefault();
129130
self.hide();
130131
});
@@ -198,7 +199,7 @@
198199
Modal.prototype.hide = function( callback ) {
199200

200201
// Unbind events
201-
this.doc.off('.modal');
202+
this.doc.off('.' + this.opts.namespace);
202203

203204
this.wrapper
204205
.add(this.overlay)

js/modal.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/qunit.html

+31-37
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,17 @@
2020
</head>
2121
<body>
2222

23-
<div id="container">
24-
25-
<section id="introduction">
26-
<h1>QUnit tests</h1>
27-
28-
<p id="example-1" style="display:none;">
29-
Rump sausage ham short loin pork. Pig venison boudin bresaola, frankfurter sirloin filet mignon pork shankle
30-
capicola. Leberkas jerky ground round short loin bacon. Capicola strip steak flank meatball pork loin beef
31-
ribs turducken, biltong jowl kielbasa rump shank short ribs. Beef beef ribs filet mignon frankfurter,
32-
prosciutto pork chop chicken ground round short ribs tenderloin sirloin fatback brisket.
33-
</p>
34-
35-
<p id="example-2" style="display:none;">
36-
Brisket short ribs beef ribs, pork loin rump ribeye shankle meatball tri-tip tail chuck meatloaf filet
37-
mignon. Pork chop filet mignon tail, chicken kielbasa salami venison ball tip rump. Tenderloin brisket
38-
andouille shank pig, meatloaf filet mignon spare ribs ball tip t-bone sausage. Ribeye tail doner shank,
39-
pork belly ham hock spare ribs salami pastrami cow. Meatball leberkas pork frankfurter meatloaf turkey
40-
rump drumstick, spare ribs beef ribs.
41-
</p>
42-
43-
</section>
44-
45-
</div>
23+
<p id="example-content" style="display:none;">
24+
Rump sausage ham short loin pork. Pig venison boudin bresaola, frankfurter sirloin filet mignon pork shankle
25+
capicola. Leberkas jerky ground round short loin bacon. Capicola strip steak flank meatball pork loin beef
26+
ribs turducken, biltong jowl kielbasa rump shank short ribs. Beef beef ribs filet mignon frankfurter,
27+
prosciutto pork chop chicken ground round short ribs tenderloin sirloin fatback brisket.
28+
</p>
4629

4730
<section id="tests" style="margin: 20px;">
48-
<h2>Tests</h2>
4931
<div id="qunit"></div>
5032
</section>
5133

52-
5334
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
5435
<script src="../js/modal.js"></script>
5536
<script src="qunit-1.10.0.js"></script>
@@ -91,24 +72,22 @@ <h2>Tests</h2>
9172

9273
test(".open()", function() {
9374

94-
window.testOpen = false;
95-
96-
var content = $('#example-1').html()
75+
var testOpen = false;
9776

98-
api.open( content, function() {
99-
window.testOpen = true;
77+
api.open('', function() {
78+
testOpen = true;
10079
});
10180

10281
equal(api.isOpen, true, "Check isOpen is correct");
103-
equal(api.content.html(), content, "Check modal content was populated");
104-
equal(window.testOpen, true, "Check callback was called");
82+
equal(api.content.is(':visible'), true, "Check modal is hidden");
83+
equal(testOpen, true, "Check callback was called");
10584
});
10685

10786
test(".update()", function() {
10887

109-
window.testUpdate = false;
88+
window.testOpen = false;
11089

111-
var content = $('#example-2').html();
90+
var content = $('#example-content').html();
11291

11392
api.update(content, function() {
11493
window.testUpdate = true;
@@ -125,15 +104,30 @@ <h2>Tests</h2>
125104

126105
test(".hide()", function() {
127106

128-
window.testHide = false;
107+
var testOpen = true;
129108

130109
api.hide(function() {
131-
window.testHide = true;
110+
testOpen = false;
132111
});
133112

113+
equal(api.isOpen, false, "Check isOpen is correct");
134114
equal(api.content.is(':visible'), false, "Check modal is hidden");
115+
equal(testOpen, false, "Check callback was called");
116+
});
117+
118+
//
119+
// user controls
120+
//
121+
122+
module("User controls", lifecycle);
123+
124+
test("Close button", function() {
125+
126+
api.open();
127+
api.close.trigger('click');
128+
135129
equal(api.isOpen, false, "Check isOpen is correct");
136-
equal(window.testHide, true, "Check callback was called");
130+
equal(api.content.is(':visible'), false, "Check modal is hidden");
137131
});
138132

139133
});

0 commit comments

Comments
 (0)