Skip to content

Instantly share code, notes, and snippets.

@ellisonbg
Created February 9, 2014 22:04
Show Gist options
  • Save ellisonbg/8906675 to your computer and use it in GitHub Desktop.
Save ellisonbg/8906675 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "",
"signature": "sha256:6052e06ba99403ff11a0459dbe0ca90e39dded7879d201900e445b41041535c1"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython.display import HTML, Javascript, display"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook shows how the display of JavaScript is semi-broken on nbviewer.\n",
"\n",
"First, this cell shows that JavaScript output is not displayed:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"display(Javascript(\"alert('hi')\"))\n",
"display(HTML(\"<h3>Hi there</h3>\"))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"alert('hi')"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x10e68ead0>"
]
},
{
"html": [
"<h3>Hi there</h3>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x10e68e5d0>"
]
}
],
"prompt_number": 8
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This cell shows that when JavaScript code in a `script` tag is run, jQuery is not defined. The reason for this is that jQuery is loaded at the bottom of the page and the cell's HTML is loaded when the document body is loaded."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"HTML(\"\"\"\n",
"<script>\n",
"if (typeof $ === 'undefined') {\n",
" alert('jQuery is not defined');\n",
"} else {\n",
" alert('jQuery is defined');\n",
"}\n",
"</script>\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"\n",
"<script>\n",
"if (typeof $ === 'undefined') {\n",
" alert('jQuery is not defined');\n",
"} else {\n",
" alert('jQuery is defined');\n",
"}\n",
"</script>\n"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 9,
"text": [
"<IPython.core.display.HTML at 0x10e67d990>"
]
}
],
"prompt_number": 9
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This cell shows that `require.js` is not being loaded:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"HTML(\"\"\"\n",
"<script>\n",
"if (typeof require === 'undefined') {\n",
" alert('require.js is not defined');\n",
"} else {\n",
" alert('require.js is defined');\n",
"}\n",
"</script>\n",
"\"\"\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"\n",
"<script>\n",
"if (typeof require === 'undefined') {\n",
" alert('require.js is not defined');\n",
"} else {\n",
" alert('require.js is defined');\n",
"}\n",
"</script>\n"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 10,
"text": [
"<IPython.core.display.HTML at 0x10e67f150>"
]
}
],
"prompt_number": 10
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment