Permalink
Browse files

Support multiple elements in putAway / putBack

  • Loading branch information...
1 parent d2d6a09 commit ae45207108c1ac1095d1d040c5cb67fdd64955e3 @hofmeister committed Feb 3, 2014
Showing with 22 additions and 18 deletions.
  1. +22 −18 js/lib/utils.js
View
@@ -1037,28 +1037,32 @@
//Temporarily detach element to reduce dom changes when doing alot of manipulating. Reintroduce it into the dom
//using "putBack"
$.fn.putAway = function() {
- var elm = $(this[0]);
- if (elm.closest('body').length == 0) return;//Already removed from dom
- elm.data('parent',elm.parent())
- .data('prev',elm.prev());
- elm.detach();
+ $(this).each(function() {
+ var elm = $(this);
+ if (elm.closest('body').length == 0) return;//Already removed from dom
+ elm.data('parent',elm.parent())
+ .data('prev',elm.prev());
+ elm.detach();
+ });
};
$.fn.putBack = function() {
- var elm = $(this[0]);
- if (elm.closest('body').length > 0) return;//Already in dom
-
- var parent = elm.data('parent');
- var prev = elm.data('prev');
- if (!parent) return; //Not detached using putAway
- if (!prev || prev.length == 0) {
- parent.prepend(elm);
- } else {
- prev.after(elm);
- }
+ $(this).each(function() {
+ var elm = $(this);
+ if (elm.closest('body').length > 0) return;//Already in dom
- elm.data('parent',null);
- elm.data('prev',null);
+ var parent = elm.data('parent');
+ var prev = elm.data('prev');
+ if (!parent) return; //Not detached using putAway
+ if (!prev || prev.length == 0) {
+ parent.prepend(elm);
+ } else {
+ prev.after(elm);
+ }
+
+ elm.data('parent',null);
+ elm.data('prev',null);
+ });
};

0 comments on commit ae45207

Please sign in to comment.