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, odf*/
 26 
 27 /**
 28  * Allows only steps within the same paragraph as the first step the scanner is asked to process.
 29  * Will terminate upon encountering a step within a different paragraph, and return the most recent
 30  * step that was still within the target paragraph.
 31  *
 32  * @constructor
 33  */
 34 gui.ParagraphBoundaryScanner = function () {
 35     "use strict";
 36     var self = this,
 37         isInitialised = false,
 38         /**@type{?Element}*/
 39         lastParagraph,
 40         odfUtils = odf.OdfUtils;
 41 
 42     this.token = undefined;
 43 
 44     /**
 45      * @param {!gui.StepInfo} stepInfo
 46      * @return {!boolean}
 47      */
 48     this.process = function(stepInfo) {
 49         var currentParagraph = odfUtils.getParagraphElement(stepInfo.container());
 50         if (!isInitialised) {
 51             lastParagraph = currentParagraph;
 52             isInitialised = true;
 53         }
 54 
 55         if (lastParagraph !== currentParagraph) {
 56             return true;
 57         }
 58 
 59         self.token = stepInfo.token;
 60         return false;
 61     };
 62 };