-
Notifications
You must be signed in to change notification settings - Fork 1
/
Manager.js
92 lines (60 loc) · 2.42 KB
/
Manager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
Siesta 1.1.0-beta-1
Copyright(c) 2009-2012 Bryntum AB
http://bryntum.com/contact
http://bryntum.com/products/siesta/license
*/
Class('Siesta.Content.Manager', {
has : {
disabled : false,
presets : {
require : true
},
urls : Joose.I.Object
},
methods : {
cache : function (callback, errback, ignoreErrors) {
if (this.disabled) {
callback && callback()
return
}
var urls = this.urls
var me = this
Joose.A.each(this.presets, function (preset) {
preset.eachResource(function (resource) {
if (resource.url) urls[ resource.url ] = null
})
})
var loadCount = 0
var errorCount = 0
var total = 0
Joose.O.each(urls, function () { total++ })
if (total)
Joose.O.each(urls, function (value, url) {
me.load(url, function (content) {
if (errorCount) return
urls[ url ] = content
if (++loadCount == total) callback && callback()
}, ignoreErrors ? function () {
if (++loadCount == total) callback && callback()
} : function () {
errorCount++
errback && errback(url)
})
})
else
callback && callback()
},
load : function (url, callback, errback) {
throw "abstract method `load` called"
},
hasContentOf : function (url) {
if (url instanceof Siesta.Content.Resource) url = url.url
return typeof this.urls[ url ] == 'string'
},
getContentOf : function (url) {
if (url instanceof Siesta.Content.Resource) url = url.url
return this.urls[ url ]
}
}
})