View Javadoc
1   /*
2    * Copyright (c) 2002-2026 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.javascript.host.dom;
16  
17  import org.htmlunit.html.DomText;
18  import org.htmlunit.javascript.HtmlUnitScriptable;
19  import org.htmlunit.javascript.configuration.JsxClass;
20  import org.htmlunit.javascript.configuration.JsxConstructor;
21  import org.htmlunit.javascript.configuration.JsxFunction;
22  import org.htmlunit.javascript.configuration.JsxGetter;
23  
24  /**
25   * A JavaScript object for {@code Text}.
26   *
27   * @author David K. Taylor
28   * @author Chris Erskine
29   * @author Ahmed Ashour
30   * @author Chuck Dumont
31   * @author Ronald Brill
32   * @author Frank Danek
33   *
34   * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Text">MDN Documentation</a>
35   */
36  @JsxClass(domClass = DomText.class)
37  public class Text extends CharacterData {
38  
39      /**
40       * JavaScript constructor.
41       */
42      @Override
43      @JsxConstructor
44      public void jsConstructor() {
45          super.jsConstructor();
46      }
47  
48      /**
49       * Splits a Text node in two.
50       * @param offset the character position at which to split the Text node
51       * @return the Text node that was split from this node
52       */
53      @JsxFunction
54      public HtmlUnitScriptable splitText(final int offset) {
55          final DomText domText = (DomText) getDomNodeOrDie();
56          return getScriptableFor(domText.splitText(offset));
57      }
58  
59      /**
60       * Returns the {@code wholeText} property.
61       * @return the {@code wholeText} property
62       */
63      @JsxGetter
64      public String getWholeText() {
65          return ((DomText) getDomNodeOrDie()).getWholeText();
66      }
67  }