-
Notifications
You must be signed in to change notification settings - Fork 3
/
jquery-areaselect.min.js
15 lines (15 loc) · 3.2 KB
/
jquery-areaselect.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*!
* bootstrap-treetable - jQuery plugin for area like tree select and addressselect
*
* Copyright (c) 2016 songhlc
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* Project home:
* https://github.com/songhlc/jquery.areaselect
*
* Version: 1.0.0
*
*/
(function(a){a.fn.areaselect=function(k){var g=this;var e={inputCls:"form-control",inputIconCls:"fa fa-angle-down",initData:[],linktext:"请选择",loadData:function(l,m){},onok:function(l){alert(JSON.stringify(l))},defaultFullname:""};var d={ids:[],names:[],fullname:""};if(k){a.extend(e,k)}function i(n,m){for(var l=d.ids.length-1;l>=n;l--){d.ids.pop();d.names.pop()}d.ids.push(m.id);d.names.push(m.name);d.fullname="";for(var l=0;l<d.names.length;l++){d.fullname+=d.names[l]}}function h(l){return'<a href="javascript:void(0)" data-id="'+l.id+'" class="as-tabs-item as-tabs-item-current">请选择</a>'}function b(n){var m="";for(var l=0;l<n.length;l++){m+='<li><a href="javascript:void(0)" data-id="'+n[l].id+'">'+n[l].name+"</a></li>"}return"<ul>"+m+"</ul>"}function f(){g.undelegate().delegate(".as-content a","click",function(){var n={id:a(this).attr("data-id"),name:a(this).html()};var m=a(this).parents("ul").index();e.loadData(n,function(o){if(o&&((o.data&&o.data.length>0)||o.length>0)){if(o.keyid){o=c(o.keyid,o.keyname,o.data)}g.find(".as-content ul").each(function(p){if(p>m){a(this).addClass("j-remove")}});g.find(".as-tabs a").each(function(p){if(p>m){a(this).addClass("j-remove")}});g.find(".j-remove").remove();g.find(".as-tabs-item").removeClass("as-tabs-item-current");g.find(".as-content>ul").addClass("as-hidden");g.find(".as-tabs a").eq(m).html(a(this).html());g.find(".as-tabs").append(h(n));g.find(".as-content").append(b(o));i(m,n)}else{i(m,n);e.onok(d);g.find("input").val(d.fullname);a(g).removeClass("as-hover")}}.bind(this),m)});g.delegate(".as-tabs a","click",function(){var m=a(this).index();g.find(".as-tabs-item").removeClass("as-tabs-item-current").eq(m).addClass("as-tabs-item-current");g.find(".as-content ul").addClass("as-hidden").eq(m).removeClass("as-hidden")});var l;g.delegate(".as-linkle","mouseenter",function(){if(l){clearTimeout(l)}a(g).addClass("as-hover")});g.delegate(".as-linkle","mouseleave",function(){l=setTimeout(function(){a(g).removeClass("as-hover")},300)});g.delegate(".as-ctn","mouseenter",function(){if(l){clearTimeout(l)}a(g).addClass("as-hover")});g.delegate(".as-ctn","mouseleave",function(){l=setTimeout(function(){a(g).removeClass("as-hover")},300)})}function c(q,p,o){var n=[];for(var l=0;l<o.length;l++){var m={};m.id=o[l][q];m.name=o[l][p];n.push(m)}return n}function j(){if(e.initData){if(e.initData.keyid){e.initData=c(e.initData.keyid,e.initData.keyname,e.initData.data)}var m=e.type=="link"?'<a class="as-linkle">'+e.linktext+"</a>":'<input placeholder="'+e.linktext+'" class="as-linkle '+e.inputCls+'" type="text">';var l=m+'<div class="as-ctn">'+'<div class="as-tabs">'+'<a href="javascript:void(0)" class="as-tabs-item as-tabs-item-current">请选择</a>'+"</div>"+'<div class="clearfix"></div>'+'<div class="as-content">'+b(e.initData)+"</div>"+"</div>";g.html("").append(l);if(e.defaultFullname){g.find("input").val(e.defaultFullname)}}else{console.log("error initData")}}f();j()}})(jQuery);