Skip to content

Commit

Permalink
update extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
mip-platform committed Jun 28, 2017
1 parent 3274a09 commit e5eab73
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 15 deletions.
28 changes: 28 additions & 0 deletions mip-233-newsmore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

# mip-233-newsmore

分页加载新闻插件

标题|内容
----|----
类型|业务,广告
支持布局|N/S
所需脚本|https://mipcache.bdstatic.com/static/v1/mip-233-newsmore/mip-233-newsmore.js

## 示例

``` html
<mip-233-newsmore data-page="2" data-maxpage="10" data-filename="162929237">
<div class="news-content mid" showmorebox>
<p>童年是美好的,它犹如一杯加了糖的柠檬汁,酸甜可口,回味无穷。童年的回忆又是美妙的,它就似一幅流光溢彩的画卷,将许许多多有趣的、好玩的事情绘入我的脑海,时常一幕幕的闪现。其中两个小片断,每每想起,内心就会不由自主升起一股浓浓的笑意。
孩提时代,模仿是孩子们的天性,当然我也不例外。我三岁多的时候,经常见爸爸上厕所时不是拿着书就是带着报。我不明白其中的奥妙,但也好去模仿。每次上厕所时,也装模做样的拿着报纸进去,出来的时候又照样拿出来。爸爸发现我的这一举动后,感到很奇怪,因为那时候,我还不认识几个字。他就在我上厕所的时候,偷偷地拉开门,然后就哈哈大笑起来,笑的眼泪都快出来了。因为他看见我老老实实地坐在马桶上,并没有看报读书,而是把报纸放在墙边。原来,这是我观察爸爸后的“模仿秀”。
</p>

<p>俗话说,“一天内,人有三迷”。平常,我的小脑袋瓜也有“断电”的时候。记得有一次早上,起床有点晚,妈妈催促我赶快穿衣吃饭去上学,并叮嘱我穿好毛衣。由于时间紧,我手忙脚乱地穿衣收拾东西。但是,怎么也找不到我的毛衣,急得像热锅上的蚂蚁—团团转。我赶快向妈妈求救,让她帮我也找找毛衣。妈妈走过来后,装作很生气的样子,用手在我的小屁股上拍了一巴掌,说道:“你这孩子怎么搞的,都不长一点脑子,看看自己身上是什么。”我一低头,脸一下子就红到了耳根。原来,毛衣已经在我慌乱时穿在了身上,而我还在“骑驴找驴”。</p>

<p>童年是充满阳光的,它让我享受了世间最好的关爱;童年是五颜六色的,它使我的回忆绚丽多彩;童年又是丰富有趣的,它给了我无穷的快乐。</p>
</div>

<div class="button-div" showmorebtn><span href="javaScript:;" class="more-button">展开加载全文<i></i></span></div>
</mip-233-newsmore>
```
40 changes: 40 additions & 0 deletions mip-233-newsmore/mip-233-newsmore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @file 分页加载新闻插件
* @author 233 程序部
*/
define(function (require) {
var $ = require('zepto');
var customElem = require('customElement').create();
// build 方法,元素插入到文档时执行,仅会执行一次
customElem.prototype.build = function () {
var element = this.element;
var page = parseInt($(element).attr('data-page'), 10);
var maxpage = parseInt($(element).attr('data-maxpage'), 10);
var filename = $(element).attr('data-filename');
function newHtml(obj, filename, page) {
$.ajax({
type: 'get',
url: filename + '-' + page + '.htm?tim=' + new Date().getTime(),
scriptCharset: 'utf-8',
dataType: 'html',
success: function (data) {
if (data) {
$(element).find('.news-content').html($(element).find('.news-content').html() + data);
obj.attr('data-page', ++page);
}
},
error: function (data) {
return false;
}
});
}
$(element).find('.more-button').click(function () {
if (page <= maxpage) {
newHtml($(this), filename, page);
} else {
$(this).remove();
}
});
};
return customElem;
});
10 changes: 10 additions & 0 deletions mip-233-newsmore/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "mip-233-newsmore",
"version": "1.0.0",
"description":"分页加载新闻插件",
"author": {
"name": "newsmore",
"email": "[email protected]",
"url": "www.233.com"
}
}
2 changes: 1 addition & 1 deletion mip-qqtn-cnzz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mip-qqtn-cnzz CNZZ统计

