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

Commit 6cc9a9b

Browse files
committed
1.0.0b initial changes.
1 parent a0a19be commit 6cc9a9b

File tree

2 files changed

+40
-56
lines changed

2 files changed

+40
-56
lines changed

README.markdown

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ jQuery 1.7+
88
## Supported browsers*
99

1010
* Firefox 3.6 and 4-9
11-
* Chrome 8-18
11+
* Chrome
1212
* Safari 5.1
1313
* Internet Explorer 7-9
14-
* Opera 11.5
14+
* Opera 11.5+
1515

1616
## Issues
1717

@@ -21,7 +21,7 @@ https://github.com/i-like-robots/jQuery-Modal/issues
2121

2222
## Versioning
2323

24-
The current version is `0.9.0`. Releases will be numbered in following format:
24+
The current version is `1.0.0`. Releases will be numbered in following format:
2525

2626
`<major>.<minor>.<patch>`
2727

js/modal.js

+37-53
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* @name jQuery Modal
33
* @author Matt Hinchliffe <https://github.com/i-like-robots/jQuery-Modal>
4-
* @modified 06/08/2012
5-
* @version 0.9.0
4+
* @modified 13/09/2012
5+
* @version 1.0.0b
66
* @description A simple modal overlay
77
*
88
* @example jQuery plugin setup
@@ -18,31 +18,29 @@
1818
*
1919
* @example Generated markup
2020
* <div class="modal-wrapper">
21-
* <div class="modal-content" />
2221
* <span class="modal-close" data-toggle="modal">Close</span>
22+
* <div class="modal-content" />
2323
* </div>
2424
* <div class="modal-overlay" data-toggle="modal" />
2525
*/
26-
27-
/*jshint trailing:true, smarttabs:true */
2826
; (function($, undefined)
2927
{
3028
"use strict";
3129

3230
function Modal(target, options)
3331
{
3432
this.opts = $.extend({}, { // Create a new options object for each instance
35-
onopen: undefined,
36-
onclose: undefined,
37-
onupdate: undefined,
38-
width: 640,
39-
maxWidth: '95%',
40-
height: 480,
41-
maxHeight: '95%',
42-
fixed: false,
43-
overlay: true,
44-
blur: true,
45-
escape: true
33+
onopen: undefined,
34+
onhide: undefined,
35+
onupdate: undefined,
36+
fixed: false,
37+
overlay: true,
38+
blur: true,
39+
escape: true,
40+
width: 640,
41+
maxWidth: '95%',
42+
height: 480,
43+
maxHeight: '95%'
4644
}, options);
4745

4846
this.target = target;
@@ -62,26 +60,24 @@
6260
*/
6361
_init: function()
6462
{
65-
if (this.isInitialized)
66-
{
67-
return;
68-
}
69-
7063
this.doc = $(document);
7164

72-
// Build modal
73-
this.wrapper = $('<div class="modal-wrapper"><span class="modal-close" data-toggle="modal">Close</span></div>').css({
65+
this.wrapper = $('<div class="modal-wrapper" />').css({
7466
position: this.opts.fixed ? 'fixed' : 'absolute',
7567
width: this.opts.width,
7668
maxWidth: this.opts.maxWidth,
7769
height: this.opts.height,
7870
maxHeight: this.opts.maxHeight,
7971
display: 'none'
8072
});
73+
this.close = $('<span class="modal-close" data-toggle="modal">Close</span>').appendTo( this.wrapper );
8174
this.content = $('<div class="modal-content" />').appendTo( this.wrapper );
75+
8276
this.wrapper.appendTo( this.target );
8377

84-
// Create overlay
78+
// Define overlay to prevent errors
79+
this.overlay = false;
80+
8581
if (this.opts.overlay)
8682
{
8783
this.overlay = $('<div class="modal-overlay"' + (this.opts.blur ? 'data-toggle="modal"' : '') + ' />')
@@ -108,11 +104,11 @@
108104
*/
109105
align: function()
110106
{
111-
var height = this.wrapper.height(),
112-
width = this.wrapper.width(),
107+
var height = this.wrapper.outerHeight(),
108+
width = this.wrapper.outerWidth(),
113109
maxHeight = this.context.height(),
114-
maxWidth = this.context.width(),
115-
top = this.opts.fixed ? 0 : this.context.scrollTop();
110+
maxWidth = this.context.width(),
111+
top = this.opts.fixed ? 0 : this.context.scrollTop();
116112

117113
this.wrapper.css(
118114
{
@@ -138,10 +134,6 @@
138134
{
139135
this._init();
140136
}
141-
else if (this.isOpen)
142-
{
143-
return;
144-
}
145137

146138
var self = this;
147139

@@ -156,15 +148,15 @@
156148
{
157149
if ( e.keyCode === 27 )
158150
{
159-
self.close();
151+
self.hide();
160152
}
161153
});
162154
}
163155

164156
this.doc.on('click.modal', '[data-toggle="modal"]', function(e)
165157
{
166158
e.preventDefault();
167-
self.close();
159+
self.hide();
168160
});
169161

170162
// Fade in
@@ -181,6 +173,7 @@
181173
this.update(content);
182174
}
183175

176+
184177
// Callbacks
185178
if (this.opts.onopen)
186179
{
@@ -194,8 +187,8 @@
194187

195188
/**
196189
* Update
197-
* @description Change the modal window contents
198-
* @param {object} content
190+
* @description Update the modal window contents
191+
* @param {object|string} content
199192
* @param {function} callback
200193
*/
201194
update: function(content, callback)
@@ -221,6 +214,8 @@
221214
/**
222215
* Resize
223216
* @description Resizes the modal window content area
217+
* @param {numeric|string} width
218+
* @param {numeric|string} height
224219
*/
225220
resize: function(width, height)
226221
{
@@ -233,37 +228,26 @@
233228
},
234229

235230
/**
236-
* Close
237-
* @description Close the modal window and clear contents
231+
* Hide
232+
* @description Hide the modal window
238233
* @param {function} callback
239234
*/
240-
close: function(callback)
235+
hide: function(callback)
241236
{
242-
if ( ! this.isInitialized || ! this.isOpen)
243-
{
244-
return;
245-
}
246-
247-
var self = this;
248-
249237
// Unbind events
250238
this.doc.off('.modal');
251239

252-
// Fade out
253240
this.wrapper
254241
.add( this.overlay )
255242
.stop()
256-
.fadeOut(function()
257-
{
258-
self.content[0].innerHTML = '';
259-
});
243+
.fadeOut();
260244

261245
this.isOpen = false;
262246

263247
// Callbacks
264-
if (this.opts.onclose)
248+
if (this.opts.onhide)
265249
{
266-
this.opts.onclose.call(this);
250+
this.opts.onhide.call(this);
267251
}
268252
if (callback)
269253
{

0 commit comments

Comments
 (0)