- Currently Listening to:
- Weezer — The World Has Turned And Left Me Here
Some ordered lists are better presented in descending order. For example, my publications list works better in reverse-chronological order so that the most recent work appears at the top of the list, and is numbered highest-to-lowest.
Ordered lists in HTML are created using the ol element, but there’s no way to present a list in descending order. (It’s in the HTML5 spec, but might be a while before it’s generally usable.)
The JavaScript solutions I found to achieve this were all a bit rubbish—adding spurious numbers to the margin and generally messing up the semantics of the list. So I wrote a quick function that finds each ol element on the page that has the class “reversed”, and changes the “value” attribute of each li to the number it would have in a native reversed-order presentation. It’s not semantically perfect, but it degrades gracefully and will do until browsers support the HTML5 incarnation of ol. The JavaScript looks like this:
function reverse_lists() {
var olists = document.getElementsByTagName('ol');
for (var i = 0; i < olists.length; i++) {
if (!olists[i].className.match(/\breversed\b/))
continue;
var items = olists[i].getElementsByTagName('li');
for(var j = 0; j < items.length; j++) {
items[j].setAttribute("value", items.length - j);
}
}
}
You can download a .js file with this function and upload it to your server. Apply the code by calling the function after all of your list elements (the first script element can be put in the document’s head if you have control over that):
<ol class="reversed">
<li>Most recent item.</li>
<li>Less recent item.</li>
⋮
</ol>
<script type="text/javascript" src="reorder.js"></script>
<script type="text/javascript">
reverse_lists();
</script>
And in your place an empty space
Has filled the void behind my face.
- wtfjs
- mir.aculo.us JavaScript with Thomas Fuchs » Blog Archive » When JavaScript makes no sense
- How to print debug messages in the Google Chrome Javascript Console - Stack Overflow
- Closures - MDC
- JavaScript closures in for-loops | mennovanslooten.nl
- An implausibly illustrated introduction to HTML5 Web Workers
- Why doesn't JavaScript support multithreading? - Stack Overflow
You can however use, as was suggested, use setTimeout to allow some sort of scheduling and 'fake' concurrency. This causes the browser to regain control of the rendering thread, and start the Javascript code supplied to setTimeout after the given number of milliseconds. This is very useful if you want to allow the viewport (what you see) to refresh while performing operations on it. Just looping through e.g. coordinates and updating an element accordingly will just let you see the start and end positions, and nothing in between.
- jsPerf: JavaScript performance playground
jsPerf aims to provide an easy way to create and share test cases, comparing the performance of different JavaScript snippets by running benchmarks.
- Manipulating the browser history - MDC
HTML5 introduced the history.pushState() and history.replaceState() methods, which allow you to add and modify history entries, respectively. These methods work in conjunction with the window.onpopstate event.
- When can I use...
- Unity Technologies Blog » Blog Archive » Unity and iOS 4.0, update III
Like everyone else who’s excited about mobile development, and in particular using Unity to create awesome games for the iPhone, we’ve been following the development of the iOS 4.0 Terms of Service closely. While we’ve had some reason to believe Unity using C# and JavaScript would be okay, Apple has not confirmed anything and in general very little information has been forthcoming. However, as of today Apple is still approving every game we know of and Apple has recently featured several excellent Unity games in the App Store. And all along we’ve continued to invest heavily in our Unity iPhone line, including a number of new features that will be coming soon in the Unity 3.0 release. But as soon as the new terms of service were revealed we also started working on a contingency plan, just in case Apple decides to stop approving Unity-based games. Allow me to explain that contingency plan so everyone out there knows what “plan B” looks like.
- Google Closure Tools - Wikipedia, the free encyclopedia
Google Closure Tools is a set of tools to help developers build rich web applications with JavaScript. It was developed by Google for use in their web applications such as Gmail, Google Docs and Google Maps.
- mir.aculo.us with Thomas Fuchs » Blog Archive » Making an iPad HTML5 App & making it really fast
- Smokescreen demo: a Flash player in JavaScript
- How can I assign a property to a jQuery object? - Stack Overflow
jQuery exposes the concept of a property-bag with the data method.
// set some arbitrary data
$('#selector').data('example-property', exampleValue);
// get the value later
var theValue = $('#selector').data('example-property')
This avoids DOM manipulations which can be expensive in terms of performance.