Skip to content

Commit

Permalink
html publish tags working
Browse files Browse the repository at this point in the history
  • Loading branch information
luiseduardobrito committed Sep 17, 2013
1 parent 2fb2bb2 commit 326d50a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 19 additions & 2 deletions client/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@

var action = $(this).attr("data-action") || "(function(){})();";

// execute script in private context
(new Function( "with(this) { " + action + " }")).call(this);
(new Function( "with(this) { try {" + action + "} catch(e){ throw e; } }")).call(this);
});

}; exports.publish = publish;
Expand Down Expand Up @@ -160,6 +159,24 @@

return false;
})

$("[data-event][data-on]").each(function(){

$(this).on($(this).attr("data-on") || "", function(e){

if(e && e.preventDefault) e.preventDefault();

var evt = $(this).attr("data-event");
var pub = $(this).attr("data-pub") || "return null";

pub = JSON.parse.call(this, pub);

window.sandbox.broadcast.publish(evt, pub);
return false;

});

});
}

var init = function(){
Expand Down
4 changes: 3 additions & 1 deletion views/layout.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<!-- styles -->
<link href="/assets/stylesheets/style.css" rel="stylesheet">
</head>
<body>
<body data-subscribe="app/destroy" data-action="$(this).remove()">

<section class="header" data-subscribe="user/logout" data-action="$(this).remove();">
<b>Title:</b> <%- title %>
Expand All @@ -28,6 +28,8 @@
</div>
</section>

<button data-on="click" data-event="app/destroy" data-pub='{"msg": "app destroyed by user"}'>Destroy app</button>

<!-- system deps -->
<script src="/socket.io/socket.io.js"></script>
<script src="/js/lib/jquery.min.js"></script>
Expand Down

0 comments on commit 326d50a

Please sign in to comment.