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 27, 2017
1 parent 6bb5300 commit 1d1fb3c
Show file tree
Hide file tree
Showing 7 changed files with 331 additions and 0 deletions.
39 changes: 39 additions & 0 deletions mip-fn-comment-praise/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# mip-fn-comment-praise

<p>蜂鸟网WAP站点赞功能组件</p>

## 示例
```html
<mip-fn-comment-praise class="good-tag" praiseId="123" praiseKindid="1123" praiseNum="1" url="../data/data.json"></mip-fn-comment-praise>
```

标题|内容
----|----
类型|通用
所需脚本|http://mipcache.bdstatic.com/static/v1/mip-fn-comment-praise/mip-fn-comment-praise.js

## 属性
### praiseId
说明:点击评论所属id
必选项:是
类型:Number

### praiseKindid
说明:
必选项:是
类型:Number

### praiseNum
说明:返回地址
必选项:是
类型:字符串
取值范围:Number

### url
说明:接口请求地址
必选项:是
类型:字符串
取值范围:URL



97 changes: 97 additions & 0 deletions mip-fn-comment-praise/mip-fn-comment-praise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* @file mip-fn-praise 组件
* @author wangyan
*/
define(function (require) {
var zepto = require('zepto');
var customElem = require('customElement').create();

// 生命周期 function list,根据组件情况选用,(一般情况选用 build、firstInviewCallback) start
// build 方法,元素插入到文档时执行,仅会执行一次
customElem.prototype.build = function () {
var element = this.element;
var oSpan = document.createElement('span');
var num = element.getAttribute('praisenum');
var id = element.getAttribute('praiseid');
var kindid = element.getAttribute('praiseKindid');
var url = element.getAttribute('url');

if (num === 0) {
num = '';
}
oSpan.innerHTML = num || 0;

element.append(oSpan);

element.onclick = function () {
var oThis = this;
var className = $(this).hasClass('disable-tag');
if (className) {
return false;
}
if (id > 0 && kindid > 0) {
$.ajax({
url: url,
type: 'post',
data: {
'action': 'zan',
'id': id,
'kindid': kindid
},
dataType: 'json',
success: function (data) {
if (data.code === 1) {
var num = oThis.getAttribute('praisenum');
$(oThis).addClass('disable-tag');
if (num === '') {
var num = 1;
} else {
var numNew = parseInt(num, 10) + 1;
}
$(oThis).find('span').html(numNew);
}
},
error: function () {
alert('网络通讯异常,请稍后再试。');
return false;
}
});
} else {
alert('参数错误。');
}
};
};

// 创建元素回调
customElem.prototype.createdCallback = function () {
// console.log('created');
};
// 向文档中插入节点回调
customElem.prototype.attachedCallback = function () {
// console.log('attached');
};
// 从文档中移出节点回调
customElem.prototype.detachedCallback = function () {
// console.log('detached');
};
// 第一次进入可视区回调,只会执行一次,做懒加载,利于网页速度
customElem.prototype.firstInviewCallback = function () {
// console.log('first in viewport');
};
// 进入或离开可视区回调,每次状态变化都会执行
customElem.prototype.viewportCallback = function (isInView) {
// true 进入可视区;false 离开可视区
// console.log(isInView);
};
// 控制viewportCallback、firstInviewCallback是否提前执行
// 轮播图片等可使用此方法提前渲染
customElem.prototype.prerenderAllowed = function () {
// 判断条件,可自定义。返回值为true时,viewportCallback、firstInviewCallback会在元素build后执行
return !!this.isCarouselImg;
};
// 生命周期 function list,根据组件情况选用 end


return customElem;
});

18 changes: 18 additions & 0 deletions mip-fn-comment-praise/mip-fn-comment-praise.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
mip-fn-comment-praise {
float: right;
color: #999999;
font-size: 0.7rem;
line-height: 1.2rem;
}

mip-fn-comment-praise:before {
content: '';
float: right;
width: 0.7rem;
height: 0.7rem;
margin: 0.15rem 0 0 0.5rem;
background: url(data:image/png;
base64,iVBORw0KGgoAAAANSUhEUgAAACkAAAApCAMAAACfvvDEAAAAh1BMVEUAAADW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tbW1tZjonpvAAAALHRSTlMAgHAQoeEv7sFQuQPnhhTy6tx9dko7Ngj40LOskWQeDtXNjFzInJmVQiQabWyJgZEAAAFZSURBVDjLrZTZkoJADEVBEZQGZVFxVHBfJ///fXM7LFaXTpMHzwOkOofQJIDziekxJQq8yuljmRCT+D3iE2JNWtjNC5zRNk5x+rWKKiDa77BZnA9Ws0KtUgdbBDub6UOY6GCCYCkxOZiLzIoDC3MIi9clFmIIT76kZ59FhI5zlMOcWswj8hlHIVFkEXWhgCtNV0Tev94iJHDqipsP9LiF45pzQpotL5cERsze414sZ2TisqhWxuIFb9XY9M5tXyIywI5xjH6Azqwz/zWqq9dyIJ5re78BgqHzmZOuIjDBhmgmMzMkv1uTxxWKTJfHJTCLBNNSApOblDsSE51fDSXmApmrIzE3yPgSsyLdIokZIzFvzNxmFgFRqhpzYDNLFiTmHiPfScw7f1gSc43lR2eGLgj5b6lK1+DGb3tNQB0Bt+SNO3tGLtPzeMNzGlQ8aypmesYRmYxy1Yh//tFS8zL07SgAAAAASUVORK5CYII=) no-repeat 50% 50%; -webkit-background-size: 0.7rem 0.7rem;
background-size: 0.7rem 0.7rem;
}

12 changes: 12 additions & 0 deletions mip-fn-comment-praise/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "mip-fn-comment-praise",
"version": "1.0.0",
"description": "蜂鸟网WAP站点赞",
"author": {
"name": "fn",
"email": "[email protected]"
},
"engines": {
"mip": ">=1.1.0"
}
}
32 changes: 32 additions & 0 deletions mip-fn-show-allarticles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# mip-fn-show-allarticles

