summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/widgets/iframe_widget.js
blob: 8ecbd5f1c7d2ca05e082872aee2bef1109a5d3bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
odoo.define('web.IFrameWidget', function (require) {
"use strict";

var Widget = require('web.Widget');

/**
 * Generic widget to create an iframe that listens for clicks
 *
 * It should be extended by overwriting the methods::
 *
 *      init: function(parent) {
 *          this._super(parent, <url_of_iframe>);
 *      },
 *      _onIFrameClicked: function(e){
 *          filter the clicks you want to use and apply
 *          an action on it
 *      }
 */
var IFrameWidget = Widget.extend({
    tagName: 'iframe',
    /**
     * @constructor
     * @param {Widget} parent
     * @param {string} url
     */
    init: function (parent, url) {
        this._super(parent);
        this.url = url;
    },
    /**
     * @override
     * @returns {Promise}
     */
    start: function () {
        this.$el.css({height: '100%', width: '100%', border: 0});
        this.$el.attr({src: this.url});
        this.$el.on("load", this._bindEvents.bind(this));
        return this._super();
    },

    //--------------------------------------------------------------------------
    // Private
    //--------------------------------------------------------------------------

    /**
     * Called when the iframe is ready
     */
    _bindEvents: function (){
        this.$el.contents().click(this._onIFrameClicked.bind(this));
    },

    //--------------------------------------------------------------------------
    // Handlers
    //--------------------------------------------------------------------------

    /**
     * @param {MouseEvent} event
     */
    _onIFrameClicked: function (event){
    }
});

return IFrameWidget;

});