Skip to content

Instantly share code, notes, and snippets.

@nikz
Created December 3, 2009 04:14
Show Gist options
  • Select an option

  • Save nikz/247882 to your computer and use it in GitHub Desktop.

Select an option

Save nikz/247882 to your computer and use it in GitHub Desktop.
// TODO: perhaps change most/all live previews to inherit from this?
LivePreview = Class.create({
initialize: function(preview_fields) {
preview_fields.each(function(field_id) {
var field = $(field_id)
var div = $(field_id + "_preview");
if (div) {
this.bind_update(div, field);
}
}.bind(this));
},
bind_update: function(div, field, property) {
if (!property) property = "innerHTML";
div = $(div); field = $(field);
field.observe("keyup", function() { this.update_property(div, field, property); }.bind(this));
this.update_property(div, field, property);
},
update_property: function(div, field, prop) {
if (!prop || prop == "innerHTML") {
return div.update($F(field));
} else {
return eval("div." + prop + " = '" + $F(field).replace('"', """) + "'");
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment