webshims-rails 1.10.3 → 1.10.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +8 -8
  2. data/lib/webshims-rails/version.rb +2 -2
  3. data/vendor/assets/javascripts/webshims/polyfiller.js +96 -73
  4. data/vendor/assets/javascripts/webshims/shims/color-picker.js +2415 -0
  5. data/vendor/assets/javascripts/webshims/shims/combos/1.js +248 -745
  6. data/vendor/assets/javascripts/webshims/shims/combos/10.js +771 -1206
  7. data/vendor/assets/javascripts/webshims/shims/combos/11.js +679 -1201
  8. data/vendor/assets/javascripts/webshims/shims/combos/12.js +46 -65
  9. data/vendor/assets/javascripts/webshims/shims/combos/13.js +45 -64
  10. data/vendor/assets/javascripts/webshims/shims/combos/14.js +94 -7
  11. data/vendor/assets/javascripts/webshims/shims/combos/15.js +557 -1189
  12. data/vendor/assets/javascripts/webshims/shims/combos/16.js +598 -1249
  13. data/vendor/assets/javascripts/webshims/shims/combos/17.js +697 -1208
  14. data/vendor/assets/javascripts/webshims/shims/combos/18.js +697 -1208
  15. data/vendor/assets/javascripts/webshims/shims/combos/19.js +145 -78
  16. data/vendor/assets/javascripts/webshims/shims/combos/2.js +472 -1280
  17. data/vendor/assets/javascripts/webshims/shims/combos/20.js +144 -77
  18. data/vendor/assets/javascripts/webshims/shims/combos/21.js +14 -15
  19. data/vendor/assets/javascripts/webshims/shims/combos/22.js +2 -2
  20. data/vendor/assets/javascripts/webshims/shims/combos/23.js +45 -64
  21. data/vendor/assets/javascripts/webshims/shims/combos/24.js +848 -0
  22. data/vendor/assets/javascripts/webshims/shims/combos/25.js +4373 -0
  23. data/vendor/assets/javascripts/webshims/shims/combos/26.js +1516 -0
  24. data/vendor/assets/javascripts/webshims/shims/combos/27.js +884 -0
  25. data/vendor/assets/javascripts/webshims/shims/combos/28.js +2067 -0
  26. data/vendor/assets/javascripts/webshims/shims/combos/29.js +1156 -0
  27. data/vendor/assets/javascripts/webshims/shims/combos/3.js +313 -700
  28. data/vendor/assets/javascripts/webshims/shims/combos/30.js +1868 -0
  29. data/vendor/assets/javascripts/webshims/shims/combos/31.js +1663 -0
  30. data/vendor/assets/javascripts/webshims/shims/combos/4.js +111 -20
  31. data/vendor/assets/javascripts/webshims/shims/combos/5.js +747 -1321
  32. data/vendor/assets/javascripts/webshims/shims/combos/6.js +837 -1809
  33. data/vendor/assets/javascripts/webshims/shims/combos/7.js +435 -1239
  34. data/vendor/assets/javascripts/webshims/shims/combos/8.js +360 -766
  35. data/vendor/assets/javascripts/webshims/shims/combos/9.js +843 -1676
  36. data/vendor/assets/javascripts/webshims/shims/details.js +1 -1
  37. data/vendor/assets/javascripts/webshims/shims/dom-extend.js +90 -3
  38. data/vendor/assets/javascripts/webshims/shims/filereader.js +386 -0
  39. data/vendor/assets/javascripts/webshims/shims/form-core.js +201 -680
  40. data/vendor/assets/javascripts/webshims/shims/form-datalist-lazy.js +418 -0
  41. data/vendor/assets/javascripts/webshims/shims/form-datalist.js +69 -467
  42. data/vendor/assets/javascripts/webshims/shims/form-message.js +21 -17
  43. data/vendor/assets/javascripts/webshims/shims/form-native-extend.js +19 -82
  44. data/vendor/assets/javascripts/webshims/shims/form-number-date-api.js +17 -6
  45. data/vendor/assets/javascripts/webshims/shims/form-number-date-ui.js +570 -1185
  46. data/vendor/assets/javascripts/webshims/shims/form-shim-extend.js +181 -28
  47. data/vendor/assets/javascripts/webshims/shims/form-validation.js +599 -0
  48. data/vendor/assets/javascripts/webshims/{extras/custom-validity.js → shims/form-validators.js} +33 -38
  49. data/vendor/assets/javascripts/webshims/shims/forms-picker.js +865 -0
  50. data/vendor/assets/javascripts/webshims/shims/geolocation.js +2 -2
  51. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-de.txt +37 -34
  52. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-en.txt +88 -48
  53. data/vendor/assets/javascripts/webshims/shims/i18n/formcfg-lt.js +74 -0
  54. data/vendor/assets/javascripts/webshims/shims/jpicker/ChangeLog.txt +121 -0
  55. data/vendor/assets/javascripts/webshims/shims/jpicker/ReadMe.txt +47 -0
  56. data/vendor/assets/javascripts/webshims/shims/jpicker/images/AlphaBar.png +0 -0
  57. data/vendor/assets/javascripts/webshims/shims/jpicker/images/Bars.png +0 -0
  58. data/vendor/assets/javascripts/webshims/shims/jpicker/images/Maps.png +0 -0
  59. data/vendor/assets/javascripts/webshims/shims/jpicker/images/NoColor.png +0 -0
  60. data/vendor/assets/javascripts/webshims/shims/jpicker/images/Thumbs.db +0 -0
  61. data/vendor/assets/javascripts/webshims/shims/jpicker/images/bar-opacity.png +0 -0
  62. data/vendor/assets/javascripts/webshims/shims/jpicker/images/map-opacity.png +0 -0
  63. data/vendor/assets/javascripts/webshims/shims/jpicker/images/mappoint.gif +0 -0
  64. data/vendor/assets/javascripts/webshims/shims/jpicker/images/picker.gif +0 -0
  65. data/vendor/assets/javascripts/webshims/shims/jpicker/images/preview-opacity.png +0 -0
  66. data/vendor/assets/javascripts/webshims/shims/jpicker/images/rangearrows.gif +0 -0
  67. data/vendor/assets/javascripts/webshims/shims/jpicker/jpicker.css +257 -0
  68. data/vendor/assets/javascripts/webshims/shims/json-storage.js +4 -4
  69. data/vendor/assets/javascripts/webshims/shims/mediaelement-core.js +44 -63
  70. data/vendor/assets/javascripts/webshims/shims/mediaelement-jaris.js +10 -11
  71. data/vendor/assets/javascripts/webshims/shims/mediaelement-native-fix.js +2 -1
  72. data/vendor/assets/javascripts/webshims/shims/mediaelement-yt.js +5 -3
  73. data/vendor/assets/javascripts/webshims/shims/range-ui.js +110 -17
  74. data/vendor/assets/javascripts/webshims/shims/styles/forms.png +0 -0
  75. data/vendor/assets/javascripts/webshims/shims/styles/range-track.png +0 -0
  76. data/vendor/assets/javascripts/webshims/shims/styles/scss/shim.scss +104 -21
  77. data/vendor/assets/javascripts/webshims/shims/styles/shim.css +90 -16
  78. data/vendor/assets/javascripts/webshims/shims/styles/vertical-range.png +0 -0
  79. data/vendor/assets/javascripts/webshims/shims/swf/filereader.swf +0 -0
  80. data/vendor/assets/javascripts/webshims/shims/swfmini.js +1 -1
  81. data/vendor/assets/javascripts/webshims/shims/track-ui.js +35 -3
  82. data/vendor/assets/javascripts/webshims/shims/track.js +1 -1
  83. metadata +33 -3
