Skip to content

Commit

Permalink
fix uniqSet
Browse files Browse the repository at this point in the history
  • Loading branch information
RubyLouvre committed Aug 22, 2014
1 parent f419338 commit 7bc046b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 53 deletions.
36 changes: 25 additions & 11 deletions avalon.observe.js
Expand Up @@ -1471,19 +1471,33 @@
.replace(rnumber, ",")
.replace(rcommaOfFirstOrLast, "")
.split(rcommaInMiddle)
return cacheVars(key, uinqSet(vars))
return cacheVars(key, uniqSet(vars))
}
function uinqSet(arr) {
var set = new Set
arr.forEach(function(el) {
set.add(el)
})
var ret = []
set.forEach(function(el) {
ret.push(el)
})

function uniqSet(array) {
var ret = [], unique = {}
for (var i = 0; i < array.length; i++) {
var el = array[i]
var id = el && typeof el.$id === "string" ? el.$id : el
if (!unique[id]) {
unique[id] = ret.push(el)
}
}
return ret
}

void function() {
var test = [1, 2, 3, 1]
if (typeof Set == "function" && (new Set(test)).size == 3) {
var uniqSet = function(arr) {//重写uniqSet
var set = new Set(arr), ret = []
set.forEach(function(el) {
ret.push(el)
})
return ret
}
}
}()

function addDeps(scope, prop, data) {
var obj = scope.$accessors
Expand Down Expand Up @@ -2491,7 +2505,7 @@
} catch (e) {
launch = avalon.tick
}

duplexBinding.SELECT = function(element, evaluator, data) {
var $elem = avalon(element)
function updateVModel() {
Expand Down
20 changes: 8 additions & 12 deletions iscroll.js
@@ -1,7 +1,7 @@
function IScroll (el, options) {
this.wrapper = typeof el == 'string' ? document.querySelector(el) : el;
this.scroller = this.wrapper.children[0];
this.scrollerStyle = this.scroller.style; // cache style for better performance
this.scrollerStyle = this.scroller.style; //保存滚动条元素的样式对象,以提高性能

this.options = {

Expand Down Expand Up @@ -76,16 +76,12 @@ IScroll.prototype = {
version: '/* VERSION */',

_init: function () {
this._initEvents();

// INSERT POINT: _init

this._initEvents();//绑定事件
},

destroy: function () {
this._initEvents(true);

this._execEvent('destroy');
this._initEvents(true);//移除事件
this._execEvent('destroy');//执行用户回调
},

_transitionEnd: function (e) {
Expand All @@ -96,7 +92,7 @@ IScroll.prototype = {
this._transitionTime();
if ( !this.resetPosition(this.options.bounceTime) ) {
this.isInTransition = false;
this._execEvent('scrollEnd');
this._execEvent('scrollEnd');//执行用户回调
}
},

Expand Down Expand Up @@ -127,14 +123,14 @@ IScroll.prototype = {
this.directionY = 0;
this.directionLocked = 0;

this._transitionTime();
this._transitionTime();//设置CSS3 渐变时长 transition-duration

this.startTime = utils.getTime();

if ( this.options.useTransition && this.isInTransition ) {
this.isInTransition = false;
pos = this.getComputedPosition();
this._translate(Math.round(pos.x), Math.round(pos.y));
this._translate(Math.round(pos.x), Math.round(pos.y));//强制回到起始位置
this._execEvent('scrollEnd');
} else if ( !this.options.useTransition && this.isAnimating ) {
this.isAnimating = false;
Expand Down Expand Up @@ -234,7 +230,7 @@ IScroll.prototype = {

this.moved = true;

this._translate(newX, newY);
this._translate(newX, newY);//移动到新位置

/* REPLACE START: _move */

Expand Down
38 changes: 8 additions & 30 deletions test1.html
Expand Up @@ -23,42 +23,20 @@
})

window.onload = function() {
var elem = document.querySelector("#son")
var offset = function(el) {
var left = -el.offsetLeft,
top = -el.offsetTop;

// jshint -W084
while (el = el.offsetParent) {
left -= el.offsetLeft;
top -= el.offsetTop;
}
// jshint +W084

return {
left: left,
top: top
};
};

elem.addEventListener("DOMNodeRemovedFromDocument", function() {
setTimeout(function() {
console.log(document.documentElement.contains(elem))
console.log("ddd")
},4)

})
// var elem = document.querySelector("#son")


setTimeout(function() {
// elem.value = "dddddddddddddddd"
}, 3000)
setTimeout(function() {
var el = document.querySelector("#parent")
el.parentNode.removeChild(el)
// var el = document.querySelector("#parent")
// el.parentNode.removeChild(el)

}, 3000)

}


</script>
</head>
Expand All @@ -84,8 +62,8 @@
</div


<label for="female" ms-click="click">Female</label>
<input type="radio" name="sex" id="female" ms-click="click" />
<label for="female" ms-click="click" >Female</label>
<input name="sex" id="female" ms-click="click" disabled/>
<p type="button" ms-click="click" ms-on-dblclick="dblclick">sss</p>
<input disabled="disabled" ms-click="click" value="这是disabled元素">
</div>
Expand Down

0 comments on commit 7bc046b

Please sign in to comment.