From 8517225ddd4c3924833db6b3a5d97669e1a83b38 Mon Sep 17 00:00:00 2001
From: pifire <104460712@qq.com>
Date: Fri, 30 Dec 2016 15:18:56 +0800
Subject: [PATCH 1/5] =?UTF-8?q?muzi=E9=AB=98=E9=80=9F=E4=B8=8B=E8=BD=BD?=
=?UTF-8?q?=E5=92=8C=E6=99=AE=E9=80=9A=E4=B8=8B=E8=BD=BD=E5=88=87=E6=8D=A2?=
=?UTF-8?q?=E7=BB=84=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
mip-mz-appdownload/README.md | 61 ++++++++++
mip-mz-appdownload/mip-mz-appdownload.js | 139 +++++++++++++++++++++++
mip-mz-appdownload/package.json | 14 +++
3 files changed, 214 insertions(+)
create mode 100644 mip-mz-appdownload/README.md
create mode 100644 mip-mz-appdownload/mip-mz-appdownload.js
create mode 100644 mip-mz-appdownload/package.json
diff --git a/mip-mz-appdownload/README.md b/mip-mz-appdownload/README.md
new file mode 100644
index 000000000..e97d32ab7
--- /dev/null
+++ b/mip-mz-appdownload/README.md
@@ -0,0 +1,61 @@
+# mip-mz-appdownload
+
+mip-mz-appdownload app下载组件,在高速下载和直接下载之间切换!
+
+标题|内容
+----|----
+类型|通用
+所需脚本|http://mipcache.bdstatic.com/static/v1/mip-mz-appdownload/mip-mz-appdownload.js
+
+## 示例
+
+### app下载组件,在高速下载和直接下载之间切换!
+```html
+
' + obj.android[presenti].info + '
'; + } + return '' + obj.android[0].ubtnvalue + ''; + } + // 判断url下载还是id下载 + function checkurl(aid, addr) { + return (addr.length === 0) ? localhref + aid : addr; + } + // 点击按钮切换下载 + function changeDown(aid, addr, androidAD) { + var chk = $('#ckb'); + var yybtext = $('#yybtext'); + var gsdbtn = $('#gsdbtn'); + var presenti = 0; + for (var i = 0; i < androidAD.length; ++i) { + if (!getCookie(androidAD[i].id)) { + presenti = i; + break; + } + } + if (chk.is(':checked')) { + yybtext.css('color', 'black'); + gsdbtn.attr('href', androidAD[presenti].url); + gsdbtn.text(androidAD[presenti].btnvalue); + yybtext.html(androidAD[presenti].info); + } + else { + yybtext.css('color', 'red'); + gsdbtn.attr('href', checkurl(aid, addr)); + gsdbtn.text(androidAD[presenti].ubtnvalue); + yybtext.html(androidAD[presenti].uinfo); + } + } + // 设置cookie + function setCookie(cname, cvalue, exdays) { + var d = new Date(); + d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); + var expires = 'expires=' + d.toGMTString(); + document.cookie = cname + '=' + cvalue + ';expires=' + expires; + } + // 获取cookie + function getCookie(cname) { + var name = cname + '='; + var ca = document.cookie.split(';'); + for (var i = 0; i < ca.length; i++) { + var c = ca[i].trim(); + if (c.indexOf(name) === 0) { + return c.substring(name.length); + } + } + } + // 数组中是否包含 + function inarray(arr, obj) { + var i = arr.length; + while (i--) { + if (arr[i] === obj) { + return true; + } + } + return false; + } + + /** + * 构造元素,只会运行一次 + */ + customElement.prototype.firstInviewCallback = function () { + var element = this.element; + var $element = $(element); + var ad = $element.attr('ad'); + var aid = $element.attr('aid'); + var addr = $element.attr('addr'); + $.ajax({ + method: 'get', + url: 'http://madmin.muzisoft.com/mipappdown.json', + dataType: 'json', + success: function (data) { + var innerHTML = initAD(ad, aid, addr, data); + $('#down ul li').append(innerHTML); + $('#ckb').click(function () { + changeDown(aid, addr, data.android); + }); + // 安卓点击了高速按钮,写cookie + $('#gsdbtn').click(function () { + for (var i = 0; i < data.android.length; ++i) { + var j = (i === data.android.length - 1) ? 0 : i + 1; + if ($('#gsdbtn').attr('presentid') === data.android[i].id) { + setCookie(data.android[j].id, '', 1); + } + else { + setCookie(data.android[j].id, 1, 1); + } + } + }); + // 苹果点击了下载 + $('#confirmios').click(function () { + if (confirm(data.ios[0].name)) { + window.location.href = data.ios[0].url; + return false; + } + }); + }, + error: function () {} + }); + }; + return customElement; +}); diff --git a/mip-mz-appdownload/package.json b/mip-mz-appdownload/package.json new file mode 100644 index 000000000..69dde8bd3 --- /dev/null +++ b/mip-mz-appdownload/package.json @@ -0,0 +1,14 @@ +{ + "name": "mip-mz-appdownload", + "version": "1.0.0", + "description": "app下载组件,在高速下载和直接下载之间切换!", + "contributors": [ + { + "name": "pifire", + "email": "104460712@qq.com" + } + ], + "engines": { + "mip": ">=1.1.0" + } +} From 3fd90e4da954e23e75165a80f0df50552937773e Mon Sep 17 00:00:00 2001 From: pifire <104460712@qq.com> Date: Fri, 30 Dec 2016 15:23:23 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9ajax=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mip-mz-appdownload/mip-mz-appdownload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mip-mz-appdownload/mip-mz-appdownload.js b/mip-mz-appdownload/mip-mz-appdownload.js index 6ce7ffcd6..60f5883c5 100644 --- a/mip-mz-appdownload/mip-mz-appdownload.js +++ b/mip-mz-appdownload/mip-mz-appdownload.js @@ -104,7 +104,7 @@ define(function (require) { var addr = $element.attr('addr'); $.ajax({ method: 'get', - url: 'http://madmin.muzisoft.com/mipappdown.json', + url: 'https://m.muzisoft.com/mipappdown.json', dataType: 'json', success: function (data) { var innerHTML = initAD(ad, aid, addr, data); From cb27f4b64ab4b6226b1d8e2429896ad791eb6ab7 Mon Sep 17 00:00:00 2001 From: pifire <104460712@qq.com> Date: Fri, 30 Dec 2016 16:45:51 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=8E=A8=E8=8D=90app=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mip-mz-addonapp/README.md | 33 +++++++++++++++++++++++ mip-mz-addonapp/mip-mz-addonapp.js | 43 ++++++++++++++++++++++++++++++ mip-mz-addonapp/package.json | 14 ++++++++++ 3 files changed, 90 insertions(+) create mode 100644 mip-mz-addonapp/README.md create mode 100644 mip-mz-addonapp/mip-mz-addonapp.js create mode 100644 mip-mz-addonapp/package.json diff --git a/mip-mz-addonapp/README.md b/mip-mz-addonapp/README.md new file mode 100644 index 000000000..c363f1485 --- /dev/null +++ b/mip-mz-addonapp/README.md @@ -0,0 +1,33 @@ +# mip-mz-addonapp + +mip-mz-addonapp 推荐app下载! + +标题|内容 +----|---- +类型|通用 +所需脚本|http://mipcache.bdstatic.com/static/v1/mip-mz-addonapp/mip-mz-addonapp.js + +## 示例 + +### 推荐app下载! +```html +' + obj.android[presenti].info + '
'; + + '' + obj.android[presenti].info + '
'; } return '' + obj.android[0].ubtnvalue + ''; } @@ -41,9 +41,9 @@ define(function (require) { } // 点击按钮切换下载 function changeDown(aid, addr, androidAD) { - var chk = $('#ckb'); - var yybtext = $('#yybtext'); - var gsdbtn = $('#gsdbtn'); + var chk = document.getElementById('ckb'); + var yybtext = $('.yybtext'); + var gsdbtn = document.getElementById('gsdbtn'); var presenti = 0; for (var i = 0; i < androidAD.length; ++i) { if (!getCookie(androidAD[i].id)) { @@ -51,17 +51,19 @@ define(function (require) { break; } } - if (chk.is(':checked')) { + if (chk.checked) { yybtext.css('color', 'black'); - gsdbtn.attr('href', androidAD[presenti].url); - gsdbtn.text(androidAD[presenti].btnvalue); - yybtext.html(androidAD[presenti].info); + document.querySelector('#down span').innerText = androidAD[presenti].name; + gsdbtn.setAttribute('href', androidAD[presenti].url); + gsdbtn.innerText = androidAD[presenti].btnvalue; + yybtext.innerText = androidAD[presenti].info; } else { yybtext.css('color', 'red'); - gsdbtn.attr('href', checkurl(aid, addr)); - gsdbtn.text(androidAD[presenti].ubtnvalue); - yybtext.html(androidAD[presenti].uinfo); + document.querySelector('#down span').innerText = androidAD[presenti].name; + gsdbtn.setAttribute('href', checkurl(aid, addr)); + gsdbtn.innerText = androidAD[presenti].ubtnvalue; + yybtext.innerText = androidAD[presenti].uinfo; } } // 设置cookie @@ -94,7 +96,7 @@ define(function (require) { } /** - * 构造元素,只会运行一次 + * createdCallback */ customElement.prototype.firstInviewCallback = function () { var element = this.element; @@ -102,37 +104,35 @@ define(function (require) { var ad = $element.attr('ad'); var aid = $element.attr('aid'); var addr = $element.attr('addr'); - $.ajax({ - method: 'get', - url: 'https://m.muzisoft.com/mipappdown.json', - dataType: 'json', - success: function (data) { - var innerHTML = initAD(ad, aid, addr, data); - $('#down ul li').append(innerHTML); - $('#ckb').click(function () { - changeDown(aid, addr, data.android); - }); - // 安卓点击了高速按钮,写cookie - $('#gsdbtn').click(function () { - for (var i = 0; i < data.android.length; ++i) { - var j = (i === data.android.length - 1) ? 0 : i + 1; - if ($('#gsdbtn').attr('presentid') === data.android[i].id) { - setCookie(data.android[j].id, '', 1); - } - else { - setCookie(data.android[j].id, 1, 1); - } + function callback(json) { + var innerHTML = initAD(ad, aid, addr, json); + $('.down ul li').append(innerHTML); + $('.ckb').click(function () { + changeDown(aid, addr, json.android); + }); + // 安卓点击了高速按钮,写cookie + $('.gsdbtn').click(function () { + for (var i = 0; i < json.android.length; ++i) { + var j = (i === json.android.length - 1) ? 0 : i + 1; + if ($('.gsdbtn').attr('presentid') === json.android[i].id) { + setCookie(json.android[j].id, '', 1); } - }); - // 苹果点击了下载 - $('#confirmios').click(function () { - if (confirm(data.ios[0].name)) { - window.location.href = data.ios[0].url; - return false; + else { + setCookie(json.android[j].id, 1, 1); } - }); - }, - error: function () {} + } + }); + // 苹果点击了下载 + $('.confirmios').click(function () { + if (confirm(json.ios[0].name)) { + window.location.href = json.ios[0].url; + return false; + } + }); + } + var myRequest = new Request('https://m.muzisoft.com/mipappdown.json'); + fetch(myRequest).then(function (response) { + return response.json().then(callback); }); }; return customElement; From a1168f36f63d49414e257f724b7102bdc803d9d9 Mon Sep 17 00:00:00 2001 From: pifire <104460712@qq.com> Date: Tue, 3 Jan 2017 15:41:09 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=86=85=E7=BD=AEajax?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mip-mz-addonapp/mip-mz-addonapp.js | 2 +- mip-mz-appdownload/mip-mz-appdownload.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mip-mz-addonapp/mip-mz-addonapp.js b/mip-mz-addonapp/mip-mz-addonapp.js index 6c75c3943..f8b0067b4 100644 --- a/mip-mz-addonapp/mip-mz-addonapp.js +++ b/mip-mz-addonapp/mip-mz-addonapp.js @@ -23,7 +23,7 @@ define(function (require) { /** * createdCallback */ - customElement.prototype.firstInviewCallback = function () { + customElement.prototype.createdCallback = function () { var element = this.element; var $element = $(element); var type = $element.attr('type'); diff --git a/mip-mz-appdownload/mip-mz-appdownload.js b/mip-mz-appdownload/mip-mz-appdownload.js index 12a179420..a34cf00d4 100644 --- a/mip-mz-appdownload/mip-mz-appdownload.js +++ b/mip-mz-appdownload/mip-mz-appdownload.js @@ -98,7 +98,7 @@ define(function (require) { /** * createdCallback */ - customElement.prototype.firstInviewCallback = function () { + customElement.prototype.createdCallback = function () { var element = this.element; var $element = $(element); var ad = $element.attr('ad');