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

Commit 4c8eaa1

Browse files
committed
refactor(jqLite): remove jqLite show/hide support
it turns out that even with our tricks, jqLite#show is not usable in practice and definitely not on par with jQuery. so rather than introducing half-baked apis which introduce issues, I'm removing them. I also removed show/hide uses from docs, since they are not needed. Breaks jqLite.hide/jqLite.show which are no longer available.
1 parent 4ba35eb commit 4c8eaa1

File tree

6 files changed

+2
-95
lines changed

6 files changed

+2
-95
lines changed

docs/src/templates/doc_widgets.css

-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
@namespace doc url("http://docs.angularjs.org/");
2-
3-
doc\:example {
4-
display: none;
5-
}
6-
71
ul.doc-example {
82
list-style-type: none;
93
position: relative;

docs/src/templates/doc_widgets.js

-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
angular.widget('doc:example', function(element){
2525
this.descend(true); //compile the example code
26-
element.hide();
2726

2827
//jQuery find() methods in this widget contain primitive selectors on purpose so that we can use
2928
//jqlite instead. jqlite's find() method currently supports onlt getElementsByTagName!
@@ -53,7 +52,6 @@
5352

5453
element.html('');
5554
element.append(tabs);
56-
element.show();
5755

5856
var script = (exampleSrc.match(/<script[^\>]*>([\s\S]*)<\/script>/) || [])[1] || '';
5957
try {

src/Angular.js

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ var _undefined = undefined,
6464
$boolean = 'boolean',
6565
$console = 'console',
6666
$date = 'date',
67-
$display = 'display',
6867
$element = 'element',
6968
$function = 'function',
7069
$length = 'length',

src/directives.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ angularDirective("ng:class-even", ngClass(function(i){return i % 2 === 1;}));
738738
angularDirective("ng:show", function(expression, element){
739739
return function(element){
740740
this.$onEval(function(){
741-
toBoolean(this.$eval(expression)) ? element.show() : element.hide();
741+
element.css('display', toBoolean(this.$eval(expression)) ? '' : 'none');
742742
}, element);
743743
};
744744
});
@@ -779,7 +779,7 @@ angularDirective("ng:show", function(expression, element){
779779
angularDirective("ng:hide", function(expression, element){
780780
return function(element){
781781
this.$onEval(function(){
782-
toBoolean(this.$eval(expression)) ? element.hide() : element.show();
782+
element.css('display', toBoolean(this.$eval(expression)) ? 'none' : '');
783783
}, element);
784784
};
785785
});

src/jqLite.js

-28
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
* - [text()](http://api.jquery.com/text/)
4848
* - [trigger()](http://api.jquery.com/trigger/)
4949
* - [eq()](http://api.jquery.com/eq/)
50-
* - [show()](http://api.jquery.com/show/)
51-
* - [hide()](http://api.jquery.com/hide/)
5250
*
5351
* ## Additionally these methods extend the jQuery and are available in both jQuery and jQuery lite
5452
* version:
@@ -456,32 +454,6 @@ forEach({
456454
return element.getElementsByTagName(selector);
457455
},
458456

459-
hide: function(element) {
460-
if (element.style) {
461-
if(element.style.display !=="none" && !JQLiteData(element,"olddisplay")) {
462-
JQLiteData( element, "olddisplay", element.style.display);
463-
}
464-
element.style.display = "none";
465-
}
466-
},
467-
468-
show: function(element) {
469-
if(element.style) {
470-
var display = element.style.display;
471-
if ( display === "" || display === "none" ) {
472-
473-
// restore the original value overwritten by hide if present or default to nothing (which
474-
// will let browser correctly choose between 'inline' or 'block')
475-
element.style.display = JQLiteData(element, "olddisplay") || "";
476-
477-
// if the previous didn't make the element visible then there are some cascading rules that
478-
// are still hiding it, so let's default to 'block', which might be incorrect in case of
479-
// elmenents that should be 'inline' by default, but oh well :-)
480-
if (!isVisible([element])) element.style.display = "block";
481-
}
482-
}
483-
},
484-
485457
clone: JQLiteClone
486458
}, function(fn, name){
487459
/**

test/jqLiteSpec.js

-56
Original file line numberDiff line numberDiff line change
@@ -511,62 +511,6 @@ describe('jqLite', function(){
511511
});
512512

513513

514-
describe('hide', function() {
515-
var element;
516-
517-
afterEach(function() {
518-
if (element) dealoc(element);
519-
});
520-
521-
it('should hide the element', function() {
522-
element = jqLite('<div></div>');
523-
expect(isCssVisible(element)).toBe(true);
524-
element.hide();
525-
expect(isCssVisible(element)).toBe(false);
526-
});
527-
});
528-
529-
530-
describe('show', function() {
531-
var element;
532-
533-
afterEach(function() {
534-
if (element) dealoc(element);
535-
element.remove();
536-
});
537-
538-
539-
it('should show the element ', function() {
540-
element = jqLite('<div></div>');
541-
element[0].style.display = 'none';
542-
expect(isCssVisible(element)).toBe(false);
543-
element.show();
544-
expect(isCssVisible(element)).toBe(true);
545-
});
546-
547-
548-
it('should show previously hidden element and preserve the display value', function() {
549-
element = jqLite('<div style="display:inline">xx</div>');
550-
jqLite(document.body).append(element);
551-
element.hide();
552-
expect(isCssVisible(element)).toBe(false);
553-
element.show();
554-
expect(element[0].style.display).toBe('inline');
555-
expect(isCssVisible(element)).toBe(true);
556-
557-
element[0].style.display = 'block';
558-
element.hide();
559-
expect(isCssVisible(element)).toBe(false);
560-
element.show();
561-
expect(isCssVisible(element)).toBe(true);
562-
563-
// this totally doesn't make sense, it should be 'block', but jquery (1.4.2+1.6.2) behaves
564-
// this way.
565-
expect(element[0].style.display).toBe('inline');
566-
});
567-
});
568-
569-
570514
describe('eq', function() {
571515
it('should select the nth element ', function() {
572516
var element = jqLite('<div><span>aa</span></div><div><span>bb</span></div>');

0 commit comments

Comments
 (0)