1 /**
  2  * Copyright (C) 2010-2014 KO GmbH <copyright@kogmbh.com>
  3  *
  4  * @licstart
  5  * This file is part of WebODF.
  6  *
  7  * WebODF is free software: you can redistribute it and/or modify it
  8  * under the terms of the GNU Affero General Public License (GNU AGPL)
  9  * as published by the Free Software Foundation, either version 3 of
 10  * the License, or (at your option) any later version.
 11  *
 12  * WebODF is distributed in the hope that it will be useful, but
 13  * WITHOUT ANY WARRANTY; without even the implied warranty of
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15  * GNU Affero General Public License for more details.
 16  *
 17  * You should have received a copy of the GNU Affero General Public License
 18  * along with WebODF.  If not, see <http://www.gnu.org/licenses/>.
 19  * @licend
 20  *
 21  * @source: http://www.webodf.org/
 22  * @source: https://github.com/kogmbh/WebODF/
 23  */
 24 
 25 /*global gui, NodeFilter, odf, Node*/
 26 
 27 /**
 28  * Exclude nodes that do not make up part of the ODF's text body. This includes:
 29  * - Any text node that is not within a text grouping element
 30  * - Any node within a text:tracked-changes block
 31  *
 32  * @constructor
 33  * @implements NodeFilter
 34  */
 35 gui.OdfTextBodyNodeFilter = function () {
 36     "use strict";
 37     var odfUtils = odf.OdfUtils,
 38         TEXT_NODE = Node.TEXT_NODE,
 39         FILTER_REJECT = NodeFilter.FILTER_REJECT,
 40         FILTER_ACCEPT = NodeFilter.FILTER_ACCEPT,
 41         textns = odf.Namespaces.textns;
 42 
 43     /**
 44      * @param {!Node} node
 45      * @return {!number}
 46      */
 47     this.acceptNode = function (node) {
 48         if (node.nodeType === TEXT_NODE) {
 49             if (!odfUtils.isGroupingElement(node.parentNode)) {
 50                 return FILTER_REJECT;
 51             }
 52         } else if (node.namespaceURI === textns && node.localName === "tracked-changes") {
 53             return FILTER_REJECT;
 54         }
 55         return FILTER_ACCEPT;
 56     };
 57 };
 58