diff --git a/lib/vue-keep-scroll.js b/lib/vue-keep-scroll.js index d469bae..677e800 100644 --- a/lib/vue-keep-scroll.js +++ b/lib/vue-keep-scroll.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.10.0 +// Generated by CoffeeScript 1.11.1 (function() { var slice, vueKeepScroll; @@ -9,17 +9,17 @@ vueKeepScroll = { install: function(Vue) { return Vue.directive('keep-scroll', { - bind: function() { + bind: function(el, binding, vnode) { var oldAttached; oldAttached = void 0; - this.el.addEventListener('scroll', function(e) { + el.addEventListener('scroll', function(e) { var ele; ele = void 0; ele = e.target; return ele.setAttribute('data-vuescrlpos', ele.scrollLeft + '-' + ele.scrollTop); }); - oldAttached = this.vm.attached; - this.vm.attached = function() { + oldAttached = vnode.context.activated; + vnode.context.activated = function() { var args, ele, i, len, ref, ref1; args = void 0; ele = void 0; @@ -50,7 +50,7 @@ void 0; } }; - this.vm.$on('hook:attached', this.vm.attached); + vnode.context.$on('hook:activated', vnode.context.activated); } }); } diff --git a/src/vue-keep-scroll.coffee b/src/vue-keep-scroll.coffee index 9c76353..42bdbb8 100644 --- a/src/vue-keep-scroll.coffee +++ b/src/vue-keep-scroll.coffee @@ -1,15 +1,15 @@ vueKeepScroll = undefined slice = [].slice vueKeepScroll = install: (Vue) -> - Vue.directive 'keep-scroll', bind: -> + Vue.directive 'keep-scroll', bind: (el, binding, vnode) -> oldAttached = undefined - @el.addEventListener 'scroll', (e) -> + el.addEventListener 'scroll', (e) -> ele = undefined ele = e.target ele.setAttribute 'data-vuescrlpos', ele.scrollLeft + '-' + ele.scrollTop - oldAttached = @vm.attached + oldAttached = vnode.context.activated - @vm.attached = -> + vnode.context.activated = -> args = undefined ele = undefined i = undefined @@ -34,7 +34,7 @@ vueKeepScroll = install: (Vue) -> if oldAttached != undefined then oldAttached.call.apply(oldAttached, [ this ].concat(slice.call(args))) else undefined return - @vm.$on 'hook:attached', @vm.attached + vnode.context.$on 'hook:activated', vnode.context.activated return if typeof exports == 'object' module.exports = vueKeepScroll