sortmenu.js
2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
var $ = require('jquery');
var init=function(callback){
var $navItem = $('.list-group-item');
var $navIcon = $navItem.find('span.icon');
$navItem.click(function (event) {
var $this = $(this),
$thisNext = $this.nextAll(),
thisVal = $(this).attr('data-val'),
$target = $(event.target);
if (!$this.attr('data-active')) {
if ($target.hasClass('list-group-item')) {
$navItem.removeClass('attr-item-active');
$(this).addClass('attr-item-active').attr('data-active', 'data-active');
$('.model-attr-btn').removeAttr('disabled');
$('input#categoryId').val($this.attr('data-val'));
}
} else {
if ($target.hasClass('list-group-item')) {
$(this).removeClass('attr-item-active').removeAttr('data-active');
$('.model-attr-btn').attr('disabled', 'disabled');
}
}
if ($this.attr('data-status') === 'close') {
if ($target.hasClass('icon')) {
$thisNext.filter(function (index) {
return $(this).attr('data-parent') === thisVal;
}).removeClass('hidden');
$this.attr('data-status', 'open').find('span')
.removeClass('glyphicon-plus').addClass('glyphicon-minus');
}
} else {
if ($target.hasClass('icon')) {
$thisNext.filter(function (index) {
var thisR = $(this).attr('data-parent') === thisVal;
if (thisR && $(this).attr('data-status') === 'open') {
$(this).find('span.icon').trigger('click');
}
return thisR;
}).addClass('hidden');
$this.attr('data-status', 'close').find('span')
.removeClass('glyphicon-minus').addClass('glyphicon-plus');
}
}
window.sortid=thisVal;
window.sortname=$.trim($(".attr-item-active[data-val="+thisVal+"]").text());//c.join('/');
callback&&callback();
});
}
module.exports={init:init};