Skip to content

[platform] 哟哟哈哈36 提交组件改动:mip-s278 #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
303 changes: 145 additions & 158 deletions mip-s278/mip-s278.js
Original file line number Diff line number Diff line change
@@ -1,158 +1,145 @@
/**
* @file mip-s278 组件
* @author s278作者
*/

define(function (e) {

var a = e('customElement').create();
var n = e('zepto');
/**
* 构造元素,只会运行一次
*/
a.prototype.firstInviewCallback = function () {
var stui = {
Cookie: {
set: function (name, value, days) {
var exp = new Date();
exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
document.cookie = name + '=' + escape(value) + ';path=/;expires=' + exp.toUTCString();
},
get: function (name) {
var arr = document.cookie.match(new RegExp('(^| )' + name + '=([^;]*)(;|$)'));
if (arr != null) {
return unescape(arr[2]);
}

},
del: function (name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = this.get(name);
if (cval != null) {
document.cookie = name + '=' + escape(cval) + ';path=/;expires=' + exp.toUTCString();
}

}
},
common: {
history: function () {
if (stui.Cookie.get('recente')) {
var json = $.parseJSON('+stui.Cookie.get("recente")+');

for (var i = 0; i < json.length; i++) {
var li = document.createElement('li');
li.innerHTML = '<a href=\'' + json[i].vodurl + '\' title=\'' + json[i].vodname + '\'>';
li.innerHTML += '<span class=\'pull-right text-red\'>' + json[i].vodpart;
li.innerHTML += '</span>' + json[i].vodname + '</a>';
n('#stui_history').append(li);
}
}
else {
var p = document.createElement('p');
p.innerHTML = '您还没有看过影片哦';
p.style.textAlign = 'center';
p.style.padding = '80px 0';
n('#stui_history').append(p);
}
n('.historyclean').first().click(function () {
stui.Cookie.del('recente');
});
}
}
};
window.onload = function () {
var his = n('.stui-his').first();
var drop = n('.dropdown').first();
his.onmouseover = function () {
drop.style.display = 'block';
};
his.onmouseout = function () {
drop.style.display = 'none';
};
his.onclick = function () {
if (drop.style.display === 'none') {
drop.style.display = 'block';
}
else {
drop.style.display = 'none';
}
};
stui.common.history();
if (window.location.href.indexOf('play') > -1) {
var vodname = n('vodname').html();
var vodpart = n('playname').html();
var vodurl = window.location.href;
var recente = stui.Cookie.get('recente');
var len = 0;
var canadd = true;
if (recente) {
recente = $.parseJSON('+recente+');
len = recente.length;
$(recente).each(function () {
if (vodname === this.vodName) { // 已记录则修改
canadd = false;
var json = '[';
$(recente).each(function (i) {
var tempname;
var tempurl;
var temppart;
if (this.vodname === vodname) {
tempname = vodname;
tempurl = vodurl;
temppart = vodpart;
}
else {
tempname = this.vodname;
tempurl = this.vodurl;
temppart = this.vodpart;
}
json += '{\"vodname\":\"' + tempname + '\",\"vodurl\":\"' + tempurl;
json += '\",\"vodpart\":\"' + temppart + '\"}';
if (i !== len - 1) {
json += ',';
}

});
json += ']';
stui.Cookie.set('recente', json, {
path: '/',
expires: (2)
});
return false;
}

});
}

if (canadd) { // 无记录则添加
var json = '[';
var isfirst = ']';
isfirst = !len ? ']' : ',';
json += '{"vodname":"' + vodname + '","vodurl":"' + vodurl;
json += '","vodpart":"' + vodpart + '"}' + isfirst;
if (len > 9) {
len -= 1;
}

for (var i = 0; i < len - 1; i++) {
json += '{"vodname":"' + recente[i].vodname + '","vodurl":"' + recente[i].vodurl;
json += '","vodpart":"' + recente[i].vodpart + '"},';
}
if (len > 0) {
json += '{"vodname":"' + recente[len - 1].vodname + '","vodurl":"' + recente[len - 1].vodurl;
json += '","vodpart":"' + recente[len - 1].vodpart + '"}]';
}

stui.Cookie.set('recente', json, {
path: '/',
expires: (2)
});
}
}

};
};

return a;
});
/**
* @file mip-s278 组件
* @author s278作者
*/

