MCPcopy Create free account
hub / github.com/ipython/ipython / Javascript

Class Javascript

IPython/core/display.py:1003–1059  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1001 display(bundle, metadata=metadata, raw=True)
1002
1003class Javascript(TextDisplayObject):
1004
1005 def __init__(self, data=None, url=None, filename=None, lib=None, css=None):
1006 """Create a Javascript display object given raw data.
1007
1008 When this object is returned by an expression or passed to the
1009 display function, it will result in the data being displayed
1010 in the frontend. If the data is a URL, the data will first be
1011 downloaded and then displayed.
1012
1013 In the Notebook, the containing element will be available as `element`,
1014 and jQuery will be available. Content appended to `element` will be
1015 visible in the output area.
1016
1017 Parameters
1018 ----------
1019 data : unicode, str or bytes
1020 The Javascript source code or a URL to download it from.
1021 url : unicode
1022 A URL to download the data from.
1023 filename : unicode
1024 Path to a local file to load the data from.
1025 lib : list or str
1026 A sequence of Javascript library URLs to load asynchronously before
1027 running the source code. The full URLs of the libraries should
1028 be given. A single Javascript library URL can also be given as a
1029 string.
1030 css: : list or str
1031 A sequence of css files to load before running the source code.
1032 The full URLs of the css files should be given. A single css URL
1033 can also be given as a string.
1034 """
1035 if isinstance(lib, str):
1036 lib = [lib]
1037 elif lib is None:
1038 lib = []
1039 if isinstance(css, str):
1040 css = [css]
1041 elif css is None:
1042 css = []
1043 if not isinstance(lib, (list,tuple)):
1044 raise TypeError('expected sequence, got: %r' % lib)
1045 if not isinstance(css, (list,tuple)):
1046 raise TypeError('expected sequence, got: %r' % css)
1047 self.lib = lib
1048 self.css = css
1049 super(Javascript, self).__init__(data=data, url=url, filename=filename)
1050
1051 def _repr_javascript_(self):
1052 r = ''
1053 for c in self.css:
1054 r += _css_t % c
1055 for l in self.lib:
1056 r += _lib_t1 % l
1057 r += self.data
1058 r += _lib_t2*len(self.lib)
1059 return r
1060

Callers 1

javascriptMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected