Created
December 3, 2009 04:14
-
-
Save nikz/247882 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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