Guest User

Untitled

a guest
Jan 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. var InteractionManager = function(options) {
  2. _.bindAll(this, "reposition", "_reposition");
  3.  
  4. this.options = _.defaults(options || {}, {
  5. fromTop: 50,
  6. margin: 20
  7. });
  8.  
  9. this.items = [];
  10. };
  11.  
  12. InteractionManager.prototype = {
  13. add: function(scope, selector) {
  14. if(!scope.bind) { throw "Item must respond to '.bind'" }
  15.  
  16. if(_.any(this.items, function(other) { return scope.cid == other.scope.cid })) { return; }
  17.  
  18. this.items.push({scope: scope, selector: selector});
  19. scope.bind("element:reposition", this.reposition);
  20. },
  21.  
  22. reposition: function() {
  23. var allItems = _.extend([], this.items);
  24.  
  25. this._reposition(allItems);
  26. },
  27.  
  28. _reposition: function(list){
  29. var object = list.pop();
  30.  
  31. if(!object) { return this.options.fromTop; }
  32. var offset = this._reposition(list);
  33.  
  34. var el = object.scope.$(object.selector)
  35. , manager = this;
  36.  
  37. if(!el.is(':visible')) { return offset; }
  38.  
  39. el.clearQueue().animate({'top': offset});
  40. offset = offset + el.outerHeight(true) + manager.options.margin;
  41.  
  42. return offset;
  43. }
  44. };
  45.  
  46. _.extend(InteractionManager.prototype, Backbone.Events);
Add Comment
Please, Sign In to add comment