Show More
@@ -0,0 +1,37 b'' | |||
|
1 | Enable to add extra attributes to iframe | |
|
2 | ======================================== | |
|
3 | ||
|
4 | You can add any extra attributes to the ``<iframe>`` tag | |
|
5 | since the argument ``extras`` has been added to the ``IFrame`` class. | |
|
6 | for example:: | |
|
7 | ||
|
8 | In [1]: from IPython.display import IFrame | |
|
9 | ||
|
10 | In [2]: print(IFrame(src="src", width=300, height=300, extras=["hello", "world"])._repr_html_()) | |
|
11 | ||
|
12 | <iframe | |
|
13 | width="300" | |
|
14 | height="300" | |
|
15 | src="src" | |
|
16 | frameborder="0" | |
|
17 | allowfullscreen | |
|
18 | hello world | |
|
19 | ></iframe> | |
|
20 | ||
|
21 | Using it, you can autoplay ``YouTubeVideo`` by adding ``'allow="autoplay"'``, | |
|
22 | even in browsers that disable it by default, such as Google Chrome. | |
|
23 | And, you can write it more briefly by using the argument ``allow_autoplay``. | |
|
24 | :: | |
|
25 | ||
|
26 | In [1]: from IPython.display import YouTubeVideo | |
|
27 | ||
|
28 | In [2]: print(YouTubeVideo("video-id", allow_autoplay=True)._repr_html_()) | |
|
29 | ||
|
30 | <iframe | |
|
31 | width="400" | |
|
32 | height="300" | |
|
33 | src="https://www.youtube.com/embed/video-id?autoplay=1" | |
|
34 | frameborder="0" | |
|
35 | allowfullscreen | |
|
36 | allow="autoplay" | |
|
37 | ></iframe> |
@@ -8,7 +8,7 b' from os import walk, sep, fsdecode' | |||
|
8 | 8 | |
|
9 | 9 | from IPython.core.display import DisplayObject, TextDisplayObject |
|
10 | 10 | |
|
11 | from typing import Tuple | |
|
11 | from typing import Tuple, Iterable | |
|
12 | 12 | |
|
13 | 13 | __all__ = ['Audio', 'IFrame', 'YouTubeVideo', 'VimeoVideo', 'ScribdDocument', |
|
14 | 14 | 'FileLink', 'FileLinks', 'Code'] |
@@ -255,13 +255,18 b' class IFrame(object):' | |||
|
255 | 255 | src="{src}{params}" |
|
256 | 256 | frameborder="0" |
|
257 | 257 | allowfullscreen |
|
258 | {extras} | |
|
258 | 259 | ></iframe> |
|
259 | 260 | """ |
|
260 | 261 | |
|
261 | def __init__(self, src, width, height, **kwargs): | |
|
262 | def __init__(self, src, width, height, extras: Iterable[str] = None, **kwargs): | |
|
263 | if extras is None: | |
|
264 | extras = [] | |
|
265 | ||
|
262 | 266 | self.src = src |
|
263 | 267 | self.width = width |
|
264 | 268 | self.height = height |
|
269 | self.extras = extras | |
|
265 | 270 | self.params = kwargs |
|
266 | 271 | |
|
267 | 272 | def _repr_html_(self): |
@@ -274,10 +279,14 b' class IFrame(object):' | |||
|
274 | 279 | params = "?" + urlencode(self.params) |
|
275 | 280 | else: |
|
276 | 281 | params = "" |
|
277 |
return self.iframe.format( |
|
|
282 | return self.iframe.format( | |
|
283 | src=self.src, | |
|
278 | 284 |
|
|
279 | 285 |
|
|
280 |
|
|
|
286 | params=params, | |
|
287 | extras=" ".join(self.extras), | |
|
288 | ) | |
|
289 | ||
|
281 | 290 | |
|
282 | 291 | class YouTubeVideo(IFrame): |
|
283 | 292 | """Class for embedding a YouTube Video in an IPython session, based on its video id. |
@@ -305,9 +314,12 b' class YouTubeVideo(IFrame):' | |||
|
305 | 314 | will be inserted in the document. |
|
306 | 315 | """ |
|
307 | 316 | |
|
308 | def __init__(self, id, width=400, height=300, **kwargs): | |
|
317 | def __init__(self, id, width=400, height=300, allow_autoplay=False, **kwargs): | |
|
309 | 318 | self.id=id |
|
310 | 319 | src = "https://www.youtube.com/embed/{0}".format(id) |
|
320 | if allow_autoplay: | |
|
321 | extras = list(kwargs.get("extras", [])) + ['allow="autoplay"'] | |
|
322 | kwargs.update(autoplay=1, extras=extras) | |
|
311 | 323 | super(YouTubeVideo, self).__init__(src, width, height, **kwargs) |
|
312 | 324 | |
|
313 | 325 | def _repr_jpeg_(self): |
General Comments 0
You need to be logged in to leave comments.
Login now