forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter.d.ts
342 lines (332 loc) · 11.6 KB
/
twitter.d.ts
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
// Type definitions for Twitter for Websites
// Project: https://dev.twitter.com/web/
// Definitions by: Chitoku <https://github.com/chitoku-k>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* The interface for Twitter for Websites.
*/
interface Twitter {
/**
* All JavaScript code depending on widgets.js should execute on or after this function.
*
* @param callback A callback function which will be invoked when widgets.js is ready.
*/
ready(callback: (twttr: Twitter) => void): void;
/**
* Twitter widgets.
*/
widgets: TwitterWidgets;
/**
* Twitter events.
*/
events: TwitterEvents;
}
/**
* The interface for Twitter for Websites widgets.
*/
interface TwitterWidgets {
/**
* Initialize Twitter for Websites widgets contained within a page.
*/
load(): void;
/**
* Initialize Twitter for Websites widgets contained within children of the element.
*/
load(element: HTMLElement): void;
/**
* Initialize Twitter for Websites widgets contained within children of the elements.
*/
load(elements: HTMLElement[]): void;
/**
* Create a share button for a URL.
*
* @param url The URL to be shared.
* @param target The element in which to render the widget.
* @param options An object hash of additional options to configure the widget.
*/
createShareButton(url: string, target: HTMLElement, options?: TwitterButtonWidgetOptions): any;
/**
* Create a follow button for a user.
*
* @param screen_name The screen_name of a user to be followed.
* @param target The element in which to render the widget.
* @param options An object hash of additional options to configure the widget.
*/
createFollowButton(screen_name: string, target: HTMLElement, options?: TwitterButtonWidgetOptions): any;
/**
* Create a hashtag button for a hashtag.
*
* @param hashtag Hashtag to be Tweeted and displayed on the button.
* @param target The element in which to render the widget.
* @param options An object hash of additional options to configure the widget.
*/
createHashtagButton(hashtag: string, target: HTMLElement, options?: TwitterButtonWidgetOptions): any;
/**
* Create a mention button for a user.
*
* @param screen_name The screen_name of a user to be mentioned.
* @param target The element in which to render the widget.
* @param options An object hash of additional options to configure the widget.
*/
createMentionButton(screen_name: string, target: HTMLElement, options?: TwitterButtonWidgetOptions): any;
/**
* Create a timeline widget.
*
* @param widgetId The ID of a timeline widget to be rendered.
* @param target The element in which to render the widget.
* @param options An object hash of additional options to configure the widget.
*/
createTimeline(widgetId: string, target: HTMLElement, options?: TwitterTimelineWidgetOptions): any;
/**
* Create an embedded Tweet for a Tweet.
*
* @param tweetId The ID of a Tweet to be rendered.
* @param target The element in which to render the widget.
* @param options An object hash of additional options to configure the widget.
*/
createTweet(tweetId: string, target: HTMLElement, options?: TwitterTweetWidgetOptions): any;
}
/**
* The interface for additional configuration for all widgets.
*/
interface TwitterWidgetOptions {
/**
* Enable Do Not Track for this widget.
*/
dnt?: boolean;
/**
* A list of hashtags to be appended to default Tweet text where appropriate.
*/
hashtags?: string;
/**
* The language in which to render a widget, if supported.
*/
lang?: string;
/**
* A list of Twitter screen names to be suggested for following after a Tweet is posted.
*/
related?: string;
/**
* A Twitter user mentioned in the default Tweet text as /via @user where appropriate.
*/
via?: string;
}
/**
* The interface for additional configuration for button widgets.
*/
interface TwitterButtonWidgetOptions extends TwitterWidgetOptions {
/**
* The alignment of the button within an iframe; use this to ensure flush layout when aligning buttons against opposite edges of your grid.
*/
align?: string;
/**
* Share button and Follow button only. (Vertical count only available for share buttons.)
*/
count?: string;
/**
* If the canonical URL to be counted is different from the URL to be shared, you can provide this URL to reference the count. (Share button only.)
*/
counturl?: string;
/**
* medium or large
*/
size?: string;
/**
* The default, highlighted text a user sees in the Tweet Web Intent.
*/
text?: string;
}
/**
* The interface for additional options for embedded Tweets.
*/
interface TwitterTweetWidgetOptions extends TwitterWidgetOptions {
/**
* Float the embedded Tweet to the left or right so that text wraps around it, or align center so it floats in the middle of a paragraph.
*/
align?: string;
/**
* For Tweets that are replies, the previous Tweet in the thread will be displayed by default. Use none to hide the thread and show a Tweet alone.
*/
conversation?: string;
/**
* Toggle whether to render expanded media through Twitter Cards in Tweets. Also applies to images uploaded to Twitter.
*/
cards?: string;
/**
* Fix the width of the embedded widget.
*/
width?: string|number;
/**
* Adjust the color of links inside the widget.
*/
linkColor?: string;
/**
* Toggle the default colorscheme of the widget.
*/
theme?: string;
}
/**
* The interface for additional options for embedded Timelines.
*/
interface TwitterTimelineWidgetOptions extends TwitterWidgetOptions, TwitterButtonWidgetOptions, TwitterTweetWidgetOptions {
/**
* Apply the specified aria-polite behavior to the rendered timeline.
*/
ariaPolite?: string;
/**
* Fix the height of the embedded widget.
*/
height?: string|number;
/**
* Adjust the color of borders inside the widget.
*/
borderColor?: string;
/**
* Toggle the display of design elements in the widget. This parameter is a space-separated list of values.
*/
chrome?: string;
/**
* Render a timeline statically, displaying only n number of Tweets.
*/
tweetLimit?: number;
/**
* Override the timeline source with this user’s Tweets.
*/
screenName?: string;
/**
* Override the timeline source with this user’s Tweets.
*/
userId?: string;
/**
* When overriding a user timeline, include Tweets that are in reply to to other users.
*/
showReplies?: boolean;
/**
* Override the timeline source with favourite Tweets from this user.
*/
favoritesScreenName?: string;
/**
* Override the timeline source with favourite Tweets from this user.
*/
favoritesUserId?: string;
/**
* Override the timeline source with Tweets from a list owned by this user. Must be used in combination with listId or listSlug.
*/
listOwnerScreenName?: string;
/**
* Override the timeline source with Tweets from a list owned by this user. Must be used in combination with listId or listSlug.
*/
listOwnerId?: string;
/**
* Override the timeline source with Tweets from this list. Must be used in combination with listOwnerId or listOwnerScreenName.
*/
listId?: string;
/**
* Override the timeline source with Tweets from this list. Must be used in combination with listOwnerId or listOwnerScreenName.
*/
listSlug?: string;
}
/**
* The interface for Twitter events.
*/
interface TwitterEvents {
/**
* Occurs after twttr.widgets.load has initialized widgets in a page, from an embed code. Includes an array of references to the newly created widget nodes.
*
* @param name The name of an event.
* @param callback A callback function which will be invoked.
*/
bind(name: "loaded", callback: (ev: any) => void): void;
/**
* Bind an event occurs after an individual widget in a page is rendered. Includes a of reference to the newly created widget node. Occurs at the same time as loaded, but for each individual widget. Also triggered when creating a widget with a factory function.
*
* @param name The name of an event.
* @param callback A callback function which will be invoked.
*/
bind(name: "rendered", callback: (ev: any) => void): void;
/**
* Bind an event which will be triggered when the user publishes a Tweet (either new, or a reply) through the Tweet Web Intent.
*
* @param name The name of an event.
* @param callback A callback function which will be invoked.
*/
bind(name: "tweet", callback: (ev: TwitterIntentEvent) => void): void;
/**
* Bind an event which will populate the followed user_id in the event object’s data argument.
*
* @param name The name of an event.
* @param callback A callback function which will be invoked.
*/
bind(name: "follow", callback: (ev: TwitterIntentEvent) => void): void;
/**
* Bind an event which will populate the original Tweet that was retweeted’s source_tweet_id in the event object’s data argument.
*
* @param name The name of an event.
* @param callback A callback function which will be invoked.
*/
bind(name: "retweet", callback: (ev: TwitterIntentEvent) => void): void;
/**
* Bind an event which will populate the favorited tweet_id in the event object’s data argument.
*
* @param name The name of an event.
* @param callback A callback function which will be invoked.
*/
bind(name: "favorite", callback: (ev: TwitterIntentEvent) => void): void;
/**
* Bind an event occurs when the user invokes a Web Intent from within an embedded widget.
*
* @param name The name of an event.
* @param callback A callback function which will be invoked.
*/
bind(name: "click", callback: (ev: TwitterIntentEvent) => void): void;
/**
* Bind an event.
*
* @param name The name of an event.
* @param callback A callback function which will be invoked.
*/
bind(name: string, callback: (ev: any) => void): void;
}
/**
* The interface for an object representing the event is passed to your JavaScript callback.
*/
interface TwitterIntentEvent {
/**
* The DOM node where the widget is instantiated. Most like an iframe, but may also be the original embed code element if the widget failed to initialize, or another sandboxed element. Use this value to differentiate between different intents or buttons on the same page.
*/
target: HTMLElement;
/**
* Extended detail indicating where in a widget a user clicked. For example, button, count, or screen name portions of Tweet button or Follow button integrations, or tweet actions within embedded Tweets.
*/
region: string;
/**
* Key/value pairs relevant to the Web Intent just actioned.
*/
data: TwitterIntentEventData;
/**
* The type of the event.
*/
type: string;
}
/**
* The interface for a data relevants to the Web Intent just actioned.
*/
interface TwitterIntentEventData {
/**
* The ID of a Tweet.
*/
tweet_id?: string;
/**
* The ID of a source Tweet.
*/
source_tweet_id?: string;
/**
* The screen_name of a user;
*/
screen_name?: string;
/**
* The ID of a user.
*/
user_id?: string;
}
declare var twttr: Twitter;