fae-rails 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,719 @@
1
+ /* Line 244 contains a hack derived from here: http://stackoverflow.com/a/18022855/2347675 to enable simplemodal in IE9 */
2
+
3
+ /*
4
+ * SimpleModal 1.4.4 - jQuery Plugin
5
+ * http://simplemodal.com/
6
+ * Copyright (c) 2013 Eric Martin
7
+ * Licensed under MIT and GPL
8
+ * Date: Sun, Jan 20 2013 15:58:56 -0800
9
+ */
10
+
11
+ /**
12
+ * SimpleModal is a lightweight jQuery plugin that provides a simple
13
+ * interface to create a modal dialog.
14
+ *
15
+ * The goal of SimpleModal is to provide developers with a cross-browser
16
+ * overlay and container that will be populated with data provided to
17
+ * SimpleModal.
18
+ *
19
+ * There are two ways to call SimpleModal:
20
+ * 1) As a chained function on a jQuery object, like $('#myDiv').modal();.
21
+ * This call would place the DOM object, #myDiv, inside a modal dialog.
22
+ * Chaining requires a jQuery object. An optional options object can be
23
+ * passed as a parameter.
24
+ *
25
+ * @example $('<div>my data</div>').modal({options});
26
+ * @example $('#myDiv').modal({options});
27
+ * @example jQueryObject.modal({options});
28
+ *
29
+ * 2) As a stand-alone function, like $.modal(data). The data parameter
30
+ * is required and an optional options object can be passed as a second
31
+ * parameter. This method provides more flexibility in the types of data
32
+ * that are allowed. The data could be a DOM object, a jQuery object, HTML
33
+ * or a string.
34
+ *
35
+ * @example $.modal('<div>my data</div>', {options});
36
+ * @example $.modal('my data', {options});
37
+ * @example $.modal($('#myDiv'), {options});
38
+ * @example $.modal(jQueryObject, {options});
39
+ * @example $.modal(document.getElementById('myDiv'), {options});
40
+ *
41
+ * A SimpleModal call can contain multiple elements, but only one modal
42
+ * dialog can be created at a time. Which means that all of the matched
43
+ * elements will be displayed within the modal container.
44
+ *
45
+ * SimpleModal internally sets the CSS needed to display the modal dialog
46
+ * properly in all browsers, yet provides the developer with the flexibility
47
+ * to easily control the look and feel. The styling for SimpleModal can be
48
+ * done through external stylesheets, or through SimpleModal, using the
49
+ * overlayCss, containerCss, and dataCss options.
50
+ *
51
+ * SimpleModal has been tested in the following browsers:
52
+ * - IE 6+
53
+ * - Firefox 2+
54
+ * - Opera 9+
55
+ * - Safari 3+
56
+ * - Chrome 1+
57
+ *
58
+ * @name SimpleModal
59
+ * @type jQuery
60
+ * @requires jQuery v1.3
61
+ * @cat Plugins/Windows and Overlays
62
+ * @author Eric Martin (http://ericmmartin.com)
63
+ * @version 1.4.4
64
+ */
65
+
66
+ ;(function (factory) {
67
+ if (typeof define === 'function' && define.amd) {
68
+ // AMD. Register as an anonymous module.
69
+ define(['jquery'], factory);
70
+ } else {
71
+ // Browser globals
72
+ factory(jQuery);
73
+ }
74
+ }
75
+ (function ($) {
76
+ var d = [],
77
+ doc = $(document),
78
+ ua = navigator.userAgent.toLowerCase(),
79
+ wndw = $(window),
80
+ w = [];
81
+
82
+ var browser = {
83
+ ieQuirks: null,
84
+ msie: /msie/.test(ua) && !/opera/.test(ua),
85
+ opera: /opera/.test(ua)
86
+ };
87
+ browser.ie6 = browser.msie && /msie 6./.test(ua) && typeof window['XMLHttpRequest'] !== 'object';
88
+ browser.ie7 = browser.msie && /msie 7.0/.test(ua);
89
+
90
+ /*
91
+ * Create and display a modal dialog.
92
+ *
93
+ * @param {string, object} data A string, jQuery object or DOM object
94
+ * @param {object} [options] An optional object containing options overrides
95
+ */
96
+ $.modal = function (data, options) {
97
+ return $.modal.impl.init(data, options);
98
+ };
99
+
100
+ /*
101
+ * Close the modal dialog.
102
+ */
103
+ $.modal.close = function () {
104
+ $.modal.impl.close();
105
+ };
106
+
107
+ /*
108
+ * Set focus on first or last visible input in the modal dialog. To focus on the last
109
+ * element, call $.modal.focus('last'). If no input elements are found, focus is placed
110
+ * on the data wrapper element.
111
+ */
112
+ $.modal.focus = function (pos) {
113
+ $.modal.impl.focus(pos);
114
+ };
115
+
116
+ /*
117
+ * Determine and set the dimensions of the modal dialog container.
118
+ * setPosition() is called if the autoPosition option is true.
119
+ */
120
+ $.modal.setContainerDimensions = function () {
121
+ $.modal.impl.setContainerDimensions();
122
+ };
123
+
124
+ /*
125
+ * Re-position the modal dialog.
126
+ */
127
+ $.modal.setPosition = function () {
128
+ $.modal.impl.setPosition();
129
+ };
130
+
131
+ /*
132
+ * Update the modal dialog. If new dimensions are passed, they will be used to determine
133
+ * the dimensions of the container.
134
+ *
135
+ * setContainerDimensions() is called, which in turn calls setPosition(), if enabled.
136
+ * Lastly, focus() is called is the focus option is true.
137
+ */
138
+ $.modal.update = function (height, width) {
139
+ $.modal.impl.update(height, width);
140
+ };
141
+
142
+ /*
143
+ * Chained function to create a modal dialog.
144
+ *
145
+ * @param {object} [options] An optional object containing options overrides
146
+ */
147
+ $.fn.modal = function (options) {
148
+ return $.modal.impl.init(this, options);
149
+ };
150
+
151
+ /*
152
+ * SimpleModal default options
153
+ *
154
+ * appendTo: (String:'body') The jQuery selector to append the elements to. For .NET, use 'form'.
155
+ * focus: (Boolean:true) Focus in the first visible, enabled element?
156
+ * opacity: (Number:50) The opacity value for the overlay div, from 0 - 100
157
+ * overlayId: (String:'simplemodal-overlay') The DOM element id for the overlay div
158
+ * overlayCss: (Object:{}) The CSS styling for the overlay div
159
+ * containerId: (String:'simplemodal-container') The DOM element id for the container div
160
+ * containerCss: (Object:{}) The CSS styling for the container div
161
+ * dataId: (String:'simplemodal-data') The DOM element id for the data div
162
+ * dataCss: (Object:{}) The CSS styling for the data div
163
+ * minHeight: (Number:null) The minimum height for the container
164
+ * minWidth: (Number:null) The minimum width for the container
165
+ * maxHeight: (Number:null) The maximum height for the container. If not specified, the window height is used.
166
+ * maxWidth: (Number:null) The maximum width for the container. If not specified, the window width is used.
167
+ * autoResize: (Boolean:false) Automatically resize the container if it exceeds the browser window dimensions?
168
+ * autoPosition: (Boolean:true) Automatically position the container upon creation and on window resize?
169
+ * zIndex: (Number: 1000) Starting z-index value
170
+ * close: (Boolean:true) If true, closeHTML, escClose and overClose will be used if set.
171
+ If false, none of them will be used.
172
+ * closeHTML: (String:'<a class="modalCloseImg" title="Close"></a>') The HTML for the default close link.
173
+ SimpleModal will automatically add the closeClass to this element.
174
+ * closeClass: (String:'simplemodal-close') The CSS class used to bind to the close event
175
+ * escClose: (Boolean:true) Allow Esc keypress to close the dialog?
176
+ * overlayClose: (Boolean:false) Allow click on overlay to close the dialog?
177
+ * fixed: (Boolean:true) If true, the container will use a fixed position. If false, it will use a
178
+ absolute position (the dialog will scroll with the page)
179
+ * position: (Array:null) Position of container [top, left]. Can be number of pixels or percentage
180
+ * persist: (Boolean:false) Persist the data across modal calls? Only used for existing
181
+ DOM elements. If true, the data will be maintained across modal calls, if false,
182
+ the data will be reverted to its original state.
183
+ * modal: (Boolean:true) User will be unable to interact with the page below the modal or tab away from the dialog.
184
+ If false, the overlay, iframe, and certain events will be disabled allowing the user to interact
185
+ with the page below the dialog.
186
+ * onOpen: (Function:null) The callback function used in place of SimpleModal's open
187
+ * onShow: (Function:null) The callback function used after the modal dialog has opened
188
+ * onClose: (Function:null) The callback function used in place of SimpleModal's close
189
+ */
190
+ $.modal.defaults = {
191
+ appendTo: 'body',
192
+ focus: true,
193
+ opacity: 50,
194
+ overlayId: 'simplemodal-overlay',
195
+ overlayCss: {},
196
+ containerId: 'simplemodal-container',
197
+ containerCss: {},
198
+ dataId: 'simplemodal-data',
199
+ dataCss: {},
200
+ minHeight: null,
201
+ minWidth: null,
202
+ maxHeight: null,
203
+ maxWidth: null,
204
+ autoResize: false,
205
+ autoPosition: true,
206
+ zIndex: 1000,
207
+ close: true,
208
+ closeHTML: '<a class="modalCloseImg" title="Close"></a>',
209
+ closeClass: 'simplemodal-close',
210
+ escClose: true,
211
+ overlayClose: false,
212
+ fixed: true,
213
+ position: null,
214
+ persist: false,
215
+ modal: true,
216
+ onOpen: null,
217
+ onShow: null,
218
+ onClose: null
219
+ };
220
+
221
+ /*
222
+ * Main modal object
223
+ * o = options
224
+ */
225
+ $.modal.impl = {
226
+ /*
227
+ * Contains the modal dialog elements and is the object passed
228
+ * back to the callback (onOpen, onShow, onClose) functions
229
+ */
230
+ d: {},
231
+ /*
232
+ * Initialize the modal dialog
233
+ */
234
+ init: function (data, options) {
235
+ var s = this;
236
+
237
+ // don't allow multiple calls
238
+ if (s.d.data) {
239
+ return false;
240
+ }
241
+
242
+ // $.support.boxModel is undefined if checked earlier
243
+ // browser.ieQuirks = browser.msie && !$.support.boxModel;
244
+ browser.ieQuirks = browser.msie && (document.compatMode === "BackCompat");
245
+
246
+ // merge defaults and user options
247
+ s.o = $.extend({}, $.modal.defaults, options);
248
+
249
+ // keep track of z-index
250
+ s.zIndex = s.o.zIndex;
251
+
252
+ // set the onClose callback flag
253
+ s.occb = false;
254
+
255
+ // determine how to handle the data based on its type
256
+ if (typeof data === 'object') {
257
+ // convert DOM object to a jQuery object
258
+ data = data instanceof $ ? data : $(data);
259
+ s.d.placeholder = false;
260
+
261
+ // if the object came from the DOM, keep track of its parent
262
+ if (data.parent().parent().size() > 0) {
263
+ data.before($('<span></span>')
264
+ .attr('id', 'simplemodal-placeholder')
265
+ .css({display: 'none'}));
266
+
267
+ s.d.placeholder = true;
268
+ s.display = data.css('display');
269
+
270
+ // persist changes? if not, make a clone of the element
271
+ if (!s.o.persist) {
272
+ s.d.orig = data.clone(true);
273
+ }
274
+ }
275
+ }
276
+ else if (typeof data === 'string' || typeof data === 'number') {
277
+ // just insert the data as innerHTML
278
+ data = $('<div></div>').html(data);
279
+ }
280
+ else {
281
+ // unsupported data type!
282
+ alert('SimpleModal Error: Unsupported data type: ' + typeof data);
283
+ return s;
284
+ }
285
+
286
+ // create the modal overlay, container and, if necessary, iframe
287
+ s.create(data);
288
+ data = null;
289
+
290
+ // display the modal dialog
291
+ s.open();
292
+
293
+ // useful for adding events/manipulating data in the modal dialog
294
+ if ($.isFunction(s.o.onShow)) {
295
+ s.o.onShow.apply(s, [s.d]);
296
+ }
297
+
298
+ // don't break the chain =)
299
+ return s;
300
+ },
301
+ /*
302
+ * Create and add the modal overlay and container to the page
303
+ */
304
+ create: function (data) {
305
+ var s = this;
306
+
307
+ // get the window properties
308
+ s.getDimensions();
309
+
310
+ // add an iframe to prevent select options from bleeding through
311
+ if (s.o.modal && browser.ie6) {
312
+ s.d.iframe = $('<iframe src="javascript:false;"></iframe>')
313
+ .css($.extend(s.o.iframeCss, {
314
+ display: 'none',
315
+ opacity: 0,
316
+ position: 'fixed',
317
+ height: w[0],
318
+ width: w[1],
319
+ zIndex: s.o.zIndex,
320
+ top: 0,
321
+ left: 0
322
+ }))
323
+ .appendTo(s.o.appendTo);
324
+ }
325
+
326
+ // create the overlay
327
+ s.d.overlay = $('<div></div>')
328
+ .attr('id', s.o.overlayId)
329
+ .addClass('simplemodal-overlay')
330
+ .css($.extend(s.o.overlayCss, {
331
+ display: 'none',
332
+ opacity: s.o.opacity / 100,
333
+ height: s.o.modal ? d[0] : 0,
334
+ width: s.o.modal ? d[1] : 0,
335
+ position: 'fixed',
336
+ left: 0,
337
+ top: 0,
338
+ zIndex: s.o.zIndex + 1
339
+ }))
340
+ .appendTo(s.o.appendTo);
341
+
342
+ // create the container
343
+ s.d.container = $('<div></div>')
344
+ .attr('id', s.o.containerId)
345
+ .addClass('simplemodal-container')
346
+ .css($.extend(
347
+ {position: s.o.fixed ? 'fixed' : 'absolute'},
348
+ s.o.containerCss,
349
+ {display: 'none', zIndex: s.o.zIndex + 2}
350
+ ))
351
+ .append(s.o.close && s.o.closeHTML
352
+ ? $(s.o.closeHTML).addClass(s.o.closeClass)
353
+ : '')
354
+ .appendTo(s.o.appendTo);
355
+
356
+ s.d.wrap = $('<div></div>')
357
+ .attr('tabIndex', -1)
358
+ .addClass('simplemodal-wrap')
359
+ .css({height: '100%', outline: 0, width: '100%'})
360
+ .appendTo(s.d.container);
361
+
362
+ // add styling and attributes to the data
363
+ // append to body to get correct dimensions, then move to wrap
364
+ s.d.data = data
365
+ .attr('id', data.attr('id') || s.o.dataId)
366
+ .addClass('simplemodal-data')
367
+ .css($.extend(s.o.dataCss, {
368
+ display: 'none'
369
+ }))
370
+ .appendTo('body');
371
+ data = null;
372
+
373
+ s.setContainerDimensions();
374
+ s.d.data.appendTo(s.d.wrap);
375
+
376
+ // fix issues with IE
377
+ if (browser.ie6 || browser.ieQuirks) {
378
+ s.fixIE();
379
+ }
380
+ },
381
+ /*
382
+ * Bind events
383
+ */
384
+ bindEvents: function () {
385
+ var s = this;
386
+
387
+ // bind the close event to any element with the closeClass class
388
+ $('.' + s.o.closeClass).bind('click.simplemodal', function (e) {
389
+ e.preventDefault();
390
+ s.close();
391
+ });
392
+
393
+ // bind the overlay click to the close function, if enabled
394
+ if (s.o.modal && s.o.close && s.o.overlayClose) {
395
+ s.d.overlay.bind('click.simplemodal', function (e) {
396
+ e.preventDefault();
397
+ s.close();
398
+ });
399
+ }
400
+
401
+ // bind keydown events
402
+ doc.bind('keydown.simplemodal', function (e) {
403
+ if (s.o.modal && e.keyCode === 9) { // TAB
404
+ s.watchTab(e);
405
+ }
406
+ else if ((s.o.close && s.o.escClose) && e.keyCode === 27) { // ESC
407
+ e.preventDefault();
408
+ s.close();
409
+ }
410
+ });
411
+
412
+ // update window size
413
+ wndw.bind('resize.simplemodal orientationchange.simplemodal', function () {
414
+ // redetermine the window width/height
415
+ s.getDimensions();
416
+
417
+ // reposition the dialog
418
+ s.o.autoResize ? s.setContainerDimensions() : s.o.autoPosition && s.setPosition();
419
+
420
+ if (browser.ie6 || browser.ieQuirks) {
421
+ s.fixIE();
422
+ }
423
+ else if (s.o.modal) {
424
+ // update the iframe & overlay
425
+ s.d.iframe && s.d.iframe.css({height: w[0], width: w[1]});
426
+ s.d.overlay.css({height: d[0], width: d[1]});
427
+ }
428
+ });
429
+ },
430
+ /*
431
+ * Unbind events
432
+ */
433
+ unbindEvents: function () {
434
+ $('.' + this.o.closeClass).unbind('click.simplemodal');
435
+ doc.unbind('keydown.simplemodal');
436
+ wndw.unbind('.simplemodal');
437
+ this.d.overlay.unbind('click.simplemodal');
438
+ },
439
+ /*
440
+ * Fix issues in IE6 and IE7 in quirks mode
441
+ */
442
+ fixIE: function () {
443
+ var s = this, p = s.o.position;
444
+
445
+ // simulate fixed position - adapted from BlockUI
446
+ $.each([s.d.iframe || null, !s.o.modal ? null : s.d.overlay, s.d.container.css('position') === 'fixed' ? s.d.container : null], function (i, el) {
447
+ if (el) {
448
+ var bch = 'document.body.clientHeight', bcw = 'document.body.clientWidth',
449
+ bsh = 'document.body.scrollHeight', bsl = 'document.body.scrollLeft',
450
+ bst = 'document.body.scrollTop', bsw = 'document.body.scrollWidth',
451
+ ch = 'document.documentElement.clientHeight', cw = 'document.documentElement.clientWidth',
452
+ sl = 'document.documentElement.scrollLeft', st = 'document.documentElement.scrollTop',
453
+ s = el[0].style;
454
+
455
+ s.position = 'absolute';
456
+ if (i < 2) {
457
+ s.removeExpression('height');
458
+ s.removeExpression('width');
459
+ s.setExpression('height','' + bsh + ' > ' + bch + ' ? ' + bsh + ' : ' + bch + ' + "px"');
460
+ s.setExpression('width','' + bsw + ' > ' + bcw + ' ? ' + bsw + ' : ' + bcw + ' + "px"');
461
+ }
462
+ else {
463
+ var te, le;
464
+ if (p && p.constructor === Array) {
465
+ var top = p[0]
466
+ ? typeof p[0] === 'number' ? p[0].toString() : p[0].replace(/px/, '')
467
+ : el.css('top').replace(/px/, '');
468
+ te = top.indexOf('%') === -1
469
+ ? top + ' + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"'
470
+ : parseInt(top.replace(/%/, '')) + ' * ((' + ch + ' || ' + bch + ') / 100) + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"';
471
+
472
+ if (p[1]) {
473
+ var left = typeof p[1] === 'number' ? p[1].toString() : p[1].replace(/px/, '');
474
+ le = left.indexOf('%') === -1
475
+ ? left + ' + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"'
476
+ : parseInt(left.replace(/%/, '')) + ' * ((' + cw + ' || ' + bcw + ') / 100) + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"';
477
+ }
478
+ }
479
+ else {
480
+ te = '(' + ch + ' || ' + bch + ') / 2 - (this.offsetHeight / 2) + (t = ' + st + ' ? ' + st + ' : ' + bst + ') + "px"';
481
+ le = '(' + cw + ' || ' + bcw + ') / 2 - (this.offsetWidth / 2) + (t = ' + sl + ' ? ' + sl + ' : ' + bsl + ') + "px"';
482
+ }
483
+ s.removeExpression('top');
484
+ s.removeExpression('left');
485
+ s.setExpression('top', te);
486
+ s.setExpression('left', le);
487
+ }
488
+ }
489
+ });
490
+ },
491
+ /*
492
+ * Place focus on the first or last visible input
493
+ */
494
+ focus: function (pos) {
495
+ var s = this, p = pos && $.inArray(pos, ['first', 'last']) !== -1 ? pos : 'first';
496
+
497
+ // focus on dialog or the first visible/enabled input element
498
+ var input = $(':input:enabled:visible:' + p, s.d.wrap);
499
+ setTimeout(function () {
500
+ input.length > 0 ? input.focus() : s.d.wrap.focus();
501
+ }, 10);
502
+ },
503
+ getDimensions: function () {
504
+ // fix a jQuery bug with determining the window height - use innerHeight if available
505
+ var s = this,
506
+ h = typeof window.innerHeight === 'undefined' ? wndw.height() : window.innerHeight;
507
+
508
+ d = [doc.height(), doc.width()];
509
+ w = [h, wndw.width()];
510
+ },
511
+ getVal: function (v, d) {
512
+ return v ? (typeof v === 'number' ? v
513
+ : v === 'auto' ? 0
514
+ : v.indexOf('%') > 0 ? ((parseInt(v.replace(/%/, '')) / 100) * (d === 'h' ? w[0] : w[1]))
515
+ : parseInt(v.replace(/px/, '')))
516
+ : null;
517
+ },
518
+ /*
519
+ * Update the container. Set new dimensions, if provided.
520
+ * Focus, if enabled. Re-bind events.
521
+ */
522
+ update: function (height, width) {
523
+ var s = this;
524
+
525
+ // prevent update if dialog does not exist
526
+ if (!s.d.data) {
527
+ return false;
528
+ }
529
+
530
+ // reset orig values
531
+ s.d.origHeight = s.getVal(height, 'h');
532
+ s.d.origWidth = s.getVal(width, 'w');
533
+
534
+ // hide data to prevent screen flicker
535
+ s.d.data.hide();
536
+ height && s.d.container.css('height', height);
537
+ width && s.d.container.css('width', width);
538
+ s.setContainerDimensions();
539
+ s.d.data.show();
540
+ s.o.focus && s.focus();
541
+
542
+ // rebind events
543
+ s.unbindEvents();
544
+ s.bindEvents();
545
+ },
546
+ setContainerDimensions: function () {
547
+ var s = this,
548
+ badIE = browser.ie6 || browser.ie7;
549
+
550
+ // get the dimensions for the container and data
551
+ var ch = s.d.origHeight ? s.d.origHeight : browser.opera ? s.d.container.height() : s.getVal(badIE ? s.d.container[0].currentStyle['height'] : s.d.container.css('height'), 'h'),
552
+ cw = s.d.origWidth ? s.d.origWidth : browser.opera ? s.d.container.width() : s.getVal(badIE ? s.d.container[0].currentStyle['width'] : s.d.container.css('width'), 'w'),
553
+ dh = s.d.data.outerHeight(true), dw = s.d.data.outerWidth(true);
554
+
555
+ s.d.origHeight = s.d.origHeight || ch;
556
+ s.d.origWidth = s.d.origWidth || cw;
557
+
558
+ // mxoh = max option height, mxow = max option width
559
+ var mxoh = s.o.maxHeight ? s.getVal(s.o.maxHeight, 'h') : null,
560
+ mxow = s.o.maxWidth ? s.getVal(s.o.maxWidth, 'w') : null,
561
+ mh = mxoh && mxoh < w[0] ? mxoh : w[0],
562
+ mw = mxow && mxow < w[1] ? mxow : w[1];
563
+
564
+ // moh = min option height
565
+ var moh = s.o.minHeight ? s.getVal(s.o.minHeight, 'h') : 'auto';
566
+ if (!ch) {
567
+ if (!dh) {ch = moh;}
568
+ else {
569
+ if (dh > mh) {ch = mh;}
570
+ else if (s.o.minHeight && moh !== 'auto' && dh < moh) {ch = moh;}
571
+ else {ch = dh;}
572
+ }
573
+ }
574
+ else {
575
+ ch = s.o.autoResize && ch > mh ? mh : ch < moh ? moh : ch;
576
+ }
577
+
578
+ // mow = min option width
579
+ var mow = s.o.minWidth ? s.getVal(s.o.minWidth, 'w') : 'auto';
580
+ if (!cw) {
581
+ if (!dw) {cw = mow;}
582
+ else {
583
+ if (dw > mw) {cw = mw;}
584
+ else if (s.o.minWidth && mow !== 'auto' && dw < mow) {cw = mow;}
585
+ else {cw = dw;}
586
+ }
587
+ }
588
+ else {
589
+ cw = s.o.autoResize && cw > mw ? mw : cw < mow ? mow : cw;
590
+ }
591
+
592
+ s.d.container.css({height: ch, width: cw});
593
+ s.d.wrap.css({overflow: (dh > ch || dw > cw) ? 'auto' : 'visible'});
594
+ s.o.autoPosition && s.setPosition();
595
+ },
596
+ setPosition: function () {
597
+ var s = this, top, left,
598
+ hc = (w[0]/2) - (s.d.container.outerHeight(true)/2),
599
+ vc = (w[1]/2) - (s.d.container.outerWidth(true)/2),
600
+ st = s.d.container.css('position') !== 'fixed' ? wndw.scrollTop() : 0;
601
+
602
+ if (s.o.position && Object.prototype.toString.call(s.o.position) === '[object Array]') {
603
+ top = st + (s.o.position[0] || hc);
604
+ left = s.o.position[1] || vc;
605
+ } else {
606
+ top = st + hc;
607
+ left = vc;
608
+ }
609
+ s.d.container.css({left: left, top: top});
610
+ },
611
+ watchTab: function (e) {
612
+ var s = this;
613
+
614
+ if ($(e.target).parents('.simplemodal-container').length > 0) {
615
+ // save the list of inputs
616
+ s.inputs = $(':input:enabled:visible:first, :input:enabled:visible:last', s.d.data[0]);
617
+
618
+ // if it's the first or last tabbable element, refocus
619
+ if ((!e.shiftKey && e.target === s.inputs[s.inputs.length -1]) ||
620
+ (e.shiftKey && e.target === s.inputs[0]) ||
621
+ s.inputs.length === 0) {
622
+ e.preventDefault();
623
+ var pos = e.shiftKey ? 'last' : 'first';
624
+ s.focus(pos);
625
+ }
626
+ }
627
+ else {
628
+ // might be necessary when custom onShow callback is used
629
+ e.preventDefault();
630
+ s.focus();
631
+ }
632
+ },
633
+ /*
634
+ * Open the modal dialog elements
635
+ * - Note: If you use the onOpen callback, you must "show" the
636
+ * overlay and container elements manually
637
+ * (the iframe will be handled by SimpleModal)
638
+ */
639
+ open: function () {
640
+ var s = this;
641
+ // display the iframe
642
+ s.d.iframe && s.d.iframe.show();
643
+
644
+ if ($.isFunction(s.o.onOpen)) {
645
+ // execute the onOpen callback
646
+ s.o.onOpen.apply(s, [s.d]);
647
+ }
648
+ else {
649
+ // display the remaining elements
650
+ s.d.overlay.show();
651
+ s.d.container.show();
652
+ s.d.data.show();
653
+ }
654
+
655
+ s.o.focus && s.focus();
656
+
657
+ // bind default events
658
+ s.bindEvents();
659
+ },
660
+ /*
661
+ * Close the modal dialog
662
+ * - Note: If you use an onClose callback, you must remove the
663
+ * overlay, container and iframe elements manually
664
+ *
665
+ * @param {boolean} external Indicates whether the call to this
666
+ * function was internal or external. If it was external, the
667
+ * onClose callback will be ignored
668
+ */
669
+ close: function () {
670
+ var s = this;
671
+
672
+ // prevent close when dialog does not exist
673
+ if (!s.d.data) {
674
+ return false;
675
+ }
676
+
677
+ // remove the default events
678
+ s.unbindEvents();
679
+
680
+ if ($.isFunction(s.o.onClose) && !s.occb) {
681
+ // set the onClose callback flag
682
+ s.occb = true;
683
+
684
+ // execute the onClose callback
685
+ s.o.onClose.apply(s, [s.d]);
686
+ }
687
+ else {
688
+ // if the data came from the DOM, put it back
689
+ if (s.d.placeholder) {
690
+ var ph = $('#simplemodal-placeholder');
691
+ // save changes to the data?
692
+ if (s.o.persist) {
693
+ // insert the (possibly) modified data back into the DOM
694
+ ph.replaceWith(s.d.data.removeClass('simplemodal-data').css('display', s.display));
695
+ }
696
+ else {
697
+ // remove the current and insert the original,
698
+ // unmodified data back into the DOM
699
+ s.d.data.hide().remove();
700
+ ph.replaceWith(s.d.orig);
701
+ }
702
+ }
703
+ else {
704
+ // otherwise, remove it
705
+ s.d.data.hide().remove();
706
+ }
707
+
708
+ // remove the remaining elements
709
+ s.d.container.hide().remove();
710
+ s.d.overlay.hide();
711
+ s.d.iframe && s.d.iframe.hide().remove();
712
+ s.d.overlay.remove();
713
+
714
+ // reset the dialog object
715
+ s.d = {};
716
+ }
717
+ }
718
+ };
719
+ }));