|
455 | 455 | } |
456 | 456 | }; |
457 | 457 |
|
458 | | - var diffDOM = function(debug, diffcap, valueDiffing) { |
459 | | - if (typeof valueDiffing === 'undefined') { |
460 | | - valueDiffing = true; |
| 458 | + var diffDOM = function(options){ |
| 459 | + |
| 460 | + var defaults = { |
| 461 | + debug: false, |
| 462 | + diffcap: 10, |
| 463 | + valueDiffing: true, // Whether to take into consideration the values of forms that differ from auto assigned values (when a user fills out a form). |
| 464 | + siblingTextNodes: true, // Whether to take into consideration sibling text nodes. |
| 465 | + // diffing text elements can be overwritten for use with diff_match_patch and alike |
| 466 | + // syntax: textDiff: function (node, currentValue, expectedValue, newValue) |
| 467 | + textDiff: function() { |
| 468 | + arguments[0].data = arguments[3]; |
| 469 | + return; |
| 470 | + } |
| 471 | + }, i; |
| 472 | + |
| 473 | + if (typeof options == "undefined") { |
| 474 | + options = {}; |
461 | 475 | } |
462 | | - if (typeof debug === 'undefined') { |
463 | | - debug = false; |
464 | | - } else { |
| 476 | + |
| 477 | + for (i in defaults) { |
| 478 | + if (typeof options[i] == "undefined") { |
| 479 | + this[i] = defaults[i]; |
| 480 | + } else { |
| 481 | + this[i] = options[i]; |
| 482 | + } |
| 483 | + } |
| 484 | + |
| 485 | + if (this.debug) { |
465 | 486 | ADD_ATTRIBUTE = "add attribute"; |
466 | 487 | MODIFY_ATTRIBUTE = "modify attribute"; |
467 | 488 | REMOVE_ATTRIBUTE = "remove attribute"; |
|
494 | 515 | SELECTED = "selected"; |
495 | 516 | } |
496 | 517 |
|
497 | | - |
498 | | - if (typeof diffcap === 'undefined') { |
499 | | - diffcap = 10; |
500 | | - } |
501 | | - this.debug = debug; |
502 | | - this.diffcap = diffcap; |
503 | | - this.valueDiffing = valueDiffing; |
504 | 518 | }; |
505 | 519 | diffDOM.prototype = { |
506 | 520 |
|
|
563 | 577 | return false; |
564 | 578 | }, |
565 | 579 | findOuterDiff: function(t1, t2, route) { |
| 580 | + |
566 | 581 | var k, diffs = []; |
567 | 582 |
|
568 | 583 | if (t1.nodeName !== t2.nodeName) { |
|
639 | 654 | return diffs; |
640 | 655 | }, |
641 | 656 | findInnerDiff: function(t1, t2, route) { |
| 657 | + |
| 658 | + if (!this.siblingTextNodes && !this.valueDiffing) { |
| 659 | + if (t1.innerHTML === t2.innerHTML) { |
| 660 | + return []; |
| 661 | + } |
| 662 | + } |
| 663 | + |
642 | 664 | var subtrees = markSubTrees(t1, t2), |
643 | 665 | mappings = subtrees.length, |
644 | 666 | diff, diffs, i, last, e1, e2, |
|
885 | 907 | } |
886 | 908 | return node; |
887 | 909 | }, |
888 | | - // diffing text elements can be overwritten for use with diff_match_patch and alike |
889 | | - // syntax: textDiff: function (node, currentValue, expectedValue, newValue) |
890 | | - textDiff: function() { |
891 | | - arguments[0].data = arguments[3]; |
892 | | - return; |
893 | | - }, |
894 | 910 | applyDiff: function(tree, diff) { |
895 | 911 | var node = this.getFromRoute(tree, diff[ROUTE]), |
896 | 912 | newNode, reference, route, group, from, to, child, c, i; |
|
0 commit comments