Skip to content

Commit

Permalink
Element created by zrender add className. Fix apache/echarts#1686
Browse files Browse the repository at this point in the history
  • Loading branch information
pissang committed Jun 24, 2015
1 parent 89a22dd commit 09805df
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/Handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ define(
'touchstart', 'touchend', 'touchmove'
];

var isZRenderElement = function (event) {
// 暂时忽略 IE8-
if (window.G_vmlCanvasManager) {
return true;
}

event = event || window.event;
// 进入对象优先~
var target = event.toElement
|| event.relatedTarget
|| event.srcElement
|| event.target;

return target && target.className.match(config.elementClassName)
};

var domHandlers = {
/**
* 窗口大小改变响应函数
Expand All @@ -49,6 +65,10 @@ define(
* @param {Event} event
*/
click: function (event) {
if (! isZRenderElement(event)) {
return;
}

event = this._zrenderEventFixed(event);

// 分发config.EVENT.CLICK事件
Expand All @@ -72,6 +92,10 @@ define(
* @param {Event} event
*/
dblclick: function (event) {
if (! isZRenderElement(event)) {
return;
}

event = event || window.event;
event = this._zrenderEventFixed(event);

Expand All @@ -97,6 +121,10 @@ define(
* @param {Event} event
*/
mousewheel: function (event) {
if (! isZRenderElement(event)) {
return;
}

event = this._zrenderEventFixed(event);

// http://www.sitepoint.com/html5-javascript-mouse-wheel/
Expand Down Expand Up @@ -148,6 +176,10 @@ define(
* @param {Event} event
*/
mousemove: function (event) {
if (! isZRenderElement(event)) {
return;
}

if (this.painter.isLoading()) {
return;
}
Expand Down Expand Up @@ -241,6 +273,10 @@ define(
* @param {Event} event
*/
mouseout: function (event) {
if (! isZRenderElement(event)) {
return;
}

event = this._zrenderEventFixed(event);

var element = event.toElement || event.relatedTarget;
Expand Down Expand Up @@ -277,6 +313,10 @@ define(
* @param {Event} event
*/
mousedown: function (event) {
if (! isZRenderElement(event)) {
return;
}

// 重置 clickThreshold
this._clickThreshold = 0;

Expand All @@ -303,6 +343,10 @@ define(
* @param {Event} event
*/
mouseup: function (event) {
if (! isZRenderElement(event)) {
return;
}

event = this._zrenderEventFixed(event);
this.root.style.cursor = 'default';
this._isMouseDown = 0;
Expand All @@ -320,6 +364,10 @@ define(
* @param {Event} event
*/
touchstart: function (event) {
if (! isZRenderElement(event)) {
return;
}

// eventTool.stop(event);// 阻止浏览器默认事件,重要
event = this._zrenderEventFixed(event, true);
this._lastTouchMoment = new Date();
Expand All @@ -335,6 +383,10 @@ define(
* @param {Event} event
*/
touchmove: function (event) {
if (! isZRenderElement(event)) {
return;
}

event = this._zrenderEventFixed(event, true);
this._mousemoveHandler(event);
if (this._isDragging) {
Expand All @@ -348,6 +400,10 @@ define(
* @param {Event} event
*/
touchend: function (event) {
if (! isZRenderElement(event)) {
return;
}

// eventTool.stop(event);// 阻止浏览器默认事件,重要
event = this._zrenderEventFixed(event, true);
this._mouseupHandler(event);
Expand Down
2 changes: 2 additions & 0 deletions src/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ define(function (require) {
this.dom.style['-webkit-touch-callout'] = 'none';
this.dom.style['-webkit-tap-highlight-color'] = 'rgba(0,0,0,0)';

this.dom.className = config.elementClassName;

vmlCanvasManager && vmlCanvasManager.initElement(this.dom);

this.domBack = null;
Expand Down
1 change: 1 addition & 0 deletions src/Painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
'-webkit-touch-callout:none;'
].join('');
this._bgDom.setAttribute('data-zr-dom-id', 'bg');
this._bgDom.className = config.elementClassName;

domRoot.appendChild(this._bgDom);
this._bgDom.onselectstart = returnFalse;
Expand Down
2 changes: 2 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ define(function () {
touchClickDelay : 300
},

elementClassName: 'zr-element',

// 是否异常捕获
catchBrushException: false,

Expand Down

0 comments on commit 09805df

Please sign in to comment.