You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
simple-yewu/frontend/web/assets/js/plugins/suggest/bootstrap-suggest.min.js

9 lines
8.6 KiB

5 years ago
/*
Bootstrap_Search_Suggest - v0.0.2
Description: 这是一个基于 bootstrap 按钮式下拉菜单组件的搜索建议插件必须使用于按钮式下拉菜单组件上
Author: lizhiwen#meizu.com
Github: https://github.com/lzwme/bootstrap-suggest-plugin
Update: 2015-11-18 12:24:39
*/
!function(a){a.fn.bsSuggest=function(a){return"string"==typeof a&&b[a]?b[a].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof a&&a?void 0:b.init.apply(this,arguments)};var b={init:function(b){function c(b,c,d){return c.is(":visible")?void setTimeout(function(){d.autoDropup&&a(window).height()-b.offset().top<c.height()&&b.offset().top>c.height()+a(window).scrollTop()?c.parents(".input-group").addClass("dropup"):c.parents(".input-group.dropup").removeClass("dropup")},100):("left"===d.listAlign?c.css({left:b.siblings("div").width()-b.parent().width(),right:"auto"}):"right"===d.listAlign&&c.css({left:"auto",right:"0"}),d.autoMinWidth===!1?c.css({"min-width":b.parent().width()}):c.css("width","auto"),b)}function d(a,b){var c,d,e;return-1===b.indexId&&!b.idField||b.multiWord?a:(c=a.css("background-color").replace(/ /g,"").split(",",3).join(","),d=b.inputBgColor||"rgba(255,255,255,0.1)",e=b.inputWarnColor||"rgba(255,255,0,0.1)",!a.val()||a.attr("data-id")?a.css("background",d):(-1===e.indexOf(c)&&(a.trigger("onUnsetSelectValue"),a.css("background",e)),a))}function e(a,b){var c,d,e=a.parent().find("tbody tr."+s.listHoverCSS);e.length>0&&(c=(e.index()+3)*e.height(),d=Number(b.css("max-height").replace("px","")),b.scrollTop(c>d||b.scrollTop()>d?c-d:0))}function f(a,b){a=a||$dropdownMenu,b=b||s,a.find("tr."+b.listHoverCSS).removeClass(b.listHoverCSS)}function g(b){var c=a(b),d=c.parent(".input-group").find("ul.dropdown-menu"),e=c.data("bsSuggest");return 0===d.length?!1:e?!1:(c.data("bsSuggest",{target:b,options:s}),!0)}function h(b,c,d,e){var f,g,h,i,m,n,o,p={value:[]};if(b=b||"",e=e||s,e.url)m=-1!==e.url.indexOf("?")?"&":"?",n=e.jsonp?[e.url+b,m,e.jsonp,"=?"].join(""):e.url+b,a.ajax({type:"GET",url:n,dataType:"json",timeout:3e3}).done(function(a){d(c,a,e),c.trigger("onDataRequestSuccess",a),"firstByUrl"===s.getDataMethod&&(s.data=a,s.url=null)}).fail(q);else{if(f=e.data,g=j(f))if(b){for(o=f.value.length,h=0;o>h;h++)for(i in f.value[h])if(a.trim(f.value[h][i])&&(l(i,e)||k(i,e))&&(-1!==f.value[h][i].toString().indexOf(b)||-1!==b.indexOf(f.value[h][i]))){p.value.push(f.value[h]);break}}else p=f;d(c,p,e)}}function i(a){return validData=j(a)}function j(a){var b=!0;for(var c in a)if("value"===c){b=!1;break}return b?(q("返回数据格式错误!"),!1):0===a.value.length?!1:a}function k(b,c){return c=c||s,a.isArray(c.effectiveFields)&&c.effectiveFields.length>0&&-1===a.inArray(b,c.effectiveFields)?!1:!0}function l(b,c){return-1!==a.inArray(b,c.searchFields)?!0:!1}function m(a,b,d){var e,f,g,h,j,l,m,o=a.parent().find("ul.dropdown-menu"),p=0,q=['<table class="table table-condensed">'];if(d=d||s,b=i(b),b===!1||0===(e=b.value.length))return o.empty().hide(),a;if(d.showHeader){h="<thead><tr>";for(g in b.value[0])k(g)!==!1&&(h+=0===p?"<th>"+(d.effectiveFieldsAlias[g]||g)+"("+e+")</th>":"<th>"+(d.effectiveFieldsAlias[g]||g)+"</th>",p++);h+="</tr></thead>",q.push(h)}for(q.push("<tbody>"),f=0;e>f;f++){p=0,j="",l=b.value[f][d.idField]||"",m=b.value[f][d.keyField]||"";for(g in b.value[f])m||d.indexKey!==p||(m=b.value[f][g]),l||d.indexId!==p||(l=b.value[f][g]),p++,k(g)!==!1&&(j+='<td data-name="'+g+'">'+b.value[f][g]+"</td>");j='<tr data-index="'+f+'" data-id="'+l+'" data-key="'+m+'">'+j+"</tr>",q.push(j)}return q.push("</tbody></table>"),o.html(q.join("")).show(),n(a,o,d),o.css("max-height")&&Number(o.css("max-height").replace("px",""))<Number(o.find("table:eq(0)").css("height").replace("px",""))&&Number(o.css("min-width").replace("px",""))<Number(o.css("width").replace("px",""))?o.css("padding-right","20px").find("table:eq(0)").css("margin-bottom","20px"):o.css("padding-right",0).find("table:eq(0)").css("margin-bottom",0),c(a,o,d),a}function n(b,c,e){c=c||$dropdownMenu,e=e||s,c.find("tbody tr").each(function(){a(this).off("mouseenter").on("mouseenter",function(){f(c,e),a(this).addClass(e.listHoverCSS)}).off("mousedown").on("mousedown",function(){p(b,o(a(this)),e),d(b,e)})})}function o(a){var b={};return b.id=a.attr("data-id"),b.key=a.attr("data-key"),b}function p(a,b,c){var d,e=b||{},f=e.id||"",g=e.key||"";c&&c.multiWord?(d=a.v