Improving Edit in Place
Dan Rubin made comment on an implementation of Edit in Place I had linked to:
"I'm stumped about how one would further optimize or improve (Edit in Place), but I'm also curious: would you improve it, and how?"
What's interesting is that there are two aspects where improvements can occur: implementation and design.
Improving Implementation
By implementation, I mean, how has the developer put it together to give his code flexibility and allow for the extensibility of his code in ways he never expected. (Flexibility and Extensibility were two of my keys of Rapid Development presentation, by the way).
Take a look at the code for the EIP article that I had linked to and you see stuff like this:
if(set['type'] == 'select') {
field = '<span id="' + set['id'] + '_editor"><select id="'
+ set['id'] + '_edit" class="' + set['css_class'] + '" name="'
+ set['id'] + '_edit">';
But what if I wanted to set my own class on the span? or wanted to add some additional properties to the select? I don't have that option. The EIP object takes a restricted set of properties and that's it.
However, this could be done through a properties object that could be passed in. A default object would be stored in the EIP object and it's properties can be overridden by the properties object passed in.
var o = {
"id":"editinplace",
"class":"help",
"value":"defaultvalue"
};
for(i in o)
{
s += ' ' + i + '="'+o[i]+'"'
}
This example is just a snippet but the o object just has a series of properties and values (a valid JSON object, in fact). Then we loop through each property and append the key (the part before the colon) and value (the part after the colon) onto the string that would be my innerHTML. In fact, if you were a DOM purist, you could instead create and set your attributes in the for loop.
Improving Design
From a design perspective, the examples given weren't bad but I found them "jumpy". The padding on hover didn't feel right. Certainly this is just a style issue and easily fixable. But there are a couple other things, such as the "saving" dialog. It pops up in the same place as the editing. Can I have this appear elsewhere, do I have control over how this looks and feels?
A callback mechanism would be a nice to have for before edit, before save and after save events where I could simply tie in my own saving feedback.
Another subtle design thing that Flickr does is retain the yellow highlight for an extended time once you've left the editable area. This is effective at drawing you back to this editable area but also minimizes the jumpy feeling that one gets of seeing the yellow turn on and turn off from an accidental swipe through the area.
"There are 4,382 ways"
Okay, I think I ripped that from Dan Cederholm's Bulletproof presentation but the point being that there is always more than one way to solve a problem. And in JavaScript, there are ways to make it easier for others to use our code.
Conversation
Thanks Jonathan, this is exactly the kind of explanation I was looking for - constantly expanding my poor level of understanding :)
I've been wrapping up a new release of EditInPlace that fixes some bugs and adds some additional flexibility. In general I've tried to lean more towards low bloat instead of unlimited possibilities.
My JavaScript skills are pretty basic and I've been learning a lot from writing EditInPlace. Based on some of the feedback I've had on the project there are many, many ways to write similar solutions.
How about integration with dynamic databases so we bloggers can edit-in-place our blog entries? :)
Dan: glad I was able to explain it a little more. :)
Joseph: Sorry if this came across as a knock on your skills. That was unintentional. The goal was the mention an alternative, one that hopefully offered more flexibility and could do so without adding bloat to the code.
Sean: that's a pretty cool idea. Let me know when you've got it built. ;)
The new version (0.3.0) is up. The announcement addresses some of your points, a few new features and bug fixes.
I've rewritten this thing a few times now, I'd be interested in hearing your comments on my approach for 0.3.0.