@@ -8,7 +8,7 @@ var swfmini = function() {
8
8
 
9
9
  var UNDEF = "undefined",
10
10
  OBJECT = "object",
11
- webshims = jQuery.webshims,
11
+ webshims = jQuery.webshims || window.webshims,
12
12
  SHOCKWAVE_FLASH = "Shockwave Flash",
13
13
  SHOCKWAVE_FLASH_AX = "ShockwaveFlash.ShockwaveFlash",
14
14
  FLASH_MIME_TYPE = "application/x-shockwave-flash",
@@ -497,10 +497,10 @@ var swfmini = function() {
497
497
  }();
498
498
 
499
499
  //DOM-Extension helper
500
- jQuery.webshims.register('dom-extend', function($, webshims, window, document, undefined){
500
+ webshims.register('dom-extend', function($, webshims, window, document, undefined){
501
501
  "use strict";
502
502
 
503
- webshims.assumeARIA = Modernizr.localstorage || Modernizr.video || Modernizr.boxsizing;
503
+ webshims.assumeARIA = $.support.getSetAttribute || Modernizr.canvas || Modernizr.video || Modernizr.boxsizing;
504
504
 
505
505
  if($('<input type="email" />').attr('type') == 'text' || $('<form />').attr('novalidate') === "" || ('required' in $('<input />')[0].attributes)){
506
506
  webshims.error("IE browser modes are busted in IE10. Please test your HTML/CSS/JS with a real IE version or at least IETester or similiar tools");
@@ -509,6 +509,57 @@ jQuery.webshims.register('dom-extend', function($, webshims, window, document, u
509
509
  if(!$.parseHTML){
510
510
  webshims.error("Webshims needs jQuery 1.8+ to work properly. Please update your jQuery version or downgrade webshims.");
511
511
  }
512
+ if (!webshims.cfg.no$Switch) {
513
+ var switch$ = function(){
514
+ if (window.jQuery && (!window.$ || window.jQuery == window.$) && !window.jQuery.webshims) {
515
+ webshims.error("jQuery was included more than once. Make sure to include it only once! Webshims and other Plugins might not work properly.");
516
+ if (window.$) {
517
+ window.$ = webshims.$;
518
+ }
519
+ window.jQuery = webshims.$;
520
+ }
521
+ if(webshims.M != Modernizr){
522
+ webshims.error("Modernizr was included more than once. Make sure to include it only once! Webshims and other scripts might not work properly.");
523
+ for(var i in Modernizr){
524
+ if(!(i in webshims.M)){
525
+ webshims.M[i] = Modernizr[i];
526
+ }
527
+ }
528
+ Modernizr = webshims.M;
529
+ }
530
+ };
531
+ switch$();
532
+ setTimeout(switch$, 90);
533
+ $(switch$);
534
+ }
535
+ // (function(){
536
+ // var hostNames = {
537
+ // 'afarkas.github.io': 1,
538
+ // localhost: 1,
539
+ // '127.0.0.1': 1
540
+ // };
541
+ //
542
+ // if( webshims.debug && (hostNames[location.hostname] || location.protocol == 'file:') ){
543
+ // var list = $('<ul class="webshims-debug-list" />');
544
+ // webshims.errorLog.push = function(message){
545
+ // list.appendTo('body');
546
+ // $('<li style="display: none;">'+ message +'</li>')
547
+ // .appendTo(list)
548
+ // .slideDown()
549
+ // .delay(3000)
550
+ // .slideUp(function(){
551
+ // $(this).remove();
552
+ // if(!$('li', list).length){
553
+ // list.detach();
554
+ // }
555
+ // })
556
+ // ;
557
+ // };
558
+ // $.each(webshims.errorLog, function(i, message){
559
+ // webshims.errorLog.push(message);
560
+ // });
561
+ // }
562
+ // })();
512
563
 
513
564
  //shortcus
514
565
  var modules = webshims.modules;
@@ -526,6 +577,24 @@ jQuery.webshims.register('dom-extend', function($, webshims, window, document, u
526
577
  return (_argless) ? oldVal.call($(elem)) : oldVal.call($(elem), val);
527
578
  };
528
579
 
580
+ //jquery mobile and jquery ui
581
+ if(!$.widget){
582
+ (function(){
583
+ var _cleanData = $.cleanData;
584
+ $.cleanData = function( elems ) {
585
+ if(!$.widget){
586
+ for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
587
+ try {
588
+ $( elem ).triggerHandler( "remove" );
589
+ // http://bugs.jquery.com/ticket/8235
590
+ } catch( e ) {}
591
+ }
592
+ }
593
+ _cleanData( elems );
594
+ };
595
+ })();
596
+ }
597
+
529
598
 
530
599
  $.fn.val = function(val){
531
600
  var elem = this[0];
@@ -559,6 +628,18 @@ jQuery.webshims.register('dom-extend', function($, webshims, window, document, u
559
628
  return this.on(evt, fn).each(fn);
560
629
  };
561
630
 
631
+ $.fn.onWSOff = function(evt, fn, trigger, evtDel){
632
+ if(!evtDel){
633
+ evtDel = document;
634
+ }
635
+ $(evtDel)[trigger ? 'onTrigger' : 'on'](evt, fn);
636
+ this.on('remove', function(e){
637
+ if(!e.originalEvent){
638
+ $(evtDel).off(evt, fn);
639
+ }
640
+ });
641
+ };
642
+
562
643
  var dataID = '_webshimsLib'+ (Math.round(Math.random() * 1000));
563
644
  var elementData = function(elem, key, val){
564
645
  elem = elem.jquery ? elem[0] : elem;
@@ -920,7 +1001,7 @@ jQuery.webshims.register('dom-extend', function($, webshims, window, document, u
920
1001
  implement: function(elem, type){
921
1002
  var data = elementData(elem, 'implemented') || elementData(elem, 'implemented', {});
922
1003
  if(data[type]){
923
- webshims.info(type +' already implemented for element #'+elem.id);
1004
+ webshims.warn(type +' already implemented for element #'+elem.id);
924
1005
  return false;
925
1006
  }
926
1007
  data[type] = true;
@@ -1064,6 +1145,12 @@ jQuery.webshims.register('dom-extend', function($, webshims, window, document, u
1064
1145
  shadowFocusElementData = $.data(opts.shadowFocusElement, dataID) || $.data(opts.shadowFocusElement, dataID, shadowFocusElementData);
1065
1146
  }
1066
1147
 
1148
+ $(nativeElem).on('remove', function(e){
1149
+ if (!e.originalEvent) {
1150
+ $(shadowElem).remove();
1151
+ }
1152
+ });
1153
+
1067
1154
  nativeData.hasShadow = shadowElem;
1068
1155
  shadowFocusElementData.nativeElement = shadowData.nativeElement = nativeElem;
1069
1156
  shadowFocusElementData.shadowData = shadowData.shadowData = nativeData.shadowData = {
@@ -1539,32 +1626,9 @@ jQuery.webshims.register('dom-extend', function($, webshims, window, document, u
1539
1626
 
1540
1627
  })(jQuery, document);
1541
1628
 
1542
- //additional tests for partial implementation of forms features
1543
- (function($){
1629
+ webshims.register('form-core', function($, webshims, window, document, undefined, options){
1544
1630
  "use strict";
1545
- var isWebkit = 'webkitURL' in window;
1546
- var Modernizr = window.Modernizr;
1547
- var webshims = $.webshims;
1548
- var bugs = webshims.bugs;
1549
- var form = $('<form action="#" style="width: 1px; height: 1px; overflow: hidden;"><select name="b" required="" /><input required="" name="a" /></form>');
1550
- var testRequiredFind = function(){
1551
- if(form[0].querySelector){
1552
- try {
1553
- bugs.findRequired = !(form[0].querySelector('select:required'));
1554
- } catch(er){
1555
- bugs.findRequired = false;
1556
- }
1557
- }
1558
- };
1559
- var inputElem = $('input', form).eq(0);
1560
- var onDomextend = function(fn){
1561
- webshims.loader.loadList(['dom-extend']);
1562
- webshims.ready('dom-extend', fn);
1563
- };
1564
-
1565
- bugs.findRequired = false;
1566
- bugs.validationMessage = false;
1567
-
1631
+
1568
1632
  webshims.capturingEventPrevented = function(e){
1569
1633
  if(!e._isPolyfilled){
1570
1634
  var isDefaultPrevented = e.isDefaultPrevented;
@@ -1583,689 +1647,238 @@ jQuery.webshims.register('dom-extend', function($, webshims, window, document, u
1583
1647
  }
1584
1648
  };
1585
1649
 
1586
- if(!Modernizr.formvalidation || bugs.bustedValidity){
1587
- testRequiredFind();
1588
- } else {
1650
+ if(Modernizr.formvalidation && !webshims.bugs.bustedValidity){
1589
1651
  //create delegatable events
1590
1652
  webshims.capturingEvents(['invalid'], true);
1591
-
1592
- if(window.opera || window.testGoodWithFix){
1593
-
1594
- form.appendTo('head');
1595
-
1596
- testRequiredFind();
1597
- bugs.validationMessage = !(inputElem.prop('validationMessage'));
1653
+ }
1654
+
1655
+ var isValid = function(elem){
1656
+ return ($.prop(elem, 'validity') || {valid: 1}).valid;
1657
+ };
1658
+ var lazyLoad = function(){
1659
+ var toLoad = ['form-validation'];
1660
+ if(options.lazyCustomMessages){
1661
+ options.customMessages = true;
1662
+ toLoad.push('form-message');
1663
+ }
1664
+ if(options.addValidators){
1665
+ toLoad.push('form-validators');
1666
+ }
1667
+ webshims.reTest(toLoad);
1668
+ $(document).off('.lazyloadvalidation');
1669
+ };
1670
+ /*
1671
+ * Selectors for all browsers
1672
+ */
1673
+ var hasInvalid = function(elem){
1674
+ var ret = false;
1675
+ $(elem).jProp('elements').each(function(){
1676
+ ret = $(this).is(':invalid');
1677
+ if(ret){
1678
+ return false;
1679
+ }
1680
+ });
1681
+ return ret;
1682
+ };
1683
+ var rElementsGroup = /^(?:form)$/i;///^(?:form|fieldset)$/i
1684
+ $.extend($.expr[":"], {
1685
+ "valid-element": function(elem){
1686
+ return rElementsGroup.test(elem.nodeName || '') ? !hasInvalid(elem) :!!($.prop(elem, 'willValidate') && isValid(elem));
1687
+ },
1688
+ "invalid-element": function(elem){
1689
+ return rElementsGroup.test(elem.nodeName || '') ? hasInvalid(elem) : !!($.prop(elem, 'willValidate') && !isValid(elem));
1690
+ },
1691
+ "required-element": function(elem){
1692
+ return !!($.prop(elem, 'willValidate') && $.prop(elem, 'required'));
1693
+ },
1694
+ "user-error": function(elem){
1695
+ return ($.prop(elem, 'willValidate') && $(elem).hasClass('user-error'));
1696
+ },
1697
+ "optional-element": function(elem){
1698
+ return !!($.prop(elem, 'willValidate') && $.prop(elem, 'required') === false);
1699
+ }
1700
+ });
1701
+
1702
+ ['valid', 'invalid', 'required', 'optional'].forEach(function(name){
1703
+ $.expr[":"][name] = $.expr.filters[name+"-element"];
1704
+ });
1705
+
1706
+
1707
+ $.expr[":"].focus = function( elem ) {
1708
+ try {
1709
+ var doc = elem.ownerDocument;
1710
+ return elem === doc.activeElement && (!doc.hasFocus || doc.hasFocus());
1711
+ } catch(e){}
1712
+ return false;
1713
+ };
1714
+
1715
+ webshims.triggerInlineForm = function(elem, event){
1716
+ $(elem).trigger(event);
1717
+ };
1718
+
1719
+ var lazyLoadProxy = function(obj, fn, args){
1720
+ lazyLoad();
1721
+ webshims.ready('form-validation', function(){
1722
+ obj[fn].apply(obj, args);
1723
+ });
1724
+ };
1725
+
1726
+
1727
+ webshims.wsPopover = {
1728
+ id: 0,
1729
+ _create: function(){
1730
+ this.options = $.extend({}, webshims.cfg.wspopover, this.options);
1731
+ this.id = webshims.wsPopover.id++;
1732
+ this.eventns = '.wsoverlay' + this.id;
1733
+ this.timers = {};
1734
+ this.element = $('<div class="ws-popover" tabindex="-1"><div class="ws-po-outerbox"><div class="ws-po-arrow"><div class="ws-po-arrowbox" /></div><div class="ws-po-box" /></div></div>');
1735
+ this.contentElement = $('.ws-po-box', this.element);
1736
+ this.lastElement = $([]);
1737
+ this.bindElement();
1598
1738
 
1599
- webshims.reTest(['form-native-extend', 'form-message']);
1739
+ this.element.data('wspopover', this);
1600
1740
 
1601
- form.remove();
1602
-
1603
- $(function(){
1604
- onDomextend(function(){
1605
-
1606
- //Opera shows native validation bubbles in case of input.checkValidity()
1607
- // Opera 11.6/12 hasn't fixed this issue right, it's buggy
1608
- var preventDefault = function(e){
1609
- e.preventDefault();
1610
- };
1611
-
1612
- ['form', 'input', 'textarea', 'select'].forEach(function(name){
1613
- var desc = webshims.defineNodeNameProperty(name, 'checkValidity', {
1614
- prop: {
1615
- value: function(){
1616
- if (!webshims.fromSubmit) {
1617
- $(this).on('invalid.checkvalidity', preventDefault);
1618
- }
1619
-
1620
- webshims.fromCheckValidity = true;
1621
- var ret = desc.prop._supvalue.apply(this, arguments);
1622
- if (!webshims.fromSubmit) {
1623
- $(this).unbind('invalid.checkvalidity', preventDefault);
1624
- }
1625
- webshims.fromCheckValidity = false;
1626
- return ret;
1627
- }
1628
- }
1629
- });
1630
- });
1631
-
1632
- });
1741
+ },
1742
+ options: {},
1743
+ content: function(html){
1744
+ this.contentElement.html(html);
1745
+ },
1746
+ bindElement: function(){
1747
+ var that = this;
1748
+ var stopBlur = function(){
1749
+ that.stopBlur = false;
1750
+ };
1751
+ this.preventBlur = function(e){
1752
+ that.stopBlur = true;
1753
+ clearTimeout(that.timers.stopBlur);
1754
+ that.timers.stopBlur = setTimeout(stopBlur, 9);
1755
+ };
1756
+ this.element.on({
1757
+ 'mousedown': this.preventBlur
1633
1758
  });
1759
+ },
1760
+ show: function(){
1761
+ lazyLoadProxy(this, 'show', arguments);
1634
1762
  }
1635
-
1636
- if(isWebkit && !webshims.bugs.bustedValidity){
1637
- (function(){
1638
- var elems = /^(?:textarea|input)$/i;
1639
- var form = false;
1640
-
1641
- document.addEventListener('contextmenu', function(e){
1642
- if(elems.test( e.target.nodeName || '') && (form = e.target.form)){
1643
- setTimeout(function(){
1644
- form = false;
1645
- }, 1);
1646
- }
1647
- }, false);
1648
-
1649
- $(window).on('invalid', function(e){
1650
- if(e.originalEvent && form && form == e.target.form){
1651
- e.wrongWebkitInvalid = true;
1652
- e.stopImmediatePropagation();
1653
- }
1654
- });
1655
-
1656
- })();
1763
+ };
1764
+
1765
+ /* some extra validation UI */
1766
+ webshims.validityAlert = {
1767
+ showFor: function(){
1768
+ lazyLoadProxy(this, 'showFor', arguments);
1657
1769
  }
1658
- }
1659
-
1660
- $.webshims.register('form-core', function($, webshims, window, document, undefined, options){
1661
-
1662
- var checkTypes = {checkbox: 1, radio: 1};
1663
- var emptyJ = $([]);
1664
- var bugs = webshims.bugs;
1665
- var getGroupElements = function(elem){
1666
- elem = $(elem);
1667
- var name;
1668
- var form;
1669
- var ret = emptyJ;
1670
- if(elem[0].type == 'radio'){
1671
- form = elem.prop('form');
1672
- name = elem[0].name;
1673
- if(!name){
1674
- ret = elem;
1675
- } else if(form){
1676
- ret = $(form[name]);
1677
- } else {
1678
- ret = $(document.getElementsByName(name)).filter(function(){
1679
- return !$.prop(this, 'form');
1680
- });
1681
- }
1682
- ret = ret.filter('[type="radio"]');
1683
- }
1684
- return ret;
1685
- };
1770
+ };
1771
+
1772
+
1773
+ /* extension, but also used to fix native implementation workaround/bugfixes */
1774
+ (function(){
1775
+ var firstEvent,
1776
+ invalids = [],
1777
+ stopSubmitTimer,
1778
+ form
1779
+ ;
1686
1780
 
1687
- var getContentValidationMessage = webshims.getContentValidationMessage = function(elem, validity, key){
1688
- var message = $(elem).data('errormessage') || elem.getAttribute('x-moz-errormessage') || '';
1689
- if(key && message[key]){
1690
- message = message[key];
1691
- }
1692
- if(typeof message == 'object'){
1693
- validity = validity || $.prop(elem, 'validity') || {valid: 1};
1694
- if(!validity.valid){
1695
- $.each(validity, function(name, prop){
1696
- if(prop && name != 'valid' && message[name]){
1697
- message = message[name];
1698
- return false;
1699
- }
1700
- });
1701
- }
1702
- }
1781
+ $(document).on('invalid', function(e){
1782
+ if(e.wrongWebkitInvalid){return;}
1783
+ var jElm = $(e.target);
1703
1784
 
1704
- if(typeof message == 'object'){
1705
- message = message.defaultMessage;
1706
- }
1707
- return message || '';
1708
- };
1709
-
1710
- /*
1711
- * Selectors for all browsers
1712
- */
1713
- var rangeTypes = {number: 1, range: 1, date: 1/*, time: 1, 'datetime-local': 1, datetime: 1, month: 1, week: 1*/};
1714
- var hasInvalid = function(elem){
1715
- var ret = false;
1716
- $($.prop(elem, 'elements')).each(function(){
1717
- ret = $(this).is(':invalid');
1718
- if(ret){
1719
- return false;
1720
- }
1721
- });
1722
- return ret;
1723
- };
1724
- $.extend($.expr[":"], {
1725
- "valid-element": function(elem){
1726
- return $.nodeName(elem, 'form') ? !hasInvalid(elem) :!!($.prop(elem, 'willValidate') && isValid(elem));
1727
- },
1728
- "invalid-element": function(elem){
1729
- return $.nodeName(elem, 'form') ? hasInvalid(elem) : !!($.prop(elem, 'willValidate') && !isValid(elem));
1730
- },
1731
- "required-element": function(elem){
1732
- return !!($.prop(elem, 'willValidate') && $.prop(elem, 'required'));
1733
- },
1734
- "user-error": function(elem){
1735
- return ($.prop(elem, 'willValidate') && $(elem).hasClass('user-error'));
1736
- },
1737
- "optional-element": function(elem){
1738
- return !!($.prop(elem, 'willValidate') && $.prop(elem, 'required') === false);
1739
- },
1740
- "in-range": function(elem){
1741
- if(!rangeTypes[$.prop(elem, 'type')] || !$.prop(elem, 'willValidate')){
1742
- return false;
1743
- }
1744
- var val = $.prop(elem, 'validity');
1745
- return !!(val && !val.rangeOverflow && !val.rangeUnderflow);
1746
- },
1747
- "out-of-range": function(elem){
1748
- if(!rangeTypes[$.prop(elem, 'type')] || !$.prop(elem, 'willValidate')){
1749
- return false;
1750
- }
1751
- var val = $.prop(elem, 'validity');
1752
- return !!(val && (val.rangeOverflow || val.rangeUnderflow));
1753
- }
1754
1785
 
1786
+ if(!firstEvent){
1787
+ //trigger firstinvalid
1788
+ firstEvent = $.Event('firstinvalid');
1789
+ firstEvent.isInvalidUIPrevented = e.isDefaultPrevented;
1790
+ var firstSystemInvalid = $.Event('firstinvalidsystem');
1791
+ $(document).triggerHandler(firstSystemInvalid, {element: e.target, form: e.target.form, isInvalidUIPrevented: e.isDefaultPrevented});
1792
+ jElm.trigger(firstEvent);
1793
+ }
1794
+
1795
+ //if firstinvalid was prevented all invalids will be also prevented
1796
+ if( firstEvent && firstEvent.isDefaultPrevented() ){
1797
+ e.preventDefault();
1798
+ }
1799
+ invalids.push(e.target);
1800
+ e.extraData = 'fix';
1801
+ clearTimeout(stopSubmitTimer);
1802
+ stopSubmitTimer = setTimeout(function(){
1803
+ var lastEvent = {type: 'lastinvalid', cancelable: false, invalidlist: $(invalids)};
1804
+ //reset firstinvalid
1805
+ firstEvent = false;
1806
+ invalids = [];
1807
+ $(e.target).trigger(lastEvent, lastEvent);
1808
+ }, 9);
1809
+ jElm = null;
1755
1810
  });
1756
-
1757
- ['valid', 'invalid', 'required', 'optional'].forEach(function(name){
1758
- $.expr[":"][name] = $.expr.filters[name+"-element"];
1759
- });
1760
-
1761
-
1762
- $.expr[":"].focus = function( elem ) {
1763
- try {
1764
- var doc = elem.ownerDocument;
1765
- return elem === doc.activeElement && (!doc.hasFocus || doc.hasFocus());
1766
- } catch(e){}
1767
- return false;
1768
- };
1769
-
1770
-
1771
- var customEvents = $.event.customEvent || {};
1772
- var isValid = function(elem){
1773
- return ($.prop(elem, 'validity') || {valid: 1}).valid;
1774
- };
1775
-
1776
- if (bugs.bustedValidity || bugs.findRequired) {
1777
- (function(){
1778
- var find = $.find;
1779
- var matchesSelector = $.find.matchesSelector;
1780
-
1781
- var regExp = /(\:valid|\:invalid|\:optional|\:required|\:in-range|\:out-of-range)(?=[\s\[\~\.\+\>\:\#*]|$)/ig;
1782
- var regFn = function(sel){
1783
- return sel + '-element';
1784
- };
1785
-
1786
- $.find = (function(){
1787
- var slice = Array.prototype.slice;
1788
- var fn = function(sel){
1789
- var ar = arguments;
1790
- ar = slice.call(ar, 1, ar.length);
1791
- ar.unshift(sel.replace(regExp, regFn));
1792
- return find.apply(this, ar);
1793
- };
1794
- for (var i in find) {
1795
- if(find.hasOwnProperty(i)){
1796
- fn[i] = find[i];
1797
- }
1798
- }
1799
- return fn;
1800
- })();
1801
- if(!Modernizr.prefixed || Modernizr.prefixed("matchesSelector", document.documentElement)){
1802
- $.find.matchesSelector = function(node, expr){
1803
- expr = expr.replace(regExp, regFn);
1804
- return matchesSelector.call(this, node, expr);
1805
- };
1806
- }
1807
-
1808
- })();
1811
+ })();
1812
+
1813
+
1814
+ webshims.getContentValidationMessage = function(elem, validity, key){
1815
+ var message = $(elem).data('errormessage') || elem.getAttribute('x-moz-errormessage') || '';
1816
+ if(key && message[key]){
1817
+ message = message[key];
1809
1818
  }
1810
-
1811
- //ToDo needs testing
1812
- var oldAttr = $.prop;
1813
- var changeVals = {selectedIndex: 1, value: 1, checked: 1, disabled: 1, readonly: 1};
1814
- $.prop = function(elem, name, val){
1815
- var ret = oldAttr.apply(this, arguments);
1816
- if(elem && 'form' in elem && changeVals[name] && val !== undefined && $(elem).hasClass(invalidClass)){
1817
- if(isValid(elem)){
1818
- $(elem).getShadowElement().removeClass(invalidClass);
1819
- if(name == 'checked' && val) {
1820
- getGroupElements(elem).not(elem).removeClass(invalidClass).removeAttr('aria-invalid');
1819
+ if(typeof message == 'object'){
1820
+ validity = validity || $.prop(elem, 'validity') || {valid: 1};
1821
+ if(!validity.valid){
1822
+ $.each(validity, function(name, prop){
1823
+ if(prop && name != 'valid' && message[name]){
1824
+ message = message[name];
1825
+ return false;
1821
1826
  }
1822
- }
1827
+ });
1823
1828
  }
1824
- return ret;
1825
- };
1826
-
1827
- var returnValidityCause = function(validity, elem){
1828
- var ret;
1829
- $.each(validity, function(name, value){
1830
- if(value){
1831
- ret = (name == 'customError') ? $.prop(elem, 'validationMessage') : name;
1832
- return false;
1833
- }
1834
- });
1835
- return ret;
1836
- };
1829
+ }
1837
1830
 
1838
- var isInGroup = function(name){
1839
- var ret;
1840
- try {
1841
- ret = document.activeElement.name === name;
1842
- } catch(e){}
1843
- return ret;
1844
- };
1845
- /* form-ui-invalid/form-ui-valid are deprecated. use user-error/user-success instead */
1846
- var invalidClass = 'user-error';
1847
- var validClass = 'user-success';
1848
- var stopChangeTypes = {
1849
- time: 1,
1850
- date: 1,
1851
- month: 1,
1852
- datetime: 1,
1853
- week: 1,
1854
- 'datetime-local': 1
1855
- };
1856
- var switchValidityClass = function(e){
1857
- var elem, timer;
1858
- if(!e.target){return;}
1859
- elem = $(e.target).getNativeElement()[0];
1860
- if(elem.type == 'submit' || !$.prop(elem, 'willValidate')){return;}
1861
- timer = $.data(elem, 'webshimsswitchvalidityclass');
1862
- var switchClass = function(){
1863
- if(e.type == 'focusout' && elem.type == 'radio' && isInGroup(elem.name)){return;}
1864
- var validity = $.prop(elem, 'validity');
1865
- var shadowElem = $(elem).getShadowElement();
1866
- var addClass, removeClass, trigger, generaltrigger, validityCause;
1867
-
1868
- if(isWebkit && e.type == 'change' && !bugs.bustedValidity && stopChangeTypes[shadowElem.prop('type')] && shadowElem.is(':focus')){return;}
1869
-
1870
- $(elem).trigger('refreshCustomValidityRules');
1871
-
1872
- if(validity.valid){
1873
- if(!shadowElem.hasClass(validClass)){
1874
- addClass = validClass;
1875
- removeClass = invalidClass;
1876
- generaltrigger = 'changedvaliditystate';
1877
- trigger = 'changedvalid';
1878
- if(checkTypes[elem.type] && elem.checked){
1879
- getGroupElements(elem).not(elem).removeClass(removeClass).addClass(addClass).removeAttr('aria-invalid');
1880
- }
1881
- $.removeData(elem, 'webshimsinvalidcause');
1882
- }
1883
- } else {
1884
- validityCause = returnValidityCause(validity, elem);
1885
- if($.data(elem, 'webshimsinvalidcause') != validityCause){
1886
- $.data(elem, 'webshimsinvalidcause', validityCause);
1887
- generaltrigger = 'changedvaliditystate';
1888
- }
1889
- if(!shadowElem.hasClass(invalidClass)){
1890
- addClass = invalidClass;
1891
- removeClass = validClass;
1892
- if (checkTypes[elem.type] && !elem.checked) {
1893
- getGroupElements(elem).not(elem).removeClass(removeClass).addClass(addClass);
1894
- }
1895
- trigger = 'changedinvalid';
1896
- }
1897
- }
1898
-
1899
- if(addClass){
1900
- shadowElem.addClass(addClass).removeClass(removeClass);
1901
- //jQuery 1.6.1 IE9 bug (doubble trigger bug)
1902
- setTimeout(function(){
1903
- $(elem).trigger(trigger);
1904
- }, 0);
1905
- }
1906
- if(generaltrigger){
1907
- setTimeout(function(){
1908
- $(elem).trigger(generaltrigger);
1909
- }, 0);
1910
- }
1911
-
1912
- $.removeData(elem, 'webshimsswitchvalidityclass');
1913
- };
1914
-
1915
- if(timer){
1916
- clearTimeout(timer);
1917
- }
1918
- if(e.type == 'refreshvalidityui'){
1919
- switchClass();
1920
- } else {
1921
- $.data(elem, 'webshimsswitchvalidityclass', setTimeout(switchClass, 9));
1831
+ if(typeof message == 'object'){
1832
+ message = message.defaultMessage;
1833
+ }
1834
+ return message || '';
1835
+ };
1836
+
1837
+ $.fn.getErrorMessage = function(key){
1838
+ var message = '';
1839
+ var elem = this[0];
1840
+ if(elem){
1841
+ message = webshims.getContentValidationMessage(elem, false, key) || $.prop(elem, 'customValidationMessage') || $.prop(elem, 'validationMessage');
1842
+ }
1843
+ return message;
1844
+ };
1845
+
1846
+
1847
+ webshims.ready('forms', function(){
1848
+ $(document).on('focusin.lazyloadvalidation', function(e){
1849
+ if('form' in e.target && $(e.target).is(':invalid')){
1850
+ lazyLoad();
1922
1851
  }
1923
- };
1924
-
1925
- $(document).on(options.validityUIEvents || 'focusout change refreshvalidityui', switchValidityClass);
1926
- customEvents.changedvaliditystate = true;
1927
- customEvents.refreshCustomValidityRules = true;
1928
- customEvents.changedvalid = true;
1929
- customEvents.changedinvalid = true;
1930
- customEvents.refreshvalidityui = true;
1931
-
1932
-
1933
- webshims.triggerInlineForm = function(elem, event){
1934
- $(elem).trigger(event);
1935
- };
1936
-
1937
- webshims.modules["form-core"].getGroupElements = getGroupElements;
1938
-
1939
-
1940
- var setRoot = function(){
1941
- webshims.scrollRoot = (isWebkit || document.compatMode == 'BackCompat') ?
1942
- $(document.body) :
1943
- $(document.documentElement)
1944
- ;
1945
- };
1946
- var minWidth = (Modernizr.boxSizing || Modernizr['display-table'] || $.support.getSetAttribute) ?
1947
- 'minWidth' :
1948
- 'width'
1949
- ;
1950
- setRoot();
1951
- webshims.ready('DOM', setRoot);
1952
-
1953
- webshims.getRelOffset = function(posElem, relElem){
1954
- posElem = $(posElem);
1955
- var offset = $(relElem).offset();
1956
- var bodyOffset;
1957
- $.swap($(posElem)[0], {visibility: 'hidden', display: 'inline-block', left: 0, top: 0}, function(){
1958
- bodyOffset = posElem.offset();
1852
+ });
1853
+ });
1854
+ webshims.ready('WINDOWLOAD', lazyLoad);
1855
+ if(options.overrideMessages){
1856
+ options.customMessages = true;
1857
+ webshims.reTest('form-message');
1858
+ webshims.error('overrideMessages is deprecated. use customMessages instead.');
1859
+ }
1860
+ if(options.replaceValidationUI){
1861
+ webshims.ready('DOM forms', function(){
1862
+ $(document).on('firstinvalid', function(e){
1863
+ if(!e.isInvalidUIPrevented()){
1864
+ e.preventDefault();
1865
+ webshims.validityAlert.showFor( e.target );
1866
+ }
1959
1867
  });
1960
- offset.top -= bodyOffset.top;
1961
- offset.left -= bodyOffset.left;
1962
- return offset;
1963
- };
1964
-
1965
- webshims.wsPopover = {
1966
- _create: function(){
1967
- this.options = $.extend({}, webshims.cfg.wspopover, this.options);
1968
- this.id = webshims.wsPopover.id++;
1969
- this.eventns = '.wsoverlay'+this.id;
1970
- this.timers = {};
1971
- this.element = $('<div class="ws-popover" tabindex="-1"><div class="ws-po-outerbox"><div class="ws-po-arrow"><div class="ws-po-arrowbox" /></div><div class="ws-po-box" /></div></div>');
1972
- this.contentElement = $('.ws-po-box', this.element);
1973
- this.lastElement = $([]);
1974
- this.bindElement();
1975
-
1976
- this.element.data('wspopover', this);
1977
-
1978
- },
1979
- options: {},
1980
- content: function(html){
1981
- this.contentElement.html(html);
1982
- },
1983
- bindElement: function(){
1984
- var that = this;
1985
- var stopBlur = function(){
1986
- that.stopBlur = false;
1987
- };
1988
- this.preventBlur = function(e){
1989
- that.stopBlur = true;
1990
- clearTimeout(that.timers.stopBlur);
1991
- that.timers.stopBlur = setTimeout(stopBlur, 9);
1992
- };
1993
- this.element.on({
1994
- 'mousedown': this.preventBlur
1995
- });
1996
- },
1997
-
1998
- isInElement: function(container, contained){
1999
- return container == contained || $.contains(container, contained);
2000
- },
2001
- show: function(element){
2002
- var e = $.Event('wspopoverbeforeshow');
2003
- this.element.trigger(e);
2004
- if(e.isDefaultPrevented() || this.isVisible){return;}
2005
- this.isVisible = true;
2006
- element = $(element || this.options.prepareFor).getNativeElement() ;
2007
-
2008
- var that = this;
2009
- var visual = $(element).getShadowElement();
1868
+ });
1869
+ }
1870
+ });
1871
+
1872
+
1873
+ webshims.register('form-message', function($, webshims, window, document, undefined, options){
1874
+ "use strict";
1875
+ if(options.overrideMessages){
1876
+ options.customMessages = true;
1877
+ webshims.error('overrideMessages is deprecated. use customMessages instead.');
1878
+ }
1879
+ var validityMessages = webshims.validityMessages;
2010
1880
 
2011
- this.clear();
2012
- this.element.removeClass('ws-po-visible').css('display', 'none');
2013
-
2014
- this.prepareFor(element, visual);
2015
-
2016
- this.position(visual);
2017
- that.timers.show = setTimeout(function(){
2018
- that.element.css('display', '');
2019
- that.timers.show = setTimeout(function(){
2020
- that.element.addClass('ws-po-visible').trigger('wspopovershow');
2021
- }, 9);
2022
- }, 9);
2023
- $(document).on('focusin'+this.eventns+' mousedown'+this.eventns, function(e){
2024
- if(that.options.hideOnBlur && !that.stopBlur && !that.isInElement(that.lastElement[0] || document.body, e.target) && !that.isInElement(element[0] || document.body, e.target) && !that.isInElement(that.element[0], e.target)){
2025
- that.hide();
2026
- }
2027
- });
2028
- $(window).on('resize'+this.eventns + ' pospopover'+this.eventns, function(){
2029
- clearTimeout(that.timers.repos);
2030
- that.timers.repos = setTimeout(function(){
2031
- that.position(visual);
2032
- }, 900);
2033
- });
2034
- },
2035
- prepareFor: function(element, visual){
2036
- var onBlur;
2037
- var opts = $.extend({}, this.options, $(element.prop('form') || []).data('wspopover') || {}, element.data('wspopover'));
2038
- var that = this;
2039
- var css = {};
2040
- this.lastElement = $(element).getShadowFocusElement();
2041
- if(opts.appendTo == 'element'){
2042
- this.element.insertAfter(element);
2043
- } else {
2044
- this.element.appendTo(opts.appendTo);
2045
- }
2046
-
2047
- this.element.attr({
2048
- 'data-class': element.prop('className'),
2049
- 'data-id': element.prop('id')
2050
- });
2051
-
2052
- css[minWidth] = opts.constrainWidth ? visual.outerWidth() : '';
2053
-
2054
- this.element.css(css);
2055
-
2056
- if(opts.hideOnBlur){
2057
- onBlur = function(e){
2058
- if(that.stopBlur){
2059
- e.stopImmediatePropagation();
2060
- } else {
2061
- that.hide();
2062
- }
2063
- };
2064
-
2065
- that.timers.bindBlur = setTimeout(function(){
2066
- that.lastElement.off(that.eventns).on('focusout'+that.eventns + ' blur'+that.eventns, onBlur);
2067
- that.lastElement.getNativeElement().off(that.eventns);
2068
- }, 10);
2069
-
2070
-
2071
- }
2072
-
2073
- if(!this.prepared){
2074
-
2075
- if($.fn.bgIframe){
2076
- this.element.bgIframe();
2077
- }
2078
- }
2079
- this.prepared = true;
2080
- },
2081
- clear: function(){
2082
- $(window).off(this.eventns);
2083
- $(document).off(this.eventns);
2084
-
2085
- this.stopBlur = false;
2086
- $.each(this.timers, function(timerName, val){
2087
- clearTimeout(val);
2088
- });
2089
- },
2090
- hide: function(){
2091
- var e = $.Event('wspopoverbeforehide');
2092
- this.element.trigger(e);
2093
- if(e.isDefaultPrevented() || !this.isVisible){return;}
2094
- this.isVisible = false;
2095
- var that = this;
2096
- var forceHide = function(){
2097
- that.element.css('display', 'none').attr({'data-id': '', 'data-class': '', 'hidden': 'hidden'});
2098
- clearTimeout(that.timers.forcehide);
2099
- };
2100
- this.clear();
2101
- this.element.removeClass('ws-po-visible').trigger('wspopoverhide');
2102
- $(window).on('resize'+this.eventns, forceHide);
2103
- that.timers.forcehide = setTimeout(forceHide, 999);
2104
- },
2105
- position: function(element){
2106
- var offset = webshims.getRelOffset(this.element.css({marginTop: 0, marginLeft: 0, marginRight: 0, marginBottom: 0}).removeAttr('hidden'), element);
2107
- offset.top += element.outerHeight();
2108
- this.element.css({marginTop: '', marginLeft: '', marginRight: '', marginBottom: ''}).css(offset);
2109
- }
2110
- };
2111
-
2112
- webshims.wsPopover.id = 0;
2113
-
2114
- /* some extra validation UI */
2115
- webshims.validityAlert = (function(){
2116
-
2117
-
2118
- var focusTimer = false;
2119
-
2120
- var api = webshims.objectCreate(webshims.wsPopover, {}, options.messagePopover);
2121
- var boundHide = api.hide.bind(api);
2122
-
2123
- api.element.addClass('validity-alert').attr({role: 'alert'});
2124
- $.extend(api, {
2125
- hideDelay: 5000,
2126
- showFor: function(elem, message, noFocusElem, noBubble){
2127
-
2128
- elem = $(elem).getNativeElement();
2129
- this.clear();
2130
- this.hide();
2131
- if(!noBubble){
2132
- this.getMessage(elem, message);
2133
-
2134
- this.show(elem);
2135
- if(this.hideDelay){
2136
- this.timers.delayedHide = setTimeout(boundHide, this.hideDelay);
2137
- }
2138
-
2139
- }
2140
-
2141
- if(!noFocusElem){
2142
- this.setFocus(elem);
2143
- }
2144
- },
2145
- setFocus: function(element){
2146
- var focusElem = $(element).getShadowFocusElement();
2147
- var scrollTop = webshims.scrollRoot.scrollTop();
2148
- var elemTop = focusElem.offset().top - 30;
2149
- var smooth;
2150
-
2151
- if(scrollTop > elemTop){
2152
- webshims.scrollRoot.animate(
2153
- {scrollTop: elemTop - 5},
2154
- {
2155
- queue: false,
2156
- duration: Math.max( Math.min( 600, (scrollTop - elemTop) * 1.5 ), 80 )
2157
- }
2158
- );
2159
- smooth = true;
2160
- }
2161
- try {
2162
- focusElem[0].focus();
2163
- } catch(e){}
2164
- if(smooth){
2165
- webshims.scrollRoot.scrollTop(scrollTop);
2166
- setTimeout(function(){
2167
- webshims.scrollRoot.scrollTop(scrollTop);
2168
- }, 0);
2169
- }
2170
-
2171
- $(window).triggerHandler('pospopover'+this.eventns);
2172
- },
2173
- getMessage: function(elem, message){
2174
- if (!message) {
2175
- message = getContentValidationMessage(elem[0]) || elem.prop('customValidationMessage') || elem.prop('validationMessage');
2176
- }
2177
- if (message) {
2178
- api.contentElement.text(message);
2179
- } else {
2180
- this.hide();
2181
- }
2182
- }
2183
- });
2184
-
2185
-
2186
- return api;
2187
- })();
2188
-
2189
-
2190
- /* extension, but also used to fix native implementation workaround/bugfixes */
2191
- (function(){
2192
- var firstEvent,
2193
- invalids = [],
2194
- stopSubmitTimer,
2195
- form
2196
- ;
2197
-
2198
- $(document).on('invalid', function(e){
2199
- if(e.wrongWebkitInvalid){return;}
2200
- var jElm = $(e.target);
2201
- var shadowElem = jElm.getShadowElement();
2202
- if(!shadowElem.hasClass(invalidClass)){
2203
- shadowElem.addClass(invalidClass).removeClass(validClass);
2204
- setTimeout(function(){
2205
- $(e.target).trigger('changedinvalid').trigger('changedvaliditystate');
2206
- }, 0);
2207
- }
2208
-
2209
- if(!firstEvent){
2210
- //trigger firstinvalid
2211
- firstEvent = $.Event('firstinvalid');
2212
- firstEvent.isInvalidUIPrevented = e.isDefaultPrevented;
2213
- var firstSystemInvalid = $.Event('firstinvalidsystem');
2214
- $(document).triggerHandler(firstSystemInvalid, {element: e.target, form: e.target.form, isInvalidUIPrevented: e.isDefaultPrevented});
2215
- jElm.trigger(firstEvent);
2216
- }
2217
-
2218
- //if firstinvalid was prevented all invalids will be also prevented
2219
- if( firstEvent && firstEvent.isDefaultPrevented() ){
2220
- e.preventDefault();
2221
- }
2222
- invalids.push(e.target);
2223
- e.extraData = 'fix';
2224
- clearTimeout(stopSubmitTimer);
2225
- stopSubmitTimer = setTimeout(function(){
2226
- var lastEvent = {type: 'lastinvalid', cancelable: false, invalidlist: $(invalids)};
2227
- //reset firstinvalid
2228
- firstEvent = false;
2229
- invalids = [];
2230
- $(e.target).trigger(lastEvent, lastEvent);
2231
- }, 9);
2232
- jElm = null;
2233
- shadowElem = null;
2234
- });
2235
- })();
2236
-
2237
- $.fn.getErrorMessage = function(){
2238
- var message = '';
2239
- var elem = this[0];
2240
- if(elem){
2241
- message = getContentValidationMessage(elem) || $.prop(elem, 'customValidationMessage') || $.prop(elem, 'validationMessage');
2242
- }
2243
- return message;
2244
- };
2245
-
2246
- if(options.replaceValidationUI){
2247
- if(options.overrideMessages && (options.customMessages || options.customMessages == null)){
2248
- options.customMessages = true;
2249
- options.overrideMessages = false;
2250
- webshims.info("set overrideMessages to false. Use customMessages instead");
2251
- }
2252
- webshims.ready('DOM forms', function(){
2253
- $(document).on('firstinvalid', function(e){
2254
- if(!e.isInvalidUIPrevented()){
2255
- e.preventDefault();
2256
- $.webshims.validityAlert.showFor( e.target );
2257
- }
2258
- });
2259
- });
2260
- }
2261
- });
2262
-
2263
- })(jQuery);
2264
- jQuery.webshims.register('form-message', function($, webshims, window, document, undefined, options){
2265
- "use strict";
2266
- var validityMessages = webshims.validityMessages;
2267
-
2268
- var implementProperties = (options.overrideMessages || options.customMessages) ? ['customValidationMessage'] : [];
1881
+ var implementProperties = options.customMessages ? ['customValidationMessage'] : [];
2269
1882
 
2270
1883
  validityMessages.en = $.extend(true, {
2271
1884
  typeMismatch: {
@@ -2296,17 +1909,17 @@ jQuery.webshims.register('form-message', function($, webshims, window, document,
2296
1909
 
2297
1910
  if(typeof validityMessages['en'].valueMissing == 'object'){
2298
1911
  ['select', 'radio'].forEach(function(type){
2299
- validityMessages.en.valueMissing[type] = 'Please select an option.';
1912
+ validityMessages.en.valueMissing[type] = validityMessages.en.valueMissing[type] || 'Please select an option.';
2300
1913
  });
2301
1914
  }
2302
1915
  if(typeof validityMessages.en.rangeUnderflow == 'object'){
2303
1916
  ['date', 'time', 'datetime-local', 'month'].forEach(function(type){
2304
- validityMessages.en.rangeUnderflow[type] = 'Value must be at or after {%min}.';
1917
+ validityMessages.en.rangeUnderflow[type] = validityMessages.en.rangeUnderflow[type] || 'Value must be at or after {%min}.';
2305
1918
  });
2306
1919
  }
2307
1920
  if(typeof validityMessages.en.rangeOverflow == 'object'){
2308
1921
  ['date', 'time', 'datetime-local', 'month'].forEach(function(type){
2309
- validityMessages.en.rangeOverflow[type] = 'Value must be at or before {%max}.';
1922
+ validityMessages.en.rangeOverflow[type] = validityMessages.en.rangeOverflow[type] || 'Value must be at or before {%max}.';
2310
1923
  });
2311
1924
  }
2312
1925
 
@@ -2342,17 +1955,17 @@ jQuery.webshims.register('form-message', function($, webshims, window, document,
2342
1955
 
2343
1956
  if(typeof validityMessages.de.valueMissing == 'object'){
2344
1957
  ['select', 'radio'].forEach(function(type){
2345
- validityMessages.de.valueMissing[type] = 'Bitte wählen Sie eine Option aus.';
1958
+ validityMessages.de.valueMissing[type] = validityMessages.de.valueMissing[type] || 'Bitte wählen Sie eine Option aus.';
2346
1959
  });
2347
1960
  }
2348
1961
  if(typeof validityMessages.de.rangeUnderflow == 'object'){
2349
1962
  ['date', 'time', 'datetime-local', 'month'].forEach(function(type){
2350
- validityMessages.de.rangeUnderflow[type] = '{%value} ist zu früh. {%min} ist die früheste Zeit, die Sie benutzen können.';
1963
+ validityMessages.de.rangeUnderflow[type] = validityMessages.de.rangeUnderflow[type] || '{%value} ist zu früh. {%min} ist die früheste Zeit, die Sie benutzen können.';
2351
1964
  });
2352
1965
  }
2353
1966
  if(typeof validityMessages.de.rangeOverflow == 'object'){
2354
1967
  ['date', 'time', 'datetime-local', 'month'].forEach(function(type){
2355
- validityMessages.de.rangeOverflow[type] = '{%value} ist zu spät. {%max} ist die späteste Zeit, die Sie benutzen können.';
1968
+ validityMessages.de.rangeOverflow[type] = validityMessages.de.rangeOverflow[type] || '{%value} ist zu spät. {%max} ist die späteste Zeit, die Sie benutzen können.';
2356
1969
  });
2357
1970
  }
2358
1971
 
@@ -2370,12 +1983,12 @@ jQuery.webshims.register('form-message', function($, webshims, window, document,
2370
1983
  };
2371
1984
 
2372
1985
  webshims.createValidationMessage = function(elem, name){
2373
- var spinner;
1986
+ var widget;
2374
1987
  var message = getMessageFromObj(currentValidationMessage[name], elem);
2375
-
1988
+ var type = $.prop(elem, 'type');
2376
1989
  if(!message){
2377
- message = getMessageFromObj(validityMessages[''][name], elem) || 'invalid value';
2378
- webshims.info('could not find errormessage for: '+ name +' / '+ $.prop(elem, 'type') +'. in language: '+$.webshims.activeLang());
1990
+ message = getMessageFromObj(validityMessages[''][name], elem) || $.prop(elem, 'validationMessage');
1991
+ webshims.info('could not find errormessage for: '+ name +' / '+ type +'. in language: '+$.webshims.activeLang());
2379
1992
  }
2380
1993
  if(message){
2381
1994
  ['value', 'min', 'max', 'title', 'maxlength', 'label'].forEach(function(attr){
@@ -2385,11 +1998,11 @@ jQuery.webshims.register('form-message', function($, webshims, window, document,
2385
1998
  webshims.error('no title for patternMismatch provided. Always add a title attribute.');
2386
1999
  }
2387
2000
  if(valueVals[attr]){
2388
- if(!spinner){
2389
- spinner = $(elem).getShadowElement().data('wsspinner');
2001
+ if(!widget){
2002
+ widget = $(elem).getShadowElement().data('wsWidget'+type);
2390
2003
  }
2391
- if(spinner && spinner.formatValue){
2392
- val = spinner.formatValue(val, false);
2004
+ if(widget && widget.formatValue){
2005
+ val = widget.formatValue(val, false);
2393
2006
  }
2394
2007
  }
2395
2008
  message = message.replace('{%'+ attr +'}', val);
@@ -2404,7 +2017,7 @@ jQuery.webshims.register('form-message', function($, webshims, window, document,
2404
2017
  };
2405
2018
 
2406
2019
 
2407
- if(webshims.bugs.validationMessage || !Modernizr.formvalidation || webshims.bugs.bustedValidity){
2020
+ if(!Modernizr.formvalidation || webshims.bugs.bustedValidity){
2408
2021
  implementProperties.push('validationMessage');
2409
2022
  }
2410
2023
 
@@ -2462,9 +2075,37 @@ jQuery.webshims.register('form-message', function($, webshims, window, document,
2462
2075
 
2463
2076
  });
2464
2077
  });
2465
- jQuery.webshims.register('form-datalist', function($, webshims, window, document, undefined, options){
2078
+ webshims.register('form-datalist', function($, webshims, window, document, undefined, options){
2466
2079
  "use strict";
2467
- var doc = document;
2080
+ var doc = document;
2081
+ var lazyLoad = function(name){
2082
+ if(!name || typeof name != 'string'){
2083
+ name = 'DOM';
2084
+ }
2085
+ if(!lazyLoad[name+'Loaded']){
2086
+ lazyLoad[name+'Loaded'] = true;
2087
+ webshims.ready(name, function(){
2088
+ webshims.loader.loadList(['form-datalist-lazy']);
2089
+ });
2090
+ }
2091
+ };
2092
+ var noDatalistSupport = {
2093
+ submit: 1,
2094
+ button: 1,
2095
+ reset: 1,
2096
+ hidden: 1,
2097
+
2098
+ range: 1,
2099
+ date: 1,
2100
+ month: 1
2101
+ };
2102
+ if(webshims.modules["form-number-date-ui"].loaded){
2103
+ $.extend(noDatalistSupport, {
2104
+ number: 1,
2105
+ time: 1
2106
+ });
2107
+ }
2108
+
2468
2109
 
2469
2110
  /*
2470
2111
  * implement propType "element" currently only used for list-attribute (will be moved to dom-extend, if needed)
@@ -2500,28 +2141,6 @@ jQuery.webshims.register('form-datalist', function($, webshims, window, document
2500
2141
  var initializeDatalist = function(){
2501
2142
 
2502
2143
 
2503
- if(!listSupport){
2504
- webshims.defineNodeNameProperty('datalist', 'options', {
2505
- prop: {
2506
- writeable: false,
2507
- get: function(){
2508
- var elem = this;
2509
- var select = $('select', elem);
2510
- var options;
2511
- if(select[0]){
2512
- options = select[0].options;
2513
- } else {
2514
- options = $('option', elem).get();
2515
- if(options.length){
2516
- webshims.warn('you should wrap your option-elements for a datalist in a select element to support IE and other old browsers.');
2517
- }
2518
- }
2519
- return options;
2520
- }
2521
- }
2522
- });
2523
- }
2524
-
2525
2144
  var inputListProto = {
2526
2145
  //override autocomplete
2527
2146
  autocomplete: {
@@ -2581,27 +2200,8 @@ jQuery.webshims.register('form-datalist', function($, webshims, window, document
2581
2200
  };
2582
2201
  }
2583
2202
 
2584
- if(!listSupport){
2585
-
2586
- inputListProto['list'] = {
2587
- attr: {
2588
- get: function(){
2589
- var val = webshims.contentAttr(this, 'list');
2590
- return (val == null) ? undefined : val;
2591
- },
2592
- set: function(value){
2593
- var elem = this;
2594
- webshims.contentAttr(elem, 'list', value);
2595
- webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
2596
- $(elem).triggerHandler('listdatalistchange');
2597
- }
2598
- },
2599
- initAttr: true,
2600
- reflect: true,
2601
- propType: 'element',
2602
- propNodeName: 'datalist'
2603
- };
2604
- } else {
2203
+
2204
+ if(listSupport){
2605
2205
  //options only return options, if option-elements are rooted: but this makes this part of HTML5 less backwards compatible
2606
2206
  if(!($('<datalist><select><option></option></select></datalist>').prop('options') || []).length ){
2607
2207
  webshims.defineNodeNameProperty('datalist', 'options', {
@@ -2621,13 +2221,15 @@ jQuery.webshims.register('form-datalist', function($, webshims, window, document
2621
2221
  }
2622
2222
  });
2623
2223
  }
2624
- inputListProto['list'] = {
2224
+ inputListProto.list = {
2625
2225
  attr: {
2626
2226
  get: function(){
2627
2227
  var val = webshims.contentAttr(this, 'list');
2628
2228
  if(val != null){
2629
2229
  $.data(this, 'datalistListAttr', val);
2630
- this.removeAttribute('list');
2230
+ if(!noDatalistSupport[$.prop(this, 'type')] && !noDatalistSupport[$.attr(this, 'type')]){
2231
+ this.removeAttribute('list');
2232
+ }
2631
2233
  } else {
2632
2234
  val = $.data(this, 'datalistListAttr');
2633
2235
  }
@@ -2637,7 +2239,15 @@ jQuery.webshims.register('form-datalist', function($, webshims, window, document
2637
2239
  set: function(value){
2638
2240
  var elem = this;
2639
2241
  $.data(elem, 'datalistListAttr', value);
2640
- webshims.objectCreate(shadowListProto, undefined, {input: elem, id: value, datalist: $.prop(elem, 'list')});
2242
+ if (!noDatalistSupport[$.prop(this, 'type')] && !noDatalistSupport[$.attr(this, 'type')]) {
2243
+ webshims.objectCreate(shadowListProto, undefined, {
2244
+ input: elem,
2245
+ id: value,
2246
+ datalist: $.prop(elem, 'list')
2247
+ });
2248
+ } else {
2249
+ elem.setAttribute('list', value);
2250
+ }
2641
2251
  $(elem).triggerHandler('listdatalistchange');
2642
2252
  }
2643
2253
  },
@@ -2657,62 +2267,14 @@ jQuery.webshims.register('form-datalist', function($, webshims, window, document
2657
2267
  .each(function(){
2658
2268
  $(this).triggerHandler('updateDatalist');
2659
2269
  })
2660
-
2661
2270
  ;
2662
-
2663
2271
  });
2664
-
2665
-
2666
2272
  };
2667
2273
 
2668
2274
 
2669
2275
  /*
2670
2276
  * ShadowList
2671
2277
  */
2672
- var listidIndex = 0;
2673
- var noDatalistSupport = {
2674
- submit: 1,
2675
- button: 1,
2676
- reset: 1,
2677
- hidden: 1,
2678
-
2679
- range: 1,
2680
- date: 1,
2681
- month: 1
2682
- };
2683
- if(webshims.modules["form-number-date-ui"].loaded){
2684
- $.extend(noDatalistSupport, {
2685
- number: 1,
2686
- time: 1
2687
- });
2688
- }
2689
-
2690
- var globStoredOptions = {};
2691
- var getStoredOptions = function(name){
2692
- if(!name){return [];}
2693
- if(globStoredOptions[name]){
2694
- return globStoredOptions[name];
2695
- }
2696
- var data;
2697
- try {
2698
- data = JSON.parse(localStorage.getItem('storedDatalistOptions'+name));
2699
- } catch(e){}
2700
- globStoredOptions[name] = data || [];
2701
- return data || [];
2702
- };
2703
- var storeOptions = function(name, val){
2704
- if(!name){return;}
2705
- val = val || [];
2706
- try {
2707
- localStorage.setItem( 'storedDatalistOptions'+name, JSON.stringify(val) );
2708
- } catch(e){}
2709
- };
2710
-
2711
- var getText = function(elem){
2712
- return (elem.textContent || elem.innerText || $.text([ elem ]) || '');
2713
- };
2714
- var lReg = /</g;
2715
- var gReg = />/g;
2716
2278
 
2717
2279
  var shadowListProto = {
2718
2280
  _create: function(opts){
@@ -2720,6 +2282,7 @@ jQuery.webshims.register('form-datalist', function($, webshims, window, document
2720
2282
  if(noDatalistSupport[$.prop(opts.input, 'type')] || noDatalistSupport[$.attr(opts.input, 'type')]){return;}
2721
2283
  var datalist = opts.datalist;
2722
2284
  var data = $.data(opts.input, 'datalistWidget');
2285
+ var that = this;
2723
2286
  if(datalist && data && data.datalist !== datalist){
2724
2287
  data.datalist = datalist;
2725
2288
  data.id = opts.id;
@@ -2740,9 +2303,8 @@ jQuery.webshims.register('form-datalist', function($, webshims, window, document
2740
2303
  } else if(data && data.datalist === datalist){
2741
2304
  return;
2742
2305
  }
2743
- listidIndex++;
2744
- var that = this;
2745
- this.hideList = $.proxy(that, 'hideList');
2306
+
2307
+
2746
2308
 
2747
2309
  this.datalist = datalist;
2748
2310
  this.id = opts.id;
@@ -2750,121 +2312,21 @@ jQuery.webshims.register('form-datalist', function($, webshims, window, document
2750
2312
  this._autocomplete = $.attr(opts.input, 'autocomplete');
2751
2313
  $.data(opts.input, 'datalistWidget', this);
2752
2314
 
2753
- this.popover = webshims.objectCreate(webshims.wsPopover, {}, options.datalistPopover);
2754
- this.shadowList = this.popover.element.addClass('datalist-polyfill');
2315
+ lazyLoad('WINDOWLOAD');
2755
2316
 
2756
-
2757
- this.index = -1;
2758
- this.input = opts.input;
2759
- this.arrayOptions = [];
2760
-
2761
- this.shadowList
2762
- .delegate('li', 'mouseenter.datalistWidget mousedown.datalistWidget click.datalistWidget', function(e){
2763
- var items = $('li:not(.hidden-item)', that.shadowList);
2764
- var select = (e.type == 'mousedown' || e.type == 'click');
2765
- that.markItem(items.index(e.currentTarget), select, items);
2766
- if(e.type == 'click'){
2767
- that.hideList();
2768
- if(formsCFG.customDatalist){
2769
- $(opts.input).getNativeElement().trigger('datalistselect');
2770
- }
2771
- }
2772
- return (e.type != 'mousedown');
2773
- })
2774
- ;
2775
-
2776
- opts.input.setAttribute('autocomplete', 'off');
2777
-
2778
- $(opts.input)
2779
- .attr({
2780
- //role: 'combobox',
2781
- 'aria-haspopup': 'true'
2782
- })
2783
- .on({
2784
- 'input.datalistWidget': function(){
2785
- if(!that.triggeredByDatalist){
2786
- that.changedValue = false;
2787
- that.showHideOptions();
2788
- }
2789
- },
2790
- 'keydown.datalistWidget': function(e){
2791
- var keyCode = e.keyCode;
2792
- var activeItem;
2793
- var items;
2794
- if(keyCode == 40 && !that.showList()){
2795
- that.markItem(that.index + 1, true);
2796
- return false;
2797
- }
2798
-
2799
- if(!that.popover.isVisible){return;}
2800
-
2801
-
2802
- if(keyCode == 38){
2803
- that.markItem(that.index - 1, true);
2804
- return false;
2805
- }
2806
- if(!e.shiftKey && (keyCode == 33 || keyCode == 36)){
2807
- that.markItem(0, true);
2808
- return false;
2809
- }
2810
- if(!e.shiftKey && (keyCode == 34 || keyCode == 35)){
2811
- items = $('li:not(.hidden-item)', that.shadowList);
2812
- that.markItem(items.length - 1, true, items);
2813
- return false;
2814
- }
2815
- if(keyCode == 13 || keyCode == 27){
2816
- if (keyCode == 13){
2817
- activeItem = $('li.active-item:not(.hidden-item)', that.shadowList);
2818
- that.changeValue( $('li.active-item:not(.hidden-item)', that.shadowList) );
2819
- }
2820
- that.hideList();
2821
- if(formsCFG.customDatalist && activeItem && activeItem[0]){
2822
- $(opts.input).getNativeElement().trigger('datalistselect');
2823
- }
2824
- return false;
2825
- }
2826
- },
2827
- 'focus.datalistWidget': function(){
2828
- if($(this).hasClass('list-focus')){
2829
- that.showList();
2830
- }
2831
- },
2832
- 'mousedown.datalistWidget': function(){
2833
- if($(this).is(':focus')){
2834
- that.showList();
2835
- }
2836
- }
2837
- })
2838
- ;
2839
-
2840
-
2841
- $(this.datalist)
2842
- .off('updateDatalist.datalistWidget')
2843
- .on('updateDatalist.datalistWidget', $.proxy(this, '_resetListCached'))
2844
- ;
2845
-
2846
- this._resetListCached();
2847
-
2848
- if(opts.input.form && (opts.input.name || opts.input.id)){
2849
- $(opts.input.form).on('submit.datalistWidget'+opts.input.id, function(){
2850
- if(!$(opts.input).hasClass('no-datalist-cache') && that._autocomplete != 'off'){
2851
- var val = $.prop(opts.input, 'value');
2852
- var name = (opts.input.name || opts.input.id) + $.prop(opts.input, 'type');
2853
- if(!that.storedOptions){
2854
- that.storedOptions = getStoredOptions( name );
2855
- }
2856
- if(val && that.storedOptions.indexOf(val) == -1){
2857
- that.storedOptions.push(val);
2858
- storeOptions(name, that.storedOptions );
2859
- }
2317
+ if(webshims.isReady('form-datalist-lazy')){
2318
+ this._lazyCreate(opts);
2319
+ } else {
2320
+ $(opts.input).one('focus', lazyLoad);
2321
+ webshims.ready('form-datalist-lazy', function(){
2322
+ if(!that._destroyed){
2323
+ that._lazyCreate(opts);
2860
2324
  }
2861
2325
  });
2862
2326
  }
2863
- $(window).on('unload.datalist'+this.id+' beforeunload.datalist'+this.id, function(){
2864
- that.destroy();
2865
- });
2866
2327
  },
2867
- destroy: function(){
2328
+ destroy: function(e){
2329
+ var input;
2868
2330
  var autocomplete = $.attr(this.input, 'autocomplete');
2869
2331
  $(this.input)
2870
2332
  .off('.datalistWidget')
@@ -2882,268 +2344,21 @@ jQuery.webshims.register('form-datalist', function($, webshims, window, document
2882
2344
  } else {
2883
2345
  $(this.input).attr('autocomplete', autocomplete);
2884
2346
  }
2885
- },
2886
- _resetListCached: function(e){
2887
- var that = this;
2888
- var forceShow;
2889
- this.needsUpdate = true;
2890
- this.lastUpdatedValue = false;
2891
- this.lastUnfoundValue = '';
2892
-
2893
- if(!this.updateTimer){
2894
- if(window.QUnit || (forceShow = ($(that.input).is(':focus') && ($(that.input).hasClass('list-focus') || $.prop(that.input, 'value'))) )){
2895
- that.updateListOptions(forceShow);
2896
- } else {
2897
- webshims.ready('WINDOWLOAD', function(){
2898
- that.updateTimer = setTimeout(function(){
2899
- that.updateListOptions();
2900
- that = null;
2901
- listidIndex = 1;
2902
- }, 200 + (100 * listidIndex));
2903
- });
2904
- }
2905
- }
2906
- },
2907
- updateListOptions: function(_forceShow){
2908
- this.needsUpdate = false;
2909
- clearTimeout(this.updateTimer);
2910
- this.updateTimer = false;
2911
-
2912
- this.searchStart = formsCFG.customDatalist && $(this.input).hasClass('search-start');
2913
- this.addMarkElement = options.addMark || $(this.input).hasClass('mark-option-text');
2914
-
2915
- var list = [];
2916
-
2917
- var values = [];
2918
- var allOptions = [];
2919
- var rElem, rItem, rOptions, rI, rLen, item, value;
2920
- for(rOptions = $.prop(this.datalist, 'options'), rI = 0, rLen = rOptions.length; rI < rLen; rI++){
2921
- rElem = rOptions[rI];
2922
- if(!rElem.disabled && (value = $(rElem).val())){
2923
- rItem = {
2924
- value: value.replace(lReg, '&lt;').replace(gReg, '&gt;'),
2925
- label: $.trim($.attr(rElem, 'label') || getText(rElem)).replace(lReg, '&lt;').replace(gReg, '&gt;'),
2926
- className: rElem.className || ''
2927
- };
2928
-
2929
- if(rItem.label){
2930
- rItem.className += ' has-option-label';
2931
- }
2932
- values.push(rItem.value);
2933
- allOptions.push(rItem);
2934
- }
2935
- }
2936
-
2937
- if(!this.storedOptions){
2938
- this.storedOptions = ($(this.input).hasClass('no-datalist-cache') || this._autocomplete == 'off') ? [] : getStoredOptions((this.input.name || this.input.id) + $.prop(this.input, 'type'));
2939
- }
2940
-
2941
- this.storedOptions.forEach(function(val, i){
2942
- if(values.indexOf(val) == -1){
2943
- allOptions.push({value: val, label: '', className: 'stored-suggest', style: ''});
2944
- }
2945
- });
2946
-
2947
- for(rI = 0, rLen = allOptions.length; rI < rLen; rI++){
2948
- item = allOptions[rI];
2949
- list[rI] = '<li class="'+ item.className +'" tabindex="-1" role="listitem">'+ this.getOptionContent(item) +'</li>';
2950
- }
2951
-
2952
- this.arrayOptions = allOptions;
2953
- this.popover.contentElement.html('<div class="datalist-box"><ul role="list">'+ list.join("\n") +'</ul></div>');
2954
-
2955
-
2956
- if(_forceShow || this.popover.isVisible){
2957
- this.showHideOptions();
2958
- }
2959
- },
2960
- getOptionContent: function(item){
2961
- var content = '';
2962
- if(options.getOptionContent){
2963
- content = options.apply(this, arguments) || '';
2964
- } else {
2965
- content = '<span class="option-value">'+ item.value +'</span>';
2966
- if(item.label){
2967
- content += ' <span class="option-label">'+ item.label +'</span>';
2968
- }
2969
- }
2970
- return content;
2971
- },
2972
- showHideOptions: function(_fromShowList){
2973
- var value = $.prop(this.input, 'value').toLowerCase();
2974
-
2975
- //first check prevent infinite loop, second creates simple lazy optimization
2976
- if(value === this.lastUpdatedValue){
2977
- return;
2978
- }
2979
- if(this.lastUnfoundValue && value.indexOf(this.lastUnfoundValue) === 0){
2980
- this.hideList();
2981
- return;
2982
- }
2983
-
2984
-
2985
- this.lastUpdatedValue = value;
2986
- var found = false;
2987
- var startSearch = this.searchStart;
2988
- var lis = $('li', this.shadowList);
2989
- var that = this;
2990
- if(value){
2991
-
2992
- this.arrayOptions.forEach(function(item, i){
2993
- var search, searchIndex, foundName;
2994
- if(!('lowerValue' in item)){
2995
- item.lowerValue = item.value.toLowerCase();
2996
- if(item.label && item.label != item.value ){
2997
- item.lowerLabel = item.label.toLowerCase();
2998
- }
2999
- }
3000
-
3001
- if(value != item.lowerValue && item.lowerLabel != value){
3002
- searchIndex = item.lowerValue.indexOf(value);
3003
- search = startSearch ? !searchIndex : searchIndex !== -1;
3004
- if(search){
3005
- foundName = 'value';
3006
- } else if(item.lowerLabel){
3007
- searchIndex = item.lowerLabel.indexOf(value);
3008
- search = startSearch ? !searchIndex : searchIndex !== -1;
3009
- foundName = 'label';
3010
- }
3011
- }
3012
-
3013
- if(search){
3014
- that.addMark($(lis[i]).removeClass('hidden-item'), item, foundName, searchIndex, value.length);
3015
- found = true;
3016
- } else {
3017
- $(lis[i]).addClass('hidden-item');
3018
- }
3019
- });
3020
- } else if(lis.length) {
3021
- this.removeMark(lis.removeClass('hidden-item'));
3022
- found = true;
3023
- }
3024
-
3025
- this.hasViewableData = found;
3026
- if(!_fromShowList && found){
3027
- this.showList();
3028
- }
3029
-
3030
- if(!found){
3031
- this.lastUnfoundValue = value;
3032
- this.hideList();
3033
- } else {
3034
- this.lastUnfoundValue = false;
3035
- }
3036
- },
3037
- otherType: {
3038
- value: 'label',
3039
- label: 'value'
3040
- },
3041
- addMark: function(elem, item, prop, start, length){
3042
- if(this.addMarkElement){
3043
- var text = item[prop].substr(start, length);
3044
- text = item[prop].replace(text ,'<mark>'+ text +'</mark>');
3045
- $('.option-'+ this.otherType[prop] +' > mark', elem).each(this._replaceMark);
3046
- $('.option-'+prop, elem).html(text);
3047
-
3048
- }
3049
- },
3050
- _replaceMark: function(){
3051
- var content = $(this).html();
3052
- $(this).replaceWith(content);
3053
- },
3054
- removeMark: function(lis){
3055
- if(this.addMarkElement){
3056
- $('mark', lis).each(this._replaceMark);
3057
- }
3058
- },
3059
- showList: function(){
3060
- if(this.popover.isVisible){return false;}
3061
- if(this.needsUpdate){
3062
- this.updateListOptions();
3063
- }
3064
- this.showHideOptions(true);
3065
- if(!this.hasViewableData){return false;}
3066
- var that = this;
3067
-
3068
- that.shadowList.find('li.active-item').removeClass('active-item');
3069
- that.popover.show(this.input);
3070
-
3071
-
3072
- return true;
3073
- },
3074
- hideList: function(){
3075
- if(!this.popover.isVisible){return false;}
3076
- var that = this;
3077
-
3078
-
3079
- this.popover.hide();
3080
- that.shadowList.removeClass('datalist-visible list-item-active');
3081
- that.index = -1;
3082
- if(that.changedValue){
3083
- that.triggeredByDatalist = true;
3084
- $(that.input).trigger('input').trigger('change');
3085
- that.changedValue = false;
3086
- that.triggeredByDatalist = false;
3087
- }
3088
-
3089
- return true;
3090
- },
3091
- scrollIntoView: function(elem){
3092
- var ul = $('ul', this.shadowList);
3093
- var div = $('div.datalist-box', this.shadowList);
3094
- var elemPos = elem.position();
3095
- var containerHeight;
3096
- elemPos.top -= (parseInt(ul.css('paddingTop'), 10) || 0) + (parseInt(ul.css('marginTop'), 10) || 0) + (parseInt(ul.css('borderTopWidth'), 10) || 0);
3097
- if(elemPos.top < 0){
3098
- div.scrollTop( div.scrollTop() + elemPos.top - 2);
3099
- return;
3100
- }
3101
- elemPos.top += elem.outerHeight();
3102
- containerHeight = div.height();
3103
- if(elemPos.top > containerHeight){
3104
- div.scrollTop( div.scrollTop() + (elemPos.top - containerHeight) + 2);
3105
- }
3106
- },
3107
- changeValue: function(activeItem){
3108
- if(!activeItem[0]){return;}
3109
- var spinner;
3110
- var newValue = $('span.option-value', activeItem).text();
3111
- var oldValue = $.prop(this.input, 'value');
3112
- if(newValue != oldValue){
3113
-
3114
- $(this.input)
3115
- .prop('value', newValue)
3116
- .triggerHandler('updateInput')
3117
- ;
3118
- this.changedValue = true;
3119
- if((spinner = $.data(this.input, 'wsspinner')) && spinner.setInput){
3120
- spinner.setInput(newValue);
3121
- }
3122
- }
3123
- },
3124
- markItem: function(index, doValue, items){
3125
- var activeItem;
3126
- var goesUp;
3127
-
3128
- items = items || $('li:not(.hidden-item)', this.shadowList);
3129
- if(!items.length){return;}
3130
- if(index < 0){
3131
- index = items.length - 1;
3132
- } else if(index >= items.length){
3133
- index = 0;
3134
- }
3135
- items.removeClass('active-item');
3136
- this.shadowList.addClass('list-item-active');
3137
- activeItem = items.filter(':eq('+ index +')').addClass('active-item');
3138
-
3139
- if(doValue){
3140
- this.changeValue(activeItem);
3141
- this.scrollIntoView(activeItem);
2347
+ if(e && e.type == 'beforeunload'){
2348
+ input = this.input;
2349
+ setTimeout(function(){
2350
+ $.attr(input, 'list', $.attr(input, 'list'));
2351
+ }, 9);
3142
2352
  }
3143
- this.index = index;
2353
+ this._destroyed = true;
3144
2354
  }
3145
2355
  };
3146
2356
 
2357
+ webshims.loader.addModule('form-datalist-lazy', {
2358
+ noAutoCallback: true,
2359
+ options: $.extend(options, {shadowListProto: shadowListProto})
2360
+ });
2361
+
3147
2362
  //init datalist update
3148
2363
  initializeDatalist();
3149
2364
  })();
@@ -3154,7 +2369,7 @@ jQuery.webshims.register('form-datalist', function($, webshims, window, document
3154
2369
  var hasNative = Modernizr.audio && Modernizr.video;
3155
2370
  var supportsLoop = false;
3156
2371
  var bugs = webshims.bugs;
3157
-
2372
+ var swfType = 'mediaelement-jaris';
3158
2373
  var loadSwf = function(){
3159
2374
  webshims.ready(swfType, function(){
3160
2375
  if(!webshims.mediaelement.createSWF){
@@ -3164,7 +2379,7 @@ jQuery.webshims.register('form-datalist', function($, webshims, window, document
3164
2379
  });
3165
2380
  };
3166
2381
  var options = webshims.cfg.mediaelement;
3167
- var swfType = 'mediaelement-jaris';
2382
+ var hasFullTrackSupport;
3168
2383
  var hasSwf;
3169
2384
  if(!options){
3170
2385
  webshims.error("mediaelement wasn't implemented but loaded");
@@ -3177,14 +2392,11 @@ jQuery.webshims.register('form-datalist', function($, webshims, window, document
3177
2392
 
3178
2393
  webshims.capturingEvents(['play', 'playing', 'waiting', 'paused', 'ended', 'durationchange', 'loadedmetadata', 'canplay', 'volumechange']);
3179
2394
 
3180
- if(!Modernizr.videoBuffered){
2395
+ if(!Modernizr.videoBuffered ){
3181
2396
  webshims.addPolyfill('mediaelement-native-fix', {
3182
- f: 'mediaelement',
3183
- test: Modernizr.videoBuffered,
3184
2397
  d: ['dom-support']
3185
2398
  });
3186
-
3187
- webshims.reTest('mediaelement-native-fix');
2399
+ webshims.loader.loadList(['mediaelement-native-fix']);
3188
2400
  }
3189
2401
  }
3190
2402
 
@@ -3195,9 +2407,9 @@ jQuery.webshims.register('form-datalist', function($, webshims, window, document
3195
2407
  };
3196
2408
  var switchOptions = function(e){
3197
2409
  var media;
3198
- var parent = e.target.parentNode;
2410
+ var parent;
3199
2411
  if(!options.preferFlash &&
3200
- ($(e.target).is('audio, video') || (parent && $('source:last', parent)[0] == e.target)) &&
2412
+ ($(e.target).is('audio, video') || ((parent = e.target.parentNode) && $('source:last', parent)[0] == e.target)) &&
3201
2413
  (media = $(e.target).closest('audio, video')) && !noSwitch[media.prop('error')]
3202
2414
  ){
3203
2415
  $(function(){
@@ -3211,7 +2423,7 @@ jQuery.webshims.register('form-datalist', function($, webshims, window, document
3211
2423
  $('audio, video').each(function(){
3212
2424
  webshims.mediaelement.selectSource(this);
3213
2425
  });
3214
- webshims.info("switching mediaelements option to 'preferFlash', due to an error with native player: "+e.target.src+" Mediaerror: "+ media.prop('error'));
2426
+ webshims.error("switching mediaelements option to 'preferFlash', due to an error with native player: "+e.target.src+" Mediaerror: "+ media.prop('error'));
3215
2427
  }
3216
2428
  }, 9);
3217
2429
  });
@@ -3246,43 +2458,9 @@ jQuery.webshims.register('form-datalist', function($, webshims, window, document
3246
2458
  bugs.track = true;
3247
2459
  }
3248
2460
  }
3249
-
3250
- var trackOptions = webshims.cfg.track;
3251
- var trackListener = function(e){
3252
- $(e.target).filter('track').each(changeApi);
3253
- };
3254
- var changeApi = function(){
3255
- if(bugs.track || (!trackOptions.override && $.prop(this, 'readyState') == 3)){
3256
- trackOptions.override = true;
3257
- webshims.reTest('track');
3258
- document.removeEventListener('error', trackListener, true);
3259
- if(this && $.nodeName(this, 'track')){
3260
- webshims.error("track support was overwritten. Please check your vtt including your vtt mime-type");
3261
- } else {
3262
- webshims.info("track support was overwritten. due to bad browser support");
3263
- }
3264
- return false;
3265
- }
3266
- };
3267
- var detectTrackError = function(){
3268
- document.addEventListener('error', trackListener, true);
3269
-
3270
- if(bugs.track){
3271
- changeApi();
3272
- } else {
3273
- $('track').each(changeApi);
3274
- }
3275
- };
3276
- if(!trackOptions.override){
3277
- if(webshims.isReady('track')){
3278
- detectTrackError();
3279
- } else {
3280
- $(detectTrackError);
3281
- }
3282
- }
3283
2461
  })();
3284
-
3285
2462
  }
2463
+ hasFullTrackSupport = Modernizr.track && !bugs.track;
3286
2464
 
3287
2465
  webshims.register('mediaelement-core', function($, webshims, window, document, undefined){
3288
2466
  hasSwf = swfmini.hasFlashPlayerVersion('9.0.115');
@@ -3367,7 +2545,8 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3367
2545
  var loadTrackUi = function(){
3368
2546
  if(loadTrackUi.loaded){return;}
3369
2547
  loadTrackUi.loaded = true;
3370
- $(function(){
2548
+ webshims.ready('WINDOWLOAD', function(){
2549
+ loadThird();
3371
2550
  webshims.loader.loadList(['track-ui']);
3372
2551
  });
3373
2552
  };
@@ -3540,27 +2719,40 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3540
2719
  }
3541
2720
  return ret;
3542
2721
  };
3543
-
2722
+ var emptyType = (/^\s*application\/octet\-stream\s*$/i);
2723
+ var getRemoveEmptyType = function(){
2724
+ var ret = emptyType.test($.attr(this, 'type') || '');
2725
+ if(ret){
2726
+ $(this).removeAttr('type');
2727
+ }
2728
+ return ret;
2729
+ };
3544
2730
  mediaelement.setError = function(elem, message){
3545
- if(!message){
3546
- message = "can't play sources";
2731
+ if($('source', elem).filter(getRemoveEmptyType).length){
2732
+ webshims.error('"application/octet-stream" is a useless mimetype for audio/video. Please change this attribute.');
2733
+ try {
2734
+ $(elem).mediaLoad();
2735
+ } catch(er){}
2736
+ } else {
2737
+ if(!message){
2738
+ message = "can't play sources";
2739
+ }
2740
+ $(elem).pause().data('mediaerror', message);
2741
+ webshims.error('mediaelementError: '+ message);
2742
+ setTimeout(function(){
2743
+ if($(elem).data('mediaerror')){
2744
+ $(elem).trigger('mediaerror');
2745
+ }
2746
+ }, 1);
3547
2747
  }
3548
2748
 
3549
- $(elem).pause().data('mediaerror', message);
3550
- webshims.error('mediaelementError: '+ message);
3551
- setTimeout(function(){
3552
- if($(elem).data('mediaerror')){
3553
- $(elem).trigger('mediaerror');
3554
- }
3555
- }, 1);
2749
+
3556
2750
  };
3557
2751
 
3558
2752
  var handleThird = (function(){
3559
2753
  var requested;
3560
2754
  return function( mediaElem, ret, data ){
3561
- if(!requested){
3562
- loadTrackUi();
3563
- }
2755
+
3564
2756
  webshims.ready(hasSwf ? swfType : 'mediaelement-yt', function(){
3565
2757
  if(mediaelement.createSWF){
3566
2758
  mediaelement.createSWF( mediaElem, ret, data );
@@ -3705,6 +2897,7 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3705
2897
  var buffered = getBufferedString();
3706
2898
  if(buffered != lastBuffered){
3707
2899
  lastBuffered = buffered;
2900
+ webshims.info('needed to trigger progress manually');
3708
2901
  $(elem).triggerHandler('progress');
3709
2902
  }
3710
2903
  };
@@ -3756,11 +2949,14 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3756
2949
  $('video, audio', context)
3757
2950
  .add(insertedElement.filter('video, audio'))
3758
2951
  .each(function(){
3759
- if(!mediaelement.canNativePlaySrces(this) || (!loadTrackUi.loaded && $('track', this).length)){
2952
+ if(!mediaelement.canNativePlaySrces(this)){
3760
2953
  loadThird();
3761
2954
  handleMedia = true;
3762
2955
  return false;
3763
2956
  }
2957
+ if((!hasFullTrackSupport || webshims.modules.track.options.override) && !loadTrackUi.loaded && $('track', this).length){
2958
+ loadTrackUi();
2959
+ }
3764
2960
  })
3765
2961
  ;
3766
2962
  }
@@ -3768,7 +2964,7 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3768
2964
  }
3769
2965
  };
3770
2966
 
3771
- if(Modernizr.track && !bugs.track){
2967
+ if(hasFullTrackSupport){
3772
2968
  webshims.defineProperty(TextTrack.prototype, 'shimActiveCues', {
3773
2969
  get: function(){
3774
2970
  return this._shimActiveCues || this.activeCues;
@@ -3783,6 +2979,6 @@ webshims.register('mediaelement-core', function($, webshims, window, document, u
3783
2979
  } else {
3784
2980
  webshims.ready(swfType, initMediaElements);
3785
2981
  }
3786
- webshims.ready('WINDOWLOAD mediaelement', loadTrackUi);
2982
+ webshims.ready('track', loadTrackUi);
3787
2983
  });
3788
- })(jQuery, Modernizr, jQuery.webshims);
2984
+ })(jQuery, Modernizr, webshims);