mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-06-19 06:36:15 +08:00
committed by
Michał Gołębiowski
parent
b9389b26ba
commit
1a05daf5dc
@@ -46,6 +46,7 @@
|
||||
* - [`contents()`](http://api.jquery.com/contents/)
|
||||
* - [`css()`](http://api.jquery.com/css/)
|
||||
* - [`data()`](http://api.jquery.com/data/)
|
||||
* - [`detach()`](http://api.jquery.com/detach/)
|
||||
* - [`empty()`](http://api.jquery.com/empty/)
|
||||
* - [`eq()`](http://api.jquery.com/eq/)
|
||||
* - [`find()`](http://api.jquery.com/find/) - Limited to lookups by tag name
|
||||
@@ -437,6 +438,12 @@ function jqLiteEmpty(element) {
|
||||
}
|
||||
}
|
||||
|
||||
function jqLiteRemove(element, keepData) {
|
||||
if (!keepData) jqLiteDealoc(element);
|
||||
var parent = element.parentNode;
|
||||
if (parent) parent.removeChild(element);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////
|
||||
// Functions which are declared directly.
|
||||
//////////////////////////////////////////
|
||||
@@ -536,7 +543,7 @@ forEach({
|
||||
return jqLiteInheritedData(element, '$injector');
|
||||
},
|
||||
|
||||
removeAttr: function(element,name) {
|
||||
removeAttr: function(element, name) {
|
||||
element.removeAttribute(name);
|
||||
},
|
||||
|
||||
@@ -890,10 +897,10 @@ forEach({
|
||||
wrapNode.appendChild(element);
|
||||
},
|
||||
|
||||
remove: function(element) {
|
||||
jqLiteDealoc(element);
|
||||
var parent = element.parentNode;
|
||||
if (parent) parent.removeChild(element);
|
||||
remove: jqLiteRemove,
|
||||
|
||||
detach: function(element) {
|
||||
jqLiteRemove(element, true);
|
||||
},
|
||||
|
||||
after: function(element, newElement) {
|
||||
|
||||
@@ -460,6 +460,20 @@ describe('jqLite', function() {
|
||||
}));
|
||||
|
||||
|
||||
it('should keep data if an element is removed via detach()', function() {
|
||||
var root = jqLite('<div><span>abc</span></div>'),
|
||||
span = root.find('span'),
|
||||
data = span.data();
|
||||
|
||||
span.data('foo', 'bar');
|
||||
span.detach();
|
||||
|
||||
expect(data).toEqual({foo: 'bar'});
|
||||
|
||||
span.remove();
|
||||
});
|
||||
|
||||
|
||||
it('should retrieve all data if called without params', function() {
|
||||
var element = jqLite(a);
|
||||
expect(element.data()).toEqual({});
|
||||
@@ -1586,6 +1600,16 @@ describe('jqLite', function() {
|
||||
});
|
||||
|
||||
|
||||
describe('detach', function() {
|
||||
it('should detach', function() {
|
||||
var root = jqLite('<div><span>abc</span></div>');
|
||||
var span = root.find('span');
|
||||
expect(span.detach()).toEqual(span);
|
||||
expect(root.html()).toEqual('');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('after', function() {
|
||||
it('should after', function() {
|
||||
var root = jqLite('<div><span></span></div>');
|
||||
|
||||
Reference in New Issue
Block a user