-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathz-app.js
43 lines (35 loc) · 962 Bytes
/
z-app.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
define(function(require) {
var rootClassName = 'z-app'
, rootSelector = '.' + rootClassName
, root = document.querySelector(rootSelector) || document.body
, findClosest = require('./find-closest')
, api = {}
api.isRoot = isRoot
api.root = getRoot
api.clearResource = clearResource
api.resource = resource
api.rootResource = rootResource
api.rootClassName = function() { return rootClassName }
return api
function isRoot(node) {
return root == node
}
function clearResource(node) {
node.__resource__ = null
return true
}
function rootResource() {
return resource(root)
}
function resource(node, value) {
if (arguments.length != 2) return node.__resource__
node.__resource__ = value
}
function getRoot(origin) {
if (!origin) return root
return findLocalRoot(origin)
}
function findLocalRoot(origin) {
return findClosest.bySelector(rootSelector, origin, root)
}
})