diff --git a/mip-s278/mip-s278.js b/mip-s278/mip-s278.js index fa9fd0af..723e0157 100644 --- a/mip-s278/mip-s278.js +++ b/mip-s278/mip-s278.js @@ -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 = ''; - li.innerHTML += '' + json[i].vodpart; - li.innerHTML += '' + json[i].vodname + ''; - 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: { + 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 = ''; + h.innerHTML += '' + j[l].vodpart; + h.innerHTML += '' + j[l].vodname + ''; + 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) + }); + } + } + +});