Angular:

http://angularjs.org/

by bennekrouf

HTML

<div ng-controller="MyCtrl">
  <div requiresLogin>
    <div like>
       <button ng-click="sayLike()">Say I like</button>
    </div>
</div>
</div>

JavaScript

var myApp = angular.module('myApp',[])
.directive('requiresLogin', function() {
    return {
        scope: true,
        controller: function() {
            this.isAuthenticated = function(){
                alert("You are not connected");
                return false;
            }
        }
    }
})
.directive('like', function() {
    return {
        scope: true,
        require: '^requiresLogin',
        controller: function($scope) {
            this.sayLike = function() {
                if($scope.requiresLoginCtrl.isAuthenticated()){
                    alert("I like !");
                }
            }
        },
        link: function(scope, element, attrs, requiresLoginCtrl) {
            scope.requiresLoginCtrl = requiresLoginCtrl
        }
    }
})
function MyCtrl($scope) {
}