10 lines
10 KiB
JavaScript
10 lines
10 KiB
JavaScript
|
/**
|
|||
|
* bootstrap-suggest-plugin - v0.1.29
|
|||
|
* @description 这是一个基于 bootstrap 按钮式下拉菜单组件的搜索建议插件,必须使用于按钮式下拉菜单组件上。
|
|||
|
* @author lzwme - https://lzw.me
|
|||
|
* @GitHub https://github.com/lzwme/bootstrap-suggest-plugin.git
|
|||
|
* @since 2019-11-18 09:30:06
|
|||
|
*/
|
|||
|
|
|||
|
!function(e){if("function"==typeof define&&define.amd)define(["jquery"],e);else if("object"==typeof exports&&"object"==typeof module)e(require("jquery"));else{if(!window.jQuery)throw new Error("Not found jQuery.");e(window.jQuery)}}(function(g){var c,s=g(window),l="ActiveXObject"in window,e=navigator.userAgent.match(/Chrome\/(\d+)/);e&&(e=+e[1]);var y=l||51<e,p="bsSuggest",h="onDataRequestSuccess",v="disabled",b=!0,m=!1;function w(e){return void 0===e}function x(e){return e.data()}function k(e,t){return w(t)?e.attr("alt"):e.attr("alt",t)}function S(e,t){return void 0!==t?e.attr("data-id",t):e.attr("data-id")}function C(e,t,n){if(t&&t.key){var i,o,a=n.separator||",",r=S(e);n&&n.multiWord?((i=e.val().split(a))[i.length-1]=t.key,r?(o=r.split(a)).push(t.id):o=[t.id],S(e,o.join(a)).val(i.join(a)).focus()):S(e,t.id||"").val(t.key).focus(),e.data("pre-val",e.val()).trigger("onSetSelectValue",[t,(n.data.value||n._lastData.value)[t.index]])}}function j(i,o,e){if(o.is(":visible")){var a=i.parent(),t=a.height(),n=a.width();e.autoDropup&&setTimeout(function(){var e=i.offset().top,t=s.scrollTop(),n=o.height();s.height()+t-e<n&&n+t<e?a.addClass("dropup"):a.removeClass("dropup")},10);var r={};return"left"===e.listAlign?r={left:i.siblings("div").width()-n,right:"auto"}:"right"===e.listAlign&&(r={left:"auto",right:0}),l&&!e.showBtn&&(a.hasClass("dropup")?(r.top="auto",r.bottom=t):(r.top=t,r.bottom="auto")),e.autoMinWidth||(r.minWidth=n),o.css(r),i}}function D(e,t){var n,i,o;if(-1===t.indexId&&!t.idField||t.multiWord)return e;i=t.inputBgColor,o=t.inputWarnColor;var a=e.val(),r=e.data("pre-val");return S(e)||!a?(e.css("background",i||""),!a&&r&&e.trigger("onUnsetSelectValue").data("pre-val","")):(n=e.css("backgroundColor").replace(/ /g,"").split(",",3).join(","),~o.indexOf(n)||e.trigger("onUnsetSelectValue").data("pre-val","").css("background",o)),e}function A(e,t,n){var i,o,a=e.parent().find("tbody tr."+n.listHoverCSS);a.length&&(i=(a.index()+3)*a.height(),(o=+t.css("maxHeight").replace("px",""))<i||t.scrollTop()>o?i-=o:i=0,t.scrollTop(i))}function F(e,t){e.find("tr."+t.listHoverCSS).removeClass(t.listHoverCSS)}function f(e){var t,n=b;for(t in e)if("value"===t){n=m;break}return n?(window.console&&window.console.trace,m):e.value.length?e:m}function T(e,t){var n=t.effectiveFields;return!("__index"===e||n.length&&!~g.inArray(e,n))}function H(e,t,n,i){n.html('<div style="padding:10px 5px 5px">'+e+"</div>").show(),j(t,n,i)}function q(e,t){var n=e.parent().find("ul:eq(0)");n.is(":visible")||(n.show(),e.trigger("onShowDropdown",[t?t.data.value:[]]))}function W(e,t){var n=e.parent().find("ul:eq(0)");n.is(":visible")&&(n.hide(),e.trigger("onHideDropdown",[t?t.data.value:[]]))}function B(e,t,n){var i,o,a,r,s,l,u=e.parent().find("ul:eq(0)"),d=0,f=['<table class="table table-condensed table-sm" style="margin:0">'],c=t.value;if(!t||!(i=c.length))return n.emptyTip?H(n.emptyTip,e,u,n):(u.empty(),W(e,n)),e;if(n._lastData&&JSON.stringify(n._lastData)===JSON.stringify(t)&&u.find("tr").length===i)return q(e,n),j(e,u,n);n._lastData=t;var p,h=n.effectiveFields.length?n.effectiveFields:g.map(c[0],function(e,t){return t});n.showHeader&&(f.push("<thead><tr>"),g.each(h,function(e,t){T(t,n)&&(f.push("<th>",n.effectiveFieldsAlias[t]||t,0===e?"("+i+")":"","</th>"),e++)}),f.push("</tr></thead>")),f.push("<tbody>");var v=Math.min(n.maxOptionCount,i);for(o=0;o<v;o++){for(a in d=0,r=[],s=(p=c[o])[n.idField],l=p[n.keyField],p)w(l)&&n.indexKey===d&&(l=p[a]),w(s)&&n.indexId===d&&(s=p[a]),d++;g.each(h,function(e,t){T(t,n)&&r.push('<td data-name="',t,'">',p[t],"</td>")}),f.push('<tr data-index="',p.__index||o,'" data-id="',s,'" data-key="',l,'">',r.join(""),"</tr>")}return f.push("</tbody></table>"),u.html(f.join("")),q(e,n),setTimeout(function(){if(!y){var e=u.find("table:eq(0)"),t=0,n=0;u.height()<e.height()&&+u.css("minWidth").replace("px","")<u.width()&&(t=18,n=20),u.css("paddingRight",t),e.css("marginBottom",n)}},301),j(e,u,n),e}function _(t,n){n=n||"";var e=t._preAjax;e&&e.abort&&4!==e.readyState&&e.abort();var i={type:"GET",dataType:t.jsonp?"jsonp":"json",timeout:5e3
|