Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit f3e04fb

Browse files
Di PengIgorMinar
Di Peng
authored andcommitted
fix(ng:show/ng:hide): use jqLite.show/jqLite.hide
The previous implementation didn't handle situation when in css something was hidden with a cascaded display:none rule and then we wanted to show it. Unfortunatelly our test doesn't test this scenario because it's too complicated. :-/
1 parent 00ea08e commit f3e04fb

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

src/Angular.js

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ var _undefined = undefined,
6969
$function = 'function',
7070
$length = 'length',
7171
$name = 'name',
72-
$none = 'none',
7372
$noop = 'noop',
7473
$null = 'null',
7574
$number = 'number',

src/directives.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ angularDirective("ng:class-even", ngClass(function(i){return i % 2 === 1;}));
733733
angularDirective("ng:show", function(expression, element){
734734
return function(element){
735735
this.$onEval(function(){
736-
element.css($display, toBoolean(this.$eval(expression)) ? '' : $none);
736+
toBoolean(this.$eval(expression)) ? element.show() : element.hide();
737737
}, element);
738738
};
739739
});
@@ -774,7 +774,7 @@ angularDirective("ng:show", function(expression, element){
774774
angularDirective("ng:hide", function(expression, element){
775775
return function(element){
776776
this.$onEval(function(){
777-
element.css($display, toBoolean(this.$eval(expression)) ? $none : '');
777+
toBoolean(this.$eval(expression)) ? element.hide() : element.show();
778778
}, element);
779779
};
780780
});

test/directivesSpec.js

+32-14
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,40 @@ describe("directive", function(){
252252
expect(element.hasClass('ng-exception')).toBeFalsy();
253253
});
254254

255-
it('should ng:show', function(){
256-
var scope = compile('<div ng:hide="hide"></div>');
257-
scope.$eval();
258-
expect(isCssVisible(scope.$element)).toEqual(true);
259-
scope.$set('hide', true);
260-
scope.$eval();
261-
expect(isCssVisible(scope.$element)).toEqual(false);
255+
256+
describe('ng:show', function() {
257+
it('should show and hide an element', function(){
258+
var element = jqLite('<div ng:show="exp"></div>'),
259+
scope = compile(element);
260+
261+
expect(isCssVisible(element)).toEqual(false);
262+
scope.exp = true;
263+
scope.$eval();
264+
expect(isCssVisible(element)).toEqual(true);
265+
});
266+
267+
268+
it('should make hidden element visible', function() {
269+
var element = jqLite('<div style="display: none" ng:show="exp"></div>'),
270+
scope = compile(element);
271+
272+
expect(isCssVisible(element)).toBe(false);
273+
scope.exp = true;
274+
scope.$eval();
275+
expect(isCssVisible(element)).toBe(true);
276+
});
262277
});
263278

264-
it('should ng:hide', function(){
265-
var scope = compile('<div ng:show="show"></div>');
266-
scope.$eval();
267-
expect(isCssVisible(scope.$element)).toEqual(false);
268-
scope.$set('show', true);
269-
scope.$eval();
270-
expect(isCssVisible(scope.$element)).toEqual(true);
279+
describe('ng:hide', function() {
280+
it('should hide an element', function(){
281+
var element = jqLite('<div ng:hide="exp"></div>'),
282+
scope = compile(element);
283+
284+
expect(isCssVisible(element)).toBe(true);
285+
scope.exp = true;
286+
scope.$eval();
287+
expect(isCssVisible(element)).toBe(false);
288+
});
271289
});
272290

273291
describe('ng:controller', function(){

0 commit comments

Comments
 (0)