@dolphinweex/weex-vue-render 0.2.18 → 0.2.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.common.js +108 -96
- package/package.json +1 -1
package/dist/index.common.js
CHANGED
|
@@ -3463,12 +3463,15 @@ function applySrc (item, src, placeholderSrc) {
|
|
|
3463
3463
|
if (item._src_loading === src) {
|
|
3464
3464
|
return
|
|
3465
3465
|
}
|
|
3466
|
-
|
|
3466
|
+
function isEncoded(url) { //检查 % 后是否是合法的编码
|
|
3467
|
+
return /%[0-9A-Fa-f]{2}/.test(url);
|
|
3468
|
+
}
|
|
3467
3469
|
/**
|
|
3468
3470
|
* 1. apply src immediately in case javscript blocks the image loading
|
|
3469
3471
|
* before next tick.
|
|
3470
3472
|
*/
|
|
3471
|
-
|
|
3473
|
+
const finalUrl = isEncoded(src) ? src : encodeURI(src);
|
|
3474
|
+
item.style.backgroundImage = "url(" + (src ? finalUrl : '') + ")";
|
|
3472
3475
|
item.removeAttribute(lazyloadAttr);
|
|
3473
3476
|
/**
|
|
3474
3477
|
* 2. then load the img src with Image constructor (but would not post
|
|
@@ -3476,7 +3479,8 @@ function applySrc (item, src, placeholderSrc) {
|
|
|
3476
3479
|
*/
|
|
3477
3480
|
item._src_loading = src;
|
|
3478
3481
|
preLoadImg(src, function (evt) {
|
|
3479
|
-
|
|
3482
|
+
const finalUrl = isEncoded(src) ? src : encodeURI(src);
|
|
3483
|
+
item.style.backgroundImage = "url(" + (src ? finalUrl : '') + ")";
|
|
3480
3484
|
var ref = this;
|
|
3481
3485
|
var naturalWidth = ref.width;
|
|
3482
3486
|
var naturalHeight = ref.height;
|
|
@@ -3493,8 +3497,9 @@ function applySrc (item, src, placeholderSrc) {
|
|
|
3493
3497
|
};
|
|
3494
3498
|
dispatchNativeEvent(item, 'load', params);
|
|
3495
3499
|
if (placeholderSrc) {
|
|
3500
|
+
const finalUrl = isEncoded(placeholderSrc) ? placeholderSrc : encodeURI(placeholderSrc);
|
|
3496
3501
|
preLoadImg(placeholderSrc, function () {
|
|
3497
|
-
item.style.backgroundImage = "url(" + (placeholderSrc ?
|
|
3502
|
+
item.style.backgroundImage = "url(" + (placeholderSrc ? finalUrl : '') + ")";
|
|
3498
3503
|
});
|
|
3499
3504
|
}
|
|
3500
3505
|
finallCb();
|
|
@@ -7400,6 +7405,7 @@ var slideMixin = {
|
|
|
7400
7405
|
this._clones = [];
|
|
7401
7406
|
this.innerOffset = 0;
|
|
7402
7407
|
this._indicator = null;
|
|
7408
|
+
this.cloneIndex = Boolean(this.infinite) //需要减或者加去克隆下标
|
|
7403
7409
|
},
|
|
7404
7410
|
|
|
7405
7411
|
beforeUpdate: function beforeUpdate () {
|
|
@@ -7455,7 +7461,7 @@ var slideMixin = {
|
|
|
7455
7461
|
|
|
7456
7462
|
mounted: function mounted () {
|
|
7457
7463
|
this._getWrapperSize();
|
|
7458
|
-
this._slideTo(this.currentIndex);
|
|
7464
|
+
this._slideTo(this.currentIndex + this.cloneIndex);
|
|
7459
7465
|
weex.utils.fireLazyload(this.$el, true);
|
|
7460
7466
|
},
|
|
7461
7467
|
|
|
@@ -7487,10 +7493,35 @@ var slideMixin = {
|
|
|
7487
7493
|
staticClass: ("weex-slider-cell weex-ct" + (this$1.isNeighbor ? ' neighbor-cell' : ''))
|
|
7488
7494
|
}, [vnode])
|
|
7489
7495
|
});
|
|
7496
|
+
|
|
7497
|
+
if (this.infinite && cells.length > 1) {
|
|
7498
|
+
// 克隆第一个和最后一个有效节点
|
|
7499
|
+
const cloneFirst = () => {
|
|
7500
|
+
const first = cells[0];
|
|
7501
|
+
return first ? createElement('li', {
|
|
7502
|
+
staticClass: "weex-slider-cell weex-ct clone-cell",
|
|
7503
|
+
key: 'clone-first'
|
|
7504
|
+
}, [first.children || first.componentOptions.children]) : null
|
|
7505
|
+
};
|
|
7506
|
+
|
|
7507
|
+
const cloneLast = () => {
|
|
7508
|
+
const last = cells[cells.length - 1];
|
|
7509
|
+
return last ? createElement('li', {
|
|
7510
|
+
staticClass: "weex-slider-cell weex-ct clone-cell",
|
|
7511
|
+
key: 'clone-last'
|
|
7512
|
+
}, [last.children || last.componentOptions.children]) : null
|
|
7513
|
+
};
|
|
7514
|
+
const lastClone = cloneLast();
|
|
7515
|
+
const firstClone = cloneFirst();
|
|
7516
|
+
|
|
7517
|
+
if (firstClone && lastClone) {
|
|
7518
|
+
cells = [lastClone].concat(cells).concat([firstClone]);
|
|
7519
|
+
}
|
|
7520
|
+
}
|
|
7490
7521
|
if (indicatorVnode) {
|
|
7491
7522
|
indicatorVnode.data.attrs = indicatorVnode.data.attrs || {};
|
|
7492
|
-
indicatorVnode.data.attrs.count = cells.length;
|
|
7493
|
-
indicatorVnode.data.attrs.active = this.currentIndex;
|
|
7523
|
+
indicatorVnode.data.attrs.count = cells.length - (this.infinite ? 2 : 0 ); // 显示实际数量
|
|
7524
|
+
indicatorVnode.data.attrs.active = this.currentIndex - this.cloneIndex;
|
|
7494
7525
|
this._indicator = indicatorVnode;
|
|
7495
7526
|
}
|
|
7496
7527
|
return cells
|
|
@@ -7549,55 +7580,77 @@ var slideMixin = {
|
|
|
7549
7580
|
}
|
|
7550
7581
|
},
|
|
7551
7582
|
|
|
7552
|
-
_slideTo: function _slideTo
|
|
7583
|
+
_slideTo: function _slideTo(index, isTouchScroll) {
|
|
7553
7584
|
var this$1 = this;
|
|
7554
|
-
|
|
7585
|
+
|
|
7555
7586
|
if (this.frameCount <= 0) {
|
|
7556
|
-
return
|
|
7587
|
+
return;
|
|
7557
7588
|
}
|
|
7558
7589
|
if (!this.infinite || this.infinite === 'false') {
|
|
7559
7590
|
if (index === -1 || index > (this.frameCount - 1)) {
|
|
7560
7591
|
this._slideTo(this.currentIndex);
|
|
7561
|
-
return
|
|
7592
|
+
return;
|
|
7562
7593
|
}
|
|
7563
7594
|
}
|
|
7564
7595
|
if (!this._preIndex && this._preIndex !== 0) {
|
|
7565
|
-
|
|
7566
|
-
this._preIndex = this._showNodes[0].index;
|
|
7567
|
-
}
|
|
7568
|
-
else {
|
|
7569
|
-
this._preIndex = 0;
|
|
7570
|
-
}
|
|
7596
|
+
this._preIndex = this.currentIndex || 0;
|
|
7571
7597
|
}
|
|
7572
|
-
|
|
7598
|
+
|
|
7573
7599
|
if (this._sliding) {
|
|
7574
|
-
return
|
|
7600
|
+
return;
|
|
7575
7601
|
}
|
|
7576
7602
|
this._sliding = true;
|
|
7577
|
-
|
|
7603
|
+
|
|
7578
7604
|
var newIndex = this._normalizeIndex(index);
|
|
7579
7605
|
var inner = this.$refs.inner;
|
|
7580
7606
|
var step = this._step = this.frameCount <= 1 ? 0 : this._preIndex - index;
|
|
7581
|
-
|
|
7607
|
+
|
|
7582
7608
|
if (inner) {
|
|
7583
7609
|
this._prepareNodes();
|
|
7584
7610
|
var translate = weex.utils.getTransformObj(inner).translate;
|
|
7585
7611
|
var match = translate && translate.match(/translate[^(]+\(([+-\d.]+)/);
|
|
7586
|
-
var innerX = parseFloat(inner.style.left);
|
|
7587
|
-
var dist = innerX - this.innerOffset + step;
|
|
7612
|
+
var innerX = parseFloat(inner.style.left);
|
|
7613
|
+
var dist = innerX - this.innerOffset + step;
|
|
7588
7614
|
this.innerOffset += step * this._wrapperWidth;
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7600
|
-
|
|
7615
|
+
|
|
7616
|
+
// 克隆处理:先执行正常动画到克隆的最后一张,再瞬间跳回真实的第一张
|
|
7617
|
+
if (this.infinite && index >= this.frameCount - 1) {
|
|
7618
|
+
// 先滑到克隆的 `第一张`
|
|
7619
|
+
newIndex = this.frameCount - 1;
|
|
7620
|
+
this.innerOffset = -newIndex * this._wrapperWidth;
|
|
7621
|
+
inner.style.transition = `left ${TRANSITION_TIME / 1000}s ease-in-out`;
|
|
7622
|
+
inner.style.left = `${this.innerOffset}px`;
|
|
7623
|
+
newIndex = 1; // 视觉上显示 `第一张`
|
|
7624
|
+
|
|
7625
|
+
// 等待动画完成后瞬间跳到 `第一张`
|
|
7626
|
+
setTimeout(() => {
|
|
7627
|
+
inner.style.transition = 'none';
|
|
7628
|
+
this.innerOffset = -this._wrapperWidth; // 瞬间跳到 `第一张`
|
|
7629
|
+
inner.style.left = `${this.innerOffset}px`;
|
|
7630
|
+
}, TRANSITION_TIME);
|
|
7631
|
+
} else if (this.infinite && index <= 0) {
|
|
7632
|
+
// 先滑到克隆的 `最后一张`
|
|
7633
|
+
newIndex = 0;
|
|
7634
|
+
this.innerOffset = -newIndex * this._wrapperWidth;
|
|
7635
|
+
inner.style.transition = `left ${TRANSITION_TIME / 1000}s ease-in-out`;
|
|
7636
|
+
inner.style.left = `${this.innerOffset}px`;
|
|
7637
|
+
newIndex = this.frameCount - 2; // 视觉上显示 `最后一张`
|
|
7638
|
+
|
|
7639
|
+
// 等待动画完成后瞬间跳到 `最后一张`
|
|
7640
|
+
setTimeout(() => {
|
|
7641
|
+
inner.style.transition = 'none';
|
|
7642
|
+
this.innerOffset = -(this.frameCount - 2) * this._wrapperWidth; // 瞬间跳到 `最后一张`
|
|
7643
|
+
inner.style.left = `${this.innerOffset}px`;
|
|
7644
|
+
}, TRANSITION_TIME);
|
|
7645
|
+
|
|
7646
|
+
} else {
|
|
7647
|
+
// 正常切换
|
|
7648
|
+
this.innerOffset = -newIndex * this._wrapperWidth;
|
|
7649
|
+
inner.style.transition = `left ${TRANSITION_TIME / 1000}s ease-in-out`;
|
|
7650
|
+
inner.style.left = `${this.innerOffset}px`;
|
|
7651
|
+
}
|
|
7652
|
+
|
|
7653
|
+
// 触发事件
|
|
7601
7654
|
if (!isTouchScroll) {
|
|
7602
7655
|
this._emitScrollEvent('scrollstart');
|
|
7603
7656
|
}
|
|
@@ -7606,40 +7659,42 @@ var slideMixin = {
|
|
|
7606
7659
|
this$1._emitScrollEvent('scrollend');
|
|
7607
7660
|
});
|
|
7608
7661
|
}, THROTTLE_SCROLL_TIME);
|
|
7609
|
-
|
|
7662
|
+
|
|
7610
7663
|
this._loopShowNodes(step);
|
|
7611
|
-
|
|
7664
|
+
|
|
7612
7665
|
setTimeout(function () {
|
|
7613
7666
|
if (this$1.isNeighbor) {
|
|
7614
7667
|
this$1._setNeighbors();
|
|
7615
7668
|
}
|
|
7616
|
-
|
|
7669
|
+
|
|
7617
7670
|
setTimeout(function () {
|
|
7618
7671
|
inner.style.webkitTransition = '';
|
|
7619
7672
|
inner.style.mozTransition = '';
|
|
7620
7673
|
inner.style.transition = '';
|
|
7621
7674
|
for (var i = this$1._showStartIdx; i <= this$1._showEndIdx; i++) {
|
|
7622
7675
|
var node = this$1._showNodes[i];
|
|
7623
|
-
if (!node) {
|
|
7676
|
+
if (!node) {continue;}
|
|
7624
7677
|
var elm = node.firstElementChild;
|
|
7625
|
-
if (!elm) {
|
|
7678
|
+
if (!elm) {continue;}
|
|
7626
7679
|
elm.style.webkitTransition = '';
|
|
7627
7680
|
elm.style.mozTransition = '';
|
|
7628
7681
|
elm.style.transition = '';
|
|
7629
7682
|
}
|
|
7630
|
-
// clean cloned nodes and rearrange slide cells.
|
|
7631
7683
|
this$1._rearrangeNodes(newIndex);
|
|
7632
7684
|
}, NEIGHBOR_SCALE_TIME);
|
|
7633
7685
|
}, TRANSITION_TIME);
|
|
7634
7686
|
}
|
|
7635
|
-
|
|
7687
|
+
|
|
7636
7688
|
if (newIndex !== this._preIndex) {
|
|
7637
7689
|
weex.utils.dispatchNativeEvent(this.$el, 'change', {
|
|
7638
|
-
index: newIndex
|
|
7690
|
+
index: newIndex - this.cloneIndex
|
|
7639
7691
|
});
|
|
7640
7692
|
}
|
|
7693
|
+
|
|
7694
|
+
this.currentIndex = newIndex;
|
|
7695
|
+
this._preIndex = newIndex;
|
|
7641
7696
|
},
|
|
7642
|
-
|
|
7697
|
+
|
|
7643
7698
|
_clearNodesOffset: function _clearNodesOffset () {
|
|
7644
7699
|
var this$1 = this;
|
|
7645
7700
|
|
|
@@ -7734,20 +7789,20 @@ var slideMixin = {
|
|
|
7734
7789
|
node.index = idx;
|
|
7735
7790
|
node._inShow = false;
|
|
7736
7791
|
node.style.zIndex = 0;
|
|
7737
|
-
node.style.opacity = 0;
|
|
7792
|
+
// node.style.opacity = 0;
|
|
7738
7793
|
});
|
|
7739
7794
|
},
|
|
7740
7795
|
|
|
7741
7796
|
_positionNodes: function _positionNodes (begin, end, step, anim) {
|
|
7742
7797
|
var this$1 = this;
|
|
7743
|
-
|
|
7744
7798
|
var cells = this._cells;
|
|
7745
7799
|
var start = step <= 0 ? begin : end;
|
|
7746
7800
|
var stop = step <= 0 ? end : begin;
|
|
7747
7801
|
var sign = step <= 0 ? -1 : 1;
|
|
7748
7802
|
var cellIndex = this._preIndex + sign;
|
|
7749
7803
|
for (var i = start; i !== stop - sign; i = i - sign) {
|
|
7750
|
-
var
|
|
7804
|
+
var normalizedIndex = this$1._normalizeIndex(cellIndex);
|
|
7805
|
+
var node = cells[normalizedIndex].elm;
|
|
7751
7806
|
cellIndex = cellIndex - sign;
|
|
7752
7807
|
this$1._positionNode(node, i);
|
|
7753
7808
|
}
|
|
@@ -7757,26 +7812,7 @@ var slideMixin = {
|
|
|
7757
7812
|
* index: position index in the showing cells' view.
|
|
7758
7813
|
*/
|
|
7759
7814
|
_positionNode: function _positionNode (node, index) {
|
|
7760
|
-
var holder = this._showNodes[index];
|
|
7761
|
-
if (node._inShow && (holder !== node || holder._showIndex !== index)) {
|
|
7762
|
-
if (holder && holder._isClone) { this._removeClone(holder); }
|
|
7763
|
-
if( this.autoPlay ){
|
|
7764
|
-
node = this._getClone(node.index);
|
|
7765
|
-
}
|
|
7766
|
-
}
|
|
7767
|
-
else if (node._inShow) { // holder === node
|
|
7768
|
-
return
|
|
7769
|
-
}
|
|
7770
|
-
|
|
7771
7815
|
node._inShow = true;
|
|
7772
|
-
var translateX = index * this._wrapperWidth - this.innerOffset;
|
|
7773
|
-
// ddd
|
|
7774
|
-
// weex.utils.addTransform(node, {
|
|
7775
|
-
// translate: ("translate3d(" + translateX + "px, 0px, 0px)")
|
|
7776
|
-
// });
|
|
7777
|
-
// node.style.left = translateX + 'px'
|
|
7778
|
-
|
|
7779
|
-
// node.style.zIndex = 99 - Math.abs(index);
|
|
7780
7816
|
node.style.opacity = 1;
|
|
7781
7817
|
node._showIndex = index;
|
|
7782
7818
|
this._showNodes[index] = node;
|
|
@@ -7784,29 +7820,16 @@ var slideMixin = {
|
|
|
7784
7820
|
|
|
7785
7821
|
_getClone: function _getClone (index) {
|
|
7786
7822
|
var arr = this._clones[index] || (this._clones[index] = []);
|
|
7787
|
-
var origNode = this._cells[index].elm;
|
|
7823
|
+
var origNode = this._cells[index].elm;
|
|
7788
7824
|
var clone = origNode.cloneNode(true);
|
|
7789
7825
|
clone._isClone = true;
|
|
7790
7826
|
clone._inShow = true;
|
|
7791
7827
|
// clone._inShow = origNode._inShow
|
|
7792
7828
|
clone.index = origNode.index;
|
|
7793
|
-
clone.style.opacity = 0;
|
|
7794
7829
|
clone.style.zIndex = 0;
|
|
7795
7830
|
this.$refs.inner.appendChild(clone);
|
|
7796
7831
|
arr.push(clone);
|
|
7797
7832
|
return clone
|
|
7798
|
-
// try {
|
|
7799
|
-
// let arr = this._clones[index]
|
|
7800
|
-
// if (!arr) {
|
|
7801
|
-
// this._clones[index] = arr = []
|
|
7802
|
-
// }
|
|
7803
|
-
// if (arr.length <= 0) {
|
|
7804
|
-
|
|
7805
|
-
// }
|
|
7806
|
-
// return arr.pop()
|
|
7807
|
-
// } catch (err) {
|
|
7808
|
-
// console.error('this._cells -> ', this._cells)
|
|
7809
|
-
// }
|
|
7810
7833
|
},
|
|
7811
7834
|
|
|
7812
7835
|
_removeClone: function _removeClone (node) {
|
|
@@ -7822,15 +7845,10 @@ var slideMixin = {
|
|
|
7822
7845
|
// maybe cells has been updated and this clone node is already removed from the dom tree
|
|
7823
7846
|
// throught _clearClones method.
|
|
7824
7847
|
}
|
|
7825
|
-
// const idx = node.index
|
|
7826
|
-
// this._hideNode(node)
|
|
7827
|
-
// const arr = this._clones[idx]
|
|
7828
|
-
// arr.push(node)
|
|
7829
7848
|
},
|
|
7830
7849
|
|
|
7831
7850
|
_hideNode: function _hideNode (node) {
|
|
7832
7851
|
node._inShow = false;
|
|
7833
|
-
node.style.opacity = 0;
|
|
7834
7852
|
node.style.zIndex = 0;
|
|
7835
7853
|
},
|
|
7836
7854
|
|
|
@@ -7889,7 +7907,7 @@ var slideMixin = {
|
|
|
7889
7907
|
}
|
|
7890
7908
|
var origNode = origCell.elm;
|
|
7891
7909
|
if (origNode._inShow) {
|
|
7892
|
-
return
|
|
7910
|
+
return// 原始节点已在显示区域,无需替换
|
|
7893
7911
|
}
|
|
7894
7912
|
var origShowIndex = origNode._showIndex;
|
|
7895
7913
|
var styleProps = ['opacity', 'zIndex', 'left'];
|
|
@@ -7935,7 +7953,10 @@ var slideMixin = {
|
|
|
7935
7953
|
*/
|
|
7936
7954
|
var shows = this._showNodes;
|
|
7937
7955
|
for (var i = this._showStartIdx; i <= this._showEndIdx; i++) {
|
|
7938
|
-
|
|
7956
|
+
const node = this._showNodes[i];
|
|
7957
|
+
if (node) {
|
|
7958
|
+
node._inShow = false; // 重置状态
|
|
7959
|
+
}
|
|
7939
7960
|
}
|
|
7940
7961
|
for (var i$1 = -1; i$1 <= 1; i$1++) {
|
|
7941
7962
|
var node = shows[i$1];
|
|
@@ -7990,11 +8011,6 @@ var slideMixin = {
|
|
|
7990
8011
|
translateX = 0;
|
|
7991
8012
|
}
|
|
7992
8013
|
transObj.translate = "translate3d(" + translateX + "px, 0px, 0px)";
|
|
7993
|
-
|
|
7994
|
-
// ddd
|
|
7995
|
-
// weex.utils.addTransform(elm, transObj);
|
|
7996
|
-
// elm.style.left = translateX + 'px'
|
|
7997
|
-
|
|
7998
8014
|
elm.style.opacity = i === 0 ? MAIN_SLIDE_OPACITY : this$1.neighborAlpha;
|
|
7999
8015
|
}
|
|
8000
8016
|
},
|
|
@@ -8095,10 +8111,6 @@ var slideMixin = {
|
|
|
8095
8111
|
this._emitScrollEvent('weex$scroll', {
|
|
8096
8112
|
offsetXRatio: offsetX / this._wrapperWidth
|
|
8097
8113
|
});
|
|
8098
|
-
// ddd
|
|
8099
|
-
// inner.style.webkitTransform = "translate3d(" + (this.innerOffset + offsetX) + "px, 0, 0)";
|
|
8100
|
-
// inner.style.mozTransform = "translate3d(" + (this.innerOffset + offsetX) + "px, 0, 0)";
|
|
8101
|
-
// inner.style.transform = "translate3d(" + (this.innerOffset + offsetX) + "px, 0, 0)";
|
|
8102
8114
|
inner.style.left = (this .innerOffset + offsetX) + 'px'
|
|
8103
8115
|
}
|
|
8104
8116
|
},
|
package/package.json
CHANGED