Mac OS X 10.5.1 and Multi-Safari
Seems like Multi-Safari (at least 2.0.4) broke when upgrading to Mac OS X 10.5.1. I get this error:
“You cannot use the application ‘Safari 2.0.4’ with this version of Mac OS X.”
Luckily, I’ve found a workaround. Just launch Safari from the command line (Terminal.app that is) and it should work for you:
/Applications/Safari\ 2.0.4.app/Contents/MacOS/Safari &
Ajax.CachedRequest
Recently I wanted to cache the results (responseText) from a lot of Ajax.Request
s since the returning data would not change and made the roundtrip to the server unnecessary. Maybe there are others out there interested so here’s the code. It’s not very well tested except the project where it is in use so there might be some bugs or tweaks needed.
Ajax.CachedRequest = Class.create(Ajax.Request, {
initialize: function($super, url, options) {
options = options || {};
var onSuccess = options.onSuccess || Prototype.K;
if (!Ajax.CachedRequest.cache[url] || options.reload) {
options.onSuccess = function(transport) {
Ajax.CachedRequest.cache[url] = transport.responseText;
onSuccess(transport);
}
$super(url, options);
} else {
eval(Ajax.CachedRequest.cache[url]);
this.dispatch.defer();
[onSuccess, options.onComplete].each(function(m) { m && m() });
}
},
dispatch: function() {
Ajax.Responders.dispatch('onComplete', null);
}
});
Ajax.CachedRequest.cache = {};
Of course this assumes you’re using the brand new Prototype 1.6
OmniFocus to iPhone bookmark exporter
Since the iPhone lacks the possibility to export tasks from iCal I made hack/script to export all tasks from OmniFocus to a Safari bookmark and therefore be syncable with Safari.
Read more in the OmniGroup forums and/or download the latest version here.
Update: On request, here are some screenshots of how the todo list looks like:
Burnfield Dark WordPress Theme issue
I get a lot of questions on how to make the thumbails show up on theme behind this site. So I’ve updated the page with some instructions to help you all.
I’ve started on the 2.0 version on the theme that will (along other features) make thumbnails easier to manage.
Prototype & Script.aculo.us SVN checkins RSS feed
Thanks to Yahoo Pipes I created two RSS feeds for the Ruby on Rails checkins (changesets). One containing only the Rails-spinoffs checkins (that is Prototype and Script.aculo.us right now) and another without the spinoffs. This way I can follow the JavaScript-related changes as they happen but watch the Ruby-stuff every now and then.
AppleScript to open iTerm tabs for Rails development
Update: This script is ported (and improved) to work with OSX Leopards’ Terminal.app.
I never really liked iTerm because of slow redrawing, ugly text anti aliasing and not reflowing text when resizing the window.
After reading some interviews on a Rails site today and saw that a lot of people are using iTerm i wanted to give one more try (because I’d really like a tabbed terminal).
It has improved a lot the latest months and seems really usable now. To make Rails development easier, I hacked together a small AppleScript what will ask you for the path to the Rails directory you want to use and then open four new tabs with Server/Mongrel, Console, Autotest and the directory itself. I thought it could be useful for others as well so here you go:
Save as an .app and run from Quicksilver:
global rails_dir
tell application "iTerm"
activate
set rails_dir to the text returned of (display dialog ¬
"Please Enter the Path to Your Rails Directory" default answer ¬
"~/Projects/" as text)
if (count of terminal) = 0 then make new terminal
my open_tab("Server", "&& ./script/server")
my open_tab("Console", "&& ./script/console")
my open_tab("Autotest", "&& autotest")
my open_tab("Rails Directory", "")
end tell
on open_tab(title, command)
tell application "iTerm" to tell first terminal
launch session "Default"
tell last session
write text "cd " & rails_dir & command
set name to title
end tell
end tell
end run_command
What's new in Prototype svn?
Just after posting this I saw that sam tagged the 1.5.1 release in svn so I guess this means that 1.5.1 is final. Great work!
There has been a lot of action the past days in the Prototype SVN; the release of 1.5.1 RC4, the new DOM and Position branches and a lot of other work. Since I watch most of the tickets and changesets I thought I write something about what’s (might be) in the future for Prototype.
DOM branch
I was happy to see a patch I’ve been working on (#7476) to get included some days ago.
It will define a new Element#writeAttribute
method which will work together as the already existing #readAttribute
to work around many issues browsers having with the native set/getAttribute
methods (as always mostly in IE) but also to make chaining work:
$('my_image').writeAttribute('src', 'new-image.png').show();
The method will also accept a hash for the attributes to let you set multiple attributes at once:
$('my_image').writeAttribute({src: 'new-image.png', custom_attr: 'foo'}).show();
The patch will also make the Element
object into a constructor for very easy and fast element creation (i.e. document.createElement
wrapper):
var header = new Element('h1');
The constructor will also accept an optional attributes hash for the attributes (as seen above in the #writeAttribute
method):
var header = new Element('h1', {id: 'myHeader'});
Of course chaining will work so for a simple image switcher with preloading you could do this:
<!-- html --><br />
<img src="thumbnail.jpg" id="thumbnail" hires="big.jpg">
// javascript<br />
$('thumbnail').observe('click', function(event) {<br />
var thumb = Event.element(event),<br />
preloader = new Element('img', {src: thumb.readAttribute('hires')});<br />
preloader.observe('load', function(event) {<br />
thumb.writeAttribute('src', preloader.readAttribute('src'));<br />
});<br />
});
Event Branch
I haven’t followed the event branch very closely but from the code and messages on the ML I’ve seen there should be new functionality for better garbage collection (to prevent memory leaks) and for e.g. easier removal of observers from elements.
Where you before had to manually collect all an element’s event listeners to be able to remove them later:
var listener1 = function(event) {...}.bindAsEventListener();<br />
var listener2 = function(event) {...}.bindAsEventListener();
// start listening<br />
$('myElement').observe('click', listener1);<br />
$('myElement').observe('click', listener2);
// stop listening<br />
$('myElement').stopObserving('click', listener1);<br />
$('myElement').stopObserving('click', listener2);
you will now be able to remove all event listener for a specfic event:
$('myElement').stopObserving('click'); // or Event.stopObserving('myElement', 'click');
Other
Some other new additions worth mentioning are:
But to not make this post too long you’ll have to read about it on your own (check the source and/or the changesets manually).
Please notice that all these are subject to change since it’s under development right now and might never get into any future release of Prototype.
Konst & Teknik site finally launched
After five months we finally launched the new site for Konst & Teknik last night. It is my first Ruby on Rails-project and even though it might look pretty simple it has a lot of advanced things going on both server- and client wise. I plan to write more about the development of the site shortly.
One animated background image for multiple elements in Safari
I’ve found out that Safari can’t handle the same animated gif as background for multiple elements, it will just animate one of them at the same time. On a project I’m currently working on my I use the following trick to make all requests to the background image (in this case indicator_black.gif
) unique.
[...]<br />
var text = transport.responseText;<br />
if (Browser.WebKit) {<br />
text = text.gsub('indicator_black.gif', function(match) {<br />
return match + '?' + new Date().valueOf() +<br />
Math.round(Math.random() * 5000);<br />
});<br />
}<br />
[...]
Note that it uses Prototype JavaScript framework and you should too.
Update:
This is fixed in WebKit nightly (and therefore Safari 3 but I haven't tested yet).Rails' time extensions ported to JavaScript
I’ve ported Rails’ Numeric Time extensions to JavaScript since I needed to do some date calculations for a project I’m working on. Now one should be able to calculate dates in JS like this:
(5).seconds() // => 5000<br />
(2).weeks() + (2).hours() + (15).seconds() // => 1216815000<br />
(1).week().fromNow().toDate() // => Fri Sep 22 2006 19:16:32 GMT+0200 (CEST)<br />
var date = new Date(2000, 11, 18, 18, 15, 23);<br />
(2).years().since(date).toDate() // => Thu Dec 19 2002 06:15:23 GMT+0100 (CET)
Thought it could be useful for others as well.
You’ll need the latest prototype library, unit tests are included.
Download a zip with both .js file and unit tests or just the .js-file.