function ClickVerify(options) {
this.id = options.id || "clickMark";
this.imgUrl = options.imgUrl;
this.num = options.num;
this.success = options.success;
this.initDom = options.initDom;
this.textDom = options.textDom;
this.text = options.text;
this.markIcon = options.markIcon || '这里写默认图标(可从后端接受或者自己查找)';
}
ClickVerify.prototype = {
markNum: 1,
infos: [],
offsetX: 0,
offsetY: 0,
container: null,
img: null,
refreshIcon: '',
refreshIconDisable: true,
init: function () {
this.markNum = 1;
this.infos = [];
this.offsetX = 0;
this.offsetY = 0;
this.container = null;
this.img = null;
this.container = document.createElement("div");
this.img = new Image();
this.container.id = this.id;
var that = this;
var parentDom = this.initDom || document.body;
this.img.src = this.imgUrl;
this.img.style.verticalAlign = "middle";
this.container.style.display = "inline-block";
this.container.style.position = "relative";
this.container.appendChild(this.img);
this.textDom.innerHTML = this.text + ' (请按照文字顺序进行点选)';
parentDom.appendChild(this.container);
this.container.onclick = function (e) {
if (that.markNum > that.num) {
return false;
}
e = e || window.event;
that.offsetX = e.offsetX - 15;
that.offsetY = e.offsetY - 15;
var mark = document.createElement("div");
var markImg = new Image()
markImg.src = that.markIcon;
markImg.style.width = '30px';
markImg.style.height = '30px';
markImg.style.position = 'absolute';
markImg.style.top = '50%';
markImg.style.left = '50%';
markImg.style.marginTop = '-15px'
markImg.style.marginLeft = '-15px'
markImg.style.zIndex = '-1';
mark.style.color = "#fff";
mark.style.textAlign = "center";
mark.style.lineHeight = "24px";
mark.style.width = "30px";
mark.style.height = "30px";
mark.style.position = "absolute";
mark.style.top = that.offsetY + "px";
mark.style.left = that.offsetX + "px";
mark.style.fontSize = 12 + "px";
mark.style.zIndex = '99999';
mark.style.cursor = 'default'
mark.innerText = that.markNum;
mark.background = "url('" + that.markIcon + "') no-repeat 100% 100%"
mark.appendChild(markImg)
this.appendChild(mark);
that.infos.push({
order: that.markNum,
x: that.offsetX.toFixed(0),
y: that.offsetY.toFixed(0)
});
if (that.markNum === that.num) {
typeof that.success === "function" && that.success(that.getResultInfo());
}
that.markNum++;
};
},
reset: function (destroy) {
this.infos = [];
this.markNum = 1;
if (!destroy) {
this.textDom.innerText = '';
this.initDom.innerHTML = '';
} else {
this.container.innerHTML = '';
this.container.appendChild(this.img)
}
},
getResultInfo: function () {
return this.infos;
}
};