If you are running a JavaScript example page you can use the following function that will take the last script element on the page and print it out in a code tag. It uses JQuery to do the work, so you will need to include that library before using this function.
<script type="text/javascript">//<![CDATA[
function displaySource(name) {
$('<code>'
+ $('#display-' + name).prevAll('script').eq(0).html()
.replace(/^\s*|\s*$/g, '')
.split('\n').slice(1, -1).join('\n')
.replace(/(^|\n) /g, '$1')
.replace(/('[^']*')/g, '<em>$1</em>')
+ '</code>')
.insertAfter('#display-' + name);
}
//]]></script>
The function works by selecting the current script tag and finding all script elements before it. It then selects the first one it finds and outputs the contents to a code tag. It uses a few regular expressions to convert some of the characters to a more human readable format. The function is called like this.
<script type="text/javascript" id="display-test">displaySource("test");</script>
If you are running FireFox then there is a handy little short cut you can use to view the source of a page you are looking at. If you add the text view-source on any web address then you will see the equivalent of viewing the source of a page (perhaps by pressing Ctrl+u). Although not entirely useful, it does have a couple of benefits, such as being able to view your code in another tab, rather than another window.
Unfortunately, this only works in FireFox up to the latest version (currently 3). I have tested this in IE 7, Opera and Safari and they all complain about invalid protocols. Apparently it used to work in IE 6 before SP2, but was removed with that patch. This leads me to believe that it is not really a protocol, but a command that the browser understands on a local level. Much in the same way as about:config works.
If you want to view the source of the page you are currently looking at quickly then add this bit of HTML and JavaScript into your page. It will just take the current URL, paste view-source in front of it and then redirect to that address.
<form><input type="button" value="View Source Code" onclick="javascript:location='view-source:'+location"></form>
Koders is a search engine that searches through millions of lines of open source code in lots of different languages to find what you are looking for. The good thing about this is that you can look at real world examples of code that you are writing yourself.

My one criticism is that Koders is more of an interesting toy than anything useful. Although there are lots of examples in the system, there are almost no descriptions on what they do. However, if you are stuck on how to tackle a problem, or can’t seem to figure out how a class or a function works then Koders might be of help to you. You might even find a class that does what you are trying to do.
Recent Comments