Sha256: c390ea2e424d7eac9319ecdb645cb695cf36dbf6adba8cf08ef793a8e0722587

Contents?: true

Size: 1.49 KB

Versions: 7

Compression:

Stored size: 1.49 KB

Contents

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
        if (this.handler) {
            el.removeEventListener(this.arg, this.handler)
        }
    },

    unbind: function () {
        this.reset()
        this.el.removeEventListener('load', this.iframeBind)
    }
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fluentd-ui-0.3.8 vendor/assets/javascripts/bower/vue/src/directives/on.js
fluentd-ui-0.3.7 vendor/assets/javascripts/bower/vue/src/directives/on.js
fluentd-ui-0.3.6 vendor/assets/javascripts/bower/vue/src/directives/on.js
fluentd-ui-0.3.5 vendor/assets/javascripts/bower/vue/src/directives/on.js
fluentd-ui-0.3.3 vendor/assets/javascripts/bower/vue/src/directives/on.js
fluentd-ui-0.3.2 vendor/assets/javascripts/bower/vue/src/directives/on.js
fluentd-ui-0.3.1 vendor/assets/javascripts/bower/vue/src/directives/on.js