- var spanParent = el.parent().attr('wlxml-tag') === 'span',
- spanBefore = el.prev().length > 0 && $(el.prev()[0]).attr('wlxml-tag') === 'span',
- spanAfter = el.next().length > 0 && $(el.next()[0]).attr('wlxml-tag') === 'span';
-
- var oldText = this.data,
- oldLength = this.data.length;
- var parent = el.parent(),
- parentContents = parent.contents(),
- idx = parentContents.index(this),
- next = idx < parentContents.length - 1 ? parentContents[idx+1] : null;
-
- var addInfo = function(toAdd) {
- if(next) {
- $(next).data('orig-before', toAdd);
- } else {
- parent.data('orig-append', toAdd);
- }
+
+ var el = $(this),
+ text = {original: el.text(), trimmed: $.trim(el.text())},
+ elParent = el.parent(),
+ hasSpanParent = elParent.attr('wlxml-tag') === 'span',
+ hasSpanBefore = el.prev().length > 0 && $(el.prev()[0]).attr('wlxml-tag') === 'span',
+ hasSpanAfter = el.next().length > 0 && $(el.next()[0]).attr('wlxml-tag') === 'span';
+
+
+ var addInfo = function(toAdd, where) {
+ var parentContents = elParent.contents(),
+ idx = parentContents.index(el[0]),
+ prev = idx > 0 ? parentContents[idx-1] : null,
+ next = idx < parentContents.length - 1 ? parentContents[idx+1] : null,
+ target, key;
+
+ if(where === 'above') {
+ target = prev ? $(prev) : elParent;
+ key = prev ? 'orig-after' : 'orig-begin';
+ } else if(where === 'below') {
+ target = next ? $(next) : elParent;
+ key = next ? 'orig-before' : 'orig-end';
+ } else { throw new Object;}
+
+ target.data(key, toAdd);