webshims-rails 1.14.4 → 1.14.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Rakefile +58 -0
  4. data/lib/webshims-rails/version.rb +2 -2
  5. data/vendor/assets/javascripts/webshims/polyfiller.js +45 -26
  6. data/vendor/assets/javascripts/webshims/shims/combos/1.js +18 -5
  7. data/vendor/assets/javascripts/webshims/shims/combos/10.js +26 -22
  8. data/vendor/assets/javascripts/webshims/shims/combos/11.js +24 -21
  9. data/vendor/assets/javascripts/webshims/shims/combos/12.js +4 -0
  10. data/vendor/assets/javascripts/webshims/shims/combos/13.js +4 -0
  11. data/vendor/assets/javascripts/webshims/shims/combos/14.js +0 -1
  12. data/vendor/assets/javascripts/webshims/shims/combos/15.js +17 -7
  13. data/vendor/assets/javascripts/webshims/shims/combos/16.js +21 -7
  14. data/vendor/assets/javascripts/webshims/shims/combos/17.js +24 -22
  15. data/vendor/assets/javascripts/webshims/shims/combos/18.js +122 -97
  16. data/vendor/assets/javascripts/webshims/shims/combos/2.js +20 -6
  17. data/vendor/assets/javascripts/webshims/shims/combos/21.js +4 -3
  18. data/vendor/assets/javascripts/webshims/shims/combos/23.js +4 -0
  19. data/vendor/assets/javascripts/webshims/shims/combos/25.js +7 -5
  20. data/vendor/assets/javascripts/webshims/shims/combos/26.js +1 -1
  21. data/vendor/assets/javascripts/webshims/shims/combos/27.js +29 -9
  22. data/vendor/assets/javascripts/webshims/shims/combos/28.js +1 -2
  23. data/vendor/assets/javascripts/webshims/shims/combos/29.js +0 -1
  24. data/vendor/assets/javascripts/webshims/shims/combos/3.js +16 -6
  25. data/vendor/assets/javascripts/webshims/shims/combos/30.js +16 -6
  26. data/vendor/assets/javascripts/webshims/shims/combos/31.js +16 -6
  27. data/vendor/assets/javascripts/webshims/shims/combos/33.js +0 -1
  28. data/vendor/assets/javascripts/webshims/shims/combos/34.js +2 -1
  29. data/vendor/assets/javascripts/webshims/shims/combos/4.js +2 -1
  30. data/vendor/assets/javascripts/webshims/shims/combos/5.js +24 -22
  31. data/vendor/assets/javascripts/webshims/shims/combos/6.js +24 -22
  32. data/vendor/assets/javascripts/webshims/shims/combos/7.js +20 -6
  33. data/vendor/assets/javascripts/webshims/shims/combos/8.js +20 -6
  34. data/vendor/assets/javascripts/webshims/shims/combos/9.js +26 -22
  35. data/vendor/assets/javascripts/webshims/shims/combos/97.js +0 -24
  36. data/vendor/assets/javascripts/webshims/shims/combos/98.js +22 -25
  37. data/vendor/assets/javascripts/webshims/shims/combos/99.js +22 -25
  38. data/vendor/assets/javascripts/webshims/shims/dom-extend.js +2 -1
  39. data/vendor/assets/javascripts/webshims/shims/filereader.js +1 -1
  40. data/vendor/assets/javascripts/webshims/shims/form-core.js +14 -5
  41. data/vendor/assets/javascripts/webshims/shims/form-datalist-lazy.js +8 -4
  42. data/vendor/assets/javascripts/webshims/shims/form-number-date-api.js +0 -1
  43. data/vendor/assets/javascripts/webshims/shims/form-number-date-ui.js +24 -21
  44. data/vendor/assets/javascripts/webshims/shims/form-shim-extend.js +1 -1
  45. data/vendor/assets/javascripts/webshims/shims/form-shim-extend2.js +28 -8
  46. data/vendor/assets/javascripts/webshims/shims/form-validation.js +17 -20
  47. data/vendor/assets/javascripts/webshims/shims/form-validators.js +17 -10
  48. data/vendor/assets/javascripts/webshims/shims/forms-picker.js +3 -3
  49. data/vendor/assets/javascripts/webshims/shims/jme/base.js +0 -24
  50. data/vendor/assets/javascripts/webshims/shims/jme/controls.css +23 -9
  51. data/vendor/assets/javascripts/webshims/shims/jme/controls.scss +21 -3
  52. data/vendor/assets/javascripts/webshims/shims/jme/mediacontrols-lazy.js +13 -4
  53. data/vendor/assets/javascripts/webshims/shims/jme/mediacontrols.js +22 -1
  54. data/vendor/assets/javascripts/webshims/shims/mediaelement-core.js +4 -0
  55. data/vendor/assets/javascripts/webshims/shims/mediaelement-jaris.js +4 -3
  56. data/vendor/assets/javascripts/webshims/shims/picture.js +122 -97
  57. data/vendor/assets/javascripts/webshims/shims/plugins/jquery.ui.position.js +470 -452
  58. data/vendor/assets/javascripts/webshims/shims/sizzle.js +35 -27
  59. data/vendor/assets/javascripts/webshims/shims/styles/forms-ext.css +10 -2
  60. data/vendor/assets/javascripts/webshims/shims/styles/forms-picker.css +1 -1
  61. data/vendor/assets/javascripts/webshims/shims/styles/scss/_api-forms-ext.scss +10 -0
  62. data/vendor/assets/javascripts/webshims/shims/styles/scss/forms-ext.scss +4 -2
  63. data/vendor/assets/javascripts/webshims/shims/styles/scss/forms-picker.scss +1 -1
  64. data/vendor/assets/javascripts/webshims/shims/styles/scss/shim.scss +6 -24
  65. data/vendor/assets/javascripts/webshims/shims/styles/shim-ext.css +15 -21
  66. data/vendor/assets/javascripts/webshims/shims/styles/shim.css +5 -19
  67. data/vendor/assets/javascripts/webshims/shims/track-ui.js +2 -2
  68. metadata +2 -3
  69. data/vendor/assets/javascripts/webshims/shims/promise.js +0 -684
@@ -531,6 +531,10 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
531
531
  webshims.ready(swfType, initMediaElements);
532
532
  }
533
533
  webshims.ready('track', loadTrackUi);
534
+
535
+ if(document.readyState == 'complete'){
536
+ webshims.isReady('WINDOWLOAD', true);
537
+ }
534
538
  });
535
539
 
536
540
  })(webshims);
