-
Notifications
You must be signed in to change notification settings - Fork 0
/
topmodal.js
86 lines (70 loc) · 2.67 KB
/
topmodal.js
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
;( function( $, window, document, undefined ) {
'use strict';
var pluginName = 'topmodal',
defaults = {
topmodal: '.js-topmodal',
topmodalBtn: '.js-topmodal-btn',
topmodalBtnClose: '.js-topmodal-btn-close',
topmodalContainer: '.js-topmodal-container',
topmodalOverlay: '.js-topmodal-overlay'
};
function Plugin ( element, options ) {
this.element = element;
this.settings = $.extend( {}, defaults, options );
this._defaults = defaults;
this._name = pluginName;
this.init();
}
$.extend( Plugin.prototype, {
init: function() {
var _obj = this.settings;
Plugin.prototype.handlerMethods( _obj );
},
handlerMethods: function( _obj ) {
$( document ).on( 'click', _obj.topmodalBtn, function() {
Plugin.prototype.show( _obj );
Plugin.prototype.showContainer( _obj );
Plugin.prototype.showOverlay( _obj );
});
$( document ).on( 'click', _obj.topmodalBtnClose, function() {
Plugin.prototype.hide( _obj );
Plugin.prototype.hideContainer( _obj );
Plugin.prototype.hideOverlay( _obj );
});
$( document ).on( 'click', _obj.topmodalContainer, function() {
Plugin.prototype.hide( _obj );
Plugin.prototype.hideContainer( _obj );
Plugin.prototype.hideOverlay( _obj );
});
$( document ).on( 'click', _obj.topmodal, function( event ) {
event.stopPropagation();
});
},
show: function( _obj ) {
$( _obj.topmodal ).addClass( 'is-open' );
},
hide: function( _obj ) {
$( _obj.topmodal ).removeClass( 'is-open' );
},
showContainer: function( _obj ) {
$( _obj.topmodalContainer ).addClass( 'is-open' );
},
hideContainer: function( _obj ) {
$( _obj.topmodalContainer ).removeClass( 'is-open' );
},
showOverlay: function( _obj ) {
$( _obj.topmodalOverlay ).addClass( 'is-open' );
},
hideOverlay: function( _obj ) {
$( _obj.topmodalOverlay ).removeClass( 'is-open' );
}
});
$.fn[ pluginName ] = function( options ) {
return this.each( function() {
if ( !$.data( this, "plugin_" + pluginName ) ) {
$.data( this, "plugin_" +
pluginName, new Plugin( this, options ) );
}
} );
};
} )( jQuery, window, document );