mirror of https://github.com/artf/grapesjs.git
7 changed files with 71 additions and 36 deletions
@ -1,4 +1,30 @@ |
|||||
|
import { bindAll } from 'underscore'; |
||||
import Backbone from 'backbone'; |
import Backbone from 'backbone'; |
||||
import model from './Frame'; |
import model from './Frame'; |
||||
|
|
||||
export default Backbone.Collection.extend({ model }); |
export default Backbone.Collection.extend({ |
||||
|
model, |
||||
|
|
||||
|
initialize() { |
||||
|
bindAll(this, 'itemLoaded'); |
||||
|
}, |
||||
|
|
||||
|
itemLoaded() { |
||||
|
this.loadedItems++; |
||||
|
|
||||
|
if (this.loadedItems >= this.itemsToLoad) { |
||||
|
this.trigger('loaded:all'); |
||||
|
this.listenToLoadItems(0); |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
listenToLoad() { |
||||
|
this.loadedItems = 0; |
||||
|
this.itemsToLoad = this.length; |
||||
|
this.listenToLoadItems(1); |
||||
|
}, |
||||
|
|
||||
|
listenToLoadItems(on) { |
||||
|
this.forEach(item => item[on ? 'on' : 'off']('loaded', this.itemLoaded)); |
||||
|
} |
||||
|
}); |
||||
|
|||||
Loading…
Reference in new issue