Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var InteractionManager = function(options) {
- _.bindAll(this, "reposition", "_reposition");
- this.options = _.defaults(options || {}, {
- fromTop: 50,
- margin: 20
- });
- this.items = [];
- };
- InteractionManager.prototype = {
- add: function(scope, selector) {
- if(!scope.bind) { throw "Item must respond to '.bind'" }
- if(_.any(this.items, function(other) { return scope.cid == other.scope.cid })) { return; }
- this.items.push({scope: scope, selector: selector});
- scope.bind("element:reposition", this.reposition);
- },
- reposition: function() {
- var allItems = _.extend([], this.items);
- this._reposition(allItems);
- },
- _reposition: function(list){
- var object = list.pop();
- if(!object) { return this.options.fromTop; }
- var offset = this._reposition(list);
- var el = object.scope.$(object.selector)
- , manager = this;
- if(!el.is(':visible')) { return offset; }
- el.clearQueue().animate({'top': offset});
- offset = offset + el.outerHeight(true) + manager.options.margin;
- return offset;
- }
- };
- _.extend(InteractionManager.prototype, Backbone.Events);
Add Comment
Please, Sign In to add comment