Skip to content

Commit

Permalink
feat: add all mouseEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
rajatkhanna82 committed Aug 11, 2014
1 parent 968b09a commit cbd875b
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 166 deletions.
148 changes: 66 additions & 82 deletions dist/famous-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,47 @@
* @link https:/Famous/famous-angular
* @license MPL v2.0
*/
'use strict';
var ngFameApp = angular.module('famous.angular', []);
// 'use strict';

window.$famousUtils = function() {

var SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g;
var MOZ_HACK_REGEXP = /^moz([A-Z])/;

/**
* Converts snake_case to camelCase.
* Also there is special case for Moz prefix starting with upper case letter.
* @param name Name to normalize
*/
function camelCase(name) {
return name.
replace(SPECIAL_CHARS_REGEXP, function(_, separator, letter, offset) {
return offset ? letter.toUpperCase() : letter;
}).
replace(MOZ_HACK_REGEXP, 'Moz$1');
}

var PREFIX_REGEXP = /^(x[\:\-_]|data[\:\-_])/i;

return {
/**
* @description Converts all accepted directives format into proper directive name.
* All of these will become 'myDirective':
* my:Directive
* my-directive
* x-my-directive
* data-my:directive
*
* Also there is special case for Moz prefix starting with upper case letter.
* @param name Name to normalize
*/
directiveNormalize: function(name) {
return camelCase(name.replace(PREFIX_REGEXP, ''));
}
};
}();
var ngFameApp = angular.module('famous.angular', ['ngTouch']);

/**
* @ngdoc provider
* @name $famousProvider
Expand Down Expand Up @@ -215,6 +254,8 @@ ngFameApp.provider('$famous', function() {
return _modules;
};
});


/**
* @ngdoc service
* @name $animate
Expand Down Expand Up @@ -1655,6 +1696,7 @@ angular.module('famous.angular')
* @restrict A
* @param {expression} faClick {@link https://docs.angularjs.org/guide/expression Expression} to evaluate upon
* click. ({@link https://docs.angularjs.org/guide/expression#-event- Event object is available as `$event`})
* @deprecated true
* @description
* This directive allows you to specify custom behavior when an element is clicked.
*
Expand Down Expand Up @@ -1707,66 +1749,30 @@ 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')
.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.ngClick) {
var renderNode = (isolate.renderNode._eventInput || isolate.renderNode);
.directive('faClick', ["$parse", "$famousDecorator", function ($parse, $famousDecorator) {
return {
restrict: 'A',
compile: function () {
return {
post: function (scope, element, attrs) {
var isolate = $famousDecorator.ensureIsolate(scope);

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

/**
* @ngdoc directive
Expand Down Expand Up @@ -2727,28 +2733,6 @@ angular.module('famous.angular')
return part.getPosition();
};

//TODO: make a stand-alone window-level utility
// object to store stuff like this
/* Copied from angular.js */
var SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g;
var MOZ_HACK_REGEXP = /^moz([A-Z])/;

function camelCase(name) {
return name.
replace(SPECIAL_CHARS_REGEXP,function (_, separator, letter, offset) {
return offset ? letter.toUpperCase() : letter;
}).
replace(MOZ_HACK_REGEXP, 'Moz$1');
}

var PREFIX_REGEXP = /^(x[\:\-_]|data[\:\-_])/i;

function directiveNormalize(name) {
return camelCase(name.replace(PREFIX_REGEXP, ''));
}

/* end copy from angular.js */

