This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathgoogle-hangout-button.html
142 lines (127 loc) · 3.88 KB
/
google-hangout-button.html
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../google-apis/google-plusone-api.html">
<!--
Element providing a button to start a Google Hangout.
##### Example
<google-hangout-button></google-hangout-button>
@demo
-->
<dom-module id="google-hangout-button">
<style>
:host, span {
display: inline-block;
}
</style>
<template>
<google-plusone-api id="plusone" on-api-load="_load"></google-plusone-api>
<span id="container"></span>
</template>
</dom-module>
<script>
Polymer({
is: 'google-hangout-button',
/**
* Fired when the hangout api is loaded but before rendering the button.
*
* @event google-hangout-button-pregame
* @param {Object} e Event parameters.
*/
/**
* Fired when the button is rendered and ready to use.
*
* @event google-hangout-button-ready
* @param {Object} e Event parameters.
*/
properties: {
/**
* Specifies what type of Hangout should be started.
* Valid values are 'normal', 'onair', 'party' and 'moderated'
*
* See the [Hangout button parameter reference](https://developers.google.com/+/hangouts/button#hangout_button_parameters)
* for more details.
*/
type: {
type: String,
value: 'normal'
},
/**
* Specifies the Google+ Hangout apps to launch when a user clicks the
* Hangout button. Invalid objects and parameters are ignored.
*
* See the [Initial app parameters reference](https://developers.google.com/+/hangouts/button#initial_app_parameters)
* for more details.
*/
apps: {
type: Array,
value: function() { return []; }
},
/**
* Specifies the list of people to invite when the user clicks the
* Hangout button. Invalid objects and parameters are ignored.
*
* See the [Invite parameters reference](https://developers.google.com/+/hangouts/button#invite_parameters)
* for more details.
*/
invites: {
type: Array,
value: function() { return []; }
},
/**
* Pre-populates the topic field for Hangouts on Air. Note that users can
* change the topic of the Hangout after they have joined.
*/
topic: {
type: String,
value: null
},
/**
* Specifies the width of the button.
*/
width: {
type: Number,
value: 136
},
_loaded: {
type: Boolean,
value: false
}
},
_load: function() {
// TODO(sjmiles): pre/post shenanigans required because gapi.hangout.render
// throws if not rendered into main document light-dom
var container = this._pregame();
this.$.plusone.api.hangout.render(container, {
'render': 'createhangout',
'hangout_type': this.type,
'initial_apps': this.apps,
'invites': this.invites,
'topic': this.topic,
'widget_size': this.width
});
this._postgame(container);
},
_pregame: function() {
var object = document.createElement('span');
document.body.appendChild(object);
this.fire('google-hangout-button-pregame');
return object;
},
_postgame: function(object) {
// when the iframe finishes it's dirty business, snarf it into the shadow-root
var iframe = object.firstElementChild;
iframe.addEventListener('load', function() {
if (!this._loaded) {
// TODO(sjmiles): appending directly to shadowRoot not working under polyfill
//this.shadowRoot.appendChild(object);
this.$.container.appendChild(object);
this._loaded = true;
this.fire('google-hangout-button-ready');
}
}.bind(this));
},
ready: function () {
this.apps = this.apps || [];
this.invites = this.invites || [];
}
});
</script>