-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_priority.html
92 lines (69 loc) · 2.88 KB
/
demo_priority.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ComponentManger | Demo</title>
<link href='https://fonts.googleapis.com/css?family=Crimson+Text' rel='stylesheet' type='text/css'>
<style type="text/css">
* {
font-family: 'Crimson Text', serif;
}
button {
font-size: 1rem;
}
</style>
<script src="https://code.jquery.com/jquery-3.1.0.slim.min.js" integrity="sha256-cRpWjoSOw5KcyIOaZNo4i6fZ9tKPhYYb6i5T9RSVJG8=" crossorigin="anonymous"></script>
<script src="src/manager.js"></script>
<script src="demo/jquery.informer.js"></script>
<script src="demo/jquery.fakeLatin.js"></script>
</head>
<body>
<h1>Demo</h1>
<button id="addComponent">Add block with nested components</button>
<button id="removeComponent">Remove last block</button>
<div id="component-container"></div>
<script type="text/javascript">
// Register a component that reads the public fields of the jQuery plugin which lives on its inner <div>
ComponentManager.register(
'informer',
function(addedNode) {
// If the plugins uses options, those can be passed to the plugin here
$(addedNode).informer();
},
function(removedNode) {
// Call the destructor to allow the plugin to tear down
$(removedNode).data('plugin_informer').destroy();
},
20
);
// Register a component: a simple jQuery plugin that displays parts of "lorem ipsum"
ComponentManager.register(
'fakelatin',
function(addedNode) {
$(addedNode).fakeLatin();
},
function(removedNode) {
$(removedNode).data('plugin_fakeLatin').destroy();
},
10
);
// Tell the component manager to start listening for changes to the DOM
ComponentManager.init();
// UI code for this demo
var addComponent = function() {
var divElement = document.createElement('div');
divElement.innerHTML = '<div data-component-name="informer"><p></p><blockquote data-component-name="fakelatin"></blockquote></div>';
document.body.querySelector('#component-container').appendChild(divElement);
};
var removeComponent = function () {
var container = document.body.querySelector('#component-container');
var components = container.childNodes;
if (components.length) {
container.removeChild(components[components.length - 1]);
}
};
document.querySelector('#addComponent').addEventListener('click', addComponent, false);
document.querySelector('#removeComponent').addEventListener('click', removeComponent, false);
</script>
</body>
</html>