List of usage examples for com.google.gwt.dom.client NodeList getItem
public T getItem(int index)
From source file:org.xwiki.gwt.wysiwyg.client.plugin.line.LinePlugin.java
License:Open Source License
/** * Marks the BRs that have been added as spacers during the editing. These BRs were added to overcome a Mozilla bug * that prevents us from typing inside an empty block level element. */// ww w. j a v a 2s . c om protected void markSpacers() { Document document = getTextArea().getDocument(); NodeList<com.google.gwt.dom.client.Element> brs = document.getBody().getElementsByTagName(BR); for (int i = 0; i < brs.getLength(); i++) { Element br = brs.getItem(i).cast(); // Ignore the BRs that have been there from the beginning. if (LINE_BREAK.equals(br.getClassName())) { continue; } Node container = domUtils.getNearestBlockContainer(br); Node leaf = domUtils.getNextLeaf(br); boolean emptyLine = true; // Look if there is any visible element on the new line, taking care to remain in the current block // container. while (leaf != null && container == domUtils.getNearestBlockContainer(leaf)) { if (needsSpace(leaf)) { emptyLine = false; break; } leaf = domUtils.getNextLeaf(leaf); } if (emptyLine) { br.setClassName(SPACER); } else { br.removeAttribute(CLASS_NAME); } } }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.line.LinePlugin.java
License:Open Source License
/** * @see #markSpacers()/*from w ww . j a v a 2s . co m*/ */ protected void unMarkSpacers() { Document document = getTextArea().getDocument(); NodeList<com.google.gwt.dom.client.Element> brs = document.getBody().getElementsByTagName(BR); for (int i = 0; i < brs.getLength(); i++) { Element br = (Element) brs.getItem(i); if (SPACER.equals(br.getClassName())) { br.removeAttribute(CLASS_NAME); } } }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.line.LinePlugin.java
License:Open Source License
/** * Marks the initial line breaks so they are not mistaken as {@link #SPACER}. *//*from w w w .j ava2s . c om*/ protected void markInitialLineBreaks() { Document document = getTextArea().getDocument(); NodeList<com.google.gwt.dom.client.Element> brs = document.getBody().getElementsByTagName(BR); for (int i = 0; i < brs.getLength(); i++) { Element br = (Element) brs.getItem(i); // Skip the spaces and the BRs added by the browser before the document was loaded. if (!br.hasAttribute("_moz_dirty") && !SPACER.equals(br.getClassName())) { br.setClassName(LINE_BREAK); } } }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.line.LinePlugin.java
License:Open Source License
/** * Replaces {@code <div class="wikimodel-emptyline"/>} with {@code <p/>}. Empty lines are used by WikiModel to * separate block level elements, but since the user should be able to write on these empty lines we convert them to * paragraphs./*ww w .ja va2 s . c o m*/ */ protected void replaceEmptyLinesWithParagraphs() { Document document = getTextArea().getDocument(); NodeList<com.google.gwt.dom.client.Element> divs = document.getBody().getElementsByTagName("div"); // Since NodeList is updated when one of its nodes are detached, we store the empty lines in a separate list. List<Node> emptyLines = new ArrayList<Node>(); for (int i = 0; i < divs.getLength(); i++) { Element div = divs.getItem(i).cast(); if (div.hasClassName("wikimodel-emptyline")) { emptyLines.add(div); } } // Replace the empty lines with paragraphs. for (Node emptyLine : emptyLines) { emptyLine.getParentNode().replaceChild(document.createPElement(), emptyLine); } }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.link.EmptyLinkFilter.java
License:Open Source License
/** * @return the list of empty anchors/*from www . j a v a 2 s.co m*/ * @see #isEmpty(Element) */ private List<Element> getEmptyAnchors() { List<Element> emptyAnchors = new ArrayList<Element>(); NodeList<Element> anchorsList = rta.getDocument().getElementsByTagName("a"); for (int i = 0; i < anchorsList.getLength(); i++) { Element anchor = anchorsList.getItem(i); if (isEmpty(AnchorElement.as(anchor))) { emptyAnchors.add(anchor); } } return emptyAnchors; }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.link.LinkMetaDataExtractor.java
License:Open Source License
/** * {@inheritDoc}/*from www . ja va 2s. co m*/ * * @see InnerHTMLListener#onInnerHTMLChange(Element) */ public void onInnerHTMLChange(Element parent) { // look up all images in this subtree NodeList<com.google.gwt.dom.client.Element> anchors = parent.getElementsByTagName("a"); for (int i = 0; i < anchors.getLength(); i++) { Element anchor = (Element) anchors.getItem(i); processElement(anchor); } }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.list.internal.MozillaListBehaviorAdjuster.java
License:Open Source License
/** * {@inheritDoc} In addition to default cleanup, also add a br in each empty list item (<li />), so that it * stays editable.//from w w w.j a v a 2s .co m * * @see ListBehaviorAdjuster#cleanUp(Element) */ protected void cleanUp(Element element) { // default cleanup behavior super.cleanUp(element); // now for each list item, if it's empty, add a line break inside NodeList<com.google.gwt.dom.client.Element> listItems = element.getElementsByTagName(LIST_ITEM_TAG); for (int i = 0; i < listItems.getLength(); i++) { Element currentListItem = (Element) listItems.getItem(i); if (currentListItem.getChildNodes().getLength() == 0) { currentListItem.appendChild(element.getOwnerDocument().createBRElement()); } } }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.list.ListBehaviorAdjuster.java
License:Open Source License
/** * Executes lists clean up on the subtree rooted in the element passed as parameter. Lists cleanup consists of: * <ul>/*from w ww.j a v a 2s.co m*/ * <li>finding all the {@code ul} or {@code ol} tags which are in another {@code ul} or {@code ol} and adding a * {@code li} wrapper around each</li> * <li>finding all the {@code ul} or {@code ol} tags which are at the beginning (first child) of a list item and * making the parent list items editable</li> * </ul> * (but these operations are executed in a single pass). <br /> * Note that while these operations are not enough from a strict xhtml cleaning point of view, they address all the * practical cases that appear so we chose to limit the operations executed to only these for performance reasons. * * @param element the root element of the subtree in which to execute cleanup. */ protected void cleanUp(Element element) { // find all lists NodeList<com.google.gwt.dom.client.Element> orderedLists = element.getElementsByTagName(ORDERED_LIST_TAG); NodeList<com.google.gwt.dom.client.Element> unorderedLists = element .getElementsByTagName(UNORDERED_LIST_TAG); // send them to the actual cleaner cleanUpLists(orderedLists); cleanUpLists(unorderedLists); // Ensure that each list item can be edited. NodeList<com.google.gwt.dom.client.Element> listItems = element.getElementsByTagName(LIST_ITEM_TAG); for (int i = 0; i < listItems.getLength(); i++) { Element.as(listItems.getItem(i)).ensureEditable(); } }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.list.ListBehaviorAdjuster.java
License:Open Source License
/** * Helper function to handle a list of list elements and clean them. * /*from w w w .jav a 2s.c om*/ * @param listElements the list elements to clean up, according to the description at {@link #cleanUp(Element)} */ protected void cleanUpLists(NodeList<com.google.gwt.dom.client.Element> listElements) { for (int i = 0; i < listElements.getLength(); i++) { Element listElement = (Element) listElements.getItem(i); // check the parent of this list Element if (listElement.getParentNode().getNodeName().equalsIgnoreCase(ORDERED_LIST_TAG) || listElement.getParentNode().getNodeName().equalsIgnoreCase(UNORDERED_LIST_TAG)) { wrapList(listElement); } // check if this element is the first element of a list item if (listElement.getParentNode().getNodeName().equalsIgnoreCase(LIST_ITEM_TAG) && listElement.getPreviousSibling() == null) { // is first element handleEmptyListItem((Element) listElement.getParentNode()); } } }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.style.StylePlugin.java
License:Open Source License
/** * Initialize the style name picker.//www. j a va2s . com */ private void initStyleNamePicker() { styleNamePicker = new ListBox(); styleNamePicker.setTitle(Strings.INSTANCE.stylePickerTitle()); styleNamePicker.addStyleName("xStyleNamePicker"); styleNamePicker.addItem(Strings.INSTANCE.stylePickerLabel(), ""); saveRegistration(styleNamePicker.addChangeHandler(this)); StyleDescriptorJSONParser parser = new StyleDescriptorJSONParser(); for (StyleDescriptor descriptor : parser.parse(getConfig().getParameter("styleNames", "[]"))) { styleNamePicker.addItem(descriptor.getLabel(), descriptor.getName()); NodeList<OptionElement> options = SelectElement.as(styleNamePicker.getElement()).getOptions(); OptionElement option = options.getItem(options.getLength() - 1); option.setPropertyBoolean(INLINE, descriptor.isInline()); (descriptor.isInline() ? inlineStyles : blockStyles).add(option); } if (blockStyles.size() > 0 && inlineStyles.size() > 0) { groupStyleNames(Strings.INSTANCE.styleBlockGroupLabel(), blockStyles); groupStyleNames(Strings.INSTANCE.styleInlineGroupLabel(), inlineStyles); } styleNamePicker.setSelectedIndex(0); toolBarExtension.addFeature("stylename", styleNamePicker); }