Skip to content

Commit d1b3fb6

Browse files
committedJan 11, 2019
UMD fix, removed window as dependency, added jconfirm and Jconfirm as globals.
1 parent b548947 commit d1b3fb6

File tree

1 file changed

+82
-78
lines changed

1 file changed

+82
-78
lines changed
 

‎js/jquery-confirm.js

+82-78
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
(function(factory){
1717
if(typeof define === 'function' && define.amd){
1818
// AMD. Register as an anonymous module.
19-
define(['jquery', 'window'], factory);
19+
define(['jquery'], factory);
2020
}else if(typeof module === 'object' && module.exports){
2121
// Node/CommonJS
2222
module.exports = function(root, jQuery){
@@ -32,16 +32,20 @@
3232
jQuery = require('jquery')(root);
3333
}
3434
}
35-
factory(jQuery, window);
35+
factory(jQuery);
3636
return jQuery;
3737
};
3838
}else{
3939
// Browser globals
40-
factory(jQuery, window);
40+
factory(jQuery);
4141
}
42-
}(function($, window){
42+
}(function($){
4343
"use strict";
44-
var jconfirm, Jconfirm;
44+
45+
// locally assign window
46+
var w = window;
47+
// w.jconfirm
48+
// w.Jconfirm;
4549

4650
$.fn.confirm = function(options, option2){
4751
if(typeof options === 'undefined') options = {};
@@ -73,7 +77,7 @@
7377

7478
jcOption['$target'] = $this;
7579
if($this.attr('href') && Object.keys(jcOption['buttons']).length === 0){
76-
var buttons = $.extend(true, {}, jconfirm.pluginDefaults.defaultButtons, (jconfirm.defaults || {}).defaultButtons || {});
80+
var buttons = $.extend(true, {}, w.jconfirm.pluginDefaults.defaultButtons, (w.jconfirm.defaults || {}).defaultButtons || {});
7781
var firstBtn = Object.keys(buttons)[0];
7882
jcOption['buttons'] = buttons;
7983
jcOption.buttons[firstBtn].action = function(){
@@ -103,14 +107,14 @@
103107
options['buttons'] = {};
104108

105109
if(Object.keys(options['buttons']).length === 0 && putDefaultButtons){
106-
var buttons = $.extend(true, {}, jconfirm.pluginDefaults.defaultButtons, (jconfirm.defaults || {}).defaultButtons || {});
110+
var buttons = $.extend(true, {}, w.jconfirm.pluginDefaults.defaultButtons, (w.jconfirm.defaults || {}).defaultButtons || {});
107111
options['buttons'] = buttons;
108112
}
109113

110114
/*
111115
* Alias of jconfirm
112116
*/
113-
return jconfirm(options);
117+
return w.jconfirm(options);
114118
};
115119
$.alert = function(options, option2){
116120
if(typeof options === 'undefined') options = {};
@@ -127,14 +131,14 @@
127131
options.buttons = {};
128132

129133
if(Object.keys(options['buttons']).length === 0 && putDefaultButtons){
130-
var buttons = $.extend(true, {}, jconfirm.pluginDefaults.defaultButtons, (jconfirm.defaults || {}).defaultButtons || {});
134+
var buttons = $.extend(true, {}, w.jconfirm.pluginDefaults.defaultButtons, (w.jconfirm.defaults || {}).defaultButtons || {});
131135
var firstBtn = Object.keys(buttons)[0];
132136
options['buttons'][firstBtn] = buttons[firstBtn];
133137
}
134138
/*
135139
* Alias of jconfirm
136140
*/
137-
return jconfirm(options);
141+
return w.jconfirm(options);
138142
};
139143
$.dialog = function(options, option2){
140144
if(typeof options === 'undefined') options = {};
@@ -159,41 +163,41 @@
159163
* Alias of jconfirm
160164
*/
161165
options.confirmKeys = [13];
162-
return jconfirm(options);
166+
return w.jconfirm(options);
163167
};
164168

165-
jconfirm = function(options){
169+
w.jconfirm = function(options){
166170
if(typeof options === 'undefined') options = {};
167171
/*
168172
* initial function for calling.
169173
*/
170-
var pluginOptions = $.extend(true, {}, jconfirm.pluginDefaults);
171-
if(jconfirm.defaults){
172-
pluginOptions = $.extend(true, pluginOptions, jconfirm.defaults);
174+
var pluginOptions = $.extend(true, {}, w.jconfirm.pluginDefaults);
175+
if(w.jconfirm.defaults){
176+
pluginOptions = $.extend(true, pluginOptions, w.jconfirm.defaults);
173177
}
174178

175179
/*
176180
* merge options with plugin defaults.
177181
*/
178182
pluginOptions = $.extend(true, {}, pluginOptions, options);
179-
var instance = new Jconfirm(pluginOptions);
180-
jconfirm.instances.push(instance);
183+
var instance = new w.Jconfirm(pluginOptions);
184+
w.jconfirm.instances.push(instance);
181185
return instance;
182186
};
183-
Jconfirm = function(options){
187+
w.Jconfirm = function(options){
184188
/*
185189
* constructor function Jconfirm,
186190
* options = user options.
187191
*/
188192
$.extend(this, options);
189193
this._init();
190194
};
191-
Jconfirm.prototype = {
195+
w.Jconfirm.prototype = {
192196
_init: function(){
193197
var that = this;
194198

195-
if(!jconfirm.instances.length)
196-
jconfirm.lastFocused = $('body').find(':focus');
199+
if(!w.jconfirm.instances.length)
200+
w.jconfirm.lastFocused = $('body').find(':focus');
197201

198202
this._id = Math.round(Math.random() * 99999);
199203
/**
@@ -317,7 +321,7 @@
317321
that._watchContent();
318322
});
319323

320-
if (this.animation === 'none') {
324+
if(this.animation === 'none'){
321325
this.animationSpeed = 1;
322326
this.animationBounce = 1;
323327
}
@@ -547,12 +551,12 @@
547551
if(that.smoothContent){
548552
var contentHeight = that.$content.outerHeight() || 0;
549553
if(contentHeight !== prevContentHeight){
550-
551-
// Commented out to prevent scroll to top when updating the content
552-
// (for example when using ajax in forms in content)
553-
// that.$contentPane.css({
554-
// 'height': contentHeight
555-
// }).scrollTop(0);
554+
555+
// Commented out to prevent scroll to top when updating the content
556+
// (for example when using ajax in forms in content)
557+
// that.$contentPane.css({
558+
// 'height': contentHeight
559+
// }).scrollTop(0);
556560
prevContentHeight = contentHeight;
557561
}
558562
var wh = $(window).height();
@@ -1089,22 +1093,22 @@
10891093
setTimeout(function(){
10901094
that.$el.remove();
10911095

1092-
var l = jconfirm.instances;
1093-
var i = jconfirm.instances.length - 1;
1096+
var l = w.jconfirm.instances;
1097+
var i = w.jconfirm.instances.length - 1;
10941098
for(i; i >= 0; i--){
1095-
if(jconfirm.instances[i]._id === that._id){
1096-
jconfirm.instances.splice(i, 1);
1099+
if(w.jconfirm.instances[i]._id === that._id){
1100+
w.jconfirm.instances.splice(i, 1);
10971101
}
10981102
}
10991103

11001104
// Focusing a element, scrolls automatically to that element.
11011105
// no instances should be open, lastFocused should be true, the lastFocused element must exists in DOM
1102-
if(!jconfirm.instances.length){
1103-
if(that.scrollToPreviousElement && jconfirm.lastFocused && jconfirm.lastFocused.length && $.contains(document, jconfirm.lastFocused[0])){
1104-
var $lf = jconfirm.lastFocused;
1106+
if(!w.jconfirm.instances.length){
1107+
if(that.scrollToPreviousElement && w.jconfirm.lastFocused && w.jconfirm.lastFocused.length && $.contains(document, w.jconfirm.lastFocused[0])){
1108+
var $lf = w.jconfirm.lastFocused;
11051109
if(that.scrollToPreviousElementAnimate){
11061110
var st = $(window).scrollTop();
1107-
var ot = jconfirm.lastFocused.offset().top;
1111+
var ot = w.jconfirm.lastFocused.offset().top;
11081112
var wh = $(window).height();
11091113
if(!(ot > st && ot < (st + wh))){
11101114
var scrollTo = (ot - Math.round((wh / 3)));
@@ -1121,7 +1125,7 @@
11211125
}else{
11221126
$lf.focus();
11231127
}
1124-
jconfirm.lastFocused = false;
1128+
w.jconfirm.lastFocused = false;
11251129
}
11261130
}
11271131

@@ -1149,10 +1153,10 @@
11491153

11501154
if(this.animateFromElement !== true && this.animateFromElement){
11511155
el = this.animateFromElement;
1152-
jconfirm.lastClicked = false;
1153-
}else if(jconfirm.lastClicked && this.animateFromElement === true){
1154-
el = jconfirm.lastClicked;
1155-
jconfirm.lastClicked = false;
1156+
w.jconfirm.lastClicked = false;
1157+
}else if(w.jconfirm.lastClicked && this.animateFromElement === true){
1158+
el = w.jconfirm.lastClicked;
1159+
w.jconfirm.lastClicked = false;
11561160
}else{
11571161
return false;
11581162
}
@@ -1215,7 +1219,7 @@
12151219
}, this.animationSpeed);
12161220
},
12171221
loadedClass: 'jconfirm-open',
1218-
isClosed: function () {
1222+
isClosed: function(){
12191223
return !this.$el || this.$el.parent().length === 0;
12201224
},
12211225
isOpen: function(){
@@ -1229,40 +1233,40 @@
12291233
}
12301234
};
12311235

1232-
jconfirm.instances = [];
1233-
jconfirm.lastFocused = false;
1234-
jconfirm.pluginDefaults = {
1236+
w.jconfirm.instances = [];
1237+
w.jconfirm.lastFocused = false;
1238+
w.jconfirm.pluginDefaults = {
12351239
template: '' +
1236-
'<div class="jconfirm">' +
1237-
'<div class="jconfirm-bg jconfirm-bg-h"></div>' +
1238-
'<div class="jconfirm-scrollpane">' +
1239-
'<div class="jconfirm-row">' +
1240-
'<div class="jconfirm-cell">' +
1241-
'<div class="jconfirm-holder">' +
1242-
'<div class="jc-bs3-container">' +
1243-
'<div class="jc-bs3-row">' +
1244-
'<div class="jconfirm-box-container jconfirm-animated">' +
1245-
'<div class="jconfirm-box" role="dialog" aria-labelledby="labelled" tabindex="-1">' +
1246-
'<div class="jconfirm-closeIcon">&times;</div>' +
1247-
'<div class="jconfirm-title-c">' +
1248-
'<span class="jconfirm-icon-c"></span>' +
1249-
'<span class="jconfirm-title"></span>' +
1250-
'</div>' +
1251-
'<div class="jconfirm-content-pane">' +
1252-
'<div class="jconfirm-content"></div>' +
1253-
'</div>' +
1254-
'<div class="jconfirm-buttons">' +
1255-
'</div>' +
1256-
'<div class="jconfirm-clear">' +
1257-
'</div>' +
1258-
'</div>' +
1259-
'</div>' +
1260-
'</div>' +
1261-
'</div>' +
1262-
'</div>' +
1263-
'</div>' +
1264-
'</div>' +
1265-
'</div></div>',
1240+
'<div class="jconfirm">' +
1241+
'<div class="jconfirm-bg jconfirm-bg-h"></div>' +
1242+
'<div class="jconfirm-scrollpane">' +
1243+
'<div class="jconfirm-row">' +
1244+
'<div class="jconfirm-cell">' +
1245+
'<div class="jconfirm-holder">' +
1246+
'<div class="jc-bs3-container">' +
1247+
'<div class="jc-bs3-row">' +
1248+
'<div class="jconfirm-box-container jconfirm-animated">' +
1249+
'<div class="jconfirm-box" role="dialog" aria-labelledby="labelled" tabindex="-1">' +
1250+
'<div class="jconfirm-closeIcon">&times;</div>' +
1251+
'<div class="jconfirm-title-c">' +
1252+
'<span class="jconfirm-icon-c"></span>' +
1253+
'<span class="jconfirm-title"></span>' +
1254+
'</div>' +
1255+
'<div class="jconfirm-content-pane">' +
1256+
'<div class="jconfirm-content"></div>' +
1257+
'</div>' +
1258+
'<div class="jconfirm-buttons">' +
1259+
'</div>' +
1260+
'<div class="jconfirm-clear">' +
1261+
'</div>' +
1262+
'</div>' +
1263+
'</div>' +
1264+
'</div>' +
1265+
'</div>' +
1266+
'</div>' +
1267+
'</div>' +
1268+
'</div>' +
1269+
'</div></div>',
12661270
title: 'Hello',
12671271
titleClass: '',
12681272
type: 'default',
@@ -1368,8 +1372,8 @@
13681372
$(window).on('keyup', function(){
13691373
keyDown = false;
13701374
});
1371-
jconfirm.lastClicked = false;
1372-
$(document).on('mousedown', 'button, a', function(){
1373-
jconfirm.lastClicked = $(this);
1375+
w.jconfirm.lastClicked = false;
1376+
$(document).on('mousedown', 'button, a, [jc-source]', function(){
1377+
w.jconfirm.lastClicked = $(this);
13741378
});
13751379
}));

0 commit comments

Comments
 (0)
Please sign in to comment.