PageSourceSearch

https://www.gxpipetech.com/assets/js/kaka/libs/kaka.explorer.js?v=1.43

js gxpipetech.com collected 2026-10-04 04:59:53 UTC 16,097 bytes, 544 lines download raw bytes

1kakaExplorer = function(container, opts) {
2
3	var self = this;
4
5	self.defaults = {
6		container: container,
7		loadingTpl: '<div class="sui-loading"><div class="sui-loading-text"><i class="fa fa-spinner fa-spin"></i> 正在加载... </div></div>',
8		indentTpl: '<span class="x-tree-node-indent"></span>',
9		targetObj: '.sui-primary-2cols-right',
10		server: 'server.php',
11		cookiePrefix: 'x-tree',
12		sortable: true,
13		contextMenu: true,
14	};
15
16	self.opts = $.extend(true, self.defaults, opts);
17
18	self.init = function(){
19		self.loadNote(self.opts.container, 0);
20		self.buildAddEvent('.kjs-new-item');
21		if (self.opts.contextMenu !== false) {
22			self.buildContextMenu('.kjs-menu-item');
23		}
24		
25		return self;
26	}
27
28	self.loadNote = function(el, id) {
29		$(el).html('<div class="kjs-loading">'+self.opts.loadingTpl+'</div>');
30		$.getJSON(self.opts.server, {action:'get_json_list', id: id}, function(json){
31
32			$('.kjs-loading', el).remove();
33			$(el).hide();
34			$.each(json.list, function(){
35				if (this.is_hide_menu == 1) {
36					var icon = 'eye-slash';
37				} else if (this.thumb) {
38					var icon = 'file-image-o';
39				} else if (this.content_type == 'pdf') {
40					var icon = 'file-pdf-o';
41				} else if (this.content_type == 'json') {
42					var icon = 'file-code-o';
43				} else if (this.content_type == 'xml') {
44					var icon = 'file-code-o';
45				} else if (parseInt(this.child_num) > 0) {
46					var icon = 'folder';
47				} else if (this.redirect) {
48					var icon = 'link';
49				} else {
50					var icon = 'file-text-o';
51				}
52
53				if (this.icon) {
54					var icon = this.icon;
55				}
56
57				if (parseInt(this.child_num) > 0) {
58					var foldIcon = 'fold';
59					var icon = 'folder';
60				} else {
61					var foldIcon = 'fold-empty';
62				}
63                if (this.status == 1) {
64                    var colorIcon = '';
65                } else if (this.status == 2) {
66                    var colorIcon = 'color';
67                }
68				var srvUrl = this.srvUrl ? this.srvUrl : self.opts.server;
69				var safeName = $('<div>').text(this.name == null ? '' : this.name).html();
70				var safeTitle = $('<div>').text(this.name == null ? '' : this.name).html().replace(/"/g, '&quot;');
71				var safeSrv = $('<div>').text(srvUrl).html().replace(/"/g, '&quot;');
72				var safeContext = $('<div>').text(this.context || '').html().replace(/"/g, '&quot;');
73				var rawId = this.id == null ? '' : String(this.id);
74				var safeId = $('<div>').text(rawId).html().replace(/"/g, '&quot;');
75				var numericId = parseInt(rawId, 10);
76				var displaysNumericId = rawId !== '' && String(numericId) === rawId;
77				$(el).append('<li class="kjs-tree-li '+(parseInt(this.child_num) > 0?'has-child':'')+'">'
78					+'<a href="javascript:;" draggable="false" class="kjs-menu-item" title="'+safeTitle+'" data-srv="'+safeSrv+'" data-context="'+safeContext+'" data-id="'+safeId+'" data-locked="'+(parseInt(this.is_locked)?1:0)+'" data-childs="'+parseInt(this.child_num, 10)+'">'
79					+self.opts.indentTpl.repeat(Math.max(0, parseInt(this.level, 10)-1))
80					+'<i class="fa fa-fw fa-'+foldIcon+' kjs-fold"></i>'
81					+'<i class="fa fa-fw fa-'+icon+'"></i>'
82					+'<span class="menu-text '+colorIcon+'">'+(this.is_enabled == 0 ? '<del>'+safeName+'</del>' : safeName)+'</span>'
83					+(displaysNumericId ? '(#'+numericId+')' : '')+'</a><span class="dargsort-handle" title="拖动此处可进行排序"><i class="fa fa-bars kjs-dargsort"></i></span></li>');
84			})
85			$(el).slideDown(150);
86			self.buildFoldEvent('.kjs-menu-item .kjs-fold');
87			self.buildEditEvent('.kjs-menu-item');
88			self.buildSort(el);
89			self.loadCookie();
90		});
91	}
92
93	self.loadPage = function(url, data, func) {
94        // 追加 “正在加载” 的旋转按钮
95        $(self.opts.targetObj).append(self.opts.loadingTpl);
96		$.get(url, data, function(ret){
97			if (func) {
98				func(ret);
99			} else {
100				$(self.opts.targetObj).html(ret);
101				self.buildFormEvent('form.sui-form');
102				
103				if (kaka) {
104					kaka.init(self.opts.targetObj);
105				}
106			}
107		});
108	}
109
110	self.saveCookie = function() {
111		//保存打开列表
112		var opened = new Array();
113		$('.kjs-tree-li.opened>a').each(function(){
114			var id = $(this).data('id');
115			opened.push(id);
116		});
117
118		var actived = $('.kjs-tree-li.active>a').data('id');
119		var prefix = self.opts.cookiePrefix || 'x-tree';
120
121		$.setCookie(prefix + '-opened', opened);
122		$.setCookie(prefix + '-actived', actived);
123	}
124
125	self.isLoaded = 0;
126	self.loadCookie = function() {
127		var opened = new Array();
128		var prefix = self.opts.cookiePrefix || 'x-tree';
129		var openedCookie = $.getCookie(prefix + '-opened');
130		var activedCookie = $.getCookie(prefix + '-actived');
131
132		if (openedCookie) {
133			var opened = openedCookie.split(',');
134		}
135
136		for (k in opened) {
137			var xid = opened[k];
138			var mi = $('.kjs-menu-item[data-id="'+xid+'"]', self.opts.container);
139			var mp = mi.parent();
140
141			if (mi.length) {
142				$('.kjs-fold', mi).trigger('click');
143				mp.removeClass('active');
144			}
145		}
146
147		//打开活动页面
148		var xid = activedCookie;
149		var mi = $('.kjs-menu-item[data-id="'+xid+'"]', self.opts.container);
150		var mp = mi.parent();
151
152		mp.addClass('active');
153		
154		if (mi.length && self.isLoaded==0) {
155			self.isLoaded = 1; 
156			self.loadPage(mi.data('srv'), {action:'edit', id: xid});
157		}
158	}
159
160	self.buildSort = function(el) {
161		if (self.opts.sortable === false) {
162			$('.dargsort-handle', el).hide();
163			return;
164		}
165		seajs.use('/assets/js/kaka/libs/dragsort/jquery.dragsort-0.5.2.js', function(dragsort){
166			$(el).dragsort({
167				dragSelector:'.kjs-tree-li', 
168				dragSelectorExclude: 'a',
169				placeHolderTemplate: '<li class="divider"></li>',
170				dragEnd: function(){
171					var data = {};
172					$('.kjs-menu-item', el).each(function(i){
173						var id = $(this).data('id');
174						var pid = $(this).parents('.kjs-menu-item').data('id');
175						data[id] = {'rank':i+1};
176					});
177
178					var srv = $('a', el).data('srv');
179					self.eventNotice('<i class="fa fa-spinner fa-spin"></i> 正在保存排序...');
180					$.post(srv, {action:'batch', act:'update', data:data}, function(ret){
181						self.eventNotice('<i class="fa fa-check"></i> 保存成功');
182					});
183				}
184			});
185		});
186	}
187
188	self.buildAddEvent = function(el){
189		$(el).on('click', function(){
190			self.loadPage(self.opts.server, {action:'add'});
191		})
192	}
193
194	self.buildEditEvent = function(el)
195	{
196		$(el).off('click');
197		$(el).on('click', function(e){
198			var id = $(this).data('id');
199			var childs = $(this).data('childs');
200			var parent = $(this).parent();
201			var srv = $(this).data('srv');
202			var locked = $(this).data('locked');
203
204			$('.kjs-tree-li').removeClass('active');
205			parent.addClass('active');
206
207			if (!e.isTrigger) {
208				if (!locked) {
209					self.loadPage(srv?srv:self.opts.server, {action:'edit', id: id});
210				}
211				self.saveCookie();
212			}
213		})
214	}
215
216	self.buildFoldEvent = function(el) {
217		$(el).off('click');
218		$(el).on('click', function(e){
219			var id = $(this).parents('a').data('id');
220			var childs = $(this).parents('a').data('childs');
221			var parent = $(this).parents('a').parent();
222			var srv = $(this).parents('a').data('srv');
223
224			if (childs > 0) { //目录
225				if (parent.hasClass('opened')) {
226					if (!e.isTrigger) {
227						$('ul', parent).slideUp(150, function(){
228							$(this).remove();
229						});
230						parent.removeClass('opened');
231					}
232				} else {
233					parent.append('<ul></ul>');
234					self.loadNote($('ul', parent), id);
235					parent.addClass('opened');
236				}
237			}
238
239			if (!e.isTrigger) {
240				self.saveCookie();
241			}
242			return false;
243		})
244	}
245
246	self.buildFormEvent = function(el) {
247		/*$(window).off('keypress');
248		$(window).on('keypress', function(event){
249			if ((event.ctrlKey || event.metaKey) && event.keyCode == 115) {
250				$(el).trigger('submit');
251				return false;
252			}
253		});*/
254		
255		$(el).off('submit');
256		$(el).on('submit', function(){
257			var kv = new kakaValidator(el);
258			if (kv.run()) {
259				var act = $(this).attr('action');
260
261				self.eventNotice('<i class="fa fa-spinner fa-spin"></i> 正在保存...');
262				$(".btn-primary").attr({disabled:"disabled"});
263				$.ajax({
264					url: act,
265					type: 'POST',
266					cache: false,
267					data: new FormData($(this)[0]),
268					processData: false,
269					contentType: false,
270					dataType: 'json'
271				}).done(function(ret) {
272					$(".btn-primary").removeAttr("disabled");
273					//console.log(ret);
274					if (ret.result) {
275						self.eventNotice('<i class="fa fa-check"></i> 保存成功');
276						// 保存后不重新加载,小bug不影响
277						self.isLoaded = 1;
278						self.init();
279
280						var na = act.replace('\/add\/', '/edit/?id='+ret.id);
281						
282						$(el).attr('action', na);
283					} else {
284						self.eventNotice('<i class="fa fa-times"></i> '+ret.title);
285					}
286				})
287			}
288
289			return false;
290		});
291
292		$('.btn-cancel', el).attr('onclick', 'return false');
293		$('.btn-cancel', el).on('click', function(event){
294			$(self.opts.targetObj).html('<div class="notfound">您还没有打开页面哦!(⊙ˍ⊙)</div>');
295			event.stopPropagation();
296			return false;
297		});
298	}
299
300	self.buildContextMenu = function(el) {
301		seajs.use('/assets/js/kaka/libs/context/context.js', function(){
302			var menu = new BootstrapMenu(el, {
303				fetchElementData: function($el) {
304					$('.kjs-menu-item').parent().removeClass('active');
305					$el.parent().addClass('active');
306					return $el;
307				},
308				actions: 
309				[{
310					iconClass: 'fa-plus',
311					name: '在此新建',
312					isShown: function(el) {
313						var context = el.data('context');
314						if (context.indexOf('add') < 0) {
315							return false;
316						}
317					},
318					onClick: function(el) {
319						var id = el.data('id');
320						var srv = el.data('srv');
321						self.loadPage(srv, {action:'add', pid: id});
322					}
323				},
324				{
325					classNames: 'divider',
326					isShown: function(el) {
327						var context = el.data('context');
328						if (context.indexOf('add') < 0) {
329							return false;
330						}
331					},
332				},
333				{
334					name: '编辑',
335					iconClass: 'fa-edit',
336					isShown: function(el) {
337						var context = el.data('context');
338						if (context.indexOf('edit') < 0) {
339							return false;
340
341
342						}
343					},
344					onClick: function(el) {
345						var id = el.data('id');
346						var srv = el.data('srv');
347						self.loadPage(srv, {action:'edit', id: id});
348					}
349				},
350				{
351					name: '创建副本',
352					iconClass: 'fa-copy',
353					isShown: function(el) {
354						var context = el.data('context');
355						if (context.indexOf('copy') < 0) {
356							return false;
357						}
358					},
359					onClick: function(el) {
360						var id = el.data('id');
361						var srv = el.data('srv');
362						self.loadPage(srv, {action:'copy', id: id}, function(){
363							self.init();
364						});
365					}
366				},
367				{
368					name: '预览',
369					iconClass: 'fa-eye',
370					isShown: function(el) {
371						var context = el.data('context');
372						if (context.indexOf('review') < 0) {
373							return false;
374						}
375					},
376					onClick: function(el) {
377						var id = el.data('id');
378
379						var a = document.createElement('a');
380						a.setAttribute('href', '/?id='+id);
381						a.setAttribute('target', '_blank');
382						a.setAttribute('id', '_href_'+id);
383
384						if(!document.getElementById(id)) {                     
385							document.body.appendChild(a);
386						}
387						a.click();
388					}
389				},
390				{
391					name: '列表页展开',
392					iconClass: 'fa-list',
393					isShown: function(el) {
394						var context = el.data('context');
395						if (context.indexOf('list') < 0) {
396							return false;
397						}
398					},
399					onClick: function(el) {
400						var id = el.data('id');
401						var srv = el.data('srv');
402						
403						window.location.href = (srv+'&action=list&cid='+id);
404					}
405				},
406                    {
407                        name: '导入 Tag',
408                        iconClass: 'fa-import',
409                        isShown: function(el) {
410                            var context = el.data('context');
411                            if (context.indexOf('import') < 0) {
412                                return false;
413                            }
414                        },
415                        onClick: function(el) {
416                            var id = el.data('id');
417
418                            var a = document.createElement('a');
419                            a.setAttribute('href', '/admincp/content/import?cid='+id);
420
421                            if(!document.getElementById(id)) {
422                                document.body.appendChild(a); 
423                            }
424                            a.click();
425                        }
426                    },
427                    {
428                        name: 'Tag 列表',
429                        iconClass: 'fa-report',
430                        isShown: function(el) {
431                            var context = el.data('context');
432                            if (context.indexOf('report') < 0) {
433                                return false;
434                            }
435                        },
436                        onClick: function(el) {
437                            var id = el.data('id');
438
439                            var a = document.createElement('a');
440                            a.setAttribute('href', '/admincp/content/report');   // ?cid='+id
441
442                            if(!document.getElementById(id)) {
443                                document.body.appendChild(a);
444                            }
445                            a.click();
446                        }
447                    },
448				{
449					name: '导出 Excel',
450					iconClass: 'fa-download',
451					isShown: function(el) {
452						var context = el.data('context');
453						if (context.indexOf('export') < 0) {
454							return false;
455						}
456					},
457					onClick: function(el) {
458						var id = el.data('id');
459
460						var a = document.createElement('a');
461						a.setAttribute('href', '/admincp/content/export?cid='+id);
462
463						if(!document.getElementById(id)) {                     
464							document.body.appendChild(a);
465						}
466						a.click();
467					}
468				},
469
470				{
471					name: '下载文件',
472					iconClass: 'fa-download',
473					isShown: function(el) {
474						var context = el.data('context');
475						if (context.indexOf('download') < 0) {
476							return false;
477						}
478					},
479					onClick: function(el) {
480						var id = el.data('id');
481						var srv = el.data('srv');
482
483						window.location.href = (srv+'&action=download&path='+id);
484					}
485				},
486				{classNames: 'divider'},
487                    {
488                        name: '恢复',
489                        iconClass: 'fa-trash-i',
490                        isEnabled: function(el) {
491                            var context = el.data('context');
492                            if (context.indexOf('renew') < 0) {
493                                return false;
494                            }
495                        },
496                        onClick: function(el) {
497                            var id = el.data('id');
498                            var srv = el.data('srv');
499                            if (confirm('确认要恢复吗')) {
500                                self.loadPage(srv, {action:'renew', id: id}, function(ret){
501                                    $(self.opts.targetObj).html('<div class="notfound">页面已恢复</div>');
502                                    self.init();
503                                });
504                            }
505                        }
506                    },
507				{
508					name: '删除',
509					iconClass: 'fa-trash-o',
510					isEnabled: function(el) {
511						var context = el.data('context');
512						if (context.indexOf('delete') < 0) {
513							return false;
514						}
515					},
516					onClick: function(el) {
517						var id = el.data('id');
518						var srv = el.data('srv');
519						if (confirm('确认要删除吗')) {
520                            self.loadPage(srv, {action:'delete', id: id}, function(ret){
521                                $(self.opts.targetObj).html('<div class="notfound">页面已删除</div>');
522                                self.init();
523                            });
524						}
525					},
526				}]
527			});
528		});
529	}
530
531	self.eventNotice = function(msg) {
532		$('.sui-notify').remove();
533		$('body').append('<div class="sui-notify">'+msg+'</div>');
534
535		clearInterval();
536		setInterval(function(){
537			$('.sui-notify').fadeOut(200);
538		}, 6000);
539	}
540
541	self.init();
542
543	return self;
544}

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.