forked from bergie/VIE
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example-wymeditor.html
95 lines (82 loc) · 5.04 KB
/
example-wymeditor.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
93
94
95
<!doctype html>
<html
version="HTML+RDFa 1.0"
xmlns:sioc="http://rdfs.org/sioc/ns#"
xmlns:dcterms="http://purl.org/dc/terms/">
<head>
<title>VIE example</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="underscore-min.js"></script>
<script src="backbone-min.js"></script>
<script src="vie.js"></script>
<script src="vie-containermanager.js"></script>
<script src="vie-collectionmanager.js"></script>
<script src="wymeditor.js"></script>
<script src="vie-wymeditor.js"></script>
<script>
$(function($) {
// Implement our own Backbone.sync method
Backbone.sync = function(method, model, options) {
console.log(method, model.toJSONLD());
};
// Functionality for adding items
$('#addbutton').bind('click', function() {
var container = VIE.EntityManager.getBySubject('<http://example.net/blog/>').get('dcterms:hasPart').add([{}]);
VIE.Wymeditor.createEditable($('[typeof="sioc:Post"][about=""]'));
});
// Load all RDFa entities into VIE
VIE.RDFaEntities.getInstances();
// Make all RDFa entities editable
$('[typeof][about]').each(function() {
VIE.Wymeditor.createEditable(this);
});
$('#savebutton').bind('click', function() {
// Go through all Backbone model instances loaded for the page
VIE.EntityManager.entities.each(function(objectInstance) {
if (!VIE.Wymeditor.refreshFromEditables(objectInstance)) {
// No changes to this object, skip
return true;
}
// Set the modified properties to the model instance
objectInstance.save(null, {
success: function(savedModel, response) {
alert(savedModel.id + " was saved, see JS console for details");
$.each(modifiedProperties, function(propertyName, propertyValue) {
savedModel.editables[propertyName].setUnmodified();
});
},
error: function(response) {
console.log("Save failed");
}
});
});
});
$('#tweakbutton').bind('click', function() {
VIE.EntityManager.getByType('sioc:Post')[0].set({'dcterms:title': 'Hello, world!'});
});
});
</script>
</head>
<body>
<p>Click on the content below to edit it, then <button id="savebutton">Save</button>, <button id="addbutton">Add items</button> or <button id="tweakbutton">Change via JS</button>.</p>
<div about="http://example.net/blog/" rel="dcterms:hasPart" rev="dcterms:partOf">
<article typeof="sioc:Post" about="http://example.net/blog/news_item">
<h1 property="dcterms:title">News item title</h1>
<div property="sioc:content">
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
</p>
<p>
Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.
</p>
</div>
</article>
<article typeof="http://rdfs.org/sioc/ns#Post" about="http://example.net/blog/second_news_item">
<h1 property="dcterms:title">Another item</h1>
<div property="sioc:content">
<p>Hello, world!</p>
</div>
</article>
</div>
</body>
</html>