2 'libs/jquery-1.9.1.min',
4 'modules/documentCanvas/canvas/documentElement'
5 ], function($, _, documentElement) {
9 var Canvas = function(xml) {
10 xml = $.parseXML(xml);
11 this.d = xml !== null ? $(xml.childNodes[0]) : null;
14 $.extend(Canvas.prototype, {
19 return documentElement.wrap(this.d.get(0), this); //{wlxmlTag: this.d.prop('tagName')};
22 wrapText: function(params) {
23 params = _.extend({textNodeIdx: 0}, params);
24 if(typeof params.textNodeIdx === 'number')
25 params.textNodeIdx = [params.textNodeIdx];
27 //var container = params.inside.dom(),
28 var childrenInside = params.inside.children(),
29 idx1 = Math.min.apply(Math, params.textNodeIdx),
30 idx2 = Math.max.apply(Math, params.textNodeIdx),
31 textNode1 = childrenInside[idx1],
32 textNode2 = childrenInside[idx2],
33 sameNode = textNode1.sameNode(textNode2),
34 prefixOutside = textNode1.getText().substr(0, params.offsetStart),
35 prefixInside = textNode1.getText().substr(params.offsetStart),
36 suffixInside = textNode2.getText().substr(0, params.offsetEnd),
37 suffixOutside = textNode2.getText().substr(params.offsetEnd)
40 var wrapperElement = documentElement.DocumentNodeElement.create({tag: params._with.tag, klass: params._with.klass});
41 textNode1.after(wrapperElement);
44 wrapperElement.before({text:prefixOutside});
46 var core = textNode1.getText().substr(params.offsetStart, params.offsetEnd - params.offsetStart);
47 wrapperElement.append({text: core});
50 wrapperElement.append({text: prefixInside});
51 for(var i = idx1 + 1; i < idx2; i++) {
52 wrapperElement.append(childrenInside[i]);
55 wrapperElement.append({text: suffixInside});
57 wrapperElement.after({text: suffixOutside});
58 return wrapperElement;
64 fromXML: function(xml) {
65 return new Canvas(xml);