Path: blob/trunk/third_party/closure/goog/dom/pattern/callback/callback.js
2871 views
// Copyright 2007 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Useful callback functions for the DOM matcher.16*17* @author [email protected] (Robby Walker)18*/1920goog.provide('goog.dom.pattern.callback');2122goog.require('goog.dom');23goog.require('goog.dom.TagWalkType');24goog.require('goog.iter');252627/**28* Callback function for use in {@link goog.dom.pattern.Matcher.addPattern}29* that removes the matched node from the tree. Should be used in conjunciton30* with a {@link goog.dom.pattern.StartTag} pattern.31*32* @param {Node} node The node matched by the pattern.33* @param {goog.dom.TagIterator} position The position where the match34* finished.35* @return {boolean} Returns true to indicate tree changes were made.36*/37goog.dom.pattern.callback.removeNode = function(node, position) {38// Find out which position would be next.39position.setPosition(node, goog.dom.TagWalkType.END_TAG);4041goog.iter.nextOrValue(position, null);4243// Remove the node.44goog.dom.removeNode(node);4546// Correct for the depth change.47position.depth -= 1;4849// Indicate that we made position/tree changes.50return true;51};525354/**55* Callback function for use in {@link goog.dom.pattern.Matcher.addPattern}56* that removes the matched node from the tree and replaces it with its57* children. Should be used in conjunction with a58* {@link goog.dom.pattern.StartTag} pattern.59*60* @param {Element} node The node matched by the pattern.61* @param {goog.dom.TagIterator} position The position where the match62* finished.63* @return {boolean} Returns true to indicate tree changes were made.64*/65goog.dom.pattern.callback.flattenElement = function(node, position) {66// Find out which position would be next.67position.setPosition(68node, node.firstChild ? goog.dom.TagWalkType.START_TAG :69goog.dom.TagWalkType.END_TAG);7071goog.iter.nextOrValue(position, null);7273// Flatten the node.74goog.dom.flattenElement(node);7576// Correct for the depth change.77position.depth -= 1;7879// Indicate that we made position/tree changes.80return true;81};828384