### CNZZ统计
```html
<mip-qqtn-cnzz></mip-qqtn-cnzz>
<mip-qqtn-cnzz token="1257361975"></mip-qqtn-cnzz>
```


126 changes: 112 additions & 14 deletions mip-qqtn-cnzz/mip-qqtn-cnzz.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,121 @@
* @version 1.0
* @copyright 2016 Baidu.com, Inc. All Rights Reserved
*/

define(function (require) {
var $ = require('zepto');

var customElement = require('customElement').create();
function mipcnzz() {
var cnzzprotocol = 'https://';
var cnzzid;
var cnzzsite;
var jsStr = '%3Cspan id=\'cnzz_stat_icon_5932461';
jsStr += cnzzid + '\'%3E%3C/span%3E%3Cscript src=\'';
jsStr += cnzzprotocol;
jsStr += cnzzsite;
jsStr += 's12.cnzz.com/stat.php%3Fid%3D593246';
jsStr += cnzzid;
jsStr += '%26show%3Dpic1\' type=\'text/javascript\'%3E%3C/script%3E';
document.write(unescape(jsStr));
}
customElement.prototype.build = function () {
mipcnzz();
var element = this.element;
var $element = $(element);
var token = element.getAttribute('token');
var setConfig = element.getAttribute('setconfig');
var yczc;
if (token) {
window.yczc = window.yczc || [];
yczc.push([
'_setAccount',
token
]);

// 检测setconfig是否存在
if (setConfig) {
var setCustom = buildArry(decodeURIComponent(setConfig));
yczc.push(setCustom);
}

var cnzzScript = document.createElement('script');
var src = 'https://s12.cnzz.com/z_stat.php?id=' + token
+ '&web_id=' + token;
cnzzScript.setAttribute('language', 'JavaScript');
cnzzScript.src = src;
$element.append($(cnzzScript));
bindEle();
}

};


// 绑定事件
function bindEle() {
var tagBox = document.querySelectorAll('*[data-stats-cnzz-obj]');

for (var index = 0; index < tagBox.length; index++) {
var statusData = tagBox[index].getAttribute('data-stats-cnzz-obj');

// 检测statusData是否存在
if (!statusData) {
return;
}

try {
statusData = JSON.parse(decodeURIComponent(statusData));
} catch (e) {
return;
}
var eventtype = statusData.type;
if (!statusData.data) {
return;
}

var data = buildArry(statusData.data);

if (eventtype !== 'click' && eventtype !== 'mouseup' && eventtype !== 'load') {
// 事件限制到click,mouseup,load(直接触发)
return;
}

if ($(tagBox[index]).hasClass('mip-stats-eventload')) {
return;
}

$(tagBox[index]).addClass('mip-stats-eventload');
var yczc;
if (eventtype === 'load') {
yczc.push(data);
}
else {
tagBox[index].addEventListener(eventtype, function (event) {
var tempData = this.getAttribute('data-stats-cnzz-obj');
if (!tempData) {
return;
}
var statusJson;
try {
statusJson = JSON.parse(decodeURIComponent(tempData));
} catch (e) {
return;
}
if (!statusJson.data) {
return;
}
var attrData = buildArry(statusJson.data);
yczc.push(attrData);
}, false);
}
}
}

// 数据换转
function buildArry(arrayStr) {
if (!arrayStr) {
return;
}

var strArr = arrayStr.slice(1, arrayStr.length - 1).split(',');
var newArray = [];

for (var index = 0; index < strArr.length; index++) {
var item = strArr[index].replace(/(^\s*)|(\s*$)/g, '').replace(/\'/g, '');
if (item === 'false' || item === 'true') {
item = Boolean(item);
}

newArray.push(item);
}
return newArray;
}

return customElement;
});

0 comments on commit e5eab73

Please sign in to comment.