twinstone / tdi

Turbocharged DOM Infusion
Apache License 2.0
6 stars 1 forks source link

Allow custom attributes for default update/insert instructions #12

Closed mishal closed 7 years ago

mishal commented 7 years ago

Our use case:

<update target="#target" custom-attribute="value" />

Js hook:

$(document).on('tdi:ajax:beforeUpdate', function (e, eventData) {
  var $target = eventData.target;
  // there no access to the original tag attributes
});

As per docs there are several properties of the event playload available, but there is no access to the original tag attributes (like in _onBeforeUnknown).

I patched the TDI function which triggers the event and includes the additional tag attributes. I can now access the tag attribute:

$(document).on('tdi:ajax:beforeUpdate', function (e, eventData) {
  var $target = eventData.target;
  var $tag = eventData.tag;
  var customAttribute = eventData.attributes['custom-attribute'];
  // do something cool :-)
});

We use the attribute to decide if the UI should highlight another element. We used script instructions before, but it was problematic.

Could TDI include the additional/original tag attributes for update and insert instructions?

centi commented 7 years ago

Maybe I could pass the whole XML tag structure. You could extract the attributes from it yourself but also have the possibility to do something more with the tag.

mishal commented 7 years ago

yes, that would be more flexible.

mishal commented 7 years ago

what name will be the best? (I can prepare the PR). simple tag: $tag would work for me.

centi commented 7 years ago

Yes, "tag" is OK.

mishal commented 7 years ago

PR #23