var _transformFields = [
"aboutOrigin",
"perspective",
Expand All @@ -2769,7 +2753,7 @@ angular.module('famous.angular')

var _parsedTransforms = {};
angular.forEach(_transformFields, function (field) {
var attrName = directiveNormalize('fa-' + field);
var attrName = window.$famousUtils.directiveNormalize('fa-' + field);
attrs.$observe(attrName, function () {
_parsedTransforms[field] = $parse(attrs[attrName]);
});
Expand Down
2 changes: 1 addition & 1 deletion dist/famous-angular.min.js

Large diffs are not rendered by default.

79 changes: 22 additions & 57 deletions src/scripts/directives/fa-click.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @restrict A
* @param {expression} faClick {@link https://docs.angularjs.org/guide/expression Expression} to evaluate upon
* click. ({@link https://docs.angularjs.org/guide/expression#-event- Event object is available as `$event`})
* @deprecated true
* @description
* This directive allows you to specify custom behavior when an element is clicked.
*
Expand Down Expand Up @@ -57,63 +58,27 @@
* };
* ```
*/

// .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')
.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.ngClick) {
var renderNode = (isolate.renderNode._eventInput || isolate.renderNode);
.directive('faClick', ["$parse", "$famousDecorator", function ($parse, $famousDecorator) {
return {
restrict: 'A',
compile: function () {
return {
post: function (scope, element, attrs) {
var isolate = $famousDecorator.ensureIsolate(scope);

renderNode.on("click", function (data) {
var fn = $parse(attrs.ngClick);
fn(scope, {$event: data});
if (!scope.$$phase){
scope.$apply();
}
});
}
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();
}
});
}
};
}else {
console.log("compile in normal");
return compile(element , attrs, transclude);
}
};
return $delegate;
});
});
}
};
}
};
}])
24 changes: 1 addition & 23 deletions src/scripts/directives/fa-modifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,28 +238,6 @@ angular.module('famous.angular')
return part.getPosition();
};

//TODO: make a stand-alone window-level utility
// object to store stuff like this
/* Copied from angular.js */
var SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g;
var MOZ_HACK_REGEXP = /^moz([A-Z])/;

function camelCase(name) {
return name.
replace(SPECIAL_CHARS_REGEXP,function (_, separator, letter, offset) {
return offset ? letter.toUpperCase() : letter;
}).
replace(MOZ_HACK_REGEXP, 'Moz$1');
}

var PREFIX_REGEXP = /^(x[\:\-_]|data[\:\-_])/i;

function directiveNormalize(name) {
return camelCase(name.replace(PREFIX_REGEXP, ''));
}

/* end copy from angular.js */

var _transformFields = [
"aboutOrigin",
"perspective",
Expand All @@ -280,7 +258,7 @@ angular.module('famous.angular')

var _parsedTransforms = {};
angular.forEach(_transformFields, function (field) {
var attrName = directiveNormalize('fa-' + field);
var attrName = window.$famousUtils.directiveNormalize('fa-' + field);
attrs.$observe(attrName, function () {
_parsedTransforms[field] = $parse(attrs[attrName]);
});
Expand Down
42 changes: 40 additions & 2 deletions src/scripts/module.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
'use strict';
var ngFameApp = angular.module('famous.angular', []);
// 'use strict';

window.$famousUtils = function() {

var SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g;
var MOZ_HACK_REGEXP = /^moz([A-Z])/;

/**
* Converts snake_case to camelCase.
* Also there is special case for Moz prefix starting with upper case letter.
* @param name Name to normalize
*/
function camelCase(name) {
return name.
replace(SPECIAL_CHARS_REGEXP, function(_, separator, letter, offset) {
return offset ? letter.toUpperCase() : letter;
}).
replace(MOZ_HACK_REGEXP, 'Moz$1');
}

var PREFIX_REGEXP = /^(x[\:\-_]|data[\:\-_])/i;

return {
/**
* @description Converts all accepted directives format into proper directive name.
* All of these will become 'myDirective':
* my:Directive
* my-directive
* x-my-directive
* data-my:directive
*
* Also there is special case for Moz prefix starting with upper case letter.
* @param name Name to normalize
*/
directiveNormalize: function(name) {
return camelCase(name.replace(PREFIX_REGEXP, ''));
}
};
}();
var ngFameApp = angular.module('famous.angular', ['ngTouch']);
3 changes: 2 additions & 1 deletion src/scripts/services/famous.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,5 @@ ngFameApp.provider('$famous', function() {

return _modules;
};
});
});

0 comments on commit cbd875b

Please sign in to comment.