forked from brettdewoody/jQuery-Interstitial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.interstitial.js
More file actions
95 lines (75 loc) · 2.58 KB
/
jquery.interstitial.js
File metadata and controls
95 lines (75 loc) · 2.58 KB
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
/*
* jQuery interstitial plugin v1.1
* jquery.interstitial.js
*
* https://github.com/brettdewoody/jQuery-Interstitial
*
* Copyright (c) 2011 Brett DeWoody
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* Special thanks to Soh Tanaka (http://www.sohtanaka.com) for inspiring
* this jQuery-based interstitial popup. You can read about his original
* method here on Soh Tanaka's webite:
*
* http://www.sohtanaka.com/web-design/inline-modal-window-w-css-and-jquery
*/
(function( $ ){
var methods = {
open : function( options ) {
var defaults = {
'url' : '',
'width' : 600,
'height' : 400,
'opacity' : 70,
'id' : 'popupBlock',
'onInterstitialClose' : function(){}
};
var settings = $.extend({}, defaults, options);
//Fade in Background
$('body').append('<div id="fade"></div>');
$('#fade').css({'filter' : 'alpha(opacity=' + settings.opacity + ')'}).fadeIn();
//Fade in the Popup
$('body').append('<div id="' + settings.id + '"></div>');
$('#' + settings.id).load(settings.url, function() {
$('#' + settings.id).css({'width' : Number(settings.width), 'height' : Number(settings.height)}).fadeIn();
});
//Define margin for center alignment (vertical + horizontal)
var popMargTop = settings.height / 2;
var popMargLeft = settings.width / 2;
//Apply Margin to Popup
$('#' + settings.id).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
//On click of the fade, close the popup and fade
$('#fade').on('click', function() {
$().interstitial('close', settings);
});
},
// Function: Close the interstitial
close : function( options ) {
var defaults = {
'id' : 'popupBlock',
'onInterstitialClose' : function(){}
};
var settings = $.extend({}, defaults, options);
$('#fade , #' + settings.id).fadeOut(function() {
$('#fade').remove();
});
// onInterstitialClose callback
settings.onInterstitialClose.call(this);
}
};
$.fn.interstitial = function( method ) {
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.interstitial' );
}
};
})( jQuery );