Authored by 梁志锋

yas去掉对sizzle库的依赖,减小yas的体积

{
"name": "yas-jssdk",
"version": "1.0.15",
"version": "1.0.14",
"description": "YOHO!采集系统的前端js的开发包",
"keywords": ["YOHO!", "Acquisition", "System", "JS-SDK"],
"homepage": "",
... ... @@ -20,13 +20,11 @@
"spm": {
"main": "yas.js",
"dependencies": {
"yoho.sizzle": "2.2.2-pre",
"yoho.json2": "1.0.0"
},
"devDependencies": {
"expect.js": "0.3.1",
"sinon": "1.6.0",
"yoho.sizzle": "2.2.2-pre"
"sinon": "1.6.0"
},
"buildArgs": "--include standalone"
},
... ...
... ... @@ -17,8 +17,6 @@ var ev = require('./event');
var config = require('./config');
var sizzle = require('yoho.sizzle');
require('yoho.json2');
//sdk 版本
... ... @@ -75,8 +73,6 @@ var browserInfo = {
fv: flash.f ? flash.v : 0 //flashVersion
};
var eventArray = [];
//入口方法
var _yas = function(initTime, version, tid, uid, geo, selector) {
custInfo.ak = tid;
... ... @@ -133,34 +129,13 @@ var _yas = function(initTime, version, tid, uid, geo, selector) {
}
/**
* 用于统计用户点击了选择器元素的序号,此方法依赖第三方库Sizzle
* 用于统计用户点击的selector元素的序号
* 记录cookie, 待进入新页面后通过send方法将cookie中的鼠标记录发送并清空.
*
*/
var nodes = null;
if (selector) {
if (Object.prototype.toString.call(selector) === "[object String]") {
if (sizzle) {
nodes = sizzle(selector);
}
} else {
nodes = selector;
}
}
if (nodes) {
for (var index = 0, length = nodes.length; index < length; index++) {
(function(i){
ev.addEventHandler(nodes[i], 'click', function (e) {
ix = i + 1;
var pos = getMouseEventPosition(e);
cookies('_yasmp', pos.x + ',' + pos.y + ',' + e.type + ',' + (i + 1), {
path: '/',
domain: yasDomain,
expires: 365 * 200
});
});
})(index);
if (selector[0]) {
for (var i = 0, length = selector.length; i < length; i++) {
selector[i].setAttribute('yoho_index', (i +1));
}
} else {
/**
... ... @@ -173,7 +148,12 @@ var _yas = function(initTime, version, tid, uid, geo, selector) {
var target = e.target || e.srcElement;
if(target && (target.nodeName === 'A' || (target.nodeName === 'IMG' && target.parentNode.nodeName === 'A'))) {
var pos = getMouseEventPosition(e);
cookies('_yasmp', pos.x + ',' + pos.y + ',' + e.type, {
var str = pos.x + ',' + pos.y + ',' + e.type;
var yoho_index = target.getAttribute('yoho_index') || target.parentNode.getAttribute('yoho_index');
if (yoho_index) {
str += ',' + yoho_index;
}
cookies('_yasmp', str, {
path: '/',
domain: yasDomain,
expires: 365 * 200
... ...
... ... @@ -21,7 +21,7 @@
a.src=j;
m.parentNode.insertBefore(a,m);
}
)(window,document,'script','/dist/yas-jssdk/1.0.15/yas.js&'+Math.random(),'_yas');
)(window,document,'script','/dist/yas-jssdk/1.0.14/yas.js&'+Math.random(),'_yas');
_yas(1*new Date(),'1.0','ds6das2kkj','21323231','geo');
... ...
... ... @@ -6,42 +6,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="generator" content="nico 0.5.1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script>
(
function(w,d,s,j,f)
{
w['YohoAcquisitionObject'] = f;
w[f] = function()
{
w[f].p=arguments;
};
var a=d.createElement(s);
var m=d.getElementsByTagName(s)[0];
a.async=1;
a.src=j;
m.parentNode.insertBefore(a,m);
}
)(window,document,'script','/dist/yas-jssdk/1.0.15/yas-debug.js','_yas');
_yas(1*new Date(),'1.0','ds6das2kkj','21323231','geo', '.test >a >img');
window.onload = function(){
alert('haha!');
var button = document.getElementById('button');
button.onclick = function(e){
_yas.sendMouseEvent(e);
}
}
<script type="text/javascript" src="../yas.js"></script>
<script type="text/javascript">
seajs.use('yas',function(_yas){
_yas(1*new Date(),'1.0.14','ds6das2kkj','21323231','geo');
});
</script>
</head>
<body style="height:2000px; width:800px; scroll:auto">
<div class="test">
<a href="test2.html">
<img src="http://img11.static.yhbimg.com/yhb-img01/2015/09/12/06/013a80e1affcac788863ef4325b0708e82.jpg?imageView/2/w/640/h/240">
</a>
</div>
<p><button id="button">触发记录</button>
<body>
</body>
</html>
\ No newline at end of file
... ...
... ... @@ -21,9 +21,9 @@
a.src=j;
m.parentNode.insertBefore(a,m);
}
)(window,document,'script','/dist/yas-jssdk/1.0.15/yas-debug.js','_yas');
)(window,document,'script','/dist/yas-jssdk/1.0.14/yas-debug.js','_yas');
_yas(1*new Date(),'1.0','ds6das2kkj','21323231','geo', '.test >a >img');
_yas(1*new Date(),'1.0','ds6das2kkj','21323231','geo', $('.test >a >img'));
window.onload = function(){
alert('haha!');
... ...