@@ -127,6 +127,7 @@ webshims.register('mediaelement-jaris', function($, webshims, window, document,
127
127
  var onEvent = {
128
128
  onPlayPause: function(jaris, data, override){
129
129
  var playing, type;
130
+ var idled = data.paused || data.ended;
130
131
  if(override == null){
131
132
  try {
132
133
  playing = data.api.api_get("isPlaying");
@@ -134,7 +135,7 @@ webshims.register('mediaelement-jaris', function($, webshims, window, document,
134
135
  } else {
135
136
  playing = override;
136
137
  }
137
- if(playing == data.paused){
138
+ if(playing == idled || playing == null){
138
139
 
139
140
  data.paused = !playing;
140
141
  type = data.paused ? 'pause' : 'play';
@@ -1211,11 +1212,11 @@ webshims.register('mediaelement-jaris', function($, webshims, window, document,
1211
1212
  var media, error, parent;
1212
1213
  if(
1213
1214
  ($(e.target).is('audio, video') || ((parent = e.target.parentNode) && $('source', parent).last()[0] == e.target)) &&
1214
- (media = $(e.target).closest('audio, video')) && !media.is('.nonnative-api-active')
1215
+ (media = $(e.target).closest('audio, video')) && !media.hasClass('nonnative-api-active')
1215
1216
  ){
1216
1217
  error = media.prop('error');
1217
1218
  setTimeout(function(){
1218
- if(!media.is('.nonnative-api-active')){
1219
+ if(!media.hasClass('nonnative-api-active')){
1219
1220
  if(error && switchErrors[error.code]){
1220
1221
  options.preferFlash = true;
1221
1222
  document.removeEventListener('error', switchOptions, true);
@@ -10,23 +10,65 @@
10
10
 
11
11
  webshim.isReady('picture', true);
12
12
  setTimeout(function(){
13
- webshim.ready('matchMedia', function(){
14
- if(window.picturefill){
15
- var sel = 'picture, img[srcset]';
16
- webshim.addReady(function(context){
17
- if(context.querySelector(sel)){
18
- window.picturefill();
19
- }
20
- });
21
- }
22
- });
13
+ if(window.picturefill){
14
+ var sel = 'picture, img[srcset]';
15
+ webshim.addReady(function(context){
16
+ if(context.querySelector(sel)){
17
+ window.picturefill();
18
+ }
19
+ });
20
+ }
23
21
  });
24
22
  })();
25
-
26
- /*! Picturefill - v2.1.0-beta - 2014-06-03
23
+ /*! Picturefill - v2.1.0-beta - 2014-07-15
27
24
  * http://scottjehl.github.io/picturefill
28
25
  * Copyright (c) 2014 https://github.com/scottjehl/picturefill/blob/master/Authors.txt; Licensed MIT */
26
+ /*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas, David Knight. Dual MIT/BSD license */
27
+
28
+ window.matchMedia || (window.matchMedia = function() {
29
+ "use strict";
30
+
31
+ // For browsers that support matchMedium api such as IE 9 and webkit
32
+ var styleMedia = (window.styleMedia || window.media);
33
+
34
+ // For those that don't support matchMedium
35
+ if (!styleMedia) {
36
+ var style = document.createElement('style'),
37
+ script = document.getElementsByTagName('script')[0],
38
+ info = null;
39
+
40
+ style.type = 'text/css';
41
+ style.id = 'matchmediajs-test';
42
+
43
+ script.parentNode.insertBefore(style, script);
29
44
 
45
+ // 'style.currentStyle' is used by IE <= 8 and 'window.getComputedStyle' for all other browsers
46
+ info = ('getComputedStyle' in window) && window.getComputedStyle(style, null) || style.currentStyle;
47
+
48
+ styleMedia = {
49
+ matchMedium: function(media) {
50
+ var text = '@media ' + media + '{ #matchmediajs-test { width: 1px; } }';
51
+
52
+ // 'style.styleSheet' is used by IE <= 8 and 'style.textContent' for all other browsers
53
+ if (style.styleSheet) {
54
+ style.styleSheet.cssText = text;
55
+ } else {
56
+ style.textContent = text;
57
+ }
58
+
59
+ // Test if media query is true or false
60
+ return info.width === '1px';
61
+ }
62
+ };
63
+ }
64
+
65
+ return function(media) {
66
+ return {
67
+ matches: styleMedia.matchMedium(media || 'all'),
68
+ media: media || 'all'
69
+ };
70
+ };
71
+ }());
30
72
  /*! Picturefill - Responsive Images that work today.
31
73
  * Author: Scott Jehl, Filament Group, 2012 ( new proposal implemented by Shawn Jansepar )
32
74
  * License: MIT/GPLv2
@@ -38,6 +80,7 @@
38
80
 
39
81
  // If picture is supported, well, that's awesome. Let's get outta here...
40
82
  if ( w.HTMLPictureElement ) {
83
+ w.picturefill = function() { };
41
84
  return;
42
85
  }
43
86
 
@@ -51,7 +94,8 @@
51
94
  pf.ns = "picturefill";
52
95
 
53
96
  // srcset support test
54
- pf.srcsetSupported = new w.Image().srcset !== undefined;
97
+ pf.srcsetSupported = "srcset" in doc.createElement( "img" );
98
+ pf.sizesSupported = w.HTMLImageElement.sizes;
55
99
 
56
100
  // just a string trim workaround
57
101
  pf.trim = function( str ) {
@@ -82,8 +126,8 @@
82
126
  * http://dev.w3.org/csswg/css-values-3/#length-value
83
127
  */
84
128
  pf.getWidthFromLength = function( length ) {
85
- // If no length was specified, or it is 0, default to `100vw` (per the spec).
86
- length = length && parseFloat( length ) > 0 ? length : "100vw";
129
+ // If no length was specified, or it is 0 or negative, default to `100vw` (per the spec).
130
+ length = length && ( parseFloat( length ) > 0 || length.indexOf( "calc(" ) > -1 ) ? length : "100vw";
87
131
 
88
132
  /**
89
133
  * If length is specified in `vw` units, use `%` instead since the div we’re measuring
@@ -101,7 +145,12 @@
101
145
 
102
146
  // Positioning styles help prevent padding/margin/width on `html` from throwing calculations off.
103
147
  pf.lengthEl.style.cssText = "position: absolute; left: 0; width: " + length + ";";
104
- // Using offsetWidth to get width from CSS
148
+
149
+ if ( pf.lengthEl.offsetWidth <= 0 ) {
150
+ // Something has gone wrong. `calc()` is in use and unsupported, most likely. Default to `100vw` (`100%`, for broader support.):
151
+ pf.lengthEl.style.cssText = "width: 100%;";
152
+ }
153
+
105
154
  return pf.lengthEl.offsetWidth;
106
155
  };
107
156
 
@@ -263,38 +312,32 @@
263
312
  return candidates;
264
313
  };
265
314
 
266
- pf.parseDescriptor = function( descriptor, sizes ) {
315
+ pf.parseDescriptor = function( descriptor, sizesattr ) {
267
316
  // 11. Descriptor parser: Let candidates be an initially empty source set. The order of entries in the list
268
317
  // is the order in which entries are added to the list.
269
- var sizeDescriptor = descriptor && descriptor.replace(/(^\s+|\s+$)/g, ""),
270
- widthInCssPixels = sizes ? pf.findWidthFromSourceSize( sizes ) : "100%",
318
+ var sizes = sizesattr || "100vw",
319
+ sizeDescriptor = descriptor && descriptor.replace(/(^\s+|\s+$)/g, ""),
320
+ widthInCssPixels = pf.findWidthFromSourceSize( sizes ),
271
321
  resCandidate;
272
322
 
273
323
  if ( sizeDescriptor ) {
274
324
  var splitDescriptor = sizeDescriptor.split(" ");
275
325
 
276
326
  for (var i = splitDescriptor.length + 1; i >= 0; i--) {
277
-
278
- var curr = splitDescriptor[ i ],
279
- lastchar = curr && curr.slice( curr.length - 1 );
280
-
281
- if ( lastchar === "w" || lastchar === "x" ) {
282
- resCandidate = curr;
283
- }
284
- if ( sizes && resCandidate ) {
285
- // get the dpr by taking the length / width in css pixels
286
- resCandidate = parseFloat( ( parseInt( curr, 10 ) / widthInCssPixels ) );
287
- } else {
288
- // get the dpr by grabbing the value of Nx
289
- var res = curr && parseFloat( curr, 10 );
290
-
291
- resCandidate = res && !isNaN( res ) && lastchar === "x" || lastchar === "w" ? res : 1;
327
+ if ( splitDescriptor[ i ] !== undefined ) {
328
+ var curr = splitDescriptor[ i ],
329
+ lastchar = curr && curr.slice( curr.length - 1 );
330
+
331
+ if ( ( lastchar === "h" || lastchar === "w" ) && !pf.sizesSupported ) {
332
+ resCandidate = parseFloat( ( parseInt( curr, 10 ) / widthInCssPixels ) );
333
+ } else if ( lastchar === "x" ) {
334
+ var res = curr && parseFloat( curr, 10 );
335
+ resCandidate = res && !isNaN( res ) ? res : 1;
336
+ }
292
337
  }
293
338
  }
294
- } else {
295
- resCandidate = 1;
296
339
  }
297
- return resCandidate;
340
+ return resCandidate || 1;
298
341
  };
299
342
 
300
343
  /**
@@ -372,7 +415,7 @@
372
415
  }
373
416
  }
374
417
 
375
- if ( !pf.endsWith( picImg.src, bestCandidate.url ) ) {
418
+ if ( bestCandidate && !pf.endsWith( picImg.src, bestCandidate.url ) ) {
376
419
  picImg.src = bestCandidate.url;
377
420
  // currentSrc attribute and property to match
378
421
  // http://picture.responsiveimages.org/#the-img-element
@@ -405,32 +448,26 @@
405
448
  };
406
449
 
407
450
  /*
408
- * Find all picture elements and,
409
- * in browsers that don't natively support srcset, find all img elements
410
- * with srcset attrs that don't have picture parents
451
+ * Find all `img` elements, and add them to the candidate list if they have
452
+ * a `picture` parent, a `sizes` attribute in basic `srcset` supporting browsers,
453
+ * a `srcset` attribute at all, and they haven’t been evaluated already.
411
454
  */
412
455
  pf.getAllElements = function() {
413
- var pictures = doc.getElementsByTagName( "picture" ),
414
- elems = [],
456
+ var elems = [],
415
457
  imgs = doc.getElementsByTagName( "img" );
416
458
 
417
- for ( var h = 0, len = pictures.length + imgs.length; h < len; h++ ) {
418
- if ( h < pictures.length ) {
419
- elems[ h ] = pictures[ h ];
420
- } else {
421
- var currImg = imgs[ h - pictures.length ];
459
+ for ( var h = 0, len = imgs.length; h < len; h++ ) {
460
+ var currImg = imgs[ h ];
422
461
 
423
- if ( currImg.parentNode.nodeName.toUpperCase() !== "PICTURE" &&
424
- ( ( pf.srcsetSupported && currImg.getAttribute( "sizes" ) ) ||
425
- currImg.getAttribute( "srcset" ) !== null ) ) {
426
- elems.push( currImg );
427
- }
462
+ if ( currImg.parentNode.nodeName.toUpperCase() === "PICTURE" ||
463
+ ( currImg.getAttribute( "srcset" ) !== null ) || currImg[ pf.ns ] && currImg[ pf.ns ].srcset !== null ) {
464
+ elems.push( currImg );
428
465
  }
429
466
  }
430
467
  return elems;
431
468
  };
432
469
 
433
- pf.getMatch = function( picture ) {
470
+ pf.getMatch = function( img, picture ) {
434
471
  var sources = picture.childNodes,
435
472
  match;
436
473
 
@@ -443,9 +480,9 @@
443
480
  continue;
444
481
  }
445
482
 
446
- // Hitting an `img` element stops the search for `sources`.
483
+ // Hitting the `img` element that started everything stops the search for `sources`.
447
484
  // If no previous `source` matches, the `img` itself is evaluated later.
448
- if ( source.nodeName.toUpperCase() === "IMG" ) {
485
+ if ( source === img ) {
449
486
  return match;
450
487
  }
451
488
 
@@ -477,24 +514,22 @@
477
514
  return match;
478
515
  };
479
516
 
480
- function picturefill( options ) {
517
+ function picturefill( opt ) {
481
518
  var elements,
482
519
  element,
483
- elemType,
520
+ parent,
484
521
  firstMatch,
485
522
  candidates,
486
- picImg;
487
523
 
488
- options = options || {};
524
+ options = opt || {};
489
525
  elements = options.elements || pf.getAllElements();
490
526
 
491
527
  // Loop through all elements
492
528
  for ( var i = 0, plen = elements.length; i < plen; i++ ) {
493
529
  element = elements[ i ];
494
- elemType = element.nodeName.toUpperCase();
530
+ parent = element.parentNode;
495
531
  firstMatch = undefined;
496
532
  candidates = undefined;
497
- picImg = undefined;
498
533
 
499
534
  // expando for caching data on the img
500
535
  if ( !element[ pf.ns ] ) {
@@ -508,16 +543,16 @@
508
543
  continue;
509
544
  }
510
545
 
511
- // if element is a picture element
512
- if ( elemType === "PICTURE" ) {
546
+ // if `img` is in a `picture` element
547
+ if ( parent.nodeName.toUpperCase() === "PICTURE" ) {
513
548
 
514
549
  // IE9 video workaround
515
- pf.removeVideoShim( element );
550
+ pf.removeVideoShim( parent );
516
551
 
517
552
  // return the first match which might undefined
518
553
  // returns false if there is a pending source
519
554
  // TODO the return type here is brutal, cleanup
520
- firstMatch = pf.getMatch( element );
555
+ firstMatch = pf.getMatch( element, parent );
521
556
 
522
557
  // if any sources are pending in this picture due to async type test(s)
523
558
  // remove the evaluated attr and skip for now ( the pending test will
@@ -525,43 +560,32 @@
525
560
  if ( firstMatch === false ) {
526
561
  continue;
527
562
  }
528
-
529
- // Find any existing img element in the picture element
530
- picImg = element.getElementsByTagName( "img" )[ 0 ];
531
563
  } else {
532
- // if it's an img element
533
564
  firstMatch = undefined;
534
- picImg = element;
535
565
  }
536
566
 
537
- if ( picImg ) {
538
-
539
- // expando for caching data on the img
540
- if ( !picImg[ pf.ns ] ) {
541
- picImg[ pf.ns ] = {};
542
- }
543
-
544
- // Cache and remove `srcset` if present and we’re going to be doing `sizes`/`picture` polyfilling to it.
545
- if ( picImg.srcset && ( elemType === "PICTURE" || picImg.getAttribute( "sizes" ) ) ) {
546
- pf.dodgeSrcset( picImg );
547
- }
548
-
549
- if ( firstMatch ) {
550
- candidates = pf.processSourceSet( firstMatch );
551
- pf.applyBestCandidate( candidates, picImg );
552
- } else {
553
- // No sources matched, so we’re down to processing the inner `img` as a source.
554
- candidates = pf.processSourceSet( picImg );
567
+ // Cache and remove `srcset` if present and we’re going to be doing `picture`/`srcset`/`sizes` polyfilling to it.
568
+ if ( parent.nodeName.toUpperCase() === "PICTURE" ||
569
+ ( element.srcset && !pf.srcsetSupported ) ||
570
+ ( !pf.sizesSupported && ( element.srcset && element.srcset.indexOf("w") > -1 ) ) ) {
571
+ pf.dodgeSrcset( element );
572
+ }
555
573
 
556
- if ( picImg.srcset === undefined || picImg[ pf.ns ].srcset ) {
557
- // Either `srcset` is completely unsupported, or we need to polyfill `sizes` functionality.
558
- pf.applyBestCandidate( candidates, picImg );
559
- } // Else, resolution-only `srcset` is supported natively.
560
- }
574
+ if ( firstMatch ) {
575
+ candidates = pf.processSourceSet( firstMatch );
576
+ pf.applyBestCandidate( candidates, element );
577
+ } else {
578
+ // No sources matched, so we’re down to processing the inner `img` as a source.
579
+ candidates = pf.processSourceSet( element );
561
580
 
562
- // set evaluated to true to avoid unnecessary reparsing
563
- element[ pf.ns ].evaluated = true;
581
+ if ( element.srcset === undefined || element[ pf.ns ].srcset ) {
582
+ // Either `srcset` is completely unsupported, or we need to polyfill `sizes` functionality.
583
+ pf.applyBestCandidate( candidates, element );
584
+ } // Else, resolution-only `srcset` is supported natively.
564
585
  }
586
+
587
+ // set evaluated to true to avoid unnecessary reparsing
588
+ element[ pf.ns ].evaluated = true;
565
589
  }
566
590
  }
567
591
 
@@ -596,7 +620,7 @@
596
620
  }
597
621
  }
598
622
 
599
- webshim.ready('matchMedia', runPicturefill);
623
+ runPicturefill();
600
624
 
601
625
  /* expose methods for testing */
602
626
  picturefill._ = pf;
@@ -615,3 +639,4 @@
615
639
 
616
640
  } )( this, this.document );
617
641
 
642
+
@@ -1,497 +1,515 @@
1
1
  /*!
2
- * jQuery UI Position 1.10.3
2
+ * jQuery UI Position 1.11.0
3
3
  * http://jqueryui.com
4
4
  *
5
- * Copyright 2013 jQuery Foundation and other contributors
5
+ * Copyright 2014 jQuery Foundation and other contributors
6
6
  * Released under the MIT license.
7
7
  * http://jquery.org/license
8
8
  *
9
9
  * http://api.jqueryui.com/position/
10
10
  */
11
- (function( $, undefined ) {
12
-
13
- $.ui = $.ui || {};
14
-
15
- var cachedScrollbarWidth,
16
- max = Math.max,
17
- abs = Math.abs,
18
- round = Math.round,
19
- rhorizontal = /left|center|right/,
20
- rvertical = /top|center|bottom/,
21
- roffset = /[\+\-]\d+(\.[\d]+)?%?/,
22
- rposition = /^\w+/,
23
- rpercent = /%$/,
24
- _position = $.fn.position;
25
-
26
- function getOffsets( offsets, width, height ) {
27
- return [
28
- parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
29
- parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
30
- ];
31
- }
32
-
33
- function parseCss( element, property ) {
34
- return parseInt( $.css( element, property ), 10 ) || 0;
35
- }
36
-
37
- function getDimensions( elem ) {
38
- var raw = elem[0];
39
- if ( raw.nodeType === 9 ) {
40
- return {
41
- width: elem.width(),
42
- height: elem.height(),
43
- offset: { top: 0, left: 0 }
44
- };
45
- }
46
- if ( $.isWindow( raw ) ) {
47
- return {
48
- width: elem.width(),
49
- height: elem.height(),
50
- offset: { top: elem.scrollTop(), left: elem.scrollLeft() }
51
- };
52
- }
53
- if ( raw.preventDefault ) {
54
- return {
55
- width: 0,
56
- height: 0,
57
- offset: { top: raw.pageY, left: raw.pageX }
58
- };
11
+ (function( factory ) {
12
+ if ( typeof define === "function" && define.amd ) {
13
+
14
+ // AMD. Register as an anonymous module.
15
+ define( [ "jquery" ], factory );
16
+ } else {
17
+
18
+ // Browser globals
19
+ factory( window.webshims && window.webshims.$ || jQuery );
59
20
  }
60
- return {
61
- width: elem.outerWidth(),
62
- height: elem.outerHeight(),
63
- offset: elem.offset()
64
- };
65
- }
66
-
67
- $.position = {
68
- scrollbarWidth: function() {
69
- if ( cachedScrollbarWidth !== undefined ) {
70
- return cachedScrollbarWidth;
21
+ }(function( $ ) {
22
+ (function() {
23
+
24
+ $.ui = $.ui || {};
25
+
26
+ var cachedScrollbarWidth, supportsOffsetFractions,
27
+ max = Math.max,
28
+ abs = Math.abs,
29
+ round = Math.round,
30
+ rhorizontal = /left|center|right/,
31
+ rvertical = /top|center|bottom/,
32
+ roffset = /[\+\-]\d+(\.[\d]+)?%?/,
33
+ rposition = /^\w+/,
34
+ rpercent = /%$/,
35
+ _position = $.fn.position;
36
+
37
+ function getOffsets( offsets, width, height ) {
38
+ return [
39
+ parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
40
+ parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
41
+ ];
71
42
  }
72
- var w1, w2,
73
- div = $( "<div style='display:block;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>" ),
74
- innerDiv = div.children()[0];
75
-
76
- $( "body" ).append( div );
77
- w1 = innerDiv.offsetWidth;
78
- div.css( "overflow", "scroll" );
79
43
 
80
- w2 = innerDiv.offsetWidth;
44
+ function parseCss( element, property ) {
45
+ return parseInt( $.css( element, property ), 10 ) || 0;
46
+ }
81
47
 
82
- if ( w1 === w2 ) {
83
- w2 = div[0].clientWidth;
48
+ function getDimensions( elem ) {
49
+ var raw = elem[0];
50
+ if ( raw.nodeType === 9 ) {
51
+ return {
52
+ width: elem.width(),
53
+ height: elem.height(),
54
+ offset: { top: 0, left: 0 }
55
+ };
56
+ }
57
+ if ( $.isWindow( raw ) ) {
58
+ return {
59
+ width: elem.width(),
60
+ height: elem.height(),
61
+ offset: { top: elem.scrollTop(), left: elem.scrollLeft() }
62
+ };
63
+ }
64
+ if ( raw.preventDefault ) {
65
+ return {
66
+ width: 0,
67
+ height: 0,
68
+ offset: { top: raw.pageY, left: raw.pageX }
69
+ };
70
+ }
71
+ return {
72
+ width: elem.outerWidth(),
73
+ height: elem.outerHeight(),
74
+ offset: elem.offset()
75
+ };
84
76
  }
85
77
 
86
- div.remove();
87
-
88
- return (cachedScrollbarWidth = w1 - w2);
89
- },
90
- getScrollInfo: function( within ) {
91
- var overflowX = within.isWindow ? "" : within.element.css( "overflow-x" ),
92
- overflowY = within.isWindow ? "" : within.element.css( "overflow-y" ),
93
- hasOverflowX = overflowX === "scroll" ||
94
- ( overflowX === "auto" && within.width < within.element[0].scrollWidth ),
95
- hasOverflowY = overflowY === "scroll" ||
96
- ( overflowY === "auto" && within.height < within.element[0].scrollHeight );
97
- return {
98
- width: hasOverflowY ? $.position.scrollbarWidth() : 0,
99
- height: hasOverflowX ? $.position.scrollbarWidth() : 0
100
- };
101
- },
102
- getWithinInfo: function( element ) {
103
- var withinElement = $( element || window ),
104
- isWindow = $.isWindow( withinElement[0] );
105
- return {
106
- element: withinElement,
107
- isWindow: isWindow,
108
- offset: withinElement.offset() || { left: 0, top: 0 },
109
- scrollLeft: withinElement.scrollLeft(),
110
- scrollTop: withinElement.scrollTop(),
111
- width: isWindow ? withinElement.width() : withinElement.outerWidth(),
112
- height: isWindow ? withinElement.height() : withinElement.outerHeight()
113
- };
114
- }
115
- };
78
+ $.position = {
79
+ scrollbarWidth: function() {
80
+ if ( cachedScrollbarWidth !== undefined ) {
81
+ return cachedScrollbarWidth;
82
+ }
83
+ var w1, w2,
84
+ div = $( "<div style='display:block;position:absolute;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>" ),
85
+ innerDiv = div.children()[0];
116
86
 
117
- $.fn.position = function( options ) {
118
- if ( !options || !options.of ) {
119
- return _position.apply( this, arguments );
120
- }
87
+ $( "body" ).append( div );
88
+ w1 = innerDiv.offsetWidth;
89
+ div.css( "overflow", "scroll" );
121
90
 
122
- // make a copy, we don't want to modify arguments
123
- options = $.extend( {}, options );
91
+ w2 = innerDiv.offsetWidth;
124
92
 
125
- var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
126
- target = $( options.of ),
127
- within = $.position.getWithinInfo( options.within ),
128
- scrollInfo = $.position.getScrollInfo( within ),
129
- collision = ( options.collision || "flip" ).split( " " ),
130
- offsets = {};
93
+ if ( w1 === w2 ) {
94
+ w2 = div[0].clientWidth;
95
+ }
131
96
 
132
- dimensions = getDimensions( target );
133
- if ( target[0].preventDefault ) {
134
- // force left top to allow flipping
135
- options.at = "left top";
136
- }
137
- targetWidth = dimensions.width;
138
- targetHeight = dimensions.height;
139
- targetOffset = dimensions.offset;
140
- // clone to reuse original targetOffset later
141
- basePosition = $.extend( {}, targetOffset );
142
-
143
- // force my and at to have valid horizontal and vertical positions
144
- // if a value is missing or invalid, it will be converted to center
145
- $.each( [ "my", "at" ], function() {
146
- var pos = ( options[ this ] || "" ).split( " " ),
147
- horizontalOffset,
148
- verticalOffset;
149
-
150
- if ( pos.length === 1) {
151
- pos = rhorizontal.test( pos[ 0 ] ) ?
152
- pos.concat( [ "center" ] ) :
153
- rvertical.test( pos[ 0 ] ) ?
154
- [ "center" ].concat( pos ) :
155
- [ "center", "center" ];
156
- }
157
- pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center";
158
- pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center";
159
-
160
- // calculate offsets
161
- horizontalOffset = roffset.exec( pos[ 0 ] );
162
- verticalOffset = roffset.exec( pos[ 1 ] );
163
- offsets[ this ] = [
164
- horizontalOffset ? horizontalOffset[ 0 ] : 0,
165
- verticalOffset ? verticalOffset[ 0 ] : 0
166
- ];
167
-
168
- // reduce to just the positions without the offsets
169
- options[ this ] = [
170
- rposition.exec( pos[ 0 ] )[ 0 ],
171
- rposition.exec( pos[ 1 ] )[ 0 ]
172
- ];
173
- });
174
-
175
- // normalize collision option
176
- if ( collision.length === 1 ) {
177
- collision[ 1 ] = collision[ 0 ];
178
- }
97
+ div.remove();
98
+
99
+ return (cachedScrollbarWidth = w1 - w2);
100
+ },
101
+ getScrollInfo: function( within ) {
102
+ var overflowX = within.isWindow || within.isDocument ? "" :
103
+ within.element.css( "overflow-x" ),
104
+ overflowY = within.isWindow || within.isDocument ? "" :
105
+ within.element.css( "overflow-y" ),
106
+ hasOverflowX = overflowX === "scroll" ||
107
+ ( overflowX === "auto" && within.width < within.element[0].scrollWidth ),
108
+ hasOverflowY = overflowY === "scroll" ||
109
+ ( overflowY === "auto" && within.height < within.element[0].scrollHeight );
110
+ return {
111
+ width: hasOverflowY ? $.position.scrollbarWidth() : 0,
112
+ height: hasOverflowX ? $.position.scrollbarWidth() : 0
113
+ };
114
+ },
115
+ getWithinInfo: function( element ) {
116
+ var withinElement = $( element || window ),
117
+ isWindow = $.isWindow( withinElement[0] ),
118
+ isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9;
119
+ return {
120
+ element: withinElement,
121
+ isWindow: isWindow,
122
+ isDocument: isDocument,
123
+ offset: withinElement.offset() || { left: 0, top: 0 },
124
+ scrollLeft: withinElement.scrollLeft(),
125
+ scrollTop: withinElement.scrollTop(),
126
+ width: isWindow ? withinElement.width() : withinElement.outerWidth(),
127
+ height: isWindow ? withinElement.height() : withinElement.outerHeight()
128
+ };
129
+ }
130
+ };
179
131
 
180
- if ( options.at[ 0 ] === "right" ) {
181
- basePosition.left += targetWidth;
182
- } else if ( options.at[ 0 ] === "center" ) {
183
- basePosition.left += targetWidth / 2;
184
- }
132
+ $.fn.position = function( options ) {
133
+ if ( !options || !options.of ) {
134
+ return _position.apply( this, arguments );
135
+ }
185
136
 
186
- if ( options.at[ 1 ] === "bottom" ) {
187
- basePosition.top += targetHeight;
188
- } else if ( options.at[ 1 ] === "center" ) {
189
- basePosition.top += targetHeight / 2;
190
- }
137
+ // make a copy, we don't want to modify arguments
138
+ options = $.extend( {}, options );
191
139
 
192
- atOffset = getOffsets( offsets.at, targetWidth, targetHeight );
193
- basePosition.left += atOffset[ 0 ];
194
- basePosition.top += atOffset[ 1 ];
195
-
196
- return this.each(function() {
197
- var collisionPosition, using,
198
- elem = $( this ),
199
- elemWidth = elem.outerWidth(),
200
- elemHeight = elem.outerHeight(),
201
- marginLeft = parseCss( this, "marginLeft" ),
202
- marginTop = parseCss( this, "marginTop" ),
203
- collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) + scrollInfo.width,
204
- collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) + scrollInfo.height,
205
- position = $.extend( {}, basePosition ),
206
- myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );
207
-
208
- if ( options.my[ 0 ] === "right" ) {
209
- position.left -= elemWidth;
210
- } else if ( options.my[ 0 ] === "center" ) {
211
- position.left -= elemWidth / 2;
212
- }
140
+ var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
141
+ target = $( options.of ),
142
+ within = $.position.getWithinInfo( options.within ),
143
+ scrollInfo = $.position.getScrollInfo( within ),
144
+ collision = ( options.collision || "flip" ).split( " " ),
145
+ offsets = {};
213
146
 
214
- if ( options.my[ 1 ] === "bottom" ) {
215
- position.top -= elemHeight;
216
- } else if ( options.my[ 1 ] === "center" ) {
217
- position.top -= elemHeight / 2;
218
- }
147
+ dimensions = getDimensions( target );
148
+ if ( target[0].preventDefault ) {
149
+ // force left top to allow flipping
150
+ options.at = "left top";
151
+ }
152
+ targetWidth = dimensions.width;
153
+ targetHeight = dimensions.height;
154
+ targetOffset = dimensions.offset;
155
+ // clone to reuse original targetOffset later
156
+ basePosition = $.extend( {}, targetOffset );
157
+
158
+ // force my and at to have valid horizontal and vertical positions
159
+ // if a value is missing or invalid, it will be converted to center
160
+ $.each( [ "my", "at" ], function() {
161
+ var pos = ( options[ this ] || "" ).split( " " ),
162
+ horizontalOffset,
163
+ verticalOffset;
164
+
165
+ if ( pos.length === 1) {
166
+ pos = rhorizontal.test( pos[ 0 ] ) ?
167
+ pos.concat( [ "center" ] ) :
168
+ rvertical.test( pos[ 0 ] ) ?
169
+ [ "center" ].concat( pos ) :
170
+ [ "center", "center" ];
171
+ }
172
+ pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center";
173
+ pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center";
174
+
175
+ // calculate offsets
176
+ horizontalOffset = roffset.exec( pos[ 0 ] );
177
+ verticalOffset = roffset.exec( pos[ 1 ] );
178
+ offsets[ this ] = [
179
+ horizontalOffset ? horizontalOffset[ 0 ] : 0,
180
+ verticalOffset ? verticalOffset[ 0 ] : 0
181
+ ];
182
+
183
+ // reduce to just the positions without the offsets
184
+ options[ this ] = [
185
+ rposition.exec( pos[ 0 ] )[ 0 ],
186
+ rposition.exec( pos[ 1 ] )[ 0 ]
187
+ ];
188
+ });
189
+
190
+ // normalize collision option
191
+ if ( collision.length === 1 ) {
192
+ collision[ 1 ] = collision[ 0 ];
193
+ }
219
194
 
220
- position.left += myOffset[ 0 ];
221
- position.top += myOffset[ 1 ];
195
+ if ( options.at[ 0 ] === "right" ) {
196
+ basePosition.left += targetWidth;
197
+ } else if ( options.at[ 0 ] === "center" ) {
198
+ basePosition.left += targetWidth / 2;
199
+ }
222
200
 
223
- // if the browser doesn't support fractions, then round for consistent results
224
- if ( !$.support.offsetFractions ) {
225
- position.left = round( position.left );
226
- position.top = round( position.top );
227
- }
201
+ if ( options.at[ 1 ] === "bottom" ) {
202
+ basePosition.top += targetHeight;
203
+ } else if ( options.at[ 1 ] === "center" ) {
204
+ basePosition.top += targetHeight / 2;
205
+ }
228
206
 
229
- collisionPosition = {
230
- marginLeft: marginLeft,
231
- marginTop: marginTop
232
- };
207
+ atOffset = getOffsets( offsets.at, targetWidth, targetHeight );
208
+ basePosition.left += atOffset[ 0 ];
209
+ basePosition.top += atOffset[ 1 ];
210
+
211
+ return this.each(function() {
212
+ var collisionPosition, using,
213
+ elem = $( this ),
214
+ elemWidth = elem.outerWidth(),
215
+ elemHeight = elem.outerHeight(),
216
+ marginLeft = parseCss( this, "marginLeft" ),
217
+ marginTop = parseCss( this, "marginTop" ),
218
+ collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) + scrollInfo.width,
219
+ collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) + scrollInfo.height,
220
+ position = $.extend( {}, basePosition ),
221
+ myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );
222
+
223
+ if ( options.my[ 0 ] === "right" ) {
224
+ position.left -= elemWidth;
225
+ } else if ( options.my[ 0 ] === "center" ) {
226
+ position.left -= elemWidth / 2;
227
+ }
233
228
 
234
- $.each( [ "left", "top" ], function( i, dir ) {
235
- if ( $.ui.position[ collision[ i ] ] ) {
236
- $.ui.position[ collision[ i ] ][ dir ]( position, {
237
- targetWidth: targetWidth,
238
- targetHeight: targetHeight,
239
- elemWidth: elemWidth,
240
- elemHeight: elemHeight,
241
- collisionPosition: collisionPosition,
242
- collisionWidth: collisionWidth,
243
- collisionHeight: collisionHeight,
244
- offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],
245
- my: options.my,
246
- at: options.at,
247
- within: within,
248
- elem : elem
249
- });
250
- }
251
- });
252
-
253
- if ( options.using ) {
254
- // adds feedback as second argument to using callback, if present
255
- using = function( props ) {
256
- var left = targetOffset.left - position.left,
257
- right = left + targetWidth - elemWidth,
258
- top = targetOffset.top - position.top,
259
- bottom = top + targetHeight - elemHeight,
260
- feedback = {
261
- target: {
262
- element: target,
263
- left: targetOffset.left,
264
- top: targetOffset.top,
265
- width: targetWidth,
266
- height: targetHeight
267
- },
268
- element: {
269
- element: elem,
270
- left: position.left,
271
- top: position.top,
272
- width: elemWidth,
273
- height: elemHeight
274
- },
275
- horizontal: right < 0 ? "left" : left > 0 ? "right" : "center",
276
- vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle"
277
- };
278
- if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) {
279
- feedback.horizontal = "center";
229
+ if ( options.my[ 1 ] === "bottom" ) {
230
+ position.top -= elemHeight;
231
+ } else if ( options.my[ 1 ] === "center" ) {
232
+ position.top -= elemHeight / 2;
280
233
  }
281
- if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) {
282
- feedback.vertical = "middle";
234
+
235
+ position.left += myOffset[ 0 ];
236
+ position.top += myOffset[ 1 ];
237
+
238
+ // if the browser doesn't support fractions, then round for consistent results
239
+ if ( !supportsOffsetFractions ) {
240
+ position.left = round( position.left );
241
+ position.top = round( position.top );
283
242
  }
284
- if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) {
285
- feedback.important = "horizontal";
286
- } else {
287
- feedback.important = "vertical";
243
+
244
+ collisionPosition = {
245
+ marginLeft: marginLeft,
246
+ marginTop: marginTop
247
+ };
248
+
249
+ $.each( [ "left", "top" ], function( i, dir ) {
250
+ if ( $.ui.position[ collision[ i ] ] ) {
251
+ $.ui.position[ collision[ i ] ][ dir ]( position, {
252
+ targetWidth: targetWidth,
253
+ targetHeight: targetHeight,
254
+ elemWidth: elemWidth,
255
+ elemHeight: elemHeight,
256
+ collisionPosition: collisionPosition,
257
+ collisionWidth: collisionWidth,
258
+ collisionHeight: collisionHeight,
259
+ offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],
260
+ my: options.my,
261
+ at: options.at,
262
+ within: within,
263
+ elem: elem
264
+ });
265
+ }
266
+ });
267
+
268
+ if ( options.using ) {
269
+ // adds feedback as second argument to using callback, if present
270
+ using = function( props ) {
271
+ var left = targetOffset.left - position.left,
272
+ right = left + targetWidth - elemWidth,
273
+ top = targetOffset.top - position.top,
274
+ bottom = top + targetHeight - elemHeight,
275
+ feedback = {
276
+ target: {
277
+ element: target,
278
+ left: targetOffset.left,
279
+ top: targetOffset.top,
280
+ width: targetWidth,
281
+ height: targetHeight
282
+ },
283
+ element: {
284
+ element: elem,
285
+ left: position.left,
286
+ top: position.top,
287
+ width: elemWidth,
288
+ height: elemHeight
289
+ },
290
+ horizontal: right < 0 ? "left" : left > 0 ? "right" : "center",
291
+ vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle"
292
+ };
293
+ if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) {
294
+ feedback.horizontal = "center";
295
+ }
296
+ if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) {
297
+ feedback.vertical = "middle";
298
+ }
299
+ if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) {
300
+ feedback.important = "horizontal";
301
+ } else {
302
+ feedback.important = "vertical";
303
+ }
304
+ options.using.call( this, props, feedback );
305
+ };
288
306
  }
289
- options.using.call( this, props, feedback );
290
- };
291
- }
292
307
 
293
- elem.offset( $.extend( position, { using: using } ) );
294
- });
295
- };
296
-
297
- $.ui.position = {
298
- fit: {
299
- left: function( position, data ) {
300
- var within = data.within,
301
- withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
302
- outerWidth = within.width,
303
- collisionPosLeft = position.left - data.collisionPosition.marginLeft,
304
- overLeft = withinOffset - collisionPosLeft,
305
- overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
306
- newOverRight;
307
-
308
- // element is wider than within
309
- if ( data.collisionWidth > outerWidth ) {
310
- // element is initially over the left side of within
311
- if ( overLeft > 0 && overRight <= 0 ) {
312
- newOverRight = position.left + overLeft + data.collisionWidth - outerWidth - withinOffset;
313
- position.left += overLeft - newOverRight;
314
- // element is initially over right side of within
315
- } else if ( overRight > 0 && overLeft <= 0 ) {
316
- position.left = withinOffset;
317
- // element is initially over both left and right sides of within
318
- } else {
319
- if ( overLeft > overRight ) {
320
- position.left = withinOffset + outerWidth - data.collisionWidth;
308
+ elem.offset( $.extend( position, { using: using } ) );
309
+ });
310
+ };
311
+
312
+ $.ui.position = {
313
+ fit: {
314
+ left: function( position, data ) {
315
+ var within = data.within,
316
+ withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
317
+ outerWidth = within.width,
318
+ collisionPosLeft = position.left - data.collisionPosition.marginLeft,
319
+ overLeft = withinOffset - collisionPosLeft,
320
+ overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
321
+ newOverRight;
322
+
323
+ // element is wider than within
324
+ if ( data.collisionWidth > outerWidth ) {
325
+ // element is initially over the left side of within
326
+ if ( overLeft > 0 && overRight <= 0 ) {
327
+ newOverRight = position.left + overLeft + data.collisionWidth - outerWidth - withinOffset;
328
+ position.left += overLeft - newOverRight;
329
+ // element is initially over right side of within
330
+ } else if ( overRight > 0 && overLeft <= 0 ) {
331
+ position.left = withinOffset;
332
+ // element is initially over both left and right sides of within
333
+ } else {
334
+ if ( overLeft > overRight ) {
335
+ position.left = withinOffset + outerWidth - data.collisionWidth;
336
+ } else {
337
+ position.left = withinOffset;
338
+ }
339
+ }
340
+ // too far left -> align with left edge
341
+ } else if ( overLeft > 0 ) {
342
+ position.left += overLeft;
343
+ // too far right -> align with right edge
344
+ } else if ( overRight > 0 ) {
345
+ position.left -= overRight;
346
+ // adjust based on position and margin
321
347
  } else {
322
- position.left = withinOffset;
348
+ position.left = max( position.left - collisionPosLeft, position.left );
323
349
  }
324
- }
325
- // too far left -> align with left edge
326
- } else if ( overLeft > 0 ) {
327
- position.left += overLeft;
328
- // too far right -> align with right edge
329
- } else if ( overRight > 0 ) {
330
- position.left -= overRight;
331
- // adjust based on position and margin
332
- } else {
333
- position.left = max( position.left - collisionPosLeft, position.left );
334
- }
335
- },
336
- top: function( position, data ) {
337
- var within = data.within,
338
- withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
339
- outerHeight = data.within.height,
340
- collisionPosTop = position.top - data.collisionPosition.marginTop,
341
- overTop = withinOffset - collisionPosTop,
342
- overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
343
- newOverBottom;
344
-
345
- // element is taller than within
346
- if ( data.collisionHeight > outerHeight ) {
347
- // element is initially over the top of within
348
- if ( overTop > 0 && overBottom <= 0 ) {
349
- newOverBottom = position.top + overTop + data.collisionHeight - outerHeight - withinOffset;
350
- position.top += overTop - newOverBottom;
351
- // element is initially over bottom of within
352
- } else if ( overBottom > 0 && overTop <= 0 ) {
353
- position.top = withinOffset;
354
- // element is initially over both top and bottom of within
355
- } else {
356
- if ( overTop > overBottom ) {
357
- position.top = withinOffset + outerHeight - data.collisionHeight;
350
+ },
351
+ top: function( position, data ) {
352
+ var within = data.within,
353
+ withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
354
+ outerHeight = data.within.height,
355
+ collisionPosTop = position.top - data.collisionPosition.marginTop,
356
+ overTop = withinOffset - collisionPosTop,
357
+ overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
358
+ newOverBottom;
359
+
360
+ // element is taller than within
361
+ if ( data.collisionHeight > outerHeight ) {
362
+ // element is initially over the top of within
363
+ if ( overTop > 0 && overBottom <= 0 ) {
364
+ newOverBottom = position.top + overTop + data.collisionHeight - outerHeight - withinOffset;
365
+ position.top += overTop - newOverBottom;
366
+ // element is initially over bottom of within
367
+ } else if ( overBottom > 0 && overTop <= 0 ) {
368
+ position.top = withinOffset;
369
+ // element is initially over both top and bottom of within
370
+ } else {
371
+ if ( overTop > overBottom ) {
372
+ position.top = withinOffset + outerHeight - data.collisionHeight;
373
+ } else {
374
+ position.top = withinOffset;
375
+ }
376
+ }
377
+ // too far up -> align with top
378
+ } else if ( overTop > 0 ) {
379
+ position.top += overTop;
380
+ // too far down -> align with bottom edge
381
+ } else if ( overBottom > 0 ) {
382
+ position.top -= overBottom;
383
+ // adjust based on position and margin
358
384
  } else {
359
- position.top = withinOffset;
385
+ position.top = max( position.top - collisionPosTop, position.top );
360
386
  }
361
387
  }
362
- // too far up -> align with top
363
- } else if ( overTop > 0 ) {
364
- position.top += overTop;
365
- // too far down -> align with bottom edge
366
- } else if ( overBottom > 0 ) {
367
- position.top -= overBottom;
368
- // adjust based on position and margin
369
- } else {
370
- position.top = max( position.top - collisionPosTop, position.top );
371
- }
372
- }
373
- },
374
- flip: {
375
- left: function( position, data ) {
376
- var within = data.within,
377
- withinOffset = within.offset.left + within.scrollLeft,
378
- outerWidth = within.width,
379
- offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,
380
- collisionPosLeft = position.left - data.collisionPosition.marginLeft,
381
- overLeft = collisionPosLeft - offsetLeft,
382
- overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
383
- myOffset = data.my[ 0 ] === "left" ?
384
- -data.elemWidth :
385
- data.my[ 0 ] === "right" ?
386
- data.elemWidth :
387
- 0,
388
- atOffset = data.at[ 0 ] === "left" ?
389
- data.targetWidth :
390
- data.at[ 0 ] === "right" ?
391
- -data.targetWidth :
392
- 0,
393
- offset = -2 * data.offset[ 0 ],
394
- newOverRight,
395
- newOverLeft;
396
-
397
- if ( overLeft < 0 ) {
398
- newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth - outerWidth - withinOffset;
399
- if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) {
400
- position.left += myOffset + atOffset + offset;
388
+ },
389
+ flip: {
390
+ left: function( position, data ) {
391
+ var within = data.within,
392
+ withinOffset = within.offset.left + within.scrollLeft,
393
+ outerWidth = within.width,
394
+ offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,
395
+ collisionPosLeft = position.left - data.collisionPosition.marginLeft,
396
+ overLeft = collisionPosLeft - offsetLeft,
397
+ overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
398
+ myOffset = data.my[ 0 ] === "left" ?
399
+ -data.elemWidth :
400
+ data.my[ 0 ] === "right" ?
401
+ data.elemWidth :
402
+ 0,
403
+ atOffset = data.at[ 0 ] === "left" ?
404
+ data.targetWidth :
405
+ data.at[ 0 ] === "right" ?
406
+ -data.targetWidth :
407
+ 0,
408
+ offset = -2 * data.offset[ 0 ],
409
+ newOverRight,
410
+ newOverLeft;
411
+
412
+ if ( overLeft < 0 ) {
413
+ newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth - outerWidth - withinOffset;
414
+ if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) {
415
+ position.left += myOffset + atOffset + offset;
416
+ }
417
+ } else if ( overRight > 0 ) {
418
+ newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset + atOffset + offset - offsetLeft;
419
+ if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) {
420
+ position.left += myOffset + atOffset + offset;
421
+ }
422
+ }
423
+ },
424
+ top: function( position, data ) {
425
+ var within = data.within,
426
+ withinOffset = within.offset.top + within.scrollTop,
427
+ outerHeight = within.height,
428
+ offsetTop = within.isWindow ? within.scrollTop : within.offset.top,
429
+ collisionPosTop = position.top - data.collisionPosition.marginTop,
430
+ overTop = collisionPosTop - offsetTop,
431
+ overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
432
+ top = data.my[ 1 ] === "top",
433
+ myOffset = top ?
434
+ -data.elemHeight :
435
+ data.my[ 1 ] === "bottom" ?
436
+ data.elemHeight :
437
+ 0,
438
+ atOffset = data.at[ 1 ] === "top" ?
439
+ data.targetHeight :
440
+ data.at[ 1 ] === "bottom" ?
441
+ -data.targetHeight :
442
+ 0,
443
+ offset = -2 * data.offset[ 1 ],
444
+ newOverTop,
445
+ newOverBottom;
446
+ if ( overTop < 0 ) {
447
+ newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight - outerHeight - withinOffset;
448
+ if ( ( position.top + myOffset + atOffset + offset) > overTop && ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) ) {
449
+ position.top += myOffset + atOffset + offset;
450
+ }
451
+ } else if ( overBottom > 0 ) {
452
+ newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset + offset - offsetTop;
453
+ if ( ( position.top + myOffset + atOffset + offset) > overBottom && ( newOverTop > 0 || abs( newOverTop ) < overBottom ) ) {
454
+ position.top += myOffset + atOffset + offset;
455
+ }
456
+ }
401
457
  }
402
- }
403
- else if ( overRight > 0 ) {
404
- newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset + atOffset + offset - offsetLeft;
405
- if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) {
406
- position.left += myOffset + atOffset + offset;
458
+ },
459
+ flipfit: {
460
+ left: function() {
461
+ $.ui.position.flip.left.apply( this, arguments );
462
+ $.ui.position.fit.left.apply( this, arguments );
463
+ },
464
+ top: function() {
465
+ $.ui.position.flip.top.apply( this, arguments );
466
+ $.ui.position.fit.top.apply( this, arguments );
407
467
  }
408
468
  }
409
- },
410
- top: function( position, data ) {
411
- var within = data.within,
412
- withinOffset = within.offset.top + within.scrollTop,
413
- outerHeight = within.height,
414
- offsetTop = within.isWindow ? within.scrollTop : within.offset.top,
415
- collisionPosTop = position.top - data.collisionPosition.marginTop,
416
- overTop = collisionPosTop - offsetTop,
417
- overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
418
- top = data.my[ 1 ] === "top",
419
- myOffset = top ?
420
- -data.elemHeight :
421
- data.my[ 1 ] === "bottom" ?
422
- data.elemHeight :
423
- 0,
424
- atOffset = data.at[ 1 ] === "top" ?
425
- data.targetHeight :
426
- data.at[ 1 ] === "bottom" ?
427
- -data.targetHeight :
428
- 0,
429
- offset = -2 * data.offset[ 1 ],
430
- newOverTop,
431
- newOverBottom;
432
- if ( overTop < 0 ) {
433
- newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight - outerHeight - withinOffset;
434
- if ( ( position.top + myOffset + atOffset + offset) > overTop && ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) ) {
435
- position.top += myOffset + atOffset + offset;
436
- }
469
+ };
470
+
471
+ // fraction support test
472
+ (function() {
473
+ var testElement, testElementParent, testElementStyle, offsetLeft, i,
474
+ body = document.getElementsByTagName( "body" )[ 0 ],
475
+ div = document.createElement( "div" );
476
+
477
+ //Create a "fake body" for testing based on method used in jQuery.support
478
+ testElement = document.createElement( body ? "div" : "body" );
479
+ testElementStyle = {
480
+ visibility: "hidden",
481
+ width: 0,
482
+ height: 0,
483
+ border: 0,
484
+ margin: 0,
485
+ background: "none"
486
+ };
487
+ if ( body ) {
488
+ $.extend( testElementStyle, {
489
+ position: "absolute",
490
+ left: "-1000px",
491
+ top: "-1000px"
492
+ });
437
493
  }
438
- else if ( overBottom > 0 ) {
439
- newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset + offset - offsetTop;
440
- if ( ( position.top + myOffset + atOffset + offset) > overBottom && ( newOverTop > 0 || abs( newOverTop ) < overBottom ) ) {
441
- position.top += myOffset + atOffset + offset;
442
- }
494
+ for ( i in testElementStyle ) {
495
+ testElement.style[ i ] = testElementStyle[ i ];
443
496
  }
444
- }
445
- },
446
- flipfit: {
447
- left: function() {
448
- $.ui.position.flip.left.apply( this, arguments );
449
- $.ui.position.fit.left.apply( this, arguments );
450
- },
451
- top: function() {
452
- $.ui.position.flip.top.apply( this, arguments );
453
- $.ui.position.fit.top.apply( this, arguments );
454
- }
455
- }
456
- };
497
+ testElement.appendChild( div );
498
+ testElementParent = body || document.documentElement;
499
+ testElementParent.insertBefore( testElement, testElementParent.firstChild );
457
500
 
458
- // fraction support test
459
- (function () {
460
- var testElement, testElementParent, testElementStyle, offsetLeft, i,
461
- body = document.getElementsByTagName( "body" )[ 0 ],
462
- div = document.createElement( "div" );
463
-
464
- //Create a "fake body" for testing based on method used in jQuery.support
465
- testElement = document.createElement( body ? "div" : "body" );
466
- testElementStyle = {
467
- visibility: "hidden",
468
- width: 0,
469
- height: 0,
470
- border: 0,
471
- margin: 0,
472
- background: "none"
473
- };
474
- if ( body ) {
475
- $.extend( testElementStyle, {
476
- position: "absolute",
477
- left: "-1000px",
478
- top: "-1000px"
479
- });
480
- }
481
- for ( i in testElementStyle ) {
482
- testElement.style[ i ] = testElementStyle[ i ];
483
- }
484
- testElement.appendChild( div );
485
- testElementParent = body || document.documentElement;
486
- testElementParent.insertBefore( testElement, testElementParent.firstChild );
501
+ div.style.cssText = "position: absolute; left: 10.7432222px;";
502
+
503
+ offsetLeft = $( div ).offset().left;
504
+ supportsOffsetFractions = offsetLeft > 10 && offsetLeft < 11;
505
+
506
+ testElement.innerHTML = "";
507
+ testElementParent.removeChild( testElement );
508
+ })();
487
509
 
488
- div.style.cssText = "position: absolute; left: 10.7432222px;";
510
+ })();
489
511
 
490
- offsetLeft = $( div ).offset().left;
491
- $.support.offsetFractions = offsetLeft > 10 && offsetLeft < 11;
512
+ return $.ui.position;
492
513
 
493
- testElement.innerHTML = "";
494
- testElementParent.removeChild( testElement );
495
- })();
514
+ }));
496
515
 
497
- }( window.webshims && window.webshims.$ || jQuery ) );