outsourced all types (except for object type)

This commit is contained in:
DadaMonad
2015-02-27 18:01:21 +00:00
parent c663230c1b
commit 96ed8b0f98
33 changed files with 94032 additions and 63591 deletions

View File

@@ -316,7 +316,7 @@ module.exports = function() {
}
this.prev_cl.next_cl = this.next_cl;
this.next_cl.prev_cl = this.prev_cl;
if (this.content instanceof ops.Operation && !deleted_earlyer) {
if (this.content instanceof ops.Operation) {
this.content.referenced_by--;
if (this.content.referenced_by <= 0 && !this.content.is_deleted) {
this.content.applyDelete();

View File

@@ -1,97 +0,0 @@
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");
module.exports = function(HB) {
var XmlType, json_types, parser, types;
json_types = json_types_uninitialized(HB);
types = json_types.types;
parser = json_types.parser;
XmlType = (function(_super) {
__extends(XmlType, _super);
function XmlType(uid, _at_tagname, attributes, elements, _at_xml) {
this.tagname = _at_tagname;
this.xml = _at_xml;
}
XmlType.prototype.setXmlProxy = function() {};
XmlType.prototype.val = function(enforce) {
var a, attr, attr_name, e, n, text_node, value;
if (enforce == null) {
enforce = false;
}
if (typeof document !== "undefined" && document !== null) {
if ((this.xml == null) || enforce) {
this.xml = document.createElement(this.tagname);
attr = this.attributes.val();
for (attr_name in attr) {
value = attr[attr_name];
if (value != null) {
a = document.createAttribute(attr_name);
a.value = value;
this.xml.setAttributeNode(a);
}
}
e = this.elements.beginning.next_cl;
while (e.type !== "Delimiter") {
n = e.content;
if (!e.isDeleted() && (e.content != null)) {
if (n.type === "XmlType") {
this.xml.appendChild(n.val(enforce));
} else if (n.type === "TextNodeType") {
text_node = n.val();
this.xml.appendChild(text_node);
} else {
throw new Error("Internal structure cannot be transformed to dom");
}
}
e = e.next_cl;
}
}
this.setXmlProxy();
return this.xml;
}
};
XmlType.prototype.execute = function() {
return XmlType.__super__.execute.call(this);
};
/*
if not @validateSavedOperations()
return false
else
return true
*/
XmlType.prototype.getParent = function() {
return this.parent;
};
XmlType.prototype._encode = function() {
var json;
json = {
'type': this.type,
'attributes': this.attributes.getUid(),
'elements': this.elements.getUid(),
'tagname': this.tagname,
'uid': this.getUid()
};
return json;
};
return XmlType;
})(types.Insert);
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);
};
};

View File

@@ -1,84 +0,0 @@
var YList;
YList = (function() {
function YList(list) {
if (list == null) {
this._list = [];
} else if (list.constructor === Array) {
this._list = list;
} else {
throw new Error("Y.List expects an Array as a parameter");
}
}
YList.prototype._name = "List";
YList.prototype._getModel = function(types, ops) {
if (this._model == null) {
this._model = new ops.ListManager(this).execute();
this._model.insert(0, this._list);
}
delete this._list;
return this._model;
};
YList.prototype._setModel = function(_at__model) {
this._model = _at__model;
return delete this._list;
};
YList.prototype.val = function() {
return this._model.val.apply(this._model, arguments);
};
YList.prototype.observe = function() {
this._model.observe.apply(this._model, arguments);
return this;
};
YList.prototype.unobserve = function() {
this._model.unobserve.apply(this._model, arguments);
return this;
};
YList.prototype.insert = function(position, content) {
if (typeof position !== "number") {
throw new Error("Y.List.insert expects a Number as the first parameter!");
}
this._model.insert(position, [content]);
return this;
};
YList.prototype.insertContents = function(position, contents) {
if (typeof position !== "number") {
throw new Error("Y.List.insert expects a Number as the first parameter!");
}
this._model.insert(position, contents);
return this;
};
YList.prototype["delete"] = function(position, length) {
this._model["delete"](position, length);
return this;
};
YList.prototype.push = function(content) {
this._model.push(content);
return this;
};
return YList;
})();
if (typeof window !== "undefined" && window !== null) {
if (window.Y != null) {
window.Y.List = YList;
} else {
throw new Error("You must first import Y!");
}
}
if (typeof module !== "undefined" && module !== null) {
module.exports = YList;
}

View File

@@ -1,335 +0,0 @@
var YText;
YText = (function() {
function YText(text) {
this.textfields = [];
if (text == null) {
this._text = "";
} else if (text.constructor === String) {
this._text = text;
} else {
throw new Error("Y.Text expects a String as a constructor");
}
}
YText.prototype._name = "Text";
YText.prototype._getModel = function(types, ops) {
if (this._model == null) {
this._model = new ops.ListManager(this).execute();
this.insert(0, this._text);
}
delete this._text;
return this._model;
};
YText.prototype._setModel = function(_at__model) {
this._model = _at__model;
return delete this._text;
};
YText.prototype.val = function() {
return this._model.fold("", function(left, o) {
return left + o.val();
});
};
YText.prototype.observe = function() {
return this._model.observe.apply(this._model, arguments);
};
YText.prototype.unobserve = function() {
return this._model.unobserve.apply(this._model, arguments);
};
YText.prototype.toString = function() {
return this.val();
};
YText.prototype.insert = function(position, content) {
var ith;
if (content.constructor !== String) {
throw new Error("Y.String.insert expects a String as the second parameter!");
}
if (typeof position !== "number") {
throw new Error("Y.String.insert expects a Number as the first parameter!");
}
if (content.length > 0) {
ith = this._model.getOperationByPosition(position);
return this._model.insertAfter(ith, content);
}
};
YText.prototype["delete"] = function(position, length) {
return this._model["delete"](position, length);
};
YText.prototype.bind = function(textfield, dom_root) {
var createRange, creator_token, t, word, writeContent, writeRange, _i, _len, _ref;
if (dom_root == null) {
dom_root = window;
}
if (dom_root.getSelection == null) {
dom_root = window;
}
_ref = this.textfields;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
t = _ref[_i];
if (t === textfield) {
return;
}
}
creator_token = false;
word = this;
textfield.value = this.val();
this.textfields.push(textfield);
if ((textfield.selectionStart != null) && (textfield.setSelectionRange != null)) {
createRange = function(fix) {
var left, right;
left = textfield.selectionStart;
right = textfield.selectionEnd;
if (fix != null) {
left = fix(left);
right = fix(right);
}
return {
left: left,
right: right
};
};
writeRange = function(range) {
writeContent(word.val());
return textfield.setSelectionRange(range.left, range.right);
};
writeContent = function(content) {
return textfield.value = content;
};
} else {
createRange = function(fix) {
var clength, edited_element, range, s;
range = {};
s = dom_root.getSelection();
clength = textfield.textContent.length;
range.left = Math.min(s.anchorOffset, clength);
range.right = Math.min(s.focusOffset, clength);
if (fix != null) {
range.left = fix(range.left);
range.right = fix(range.right);
}
edited_element = s.focusNode;
if (edited_element === textfield || edited_element === textfield.childNodes[0]) {
range.isReal = true;
} else {
range.isReal = false;
}
return range;
};
writeRange = function(range) {
var r, s, textnode;
writeContent(word.val());
textnode = textfield.childNodes[0];
if (range.isReal && (textnode != null)) {
if (range.left < 0) {
range.left = 0;
}
range.right = Math.max(range.left, range.right);
if (range.right > textnode.length) {
range.right = textnode.length;
}
range.left = Math.min(range.left, range.right);
r = document.createRange();
r.setStart(textnode, range.left);
r.setEnd(textnode, range.right);
s = window.getSelection();
s.removeAllRanges();
return s.addRange(r);
}
};
writeContent = function(content) {
var c, content_array, i, _j, _len1, _results;
content_array = content.replace(new RegExp("\n", 'g'), " ").split(" ");
textfield.innerText = "";
_results = [];
for (i = _j = 0, _len1 = content_array.length; _j < _len1; i = ++_j) {
c = content_array[i];
textfield.innerText += c;
if (i !== content_array.length - 1) {
_results.push(textfield.innerHTML += '&nbsp;');
} else {
_results.push(void 0);
}
}
return _results;
};
}
writeContent(this.val());
this.observe(function(events) {
var event, fix, o_pos, r, _j, _len1, _results;
_results = [];
for (_j = 0, _len1 = events.length; _j < _len1; _j++) {
event = events[_j];
if (!creator_token) {
if (event.type === "insert") {
o_pos = event.position;
fix = function(cursor) {
if (cursor <= o_pos) {
return cursor;
} else {
cursor += 1;
return cursor;
}
};
r = createRange(fix);
_results.push(writeRange(r));
} else if (event.type === "delete") {
o_pos = event.position;
fix = function(cursor) {
if (cursor < o_pos) {
return cursor;
} else {
cursor -= 1;
return cursor;
}
};
r = createRange(fix);
_results.push(writeRange(r));
} else {
_results.push(void 0);
}
} else {
_results.push(void 0);
}
}
return _results;
});
textfield.onkeypress = function(event) {
var char, diff, pos, r;
if (word.is_deleted) {
textfield.onkeypress = null;
return true;
}
creator_token = true;
char = null;
if (event.keyCode === 13) {
char = '\n';
} else if (event.key != null) {
if (event.charCode === 32) {
char = " ";
} else {
char = event.key;
}
} else {
char = window.String.fromCharCode(event.keyCode);
}
if (char.length > 1) {
return true;
} else if (char.length > 0) {
r = createRange();
pos = Math.min(r.left, r.right);
diff = Math.abs(r.right - r.left);
word["delete"](pos, diff);
word.insert(pos, char);
r.left = pos + char.length;
r.right = r.left;
writeRange(r);
}
event.preventDefault();
creator_token = false;
return false;
};
textfield.onpaste = function(event) {
if (word.is_deleted) {
textfield.onpaste = null;
return true;
}
return event.preventDefault();
};
textfield.oncut = function(event) {
if (word.is_deleted) {
textfield.oncut = null;
return true;
}
return event.preventDefault();
};
return textfield.onkeydown = function(event) {
var del_length, diff, new_pos, pos, r, val;
creator_token = true;
if (word.is_deleted) {
textfield.onkeydown = null;
return true;
}
r = createRange();
pos = Math.min(r.left, r.right, word.val().length);
diff = Math.abs(r.left - r.right);
if ((event.keyCode != null) && event.keyCode === 8) {
if (diff > 0) {
word["delete"](pos, diff);
r.left = pos;
r.right = pos;
writeRange(r);
} else {
if ((event.ctrlKey != null) && event.ctrlKey) {
val = word.val();
new_pos = pos;
del_length = 0;
if (pos > 0) {
new_pos--;
del_length++;
}
while (new_pos > 0 && val[new_pos] !== " " && val[new_pos] !== '\n') {
new_pos--;
del_length++;
}
word["delete"](new_pos, pos - new_pos);
r.left = new_pos;
r.right = new_pos;
writeRange(r);
} else {
if (pos > 0) {
word["delete"](pos - 1, 1);
r.left = pos - 1;
r.right = pos - 1;
writeRange(r);
}
}
}
event.preventDefault();
creator_token = false;
return false;
} else if ((event.keyCode != null) && event.keyCode === 46) {
if (diff > 0) {
word["delete"](pos, diff);
r.left = pos;
r.right = pos;
writeRange(r);
} else {
word["delete"](pos, 1);
r.left = pos;
r.right = pos;
writeRange(r);
}
event.preventDefault();
creator_token = false;
return false;
} else {
creator_token = false;
return true;
}
};
};
return YText;
})();
if (typeof window !== "undefined" && window !== null) {
if (window.Y != null) {
window.Y.Text = YText;
} else {
throw new Error("You must first import Y!");
}
}
if (typeof module !== "undefined" && module !== null) {
module.exports = YText;
}

