', { 'class': flowInfoClass })
.append($('
', { 'class': flowNameClass, text:v+" "+ name }))
.append($detail);
that.customMenu($detail, function ($node, $menu) {
$menu.find("a.dropdown-item").hide();
$menu.find("a.dropdown-item.flow-d").show();
if (opts.customMenuBefore && $.type(opts.customMenuBefore) === 'function') {
opts.customMenuBefore($node, $menu);
}
});
$flowInfoBox.append($flow);
});
}
return $flowInfoBox;
},
customMenu: function ($node,beforeFun) {
var that = this;
var opts = that.options;
var $menu = typeof opts.customMenu === 'string' ? $('#' + opts.customMenu) : $(opts.customMenu);;
$node.css('cursor', 'help');
$node.contextmenu(function (e) {
if (beforeFun && $.type(beforeFun) === 'function') {
beforeFun($node, $menu);
}
e = e || window.event;
//鼠标点的坐标
var oX = e.clientX;
var oY = e.clientY;
//菜单出现后的位置
$menu.fadeIn();
$menu.offset({ top: oY, left: oX });
//阻止浏览器默认事件
return false; //一般点击右键会出现浏览器默认的右键菜单,写了这句代码就可以阻止该默认事件。)
});
$(document).on('click', function (e) {
e = e || window.event;
$menu.hide();
});
$node.on('click', function (e) {
e = e || window.event;
e.cancelBubble = true;
});
},
zoomWheel: function (e) {
var nt = e.data.nt;
e.preventDefault();
var newScale = 1 + (e.originalEvent.deltaY > 0 ? -0.05 : 0.05);
nt.setChartScale(nt.$nodeTree, newScale);
},
setChartScale: function ($nodeTree, newScale) {
var that = this;
var opts = that.options;
var lastTf = $nodeTree.css('transform');
var matrix = '';
var targetScale = 1;
if (lastTf === 'none') {
$nodeTree.css('transform', 'scale(' + newScale + ',' + newScale + ')');
} else {
matrix = lastTf.split(',');
if (lastTf.indexOf('3d') === -1) {
targetScale = Math.abs(window.parseFloat(matrix[3]) * newScale);
if (targetScale > opts.zoomMinLimit && targetScale < opts.zoomMaxLimit) {
$nodeTree.css('transform', lastTf + ' scale(' + newScale + ',' + newScale + ')');
}
} else {
targetScale = Math.abs(window.parseFloat(matrix[1]) * newScale);
if (targetScale > opts.zoomMinLimit && targetScale < opts.zoomMaxLimit) {
$nodeTree.css('transform', lastTf + ' scale3d(' + newScale + ',' + newScale + ', 1)');
}
}
}
},
drag: function ($node) {
var that = this;
var opts = that.options;
var x = 0;
var y = 0;
var l = 0;
var t = 0;
var cursor = 'pointer';
var timeout = undefined;
$node.data('drag', false);
//点击(松开后触发)
$node.mousedown(function (e) {
if (e.which === 3) {//禁止右键拖动
return;
}
var $this = $(this);
timeout = setTimeout(function() {
//获取x坐标和y坐标
x = e.clientX;
y = e.clientY;
//获取左部和顶部的偏移量
l = that.$nodeTree.offset().left;
t = that.$nodeTree.offset().top;
//开关打开
$node.data('drag', true);
that.$nodeTree.fadeTo(20, 0.5);
//设置样式
cursor = $this.css('cursor');
$this.css('cursor', 'move');
}, opts.dragDelay);
});
that.$nodeContainer.mousemove(function (e) {
e.preventDefault();
if ($node.data('drag') !== true) {
return;
}
//获取x和y
var nx = e.clientX;
var ny = e.clientY;
//计算移动后的左偏移量和顶部的偏移量
var nl = nx - (x - l);
var nt = ny - (y - t);
that.$nodeTree.offset({ top: nt, left: nl });
});
$node.mouseup(function () {
//开关打开
$node.data('drag', false);
that.$nodeTree.fadeTo("fast", 1);
//设置样式
$(this).css('cursor', cursor);
clearTimeout(timeout);
});
//$node.mouseleave(function(e) {
// //开关打开
// $node.data('drag', false).fadeTo("fast", 1);
// //设置样式
// $(this).css('cursor', 'default');
//});
},
exportData: function (input) {
var that = this;
var $nodeContainer = this.$nodeContainer;
input = input || this.options.exportDataInput;
if ($(this).children('.spinner').length) {
return false;
}
var img;
var sourceChart = $nodeContainer.addClass('canvasContainer').find('.' + treeClass + ':not(".hidden")').get(0);
var flag = that.options.direction === 'l2r' || that.options.direction === 'r2l';
window.html2canvas(sourceChart, {
'width': flag ? sourceChart.clientHeight : sourceChart.clientWidth,
'height': flag ? sourceChart.clientWidth : sourceChart.clientHeight,
'onclone': function (cloneDoc) {
$(cloneDoc).find('.canvasContainer').css('overflow', 'visible')
.find('.' + treeClass + ':not(".hidden"):first').css('transform', '');
},
'onrendered': function (canvas) {
img = canvas.toDataURL("image/png");
console.log("exportData-over");
input.val(img);
}
})
.then(function () {
$nodeContainer.removeClass('canvasContainer');
});
return img;
},
refresh: function(opt) {
var that = this;
var opts = $.extend({}, this.options, opt || {});
var data = opts.data, $node = opts.node, str, $that,$setting;
if (data) {
switch (opts.type) {
case 'roundSetting':
case 'guide':
case 'PRE':
case 'RUN':
case 'POST':
if ($node.hasClass(roundSettingClass)) {
str = that.buildRoundSetting(data);
$node.find('.' + contentClass).empty().html(str);
} else if ($node.hasClass(settingBoxClass)) {
str = that.buildSetting(data);
$node.empty().html(str);
} else if ($node.hasClass(nodeRoundClass)) {
var $settingBox = $node.parent().find('.' + roundSettingClass);
if ($settingBox.length === 1) {
str = that.buildRoundSetting(data);
$settingBox.find('.' + contentClass).empty().html(str);
}
}
$setting = $node;
break;
case 'flow':
var $info = that.buildFlowInfo(data);
$node.empty().append($info);
break;
case 'addRound':
$('.' + roundClass + ' .' + nodeRoundClass).removeClass('last');
var $round = that.buildRoundInfo(data, true);
$node.parent().after($round);
$setting = $round;
break;
case 'deleteRound':
$node.closest('.round-box').prev().find('.round-node').addClass('last');
$node.closest('.round-box').remove();
break;
case 'addBlock':
$that = $node.closest('.' + nodeBlockClass);
var $item = that.buildEvTab(data);
$that.find('.tab-box .nav').append($item);
var $pane = that.buildEvTabPane(data);
$that.find('.tab-content-box .tab-content').append($pane);
$item.find('.nav-link').tab('show');
break;
case 'deleteBlock':
$that = $node.closest('.' + nodeBlockClass);
if ($node.find('.nav-link').hasClass('active')) {
$that.find('.tab-box .nav .nav-item').eq(0).find('.nav-link').tab('show');
$that.find('.tab-content-box .tab-content .tab-pane').eq(0).addClass('active show');
}
$node.remove();
$that.find('.tab-content-box .tab-content').find('#ev-block-' + data.path).remove();
break;
default:
init(data);
break;
}
if ($setting) {
$setting.find('.setting').off("click.setting").on("click.setting", function () { that.options.settingFun($(this)); });
}
}
}
};
var allowedMethods = ["refresh"];
$.fn.packageTree = function (option) {
var value,
args = Array.prototype.slice.call(arguments, 1);
this.each(function () {
var $this = $(this);
var data = $this.data('iwb.package.tree'),
options = $.extend({}, $this.data(),
typeof option === 'object' && option);
if (typeof option === 'string') {
if ($.inArray(option, allowedMethods) < 0) {
throw new Error("Unknown method: " + option);
}
if (!data) {
return;
}
value = data[option].apply(data, args);
//if (option === 'destroy') {
// $this.removeData('iwb.package.tree');
// $this.removeData('iwb.package.tree.init');
// return;
//}
} else {
data = new PackageTree(this, options).init();
$this.data('iwb.package.tree', data);
}
//if ($this.data('iwb.package.tree.init')) {
// return;
//}
//$this.data('iwb.package.tree.init', true);
//if (!data) {
// data = new PackageTree(this, options).init();
// $this.data('iwb.package.tree', data);
//}
});
return typeof value === 'undefined' ? this : value;
};
}));