PageSourceSearch

https://www.gxpipetech.com/assets/js/kaka/libs/kaka.dmenu.js

js gxpipetech.com collected 2026-10-04 04:59:51 UTC 3,150 bytes, 140 lines download raw bytes

1
2
3kakaDmenu = function(DOM, opts){
4	var self = this;
5
6	self.defaults = {
7		htmlTpl: '<select></select>', //控件模板
8		selected: 0, //选中项ID
9		disableId: 0, //禁止ID加载
10		defaultText: false, //默认文本
11		firstText: false, //首个加载控件文本
12		script: '', //请求脚本地址
13		mapping: new Array(), //控件映射 [['province', '请选择省份...'], ['city', '请选择城市...']]
14		callback: function(el, data) {}, //回调方法
15		rootId: 0, //载入的根ID
16		limit: 0
17	};
18
19	var opts = $.extend(true, self.defaults, opts);
20	var data = new Object();
21	var path = new Array();
22
23	self.init = function(){
24		//载入数据
25		$.getJSON(opts.script, function(result) { 
26			data = result; 
27			el = self.loadNote(opts.rootId, $(this));
28			if (opts.selected) {
29				//name转换成ID
30				if (!parseInt(opts.selected)) {
31					var sId = 0;
32					$.each(data, function(key, val) {
33						if (opts.selected.indexOf(val.name) >= 0) {
34							path = new Array();
35							self.parsePath(val.id);
36							path = path.reverse();
37							
38							var str = '';
39							for(idx in path) {
40								str += path[idx].name;
41							}
42							if (opts.selected == str) {
43								sId = val.id;
44							}
45						}
46					});
47					opts.selected = sId;
48				}
49
50				path = new Array();
51				self.parsePath(opts.selected);
52				path = path.reverse();
53
54				for(idx in path) {
55					var id = path[idx].id;
56					if (id != opts.rootId) {
57						$('[value='+id+']', el).attr('selected', true);
58						if (opts.limit != 0 && idx > opts.limit) return false;
59
60						el = self.loadNote(id, el);
61					}
62				}
63			}
64		});
65	}
66
67	self.parsePath = function(id) {
68		if (opts.rootId != id) {
69			$.each(data, function(key, val) {
70				if (id == val.id) {
71					path.push(val);
72					self.parsePath(val.parent_id);
73				}
74			});
75		}
76	}
77	
78	self.loadNote = function(id, obj) {
79		var extend = data[id];
80		var level = parseInt(extend ? extend.level : 1);
81
82		$(obj).nextAll().remove();
83
84		opts.callback(obj, extend ? extend : false);
85		if (opts.limit != 0 && level >= opts.limit+1) return false;
86		var mp = opts.mapping[level-1];
87		var el = $(opts.htmlTpl)
88			.data('level', level)
89			.change(function() {
90				if (!$(this).val()) return false;
91				self.loadNote($(this).val(), $(this));
92			});
93
94		el.appendTo(DOM);
95
96		if (opts.firstText && id == opts.rootId) {
97			el.empty();
98			$(el).append('<option value="-1">'+opts.firstText+'</option>');
99		} else if (opts.defaultText) {
100			el.empty();
101			var defText = opts.defaultText;
102			if (typeof(defText) == 'object') {
103				var defText = defText[level-1];
104			}
105
106			$(el).append('<option value="-1">'+defText+'</option>');					
107		}
108
109		if (mp) {
110			if (typeof(mp) == 'object') {
111				el.attr('name', mp[0]);
112				if (mp[1]) {
113					el.empty();
114					el.append('<option value="-1">'+mp[1]+'</option>');
115				}
116			} else {
117				el.attr('name', mp);
118			}
119		}
120
121		var find = false;
122		$.each(data, function(key, val) {
123			if (opts.disableId != val.id) {
124				if (val.parent_id == id) {
125					$(el).append('<option value="'+val.id+'">'+val.name+'</option>');
126					find = true;
127				}
128			}
129		});
130
131		if (!find) $(el).remove();
132		
133		return el;
134	}
135
136	self.init();
137
138
139	return self;
140}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.