1
0
Fork 0
mirror of https://github.com/kbparagua/paloma synced 2023-03-27 23:21:17 -04:00

refactor hook

This commit is contained in:
kbparagua 2016-03-02 00:16:09 +08:00
parent 8ac945ce96
commit 5e782c5bf7
2 changed files with 20 additions and 16 deletions

View file

@ -3,26 +3,30 @@
<div class="js-paloma-hook" data-palomaid="<%= id %>"> <div class="js-paloma-hook" data-palomaid="<%= id %>">
<script type="text/javascript"> <script type="text/javascript">
(function(){ (function(){
// Do not continue if Paloma not found.
if (window['Paloma'] === undefined) {
return true;
}
if (window['Paloma'] === undefined) return true;
Paloma.env = '<%= Rails.env %>'; Paloma.env = '<%= Rails.env %>';
// Remove any callback details if any var id = "<%= id %>",
var hook = request = <%= request.to_json.html_safe %>;
document.querySelector("[data-palomaid='" + <%= id %> + "']")[0];
if (hook) hook.parentNode.removeChild(hook);
var request = <%= request.to_json.html_safe %>;
Paloma.engine.setRequest({ Paloma.engine.setRequest({
id: "<%= id %>", id: id,
resource: request['resource'], resource: request.resource,
action: request['action'], action: request.action,
params: request['params']}); params: request.params
});
// Remove old hooks
var hooks = document.getElementsByClassName('js-paloma-hook');
for (var i = 0, n = hooks.length; i < n; i++){
var hook = hooks[i],
palomaid = hook.dataset.palomaid.toString();
if (palomaid != id) hook.parentNode.removeChild(hook);
}
})(); })();
</script> </script>
</div> </div>

View file

@ -13,7 +13,7 @@
//= require jquery //= require jquery
//= require jquery.turbolinks //= require jquery.turbolinks
//= require jquery_ujs //= require jquery_ujs
//=# require turbolinks //= require turbolinks
//= require paloma //= require paloma
//= require_tree . //= require_tree .