-
Notifications
You must be signed in to change notification settings - Fork 4
/
gk-firebase.html
60 lines (48 loc) · 1.26 KB
/
gk-firebase.html
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
<script src="https://cdn.firebase.com/js/client/1.0.19/firebase.js"></script>
<element name="gk-firebase">
<template>
<div id="{{id}}" root="{{root}}"></div>
</template>
<script>
var utils = require('./js/utils'),
properties = ['root'];
function getPageId($ele) {
return '#' + $ele.closest('[data-role="page"]').attr('id');
}
registerElement('gk-firebase', {
rootRef: null,
init: function() {
var self = this;
utils.exposeProperties(properties, self,
function(attr) {
return self.$ele.attr(attr);
},
function(attr, val) {
self.$ele.attr(attr, val);
if (attr === 'root') {
self.rootRef = new Firebase(self.root);
}
}
);
if ($.mobile) {
$(document).on('pageinit', getPageId(self.$ele), function() {
self.rootRef = new Firebase(self.root);
});
} else {
$(document).on('gkComponentsReady', function() {
self.rootRef = new Firebase(self.root);
});
}
},
ref: function(path) {
return this.rootRef.child(path);
},
online: function() {
Firebase.goOnline();
},
offline: function() {
Firebase.goOffline();
}
});
</script>
</element>