| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- var utils = require('../utils')
- /**
- * Binding for event listeners
- */
- module.exports = {
- isFn: true,
- bind: function () {
- this.context = this.binding.isExp
- ? this.vm
- : this.binding.compiler.vm
- if (this.el.tagName === 'IFRAME' && this.arg !== 'load') {
- var self = this
- this.iframeBind = function () {
- self.el.contentWindow.addEventListener(self.arg, self.handler)
- }
- this.el.addEventListener('load', this.iframeBind)
- }
- },
- update: function (handler) {
- if (typeof handler !== 'function') {
- utils.warn('Directive "v-on:' + this.expression + '" expects a method.')
- return
- }
- this.reset()
- var vm = this.vm,
- context = this.context
- this.handler = function (e) {
- e.targetVM = vm
- context.$event = e
- var res = handler.call(context, e)
- context.$event = null
- return res
- }
- if (this.iframeBind) {
- this.iframeBind()
- } else {
- this.el.addEventListener(this.arg, this.handler)
- }
- },
- reset: function () {
- var el = this.iframeBind
- ? this.el.contentWindow
- : this.el
- el.removeEventListener(this.arg, this.handler)
- },
- unbind: function () {
- this.reset()
- this.el.removeEventListener('load', this.iframeBind)
- }
- }
|