-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.js
149 lines (134 loc) · 2.69 KB
/
demo.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"use strict";
/*global module, require*/
var d3 = require("d3"),
body = d3.select(document.body),
coll = "demo",
model = {
text: "type here"
},
text = body.append("textarea")
.on("input", function(d, i) {
model.text = text.node().value;
})
.style("position", "absolute")
.style("bottom", "1em")
.style("left", "1em")
.style("height", "5em")
.style("width", "100%"),
identity = function(o) {
return o;
},
toggle = false,
menuModule = require("./js/index.js")(
coll,
"demo",
identity,
identity,
function() {
return model;
},
function(val) {
model = val;
text.node().value = val.text;
},
function() {
return {
text: "type here"
};
}),
spec = menuModule.spec,
menu = menuModule.buildMenu(body);
menu.setButtons(
menu.standardButtons.ordered.concat
([
spec.button(
/*
This button searches a collection and alerts when a user clicks a result.
*/
"Example",
null,
function(result) {
alert("Searched the test collection and found " + result);
},
{
onlineOffline: {
online: true,
offline: false
},
search: {
collection: coll,
excludeTerms: spec.matchEmpty,
includeSearchTerm: true
}
}
),
spec.button(
/*
This button changes text every time the title of the page changes.
It is an anchor tag instead of a div.
*/
"Hook",
null,
function() {
// Noop
},
{
hooks: function(button) {
menuModule.store.onNavigate(function(newTitle, newVersion) {
button.text("Title: " + newTitle);
});
}
}
),
spec.button(
/*
Embeds an iframe in the page.
*/
"Embed iframe",
null,
function() {
body.append("iframe")
.attr("src", document.location)
.style("width", "400px")
.style("height", "400px")
.style("position", "absolute")
.style("right", 0)
.style("bottom", 0);
},
{}
),
spec.button(
/*
Makes an arbitrary change to the iframe's query string, allowing us to test it's messaging and history stuff.
*/
"Push history",
null,
function() {
menuModule.queryString.param(
"random",
function(val) {
console.log("random", val);
},
function() {
return Math.random();
}
);
menuModule.queryString.toURL();
},
{}
),
spec.button(
"Toggle",
function() {
return toggle;
},
function(wasActive) {
toggle = !wasActive;
},
{}
)
]));
menuModule.queryString.fromURL();
window.addEventListener("message", function(event) {
console.log("iframe message", event.data, event.source.frameElement);
});