Path: blob/trunk/third_party/closure/goog/dom/pattern/callback/test.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 Callback object that tests if a pattern matches at least once.16*17* @author [email protected] (Robby Walker)18*/1920goog.provide('goog.dom.pattern.callback.Test');2122goog.require('goog.iter.StopIteration');23242526/**27* Callback class for testing for at least one match.28* @constructor29* @final30*/31goog.dom.pattern.callback.Test = function() {32/**33* Whether or not the pattern matched.34*35* @type {boolean}36*/37this.matched = false;3839/**40* The callback function. Suitable as a callback for41* {@link goog.dom.pattern.Matcher}.42* @private {Function}43*/44this.callback_ = null;45};464748/**49* Get a bound callback function that is suitable as a callback for50* {@link goog.dom.pattern.Matcher}.51*52* @return {!Function} A callback function.53*/54goog.dom.pattern.callback.Test.prototype.getCallback = function() {55if (!this.callback_) {56this.callback_ = goog.bind(function(node, position) {57// Mark our match.58this.matched = true;5960// Stop searching.61throw goog.iter.StopIteration;62}, this);63}64return this.callback_;65};666768/**69* Reset the counter.70*/71goog.dom.pattern.callback.Test.prototype.reset = function() {72this.matched = false;73};747576