|
16 | 16 | (function(factory){ |
17 | 17 | if(typeof define === 'function' && define.amd){ |
18 | 18 | // AMD. Register as an anonymous module. |
19 | | - define(['jquery', 'window'], factory); |
| 19 | + define(['jquery'], factory); |
20 | 20 | }else if(typeof module === 'object' && module.exports){ |
21 | 21 | // Node/CommonJS |
22 | 22 | module.exports = function(root, jQuery){ |
|
32 | 32 | jQuery = require('jquery')(root); |
33 | 33 | } |
34 | 34 | } |
35 | | - factory(jQuery, window); |
| 35 | + factory(jQuery); |
36 | 36 | return jQuery; |
37 | 37 | }; |
38 | 38 | }else{ |
39 | 39 | // Browser globals |
40 | | - factory(jQuery, window); |
| 40 | + factory(jQuery); |
41 | 41 | } |
42 | | -}(function($, window){ |
| 42 | +}(function($){ |
43 | 43 | "use strict"; |
44 | | - var jconfirm, Jconfirm; |
| 44 | + |
| 45 | + // locally assign window |
| 46 | + var w = window; |
| 47 | + // w.jconfirm |
| 48 | + // w.Jconfirm; |
45 | 49 |
|
46 | 50 | $.fn.confirm = function(options, option2){ |
47 | 51 | if(typeof options === 'undefined') options = {}; |
|
73 | 77 |
|
74 | 78 | jcOption['$target'] = $this; |
75 | 79 | 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 || {}); |
77 | 81 | var firstBtn = Object.keys(buttons)[0]; |
78 | 82 | jcOption['buttons'] = buttons; |
79 | 83 | jcOption.buttons[firstBtn].action = function(){ |
|
103 | 107 | options['buttons'] = {}; |
104 | 108 |
|
105 | 109 | 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 || {}); |
107 | 111 | options['buttons'] = buttons; |
108 | 112 | } |
109 | 113 |
|
110 | 114 | /* |
111 | 115 | * Alias of jconfirm |
112 | 116 | */ |
113 | | - return jconfirm(options); |
| 117 | + return w.jconfirm(options); |
114 | 118 | }; |
115 | 119 | $.alert = function(options, option2){ |
116 | 120 | if(typeof options === 'undefined') options = {}; |
|
127 | 131 | options.buttons = {}; |
128 | 132 |
|
129 | 133 | 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 || {}); |
131 | 135 | var firstBtn = Object.keys(buttons)[0]; |
132 | 136 | options['buttons'][firstBtn] = buttons[firstBtn]; |
133 | 137 | } |
134 | 138 | /* |
135 | 139 | * Alias of jconfirm |
136 | 140 | */ |
137 | | - return jconfirm(options); |
| 141 | + return w.jconfirm(options); |
138 | 142 | }; |
139 | 143 | $.dialog = function(options, option2){ |
140 | 144 | if(typeof options === 'undefined') options = {}; |
|
159 | 163 | * Alias of jconfirm |
160 | 164 | */ |
161 | 165 | options.confirmKeys = [13]; |
162 | | - return jconfirm(options); |
| 166 | + return w.jconfirm(options); |
163 | 167 | }; |
164 | 168 |
|
165 | | - jconfirm = function(options){ |
| 169 | + w.jconfirm = function(options){ |
166 | 170 | if(typeof options === 'undefined') options = {}; |
167 | 171 | /* |
168 | 172 | * initial function for calling. |
169 | 173 | */ |
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); |
173 | 177 | } |
174 | 178 |
|
175 | 179 | /* |
176 | 180 | * merge options with plugin defaults. |
177 | 181 | */ |
178 | 182 | 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); |
181 | 185 | return instance; |
182 | 186 | }; |
183 | | - Jconfirm = function(options){ |
| 187 | + w.Jconfirm = function(options){ |
184 | 188 | /* |
185 | 189 | * constructor function Jconfirm, |
186 | 190 | * options = user options. |
187 | 191 | */ |
188 | 192 | $.extend(this, options); |
189 | 193 | this._init(); |
190 | 194 | }; |
191 | | - Jconfirm.prototype = { |
| 195 | + w.Jconfirm.prototype = { |
192 | 196 | _init: function(){ |
193 | 197 | var that = this; |
194 | 198 |
|
195 | | - if(!jconfirm.instances.length) |
196 | | - jconfirm.lastFocused = $('body').find(':focus'); |
| 199 | + if(!w.jconfirm.instances.length) |
| 200 | + w.jconfirm.lastFocused = $('body').find(':focus'); |
197 | 201 |
|
198 | 202 | this._id = Math.round(Math.random() * 99999); |
199 | 203 | /** |
|
317 | 321 | that._watchContent(); |
318 | 322 | }); |
319 | 323 |
|
320 | | - if (this.animation === 'none') { |
| 324 | + if(this.animation === 'none'){ |
321 | 325 | this.animationSpeed = 1; |
322 | 326 | this.animationBounce = 1; |
323 | 327 | } |
|
547 | 551 | if(that.smoothContent){ |
548 | 552 | var contentHeight = that.$content.outerHeight() || 0; |
549 | 553 | 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); |
556 | 560 | prevContentHeight = contentHeight; |
557 | 561 | } |
558 | 562 | var wh = $(window).height(); |
|
1089 | 1093 | setTimeout(function(){ |
1090 | 1094 | that.$el.remove(); |
1091 | 1095 |
|
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; |
1094 | 1098 | 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); |
1097 | 1101 | } |
1098 | 1102 | } |
1099 | 1103 |
|
1100 | 1104 | // Focusing a element, scrolls automatically to that element. |
1101 | 1105 | // 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; |
1105 | 1109 | if(that.scrollToPreviousElementAnimate){ |
1106 | 1110 | var st = $(window).scrollTop(); |
1107 | | - var ot = jconfirm.lastFocused.offset().top; |
| 1111 | + var ot = w.jconfirm.lastFocused.offset().top; |
1108 | 1112 | var wh = $(window).height(); |
1109 | 1113 | if(!(ot > st && ot < (st + wh))){ |
1110 | 1114 | var scrollTo = (ot - Math.round((wh / 3))); |
|
1121 | 1125 | }else{ |
1122 | 1126 | $lf.focus(); |
1123 | 1127 | } |
1124 | | - jconfirm.lastFocused = false; |
| 1128 | + w.jconfirm.lastFocused = false; |
1125 | 1129 | } |
1126 | 1130 | } |
1127 | 1131 |
|
|
1149 | 1153 |
|
1150 | 1154 | if(this.animateFromElement !== true && this.animateFromElement){ |
1151 | 1155 | 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; |
1156 | 1160 | }else{ |
1157 | 1161 | return false; |
1158 | 1162 | } |
|
1215 | 1219 | }, this.animationSpeed); |
1216 | 1220 | }, |
1217 | 1221 | loadedClass: 'jconfirm-open', |
1218 | | - isClosed: function () { |
| 1222 | + isClosed: function(){ |
1219 | 1223 | return !this.$el || this.$el.parent().length === 0; |
1220 | 1224 | }, |
1221 | 1225 | isOpen: function(){ |
|
1229 | 1233 | } |
1230 | 1234 | }; |
1231 | 1235 |
|
1232 | | - jconfirm.instances = []; |
1233 | | - jconfirm.lastFocused = false; |
1234 | | - jconfirm.pluginDefaults = { |
| 1236 | + w.jconfirm.instances = []; |
| 1237 | + w.jconfirm.lastFocused = false; |
| 1238 | + w.jconfirm.pluginDefaults = { |
1235 | 1239 | 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">×</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">×</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>', |
1266 | 1270 | title: 'Hello', |
1267 | 1271 | titleClass: '', |
1268 | 1272 | type: 'default', |
|
1368 | 1372 | $(window).on('keyup', function(){ |
1369 | 1373 | keyDown = false; |
1370 | 1374 | }); |
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); |
1374 | 1378 | }); |
1375 | 1379 | })); |
0 commit comments