Skip to content

Commit

Permalink
Add optional slide attribute in revealToggle
Browse files Browse the repository at this point in the history
Used jQuery to add a slideDown/slideUp animation.
  • Loading branch information
LFDM committed Jul 7, 2014
1 parent 97aa29c commit eda9e7d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/js/arethusa.core/directives/reveal_toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ angular.module('arethusa.core').directive('revealToggle', function() {
link: function(scope, element, attrs) {
var tId = attrs.revealToggle;
var alwaysReveal = attrs.alwaysReveal;
var slide = attrs.slide;


function el() {
return angular.element(document.getElementById(tId));
Expand All @@ -14,9 +16,11 @@ angular.module('arethusa.core').directive('revealToggle', function() {
element.bind('click', function() {
var t = el();
if (alwaysReveal || t.hasClass('hide')) {
if (slide) t.slideDown();
t.removeClass('hide');
t.trigger('show-' + tId);
} else {
if (slide) t.slideUp();
t.addClass('hide');
t.trigger('hide-' + tId);
}
Expand Down
10 changes: 8 additions & 2 deletions spec/arethusa.core/directives/reveal_toggle_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ describe("revealToggle", function() {
var element;
beforeEach(module("arethusa.core"));

function stubFunctions(obj, functions) {
angular.forEach(functions, function(functionName, i) {
obj[functionName] = function() {};
});
}

beforeEach(inject(function($compile, $rootScope) {
element = angular.element('<p><span reveal-toggle="1"/><target id="1"/></p>');
// We're using a jQuery function in this directive!
angular.element.prototype.trigger = function() {};
// We're using jQuery functions in this directive!
stubFunctions(angular.element.prototype, ['trigger', 'slideUp', 'slideDown']);
$compile(element)($rootScope);
}));

Expand Down

0 comments on commit eda9e7d

Please sign in to comment.