diff options
author | Paul Duncan <pabs@pablotron.org> | 2017-11-10 19:05:58 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2017-11-10 19:05:58 -0500 |
commit | bbc7aa8b51e4890f66c8298d6dc7d6368ebade38 (patch) | |
tree | e8b7c8d37330be0188649718f6d4358963449f21 /htdocs/js | |
parent | 142e66c257c29fbca426bbfeb58ac8d2f883c817 (diff) | |
download | mathy-bbc7aa8b51e4890f66c8298d6dc7d6368ebade38.tar.bz2 mathy-bbc7aa8b51e4890f66c8298d6dc7d6368ebade38.zip |
add permalinks, move about links to data.js
Diffstat (limited to 'htdocs/js')
-rw-r--r-- | htdocs/js/data.js | 17 | ||||
-rw-r--r-- | htdocs/js/mathy.js | 44 |
2 files changed, 57 insertions, 4 deletions
diff --git a/htdocs/js/data.js b/htdocs/js/data.js index f17f364..5a12764 100644 --- a/htdocs/js/data.js +++ b/htdocs/js/data.js @@ -1,4 +1,21 @@ var DATA = { + links: [{ + name: 'Ace Editor', + link: 'https://ace.c9.io/', + }, { + name: 'Bootstrap', + link: 'https://getbootstrap.com/', + }, { + name: 'Font Awesome', + link: 'http://fontawesome.io/', + }, { + name: 'jQuery', + link: 'https://jquery.com', + }, { + name: 'MathJax', + link: 'https://www.mathjax.org/', + }], + examples: [{ name: "Some Limit", text: [ diff --git a/htdocs/js/mathy.js b/htdocs/js/mathy.js index 2100b26..9e9c71d 100644 --- a/htdocs/js/mathy.js +++ b/htdocs/js/mathy.js @@ -2,6 +2,18 @@ jQuery(function($) { "use strict"; var TEMPLATES = new LuigiTemplate.Cache({ + link: [ + "<li>", + "<a ", + "href='%{link|h}' ", + "title='%{name|h}' ", + "target='_blank' ", + ">", + "%{name|h}", + "</a>", + "</li>", + ], + save: [ "<li>", "<a ", @@ -162,13 +174,24 @@ jQuery(function($) { }); (function() { - // load autosaved text - var last = localStorage.getItem('mathy_last'); - if (!last) + var text = null; + + // guard against old IE + if (window.URL) { + // load from query parameter + text = (new URL(document.location)).searchParams.get('t'); + } + + if (!text) { + // load autosaved text + text = localStorage.getItem('mathy_last'); + } + + if (!text) return; // set text - editor.setValue(last); + editor.setValue(text); })(); $('#saves').on('click', 'a', function() { @@ -269,4 +292,17 @@ jQuery(function($) { // stop event return false; }); + + // populate links + $('#about-dialog .modal-body ul').html($.map(DATA.links, function(row) { + return TEMPLATES.run('link', row); + }).join('')); + + $('#link-dialog').on('show.bs.modal', function() { + $(this).find('input').val(document.location + '?' + $.param({ + t: editor.getValue(), + })); + }).on('shown.bs.modal', function() { + $(this).find('input').focus().select(); + }); }); |