If you’re using the Strathspey SCD Database, you may have found that “dance lists” are a pretty nifty feature. They can take much of the hassle out of planning lessons or devising and publishing programmes for social functions. And they’re really easy to add to your web page as long as that web page is hosted on my.strathspey: A simple
<<dlist-table:My Dancelist>>
(where “My Dancelist” is the name of your dance list in the database) will do the trick.
If your web site isn’t on my.strathspey, however, things are a little bit more difficult. On your dance list’s page in the database there is a tab that lets you copy HTML code for the dance list to paste into your own web site, but this is inconvenient. In particular, if the dance list changes after the fact, you need to manually fix your own site by re-copying the HTML code from the database.
In this post we present a new approach that lets you add a dance list to your own web site such that it will be fetched from the database when required. This means that any changes or updates to the dance list in the database will automatically be reflected on your own site. Bliss!
The basic approach is to include a short JavaScript snippet in your page that will do the actual work. JavaScript is a programming language which is popular on the Web, but you won’t have to do any actual programming – if you follow the examples displayed below you should have little trouble. (Of course a working knowledge of HTML would come in very useful.) On the other hand, if you’ve ever worked with something like the Google Maps API, this should really be child’s play.
A complete sample document is available from the Strathspey site. You can use this to try the various steps shown here.
To add a dance list to your web page, first put an HTML “div” tag in the place where you would like the dance list to show up later. (The dance list will probably turn out to be a biggish HTML table, just so you know what you’re getting yourself into.) Something like
<div id="dlist">
(Please enable JavaScript to see the dance list.)
</div>
would be suitable. The “class=“dlist”” is required so our JavaScript code will find the “div” later. (The actual class name is irrelevant; you could use something else or even an “id=…” attribute.)
Then we need to load the actual JavaScript code, which you can retrieve from the Strathspey site or copy and put on your own site. It is best to put something like
<script type="text/javascript"
src="https://media.strathspey.org/scddb/js/jquery.danceList.js"></script>
(replace the URL with one pointing to wherever you have put the JavaScript file on your own site if you want to host your own copy.) As a matter of fact, our code makes use of the very popular jQuery framework, which must also be available when our code is loaded¹. If you haven’t loaded jQuery before, anyway, the instructions should really look like
<script type="text/javascript"
src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script type="text/javascript"
src="https://media.strathspey.org/scddb/js/jquery.danceList.js"></script>
(the first two lines will fetch jQuery from the official jQuery distribution network).
In case you’re wondering why we don’t offer a “minified” version of the jquery.danceList.js plugin: It’s only 25 lines and so far we haven’t bothered. If there is strong demand for it we’d be happy to sort this out.
The only remaining task on the JavaScript side is actually loading the dance list. Here’s how:
<script type="text/javascript">
$("#dlist").danceList({
name: "My Dancelist"
});
</script>
This will replace the content of the “div” tag with ID “dlist” by the dance list from the server. There will be a very brief delay while the JavaScript plugin goes out to fetch the dance list, but after that it will look like it was part of your web page all along.
The parameter to the “danceList” function is a JavaScript object whose properties describe how the dance list should appear. The following properties are currently defined:
If you’ve tried this with a simple HTML page you will probably have noticed that the dance list looks rather ugly. This is simple to fix using CSS, and we make available a sample style sheet for your convenience. You can use this by adding
<link rel="stylesheet" type="text/css"
href="https://media-dev.strathspey.org/scddb/css/danceList.css"
media="screen">
to the “head” section of your HTML file (where the other CSS files are mentioned), or feel free to copy it from our machine to yours and tweak it until you like the way the dance list looks.
The dance list is a fairly simple HTML table. The nesting of HTML elements looks like
div.dlist [Enclosing element]
table.table.danceList
thead
tr
th.danceNumber
th.danceName
th.danceType
th.danceShape
th.dancePublication
tbody
td
td.danceNumber
td.danceName
td.danceType
td.danceShape
td.dancePublication
tfoot
(the table footer is used for a link to the dance list’s page in the Strathspey SCD database, and for the shortcut links to the crib and diagram sheets and the video page).
You can use the classes mentioned in this overview to re-style the dance list to your liking by making appropriate CSS definitions in a place where the browser can see them.
At this point this facility is still fairly experimental. If you use it, feel free to let me know how you get on, report bugs, or make suggestions for enhancements. Enjoy!
Sign in to see recent visitors!