Blame view
static/plugins/webshim-gh-pages/js-webshim/dev/shims/form-combat.js
4.99 KB
831eac332 add file |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
// webshims.register('form-combat', function($,webshims){ "use strict"; var replacementDatas = { }; var addReplacement = function(pName, dataName, obj){ if($.fn[pName]){ if(typeof dataName == 'object'){ obj = dataName; dataName = pName; } replacementDatas[dataName] = obj; webshims.info('detected use of '+ pName +' try to add support.'); } }; if($.fn.select2){ addReplacement('select2', { shadow: $.fn.select2.amd ? '$container' : 'container', shadowFocus: $.fn.select2.amd ? '$selection' : 'focusser', _create: function(elem, shadow, shadowFocus, widgetData){ var onValidate; if(('$dropdown' in widgetData)){ onValidate = function(e){ if (!webshims.wsPopover.isInElement([elem, shadow, shadowFocus, $(widgetData.$dropdown)], e.target)) { $(elem).trigger('updatevalidation.webshims'); } }; $(shadow).on('wsallowinstantvalidation', function(e, data){ $(document).off('focusin', onValidate); if(data.type == 'focusout' && data.target != elem){ $(document).on('focusin', onValidate); return false; } }); } else if(('container' in widgetData) && $.isFunction(widgetData.opened)){ onValidate = function(e){ if (!webshims.wsPopover.isInElement([elem, shadow, shadowFocus, $(widgetData.container)], e.target)) { $(elem).trigger('updatevalidation.webshims'); } }; $(shadow).on('wsallowinstantvalidation', function(e, data){ $(document).off('focusin', onValidate); if(data.type == 'focusout' && data.target != elem && widgetData.opened()){ $(document).on('focusin', onValidate); return false; } }); } } }); } addReplacement('chosen', { shadow: 'container', shadowFocus: 'search_field' }); addReplacement('selectpicker', { shadow: '$newElement', shadowFocus: '$button', _create: function(elem, shadow, shadowFocus, widgetData){ if(('$menu' in widgetData)){ var onValidate = function(e){ if (!webshims.wsPopover.isInElement([elem, shadow, shadowFocus, $(widgetData.$menu)], e.target)) { $(elem).trigger('updatevalidation.webshims'); } }; $(shadow).on('wsallowinstantvalidation', function(e, data){ $(document).off('focusin', onValidate); if(data.type == 'focusout' && data.target != elem){ $(document).on('focusin', onValidate); return false; } }); } } }); addReplacement('selectBoxIt', { shadow: 'dropdownContainer', shadowFocus: 'dropdown' }); addReplacement('checkboxradio', 'mobileCheckboxradio', { shadow: 'label', shadowFocus: 'element' }); var uiSelect = { shadow: 'button', shadowFocus: function(data){ return data.options.nativeMenu ? data.element : data.button; }, _create: function(elem, shadow, shadowFocus, widgetData){ var menuName; if(('menu' in widgetData)){ menuName = 'menuName'; } else if(('listbox' in widgetData)){ menuName = 'listbox'; } if(menuName){ var onValidate = function(e){ if (!webshims.wsPopover.isInElement([elem, shadow, shadowFocus, $(widgetData[menuName]).parent()], e.target)) { $(elem).trigger('updatevalidation.webshims'); } }; $(shadow).on('wsallowinstantvalidation', function(e, data){ if(data.type == 'focusout' && data.target != elem && widgetData.isOpen){ setTimeout(function(){ $(document).off('focusin', onValidate).on('focusin', onValidate); }, 1); return false; } }); } } }; addReplacement('selectmenu', 'mobileSelectmenu', uiSelect); addReplacement('selectmenu', 'uiSelectmenu', uiSelect); function find(context){ $('select:not(.ui-select-nativeonly), input[type="radio"], input[type="checkbox"]', context).each(find.detectReplacement); } find.register = function(elem, data, pluginDescriptor, plugin){ var shadow = typeof pluginDescriptor.shadow == 'string' ? data[pluginDescriptor.shadow] : pluginDescriptor.shadow(data, elem); var shadowFocus = typeof pluginDescriptor.shadowFocus == 'string' ? data[pluginDescriptor.shadowFocus] : pluginDescriptor.shadowFocus(data, elem); if(!shadowFocus){ shadowFocus = shadow; } if(shadow && (replacementDatas.success || ($(shadowFocus).attr('tabindex') || $(shadowFocus).prop('tabIndex') > -1))){ webshims.addShadowDom(elem, shadow, {shadowFocusElement: shadowFocus}); if(pluginDescriptor._create){ pluginDescriptor._create(elem, shadow, shadowFocus, data); } replacementDatas.success = true; } else { webshims.error("webshim could not add support for "+plugin); if(plugin in replacementDatas){ delete replacementDatas[plugin]; } } }; find.detectReplacement = function(){ var plugin; var data = $(this).data(); if(data && !(webshims.data(this) || {}).hasShadow){ for(plugin in replacementDatas){ if(data[plugin]){ find.register(this, data[plugin], replacementDatas[plugin], plugin); break; } } } }; webshims.addReady(function(context){ setTimeout(function(){ find(context); }, 4); }); }); |