completed the xml tests - and lots of them run successfully
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -433,7 +433,8 @@ module.exports = function() {
|
||||
position: this.getPosition(),
|
||||
object: this.parent.getCustomType(),
|
||||
length: 1,
|
||||
changedBy: o.uid.creator
|
||||
changedBy: o.uid.creator,
|
||||
oldValue: this.val()
|
||||
}
|
||||
]);
|
||||
};
|
||||
|
||||
@@ -1,50 +1,11 @@
|
||||
var dont_proxy, json_types_uninitialized, proxy_token, _proxy,
|
||||
var json_types_uninitialized,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
|
||||
json_types_uninitialized = require("./JsonTypes");
|
||||
|
||||
proxy_token = false;
|
||||
|
||||
dont_proxy = function(f) {
|
||||
var e;
|
||||
proxy_token = true;
|
||||
try {
|
||||
f();
|
||||
} catch (_error) {
|
||||
e = _error;
|
||||
proxy_token = false;
|
||||
throw new Error(e);
|
||||
}
|
||||
return proxy_token = false;
|
||||
};
|
||||
|
||||
_proxy = function(f_name, f) {
|
||||
var old_f;
|
||||
old_f = this[f_name];
|
||||
if (old_f != null) {
|
||||
return this[f_name] = function() {
|
||||
var args, that, _ref;
|
||||
if (!proxy_token && !((_ref = this._y) != null ? _ref.isDeleted() : void 0)) {
|
||||
that = this;
|
||||
args = arguments;
|
||||
return dont_proxy(function() {
|
||||
f.apply(that, args);
|
||||
return old_f.apply(that, args);
|
||||
});
|
||||
} else {
|
||||
return old_f.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof Element !== "undefined" && Element !== null) {
|
||||
Element.prototype._proxy = _proxy;
|
||||
}
|
||||
|
||||
module.exports = function(HB) {
|
||||
var TextNodeType, XmlType, json_types, parser, types;
|
||||
var XmlType, json_types, parser, types;
|
||||
json_types = json_types_uninitialized(HB);
|
||||
types = json_types.types;
|
||||
parser = json_types.parser;
|
||||
@@ -52,234 +13,11 @@ module.exports = function(HB) {
|
||||
__extends(XmlType, _super);
|
||||
|
||||
function XmlType(uid, _at_tagname, attributes, elements, _at_xml) {
|
||||
var attr, d, element, i, n, word, _i, _j, _len, _ref, _ref1, _ref2;
|
||||
this.tagname = _at_tagname;
|
||||
this.xml = _at_xml;
|
||||
|
||||
/* In case you make this instanceof Insert again
|
||||
if prev? and (not next?) and prev.type?
|
||||
* adjust what you actually mean. you want to insert after prev, then
|
||||
* next is not defined. but we only insert after non-deleted elements.
|
||||
* This is also handled in TextInsert.
|
||||
while prev.isDeleted()
|
||||
prev = prev.prev_cl
|
||||
next = prev.next_cl
|
||||
*/
|
||||
XmlType.__super__.constructor.call(this, uid);
|
||||
if (((_ref = this.xml) != null ? _ref._y : void 0) != null) {
|
||||
d = new types.Delete(void 0, this.xml._y);
|
||||
HB.addOperation(d).execute();
|
||||
this.xml._y = null;
|
||||
}
|
||||
if ((attributes != null) && (elements != null)) {
|
||||
this.saveOperation('attributes', attributes);
|
||||
this.saveOperation('elements', elements);
|
||||
} else if ((attributes == null) && (elements == null)) {
|
||||
this.attributes = new types.JsonType();
|
||||
this.attributes.setMutableDefault('immutable');
|
||||
HB.addOperation(this.attributes).execute();
|
||||
this.elements = new types.WordType();
|
||||
this.elements.parent = this;
|
||||
HB.addOperation(this.elements).execute();
|
||||
} else {
|
||||
throw new Error("Either define attribute and elements both, or none of them");
|
||||
}
|
||||
if (this.xml != null) {
|
||||
this.tagname = this.xml.tagName;
|
||||
for (i = _i = 0, _ref1 = this.xml.attributes.length; 0 <= _ref1 ? _i < _ref1 : _i > _ref1; i = 0 <= _ref1 ? ++_i : --_i) {
|
||||
attr = xml.attributes[i];
|
||||
this.attributes.val(attr.name, attr.value);
|
||||
}
|
||||
_ref2 = this.xml.childNodes;
|
||||
for (_j = 0, _len = _ref2.length; _j < _len; _j++) {
|
||||
n = _ref2[_j];
|
||||
if (n.nodeType === n.TEXT_NODE) {
|
||||
word = new TextNodeType(void 0, n);
|
||||
HB.addOperation(word).execute();
|
||||
this.elements.push(word);
|
||||
} else if (n.nodeType === n.ELEMENT_NODE) {
|
||||
element = new XmlType(void 0, void 0, void 0, void 0, n);
|
||||
HB.addOperation(element).execute();
|
||||
this.elements.push(element);
|
||||
} else {
|
||||
throw new Error("I don't know Node-type " + n.nodeType + "!!");
|
||||
}
|
||||
}
|
||||
this.setXmlProxy();
|
||||
}
|
||||
void 0;
|
||||
}
|
||||
|
||||
XmlType.prototype.type = "XmlType";
|
||||
|
||||
XmlType.prototype.applyDelete = function(op) {
|
||||
if ((this.insert_parent != null) && !this.insert_parent.isDeleted()) {
|
||||
return this.insert_parent.applyDelete(op);
|
||||
} else {
|
||||
this.attributes.applyDelete();
|
||||
this.elements.applyDelete();
|
||||
return XmlType.__super__.applyDelete.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
XmlType.prototype.cleanup = function() {
|
||||
return XmlType.__super__.cleanup.call(this);
|
||||
};
|
||||
|
||||
XmlType.prototype.setXmlProxy = function() {
|
||||
var findNode, insertBefore, removeChild, renewClassList, that;
|
||||
this.xml._y = this;
|
||||
that = this;
|
||||
this.elements.on('insert', function(event, op) {
|
||||
var newNode, right, rightNode;
|
||||
if (op.creator !== HB.getUserId() && this === that.elements) {
|
||||
newNode = op.content.val();
|
||||
right = op.next_cl;
|
||||
while ((right != null) && right.isDeleted()) {
|
||||
right = right.next_cl;
|
||||
}
|
||||
rightNode = null;
|
||||
if (right.type !== 'Delimiter') {
|
||||
rightNode = right.val().val();
|
||||
}
|
||||
return dont_proxy(function() {
|
||||
return that.xml.insertBefore(newNode, rightNode);
|
||||
});
|
||||
}
|
||||
});
|
||||
this.elements.on('delete', function(event, op) {
|
||||
var del_op, deleted;
|
||||
del_op = op.deleted_by[0];
|
||||
if ((del_op != null) && del_op.creator !== HB.getUserId() && this === that.elements) {
|
||||
deleted = op.content.val();
|
||||
return dont_proxy(function() {
|
||||
return that.xml.removeChild(deleted);
|
||||
});
|
||||
}
|
||||
});
|
||||
this.attributes.on(['add', 'update'], function(event, property_name, op) {
|
||||
if (op.creator !== HB.getUserId() && this === that.attributes) {
|
||||
return dont_proxy(function() {
|
||||
var newval;
|
||||
newval = op.val().val();
|
||||
if (newval != null) {
|
||||
return that.xml.setAttribute(property_name, op.val().val());
|
||||
} else {
|
||||
return that.xml.removeAttribute(property_name);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
findNode = function(child) {
|
||||
var elem;
|
||||
if (child == null) {
|
||||
throw new Error("you must specify a parameter!");
|
||||
}
|
||||
child = child._y;
|
||||
elem = that.elements.beginning.next_cl;
|
||||
while (elem.type !== 'Delimiter' && elem.content !== child) {
|
||||
elem = elem.next_cl;
|
||||
}
|
||||
if (elem.type === 'Delimiter') {
|
||||
return false;
|
||||
} else {
|
||||
return elem;
|
||||
}
|
||||
};
|
||||
insertBefore = function(insertedNode_s, adjacentNode) {
|
||||
var child, element, inserted_nodes, next, prev, _results;
|
||||
next = null;
|
||||
if (adjacentNode != null) {
|
||||
next = findNode(adjacentNode);
|
||||
}
|
||||
prev = null;
|
||||
if (next) {
|
||||
prev = next.prev_cl;
|
||||
} else {
|
||||
prev = this._y.elements.end.prev_cl;
|
||||
while (prev.isDeleted()) {
|
||||
prev = prev.prev_cl;
|
||||
}
|
||||
}
|
||||
inserted_nodes = null;
|
||||
if (insertedNode_s.nodeType === insertedNode_s.DOCUMENT_FRAGMENT_NODE) {
|
||||
child = insertedNode_s.lastChild;
|
||||
_results = [];
|
||||
while (child != null) {
|
||||
element = new XmlType(void 0, void 0, void 0, void 0, child);
|
||||
HB.addOperation(element).execute();
|
||||
that.elements.insertAfter(prev, element);
|
||||
_results.push(child = child.previousSibling);
|
||||
}
|
||||
return _results;
|
||||
} else {
|
||||
element = new XmlType(void 0, void 0, void 0, void 0, insertedNode_s);
|
||||
HB.addOperation(element).execute();
|
||||
return that.elements.insertAfter(prev, element);
|
||||
}
|
||||
};
|
||||
this.xml._proxy('insertBefore', insertBefore);
|
||||
this.xml._proxy('appendChild', insertBefore);
|
||||
this.xml._proxy('removeAttribute', function(name) {
|
||||
return that.attributes.val(name, void 0);
|
||||
});
|
||||
this.xml._proxy('setAttribute', function(name, value) {
|
||||
return that.attributes.val(name, value);
|
||||
});
|
||||
renewClassList = function(newclass) {
|
||||
var dont_do_it, elem, value, _i, _len;
|
||||
dont_do_it = false;
|
||||
if (newclass != null) {
|
||||
for (_i = 0, _len = this.length; _i < _len; _i++) {
|
||||
elem = this[_i];
|
||||
if (newclass === elem) {
|
||||
dont_do_it = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
value = Array.prototype.join.call(this, " ");
|
||||
if ((newclass != null) && !dont_do_it) {
|
||||
value += " " + newclass;
|
||||
}
|
||||
return that.attributes.val('class', value);
|
||||
};
|
||||
_proxy.call(this.xml.classList, 'add', renewClassList);
|
||||
_proxy.call(this.xml.classList, 'remove', renewClassList);
|
||||
this.xml.__defineSetter__('className', function(val) {
|
||||
return this.setAttribute('class', val);
|
||||
});
|
||||
this.xml.__defineGetter__('className', function() {
|
||||
return that.attributes.val('class');
|
||||
});
|
||||
this.xml.__defineSetter__('textContent', function(val) {
|
||||
var elem, remove, text_node;
|
||||
elem = that.xml.firstChild;
|
||||
while (elem != null) {
|
||||
remove = elem;
|
||||
elem = elem.nextSibling;
|
||||
that.xml.removeChild(remove);
|
||||
}
|
||||
if (val !== "") {
|
||||
text_node = document.createTextNode(val);
|
||||
return that.xml.appendChild(text_node);
|
||||
}
|
||||
});
|
||||
removeChild = function(node) {
|
||||
var d, elem;
|
||||
elem = findNode(node);
|
||||
if (!elem) {
|
||||
throw new Error("You are only allowed to delete existing (direct) child elements!");
|
||||
}
|
||||
d = new types.Delete(void 0, elem);
|
||||
HB.addOperation(d).execute();
|
||||
return node._y = null;
|
||||
};
|
||||
this.xml._proxy('removeChild', removeChild);
|
||||
return this.xml._proxy('replaceChild', function(insertedNode, replacedNode) {
|
||||
insertBefore.call(this, insertedNode, replacedNode);
|
||||
return removeChild.call(this, replacedNode);
|
||||
});
|
||||
};
|
||||
XmlType.prototype.setXmlProxy = function() {};
|
||||
|
||||
XmlType.prototype.val = function(enforce) {
|
||||
var a, attr, attr_name, e, n, text_node, value;
|
||||
@@ -351,54 +89,9 @@ module.exports = function(HB) {
|
||||
return XmlType;
|
||||
|
||||
})(types.Insert);
|
||||
parser['XmlType'] = function(json) {
|
||||
return parser['XmlType'] = function(json) {
|
||||
var attributes, elements, tagname, uid;
|
||||
uid = json['uid'], attributes = json['attributes'], elements = json['elements'], tagname = json['tagname'];
|
||||
return new XmlType(uid, tagname, attributes, elements, void 0);
|
||||
};
|
||||
TextNodeType = (function(_super) {
|
||||
__extends(TextNodeType, _super);
|
||||
|
||||
function TextNodeType(uid, content) {
|
||||
var d;
|
||||
if (content._y != null) {
|
||||
d = new types.Delete(void 0, content._y);
|
||||
HB.addOperation(d).execute();
|
||||
content._y = null;
|
||||
}
|
||||
content._y = this;
|
||||
TextNodeType.__super__.constructor.call(this, uid, content);
|
||||
}
|
||||
|
||||
TextNodeType.prototype.applyDelete = function(op) {
|
||||
if ((this.insert_parent != null) && !this.insert_parent.isDeleted()) {
|
||||
return this.insert_parent.applyDelete(op);
|
||||
} else {
|
||||
return TextNodeType.__super__.applyDelete.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
TextNodeType.prototype.type = "TextNodeType";
|
||||
|
||||
TextNodeType.prototype._encode = function() {
|
||||
var json;
|
||||
json = {
|
||||
'type': this.type,
|
||||
'uid': this.getUid(),
|
||||
'content': this.content.textContent
|
||||
};
|
||||
return json;
|
||||
};
|
||||
|
||||
return TextNodeType;
|
||||
|
||||
})(types.ImmutableObject);
|
||||
parser['TextNodeType'] = function(json) {
|
||||
var content, textnode, uid;
|
||||
uid = json['uid'], content = json['content'];
|
||||
textnode = document.createTextNode(content);
|
||||
return new TextNodeType(uid, textnode);
|
||||
};
|
||||
types['XmlType'] = XmlType;
|
||||
return json_types;
|
||||
};
|
||||
|
||||
@@ -1,78 +1,131 @@
|
||||
var YXml;
|
||||
var YXml, dont_proxy, initialize_proxies, proxies_are_initialized, proxy_token;
|
||||
|
||||
YXml = (function() {
|
||||
function YXml(tagname, attributes) {
|
||||
var a, a_name, c, c_name, _classes, _i, _len, _ref;
|
||||
function YXml(tag_or_dom, attributes) {
|
||||
var a, a_name, c, c_name, tagname, _classes, _i, _len, _ref;
|
||||
if (attributes == null) {
|
||||
attributes = {};
|
||||
}
|
||||
this._xml = {};
|
||||
this._xml.tagname = tagname;
|
||||
if (attributes.constructor !== Object) {
|
||||
throw new Error("The attributes must be specified as a Object");
|
||||
}
|
||||
for (a_name in attributes) {
|
||||
a = attributes[a_name];
|
||||
if (a.constructor !== String) {
|
||||
throw new Error("The attributes must be of type String!");
|
||||
if (tag_or_dom == null) {
|
||||
|
||||
} else if (tag_or_dom.constructor === String) {
|
||||
tagname = tag_or_dom;
|
||||
this._xml = {};
|
||||
this._xml.children = [];
|
||||
this._xml.tagname = tagname;
|
||||
if (attributes.constructor !== Object) {
|
||||
throw new Error("The attributes must be specified as a Object");
|
||||
}
|
||||
}
|
||||
this._xml.attributes = attributes;
|
||||
this._xml.classes = {};
|
||||
_classes = this._xml.attributes["class"];
|
||||
delete this._xml.attributes["class"];
|
||||
if (_classes != null) {
|
||||
_ref = _classes.split(" ");
|
||||
for (c = _i = 0, _len = _ref.length; _i < _len; c = ++_i) {
|
||||
c_name = _ref[c];
|
||||
if (c.length > 0) {
|
||||
this._xml.classes[c_name] = c;
|
||||
for (a_name in attributes) {
|
||||
a = attributes[a_name];
|
||||
if (a.constructor !== String) {
|
||||
throw new Error("The attributes must be of type String!");
|
||||
}
|
||||
}
|
||||
this._xml.attributes = attributes;
|
||||
this._xml.classes = {};
|
||||
_classes = this._xml.attributes["class"];
|
||||
delete this._xml.attributes["class"];
|
||||
if (_classes != null) {
|
||||
_ref = _classes.split(" ");
|
||||
for (c = _i = 0, _len = _ref.length; _i < _len; c = ++_i) {
|
||||
c_name = _ref[c];
|
||||
if (c.length > 0) {
|
||||
this._xml.classes[c_name] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
void 0;
|
||||
} else if (tag_or_dom instanceof Element) {
|
||||
this._dom = tag_or_dom;
|
||||
this._xml = {};
|
||||
}
|
||||
void 0;
|
||||
}
|
||||
|
||||
YXml.prototype._name = "Xml";
|
||||
|
||||
YXml.prototype._getModel = function(Y, ops) {
|
||||
var attribute, c, child, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
|
||||
if (this._model == null) {
|
||||
if (this._dom != null) {
|
||||
this._xml.tagname = this._dom.tagName.toLowerCase();
|
||||
this._xml.attributes = {};
|
||||
this._xml.classes = {};
|
||||
_ref = this._dom.attributes;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
attribute = _ref[_i];
|
||||
if (attribute.name === "class") {
|
||||
_ref1 = attribute.value.split(" ");
|
||||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||
c = _ref1[_j];
|
||||
this._xml.classes[c] = true;
|
||||
}
|
||||
} else {
|
||||
this._xml.attributes[attribute.name] = attribute.value;
|
||||
}
|
||||
}
|
||||
this._xml.children = [];
|
||||
_ref2 = this._dom.childNodes;
|
||||
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
|
||||
child = _ref2[_k];
|
||||
if (child.nodeType === child.TEXT_NODE) {
|
||||
this._xml.children.push(child.textContent);
|
||||
} else {
|
||||
this._xml.children.push(new YXml(child));
|
||||
}
|
||||
}
|
||||
}
|
||||
this._model = new ops.MapManager(this).execute();
|
||||
this._model.val("attributes", new Y.Object(this._xml.attributes));
|
||||
this._model.val("classes", new Y.Object(this._xml.classes));
|
||||
this._model.val("tagname", this._xml.tagname);
|
||||
this._model.val("children", new Y.List());
|
||||
this._model.val("children", new Y.List(this._xml.children));
|
||||
if (this._xml.parent != null) {
|
||||
this._model.val("parent", this._xml.parent);
|
||||
}
|
||||
if (this._dom != null) {
|
||||
this.getDom();
|
||||
}
|
||||
this._setModel(this._model);
|
||||
}
|
||||
this._setModel(this._model);
|
||||
return this._model;
|
||||
};
|
||||
|
||||
YXml.prototype._setModel = function(_at__model) {
|
||||
this._model = _at__model;
|
||||
delete this._xml;
|
||||
return this._model.observe(function(events) {
|
||||
var c, children, event, i, parent, _i, _j, _len, _len1, _ref;
|
||||
this._model.observe(function(events) {
|
||||
var c, children, event, i, parent, _i, _len, _ref, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = events.length; _i < _len; _i++) {
|
||||
event = events[_i];
|
||||
if (event.name === "parent" && event.type !== "add") {
|
||||
parent = event.oldValue;
|
||||
children = (_ref = parent._model.val("children")) != null ? _ref.val() : void 0;
|
||||
if (children != null) {
|
||||
for (i = _j = 0, _len1 = children.length; _j < _len1; i = ++_j) {
|
||||
c = children[i];
|
||||
if (c === this) {
|
||||
parent._model.val("children")["delete"](i);
|
||||
break;
|
||||
_results.push((function() {
|
||||
var _j, _len1, _results1;
|
||||
_results1 = [];
|
||||
for (i = _j = 0, _len1 = children.length; _j < _len1; i = ++_j) {
|
||||
c = children[i];
|
||||
if (c === this) {
|
||||
parent._model.val("children")["delete"](i);
|
||||
break;
|
||||
} else {
|
||||
_results1.push(void 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return _results1;
|
||||
}).call(this));
|
||||
} else {
|
||||
_results.push(void 0);
|
||||
}
|
||||
} else {
|
||||
_results.push(void 0);
|
||||
}
|
||||
}
|
||||
return void 0;
|
||||
return _results;
|
||||
});
|
||||
return delete this._xml;
|
||||
};
|
||||
|
||||
YXml.prototype._setParent = function(parent) {
|
||||
@@ -294,10 +347,225 @@ YXml = (function() {
|
||||
return this._model.val("children").val();
|
||||
};
|
||||
|
||||
YXml.prototype.getPosition = function() {
|
||||
var c, i, parent, _i, _len, _ref;
|
||||
parent = this._model.val("parent");
|
||||
if (parent != null) {
|
||||
_ref = parent._model.val("children").val();
|
||||
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
||||
c = _ref[i];
|
||||
if (c === this) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
throw new Error("This is not a child of its parent (should not happen in Y.Xml!)");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
YXml.prototype.getDom = function() {
|
||||
var attr_name, attr_value, child, dom, i, that, _i, _len, _ref, _ref1;
|
||||
if (this._dom == null) {
|
||||
this._dom = document.createElement(this._model.val("tagname"));
|
||||
_ref = this.attr();
|
||||
for (attr_name in _ref) {
|
||||
attr_value = _ref[attr_name];
|
||||
this._dom.setAttribute(attr_name, attr_value);
|
||||
}
|
||||
_ref1 = this.getChildren();
|
||||
for (i = _i = 0, _len = _ref1.length; _i < _len; i = ++_i) {
|
||||
child = _ref1[i];
|
||||
if (child.constructor === String) {
|
||||
dom = document.createTextNode(child);
|
||||
} else {
|
||||
dom = child.getDom();
|
||||
}
|
||||
this._dom.insertBefore(dom);
|
||||
}
|
||||
}
|
||||
that = this;
|
||||
if (this._dom._y_xml == null) {
|
||||
this._dom._y_xml = this;
|
||||
initialize_proxies.call(this);
|
||||
this._model.val("children").observe(function(events) {
|
||||
var children, deleted, event, newNode, rightNode, _j, _len1, _results;
|
||||
_results = [];
|
||||
for (_j = 0, _len1 = events.length; _j < _len1; _j++) {
|
||||
event = events[_j];
|
||||
if (event.type === "insert") {
|
||||
newNode = event.value.getDom();
|
||||
children = that._dom.childNodes;
|
||||
if (children.length > 0) {
|
||||
rightNode = children[0];
|
||||
} else {
|
||||
rightNode = null;
|
||||
}
|
||||
event.value._setParent(that);
|
||||
_results.push(dont_proxy(function() {
|
||||
return that._dom.insertBefore(newNode, rightNode);
|
||||
}));
|
||||
} else if (event.type === "delete") {
|
||||
deleted = event.oldValue.getDom();
|
||||
_results.push(dont_proxy(function() {
|
||||
return that._dom.removeChild(deleted);
|
||||
}));
|
||||
} else {
|
||||
_results.push(void 0);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
});
|
||||
this._model.val("attributes").observe(function(events) {
|
||||
var event, newval, _j, _len1, _results;
|
||||
_results = [];
|
||||
for (_j = 0, _len1 = events.length; _j < _len1; _j++) {
|
||||
event = events[_j];
|
||||
if (event.type === "add" || event.type === "update") {
|
||||
newval = event.object.val(event.name);
|
||||
_results.push(dont_proxy(function() {
|
||||
return that._dom.setAttribute(event.name, newval);
|
||||
}));
|
||||
} else if (event.type === "delete") {
|
||||
_results.push(dont_proxy(function() {
|
||||
return that._dom.removeAttribute(event.name);
|
||||
}));
|
||||
} else {
|
||||
_results.push(void 0);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
});
|
||||
this._model.val("classes").observe(function(events) {
|
||||
var event, _j, _len1, _results;
|
||||
_results = [];
|
||||
for (_j = 0, _len1 = events.length; _j < _len1; _j++) {
|
||||
event = events[_j];
|
||||
if (event.type === "add" || event.type === "update") {
|
||||
_results.push(dont_proxy(function() {
|
||||
return that._dom.classList.add(event.name);
|
||||
}));
|
||||
} else if (event.type === "delete") {
|
||||
_results.push(dont_proxy(function() {
|
||||
return that._dom.classList.remove(event.name);
|
||||
}));
|
||||
} else {
|
||||
_results.push(void 0);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
});
|
||||
}
|
||||
return this._dom;
|
||||
};
|
||||
|
||||
return YXml;
|
||||
|
||||
})();
|
||||
|
||||
proxies_are_initialized = false;
|
||||
|
||||
proxy_token = false;
|
||||
|
||||
dont_proxy = function(f) {
|
||||
var e;
|
||||
proxy_token = true;
|
||||
try {
|
||||
f();
|
||||
} catch (_error) {
|
||||
e = _error;
|
||||
proxy_token = false;
|
||||
throw new Error(e);
|
||||
}
|
||||
return proxy_token = false;
|
||||
};
|
||||
|
||||
initialize_proxies = function() {
|
||||
var insertBefore, removeChild, replaceChild, that, _proxy;
|
||||
_proxy = function(f_name, f, source) {
|
||||
var old_f;
|
||||
if (source == null) {
|
||||
source = Element.prototype;
|
||||
}
|
||||
old_f = source[f_name];
|
||||
return source[f_name] = function() {
|
||||
if ((this._y_xml == null) || proxy_token) {
|
||||
return old_f.apply(this, arguments);
|
||||
} else {
|
||||
return f.apply(this._y_xml, arguments);
|
||||
}
|
||||
};
|
||||
};
|
||||
that = this;
|
||||
this._dom.classList.add = function(c) {
|
||||
return that.addClass(c);
|
||||
};
|
||||
this._dom.classList.remove = function(c) {
|
||||
return that.removeClass(c);
|
||||
};
|
||||
this._dom.__defineSetter__('className', function(val) {
|
||||
return that.attr('class', val);
|
||||
});
|
||||
this._dom.__defineGetter__('className', function() {
|
||||
return that.attr('class');
|
||||
});
|
||||
this._dom.__defineSetter__('textContent', function(val) {
|
||||
that.empty();
|
||||
if (val !== "") {
|
||||
return that.append(val);
|
||||
}
|
||||
});
|
||||
if (proxies_are_initialized) {
|
||||
return;
|
||||
}
|
||||
proxies_are_initialized = true;
|
||||
insertBefore = function(insertedNode_s, adjacentNode) {
|
||||
var child, new_childs, pos;
|
||||
if (adjacentNode != null) {
|
||||
pos = adjacentNode._y_xml.getPosition();
|
||||
} else {
|
||||
pos = this.getChildren().length;
|
||||
}
|
||||
new_childs = [];
|
||||
if (insertedNode_s.nodeType === insertedNode_s.DOCUMENT_FRAGMENT_NODE) {
|
||||
child = insertedNode_s.firstChild;
|
||||
while (child != null) {
|
||||
new_childs.push(child);
|
||||
child = child.nextSibling;
|
||||
}
|
||||
} else {
|
||||
new_childs.push(insertedNode_s);
|
||||
}
|
||||
new_childs = new_childs.map(function(child) {
|
||||
if (child._y_xml != null) {
|
||||
return child._y_xml;
|
||||
} else if (child.nodeType === child.TEXT_NODE) {
|
||||
return child.textContent;
|
||||
} else {
|
||||
return new YXml(child);
|
||||
}
|
||||
});
|
||||
return this._model.val("children").insertContents(pos, new_childs);
|
||||
};
|
||||
_proxy('insertBefore', insertBefore);
|
||||
_proxy('appendChild', insertBefore);
|
||||
_proxy('removeAttribute', function(name) {
|
||||
return this.removeAttr(name);
|
||||
});
|
||||
_proxy('setAttribute', function(name, value) {
|
||||
return this.attr(name, value);
|
||||
});
|
||||
removeChild = function(node) {
|
||||
return node._y_xml.remove();
|
||||
};
|
||||
_proxy('removeChild', removeChild, this._dom);
|
||||
replaceChild = function(insertedNode, replacedNode) {
|
||||
insertBefore.call(this, insertedNode, replacedNode);
|
||||
return removeChild.call(this, replacedNode);
|
||||
};
|
||||
return _proxy('replaceChild', replaceChild, this._dom);
|
||||
};
|
||||
|
||||
if (typeof window !== "undefined" && window !== null) {
|
||||
if (window.Y != null) {
|
||||
window.Y.Xml = YXml;
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -2,7 +2,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test Yjs!</title>
|
||||
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
|
||||
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
|
||||
Reference in New Issue
Block a user