Skip to content

Commit

Permalink
feat: decorate ng-click to register on renderNode in fa-directives
Browse files Browse the repository at this point in the history
  • Loading branch information
rajatkhanna82 committed Aug 11, 2014
1 parent 864bd8b commit 968b09a
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 45 deletions.
76 changes: 55 additions & 21 deletions dist/famous-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -1708,31 +1708,65 @@ angular.module('famous.angular')
* ```
*/

// .directive('faClick', ["$parse", "$famousDecorator", function ($parse, $famousDecorator) {
// return {
// restrict: 'A',
// compile: function () {
// return {
// post: function (scope, element, attrs) {
// var isolate = $famousDecorator.ensureIsolate(scope);

// if (attrs.faClick) {
// var renderNode = (isolate.renderNode._eventInput || isolate.renderNode);

// renderNode.on("click", function (data) {
// var fn = $parse(attrs.faClick);
// fn(scope, {$event: data});
// if (!scope.$$phase){
// scope.$apply();
// }
// });
// }
// }
// };
// }
// };
// }])
angular.module('famous.angular')
.directive('faClick', ["$parse", "$famousDecorator", function ($parse, $famousDecorator) {
return {
restrict: 'A',
compile: function () {
return {
post: function (scope, element, attrs) {
var isolate = $famousDecorator.ensureIsolate(scope);
.config(function($provide) {
$provide.decorator('ngClickDirective', function($delegate, $famousDecorator, $parse) {
var directive = $delegate[0];

if (attrs.faClick) {
var renderNode = (isolate.renderNode._eventInput || isolate.renderNode);
var compile = directive.compile;
directive.compile = function(element , attrs, transclude) {
var isFa = /^FA\-.*/;
if(isFa.test(element[0].tagName)) {
console.log("compile in",element[0]);
return {
post: function (scope, element, attrs) {
var isolate = $famousDecorator.ensureIsolate(scope);

renderNode.on("click", function (data) {
var fn = $parse(attrs.faClick);
fn(scope, {$event: data});
if (!scope.$$phase){
scope.$apply();
}
});
if (attrs.ngClick) {
var renderNode = (isolate.renderNode._eventInput || isolate.renderNode);

renderNode.on("click", function (data) {
var fn = $parse(attrs.ngClick);
fn(scope, {$event: data});
if (!scope.$$phase){
scope.$apply();
}
});
}
}
}
};
}
};
}]);
};
}else {
console.log("compile in normal");
return compile(element , attrs, transclude);
}
};
return $delegate;
});
});

/**
* @ngdoc directive
Expand Down
2 changes: 1 addition & 1 deletion dist/famous-angular.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion famous-angular-docs
2 changes: 1 addition & 1 deletion famous-angular-examples
76 changes: 55 additions & 21 deletions src/scripts/directives/fa-click.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,62 @@
* ```
*/

// .directive('faClick', ["$parse", "$famousDecorator", function ($parse, $famousDecorator) {
// return {
// restrict: 'A',
// compile: function () {
// return {
// post: function (scope, element, attrs) {
// var isolate = $famousDecorator.ensureIsolate(scope);

// if (attrs.faClick) {
// var renderNode = (isolate.renderNode._eventInput || isolate.renderNode);

// renderNode.on("click", function (data) {
// var fn = $parse(attrs.faClick);
// fn(scope, {$event: data});
// if (!scope.$$phase){
// scope.$apply();
// }
// });
// }
// }
// };
// }
// };
// }])
angular.module('famous.angular')
.directive('faClick', ["$parse", "$famousDecorator", function ($parse, $famousDecorator) {
return {
restrict: 'A',
compile: function () {
return {
post: function (scope, element, attrs) {
var isolate = $famousDecorator.ensureIsolate(scope);
.config(function($provide) {
$provide.decorator('ngClickDirective', function($delegate, $famousDecorator, $parse) {
var directive = $delegate[0];

var compile = directive.compile;
directive.compile = function(element , attrs, transclude) {
var isFa = /^FA\-.*/;
if(isFa.test(element[0].tagName)) {
console.log("compile in",element[0]);
return {
post: function (scope, element, attrs) {
var isolate = $famousDecorator.ensureIsolate(scope);

if (attrs.faClick) {
var renderNode = (isolate.renderNode._eventInput || isolate.renderNode);
if (attrs.ngClick) {
var renderNode = (isolate.renderNode._eventInput || isolate.renderNode);

renderNode.on("click", function (data) {
var fn = $parse(attrs.faClick);
fn(scope, {$event: data});
if (!scope.$$phase){
scope.$apply();
}
});
renderNode.on("click", function (data) {
var fn = $parse(attrs.ngClick);
fn(scope, {$event: data});
if (!scope.$$phase){
scope.$apply();
}
});
}
}
}
};
}
};
}]);
};
}else {
console.log("compile in normal");
return compile(element , attrs, transclude);
}
};
return $delegate;
});
});
1 change: 1 addition & 0 deletions src/scripts/famous
Submodule famous added at 81850e

0 comments on commit 968b09a

Please sign in to comment.