selectedIndex is now cloned cross-browser (#1294)

This commit is contained in:
Brandon Aaron 2007-07-21 04:26:13 +00:00
parent 9b9a793273
commit a65a811ce0

22
src/jquery/jquery.js vendored
View file

@ -852,9 +852,10 @@ jQuery.fn = jQuery.prototype = {
* @cat DOM/Manipulation * @cat DOM/Manipulation
*/ */
clone: function(deep) { clone: function(deep) {
deep = deep != undefined ? deep : true
var $this = this.add(this.find("*"));
if (jQuery.browser.msie) { if (jQuery.browser.msie) {
// Need to remove events on the element and its descendants // Need to remove events on the element and its descendants
var $this = this.add(this.find("*"));
$this.each(function() { $this.each(function() {
this._$events = {}; this._$events = {};
for (var type in this.$events) for (var type in this.$events)
@ -864,23 +865,28 @@ jQuery.fn = jQuery.prototype = {
// Do the clone // Do the clone
var r = this.pushStack( jQuery.map( this, function(a){ var r = this.pushStack( jQuery.map( this, function(a){
return a.cloneNode( deep != undefined ? deep : true ); return a.cloneNode( deep );
}) ); }) );
if (jQuery.browser.msie) { if (jQuery.browser.msie) {
// Add the events back to the original and its descendants
$this.each(function() { $this.each(function() {
// Add the events back to the original and its descendants
var events = this._$events; var events = this._$events;
for (var type in events) for (var type in events)
for (var handler in events[type]) for (var handler in events[type])
jQuery.event.add(this, type, events[type][handler], events[type][handler].data); jQuery.event.add(this, type, events[type][handler], events[type][handler].data);
this._$events = null; this._$events = null;
}); });
}
// set selected values of select elements
var selects = r.find('select'); // copy form values over
$this.filter('select').each(function(i) { if (deep) {
selects[i].selectedIndex = this.selectedIndex; var inputs = r.add(r.find('*')).filter('select,input[@type=checkbox]');
$this.filter('select,input[@type=checkbox]').each(function(i) {
if (this.selectedIndex)
inputs[i].selectedIndex = this.selectedIndex;
if (this.checked)
inputs[i].checked = true;
}); });
} }