Sha256: 1b7b14e8f07dff66d2ef690643b00df20933b0546fe9a2db497183921c064df9
Contents?: true
Size: 907 Bytes
Versions: 11
Compression:
Stored size: 907 Bytes
Contents
App.DataBinder = (object_id, model_name) -> # Use a jQuery object as simple PubSub pubSub = jQuery({}) # We expect a `data` element specifying the binding # in the form: data-bind-<object_id>="<property_name>" data_attr = "input" message = object_id + ":change" jQuery(document).on "keydown", "[data-input]", (evt) -> $input = jQuery(this) pubSub.trigger message, [ $input.data(data_attr) $input.val() ] # PubSub propagates changes to all bound elements, setting value of # input tags or HTML content of other tags pubSub.on message, (evt, prop_name, new_val, id) -> # model_name = "purchase-order" model_elem = jQuery("[data-model-" + model_name + "=" + object_id + "]") attr_elm = model_elem.find("[data-attr=" + prop_name + "]") input_elm = $("[data-input=" + prop_name + "]") input_elm.val new_val attr_elm.html new_val pubSub
Version data entries
11 entries across 11 versions & 2 rubygems