forked from bergie/VIE
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vie-wymeditor.js
78 lines (67 loc) · 2.71 KB
/
vie-wymeditor.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
if (typeof VIE === 'undefined') {
VIE = {};
}
(function($){
VIE.Wymeditor = {
createEditable: function (element, options) {
element = $(element);
options = $.extend({
beforeEditing: null
}, options);
element.each(function() {
var containerInstance = VIE.RDFaEntities.getInstance(this);
if (!containerInstance) {
return;
}
containerInstance.editables = containerInstance.editables || {};
VIE.RDFa.findPredicateElements(containerInstance.id, this, false).each(function() {
var containerProperty = $(this);
// Call the configured beforeEditing function that may modify
// the content of the editable before editing is possible
if (_.isFunction(options.beforeEditing)) {
options.beforeEditing(containerProperty);
}
var propertyName = containerProperty.attr('property');
if (!_.isString(propertyName)) {
return true;
}
if (_.isArray(containerInstance.get(propertyName))) {
// For now we don't deal with multivalued properties in Aloha
return true;
}
containerInstance.editables[propertyName] = new Wymeditor.EditableArea(this);
containerInstance.editables[propertyName].vieContainerInstance = containerInstance;
});
});
},
refreshFromEditables: function (objectInstance) {
var modifiedProperties = {};
if (!objectInstance.editables) {
return false;
}
// Go through editables of the model instance
jQuery.each(objectInstance.editables, function(propertyName, editableInstance) {
/* Not implemented yet
if (!editableInstance.isModified()) {
// This editable hasn't been modified, skip
return true;
}
*/
// Refresh possible RDFa objects from inside the editable
jQuery('[typeof][about]', editableInstance.obj).each(function() {
var childInstance = VIE.RDFaEntities.getInstance(jQuery(this));
});
// Copy editable contents to the modifiedProperties object
modifiedProperties[propertyName] = editableInstance.html();
});
if (jQuery.isEmptyObject(modifiedProperties))
{
// No modified editables for this object, skip
return false;
}
// Set the modified properties to the model instance
objectInstance.set(modifiedProperties);
return true;
}
};
})(jQuery);