function readCookie(name) {
- /* global escape, unescape */
+ /* global escape, unescape, document */
var nameEQ = escape(name) + '=';
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var getDocumentFromXML = function(xml) {
return wlxml.WLXMLDocumentFromXML(xml);
-}
+};
var wait = function(callback, timeout) {
+ /* globals window */
return window.setTimeout(callback, timeout || 0.5);
};
c = canvas.fromXMLDocument(doc);
var header = doc.root.replaceWith({tagName: 'header'});
- expect(c.doc().data('wlxmlNode').sameNode(header)).to.be.true;
+ expect(c.doc().data('wlxmlNode').sameNode(header)).to.equal(true);
});
});
});
describe('Cursor', function() {
-
+ /* globals Node */
var getSelection;
var findTextNode = function(inside, text) {
};
beforeEach(function() {
+ /* globals window */
getSelection = sinon.stub(window, 'getSelection');
});
], function($) {
'use strict';
-
+/* globals Node */
var nearestInDocumentOrder = function(selector, direction, element) {
var parents = $(element).parents(),
this.clearWidgets = function() {
documentElement.dom().children('.canvas-widgets').empty();
- }
+ };
this.setDisplayStyle = function(displayStyle) {
documentElement.dom().css('display', displayStyle || '');
this.toggle = function(toggle) {
documentElement._container().toggle(toggle);
- }
+ };
var eventBus = documentElement.canvas ? documentElement.canvas.eventBus :
{trigger: function() {}};
this.trigger = function() {
eventBus.trigger.apply(eventBus, arguments);
- }
+ };
-}
+};
var getDisplayStyle = function(tag, klass) {
- if(tag === 'metadata')
+ if(tag === 'metadata') {
return 'none';
- if(tag === 'span')
+ }
+ if(tag === 'span') {
return 'inline';
- if(klass === 'item')
+ }
+ if(klass === 'item') {
return null;
+ }
return 'block';
-}
+};
var GenericManager = function(wlxmlElement) {
this.el = wlxmlElement;
this.el.toggle(toggle);
}
-})
+});
var managers = {
_m: {},
set: function(tag, klass, manager) {
- if(!this._m[tag])
+ if(!this._m[tag]) {
this._m[tag] = {};
+ }
this._m[tag][klass] = manager;
},
get: function(tag,klass) {
- if(this._m[tag] && this._m[tag][klass])
+ if(this._m[tag] && this._m[tag][klass]) {
return this._m[tag][klass];
+ }
return GenericManager;
}
-}
+};
var FootnoteManager = function(wlxmlElement) {
this.el = wlxmlElement;
this.el.setDisplayStyle(toggle ? 'block' : 'inline');
this.el.toggle(toggle);
- if(!options.silent)
+ if(!options.silent) {
this.el.trigger('elementToggled', toggle, this.el.documentElement);
+ }
}
-})
+});
managers.set('aside', 'footnote', FootnoteManager);
if(command === 'undo' || command === 'redo') {
params.callback = function(disable) {
btn.attr('disabled', !disable);
- }
+ };
}
sandbox.publish('command', command, params);
});
this.metaTable.on('keydown', '[contenteditable]', function(e) {
+ /* globals document */
if(e.which === 13) {
if($(document.activeElement).hasClass('rng-module-metadataEditor-metaItemKey')) {
metaTable.find('.rng-module-metadataEditor-metaItemValue').focus();
};
var getAttrElement = function(attrName, attr) {
- var toret = $('<div>');
+ var toret = $('<div>');
toret.append(templates.string({name: attrName, value: attr.value}));
return toret;
};
var MetaWidget = Backbone.View.extend({
events: {
- 'change [metaField-name]': 'onMetaFieldChange'
+ 'change [metaField-name]': 'onMetaFieldChange'
},
initialize: function() {
var view = this;
define([
+'libs/jquery',
'libs/chai',
'libs/sinon',
'modules/nodePane/metaWidget/metaWidget'
-], function(chai, sinon, metaWidget) {
+], function($, chai, sinon, metaWidget) {
'use strict';
+/* globals describe, it */
var assert = chai.assert;
sandbox.getModule('data').restoreVersion(event);
},
displayVersion: function(event) {
+ /* globals window */
window.open('/' + gettext('editor') + '/' + sandbox.getModule('data').getDocumentId() + '?version=' + event.version, _.uniqueId());
}
};
+++ /dev/null
-define([
-
-], function() {
-
-'use strict';
-
-var breakContentTransformation = {
- impl: function(args) {
- var node = this.context,
- newNodes, emptyNode, emptyText;
- newNodes = node.transform('smartxml.split', {offset: args.offset});
- [newNodes.first, newNodes.second].some(function(newNode) {
- if(!(newNode.contents().length)) {
- newNode.transform('smartxml.append', {text: ''});
- return true; // break
- }
- });
- return _.extend(newNodes, {emptyText: emptyText});
- },
- isAllowed: function() {
-
- }
-};
-
-
-var breakContentAction = function(document, context) { //@ editor.getDocument(); editor.getContext('...')
- var textNode = context.cursor.currentNode;
- if(textNode) {
- var result, goto;
-
- result = textNode.transform('core.break-content', {offset: context.cursor.offset});
-
- if(result.emptyText) {
- goto = result.createdEmpty;
- gotoOptions = {};
- } else {
- goto = result.second;
- gotoOptions = {caretTo: 'start'};
- }
-
- context.setCurrentElement(goto, gotoOptions);
- }
-}
-breakContentAction.isAllowed = function(document, context) {
- /* globals Node */
- var node = context.cursor.currentNode;
- return node.nodeType === Node.TEXT_NODE;
-}
-
-return {
- keyHandlers: [
- {key: 'ENTER', target: 'main-document-area', handler: function(editor) {
- var action = editor.getAction('core.break-document-content');
- if(action.isAllowed()) {
- action.execute();
- }
- }},
- {key: 'ENTER', target: 'main-document-area', actionHandler: 'core.break-document-content'}
- ],
-
- documentActions: [
- {
- name: 'core.break-document-content',
- context: 'main-document-area',
- label: 'break here'
- icon: 'core:some-name',
- action: breakContentAction
- }
- ],
-
- // zapisywanie dokumentu:
-
- documentTransformations: [
- {name: 'core.break-content', textNode: true, t: breakContentTransformation},
-
- // transformacja z poziomu smartxml
- {name: 'core.wrap-with', textNode: true, t: wrapWith}
-
- // list plugin:
- {name: 'list.remove-list', elementNode: 'list', t: null}
- // hipotetyczna akcja na itemie listy
- {name: 'list.extract', elementNode: 'item', requiresParent: 'list', requiresInParents: '?'}
- ]
-};
-
-});
\ No newline at end of file
-define([
-
-], function() {
+define(function(require) {
'use strict';
/* globals Node */
-var TEXT_NODE = Node.TEXT_NODE;
+
+var _ = require('libs/underscore'),
+ TEXT_NODE = Node.TEXT_NODE;
+
var INSERTION = function(implementation) {
var toret = function(node) {
var textNodeTransformations = {
setText: function(text) {
- //console.log('smartxml: ' + text);
this.nativeNode.data = text;
this.triggerTextChangeEvent();
},
insertion.ofNode.triggerChangeEvent('nodeAdded');
return insertion.ofNode;
}
-}
+};
return {
document: {
clone: function() {
var clone = this._$.clone(true, true);
- // clone.find('*').addBack().each(function() {
- // var n = $(this);
- // if(n.data('canvasElement')) {
- // n.data('canvasElement', $.extend(true, {}, n.data('canvasElement')));
- // n.data('canvasElement').$element = n.data('canvasElement').$element.clone(true, true);
- // }
- // });
return this.document.createDocumentNode(clone[0]);
},
var registerTransformation = function(desc, name, target) {
var Transformation = transformations.createContextTransformation(desc, name);
- //+ to sie powinna nazywac registerTransformationFromDesc or sth
- //+ ew. spr czy nie override (tylko jesli powyzej sa prototypy to trudno do nich dojsc)
target[name] = function() {
var instance = this,
args = Array.prototype.slice.call(arguments, 0);
return instance.transform(Transformation, args);
- }
+ };
};
var registerMethod = function(methodName, method, target) {
},
trigger: function() {
- //console.log('trigger: ' + arguments[0] + (arguments[1] ? ', ' + arguments[1].type : ''));
Backbone.Events.trigger.apply(this, arguments);
},
},
registerExtension: function(extension) {
- //debugger;
- var doc = this,
- existingPropertyNames = _.values(this);
+ var doc = this;
['document', 'documentNode', 'elementNode', 'textNode'].forEach(function(dstName) {
var dstExtension = extension[dstName];
},
transform: function(Transformation, args) {
- //console.log('transform');
var toret, transformation;
- //debugger;
-
- // ref: odrebnie przygotowanie transformacji, odrebnie jej wykonanie (to pierwsze to analog transform z node)
if(typeof Transformation === 'function') {
transformation = new Transformation(this, this, args);
this.undoStack.push(transformation);
}
this._transformationLevel--;
- //console.log('clearing redo stack');
if(!this._undoInProgress) {
this.redoStack = [];
}
define([
'libs/chai',
'libs/sinon',
+ 'libs/underscore',
'./smartxml.js'
-], function(chai, sinon, smartxml) {
+], function(chai, sinon, _, smartxml) {
'use strict';
/*jshint expr:true */
expect(elementNode.textTestTransformation).to.be.undefined;
expect(textNode.textTestTransformation().sameNode(textNode)).to.be.true;
- expect(textNode.elementTestTransfomation).to.be.undefined;
+ expect(textNode.elementTestTransfomation).to.be.undefined;
});
it('allows text/element node methods and transformations to access node and transormations on document node', function() {
it('smoke tests', function() {
var doc = getDocumentFromXML('<div>Alice</div>'),
- textNode = doc.root.contents()[0],
- result;
+ textNode = doc.root.contents()[0];
expect(doc.undoStack).to.have.length(0);
expect(doc.undoStack).to.have.length(0, '2');
expect(doc.toXML()).to.equal('<div>Alice</div>');
- debugger;
doc.redo();
expect(doc.undoStack).to.have.length(1, '3');
expect(doc.toXML()).to.equal('<div>A<span>l</span>ice</div>');
it('smoke tests 2', function() {
var doc = getDocumentFromXML('<div>Alice</div>'),
textNode = doc.root.contents()[0],
- path = textNode.getPath(),
- result;
+ path = textNode.getPath();
- debugger;
textNode.setText('Alice ');
textNode.setText('Alice h');
textNode.setText('Alice ha');
expect(doc.root.contents()[0].getAttr('x')).to.equal('10', 'empty redoStack so redo was noop');
doc.undo();
expect(doc.root.contents()[0].getAttr('x')).to.equal('4', 'undoing additional transformation');
- doc.redo()
+ doc.redo();
expect(doc.root.contents()[0].getAttr('x')).to.equal('10', 'redoing additional transformation');
});
});
+++ /dev/null
-//use case: edytor robi split, jesli split był na koncu (czyli druga czesc jest pusta)
-// chce tam dodac wezel tekstowy
-
-// flow: plugin_key_handler(enter, main-canvas-area) -> plugin_document_action('break-content')
-// --w srodku--> refactoring tego co teraz w keyboard:
-
-//1. jedna transformacja z warunkiem (Zarejestrowana przez plugin)
-
-
-
-var breakContentTransformation = {
- impl: function(args) {
- var node = this.context;
- emptyText = false,
- newNodes,
- emptyNode;
-
- newNodes = node.transform('core.split', {offset: args.offset});
-
- if(args.offset === 0)
- emptyNode = newNodes.first;
- else if(args.offset === node.getText().length); //@ nie ma atEnd :(
- emptyNode = newNodes.second;
-
- if(emptyNode) {
- emptyText = emptyNode.transform('core.append', {text: ''});
- }
-
- return _.extend(newNodes, {emptyText: emptyText});
- }
-};
-
-
-var breakContentAction = function(document, context) {
- var textNode = context.currentTextNode;
- if(textNode) {
- var result, goto;
-
- result = textNode.transform('core.break-content', {offset: context.offset});
-
- if(result.emptyText) {
- goto = result.createdEmpty;
- gotoOptions = {};
- } else {
- goto = result.second;
- gotoOptions = {caretTo: 'start'};
- }
-
- context.setCurrentElement(goto, gotoOptions);
- }
-}
-
-var toret = {
- keyHandlers: [
- {key: 'ENTER', target: 'main-document-area', handler: function(editor) {
- editor.getAction('core.break-document-content').execute();
- }},
- ],
-
- actions: [
- {name: 'core.break-document-content', context: 'main-document-area', action: breakContentAction}
- ],
-
- // zapisywanie dokumentu:
-
- contextTransformations: [
- {name: 'core.break-content', textNode: true, t: breakContentTransformation},
-
- // list plugin:
- {name: 'list.remove-list', elementNode: 'list', t: null}
- // hipotetyczna akcja na itemie listy
- {name: 'list.extract', elementNode: 'item', requiresParent: 'list', requiresInParents: '?'}
- ],
-
-}
-
-
-/// STARE
-
-// 1. detach via totalny fallback
-var DetachNodeTransformation = function(args) {
- this.node = args.node;
- this.document = this.node.document;
-};
-$.extend(DetachNodeTransformation.prototype, {
- run: function() {
- this.oldRoot = this.node.document.root.clone();
- this.path = this.node.getPath();
- this.node.detach(); // @TS
-
- },
- undo: function() {
- this.document.root.replaceWith(this.oldRoot); // this.getDocument?
- this.node = this.document.getNodeByPath(this.path);
- }
-});
-transformations['detach'] = DetachNodeTransformation;
-
-//2. detach via wskazanie changeroot
-
-var Detach2NodeTransformation = function(args) {
- this.nodePath = args.node.getPath();
- this.document = args.node.document;
-};
-$.extend(Detach2NodeTransformation.prototype, {
- run: function() {
- var node = this.document.getNodeByPath(this.nodePath),
- root = node.parent() ? node.parent() : this.document.root;
-
- this.rootPath = root.getPath();
- this.oldRoot = (root).clone();
- node.detach();
- },
- undo: function() {
- this.document.getNodeByPath(this.rootPath).replaceWith(this.oldRoot);
- }
-});
-//transformations['detach2'] = Detach2NodeTransformation;
-
-//2a. generyczna transformacja
-
-var createTransformation = function(desc) {
-
- var NodeTransformation = function(args) {
- this.nodePath = args.node.getPath();
- this.document = args.node.document;
- this.args = args;
- };
- $.extend(NodeTransformation.prototype, {
- run: function() {
- var node = this.document.getNodeByPath(this.nodePath),
- root;
-
- if(desc.getRoot) {
- root = desc.getRoot(node);
- } else {
- root = this.document.root;
- }
-
- this.rootPath = root.getPath();
- this.oldRoot = (root).clone();
- desc.impl.call(node, this.args);
- },
- undo: function() {
- this.document.getNodeByPath(this.rootPath).replaceWith(this.oldRoot);
- }
- });
-
- return NodeTransformation;
-}
-
-
-
-var contextTransformations = {};
-contextTransformations['setText'] = createContextTransformation({
- impl: function(args) {
- this.setText(args.text);
- },
- getChangeRoot: function() {
- return this.context;
- }
-});
-
-contextTransformations['setAttr'] = createContextTransformation({
- impl: function(args) {
- this.setAttr(args.name, args.value);
- },
- getChangeRoot: function() {
- return this.context;
- }
-});
-
-contextTransformations['split'] = createContextTransformation({
- impl: function(args) {
- return this.split({offset: args.offset});
- }//,
- // getChangeRoot: function() {
- // return this.context.parent().parent();
- // }
-});
-
-
-contextTransformations['before'] = createContextTransformation({
- getChangeRoot: function() {
- return this.context.parent();
- },
- impl: function(args) {
- this.before(args.node)
- },
-
-});
-
-contextTransformations['before'] = createContextTransformation({
- impl: function(args) {
- this.before(args.node)
- },
- undo: function() {
- this.context.detach();
- }
-});
-
-
-
-transformations['detach2'] = createTransformation({
- // impl: function() {
- // //this.setAttr('class', 'cite'); //
- // },
- impl: ElementNode.prototype.detach,
- getRoot: function(node) {
- return node.parent();
- }
-
-});
-
-transformations['setText-old'] = createTransformation({
- impl: function(args) {
- this.setText(args.text)
- },
- getRoot: function(node) {
- return node;
- }
-
-});
-
-transformations['setClass-old'] = createTransformation({
- impl: function(args) {
- this.setClass(args.klass);
- },
- getRoot: function(node) {
- return node;
- }
-})
-
-//3. detach z pełnym własnym redo
-
-var Detach3NodeTransformation = function(args) {
- this.node = args.node;
- this.document = this.node.document;
-};
-$.extend(Detach3NodeTransformation.prototype, {
- run: function() {
- //this.index = this.node.getIndex();
- //this.parent = this.node.parent();
-
- this.path = this.node.getPath();
- if(this.node.isSurroundedByTextElements()) {
- this.prevText = this.node.prev().getText();
- this.nextText = this.node.next().getText();
- this.merge = true;
- } else {
- this.prevText = this.nextText = null;
- this.merge = false;
- }
-
- this.node.detach();
- },
- undo: function() {
- var parent = this.document.getNodeByPath(this.path.slice(0,-1)),
- idx = _.last(this.path);
- var inserted = parent.insertAtIndex(this.node, idx);
- if(this.merge) {
- if(inserted.next()) {
- inserted.before({text: this.prevText});
- inserted.next().setText(this.nextText);
- } else {
- inserted.prev().setText(this.prevText);
- inserted.after({text: this.nextText});
- }
- }
- }
-});
-transformations['detach3'] = Detach3NodeTransformation;
-
-
-var registerTransformationsFromObject = function(object) {
- _.pairs(object).filter(function(pair) {
- var property = pair[1];
- return typeof property === 'function' && property._isTransformation;
- })
- .forEach(function(pair) {
- var name = pair[0],
- method = pair[1];
- object.registerTransformation(name, createContextTransformation(method));
- });
-};
-registerTransformationsFromObject(ElementNode.prototype);
-registerTransformationsFromObject(TextNode.prototype);
-registerTransformationsFromObject(Document.prototype);
\ No newline at end of file
var _ = require('libs/underscore'),
toret = {};
-var getTransDesc = function(desc, name) {
+var getTransDesc = function(desc) {
if(typeof desc === 'function') {
desc = {impl: desc};
}
if(!desc.impl) {
- throw new Error('Got transformation description without implementation.')
+ throw new Error('Got transformation description without implementation.');
}
return desc;
};
return value;
}
}
- });
+ });
}
});
}
this.snapshot = changeRoot.clone();
this.changeRootPath = changeRoot.getPath();
}
- //var toret = desc.impl.call(this.context, this.args); // a argumenty do metody?
var argsToPass = desc.undo ? [this].concat(this.args) : this.args;
var toret = desc.impl.apply(this.context, argsToPass);
this.hasRun = true;
return GenericTransformation;
};
-// var T = createGenericTransformation({impl: function() {}});
-// var t = T(doc, {a:1,b:2,c3:3});
-
toret.createContextTransformation = function(desc, name) {
- // mozna sie pozbyc przez przeniesienie object/context na koniec argumentow konstruktora generic transformation
var GenericTransformation = toret.createGenericTransformation(desc, name);
var ContextTransformation = function(document, object, args) {
if(document === object) {
this.context = document;
- } else {
+ } else {
var contextPath = object.getPath(),
transformation = this;
Object.defineProperty(this, 'context', {
get: function() {
- // todo: to jakos inaczej, bo np. this.context w undo transformacji before to juz nie ten sam obiekt
- // moze transformacja powinna zwracac zmodyfikowana sciezke do obiektu po dzialaniu run?
-
if(transformation.hasRun) {
- //console.log('returning via path');
return transformation.document.getNodeByPath(contextPath);
} else {
- //console.log('returning original arg');
return object;
-
}
}
});
}
- }
+ };
ContextTransformation.prototype = Object.create(GenericTransformation.prototype);
return ContextTransformation;
-}
-// var T = createContextTransformation({impl: function() {}});
-// var t = T(doc, node, {a:1,b:2,c3:3});
-///
-
-
-
-toret.TransformationStorage = function() {
- this._transformations = {};
};
-_.extend(toret.TransformationStorage.prototype, {
-
- register: function(Transformation) {
- var list = (this._transformations[Transformation.prototype.name] = this._transformations[Transformation.prototype.name] || []);
- list.push(Transformation);
- },
-
- get: function(name) {
- var transformations = this._transformations[name];
- if(!transformations) {
- throw new Error('Transformation "' + name + '" not found!');
- }
- // na razie zwraca pierwsza
- return transformations[0];
- }
-});
-
-
-
-// var registerTransformationFromMethod = (object, methodName, desc) {
-// if(!object[methodName]) {
-// throw new Exeption('Cannot register transformation from unknown method ' + methodName + ' on ' + object);
-// }
-// desc.impl = object[name];
-// Transformation = createContextTransformation(desc);
-// object.prototype.registerContextTransformation(name, createContextTransformation(method));
-// };
-
-
-// registerTransformationFromMethod(ElementNode, 'setAttr', {
-// impl: function(args) {
-// this.setAttr(args.name, args.value);
-// },
-// getChangeRoot: function() {
-// return this.context;
-// }
-
-// });
-
return toret;
});
\ No newline at end of file
-define(function() {
+define(function(require) {
'use strict';
-var extension = {document: {transformations: {}}, wlxmlClass: {list: {methods: {}}}};
+var _ = require('libs/underscore'),
+ extension = {document: {transformations: {}}, wlxmlClass: {list: {methods: {}}}};
extension.wlxmlClass.list.methods = {
getItem: function(index) {
return this.contents('.item')[index];
}
-}
+};
extension.documentMethods = {
areItemsOfSameList: function(params) {
return params.node1.parent().sameNode(params.node2.parent()) && params.node2.parent().is('list');
}
-}
+};
extension.document.transformations.createList = {
- impl: function(params) {
+ impl: function(params) {
+ /* globals Node */
var parent = params.node1.parent(),
parentContents = parent.contents(),
nodeIndexes = [params.node1.getIndex(), params.node2.getIndex()].sort(),
for(i = nodeIndexes[0]; i <= nodeIndexes[1]; i++) {
node = parentContents[i];
if(node.nodeType === Node.TEXT_NODE) {
- node = node.wrapWith({tagName: 'div', attrs: {'class': 'item'}}); //t
+ node = node.wrapWith({tagName: 'div', attrs: {'class': 'item'}});
} else {
- node.setClass('item'); //t
+ node.setClass('item');
}
nodesToWrap.push(node);
}
var toInsert;
if(parent.is('list') && parent.object.itemIndex(nodesToWrap[0]) > 0) { // object api
// var prevItem = parent.object.getItem(parent.object.itemIndex(nodesToWrap[0])-1); // object api
- // prevItem.append(listNode); //t
+ // prevItem.append(listNode);
toInsert = listNode.wrapWith({tagName: 'div', attrs: {'class': 'item'}});
} else {
- //nodesToWrap[0].before(listNode); //t
+ //nodesToWrap[0].before(listNode);
toInsert = listNode;
- }
+ }
params.node1.before(toInsert);
nodesToWrap.forEach(function(node) {
- listNode.append(node); //t
+ listNode.append(node);
});
},
getChangeRoot: function() {
precedingItems = [],
extractedItems = [],
succeedingItems = [],
- items = list.contents(), // lub list.object.items()
- listIsNested = list.parent().is('item'),
- i;
+ items = list.contents(),
+ listIsNested = list.parent().is('item');
+
items.forEach(function(item, idx) {
if(idx < indexes[0]) {
if(succeedingItems.length === 0) {
var reference_orig = reference;
extractedItems.forEach(function(item) {
- reference.after(item); //t
+ reference.after(item);
reference = item;
if(!listIsNested) {
- item.setClass(null); //t
+ item.setClass(null);
}
});
- if(precedingItems.length === 0)
- reference_orig.detach(); //t
+ if(precedingItems.length === 0) {
+ reference_orig.detach();
+ }
} else if(precedingItems.length === 0) {
extractedItems.forEach(function(item) {
- reference.before(item); //t
+ reference.before(item);
if(!listIsNested) {
- item.setClass(null); //t
+ item.setClass(null);
}
});
} else {
extractedItems.forEach(function(item) {
- reference.after(item); //t
- if(!listIsNested)
- item.setClass(null); //t
+ reference.after(item);
+ if(!listIsNested) {
+ item.setClass(null);
+ }
reference = item;
});
var secondList = params.item1.document.createDocumentNode({tagName: 'div', attrs: {'class':'list'}}),
'use strict';
+/* jshint multistr:true */
+/* globals describe, it */
+
var chai = require('libs/chai'),
wlxml = require('wlxml/wlxml'),
expect = chai.expect,
};
var removeEmptyTextNodes = function(xml) {
+ /* globals Node */
xml = $($.trim(xml));
xml.find(':not(iframe)')
.addBack()
doc.extractItems({item1: nestedListItem, item2: nestedListItem}); //@@ name!
- var section = doc.root,
- list = section.contents()[0],
- item1 = list.contents()[0],
+ list = doc.root.contents()[0];
+ var item1 = list.contents()[0],
item2 = list.contents()[1], //
item3 = list.contents()[2],
item4 = list.contents()[3], //
nestedListItem2 = nestedList.contents()[2];
doc.extractItems({item1: nestedListItem1, item2: nestedListItem2});
-
- var section = doc.root,
- list = section.contents()[0],
- item1 = list.contents()[0],
+ list = doc.root.contents()[0];
+ var item1 = list.contents()[0],
item2 = list.contents()[1],
item3 = list.contents()[2],
item4 = list.contents()[3],
doc.extractItems({item1: nestedListItem1, item2: nestedListItem2});
- var section = doc.root,
- list = section.contents()[0],
- item1 = list.contents()[0],
+ list = doc.root.contents()[0];
+ var item1 = list.contents()[0],
item2 = list.contents()[1],
item3 = list.contents()[2],
item4 = list.contents()[3],
doc.extractItems({item1: nestedListItem1, item2: nestedListItem2});
- var section = doc.root,
- list = section.contents()[0],
- item1 = list.contents()[0],
+ list = doc.root.contents()[0];
+ var item1 = list.contents()[0],
item2 = list.contents()[1],
item3 = list.contents()[2],
item4 = list.contents()[3];
'use strict';
+/* globals Node */
+
// utils
var isMetaAttribute = function(attrName) {
_.keys(methods).concat(_.keys(transformations)).forEach(function(key) {
instance.object[key] = _.bind(instance.object[key], instance);
});
-}
+};
var WLXMLElementNode = function(nativeNode, document) {
smartxml.ElementNode.call(this, nativeNode, document);
return this.getAttr('class') || '';
},
setClass: function(klass) {
- var methods, object;
if(klass !== this.klass) {
installObject(this, klass);
return this.setAttr('class', klass);
var WLXMLDocumentNode = function() {
smartxml.DocumentNode.apply(this, arguments);
-}
+};
WLXMLDocumentNode.prototype = Object.create(smartxml.DocumentNode.prototype);
var WLXMLDocument = function(xml, options) {
}
//}
}
-
+ /* globals document */
el.replaceWith(document.createTextNode(text.transformed));
});
this.trigger('contentSet');
thisClassTransformations[Transformation.prototype.name] = function(args) {
var nodeInstance = this;
return nodeInstance.transform(Transformation, args);
- }
+ };
},
registerClassMethod: function(methodName, method, className) {
var name = pair[0],
desc = pair[1];
doc.registerClassTransformation(transformations.createContextTransformation(desc, name), className);
- });
+ });
});
}
'use strict';
/* jshint expr:true */
-/* global it, describe */
+/* global it, describe, beforeEach */
var expect = chai.expect;
});
describe('White space handling', function() {
+ /* globals Node */
+
it('ignores white space surrounding block elements', function() {
var node = nodeFromXML('<section> <div></div> </section>'),
contents = node.contents();