Skip to content

Instantly share code, notes, and snippets.

View juanmf's full-sized avatar
💭
I may be slow to respond.

Juan Manuel Fernandez juanmf

💭
I may be slow to respond.
View GitHub Profile
/**
* Recursive Prototype Clonner:
* it relies on the following data structure:
* <someAncestor data-allow-add="true"> ...
* <button class="" data-add="add"
* data-add-prototype-node="JQ selector relative to $button.closest('[data-allow-add]'). Will be parameter of $obj.find($selector)"
* data-add-prototype-name="<?php echo $prototypeName; ?> optional, defauts to __name__"
* data-add-append-node="%data-add-prototype-node% | JQ selector relative to $button.closest('[data-allow-add]').
* Will be parameter of $obj.find($selector)"
* data-add-wrapper="html to wrap the cloned item before appending e.g. <li>__PROTOTYPE-CONTENT__</li>"
/*
* I needed it 'cause I have a generic js to add embeded subForms to a Form
* appending the prototype upon AddButton JQuery click event. So to add event
* bindings to one of the controls generated out of the prototype template, which
* is unknown to the js that adds it, I fire a message like "prototype_just_added"
* and the specific js catches it and binds the event.
*/
/*
* MediatorPatter implementaton to allow for some behavior extensions.