作者 吴亚瑞

xinjian

要显示太多修改。

为保证性能只显示 33 of 33+ 个文件。

{ // launch.json 配置了启动调试时相关设置,configurations下节点名称可为 app-plus/h5/mp-weixin/mp-baidu/mp-alipay/mp-qq/mp-toutiao/mp-360/
// launchtype项可配置值为local或remote, local代表前端连本地云函数,remote代表前端连云端云函数
"version": "0.0",
"configurations": [{
"type": "uniCloud",
"default": {
"launchtype": "remote"
}
}
]
}
... ...
<script>
export default {
onLaunch: function() {
console.log('App Launch')
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
},
post: function(url, data, method) {
var promise = new Promise((resolve, reject) => {
//init
let that = this,
token = uni.getStorageSync('token'),
header = {
'content-type': 'application/x-www-form-urlencoded;application/json;charset=UTF-8',
'token': token || ''
},
postData;
//网络请求
uni.request({
url: this.globalData.baseUrl + url,
data: data,
method: method,
header: header,
success: function(res) {
console.log(res)
//返回取得的数据
if (res.data.code == 1) {
resolve(res.data);
} else {
reject(res.data);
}
},
fail: function(e) {
reject('网络出错');
uni.hideNavigationBarLoading();
}
});
});
return promise;
},
globalData: {
userInfo: null,
// baseUrl: 'http://yijishen.brofirst.cn/api/',//正式服务器
baseUrl: 'http://yijishen.brofirst.cn/api/', //测试服务器
},
}
</script>
<style>
/*每个页面公共css */
.overflow-2 {
overflow: hidden;
display: -webkit-box;
line-clamp: 2;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
uni-rich-text img {
max-width: 100% !important;
}
</style>
... ...
.content {
width: 100%;
height: 100%;
padding: 32rpx;
box-sizing: border-box;
}
.one {
width: 100%;
height: auto;
display: flex;
padding: 32rpx 0;
box-sizing: border-box;
border-bottom: 1px solid #F1F1F1;
}
.one image {
width: 308rpx;
height: 186rpx;
border-radius: 20rpx;
margin-right: 18rpx;
}
.one .info {
flex: 1;
position: relative;
}
.one .title {
height: 84rpx;
font-size: 28rpx;
font-weight: 600;
text-align: left;
color: #06121e;
}
.one .price {
font-size: 32rpx;
font-family: PingFang SC, PingFang SC-Medium;
font-weight: 600;
margin: 8rpx 0 20rpx 0;
color: #b90038;
line-height: 44rpx;
}
.one .people {
font-size: 24rpx;
font-weight: 400;
color: #8c9198;
line-height: 44rpx;
}
.pingjia {
display: flex;
width: 100%;
height: auto;
padding: 32rpx 0;
box-sizing: border-box;
font-size: 32rpx;
}
.star {
margin-left: 64rpx;
display: flex;
align-items: center;
}
.star image {
margin-right: 12rpx;
width: 32rpx;
}
textarea {
padding: 24rpx 32rpx;
width: 100%;
height: 514rpx;
background: #f9f9f9;
}
.num {
color: #8c9198;
font-size: 24rpx;
position: absolute;
bottom: 12rpx;
right: 32rpx;
}
.footer {
width: 100%;
height: auto;
position: fixed;
bottom: 0;
left: 0;
padding: 10rpx 32rpx;
box-sizing: border-box;
}
.footer .button {
width: 100%;
height: 76rpx;
background: #f6704b;
color: #FFFFFF;
text-align: center;
line-height: 76rpx;
font-size: 28rpx;
border-radius: 36rpx;
}
... ...
.content {
width: 100%;
height: 100%;
padding: 32rpx;
box-sizing: border-box;
}
.one {
width: 100%;
height: auto;
display: flex;
padding: 32rpx 0;
box-sizing: border-box;
border-bottom: 1px solid #F1F1F1;
}
.one image {
width: 308rpx;
height: 186rpx;
border-radius: 20rpx;
margin-right: 12rpx;
}
.one .info {
flex: 1;
}
.one .info {
display: flex;
flex-direction: column;
justify-content: space-between;
}
.one .title {
height: 84rpx;
font-size: 28rpx;
font-weight: 600;
text-align: left;
color: #06121e;
line-height: 40rpx;
}
.one .price {
font-size: 32rpx;
font-weight: 600;
margin: 8rpx 0 0;
color: #b90038;
line-height: 44rpx;
}
.one .people {
font-size: 24rpx;
font-weight: 400;
color: #8c9198;
/* line-height: 44rpx; */
}
.one .assess {
width: 152rpx;
/* height: 52rpx; */
border: 2rpx solid #f6704b;
border-radius: 8rpx;
text-align: center;
line-height: 52rpx;
font-size: 24rpx;
color: #f6704b;
}
.flex_center_between {
display: flex;
justify-content: space-between;
align-items: center;
}
... ...
.container {
width: 100%;
height: 100%;
}
video {
width: 100%;
}
.list {
width: 100%;
height: 92rpx;
background: #f9f9f9;
display: flex;
align-items: center;
font-size: 28rpx;
align-items: 92rpx;
justify-content: space-around;
}
.active {
color: #F6704B;
}
.detail {
width: 100%;
height: auto;
padding: 32rpx;
box-sizing: border-box;
}
.header {
width: 90%;
margin: 0 auto;
padding: 48rpx 0;
box-sizing: border-box;
border-bottom: 1px solid #F1F1F1;
}
.title {
font-size: 36rpx;
font-weight: 600;
text-align: left;
color: #06121e;
line-height: 48rpx;
margin-bottom: 48rpx;
}
.price {
width: 100%;
height: auto;
display: flex;
align-items: center;
font-size: 44rpx;
font-weight: 600;
text-align: left;
color: #b90038;
justify-content: space-between;
}
.people {
font-size: 28rpx;
font-weight: 400;
color: #8c9198;
}
.date {
font-size: 24rpx;
margin-top: 12rpx;
font-weight: 400;
color: #8c9198;
}
.kecheng {
width: 100%;
height: auto;
padding-bottom: 32rpx;
box-sizing: border-box;
border-bottom: 1px solid #F1F1F1;
}
.name {
padding: 48rpx 0;
box-sizing: border-box;
font-size: 32rpx;
font-weight: 600;
text-align: left;
color: #b90038;
display: flex;
align-items: center;
}
.name image {
width: 48rpx;
margin-right: 12rpx;
}
.content {
font-size: 24rpx;
font-weight: 400;
text-align: left;
color: #06121e;
line-height: 40rpx;
}
.pic {
width: 100%;
height: auto;
display: flex;
align-items: center;
flex-wrap: wrap;
justify-content: center;
margin-bottom: 12rpx;
}
.pic .image {
width: 164rpx;
}
.pic .jian {
width: 48rpx;
margin: 12rpx;
}
.pic .xia {
width: 48rpx;
margin: 12rpx;
margin-left: 70%;
}
.teacher {
width: 100%;
height: auto;
display: flex;
}
.teacher image {
width: 144rpx;
margin-right: 56rpx;
}
.teacher .teacherInfo {
flex: 1;
}
.teacher .teaName {
color: #06121e;
font-size: 32rpx;
font-weight: 600;
margin-bottom: 14rpx;
}
.teacher .nichen {
font-size: 24rpx;
margin-bottom: 26rpx;
color: #b90038;
}
.teacher .other {
margin-bottom: 36rpx;
height: 316rpx;
font-size: 28rpx;
font-weight: 400;
text-align: left;
color: #06121e;
line-height: 48rpx;
}
.footer {
width: 100%;
height: auto;
padding: 10rpx 32rpx;
box-sizing: border-box;
position: fixed;
bottom: 0;
left: 0;
background-color: #FFFFFF;
}
.footer .button {
width: 100%;
height: 76rpx;
color: #FFFFFF;
text-align: center;
line-height: 76rpx;
background: #f6704b;
border-radius: 36rpx;
}
.one {
width: 100%;
height: auto;
padding: 16rpx 0;
box-sizing: border-box;
display: flex;
align-items: center;
}
.one image {
width: 216rpx;
height:130rpx;
margin-right: 30rpx;
}
.one .cont {
font-size: 32rpx;
}
.one .wenzi {
width: 216rpx;
height: 130rpx;
background-color: rgba(0, 0, 0, 0.5);
position: absolute;
top: 0;
left: 0;
text-align: center;
line-height: 130rpx;
color: #FFFFFF;
font-size: 32rpx;
}
.assess {
width: 100%;
height: auto;
display: flex;
border-bottom: 1px solid #F1F1F1;
padding: 32rpx 0;
box-sizing: border-box;
}
.assess image {
width: 80rpx;
height: 80rpx;
border-radius: 50%;
margin-right: 12rpx;
}
.star{
display: flex;
}
.star .star_left{
padding-right: 48rpx;
}
.star image{
width: 32rpx;
height: 32rpx;
}
.assess .ping {
flex: 1;
}
.assess .xing {
font-size: 32rpx;
font-weight: 600;
text-align: left;
color: #06121e;
}
.assess .time {
font-size: 24rpx;
margin: 8rpx 0 22rpx 0;
color: #8c9198;
}
.assess .wen {
font-size: 28rpx;
font-family: PingFang SC, PingFang SC-Regular;
font-weight: 400;
text-align: left;
color: #06121e;
line-height: 44rpx;
}
/* 弹框 */
.model {
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
position: fixed;
bottom: 0;
left: 0;
z-index: 99;
}
.model .erweima {
width: 90%;
height: auto;
padding: 32rpx;
box-sizing: border-box;
background-color: #FFFFFF;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 26rpx;
text-align: center;
}
.model .title {
font-size: 40rpx;
font-weight: 700;
text-align: center;
color: #06121e;
margin-top: 106rpx;
margin-bottom: 48rpx;
}
.model image {
width: 400rpx;
margin-bottom: 32rpx;
}
.model .tip {
width: 402rpx;
margin: 0 auto;
height: 100rpx;
font-size: 24rpx;
font-weight: 400;
text-align: center;
color: #06121e;
line-height: 44rpx;
}
.model .button {
width: 518rpx;
height: 86rpx;
background: linear-gradient(135deg, #f38572 1%, #ed4d35);
border-radius: 44rpx;
text-align: center;
line-height: 86rpx;
color: #FFFFFF;
margin: 40rpx auto;
}
.model .other {
color: #8c9198;
font-size: 28rpx;
margin-bottom: 26rpx;
}
.model .cancel {
font-size: 36rpx;
color: #bdc4ce;
position: absolute;
top: 16rpx;
right: 32rpx;
}
... ...
.search {
width: 100%;
height: auto;
padding: 16rpx 32rpx;
box-sizing: border-box;
position: relative;
}
.search input {
width: 100%;
height: 68rpx;
background: #f7f8fa;
border-radius: 4rpx;
line-height: 68rpx;
text-align: center;
}
.search image {
width: 32rpx;
position: absolute;
top: 50%;
left: 45%;
transform: translate(-150%, -50%);
}
.search .font {
color: #c8c9cc;
font-size: 28rpx;
}
/* 轮播图 */
swiper {
width: 100%;
height: 300rpx;
}
swiper image {
width: 100%;
}
/* 列表 */
.list {
width: 100%;
height: 92rpx;
background: #f9f9f9;
display: flex;
align-items: center;
justify-content: space-around;
padding: 20rpx 32rpx 32rpx 32rpx;
box-sizing: border-box;
color: #06121e;
font-size: 28rpx;
}
.list .two {
height: auto;
text-align: center;
position: relative;
}
.list image {
position: absolute;
left: 50%;
top: 90%;
transform: translate(-50%, 0);
width: 98rpx;
margin: 0;
}
.list .active {
font-size: 32rpx;
font-weight: 600;
text-align: center;
color: #f6704b;
}
/* 即将开班 */
.class {
width: 100%;
height: auto;
padding: 32rpx;
box-sizing: border-box;
}
.title {
width: 100%;
padding: 26rpx 0;
box-sizing: border-box;
font-size: 32rpx;
font-weight: 600;
}
.pic {
position: relative;
}
.pic .tip {
position: absolute;
width: 162rpx;
bottom: 8rpx;
left: 0;
}
.pic .begin {
font-size: 24rpx;
font-weight: 300;
text-align: left;
color: #ffffff;
width: 162rpx;
height: 48rpx;
text-align: center;
line-height: 54rpx;
position: absolute;
bottom: 12rpx;
left: 0;
}
.one {
width: 100%;
height: auto;
display: flex;
padding-top: 32rpx;
padding-bottom: 32rpx;
box-sizing: border-box;
border-bottom: 1px solid #F1F1F1;
}
.one image {
width: 300rpx;
height: 186rpx;
border-radius: 20rpx;
margin-right: 16rpx;
}
.one .info {
flex: 1;
}
.one .info {
padding: 15rpx 0;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.one .name {
color: #06121e;
font-size: 28rpx;
font-weight: 600;
}
.one .num {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
margin: 18rpx 0 20rpx 0;
}
.one .price {
font-size: 32rpx;
font-weight: 600;
color: #b90038;
}
.one .people {
font-size: 24rpx;
color: #8c9198;
}
... ...
import Vue from 'vue'
import App from './App'
Vue.config.productionTip = false
// 提交前需要注释 本地调试使用
// const vconsole = require('vconsole')
// Vue.prototype.$vconsole = new vconsole() // 使用vconsole
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()
... ...
{
"name" : "pet-class",
"appid" : "",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "100",
"transformPx" : false,
/* 5+App特有相关 */
"app-plus" : {
"usingComponents" : true,
"nvueCompiler" : "uni-app",
"compilerVersion" : 3,
"splashscreen" : {
"alwaysShowBeforeRender" : true,
"waiting" : true,
"autoclose" : true,
"delay" : 0
},
/* 模块配置 */
"modules" : {},
/* 应用发布信息 */
"distribute" : {
/* android打包配置 */
"android" : {
"permissions" : [
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
]
},
/* ios打包配置 */
"ios" : {},
/* SDK配置 */
"sdkConfigs" : {}
}
},
/* 快应用特有相关 */
"quickapp" : {},
/* 小程序特有相关 */
"mp-weixin" : {
"appid" : "",
"setting" : {
"urlCheck" : false
},
"usingComponents" : true
},
"mp-alipay" : {
"usingComponents" : true
},
"mp-baidu" : {
"usingComponents" : true
},
"mp-toutiao" : {
"usingComponents" : true
},
"uniStatistics" : {
"enable" : false
},
"h5" : {
"devServer" : {
"port" : 80,
"https" : false
},
"domain" : "http://m.yijishen.tvue.brofirst.cn"
}
}
... ...
# jweixin-module
微信JS-SDK
## 安装
### NPM
```shell
npm install jweixin-module --save
```
### UMD
```http
https://unpkg.com/jweixin-module/out/index.js
```
## 使用
```js
var jweixin = require('jweixin-module')
jweixin.ready(function(){
// TODO
});
```
## 完整API
>[微信JS-SDK说明文档](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115)
... ...
! function(e, n) {
"function" == typeof define && (define.amd || define.cmd) ? define(function() {
return n(e)
}) : n(e, !0)
}(window, function(o, e) {
if (!o.jWeixin) {
var n, c = {
config: "preVerifyJSAPI",
onMenuShareTimeline: "menu:share:timeline",
onMenuShareAppMessage: "menu:share:appmessage",
onMenuShareQQ: "menu:share:qq",
onMenuShareWeibo: "menu:share:weiboApp",
onMenuShareQZone: "menu:share:QZone",
previewImage: "imagePreview",
getLocation: "geoLocation",
openProductSpecificView: "openProductViewWithPid",
addCard: "batchAddCard",
openCard: "batchViewCard",
chooseWXPay: "getBrandWCPayRequest",
openEnterpriseRedPacket: "getRecevieBizHongBaoRequest",
startSearchBeacons: "startMonitoringBeacons",
stopSearchBeacons: "stopMonitoringBeacons",
onSearchBeacons: "onBeaconsInRange",
consumeAndShareCard: "consumedShareCard",
openAddress: "editAddress"
},
a = function() {
var e = {};
for (var n in c) e[c[n]] = n;
return e
}(),
i = o.document,
t = i.title,
r = navigator.userAgent.toLowerCase(),
s = navigator.platform.toLowerCase(),
d = !(!s.match("mac") && !s.match("win")),
u = -1 != r.indexOf("wxdebugger"),
l = -1 != r.indexOf("micromessenger"),
p = -1 != r.indexOf("android"),
f = -1 != r.indexOf("iphone") || -1 != r.indexOf("ipad"),
m = (n = r.match(/micromessenger\/(\d+\.\d+\.\d+)/) || r.match(/micromessenger\/(\d+\.\d+)/)) ? n[1] : "",
g = {
initStartTime: L(),
initEndTime: 0,
preVerifyStartTime: 0,
preVerifyEndTime: 0
},
h = {
version: 1,
appId: "",
initTime: 0,
preVerifyTime: 0,
networkType: "",
isPreVerifyOk: 1,
systemType: f ? 1 : p ? 2 : -1,
clientVersion: m,
url: encodeURIComponent(location.href)
},
v = {},
S = {
_completes: []
},
y = {
state: 0,
data: {}
};
O(function() {
g.initEndTime = L()
});
var I = !1,
_ = [],
w = {
config: function(e) {
B("config", v = e);
var t = !1 !== v.check;
O(function() {
if (t) M(c.config, {
verifyJsApiList: C(v.jsApiList),
verifyOpenTagList: C(v.openTagList)
}, function() {
S._complete = function(e) {
g.preVerifyEndTime = L(), y.state = 1, y.data = e
}, S.success = function(e) {
h.isPreVerifyOk = 0
}, S.fail = function(e) {
S._fail ? S._fail(e) : y.state = -1
};
var t = S._completes;
return t.push(function() {
! function() {
if (!(d || u || v.debug || m < "6.0.2" || h.systemType < 0)) {
var i = new Image;
h.appId = v.appId, h.initTime = g.initEndTime - g.initStartTime, h.preVerifyTime = g.preVerifyEndTime -
g.preVerifyStartTime, w.getNetworkType({
isInnerInvoke: !0,
success: function(e) {
h.networkType = e.networkType;
var n = "https://open.weixin.qq.com/sdk/report?v=" + h.version + "&o=" + h.isPreVerifyOk + "&s=" +
h.systemType + "&c=" + h.clientVersion + "&a=" + h.appId + "&n=" + h.networkType + "&i=" + h.initTime +
"&p=" + h.preVerifyTime + "&u=" + h.url;
i.src = n
}
})
}
}()
}), S.complete = function(e) {
for (var n = 0, i = t.length; n < i; ++n) t[n]();
S._completes = []
}, S
}()), g.preVerifyStartTime = L();
else {
y.state = 1;
for (var e = S._completes, n = 0, i = e.length; n < i; ++n) e[n]();
S._completes = []
}
}), w.invoke || (w.invoke = function(e, n, i) {
o.WeixinJSBridge && WeixinJSBridge.invoke(e, x(n), i)
}, w.on = function(e, n) {
o.WeixinJSBridge && WeixinJSBridge.on(e, n)
})
},
ready: function(e) {
0 != y.state ? e() : (S._completes.push(e), !l && v.debug && e())
},
error: function(e) {
m < "6.0.2" || (-1 == y.state ? e(y.data) : S._fail = e)
},
checkJsApi: function(e) {
M("checkJsApi", {
jsApiList: C(e.jsApiList)
}, (e._complete = function(e) {
if (p) {
var n = e.checkResult;
n && (e.checkResult = JSON.parse(n))
}
e = function(e) {
var n = e.checkResult;
for (var i in n) {
var t = a[i];
t && (n[t] = n[i], delete n[i])
}
return e
}(e)
}, e))
},
onMenuShareTimeline: function(e) {
P(c.onMenuShareTimeline, {
complete: function() {
M("shareTimeline", {
title: e.title || t,
desc: e.title || t,
img_url: e.imgUrl || "",
link: e.link || location.href,
type: e.type || "link",
data_url: e.dataUrl || ""
}, e)
}
}, e)
},
onMenuShareAppMessage: function(n) {
P(c.onMenuShareAppMessage, {
complete: function(e) {
"favorite" === e.scene ? M("sendAppMessage", {
title: n.title || t,
desc: n.desc || "",
link: n.link || location.href,
img_url: n.imgUrl || "",
type: n.type || "link",
data_url: n.dataUrl || ""
}) : M("sendAppMessage", {
title: n.title || t,
desc: n.desc || "",
link: n.link || location.href,
img_url: n.imgUrl || "",
type: n.type || "link",
data_url: n.dataUrl || ""
}, n)
}
}, n)
},
onMenuShareQQ: function(e) {
P(c.onMenuShareQQ, {
complete: function() {
M("shareQQ", {
title: e.title || t,
desc: e.desc || "",
img_url: e.imgUrl || "",
link: e.link || location.href
}, e)
}
}, e)
},
onMenuShareWeibo: function(e) {
P(c.onMenuShareWeibo, {
complete: function() {
M("shareWeiboApp", {
title: e.title || t,
desc: e.desc || "",
img_url: e.imgUrl || "",
link: e.link || location.href
}, e)
}
}, e)
},
onMenuShareQZone: function(e) {
P(c.onMenuShareQZone, {
complete: function() {
M("shareQZone", {
title: e.title || t,
desc: e.desc || "",
img_url: e.imgUrl || "",
link: e.link || location.href
}, e)
}
}, e)
},
updateTimelineShareData: function(e) {
M("updateTimelineShareData", {
title: e.title,
link: e.link,
imgUrl: e.imgUrl
}, e)
},
updateAppMessageShareData: function(e) {
M("updateAppMessageShareData", {
title: e.title,
desc: e.desc,
link: e.link,
imgUrl: e.imgUrl
}, e)
},
startRecord: function(e) {
M("startRecord", {}, e)
},
stopRecord: function(e) {
M("stopRecord", {}, e)
},
onVoiceRecordEnd: function(e) {
P("onVoiceRecordEnd", e)
},
playVoice: function(e) {
M("playVoice", {
localId: e.localId
}, e)
},
pauseVoice: function(e) {
M("pauseVoice", {
localId: e.localId
}, e)
},
stopVoice: function(e) {
M("stopVoice", {
localId: e.localId
}, e)
},
onVoicePlayEnd: function(e) {
P("onVoicePlayEnd", e)
},
uploadVoice: function(e) {
M("uploadVoice", {
localId: e.localId,
isShowProgressTips: 0 == e.isShowProgressTips ? 0 : 1
}, e)
},
downloadVoice: function(e) {
M("downloadVoice", {
serverId: e.serverId,
isShowProgressTips: 0 == e.isShowProgressTips ? 0 : 1
}, e)
},
translateVoice: function(e) {
M("translateVoice", {
localId: e.localId,
isShowProgressTips: 0 == e.isShowProgressTips ? 0 : 1
}, e)
},
chooseImage: function(e) {
M("chooseImage", {
scene: "1|2",
count: e.count || 9,
sizeType: e.sizeType || ["original", "compressed"],
sourceType: e.sourceType || ["album", "camera"]
}, (e._complete = function(e) {
if (p) {
var n = e.localIds;
try {
n && (e.localIds = JSON.parse(n))
} catch (e) {}
}
}, e))
},
getLocation: function(e) {},
previewImage: function(e) {
M(c.previewImage, {
current: e.current,
urls: e.urls
}, e)
},
uploadImage: function(e) {
M("uploadImage", {
localId: e.localId,
isShowProgressTips: 0 == e.isShowProgressTips ? 0 : 1
}, e)
},
downloadImage: function(e) {
M("downloadImage", {
serverId: e.serverId,
isShowProgressTips: 0 == e.isShowProgressTips ? 0 : 1
}, e)
},
getLocalImgData: function(e) {
!1 === I ? (I = !0, M("getLocalImgData", {
localId: e.localId
}, (e._complete = function(e) {
if (I = !1, 0 < _.length) {
var n = _.shift();
wx.getLocalImgData(n)
}
}, e))) : _.push(e)
},
getNetworkType: function(e) {
M("getNetworkType", {}, (e._complete = function(e) {
e = function(e) {
var n = e.errMsg;
e.errMsg = "getNetworkType:ok";
var i = e.subtype;
if (delete e.subtype, i) e.networkType = i;
else {
var t = n.indexOf(":"),
o = n.substring(t + 1);
switch (o) {
case "wifi":
case "edge":
case "wwan":
e.networkType = o;
break;
default:
e.errMsg = "getNetworkType:fail"
}
}
return e
}(e)
}, e))
},
openLocation: function(e) {
M("openLocation", {
latitude: e.latitude,
longitude: e.longitude,
name: e.name || "",
address: e.address || "",
scale: e.scale || 28,
infoUrl: e.infoUrl || ""
}, e)
},
getLocation: function(e) {
M(c.getLocation, {
type: (e = e || {}).type || "wgs84"
}, (e._complete = function(e) {
delete e.type
}, e))
},
hideOptionMenu: function(e) {
M("hideOptionMenu", {}, e)
},
showOptionMenu: function(e) {
M("showOptionMenu", {}, e)
},
closeWindow: function(e) {
M("closeWindow", {}, e = e || {})
},
hideMenuItems: function(e) {
M("hideMenuItems", {
menuList: e.menuList
}, e)
},
showMenuItems: function(e) {
M("showMenuItems", {
menuList: e.menuList
}, e)
},
hideAllNonBaseMenuItem: function(e) {
M("hideAllNonBaseMenuItem", {}, e)
},
showAllNonBaseMenuItem: function(e) {
M("showAllNonBaseMenuItem", {}, e)
},
scanQRCode: function(e) {
M("scanQRCode", {
needResult: (e = e || {}).needResult || 0,
scanType: e.scanType || ["qrCode", "barCode"]
}, (e._complete = function(e) {
if (f) {
var n = e.resultStr;
if (n) {
var i = JSON.parse(n);
e.resultStr = i && i.scan_code && i.scan_code.scan_result
}
}
}, e))
},
openAddress: function(e) {
M(c.openAddress, {}, (e._complete = function(e) {
e = function(e) {
return e.postalCode = e.addressPostalCode, delete e.addressPostalCode, e.provinceName = e.proviceFirstStageName,
delete e.proviceFirstStageName, e.cityName = e.addressCitySecondStageName, delete e.addressCitySecondStageName,
e.countryName = e.addressCountiesThirdStageName, delete e.addressCountiesThirdStageName, e.detailInfo = e
.addressDetailInfo, delete e.addressDetailInfo, e
}(e)
}, e))
},
openProductSpecificView: function(e) {
M(c.openProductSpecificView, {
pid: e.productId,
view_type: e.viewType || 0,
ext_info: e.extInfo
}, e)
},
addCard: function(e) {
for (var n = e.cardList, i = [], t = 0, o = n.length; t < o; ++t) {
var r = n[t],
a = {
card_id: r.cardId,
card_ext: r.cardExt
};
i.push(a)
}
M(c.addCard, {
card_list: i
}, (e._complete = function(e) {
var n = e.card_list;
if (n) {
for (var i = 0, t = (n = JSON.parse(n)).length; i < t; ++i) {
var o = n[i];
o.cardId = o.card_id, o.cardExt = o.card_ext, o.isSuccess = !!o.is_succ, delete o.card_id, delete o.card_ext,
delete o.is_succ
}
e.cardList = n, delete e.card_list
}
}, e))
},
chooseCard: function(e) {
M("chooseCard", {
app_id: v.appId,
location_id: e.shopId || "",
sign_type: e.signType || "SHA1",
card_id: e.cardId || "",
card_type: e.cardType || "",
card_sign: e.cardSign,
time_stamp: e.timestamp + "",
nonce_str: e.nonceStr
}, (e._complete = function(e) {
e.cardList = e.choose_card_info, delete e.choose_card_info
}, e))
},
openCard: function(e) {
for (var n = e.cardList, i = [], t = 0, o = n.length; t < o; ++t) {
var r = n[t],
a = {
card_id: r.cardId,
code: r.code
};
i.push(a)
}
M(c.openCard, {
card_list: i
}, e)
},
consumeAndShareCard: function(e) {
M(c.consumeAndShareCard, {
consumedCardId: e.cardId,
consumedCode: e.code
}, e)
},
chooseWXPay: function(e) {
M(c.chooseWXPay, V(e), e)
},
openEnterpriseRedPacket: function(e) {
M(c.openEnterpriseRedPacket, V(e), e)
},
startSearchBeacons: function(e) {
M(c.startSearchBeacons, {
ticket: e.ticket
}, e)
},
stopSearchBeacons: function(e) {
M(c.stopSearchBeacons, {}, e)
},
onSearchBeacons: function(e) {
P(c.onSearchBeacons, e)
},
openEnterpriseChat: function(e) {
M("openEnterpriseChat", {
useridlist: e.userIds,
chatname: e.groupName
}, e)
},
launchMiniProgram: function(e) {
M("launchMiniProgram", {
targetAppId: e.targetAppId,
path: function(e) {
if ("string" == typeof e && 0 < e.length) {
var n = e.split("?")[0],
i = e.split("?")[1];
return n += ".html", void 0 !== i ? n + "?" + i : n
}
}(e.path),
envVersion: e.envVersion
}, e)
},
openBusinessView: function(e) {
M("openBusinessView", {
businessType: e.businessType,
queryString: e.queryString || "",
envVersion: e.envVersion
}, (e._complete = function(n) {
if (p) {
var e = n.extraData;
if (e) try {
n.extraData = JSON.parse(e)
} catch (e) {
n.extraData = {}
}
}
}, e))
},
miniProgram: {
navigateBack: function(e) {
e = e || {}, O(function() {
M("invokeMiniProgramAPI", {
name: "navigateBack",
arg: {
delta: e.delta || 1
}
}, e)
})
},
navigateTo: function(e) {
O(function() {
M("invokeMiniProgramAPI", {
name: "navigateTo",
arg: {
url: e.url
}
}, e)
})
},
redirectTo: function(e) {
O(function() {
M("invokeMiniProgramAPI", {
name: "redirectTo",
arg: {
url: e.url
}
}, e)
})
},
switchTab: function(e) {
O(function() {
M("invokeMiniProgramAPI", {
name: "switchTab",
arg: {
url: e.url
}
}, e)
})
},
reLaunch: function(e) {
O(function() {
M("invokeMiniProgramAPI", {
name: "reLaunch",
arg: {
url: e.url
}
}, e)
})
},
postMessage: function(e) {
O(function() {
M("invokeMiniProgramAPI", {
name: "postMessage",
arg: e.data || {}
}, e)
})
},
getEnv: function(e) {
O(function() {
e({
miniprogram: "miniprogram" === o.__wxjs_environment
})
})
}
}
},
T = 1,
k = {};
return i.addEventListener("error", function(e) {
if (!p) {
var n = e.target,
i = n.tagName,
t = n.src;
if ("IMG" == i || "VIDEO" == i || "AUDIO" == i || "SOURCE" == i)
if (-1 != t.indexOf("wxlocalresource://")) {
e.preventDefault(), e.stopPropagation();
var o = n["wx-id"];
if (o || (o = T++, n["wx-id"] = o), k[o]) return;
k[o] = !0, wx.ready(function() {
wx.getLocalImgData({
localId: t,
success: function(e) {
n.src = e.localData
}
})
})
}
}
}, !0), i.addEventListener("load", function(e) {
if (!p) {
var n = e.target,
i = n.tagName;
n.src;
if ("IMG" == i || "VIDEO" == i || "AUDIO" == i || "SOURCE" == i) {
var t = n["wx-id"];
t && (k[t] = !1)
}
}
}, !0), e && (o.wx = o.jWeixin = w), w
}
function M(n, e, i) {
o.WeixinJSBridge ? WeixinJSBridge.invoke(n, x(e), function(e) {
A(n, e, i)
}) : B(n, i)
}
function P(n, i, t) {
o.WeixinJSBridge ? WeixinJSBridge.on(n, function(e) {
t && t.trigger && t.trigger(e), A(n, e, i)
}) : B(n, t || i)
}
function x(e) {
return (e = e || {}).appId = v.appId, e.verifyAppId = v.appId, e.verifySignType = "sha1", e.verifyTimestamp = v.timestamp +
"", e.verifyNonceStr = v.nonceStr, e.verifySignature = v.signature, e
}
function V(e) {
return {
timeStamp: e.timestamp + "",
nonceStr: e.nonceStr,
package: e.package,
paySign: e.paySign,
signType: e.signType || "SHA1"
}
}
function A(e, n, i) {
"openEnterpriseChat" != e && "openBusinessView" !== e || (n.errCode = n.err_code), delete n.err_code, delete n.err_desc,
delete n.err_detail;
var t = n.errMsg;
t || (t = n.err_msg, delete n.err_msg, t = function(e, n) {
var i = e,
t = a[i];
t && (i = t);
var o = "ok";
if (n) {
var r = n.indexOf(":");
"confirm" == (o = n.substring(r + 1)) && (o = "ok"), "failed" == o && (o = "fail"), -1 != o.indexOf("failed_") &&
(o = o.substring(7)), -1 != o.indexOf("fail_") && (o = o.substring(5)), "access denied" != (o = (o = o.replace(
/_/g, " ")).toLowerCase()) && "no permission to execute" != o || (o = "permission denied"), "config" == i &&
"function not exist" == o && (o = "ok"), "" == o && (o = "fail")
}
return n = i + ":" + o
}(e, t), n.errMsg = t), (i = i || {})._complete && (i._complete(n), delete i._complete), t = n.errMsg || "", v.debug &&
!i.isInnerInvoke && alert(JSON.stringify(n));
var o = t.indexOf(":");
switch (t.substring(o + 1)) {
case "ok":
i.success && i.success(n);
break;
case "cancel":
i.cancel && i.cancel(n);
break;
default:
i.fail && i.fail(n)
}
i.complete && i.complete(n)
}
function C(e) {
if (e) {
for (var n = 0, i = e.length; n < i; ++n) {
var t = e[n],
o = c[t];
o && (e[n] = o)
}
return e
}
}
function B(e, n) {
if (!(!v.debug || n && n.isInnerInvoke)) {
var i = a[e];
i && (e = i), n && n._complete && delete n._complete, console.log('"' + e + '",', n || "")
}
}
function L() {
return (new Date).getTime()
}
function O(e) {
l && (o.WeixinJSBridge ? e() : i.addEventListener && i.addEventListener("WeixinJSBridgeReady", e, !1))
}
});
... ...
{
"_from": "jweixin-module",
"_id": "jweixin-module@1.6.0",
"_inBundle": false,
"_integrity": "sha512-dGk9cf+ipipHmtzYmKZs5B2toX+p4hLyllGLF6xuC8t+B05oYxd8fYoaRz0T30U2n3RUv8a4iwvjhA+OcYz52w==",
"_location": "/jweixin-module",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "jweixin-module",
"name": "jweixin-module",
"escapedName": "jweixin-module",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/jweixin-module/-/jweixin-module-1.6.0.tgz",
"_shasum": "4a7ea614083e3c9c3f49e2fdc2bb882cfa58dfcd",
"_spec": "jweixin-module",
"_where": "C:\\Users\\PC\\Desktop\\pet-class",
"author": {
"name": "Shengqiang Guo"
},
"bugs": {
"url": "https://github.com/zhetengbiji/jweixin-module/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "微信JS-SDK",
"devDependencies": {},
"homepage": "https://github.com/zhetengbiji/jweixin-module#readme",
"keywords": [
"wxjssdk",
"weixin",
"jweixin",
"wechat",
"jssdk",
"wx"
],
"license": "ISC",
"main": "lib/index.js",
"name": "jweixin-module",
"repository": {
"type": "git",
"url": "git+https://github.com/zhetengbiji/jweixin-module.git"
},
"scripts": {},
"version": "1.6.0"
}
... ...
1.0.3 / 2017-07-25
==================
* With the posibility of the MutationEvent being deprecated, check if exists prior to usage (#8)
1.0.2 / 2015-07-07
==================
* fix delete as a reserved word issue on IE8 (#4, @kaesonho)
1.0.1 / 2015-03-10
==================
* package: re-add the "component" section
* package: use public git URL
1.0.0 / 2014-12-09
==================
* Move away from `component.json`; into webmodules organization.
* Add a MutationObserver polyfill for IE9-10. (written by the Polymer contributors)
* Change license from MIT to BSD to match the Polymer polyfill license.
0.0.1 / 2013-02-09
==================
* Initial release
... ...
// Copyright (c) 2014 Automattic Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Automattic Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Copyright (c) 2012 The Polymer Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
... ...
# mutation-observer
Exposes the native `MutationObserver` API provided by the browser, or a polyfill based on mutation events. (For compatibility with IE9-10.)
MutationObserver polyfill by the [Polymer Project](https://www.polymer-project.org/).
## Installation
```bash
$ npm install mutation-observer
```
## API
```javascript
var MutationObserver = require('mutation-observer');
```
## License
BSD (See LICENSE file)
\ No newline at end of file
... ...
var MutationObserver = window.MutationObserver
|| window.WebKitMutationObserver
|| window.MozMutationObserver;
/*
* Copyright 2012 The Polymer Authors. All rights reserved.
* Use of this source code is goverened by a BSD-style
* license that can be found in the LICENSE file.
*/
var WeakMap = window.WeakMap;
if (typeof WeakMap === 'undefined') {
var defineProperty = Object.defineProperty;
var counter = Date.now() % 1e9;
WeakMap = function() {
this.name = '__st' + (Math.random() * 1e9 >>> 0) + (counter++ + '__');
};
WeakMap.prototype = {
set: function(key, value) {
var entry = key[this.name];
if (entry && entry[0] === key)
entry[1] = value;
else
defineProperty(key, this.name, {value: [key, value], writable: true});
return this;
},
get: function(key) {
var entry;
return (entry = key[this.name]) && entry[0] === key ?
entry[1] : undefined;
},
'delete': function(key) {
var entry = key[this.name];
if (!entry) return false;
var hasValue = entry[0] === key;
entry[0] = entry[1] = undefined;
return hasValue;
},
has: function(key) {
var entry = key[this.name];
if (!entry) return false;
return entry[0] === key;
}
};
}
var registrationsTable = new WeakMap();
// We use setImmediate or postMessage for our future callback.
var setImmediate = window.msSetImmediate;
// Use post message to emulate setImmediate.
if (!setImmediate) {
var setImmediateQueue = [];
var sentinel = String(Math.random());
window.addEventListener('message', function(e) {
if (e.data === sentinel) {
var queue = setImmediateQueue;
setImmediateQueue = [];
queue.forEach(function(func) {
func();
});
}
});
setImmediate = function(func) {
setImmediateQueue.push(func);
window.postMessage(sentinel, '*');
};
}
// This is used to ensure that we never schedule 2 callas to setImmediate
var isScheduled = false;
// Keep track of observers that needs to be notified next time.
var scheduledObservers = [];
/**
* Schedules |dispatchCallback| to be called in the future.
* @param {MutationObserver} observer
*/
function scheduleCallback(observer) {
scheduledObservers.push(observer);
if (!isScheduled) {
isScheduled = true;
setImmediate(dispatchCallbacks);
}
}
function wrapIfNeeded(node) {
return window.ShadowDOMPolyfill &&
window.ShadowDOMPolyfill.wrapIfNeeded(node) ||
node;
}
function dispatchCallbacks() {
// http://dom.spec.whatwg.org/#mutation-observers
isScheduled = false; // Used to allow a new setImmediate call above.
var observers = scheduledObservers;
scheduledObservers = [];
// Sort observers based on their creation UID (incremental).
observers.sort(function(o1, o2) {
return o1.uid_ - o2.uid_;
});
var anyNonEmpty = false;
observers.forEach(function(observer) {
// 2.1, 2.2
var queue = observer.takeRecords();
// 2.3. Remove all transient registered observers whose observer is mo.
removeTransientObserversFor(observer);
// 2.4
if (queue.length) {
observer.callback_(queue, observer);
anyNonEmpty = true;
}
});
// 3.
if (anyNonEmpty)
dispatchCallbacks();
}
function removeTransientObserversFor(observer) {
observer.nodes_.forEach(function(node) {
var registrations = registrationsTable.get(node);
if (!registrations)
return;
registrations.forEach(function(registration) {
if (registration.observer === observer)
registration.removeTransientObservers();
});
});
}
/**
* This function is used for the "For each registered observer observer (with
* observer's options as options) in target's list of registered observers,
* run these substeps:" and the "For each ancestor ancestor of target, and for
* each registered observer observer (with options options) in ancestor's list
* of registered observers, run these substeps:" part of the algorithms. The
* |options.subtree| is checked to ensure that the callback is called
* correctly.
*
* @param {Node} target
* @param {function(MutationObserverInit):MutationRecord} callback
*/
function forEachAncestorAndObserverEnqueueRecord(target, callback) {
for (var node = target; node; node = node.parentNode) {
var registrations = registrationsTable.get(node);
if (registrations) {
for (var j = 0; j < registrations.length; j++) {
var registration = registrations[j];
var options = registration.options;
// Only target ignores subtree.
if (node !== target && !options.subtree)
continue;
var record = callback(options);
if (record)
registration.enqueue(record);
}
}
}
}
var uidCounter = 0;
/**
* The class that maps to the DOM MutationObserver interface.
* @param {Function} callback.
* @constructor
*/
function JsMutationObserver(callback) {
this.callback_ = callback;
this.nodes_ = [];
this.records_ = [];
this.uid_ = ++uidCounter;
}
JsMutationObserver.prototype = {
observe: function(target, options) {
target = wrapIfNeeded(target);
// 1.1
if (!options.childList && !options.attributes && !options.characterData ||
// 1.2
options.attributeOldValue && !options.attributes ||
// 1.3
options.attributeFilter && options.attributeFilter.length &&
!options.attributes ||
// 1.4
options.characterDataOldValue && !options.characterData) {
throw new SyntaxError();
}
var registrations = registrationsTable.get(target);
if (!registrations)
registrationsTable.set(target, registrations = []);
// 2
// If target's list of registered observers already includes a registered
// observer associated with the context object, replace that registered
// observer's options with options.
var registration;
for (var i = 0; i < registrations.length; i++) {
if (registrations[i].observer === this) {
registration = registrations[i];
registration.removeListeners();
registration.options = options;
break;
}
}
// 3.
// Otherwise, add a new registered observer to target's list of registered
// observers with the context object as the observer and options as the
// options, and add target to context object's list of nodes on which it
// is registered.
if (!registration) {
registration = new Registration(this, target, options);
registrations.push(registration);
this.nodes_.push(target);
}
registration.addListeners();
},
disconnect: function() {
this.nodes_.forEach(function(node) {
var registrations = registrationsTable.get(node);
for (var i = 0; i < registrations.length; i++) {
var registration = registrations[i];
if (registration.observer === this) {
registration.removeListeners();
registrations.splice(i, 1);
// Each node can only have one registered observer associated with
// this observer.
break;
}
}
}, this);
this.records_ = [];
},
takeRecords: function() {
var copyOfRecords = this.records_;
this.records_ = [];
return copyOfRecords;
}
};
/**
* @param {string} type
* @param {Node} target
* @constructor
*/
function MutationRecord(type, target) {
this.type = type;
this.target = target;
this.addedNodes = [];
this.removedNodes = [];
this.previousSibling = null;
this.nextSibling = null;
this.attributeName = null;
this.attributeNamespace = null;
this.oldValue = null;
}
function copyMutationRecord(original) {
var record = new MutationRecord(original.type, original.target);
record.addedNodes = original.addedNodes.slice();
record.removedNodes = original.removedNodes.slice();
record.previousSibling = original.previousSibling;
record.nextSibling = original.nextSibling;
record.attributeName = original.attributeName;
record.attributeNamespace = original.attributeNamespace;
record.oldValue = original.oldValue;
return record;
};
// We keep track of the two (possibly one) records used in a single mutation.
var currentRecord, recordWithOldValue;
/**
* Creates a record without |oldValue| and caches it as |currentRecord| for
* later use.
* @param {string} oldValue
* @return {MutationRecord}
*/
function getRecord(type, target) {
return currentRecord = new MutationRecord(type, target);
}
/**
* Gets or creates a record with |oldValue| based in the |currentRecord|
* @param {string} oldValue
* @return {MutationRecord}
*/
function getRecordWithOldValue(oldValue) {
if (recordWithOldValue)
return recordWithOldValue;
recordWithOldValue = copyMutationRecord(currentRecord);
recordWithOldValue.oldValue = oldValue;
return recordWithOldValue;
}
function clearRecords() {
currentRecord = recordWithOldValue = undefined;
}
/**
* @param {MutationRecord} record
* @return {boolean} Whether the record represents a record from the current
* mutation event.
*/
function recordRepresentsCurrentMutation(record) {
return record === recordWithOldValue || record === currentRecord;
}
/**
* Selects which record, if any, to replace the last record in the queue.
* This returns |null| if no record should be replaced.
*
* @param {MutationRecord} lastRecord
* @param {MutationRecord} newRecord
* @param {MutationRecord}
*/
function selectRecord(lastRecord, newRecord) {
if (lastRecord === newRecord)
return lastRecord;
// Check if the the record we are adding represents the same record. If
// so, we keep the one with the oldValue in it.
if (recordWithOldValue && recordRepresentsCurrentMutation(lastRecord))
return recordWithOldValue;
return null;
}
/**
* Class used to represent a registered observer.
* @param {MutationObserver} observer
* @param {Node} target
* @param {MutationObserverInit} options
* @constructor
*/
function Registration(observer, target, options) {
this.observer = observer;
this.target = target;
this.options = options;
this.transientObservedNodes = [];
}
Registration.prototype = {
enqueue: function(record) {
var records = this.observer.records_;
var length = records.length;
// There are cases where we replace the last record with the new record.
// For example if the record represents the same mutation we need to use
// the one with the oldValue. If we get same record (this can happen as we
// walk up the tree) we ignore the new record.
if (records.length > 0) {
var lastRecord = records[length - 1];
var recordToReplaceLast = selectRecord(lastRecord, record);
if (recordToReplaceLast) {
records[length - 1] = recordToReplaceLast;
return;
}
} else {
scheduleCallback(this.observer);
}
records[length] = record;
},
addListeners: function() {
this.addListeners_(this.target);
},
addListeners_: function(node) {
var options = this.options;
if (options.attributes)
node.addEventListener('DOMAttrModified', this, true);
if (options.characterData)
node.addEventListener('DOMCharacterDataModified', this, true);
if (options.childList)
node.addEventListener('DOMNodeInserted', this, true);
if (options.childList || options.subtree)
node.addEventListener('DOMNodeRemoved', this, true);
},
removeListeners: function() {
this.removeListeners_(this.target);
},
removeListeners_: function(node) {
var options = this.options;
if (options.attributes)
node.removeEventListener('DOMAttrModified', this, true);
if (options.characterData)
node.removeEventListener('DOMCharacterDataModified', this, true);
if (options.childList)
node.removeEventListener('DOMNodeInserted', this, true);
if (options.childList || options.subtree)
node.removeEventListener('DOMNodeRemoved', this, true);
},
/**
* Adds a transient observer on node. The transient observer gets removed
* next time we deliver the change records.
* @param {Node} node
*/
addTransientObserver: function(node) {
// Don't add transient observers on the target itself. We already have all
// the required listeners set up on the target.
if (node === this.target)
return;
this.addListeners_(node);
this.transientObservedNodes.push(node);
var registrations = registrationsTable.get(node);
if (!registrations)
registrationsTable.set(node, registrations = []);
// We know that registrations does not contain this because we already
// checked if node === this.target.
registrations.push(this);
},
removeTransientObservers: function() {
var transientObservedNodes = this.transientObservedNodes;
this.transientObservedNodes = [];
transientObservedNodes.forEach(function(node) {
// Transient observers are never added to the target.
this.removeListeners_(node);
var registrations = registrationsTable.get(node);
for (var i = 0; i < registrations.length; i++) {
if (registrations[i] === this) {
registrations.splice(i, 1);
// Each node can only have one registered observer associated with
// this observer.
break;
}
}
}, this);
},
handleEvent: function(e) {
// Stop propagation since we are managing the propagation manually.
// This means that other mutation events on the page will not work
// correctly but that is by design.
e.stopImmediatePropagation();
switch (e.type) {
case 'DOMAttrModified':
// http://dom.spec.whatwg.org/#concept-mo-queue-attributes
var name = e.attrName;
var namespace = e.relatedNode.namespaceURI;
var target = e.target;
// 1.
var record = new getRecord('attributes', target);
record.attributeName = name;
record.attributeNamespace = namespace;
// 2.
var oldValue = null;
if (!(typeof MutationEvent !== 'undefined' && e.attrChange === MutationEvent.ADDITION))
oldValue = e.prevValue;
forEachAncestorAndObserverEnqueueRecord(target, function(options) {
// 3.1, 4.2
if (!options.attributes)
return;
// 3.2, 4.3
if (options.attributeFilter && options.attributeFilter.length &&
options.attributeFilter.indexOf(name) === -1 &&
options.attributeFilter.indexOf(namespace) === -1) {
return;
}
// 3.3, 4.4
if (options.attributeOldValue)
return getRecordWithOldValue(oldValue);
// 3.4, 4.5
return record;
});
break;
case 'DOMCharacterDataModified':
// http://dom.spec.whatwg.org/#concept-mo-queue-characterdata
var target = e.target;
// 1.
var record = getRecord('characterData', target);
// 2.
var oldValue = e.prevValue;
forEachAncestorAndObserverEnqueueRecord(target, function(options) {
// 3.1, 4.2
if (!options.characterData)
return;
// 3.2, 4.3
if (options.characterDataOldValue)
return getRecordWithOldValue(oldValue);
// 3.3, 4.4
return record;
});
break;
case 'DOMNodeRemoved':
this.addTransientObserver(e.target);
// Fall through.
case 'DOMNodeInserted':
// http://dom.spec.whatwg.org/#concept-mo-queue-childlist
var target = e.relatedNode;
var changedNode = e.target;
var addedNodes, removedNodes;
if (e.type === 'DOMNodeInserted') {
addedNodes = [changedNode];
removedNodes = [];
} else {
addedNodes = [];
removedNodes = [changedNode];
}
var previousSibling = changedNode.previousSibling;
var nextSibling = changedNode.nextSibling;
// 1.
var record = getRecord('childList', target);
record.addedNodes = addedNodes;
record.removedNodes = removedNodes;
record.previousSibling = previousSibling;
record.nextSibling = nextSibling;
forEachAncestorAndObserverEnqueueRecord(target, function(options) {
// 2.1, 3.2
if (!options.childList)
return;
// 2.2, 3.3
return record;
});
}
clearRecords();
}
};
if (!MutationObserver) {
MutationObserver = JsMutationObserver;
}
module.exports = MutationObserver;
... ...
{
"_from": "mutation-observer@^1.0.3",
"_id": "mutation-observer@1.0.3",
"_inBundle": false,
"_integrity": "sha512-M/O/4rF2h776hV7qGMZUH3utZLO/jK7p8rnNgGkjKUw8zCGjRQPxB8z6+5l8+VjRUQ3dNYu4vjqXYLr+U8ZVNA==",
"_location": "/mutation-observer",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "mutation-observer@^1.0.3",
"name": "mutation-observer",
"escapedName": "mutation-observer",
"rawSpec": "^1.0.3",
"saveSpec": null,
"fetchSpec": "^1.0.3"
},
"_requiredBy": [
"/vconsole"
],
"_resolved": "https://registry.npmjs.org/mutation-observer/-/mutation-observer-1.0.3.tgz",
"_shasum": "42e9222b101bca82e5ba9d5a7acf4a14c0f263d0",
"_spec": "mutation-observer@^1.0.3",
"_where": "C:\\Users\\PC\\Desktop\\pet-class\\node_modules\\vconsole",
"bugs": {
"url": "https://github.com/webmodules/mutation-observer/issues"
},
"bundleDependencies": false,
"component": {
"scripts": {
"mutation-observer/index.js": "index.js"
}
},
"dependencies": {},
"deprecated": false,
"description": "Exposes the `MutationObserver` API, or a polyfill based on mutation events for IE 9-10.",
"homepage": "https://github.com/webmodules/mutation-observer#readme",
"name": "mutation-observer",
"repository": {
"type": "git",
"url": "git://github.com/webmodules/mutation-observer.git"
},
"tags": [
"polyfill",
"webmodule",
"mutation",
"observer",
"browser"
],
"version": "1.0.3"
}
... ...
node_modules
\ No newline at end of file
... ...
language: node_js
node_js:
- "0.10"
notification:
email:
on_success: never
on_failure: always
... ...
jshint:
jshint src/transition-end.js
minify:
uglifyjs src/transition-end.js --compress --mangle --output src/transition-end.min.js
... ...
# TransitionEnd
[![Build
Status](https://travis-ci.org/EvandroLG/transitionEnd.svg?branch=master)](https://travis-ci.org/EvandroLG/transitionEnd)
TransitionEnd is an agnostic and cross-browser library to work with event transitionend.
## Browser Support
![Chrome](https://raw.github.com/alrra/browser-logos/master/chrome/chrome_48x48.png) |
![Firefox](https://raw.github.com/alrra/browser-logos/master/firefox/firefox_48x48.png) |
![IE](https://raw.github.com/alrra/browser-logos/master/internet-explorer/internet-explorer_48x48.png) |
![Opera](https://raw.github.com/alrra/browser-logos/master/opera/opera_48x48.png) |
![Safari](https://raw.github.com/alrra/browser-logos/master/safari/safari_48x48.png)
--- | --- | --- | --- | --- |
1.0+ ✔ | 4.0+ ✔ | 10+ ✔ | 10.5 ✔ | 3.2+ ✔ |
## Methods
* transitionEnd(element).<code>bind(callback)</code>
* transitionEnd(element).<code>unbind()</code>
* transitionEnd(element).<code>whichTransitionEnd()</code>
**Examples**
```js
var box = $("#box"); // or document.getElementById("box")
var foo = $("#foo");
transitionEnd(box).bind(function(){
foo.addClass("on");
transitionEnd(box).unbind();
});
var transition = transitionEnd(box).whichTransitionEnd(); // return for example "webkitTransitionEnd"
```
... ...
{
"name": "transitionEnd",
"version": "1.0.2",
"homepage": "https://github.com/EvandroLG/transitionEnd",
"authors": [
"evandrolg"
],
"description": "TransitionEnd is a agnostic lib cross-browser to work with event transitionend.",
"main": "src/transition-end.min.js",
"keywords": [
"transitionEnd",
"js"
],
"ignore": [
"**/.*",
"test"
],
"license": "MIT"
}
... ...
*{
margin: 0;
padding: 0;
font: 12px arial, verdana, sans-serif;
color: #000;
}
div{
transition: opacity 1s;
-moz-transition: opacity 1s;
-webkit-transition: opacity 1s;
-o-transition: opacity 1s;
opacity: 0;
float: left;
width: 300px;
}
div.on{
opacity: 1;
}
#texto-01{
margin-right: 20px;
}
\ No newline at end of file
... ...
<!DOCTYPE html>
<html>
<head>
<title>Example - TransitionEnd</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/example.css">
</head>
<body>
<div id="texto-01">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam cursus. Morbi ut mi. Nullam enim leo, egestas id, condimentum at, laoreet mattis, massa. Sed eleifend nonummy diam. Praesent mauris ante, elementum et, bibendum at, posuere sit amet, nibh. Duis tincidunt lectus quis dui viverra vestibulum. Suspendisse vulputate aliquam dui. Nulla elementum dui ut augue. Aliquam vehicula mi at mauris. Maecenas placerat, nisl at consequat rhoncus, sem nunc gravida justo, quis eleifend arcu velit quis lacus. Morbi magna magna, tincidunt a, mattis non, imperdiet vitae, tellus. Sed odio est, auctor ac, sollicitudin in, consequat vitae, orci. Fusce id felis. Vivamus sollicitudin metus eget eros.
</div>
<div id="texto-02">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nam cursus. Morbi ut mi. Nullam enim leo, egestas id, condimentum at, laoreet mattis, massa. Sed eleifend nonummy diam. Praesent mauris ante, elementum et, bibendum at, posuere sit amet, nibh. Duis tincidunt lectus quis dui viverra vestibulum. Suspendisse vulputate aliquam dui. Nulla elementum dui ut augue. Aliquam vehicula mi at mauris. Maecenas placerat, nisl at consequat rhoncus, sem nunc gravida justo, quis eleifend arcu velit quis lacus. Morbi magna magna, tincidunt a, mattis non, imperdiet vitae, tellus. Sed odio est, auctor ac, sollicitudin in, consequat vitae, orci. Fusce id felis. Vivamus sollicitudin metus eget eros.
</div>
<script src="../src/jquery.js"></script>
<script src="../src/transition-end.min.js"></script>
<script>
$(function(){
var texto01 = $('#texto-01');
var texto02 = $('#texto-02');
var count = 0;
transitionEnd(texto01).bind(function(){
texto02.toggleClass('on');
});
setInterval(function(){
count++;
texto01.toggleClass('on');
if(count === 4){
alert('unbind');
transitionEnd(texto01).unbind();
}
}, 2000);
});
</script>
</body>
</html>
\ No newline at end of file
... ...
{
"Licence": "MIT",
"_from": "transitionEnd@^1.0.2",
"_id": "transitionEnd@1.0.2",
"_inBundle": false,
"_integrity": "sha1-GRTbW0Wn79w0oBr2koWjppOHFjM=",
"_location": "/transitionEnd",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "transitionEnd@^1.0.2",
"name": "transitionEnd",
"escapedName": "transitionEnd",
"rawSpec": "^1.0.2",
"saveSpec": null,
"fetchSpec": "^1.0.2"
},
"_requiredBy": [
"/vconsole"
],
"_resolved": "https://registry.npmjs.org/transitionEnd/-/transitionEnd-1.0.2.tgz",
"_shasum": "1914db5b45a7efdc34a01af69285a3a693871633",
"_spec": "transitionEnd@^1.0.2",
"_where": "C:\\Users\\PC\\Desktop\\pet-class\\node_modules\\vconsole",
"author": {
"name": "evandrolg"
},
"bugs": {
"url": "https://github.com/evandrolg/transitionEnd/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "[![Build Status](https://travis-ci.org/EvandroLG/transitionEnd.svg?branch=master)](https://travis-ci.org/EvandroLG/transitionEnd)",
"devDependencies": {
"jshint": "^2.5.x",
"uglify-js": "^2.4.16"
},
"homepage": "https://github.com/evandrolg/transitionEnd#readme",
"keywords": [
"transitionEnd",
"event",
"js",
"front-end",
"manipulation"
],
"main": "src/transition-end.js",
"name": "transitionEnd",
"repository": {
"type": "git",
"url": "git+https://github.com/evandrolg/transitionEnd.git"
},
"scripts": {
"start": "node server.js"
},
"version": "1.0.2"
}
... ...
var http = require('http');
var fs = require('fs');
var url = require('url');
var mimeTypes = {
'html': 'text/html',
'css': 'text/css',
'js': 'text/js'
};
var onHead = function(response, content, statusCode, extension){
var mimeType = mimeTypes[extension];
response.writeHead(statusCode, { 'Content-Type': mimeType });
response.end(content, 'utf-8');
};
http.createServer(function(request, response){
var pathname = '.' + url.parse(request.url, true).pathname;
fs.readFile(pathname, function(error, content){
if(error){
onHead(response, content, 400, 'html');
}
var extension = pathname.split('.')[2];
onHead(response, content, 200, extension);
});
}).listen(9000);
\ No newline at end of file
... ...
/*
* TransitionEnd
* author: Evandro Leopoldino Gonçalves <evandrolgoncalves@gmail.com>
* https://github.com/evandrolg
* License: MIT
*/
(function(window){
'use strict';
var Event = function(element, type){
this.element = element;
this.type = type;
};
Event.prototype = {
add: function(callback){
this.callback = callback;
this.element.addEventListener(this.type, this.callback, false);
},
remove: function(){
this.element.removeEventListener(this.type, this.callback, false);
}
};
var TransitionEnd = function(element){
this.element = element;
this.transitionEnd = this.whichTransitionEnd();
this.event = new Event(this.element, this.transitionEnd);
};
TransitionEnd.prototype = {
whichTransitionEnd: function(){
var transitions = {
'WebkitTransition' : 'webkitTransitionEnd',
'MozTransition' : 'transitionend',
'OTransition' : 'oTransitionEnd otransitionend',
'transition' : 'transitionend'
};
for(var t in transitions){
if(this.element.style[t] !== undefined){
return transitions[t];
}
}
},
bind: function(callback){
this.event.add(callback);
},
unbind: function(){
this.event.remove();
}
};
var Cache = {
list: [],
getPosition: function(element){
if(Array.prototype.indexOf){
return this.list.indexOf(element);
}
for(var i = 0, size = this.list.length; i < size; i++){
if(this.list[i] === element){
return i;
}
}
return -1;
},
insert: function(element){
var positonElement = this.getPosition(element);
var isCached = positonElement !== -1;
if(!isCached){
this.list.push(element);
this.list.push(new TransitionEnd(element));
positonElement = this.getPosition(element);
}
return this.list[positonElement+1];
}
};
window.transitionEnd = function(el){
if(!el){
throw 'You need to pass an element as parameter!';
}
var element = el[0] || el;
var instance = Cache.insert(element);
return instance;
};
}(window));
\ No newline at end of file
... ...
!function(t){"use strict";var i=function(t,i){this.element=t,this.type=i};i.prototype={add:function(t){this.callback=t,this.element.addEventListener(this.type,this.callback,!1)},remove:function(){this.element.removeEventListener(this.type,this.callback,!1)}};var n=function(t){this.element=t,this.transitionEnd=this.whichTransitionEnd(),this.event=new i(this.element,this.transitionEnd)};n.prototype={whichTransitionEnd:function(){var t={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var i in t)if(void 0!==this.element.style[i])return t[i]},bind:function(t){this.event.add(t)},unbind:function(){this.event.remove()}};var e={list:[],getPosition:function(t){if(Array.prototype.indexOf)return this.list.indexOf(t);for(var i=0,n=this.list.length;n>i;i++)if(this.list[i]===t)return i;return-1},insert:function(t){var i=this.getPosition(t),e=-1!==i;return e||(this.list.push(t),this.list.push(new n(t)),i=this.getPosition(t)),this.list[i+1]}};t.transitionEnd=function(t){if(!t)throw"You need to pass an element as parameter!";var i=t[0]||t,n=e.insert(i);return n}}(window);
\ No newline at end of file
... ...
#element{
transition: background 1s;
-moz-transition: background 1s;
-webkit-transition: background 0.1s;
-o-transition: background 1s;
background: #CCC;
}
#element.on{
background: #000;
}
\ No newline at end of file
... ...
body {
font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
}
.jasmine_reporter a:visited, .jasmine_reporter a {
color: #303;
}
.jasmine_reporter a:hover, .jasmine_reporter a:active {
color: blue;
}
.run_spec {
float:right;
padding-right: 5px;
font-size: .8em;
text-decoration: none;
}
.jasmine_reporter {
margin: 0 5px;
}
.banner {
color: #303;
background-color: #fef;
padding: 5px;
}
.logo {
float: left;
font-size: 1.1em;
padding-left: 5px;
}
.logo .version {
font-size: .6em;
padding-left: 1em;
}
.runner.running {
background-color: yellow;
}
.options {
text-align: right;
font-size: .8em;
}
.suite {
border: 1px outset gray;
margin: 5px 0;
padding-left: 1em;
}
.suite .suite {
margin: 5px;
}
.suite.passed {
background-color: #dfd;
}
.suite.failed {
background-color: #fdd;
}
.spec {
margin: 5px;
padding-left: 1em;
clear: both;
}
.spec.failed, .spec.passed, .spec.skipped {
padding-bottom: 5px;
border: 1px solid gray;
}
.spec.failed {
background-color: #fbb;
border-color: red;
}
.spec.passed {
background-color: #bfb;
border-color: green;
}
.spec.skipped {
background-color: #bbb;
}
.messages {
border-left: 1px dashed gray;
padding-left: 1em;
padding-right: 1em;
}
.passed {
background-color: #cfc;
display: none;
}
.failed {
background-color: #fbb;
}
.skipped {
color: #777;
background-color: #eee;
display: none;
}
/*.resultMessage {*/
/*white-space: pre;*/
/*}*/
.resultMessage span.result {
display: block;
line-height: 2em;
color: black;
}
.resultMessage .mismatch {
color: black;
}
.stackTrace {
white-space: pre;
font-size: .8em;
margin-left: 10px;
max-height: 5em;
overflow: auto;
border: 1px inset red;
padding: 1em;
background: #eef;
}
.finished-at {
padding-left: 1em;
font-size: .6em;
}
.show-passed .passed,
.show-skipped .skipped {
display: block;
}
#jasmine_content {
position:fixed;
right: 100%;
}
.runner {
border: 1px solid gray;
display: block;
margin: 5px 0;
padding: 2px 0 2px 10px;
}
\ No newline at end of file
... ...
jasmine.TrivialReporter = function(doc) {
this.document = doc || document;
this.suiteDivs = {};
this.logRunningSpecs = false;
};
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
var el = document.createElement(type);
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
if (typeof child === 'string') {
el.appendChild(document.createTextNode(child));
} else {
if (child) { el.appendChild(child); }
}
}
for (var attr in attrs) {
if (attr == "className") {
el[attr] = attrs[attr];
} else {
el.setAttribute(attr, attrs[attr]);
}
}
return el;
};
jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
var showPassed, showSkipped;
this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
this.createDom('div', { className: 'banner' },
this.createDom('div', { className: 'logo' },
this.createDom('span', { className: 'title' }, "Jasmine"),
this.createDom('span', { className: 'version' }, runner.env.versionString())),
this.createDom('div', { className: 'options' },
"Show ",
showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
)
),
this.runnerDiv = this.createDom('div', { className: 'runner running' },
this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
);
this.document.body.appendChild(this.outerDiv);
var suites = runner.suites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
var suiteDiv = this.createDom('div', { className: 'suite' },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
this.suiteDivs[suite.id] = suiteDiv;
var parentDiv = this.outerDiv;
if (suite.parentSuite) {
parentDiv = this.suiteDivs[suite.parentSuite.id];
}
parentDiv.appendChild(suiteDiv);
}
this.startedAt = new Date();
var self = this;
showPassed.onclick = function(evt) {
if (showPassed.checked) {
self.outerDiv.className += ' show-passed';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
}
};
showSkipped.onclick = function(evt) {
if (showSkipped.checked) {
self.outerDiv.className += ' show-skipped';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
}
};
};
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
var results = runner.results();
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
this.runnerDiv.setAttribute("class", className);
//do it twice for IE
this.runnerDiv.setAttribute("className", className);
var specs = runner.specs();
var specCount = 0;
for (var i = 0; i < specs.length; i++) {
if (this.specFilter(specs[i])) {
specCount++;
}
}
var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
};
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
var results = suite.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.totalCount === 0) { // todo: change this to check results.skipped
status = 'skipped';
}
this.suiteDivs[suite.id].className += " " + status;
};
jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
if (this.logRunningSpecs) {
this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
}
};
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
var results = spec.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.skipped) {
status = 'skipped';
}
var specDiv = this.createDom('div', { className: 'spec ' + status },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
this.createDom('a', {
className: 'description',
href: '?spec=' + encodeURIComponent(spec.getFullName()),
title: spec.getFullName()
}, spec.description));
var resultItems = results.getItems();
var messagesDiv = this.createDom('div', { className: 'messages' });
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'log') {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
} else if (result.type == 'expect' && result.passed && !result.passed()) {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
if (result.trace.stack) {
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
}
}
}
if (messagesDiv.childNodes.length > 0) {
specDiv.appendChild(messagesDiv);
}
this.suiteDivs[spec.suite.id].appendChild(specDiv);
};
jasmine.TrivialReporter.prototype.log = function() {
var console = jasmine.getGlobal().console;
if (console && console.log) {
if (console.log.apply) {
console.log.apply(console, arguments);
} else {
console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
}
}
};
jasmine.TrivialReporter.prototype.getLocation = function() {
return this.document.location;
};
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
var paramMap = {};
var params = this.getLocation().search.substring(1).split('&');
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}
if (!paramMap.spec) {
return true;
}
return spec.getFullName().indexOf(paramMap.spec) === 0;
};
... ...
var readFixtures = function() {
return jasmine.getFixtures().proxyCallTo_('read', arguments);
};
var preloadFixtures = function() {
jasmine.getFixtures().proxyCallTo_('preload', arguments);
};
var loadFixtures = function() {
jasmine.getFixtures().proxyCallTo_('load', arguments);
};
var setFixtures = function(html) {
jasmine.getFixtures().set(html);
};
var sandbox = function(attributes) {
return jasmine.getFixtures().sandbox(attributes);
};
var spyOnEvent = function(selector, eventName) {
jasmine.JQuery.events.spyOn(selector, eventName);
}
jasmine.getFixtures = function() {
return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures();
};
jasmine.Fixtures = function() {
this.containerId = 'jasmine-fixtures';
this.fixturesCache_ = {};
this.fixturesPath = 'spec/javascripts/fixtures';
};
jasmine.Fixtures.prototype.set = function(html) {
this.cleanUp();
this.createContainer_(html);
};
jasmine.Fixtures.prototype.preload = function() {
this.read.apply(this, arguments);
};
jasmine.Fixtures.prototype.load = function() {
this.cleanUp();
this.createContainer_(this.read.apply(this, arguments));
};
jasmine.Fixtures.prototype.read = function() {
var htmlChunks = [];
var fixtureUrls = arguments;
for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex]));
}
return htmlChunks.join('');
};
jasmine.Fixtures.prototype.clearCache = function() {
this.fixturesCache_ = {};
};
jasmine.Fixtures.prototype.cleanUp = function() {
jQuery('#' + this.containerId).remove();
};
jasmine.Fixtures.prototype.sandbox = function(attributes) {
var attributesToSet = attributes || {};
return jQuery('<div id="sandbox" />').attr(attributesToSet);
};
jasmine.Fixtures.prototype.createContainer_ = function(html) {
var container;
if(html instanceof jQuery) {
container = jQuery('<div id="' + this.containerId + '" />');
container.html(html);
} else {
container = '<div id="' + this.containerId + '">' + html + '</div>'
}
jQuery('body').append(container);
};
jasmine.Fixtures.prototype.getFixtureHtml_ = function(url) {
if (typeof this.fixturesCache_[url] == 'undefined') {
this.loadFixtureIntoCache_(url);
}
return this.fixturesCache_[url];
};
jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
var self = this;
var url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl;
jQuery.ajax({
async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
cache: false,
dataType: 'html',
url: url,
success: function(data) {
self.fixturesCache_[relativeUrl] = data;
},
error: function(jqXHR, status, errorThrown) {
throw Error('Fixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')');
}
});
};
jasmine.Fixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
return this[methodName].apply(this, passedArguments);
};
jasmine.JQuery = function() {};
jasmine.JQuery.browserTagCaseIndependentHtml = function(html) {
return jQuery('<div/>').append(html).html();
};
jasmine.JQuery.elementToString = function(element) {
return jQuery('<div />').append(element.clone()).html();
};
jasmine.JQuery.matchersClass = {};
(function(namespace) {
var data = {
spiedEvents: {},
handlers: []
};
namespace.events = {
spyOn: function(selector, eventName) {
var handler = function(e) {
data.spiedEvents[[selector, eventName]] = e;
};
jQuery(selector).bind(eventName, handler);
data.handlers.push(handler);
},
wasTriggered: function(selector, eventName) {
return !!(data.spiedEvents[[selector, eventName]]);
},
cleanUp: function() {
data.spiedEvents = {};
data.handlers = [];
}
}
})(jasmine.JQuery);
(function(){
var jQueryMatchers = {
toHaveClass: function(className) {
return this.actual.hasClass(className);
},
toBeVisible: function() {
return this.actual.is(':visible');
},
toBeHidden: function() {
return this.actual.is(':hidden');
},
toBeSelected: function() {
return this.actual.is(':selected');
},
toBeChecked: function() {
return this.actual.is(':checked');
},
toBeEmpty: function() {
return this.actual.is(':empty');
},
toExist: function() {
return this.actual.size() > 0;
},
toHaveAttr: function(attributeName, expectedAttributeValue) {
return hasProperty(this.actual.attr(attributeName), expectedAttributeValue);
},
toHaveId: function(id) {
return this.actual.attr('id') == id;
},
toHaveHtml: function(html) {
return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html);
},
toHaveText: function(text) {
if (text && jQuery.isFunction(text.test)) {
return text.test(this.actual.text());
} else {
return this.actual.text() == text;
}
},
toHaveValue: function(value) {
return this.actual.val() == value;
},
toHaveData: function(key, expectedValue) {
return hasProperty(this.actual.data(key), expectedValue);
},
toBe: function(selector) {
return this.actual.is(selector);
},
toContain: function(selector) {
return this.actual.find(selector).size() > 0;
},
toBeDisabled: function(selector){
return this.actual.is(':disabled');
},
// tests the existence of a specific event binding
toHandle: function(eventName) {
var events = this.actual.data("events");
return events && events[eventName].length > 0;
},
// tests the existence of a specific event binding + handler
toHandleWith: function(eventName, eventHandler) {
var stack = this.actual.data("events")[eventName];
var i;
for (i = 0; i < stack.length; i++) {
if (stack[i].handler == eventHandler) {
return true;
}
}
return false;
}
};
var hasProperty = function(actualValue, expectedValue) {
if (expectedValue === undefined) {
return actualValue !== undefined;
}
return actualValue == expectedValue;
};
var bindMatcher = function(methodName) {
var builtInMatcher = jasmine.Matchers.prototype[methodName];
jasmine.JQuery.matchersClass[methodName] = function() {
if (this.actual instanceof jQuery) {
var result = jQueryMatchers[methodName].apply(this, arguments);
this.actual = jasmine.JQuery.elementToString(this.actual);
return result;
}
if (builtInMatcher) {
return builtInMatcher.apply(this, arguments);
}
return false;
};
};
for(var methodName in jQueryMatchers) {
bindMatcher(methodName);
}
})();
beforeEach(function() {
this.addMatchers(jasmine.JQuery.matchersClass);
this.addMatchers({
toHaveBeenTriggeredOn: function(selector) {
this.message = function() {
return [
"Expected event " + this.actual + " to have been triggered on" + selector,
"Expected event " + this.actual + " not to have been triggered on" + selector
];
};
return jasmine.JQuery.events.wasTriggered(selector, this.actual);
}
})
});
afterEach(function() {
jasmine.getFixtures().cleanUp();
jasmine.JQuery.events.cleanUp();
});
... ...