define(function (e) {

var v = e('zepto');
var x = {
Cookie: {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

缩进有问题,应采用 4 个空格缩进

set: function (a, b, c) {
var exp = new Date();
exp.setTime(exp.getTime() + c * 24 * 60 * 60 * 1000);
document.cookie = a + '=' + escape(b) + ';path=/;expires=' + exp.toUTCString();
},
get: function (a) {
var arr = document.cookie.match(new RegExp('(^| )' + a + '=([^;]*)(;|$)'));
if (arr != null) {
return unescape(arr[2]);
}

},
del: function (a) {
var k = new Date();
k.setTime(k.getTime() - 1);
var u = this.get(a);
if (u != null) {
document.cookie = a + '=' + escape(u) + ';path=/;expires=' + k.toUTCString();
}

}
},
common: {
history: function () {
if (x.Cookie.get('recente')) {
var j = v.parseJSON(x.Cookie.get('recente'));

for (var l = 0; l < j.length; l++) {
var h = document.createElement('li');
h.innerHTML = '<a href=\'' + j[l].vodurl + '\' title=\'' + j[l].vodname + '\'>';
h.innerHTML += '<span class=\'pull-right text-red\'>' + j[l].vodpart;
h.innerHTML += '</span>' + j[l].vodname + '</a>';
v('#stui_history').append(h);
}
}
else {
var p = document.createElement('p');
p.innerHTML = '您还没有看过影片哦';
p.style.textAlign = 'center';
p.style.padding = '80px 0';
v('#stui_history').append(p);
}
v('.historyclean').first().click(function () {
x.Cookie.del('recente');
});
}
}
};
var s = v('.stui-his').first();
var f = v('.dropdown').first();
s.onmouseover = function () {
f.style.display = 'block';
};
s.onmouseout = function () {
f.style.display = 'none';
};
s.onclick = function () {
if (f.style.display === 'none') {
f.style.display = 'block';
}
else {
f.style.display = 'none';
}
};
x.common.history();
if (window.location.href.indexOf('play') > -1) {
var m = v('vodname').html();
var y = v('playname').html();
var u = window.location.href;
var z = x.Cookie.get('recente');
var q = 0;
var d = true;
if (z) {
z = v.parseJSON(z);
q = z.length;
v(z).each(function () {
if (m === this.m) { // 已记录则修改
d = false;
var o = '[';
v(z).each(function (i) {
var h;
var w;
var p;
if (this.vodname === m) {
h = m;
w = u;
p = y;
}
else {
h = this.vodname;
w = this.vodurl;
p = this.vodpart;
}
o += '{\"vodname\":\"' + h + '\",\"vodurl\":\"' + w;
o += '\",\"vodpart\":\"' + p + '\"}';
if (i !== q - 1) {
o += ',';
}

});
o += ']';
x.Cookie.set('recente', o, {
path: '/',
expires: (2)
});
return false;
}

});
}
if (d) { // 无记录则添加
var o = '[';
var r = ']';
r = !q ? ']' : ',';
o += '{"vodname":"' + m + '","vodurl":"' + u;
o += '","vodpart":"' + y + '"}' + r;
if (q > 9) {
q -= 1;
}
for (var i = 0; i < q - 1; i++) {
o += '{"vodname":"' + z[i].vodname + '","vodurl":"' + z[i].vodurl;
o += '","vodpart":"' + z[i].vodpart + '"},';
}
if (q > 0) {
o += '{"vodname":"' + z[q - 1].vodname + '","vodurl":"' + z[q - 1].vodurl;
o += '","vodpart":"' + z[q - 1].vodpart + '"}]';
}
x.Cookie.set('recente', o, {
path: '/',
expires: (2)
});
}
}

});