remove javascript fetch polyfill
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent c7f2ab8 · Browse files · 8 files·+48 added−50 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+48 added−50 removed
- tests:+2 added−2 removed
- other:+46 added−48 removed
Provenance
- Commit
6f6e328- Tree
566e652- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
c7f2ab8
8 files changed+48 added−50 removed
modified:examples/javascript/js_example/templates/base.html+4 added-4 removed
12343456783 unmodified lines121314151617161718192021222310 unmodified lines<!doctype html><title>JavaScript Example</title><link rel="stylesheet" href="https://unpkg.com/sakura.css@1.0.0/css/normalize.css"><link rel="stylesheet" href="https://unpkg.com/sakura.css@1.0.0/css/sakura-earthly.css"><link rel="stylesheet" href="https://unpkg.com/normalize.css@8.0.1/normalize.css"><link rel="stylesheet" href="https://unpkg.com/sakura.css@1.3.1/css/sakura.css"><style> ul { margin: 0; padding: 0; display: flex; list-style-type: none; } li > * { padding: 1em; } li.active > a { color: #5e5e5e; border-bottom: 2px solid #4a4a4a; }3 unmodified lines #result { font-weight: bold; }</style><ul> <li><span>Type:</span> <li class="{% if js == 'plain' %}active{% endif %}"> <a href="{{ url_for('index', js='plain') }}">Plain</a> <li class="{% if js == 'fetch' %}active{% endif %}"> <a href="{{ url_for('index', js='fetch') }}">Fetch</a> <li class="{% if js == 'xhr' %}active{% endif %}"> <a href="{{ url_for('index', js='xhr') }}">XHR</a> <li class="{% if js == 'jquery' %}active{% endif %}"> <a href="{{ url_for('index', js='jquery') }}">jQuery</a></ul><hr>10 unmodified linesmodified:examples/javascript/js_example/templates/fetch.html+2 added-5 removed
12345675678911121011121320 unmodified lines{% extends 'base.html' %}
{% block intro %} <a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch"><code>fetch</code></a> is the <em>new</em> plain JavaScript way to make requests. It's supported in all modern browsers except IE, which requires a <a href="https://github.com/github/fetch">polyfill</a>. is the <em>modern</em> plain JavaScript way to make requests. It's supported in all modern browsers.{% endblock %}
{% block script %} <script src="https://unpkg.com/promise-polyfill@7.1.2/dist/polyfill.min.js"></script> <script src="https://unpkg.com/whatwg-fetch@2.0.4/fetch.js"></script> <script> function addSubmit(ev) { ev.preventDefault(); fetch({{ url_for('add')|tojson }}, {20 unmodified linesdeleted:examples/javascript/js_example/templates/plain.html-28 removed
12345678910111213141516171819202122232425262728{% extends 'base.html' %}
{% block intro %} <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest"><code>XMLHttpRequest</code></a> is the plain JavaScript way to make requests. It's natively supported by all browsers.{% endblock %}
{% block script %} <script> function addSubmit(ev) { ev.preventDefault(); var request = new XMLHttpRequest(); request.addEventListener('load', addShow); request.open('POST', {{ url_for('add')|tojson }}); request.send(new FormData(this)); }
function addShow() { var data = JSON.parse(this.responseText); var span = document.getElementById('result'); span.innerText = data.result; }
var form = document.getElementById('calc'); form.addEventListener('submit', addSubmit); </script>{% endblock %}added:examples/javascript/js_example/templates/xhr.html+29 added
1234567891011121314151617181920212223242526272829{% extends 'base.html' %}
{% block intro %} <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest"><code>XMLHttpRequest</code></a> is the original JavaScript way to make requests. It's natively supported by all browsers, but has been superseded by <a href="{{ url_for("index", js="fetch") }}"><code>fetch</code></a>.{% endblock %}
{% block script %} <script> function addSubmit(ev) { ev.preventDefault(); var request = new XMLHttpRequest(); request.addEventListener('load', addShow); request.open('POST', {{ url_for('add')|tojson }}); request.send(new FormData(this)); }
function addShow() { var data = JSON.parse(this.responseText); var span = document.getElementById('result'); span.innerText = data.result; }
var form = document.getElementById('calc'); form.addEventListener('submit', addSubmit); </script>{% endblock %}modified:examples/javascript/js_example/views.py+2 added-2 removed
3 unmodified lines4 5 from js_example import app6 7 8-@app.route("/", defaults={"js": "plain"})9-@app.route("/<any(plain, jquery, fetch):js>")8+@app.route("/", defaults={"js": "fetch"})9+@app.route("/<any(xhr, jquery, fetch):js>")10 def index(js):11 return render_template(f"{js}.html", js=js)12 13 5 unmodified linesmodified:examples/javascript/tests/test_js_example.py+2 added-2 removed
3 unmodified lines4 5 @pytest.mark.parametrize(6 ("path", "template_name"),7 (8- ("/", "plain.html"),9- ("/plain", "plain.html"),8+ ("/", "xhr.html"),9+ ("/plain", "xhr.html"),10 ("/fetch", "fetch.html"),11 ("/jquery", "jquery.html"),12 ),13 )14 unmodified linesmodified:examples/javascript/README.rst+8 added-8 removed
1 unmodified line2 =======================3 4 Demonstrates how to post form data and process a JSON response using5 JavaScript. This allows making requests without navigating away from the6-page. Demonstrates using |XMLHttpRequest|_, |fetch|_, and7-|jQuery.ajax|_. See the `Flask docs`_ about jQuery and Ajax.6+page. Demonstrates using |fetch|_, |XMLHttpRequest|_, and7+|jQuery.ajax|_. See the `Flask docs`_ about JavaScript and Ajax.8 9-.. |XMLHttpRequest| replace:: ``XMLHttpRequest``10-.. _XMLHttpRequest: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest11-9 .. |fetch| replace:: ``fetch``10 .. _fetch: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch11 12+.. |XMLHttpRequest| replace:: ``XMLHttpRequest``13+.. _XMLHttpRequest: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest14+15 .. |jQuery.ajax| replace:: ``jQuery.ajax``16 .. _jQuery.ajax: https://api.jquery.com/jQuery.ajax/17 18 .. _Flask docs: https://flask.palletsprojects.com/patterns/jquery/1 unmodified line20 21 Install22 -------23 24-::24+.. code-block:: text25 26 $ python3 -m venv venv27 $ . venv/bin/activate28 $ pip install -e .1 unmodified line30 31 Run32 ---33 34-::34+.. code-block:: text35 36 $ export FLASK_APP=js_example37 $ flask run38 2 unmodified lines41 42 Test43 ----44 45-::45+.. code-block:: text46 47 $ pip install -e '.[test]'48 $ coverage run -m pytest49 $ coverage reportmodified:examples/javascript/setup.cfg+1 added-1 removed
1 [metadata]2 name = js_example3-version = 1.0.03+version = 1.1.04 url = https://flask.palletsprojects.com/patterns/jquery/5 license = BSD-3-Clause6 maintainer = Pallets7 maintainer_email = contact@palletsprojects.com22 unmodified lines