<p>蜂鸟网WAP站点击加载更多文章</p>

## 示例
```html
<mip-fn-show-allarticles guanlian = '["5345176","5345177","5345178","5345179"]' articleId = "5344884" dataSrc= "dataSrc"></mip-fn-show-allarticles>
```

标题|内容
----|----
类型|通用
所需脚本|http://mipcache.bdstatic.com/static/v1/mip-fn-show-allarticles/mip-fn-show-allarticles.js

## 属性
### dataSrc
说明:请求地址
必选项:是
类型:字符串
取值范围:URL

### articleid
说明:文章id
必选项:是
类型:字符串

### guanlian
说明:
必选项:是
类型:数组


120 changes: 120 additions & 0 deletions mip-fn-show-allarticles/mip-fn-show-allarticles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* @file mip-fn-show-allarticles 组件
* @author fn
*/
define(function (require) {
var $ = require('zepto');
var customElem = require('customElement').create();

// 生命周期 function list,根据组件情况选用,(一般情况选用 build、firstInviewCallback) start */
// build 方法,元素插入到文档时执行,仅会执行一次
customElem.prototype.build = function () {
// this.element 可取到当前实例对应的 dom 元素
var element = this.element;
var dataSrc = element.getAttribute('dataSrc') || '';
var articleid = element.getAttribute('articleid') || '';
var guanlian = element.getAttribute('guanlian') || '';

if (dataSrc === '' && articleid === '' && guanlian === '') {
return;
}

var showAllLink = '<article id="articleOtherContent" class="article-content"></article>'
+ '<span class="show-all-link" id="more-detail">继续阅读全文</span>'
+ '<div id="load" style="display: none;">'
+ '<mip-img layout="container" width="40" height="40" src="http://m.fengniao.com/icon/images/loading.gif" class="mip-element mip-layout-container mip-img-loaded">'
+ '</mip-img>正在加载...</div>';

$(element).html(showAllLink);

var moreDetail = $(element).find('#more-detail');
var load = $(element).find('#load');
var article = $(element).find('article');

// 加载
var loadMore = true;

guanlian = JSON.parse(guanlian);

var pagesize = 0;
var loadMoreFlg = 0; // 加载第一页的flg
var loadNextPage = 0; // 加载下一页的flg
$(function () {
if (guanlian.length === 0) {
moreDetail.hide();
}
});
moreDetail.click(function () {
load.show();
$(this).hide();
loadMoreFlg = 1;
loadMoreData();
});
window.addEventListener('scroll', nextPage);
// 判断当前是否要加载下一页的内容

function nextPage() {
if (loadNextPage === 1) {
// 内容的高度
var contentHeight = document.getElementById('article-content').offsetHeight;

var scrollTop = 0; // 滚动条到顶部的距离
if (document.documentElement && document.documentElement.scrollTop) {
scrollTop = document.documentElement.scrollTop;
} else if (document.body) {
scrollTop = document.body.scrollTop;
}
if (scrollTop >= contentHeight - 400) {
loadNextPage = 0; // 正在加载下一页,关闭滚动加载
loadMoreData();
} else {
return false;
}
} else {
return false;
}
}
// ajax 加载更多文章

function loadMoreData() {
if (loadMoreFlg === 1) {
if (guanlian.length > 0) {
if (pagesize <= guanlian.length - 1) {
load.show();
$.ajax({
// url: "/ajax/wapajax.php?a=" + Math.random(),
url: dataSrc + '?a=' + Math.random(),
type: 'POST',
data: {
'documentid': guanlian[pagesize],
'scroll': '5'
},
dataType: 'html',
success: function (data) {
if (data) {
article.append(data);
}
pagesize++;
loadNextPage = 1; // 本页已经加载完毕,开启滚动加载flg
load.hide();
},
error: function () {
alert('接收数据失败');
}
});
} else {
// 页面已经加载完 将滚动加载flg设成0
loadNextPage = 0;
load.hide();
return false;
}
} else {
return false;
}
}
}
};
return customElem;

});

13 changes: 13 additions & 0 deletions mip-fn-show-allarticles/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "mip-fn-show-allarticles",
"version": "1.0.0",
"description": "蜂鸟网WAP站点击加载更多文章",
"author": {
"name": "fn",
"email": "[email protected]"
},
"engines": {
"mip": ">=1.1.0"
}
}

0 comments on commit 1d1fb3c

Please sign in to comment.