View File

@@ -1,622 +0,0 @@
var YXml, dont_proxy, initialize_proxies, proxies_are_initialized, proxy_token;
YXml = (function() {
function YXml(tag_or_dom, attributes) {
var a, a_name, c, c_name, tagname, _classes, _i, _len, _ref;
if (attributes == null) {
attributes = {};
}
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");
}
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 = {};
}
}
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._xml.children));
if (this._xml.parent != null) {
this._model.val("parent", this._xml.parent);
}
if (this._dom != null) {
this.getDom();
}
this._setModel(this._model);
}
return this._model;
};
YXml.prototype._setModel = function(_at__model) {
this._model = _at__model;
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) {
_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 _results;
});
return delete this._xml;
};
YXml.prototype._setParent = function(parent) {
if (parent instanceof YXml) {
if (this._model != null) {
this.remove();
return this._model.val("parent", parent);
} else {
return this._xml.parent = parent;
}
} else {
throw new Error("parent must be of type Y.Xml!");
}
};
YXml.prototype.toString = function() {
var child, name, value, xml, _i, _len, _ref, _ref1;
xml = "<" + this._model.val("tagname");
_ref = this.attr();
for (name in _ref) {
value = _ref[name];
xml += " " + name + '="' + value + '"';
}
xml += ">";
_ref1 = this._model.val("children").val();
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
child = _ref1[_i];
xml += child.toString();
}
xml += '</' + this._model.val("tagname") + '>';
return xml;
};
YXml.prototype.attr = function(name, value) {
var attrs, c, classes, cs, _i, _len;
if (arguments.length > 1) {
if (value.constructor !== String) {
throw new Error("The attributes must be of type String!");
}
if (name === "class") {
classes = value.split(" ");
cs = {};
for (_i = 0, _len = classes.length; _i < _len; _i++) {
c = classes[_i];
cs[c] = true;
}
this._model.val("classes", new this._model.custom_types.Object(cs));
} else {
this._model.val("attributes").val(name, value);
}
return this;
} else if (arguments.length > 0) {
if (name === "class") {
return Object.keys(this._model.val("classes").val()).join(" ");
} else {
return this._model.val("attributes").val(name);
}
} else {
attrs = this._model.val("attributes").val();
classes = Object.keys(this._model.val("classes").val()).join(" ");
if (classes.length > 0) {
attrs["class"] = classes;
}
return attrs;
}
};
YXml.prototype.addClass = function(names) {
var name, _i, _len, _ref;
_ref = names.split(" ");
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
name = _ref[_i];
this._model.val("classes").val(name, true);
}
return this;
};
YXml.prototype.after = function() {
var c, content, contents, parent, position, _i, _j, _len, _len1, _ref;
parent = this._model.val("parent");
if (parent == null) {
throw new Error("This Xml Element must not have siblings! (for it does not have a parent)");
}
_ref = parent.getChildren();
for (position = _i = 0, _len = _ref.length; _i < _len; position = ++_i) {
c = _ref[position];
if (c === this) {
break;
}
}
contents = [];
for (_j = 0, _len1 = arguments.length; _j < _len1; _j++) {
content = arguments[_j];
if (content instanceof YXml) {
content._setParent(this._model.val("parent"));
} else if (content.constructor !== String) {
throw new Error("Y.Xml.after expects instances of YXml or String as a parameter");
}
contents.push(content);
}
return parent._model.val("children").insertContents(position + 1, contents);
};
YXml.prototype.append = function() {
var content, _i, _len;
for (_i = 0, _len = arguments.length; _i < _len; _i++) {
content = arguments[_i];
if (content instanceof YXml) {
content._setParent(this);
} else if (content.constructor !== String) {
throw new Error("Y.Xml.after expects instances of YXml or String as a parameter");
}
this._model.val("children").push(content);
}
return this;
};
YXml.prototype.before = function() {
var c, content, contents, parent, position, _i, _j, _len, _len1, _ref;
parent = this._model.val("parent");
if (parent == null) {
throw new Error("This Xml Element must not have siblings! (for it does not have a parent)");
}
_ref = parent.getChildren();
for (position = _i = 0, _len = _ref.length; _i < _len; position = ++_i) {
c = _ref[position];
if (c === this) {
break;
}
}
contents = [];
for (_j = 0, _len1 = arguments.length; _j < _len1; _j++) {
content = arguments[_j];
if (content instanceof YXml) {
content._setParent(this._model.val("parent"));
} else if (content.constructor !== String) {
throw new Error("Y.Xml.after expects instances of YXml or String as a parameter");
}
contents.push(content);
}
return parent._model.val("children").insertContents(position, contents);
};
YXml.prototype.empty = function() {
var child, children, _i, _len, _ref, _results;
children = this._model.val("children");
_ref = children.val();
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
child = _ref[_i];
if (child.constructor === String) {
_results.push(children["delete"](0));
} else {
_results.push(child.remove());
}
}
return _results;
};
YXml.prototype.hasClass = function(className) {
if (this._model.val("classes").val(className) != null) {
return true;
} else {
return false;
}
};
YXml.prototype.prepend = function() {
var content, _i, _len;
for (_i = 0, _len = arguments.length; _i < _len; _i++) {
content = arguments[_i];
if (content instanceof YXml) {
content._setParent(this);
} else if (content.constructor !== String) {
throw new Error("Y.Xml.after expects instances of YXml or String as a parameter");
}
this._model.val("children").insert(0, content);
}
return this;
};
YXml.prototype.remove = function() {
var parent;
parent = this._model["delete"]("parent");
return this;
};
YXml.prototype.removeAttr = function(attrName) {
if (attrName === "class") {
this._model.val("classes", new this._model.custom_types.Object());
} else {
this._model.val("attributes")["delete"](attrName);
}
return this;
};
YXml.prototype.removeClass = function() {
var className, _i, _len;
if (arguments.length === 0) {
this._model.val("classes", new this._model.custom_types.Object());
} else {
for (_i = 0, _len = arguments.length; _i < _len; _i++) {
className = arguments[_i];
this._model.val("classes")["delete"](className);
}
}
return this;
};
YXml.prototype.toggleClass = function() {
var className, classes, _i, _len;
for (_i = 0, _len = arguments.length; _i < _len; _i++) {
className = arguments[_i];
classes = this._model.val("classes");
if (classes.val(className) != null) {
classes["delete"](className);
} else {
classes.val(className, true);
}
}
return this;
};
YXml.prototype.getParent = function() {
return this._model.val("parent");
};
YXml.prototype.getChildren = 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, setClasses, 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") {
if (event.value.constructor === String) {
newNode = document.createTextNode(event.value);
} else {
newNode = event.value.getDom();
event.value._setParent(that);
}
children = that._dom.childNodes;
if (children.length === event.position) {
rightNode = null;
} else {
rightNode = children[event.position];
}
_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;
});
setClasses = function() {
return that._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;
});
};
setClasses();
this._model.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") {
dont_proxy(function() {
var classes;
classes = that.attr("class");
if ((classes == null) || classes === "") {
return that._dom.removeAttribute("class");
} else {
return that._dom.setAttribute("class", that.attr("class"));
}
});
_results.push(setClasses());
} 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 f_add, f_remove, insertBefore, removeChild, replaceChild, that, _proxy;
_proxy = function(f_name, f, source, y) {
var old_f;
if (source == null) {
source = Element.prototype;
}
old_f = source[f_name];
return source[f_name] = function() {
if ((!((y != null) || (this._y_xml != null))) || proxy_token) {
return old_f.apply(this, arguments);
} else if (this._y_xml != null) {
return f.apply(this._y_xml, arguments);
} else {
return f.apply(y, arguments);
}
};
};
that = this;
f_add = function(c) {
return that.addClass(c);
};
_proxy("add", f_add, this._dom.classList, this);
f_remove = function(c) {
return that.removeClass(c);
};
_proxy("remove", f_remove, this._dom.classList, this);
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);
replaceChild = function(insertedNode, replacedNode) {
insertBefore.call(this, insertedNode, replacedNode);
return removeChild.call(this, replacedNode);
};
return _proxy('replaceChild', replaceChild);
};
if (typeof window !== "undefined" && window !== null) {
if (window.Y != null) {
window.Y.Xml = YXml;
} else {
throw new Error("You must first import Y!");
}
}
if (typeof module !== "undefined" && module !== null) {
module.exports = YXml;
}

View File

@@ -42,4 +42,4 @@ if (typeof window !== "undefined" && window !== null) {
window.Y = createY;
}
createY.Object = require("./Types/Object");
createY.Object = require("./ObjectType");