diff options
Diffstat (limited to 'contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base')
53 files changed, 0 insertions, 15413 deletions
diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/a11y.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/a11y.js.svn-base deleted file mode 100644 index 1ee6463..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/a11y.js.svn-base +++ /dev/null @@ -1,541 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for adding, removing and setting ARIA roles - * as defined by W3C ARIA Working Draft: - * http://www.w3.org/TR/2010/WD-wai-aria-20100916/ - * All modern browsers have some form of ARIA support, so no browser checks are - * performed when adding ARIA to components. - * - */ -goog.provide('goog.dom.a11y'); -goog.provide('goog.dom.a11y.Announcer'); -goog.provide('goog.dom.a11y.LivePriority'); -goog.provide('goog.dom.a11y.Role'); -goog.provide('goog.dom.a11y.State'); - -goog.require('goog.Disposable'); -goog.require('goog.dom'); -goog.require('goog.object'); - - -/** - * Enumeration of ARIA states and properties. - * @enum {string} - */ -goog.dom.a11y.State = { - // ARIA property for setting the currently active descendant of an element, - // for example the selected item in a list box. Value: ID of an element. - ACTIVEDESCENDANT: 'activedescendant', - - // ARIA property that, if true, indicates that all of a changed region should - // be presented, instead of only parts. Value: one of {true, false}. - ATOMIC: 'atomic', - - // ARIA property to specify that input completion is provided. Value: - // one of {'inline', 'list', 'both', 'none'}. - AUTOCOMPLETE: 'autocomplete', - - // ARIA state to indicate that an element and its subtree are being updated. - // Value: one of {true, false}. - BUSY: 'busy', - - // ARIA state for a checked item. Value: one of {'true', 'false', 'mixed', - // undefined}. - CHECKED: 'checked', - - // ARIA property that identifies the element or elements whose contents or - // presence are controlled by this element. Value: space-separated IDs of - // other elements. - CONTROLS: 'controls', - - // ARIA property that identifies the element or elements that describe - // this element. Value: space-separated IDs of other elements. - DESCRIBEDBY: 'describedby', - - // ARIA state for a disabled item. Value: one of {true, false}. - DISABLED: 'disabled', - - // ARIA property that indicates what functions can be performed when a - // dragged object is released on the drop target. Value: one of - // {'copy', 'move', 'link', 'execute', 'popup', 'none'}. - DROPEFFECT: 'dropeffect', - - // ARIA state for setting whether the element like a tree node is expanded. - // Value: one of {true, false, undefined}. - EXPANDED: 'expanded', - - // ARIA property that identifies the next element (or elements) in the - // recommended reading order of content. Value: space-separated ids of - // elements to flow to. - FLOWTO: 'flowto', - - // ARIA state that indicates an element's "grabbed" state in drag-and-drop. - // Value: one of {true, false, undefined}. - GRABBED: 'grabbed', - - // ARIA property indicating whether the element has a popup. Value: one of - // {true, false}. - HASPOPUP: 'haspopup', - - // ARIA state indicating that the element is not visible or perceivable - // to any user. Value: one of {true, false}. - HIDDEN: 'hidden', - - // ARIA state indicating that the entered value does not conform. Value: - // one of {false, true, 'grammar', 'spelling'} - INVALID: 'invalid', - - // ARIA property that provides a label to override any other text, value, or - // contents used to describe this element. Value: string. - LABEL: 'label', - - // ARIA property for setting the element which labels another element. - // Value: space-separated IDs of elements. - LABELLEDBY: 'labelledby', - - // ARIA property for setting the level of an element in the hierarchy. - // Value: integer. - LEVEL: 'level', - - // ARIA property indicating that an element will be updated, and - // describes the types of updates the user agents, assistive technologies, - // and user can expect from the live region. Value: one of {'off', 'polite', - // 'assertive'}. - LIVE: 'live', - - // ARIA property indicating whether a text box can accept multiline input. - // Value: one of {true, false}. - MULTILINE: 'multiline', - - // ARIA property indicating if the user may select more than one item. - // Value: one of {true, false}. - MULTISELECTABLE: 'multiselectable', - - // ARIA property indicating if the element is horizontal or vertical. - // Value: one of {'vertical', 'horizontal'}. - ORIENTATION: 'orientation', - - // ARIA property creating a visual, functional, or contextual parent/child - // relationship when the DOM hierarchy can't be used to represent it. - // Value: Space-separated IDs of elements. - OWNS: 'owns', - - // ARIA property that defines an element's number of position in a list. - // Value: integer. - POSINSET: 'posinset', - - // ARIA state for a pressed item. Value: one of {true, false, undefined, - // 'mixed'}. - PRESSED: 'pressed', - - // ARIA property indicating that an element is not editable. Value: - // one of {true, false}. - READONLY: 'readonly', - - // ARIA property indicating that change notifications within this subtree - // of a live region should be announced. Value: one of {'additions', - // 'removals', 'text', 'all', 'additions text'}. - RELEVANT: 'relevant', - - // ARIA property indicating that user input is required on this element - // before a form may be submitted. Value: one of {true, false}. - REQUIRED: 'required', - - // ARIA state for setting the currently selected item in the list. - // Value: one of {true, false, undefined}. - SELECTED: 'selected', - - // ARIA property defining the number of items in a list. Value: integer. - SETSIZE: 'setsize', - - // ARIA property indicating if items are sorted. Value: one of {'ascending', - // 'descending', 'none', 'other'}. - SORT: 'sort', - - // ARIA property for slider maximum value. Value: number. - VALUEMAX: 'valuemax', - - // ARIA property for slider minimum value. Value: number. - VALUEMIN: 'valuemin', - - // ARIA property for slider active value. Value: number. - VALUENOW: 'valuenow', - - // ARIA property for slider active value represented as text. Value: string. - VALUETEXT: 'valuetext' -}; - - -/** - * Enumeration of ARIA roles. - * @enum {string} - */ -goog.dom.a11y.Role = { - // ARIA role for an alert element that doesn't need to be explicitly closed. - ALERT: 'alert', - - // ARIA role for an alert dialog element that takes focus and must be closed. - ALERTDIALOG: 'alertdialog', - - // ARIA role for an application that implements its own keyboard navigation. - APPLICATION: 'application', - - // ARIA role for an article. - ARTICLE: 'article', - - // ARIA role for a banner containing mostly site content, not page content. - BANNER: 'banner', - - // ARIA role for a button element. - BUTTON: 'button', - - // ARIA role for a checkbox button element; use with the CHECKED state. - CHECKBOX: 'checkbox', - - // ARIA role for a column header of a table or grid. - COLUMNHEADER: 'columnheader', - - // ARIA role for a combo box element. - COMBOBOX: 'combobox', - - // ARIA role for a supporting section of the document. - COMPLEMENTARY: 'complementary', - - // ARIA role for a dialog, some descendant must take initial focus. - DIALOG: 'dialog', - - // ARIA role for a directory, like a table of contents. - DIRECTORY: 'directory', - - // ARIA role for a part of a page that's a document, not a web application. - DOCUMENT: 'document', - - // ARIA role for a landmark region logically considered one form. - FORM: 'form', - - // ARIA role for an interactive control of tabular data. - GRID: 'grid', - - // ARIA role for a cell in a grid. - GRIDCELL: 'gridcell', - - // ARIA role for a group of related elements like tree item siblings. - GROUP: 'group', - - // ARIA role for a heading element. - HEADING: 'heading', - - // ARIA role for a container of elements that together comprise one image. - IMG: 'img', - - // ARIA role for a link. - LINK: 'link', - - // ARIA role for a list of non-interactive list items. - LIST: 'list', - - // ARIA role for a listbox. - LISTBOX: 'listbox', - - // ARIA role for a list item. - LISTITEM: 'listitem', - - // ARIA role for a live region where new information is added. - LOG: 'log', - - // ARIA landmark role for the main content in a document. Use only once. - MAIN: 'main', - - // ARIA role for a live region of non-essential information that changes. - MARQUEE: 'marquee', - - // ARIA role for a mathematical expression. - MATH: 'math', - - // ARIA role for a popup menu. - MENU: 'menu', - - // ARIA role for a menubar element containing menu elements. - MENUBAR: 'menubar', - - // ARIA role for menu item elements. - MENU_ITEM: 'menuitem', - - // ARIA role for a checkbox box element inside a menu. - MENU_ITEM_CHECKBOX: 'menuitemcheckbox', - - // ARIA role for a radio button element inside a menu. - MENU_ITEM_RADIO: 'menuitemradio', - - // ARIA landmark role for a collection of navigation links. - NAVIGATION: 'navigation', - - // ARIA role for a section ancillary to the main content. - NOTE: 'note', - - // ARIA role for option items that are children of combobox, listbox, menu, - // radiogroup, or tree elements. - OPTION: 'option', - - // ARIA role for ignorable cosmetic elements with no semantic significance. - PRESENTATION: 'presentation', - - // ARIA role for a progress bar element. - PROGRESSBAR: 'progressbar', - - // ARIA role for a radio button element. - RADIO: 'radio', - - // ARIA role for a group of connected radio button elements. - RADIOGROUP: 'radiogroup', - - // ARIA role for an important region of the page. - REGION: 'region', - - // ARIA role for a row of cells in a grid. - ROW: 'row', - - // ARIA role for a group of one or more rows in a grid. - ROWGROUP: 'rowgroup', - - // ARIA role for a row header of a table or grid. - ROWHEADER: 'rowheader', - - // ARIA role for a scrollbar element. - SCROLLBAR: 'scrollbar', - - // ARIA landmark role for a part of the page providing search functionality. - SEARCH: 'search', - - // ARIA role for a menu separator. - SEPARATOR: 'separator', - - // ARIA role for a slider. - SLIDER: 'slider', - - // ARIA role for a spin button. - SPINBUTTON: 'spinbutton', - - // ARIA role for a live region with advisory info less severe than an alert. - STATUS: 'status', - - // ARIA role for a tab button. - TAB: 'tab', - - // ARIA role for a tab bar (i.e. a list of tab buttons). - TAB_LIST: 'tablist', - - // ARIA role for a tab page (i.e. the element holding tab contents). - TAB_PANEL: 'tabpanel', - - // ARIA role for a textbox element. - TEXTBOX: 'textbox', - - // ARIA role for an element displaying elapsed time or time remaining. - TIMER: 'timer', - - // ARIA role for a toolbar element. - TOOLBAR: 'toolbar', - - // ARIA role for a tooltip element. - TOOLTIP: 'tooltip', - - // ARIA role for a tree. - TREE: 'tree', - - // ARIA role for a grid whose rows can be expanded and collapsed like a tree. - TREEGRID: 'treegrid', - - // ARIA role for a tree item that sometimes may be expanded or collapsed. - TREEITEM: 'treeitem' -}; - - -/** - * Enumeration of ARIA state values for live regions. - * - * See http://www.w3.org/TR/wai-aria/states_and_properties#aria-live - * for more information. - * @enum {string} - */ -goog.dom.a11y.LivePriority = { - /** - * Default value. Used for live regions that should never be spoken. - */ - OFF: 'off', - /** - * Spoke only when the user is idle. Best option in most cases. - */ - POLITE: 'polite', - /** - * Spoken as soon as possible, which means that the information has a - * higher priority than normal, but does not necessarily interrupt - * immediately. - */ - ASSERTIVE: 'assertive' -}; - - -/** - * Sets the role of an element. - * @param {Element} element DOM node to set role of. - * @param {string} roleName role name(s). - */ -goog.dom.a11y.setRole = function(element, roleName) { - element.setAttribute('role', roleName); - element.roleName = roleName; -}; - - -/** - * Gets role of an element. - * @param {Element} element DOM node to get role of. - * @return {string} rolename. - */ -goog.dom.a11y.getRole = function(element) { - return element.roleName || ''; -}; - - -/** - * Sets the state or property of an element. - * @param {Element} element DOM node where we set state. - * @param {string} state State attribute being set. Automatically adds prefix - * 'aria-' to the state name. - * @param {string|boolean|number} value Value for the state attribute. - */ -goog.dom.a11y.setState = function(element, state, value) { - element.setAttribute('aria-' + state, value); -}; - - -/** - * Gets value of specified state or property. - * @param {Element} element DOM node to get state from. - * @param {string} stateName State name. - * @return {string} Value of the state attribute. - */ -goog.dom.a11y.getState = function(element, stateName) { - var attrb = - /** @type {string|number|boolean} */(element.getAttribute('aria-' + - stateName)); - // Check for multiple representations - attrb might - // be a boolean or a string - if ((attrb === true) || (attrb === false)) { - return attrb ? 'true' : 'false'; - } else if (!attrb) { - return ''; - } else { - return String(attrb); - } -}; - - -/** - * Gets the activedescendant of the given element. - * @param {Element} element DOM node to get activedescendant from. - * @return {Element} DOM node of the activedescendant. - */ -goog.dom.a11y.getActiveDescendant = function(element) { - var id = goog.dom.a11y.getState( - element, goog.dom.a11y.State.ACTIVEDESCENDANT); - return goog.dom.getOwnerDocument(element).getElementById(id); -}; - - -/** - * Sets the activedescendant value for an element. - * @param {Element} element DOM node to set activedescendant to. - * @param {Element} activeElement DOM node being set as activedescendant. - */ -goog.dom.a11y.setActiveDescendant = function(element, activeElement) { - goog.dom.a11y.setState(element, goog.dom.a11y.State.ACTIVEDESCENDANT, - activeElement ? activeElement.id : ''); -}; - - - -/** - * Class that allows messages to be spoken by assistive technologies that the - * user may have active. - * - * @param {goog.dom.DomHelper} domHelper DOM helper. - * @constructor - * @extends {goog.Disposable} - */ -goog.dom.a11y.Announcer = function(domHelper) { - goog.base(this); - - /** - * @type {goog.dom.DomHelper} - * @private - */ - this.domHelper_ = domHelper; - - /** - * Map of priority to live region elements to use for communicating updates. - * Elements are created on demand. - * @type {Object.<goog.dom.a11y.LivePriority, Element>} - * @private - */ - this.liveRegions_ = {}; -}; -goog.inherits(goog.dom.a11y.Announcer, goog.Disposable); - - -/** @override */ -goog.dom.a11y.Announcer.prototype.disposeInternal = function() { - goog.object.forEach( - this.liveRegions_, this.domHelper_.removeNode, this.domHelper_); - this.liveRegions_ = null; - this.domHelper_ = null; - goog.base(this, 'disposeInternal'); -}; - - -/** - * Announce a message to be read by any assistive technologies the user may - * have active. - * @param {string} message The message to announce to screen readers. - * @param {goog.dom.a11y.LivePriority=} opt_priority The priority of the - * message. Defaults to POLITE. - */ -goog.dom.a11y.Announcer.prototype.say = function(message, opt_priority) { - goog.dom.setTextContent(this.getLiveRegion_( - opt_priority || goog.dom.a11y.LivePriority.POLITE), message); -}; - - -/** - * Returns an aria-live region that can be used to communicate announcements. - * @param {goog.dom.a11y.LivePriority} priority The required priority. - * @return {Element} A live region of the requested priority. - * @private - */ -goog.dom.a11y.Announcer.prototype.getLiveRegion_ = function(priority) { - if (this.liveRegions_[priority]) { - return this.liveRegions_[priority]; - } - var liveRegion; - liveRegion = this.domHelper_.createElement('div'); - liveRegion.style.position = 'absolute'; - liveRegion.style.top = '-1000px'; - goog.dom.a11y.setState(liveRegion, 'live', priority); - goog.dom.a11y.setState(liveRegion, 'atomic', 'true'); - this.domHelper_.getDocument().body.appendChild(liveRegion); - this.liveRegions_[priority] = liveRegion; - return liveRegion; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/a11y_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/a11y_test.html.svn-base deleted file mode 100644 index 9d7daba..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/a11y_test.html.svn-base +++ /dev/null @@ -1,140 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- -Author: attila@google.com (Attila Bodis) ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> - <title>Closure Unit Tests - goog.dom.a11y</title> - <script src="../base.js"></script> - <script> - goog.require('goog.dom'); - goog.require('goog.dom.a11y'); - goog.require('goog.dom.a11y.Announcer'); - goog.require('goog.dom.a11y.LivePriority'); - goog.require('goog.dom.a11y.Role'); - goog.require('goog.dom.a11y.State'); - goog.require('goog.dom.iframe'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); - </script> -</head> -<body> - <div id="sandbox"></div> - <script> - var sandbox = goog.dom.getElement('sandbox'); - var someDiv; - var someSpan; - - function setUp() { - someDiv = goog.dom.createDom('div', {id: 'someDiv'}, 'DIV'); - someSpan = goog.dom.createDom('span', {id: 'someSpan'}, 'SPAN'); - sandbox.appendChild(someDiv); - someDiv.appendChild(someSpan); - } - - function tearDown() { - sandbox.innerHTML = ''; - someDiv = null; - someSpan = null; - } - - function testGetSetRole() { - assertEquals('someDiv\'s role should be the empty string', - '', goog.dom.a11y.getRole(someDiv)); - assertEquals('someSpan\'s role should be the empty string', - '', goog.dom.a11y.getRole(someSpan)); - - goog.dom.a11y.setRole(someDiv, goog.dom.a11y.Role.MENU); - goog.dom.a11y.setRole(someSpan, goog.dom.a11y.Role.MENU_ITEM); - - assertEquals('someDiv\'s role should be MENU', - goog.dom.a11y.Role.MENU, goog.dom.a11y.getRole(someDiv)); - assertEquals('someSpan\'s role should be MENU_ITEM', - goog.dom.a11y.Role.MENU_ITEM, goog.dom.a11y.getRole(someSpan)); - } - - function testGetSetState() { - assertEquals('someDiv\'s state should be the empty string', - '', goog.dom.a11y.getState(someDiv)); - - goog.dom.a11y.setState(someDiv, goog.dom.a11y.State.LABELLEDBY, - 'someSpan'); - - assertEquals( - 'someDiv\'s labelledby state should be "someSpan"', - 'someSpan', - goog.dom.a11y.getState(someDiv, goog.dom.a11y.State.LABELLEDBY)); - } - - function testGetSetActiveDescendant() { - goog.dom.a11y.setActiveDescendant(someDiv, null); - assertNull('someDiv\'s activedescendant should be null', - goog.dom.a11y.getActiveDescendant(someDiv)); - - goog.dom.a11y.setActiveDescendant(someDiv, someSpan); - - assertEquals( - 'someDiv\'s active descendant should be "someSpan"', - someSpan, - goog.dom.a11y.getActiveDescendant(someDiv)); - } - - function testAnnouncerAndDispose() { - var text = 'test content'; - var announcer = new goog.dom.a11y.Announcer(goog.dom.getDomHelper()); - announcer.say(text); - checkLiveRegionContains(text, 'polite'); - goog.dispose(announcer); - } - - function testAnnouncerTwice() { - var text = 'test content1'; - var text2 = 'test content2'; - var announcer = new goog.dom.a11y.Announcer(goog.dom.getDomHelper()); - announcer.say(text); - announcer.say(text2); - checkLiveRegionContains(text2, 'polite'); - goog.dispose(announcer); - } - - function testAnnouncerAssertive() { - var text = 'test content'; - var announcer = new goog.dom.a11y.Announcer(goog.dom.getDomHelper()); - announcer.say(text, goog.dom.a11y.LivePriority.ASSERTIVE); - checkLiveRegionContains(text, 'assertive'); - goog.dispose(announcer); - } - - function testAnnouncerInIframe() { - var text = 'test content'; - var frame = goog.dom.iframe.createWithContent(sandbox); - var helper = goog.dom.getDomHelper( - goog.dom.getFrameContentDocument(frame).body); - var announcer = new goog.dom.a11y.Announcer(helper); - announcer.say(text, 'polite', helper); - checkLiveRegionContains(text, 'polite', helper); - goog.dispose(announcer); - } - - function checkLiveRegionContains(text, priority, opt_domHelper) { - var dom = opt_domHelper || goog.dom.getDomHelper(); - var divs = dom.getElementsByTagNameAndClass('div', null); - var liveRegions = []; - goog.array.forEach(divs, function(div) { - if (goog.dom.a11y.getState(div, 'live') == priority) { - liveRegions.push(div); - } - }); - assertEquals(1, liveRegions.length); - assertEquals(text, goog.dom.getTextContent(liveRegions[0])); - } - </script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractmultirange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractmultirange.js.svn-base deleted file mode 100644 index 58d8c74..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractmultirange.js.svn-base +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for working with ranges comprised of multiple - * sub-ranges. - * - * @author robbyw@google.com (Robby Walker) - * @author jparent@google.com (Julie Parent) - */ - - -goog.provide('goog.dom.AbstractMultiRange'); - -goog.require('goog.array'); -goog.require('goog.dom'); -goog.require('goog.dom.AbstractRange'); - - - -/** - * Creates a new multi range with no properties. Do not use this - * constructor: use one of the goog.dom.Range.createFrom* methods instead. - * @constructor - * @extends {goog.dom.AbstractRange} - */ -goog.dom.AbstractMultiRange = function() { -}; -goog.inherits(goog.dom.AbstractMultiRange, goog.dom.AbstractRange); - - -/** @override */ -goog.dom.AbstractMultiRange.prototype.containsRange = function( - otherRange, opt_allowPartial) { - // TODO(user): This will incorrectly return false if two (or more) adjacent - // elements are both in the control range, and are also in the text range - // being compared to. - var ranges = this.getTextRanges(); - var otherRanges = otherRange.getTextRanges(); - - var fn = opt_allowPartial ? goog.array.some : goog.array.every; - return fn(otherRanges, function(otherRange) { - return goog.array.some(ranges, function(range) { - return range.containsRange(otherRange, opt_allowPartial); - }); - }); -}; - - -/** @override */ -goog.dom.AbstractMultiRange.prototype.insertNode = function(node, before) { - if (before) { - goog.dom.insertSiblingBefore(node, this.getStartNode()); - } else { - goog.dom.insertSiblingAfter(node, this.getEndNode()); - } - return node; -}; - - -/** @override */ -goog.dom.AbstractMultiRange.prototype.surroundWithNodes = function(startNode, - endNode) { - this.insertNode(startNode, true); - this.insertNode(endNode, false); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractrange.js.svn-base deleted file mode 100644 index d3e2c89..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractrange.js.svn-base +++ /dev/null @@ -1,514 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Interface definitions for working with ranges - * in HTML documents. - * - * @author robbyw@google.com (Robby Walker) - */ - - -goog.provide('goog.dom.AbstractRange'); -goog.provide('goog.dom.RangeIterator'); -goog.provide('goog.dom.RangeType'); - -goog.require('goog.dom'); -goog.require('goog.dom.NodeType'); -goog.require('goog.dom.SavedCaretRange'); -goog.require('goog.dom.TagIterator'); -goog.require('goog.userAgent'); - - -/** - * Types of ranges. - * @enum {string} - */ -goog.dom.RangeType = { - TEXT: 'text', - CONTROL: 'control', - MULTI: 'mutli' -}; - - - -/** - * Creates a new selection with no properties. Do not use this constructor - - * use one of the goog.dom.Range.from* methods instead. - * @constructor - */ -goog.dom.AbstractRange = function() { -}; - - -/** - * Gets the browser native selection object from the given window. - * @param {Window} win The window to get the selection object from. - * @return {Object} The browser native selection object, or null if it could - * not be retrieved. - */ -goog.dom.AbstractRange.getBrowserSelectionForWindow = function(win) { - if (win.getSelection) { - // W3C - return win.getSelection(); - } else { - // IE - var doc = win.document; - var sel = doc.selection; - if (sel) { - // IE has a bug where it sometimes returns a selection from the wrong - // document. Catching these cases now helps us avoid problems later. - try { - var range = sel.createRange(); - // Only TextRanges have a parentElement method. - if (range.parentElement) { - if (range.parentElement().document != doc) { - return null; - } - } else if (!range.length || range.item(0).document != doc) { - // For ControlRanges, check that the range has items, and that - // the first item in the range is in the correct document. - return null; - } - } catch (e) { - // If the selection is in the wrong document, and the wrong document is - // in a different domain, IE will throw an exception. - return null; - } - // TODO(user|robbyw) Sometimes IE 6 returns a selection instance - // when there is no selection. This object has a 'type' property equals - // to 'None' and a typeDetail property bound to undefined. Ideally this - // function should not return this instance. - return sel; - } - return null; - } -}; - - -/** - * Tests if the given Object is a controlRange. - * @param {Object} range The range object to test. - * @return {boolean} Whether the given Object is a controlRange. - */ -goog.dom.AbstractRange.isNativeControlRange = function(range) { - // For now, tests for presence of a control range function. - return !!range && !!range.addElement; -}; - - -/** - * @return {goog.dom.AbstractRange} A clone of this range. - */ -goog.dom.AbstractRange.prototype.clone = goog.abstractMethod; - - -/** - * @return {goog.dom.RangeType} The type of range represented by this object. - */ -goog.dom.AbstractRange.prototype.getType = goog.abstractMethod; - - -/** - * @return {Range|TextRange} The native browser range object. - */ -goog.dom.AbstractRange.prototype.getBrowserRangeObject = goog.abstractMethod; - - -/** - * Sets the native browser range object, overwriting any state this range was - * storing. - * @param {Range|TextRange} nativeRange The native browser range object. - * @return {boolean} Whether the given range was accepted. If not, the caller - * will need to call goog.dom.Range.createFromBrowserRange to create a new - * range object. - */ -goog.dom.AbstractRange.prototype.setBrowserRangeObject = function(nativeRange) { - return false; -}; - - -/** - * @return {number} The number of text ranges in this range. - */ -goog.dom.AbstractRange.prototype.getTextRangeCount = goog.abstractMethod; - - -/** - * Get the i-th text range in this range. The behavior is undefined if - * i >= getTextRangeCount or i < 0. - * @param {number} i The range number to retrieve. - * @return {goog.dom.TextRange} The i-th text range. - */ -goog.dom.AbstractRange.prototype.getTextRange = goog.abstractMethod; - - -/** - * Gets an array of all text ranges this range is comprised of. For non-multi - * ranges, returns a single element array containing this. - * @return {Array.<goog.dom.TextRange>} Array of text ranges. - */ -goog.dom.AbstractRange.prototype.getTextRanges = function() { - var output = []; - for (var i = 0, len = this.getTextRangeCount(); i < len; i++) { - output.push(this.getTextRange(i)); - } - return output; -}; - - -/** - * @return {Node} The deepest node that contains the entire range. - */ -goog.dom.AbstractRange.prototype.getContainer = goog.abstractMethod; - - -/** - * Returns the deepest element in the tree that contains the entire range. - * @return {Element} The deepest element that contains the entire range. - */ -goog.dom.AbstractRange.prototype.getContainerElement = function() { - var node = this.getContainer(); - return /** @type {Element} */ ( - node.nodeType == goog.dom.NodeType.ELEMENT ? node : node.parentNode); -}; - - -/** - * @return {Node} The element or text node the range starts in. For text - * ranges, the range comprises all text between the start and end position. - * For other types of range, start and end give bounds of the range but - * do not imply all nodes in those bounds are selected. - */ -goog.dom.AbstractRange.prototype.getStartNode = goog.abstractMethod; - - -/** - * @return {number} The offset into the node the range starts in. For text - * nodes, this is an offset into the node value. For elements, this is - * an offset into the childNodes array. - */ -goog.dom.AbstractRange.prototype.getStartOffset = goog.abstractMethod; - - -/** - * @return {Node} The element or text node the range ends in. - */ -goog.dom.AbstractRange.prototype.getEndNode = goog.abstractMethod; - - -/** - * @return {number} The offset into the node the range ends in. For text - * nodes, this is an offset into the node value. For elements, this is - * an offset into the childNodes array. - */ -goog.dom.AbstractRange.prototype.getEndOffset = goog.abstractMethod; - - -/** - * @return {Node} The element or text node the range is anchored at. - */ -goog.dom.AbstractRange.prototype.getAnchorNode = function() { - return this.isReversed() ? this.getEndNode() : this.getStartNode(); -}; - - -/** - * @return {number} The offset into the node the range is anchored at. For - * text nodes, this is an offset into the node value. For elements, this - * is an offset into the childNodes array. - */ -goog.dom.AbstractRange.prototype.getAnchorOffset = function() { - return this.isReversed() ? this.getEndOffset() : this.getStartOffset(); -}; - - -/** - * @return {Node} The element or text node the range is focused at - i.e. where - * the cursor is. - */ -goog.dom.AbstractRange.prototype.getFocusNode = function() { - return this.isReversed() ? this.getStartNode() : this.getEndNode(); -}; - - -/** - * @return {number} The offset into the node the range is focused at - i.e. - * where the cursor is. For text nodes, this is an offset into the node - * value. For elements, this is an offset into the childNodes array. - */ -goog.dom.AbstractRange.prototype.getFocusOffset = function() { - return this.isReversed() ? this.getStartOffset() : this.getEndOffset(); -}; - - -/** - * @return {boolean} Whether the selection is reversed. - */ -goog.dom.AbstractRange.prototype.isReversed = function() { - return false; -}; - - -/** - * @return {Document} The document this selection is a part of. - */ -goog.dom.AbstractRange.prototype.getDocument = function() { - // Using start node in IE was crashing the browser in some cases so use - // getContainer for that browser. It's also faster for IE, but still slower - // than start node for other browsers so we continue to use getStartNode when - // it is not problematic. See bug 1687309. - return goog.dom.getOwnerDocument(goog.userAgent.IE ? - this.getContainer() : this.getStartNode()); -}; - - -/** - * @return {Window} The window this selection is a part of. - */ -goog.dom.AbstractRange.prototype.getWindow = function() { - return goog.dom.getWindow(this.getDocument()); -}; - - -/** - * Tests if this range contains the given range. - * @param {goog.dom.AbstractRange} range The range to test. - * @param {boolean=} opt_allowPartial If true, the range can be partially - * contained in the selection, otherwise the range must be entirely - * contained. - * @return {boolean} Whether this range contains the given range. - */ -goog.dom.AbstractRange.prototype.containsRange = goog.abstractMethod; - - -/** - * Tests if this range contains the given node. - * @param {Node} node The node to test for. - * @param {boolean=} opt_allowPartial If not set or false, the node must be - * entirely contained in the selection for this function to return true. - * @return {boolean} Whether this range contains the given node. - */ -goog.dom.AbstractRange.prototype.containsNode = function(node, - opt_allowPartial) { - return this.containsRange(goog.dom.Range.createFromNodeContents(node), - opt_allowPartial); -}; - - -/** - * Tests whether this range is valid (i.e. whether its endpoints are still in - * the document). A range becomes invalid when, after this object was created, - * either one or both of its endpoints are removed from the document. Use of - * an invalid range can lead to runtime errors, particularly in IE. - * @return {boolean} Whether the range is valid. - */ -goog.dom.AbstractRange.prototype.isRangeInDocument = goog.abstractMethod; - - -/** - * @return {boolean} Whether the range is collapsed. - */ -goog.dom.AbstractRange.prototype.isCollapsed = goog.abstractMethod; - - -/** - * @return {string} The text content of the range. - */ -goog.dom.AbstractRange.prototype.getText = goog.abstractMethod; - - -/** - * Returns the HTML fragment this range selects. This is slow on all browsers. - * The HTML fragment may not be valid HTML, for instance if the user selects - * from a to b inclusively in the following html: - * - * >div<a>/div<b - * - * This method will return - * - * a</div>b - * - * If you need valid HTML, use {@link #getValidHtml} instead. - * - * @return {string} HTML fragment of the range, does not include context - * containing elements. - */ -goog.dom.AbstractRange.prototype.getHtmlFragment = goog.abstractMethod; - - -/** - * Returns valid HTML for this range. This is fast on IE, and semi-fast on - * other browsers. - * @return {string} Valid HTML of the range, including context containing - * elements. - */ -goog.dom.AbstractRange.prototype.getValidHtml = goog.abstractMethod; - - -/** - * Returns pastable HTML for this range. This guarantees that any child items - * that must have specific ancestors will have them, for instance all TDs will - * be contained in a TR in a TBODY in a TABLE and all LIs will be contained in - * a UL or OL as appropriate. This is semi-fast on all browsers. - * @return {string} Pastable HTML of the range, including context containing - * elements. - */ -goog.dom.AbstractRange.prototype.getPastableHtml = goog.abstractMethod; - - -/** - * Returns a RangeIterator over the contents of the range. Regardless of the - * direction of the range, the iterator will move in document order. - * @param {boolean=} opt_keys Unused for this iterator. - * @return {goog.dom.RangeIterator} An iterator over tags in the range. - */ -goog.dom.AbstractRange.prototype.__iterator__ = goog.abstractMethod; - - -// RANGE ACTIONS - - -/** - * Sets this range as the selection in its window. - */ -goog.dom.AbstractRange.prototype.select = goog.abstractMethod; - - -/** - * Removes the contents of the range from the document. - */ -goog.dom.AbstractRange.prototype.removeContents = goog.abstractMethod; - - -/** - * Inserts a node before (or after) the range. The range may be disrupted - * beyond recovery because of the way this splits nodes. - * @param {Node} node The node to insert. - * @param {boolean} before True to insert before, false to insert after. - * @return {Node} The node added to the document. This may be different - * than the node parameter because on IE we have to clone it. - */ -goog.dom.AbstractRange.prototype.insertNode = goog.abstractMethod; - - -/** - * Replaces the range contents with (possibly a copy of) the given node. The - * range may be disrupted beyond recovery because of the way this splits nodes. - * @param {Node} node The node to insert. - * @return {Node} The node added to the document. This may be different - * than the node parameter because on IE we have to clone it. - */ -goog.dom.AbstractRange.prototype.replaceContentsWithNode = function(node) { - if (!this.isCollapsed()) { - this.removeContents(); - } - - return this.insertNode(node, true); -}; - - -/** - * Surrounds this range with the two given nodes. The range may be disrupted - * beyond recovery because of the way this splits nodes. - * @param {Element} startNode The node to insert at the start. - * @param {Element} endNode The node to insert at the end. - */ -goog.dom.AbstractRange.prototype.surroundWithNodes = goog.abstractMethod; - - -// SAVE/RESTORE - - -/** - * Saves the range so that if the start and end nodes are left alone, it can - * be restored. - * @return {goog.dom.SavedRange} A range representation that can be restored - * as long as the endpoint nodes of the selection are not modified. - */ -goog.dom.AbstractRange.prototype.saveUsingDom = goog.abstractMethod; - - -/** - * Saves the range using HTML carets. As long as the carets remained in the - * HTML, the range can be restored...even when the HTML is copied across - * documents. - * @return {goog.dom.SavedCaretRange?} A range representation that can be - * restored as long as carets are not removed. Returns null if carets - * could not be created. - */ -goog.dom.AbstractRange.prototype.saveUsingCarets = function() { - return (this.getStartNode() && this.getEndNode()) ? - new goog.dom.SavedCaretRange(this) : null; -}; - - -// RANGE MODIFICATION - - -/** - * Collapses the range to one of its boundary points. - * @param {boolean} toAnchor Whether to collapse to the anchor of the range. - */ -goog.dom.AbstractRange.prototype.collapse = goog.abstractMethod; - -// RANGE ITERATION - - - -/** - * Subclass of goog.dom.TagIterator that iterates over a DOM range. It - * adds functions to determine the portion of each text node that is selected. - * @param {Node} node The node to start traversal at. When null, creates an - * empty iterator. - * @param {boolean=} opt_reverse Whether to traverse nodes in reverse. - * @constructor - * @extends {goog.dom.TagIterator} - */ -goog.dom.RangeIterator = function(node, opt_reverse) { - goog.dom.TagIterator.call(this, node, opt_reverse, true); -}; -goog.inherits(goog.dom.RangeIterator, goog.dom.TagIterator); - - -/** - * @return {number} The offset into the current node, or -1 if the current node - * is not a text node. - */ -goog.dom.RangeIterator.prototype.getStartTextOffset = goog.abstractMethod; - - -/** - * @return {number} The end offset into the current node, or -1 if the current - * node is not a text node. - */ -goog.dom.RangeIterator.prototype.getEndTextOffset = goog.abstractMethod; - - -/** - * @return {Node} node The iterator's start node. - */ -goog.dom.RangeIterator.prototype.getStartNode = goog.abstractMethod; - - -/** - * @return {Node} The iterator's end node. - */ -goog.dom.RangeIterator.prototype.getEndNode = goog.abstractMethod; - - -/** - * @return {boolean} Whether a call to next will fail. - */ -goog.dom.RangeIterator.prototype.isLast = goog.abstractMethod; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractrange_test.html.svn-base deleted file mode 100644 index 8b8a409..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/abstractrange_test.html.svn-base +++ /dev/null @@ -1,73 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2009 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.abstractrange</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.AbstractRange'); - goog.require('goog.dom.Range'); - - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> -<iframe src="javascript:"<html><body contenteditable>asdf"" - id="a"> -</iframe> -<iframe src="javascript:"<html><body contenteditable>asdf"" - id="b"> -</iframe> -<iframe src="javascript:"<html><body contenteditable><img>"" - id="c"> -</iframe> -<script> - function testCorrectDocument() { - var a = goog.dom.getElement('a').contentWindow; - var b = goog.dom.getElement('b').contentWindow; - - a.document.body.focus(); - var selection = goog.dom.AbstractRange.getBrowserSelectionForWindow(a); - assertNotNull('Selection must not be null', selection); - var range = goog.dom.Range.createFromBrowserSelection(selection); - assertEquals('getBrowserSelectionForWindow must return selection in the ' + - 'correct document', a.document, range.getDocument()); - - // This is intended to trip up Internet Explorer -- - // see http://b/2048934 - b.document.body.focus(); - selection = goog.dom.AbstractRange.getBrowserSelectionForWindow(a); - // Some (non-IE) browsers keep a separate selection state for each document - // in the same browser window. That's fine, as long as the selection object - // requested from the window object is correctly associated with that - // window's document. - if (selection) { - range = goog.dom.Range.createFromBrowserSelection(selection); - assertEquals('getBrowserSelectionForWindow must return selection in ' + - 'the correct document', a.document, range.getDocument()); - } else { - assertNull(selection); - } - } - - function testSelectionIsControlRange() { - var c = goog.dom.getElement('c').contentWindow; - // Only IE supports control ranges - if (c.document.body.createControlRange) { - var controlRange = c.document.body.createControlRange(); - controlRange.add(c.document.getElementsByTagName('img')[0]); - controlRange.select(); - var selection = goog.dom.AbstractRange.getBrowserSelectionForWindow(c); - assertNotNull('Selection must not be null', selection); - } - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/annotate.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/annotate.js.svn-base deleted file mode 100644 index 1f5c7fc..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/annotate.js.svn-base +++ /dev/null @@ -1,352 +0,0 @@ -// Copyright 2006 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Methods for annotating occurrences of query terms in text or - * in a DOM tree. Adapted from Gmail code. - * - */ - -goog.provide('goog.dom.annotate'); - -goog.require('goog.array'); -goog.require('goog.dom'); -goog.require('goog.dom.NodeType'); -goog.require('goog.string'); - - -/** - * Calls {@code annotateFn} for each occurrence of a search term in text nodes - * under {@code node}. Returns the number of hits. - * - * @param {Node} node A DOM node. - * @param {Array} terms An array of [searchTerm, matchWholeWordOnly] tuples. - * The matchWholeWordOnly value is a per-term attribute because some terms - * may be CJK, while others are not. (For correctness, matchWholeWordOnly - * should always be false for CJK terms.). - * @param {Function} annotateFn A function that takes - * (1) the number of the term that is "hit", - * (2) the HTML string (search term) to be annotated, - * and returns the annotated term as an HTML string. - * @param {*=} opt_ignoreCase Whether to ignore the case of the query - * terms when looking for matches. - * @param {Array.<string>=} opt_classesToSkip Nodes with one of these CSS class - * names (and its descendants) will be skipped. - * @param {number=} opt_maxMs Number of milliseconds after which this function, - * if still annotating, should stop and return. - * - * @return {boolean} Whether any terms were annotated. - */ -goog.dom.annotate.annotateTerms = function(node, terms, annotateFn, - opt_ignoreCase, - opt_classesToSkip, - opt_maxMs) { - var stopTime = opt_maxMs > 0 ? goog.now() + opt_maxMs : 0; - - return goog.dom.annotate.annotateTermsInNode_( - node, terms, annotateFn, opt_ignoreCase, opt_classesToSkip || [], - stopTime, 0); -}; - - -/** - * The maximum recursion depth allowed. Any DOM nodes deeper than this are - * ignored. - * @type {number} - * @private - */ -goog.dom.annotate.MAX_RECURSION_ = 200; - - -/** - * The node types whose descendants should not be affected by annotation. - * @type {Array} - * @private - */ -goog.dom.annotate.NODES_TO_SKIP_ = ['SCRIPT', 'STYLE', 'TEXTAREA']; - - -/** - * Recursive helper function. - * - * @param {Node} node A DOM node. - * @param {Array} terms An array of [searchTerm, matchWholeWordOnly] tuples. - * The matchWholeWordOnly value is a per-term attribute because some terms - * may be CJK, while others are not. (For correctness, matchWholeWordOnly - * should always be false for CJK terms.). - * @param {Function} annotateFn function(number, string) : string A function - * that takes : - * (1) the number of the term that is "hit", - * (2) the HTML string (search term) to be annotated, - * and returns the annotated term as an HTML string. - * @param {*} ignoreCase Whether to ignore the case of the query terms - * when looking for matches. - * @param {Array.<string>} classesToSkip Nodes with one of these CSS class - * names will be skipped (as will their descendants). - * @param {number} stopTime Deadline for annotation operation (ignored if 0). - * @param {number} recursionLevel How deep this recursive call is; pass the - * value 0 in the initial call. - * @return {boolean} Whether any terms were annotated. - * @private - */ -goog.dom.annotate.annotateTermsInNode_ = - function(node, terms, annotateFn, ignoreCase, classesToSkip, - stopTime, recursionLevel) { - if ((stopTime > 0 && goog.now() >= stopTime) || - recursionLevel > goog.dom.annotate.MAX_RECURSION_) { - return false; - } - - var annotated = false; - - if (node.nodeType == goog.dom.NodeType.TEXT) { - var html = goog.dom.annotate.helpAnnotateText_(node.nodeValue, terms, - annotateFn, ignoreCase); - if (html != null) { - // Replace the text with the annotated html. First we put the html into - // a temporary node, to get its DOM structure. To avoid adding a wrapper - // element as a side effect, we'll only actually use the temporary node's - // children. - var tempNode = goog.dom.getOwnerDocument(node).createElement('SPAN'); - tempNode.innerHTML = html; - - var parentNode = node.parentNode; - var nodeToInsert; - while ((nodeToInsert = tempNode.firstChild) != null) { - // Each parentNode.insertBefore call removes the inserted node from - // tempNode's list of children. - parentNode.insertBefore(nodeToInsert, node); - } - - parentNode.removeChild(node); - annotated = true; - } - } else if (node.hasChildNodes() && - !goog.array.contains(goog.dom.annotate.NODES_TO_SKIP_, - node.tagName)) { - var classes = node.className.split(/\s+/); - var skip = goog.array.some(classes, function(className) { - return goog.array.contains(classesToSkip, className); - }); - - if (!skip) { - ++recursionLevel; - var curNode = node.firstChild; - var numTermsAnnotated = 0; - while (curNode) { - var nextNode = curNode.nextSibling; - var curNodeAnnotated = goog.dom.annotate.annotateTermsInNode_( - curNode, terms, annotateFn, ignoreCase, classesToSkip, - stopTime, recursionLevel); - annotated = annotated || curNodeAnnotated; - curNode = nextNode; - } - } - } - - return annotated; -}; - - -/** - * Regular expression that matches non-word characters. - * - * Performance note: Testing a one-character string using this regex is as fast - * as the equivalent string test ("a-zA-Z0-9_".indexOf(c) < 0), give or take a - * few percent. (The regex is about 5% faster in IE 6 and about 4% slower in - * Firefox 1.5.) If performance becomes critical, it may be better to convert - * the character to a numerical char code and check whether it falls in the - * word character ranges. A quick test suggests that could be 33% faster. - * - * @type {RegExp} - * @private - */ -goog.dom.annotate.NONWORD_RE_ = /\W/; - - -/** - * Annotates occurrences of query terms in plain text. This process consists of - * identifying all occurrences of all query terms, calling a provided function - * to get the appropriate replacement HTML for each occurrence, and - * HTML-escaping all the text. - * - * @param {string} text The plain text to be searched. - * @param {Array} terms An array of - * [{string} searchTerm, {boolean} matchWholeWordOnly] tuples. - * The matchWholeWordOnly value is a per-term attribute because some terms - * may be CJK, while others are not. (For correctness, matchWholeWordOnly - * should always be false for CJK terms.). - * @param {Function} annotateFn {function(number, string) : string} A function - * that takes - * (1) the number of the term that is "hit", - * (2) the HTML string (search term) to be annotated, - * and returns the annotated term as an HTML string. - * @param {*=} opt_ignoreCase Whether to ignore the case of the query - * terms when looking for matches. - * @return {?string} The HTML equivalent of {@code text} with terms - * annotated, or null if the text did not contain any of the terms. - */ -goog.dom.annotate.annotateText = function(text, terms, annotateFn, - opt_ignoreCase) { - if (opt_ignoreCase) { - terms = goog.dom.annotate.lowercaseTerms_(terms); - } - return goog.dom.annotate.helpAnnotateText_(text, terms, annotateFn, - opt_ignoreCase); -}; - - -/** - * Annotates occurrences of query terms in plain text. This process consists of - * identifying all occurrences of all query terms, calling a provided function - * to get the appropriate replacement HTML for each occurrence, and - * HTML-escaping all the text. - * - * @param {string} text The plain text to be searched. - * @param {Array} terms An array of - * [{string} searchTerm, {boolean} matchWholeWordOnly] tuples. - * If {@code ignoreCase} is true, each search term must already be lowercase. - * The matchWholeWordOnly value is a per-term attribute because some terms - * may be CJK, while others are not. (For correctness, matchWholeWordOnly - * should always be false for CJK terms.). - * @param {Function} annotateFn {function(number, string) : string} A function - * that takes - * (1) the number of the term that is "hit", - * (2) the HTML string (search term) to be annotated, - * and returns the annotated term as an HTML string. - * @param {*} ignoreCase Whether to ignore the case of the query terms - * when looking for matches. - * @return {?string} The HTML equivalent of {@code text} with terms - * annotated, or null if the text did not contain any of the terms. - * @private - */ -goog.dom.annotate.helpAnnotateText_ = function(text, terms, annotateFn, - ignoreCase) { - var hit = false; - var resultHtml = null; - var textToSearch = ignoreCase ? text.toLowerCase() : text; - var textLen = textToSearch.length; - var numTerms = terms.length; - - // Each element will be an array of hit positions for the term. - var termHits = new Array(numTerms); - - // First collect all the hits into allHits. - for (var i = 0; i < numTerms; i++) { - var term = terms[i]; - var hits = []; - var termText = term[0]; - if (termText != '') { - var matchWholeWordOnly = term[1]; - var termLen = termText.length; - var pos = 0; - // Find each hit for term t and append to termHits. - while (pos < textLen) { - var hitPos = textToSearch.indexOf(termText, pos); - if (hitPos == -1) { - break; - } else { - var prevCharPos = hitPos - 1; - var nextCharPos = hitPos + termLen; - if (!matchWholeWordOnly || - ((prevCharPos < 0 || - goog.dom.annotate.NONWORD_RE_.test( - textToSearch.charAt(prevCharPos))) && - (nextCharPos >= textLen || - goog.dom.annotate.NONWORD_RE_.test( - textToSearch.charAt(nextCharPos))))) { - hits.push(hitPos); - hit = true; - } - pos = hitPos + termLen; - } - } - } - termHits[i] = hits; - } - - if (hit) { - var html = []; - var pos = 0; - - while (true) { - // First determine which of the n terms is the next hit. - var termIndexOfNextHit; - var posOfNextHit = -1; - - for (var i = 0; i < numTerms; i++) { - var hits = termHits[i]; - // pull off the position of the next hit of term t - // (it's always the first in the array because we're shifting - // hits off the front of the array as we process them) - // this is the next candidate to consider for the next overall hit - if (!goog.array.isEmpty(hits)) { - var hitPos = hits[0]; - - // Discard any hits embedded in the previous hit. - while (hitPos >= 0 && hitPos < pos) { - hits.shift(); - hitPos = goog.array.isEmpty(hits) ? -1 : hits[0]; - } - - if (hitPos >= 0 && (posOfNextHit < 0 || hitPos < posOfNextHit)) { - termIndexOfNextHit = i; - posOfNextHit = hitPos; - } - } - } - - // Quit if there are no more hits. - if (posOfNextHit < 0) break; - - // Remove the next hit from our hit list. - termHits[termIndexOfNextHit].shift(); - - // Append everything from the end of the last hit up to this one. - html.push(goog.string.htmlEscape(text.substr(pos, posOfNextHit - pos))); - - // Append the annotated term. - var termLen = terms[termIndexOfNextHit][0].length; - var termHtml = goog.string.htmlEscape(text.substr(posOfNextHit, termLen)); - html.push(annotateFn(termIndexOfNextHit, termHtml)); - - pos = posOfNextHit + termLen; - } - - // Append everything after the last hit. - html.push(goog.string.htmlEscape(text.substr(pos))); - return html.join(''); - } else { - return null; - } -}; - - -/** - * Converts terms to lowercase. - * - * @param {Array} terms An array of - * [{string} searchTerm, {boolean} matchWholeWordOnly] tuples. - * @return {Array} An array of - * [{string} searchTerm, {boolean} matchWholeWordOnly] tuples. - * @private - */ -goog.dom.annotate.lowercaseTerms_ = function(terms) { - var lowercaseTerms = []; - for (var i = 0; i < terms.length; ++i) { - var term = terms[i]; - lowercaseTerms[i] = [term[0].toLowerCase(), term[1]]; - } - return lowercaseTerms; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/annotate_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/annotate_test.html.svn-base deleted file mode 100644 index c666494..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/annotate_test.html.svn-base +++ /dev/null @@ -1,187 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2006 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.annotate</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.annotate'); - goog.require('goog.testing.jsunit'); -</script> -<style type="text/css"> - .c0 {background-color:#ff0} - .c1 {background-color:#0ff} -</style> -</head> -<body> -<span id="p">Tom & Jerry</span> -<table> - <tr id="q"> - <td>This <b>little</b> piggy</td> - <td class="s">That little <i>pig</i>gy</td> - </tr> - <tr id="r"> - <td>This <b>little</b> piggy</td> - <td class="s">That little <i>pig</i>gy</td> - </tr> -</table> - -<div id="o"> -<object classid="clsid:SAMPLE-UNRECOGNIZED-ID" width="100" height="50"> - <param name="BorderStyle" value="1" /> - <param name="MousePointer" value="0" /> - <param name="Enabled" value="1" /> - <param name="Min" value="0" /> - <param name="Max" value="10" /> - Your browser cannot display this object. -</object> -</div> - -<script id="script">var variable;</script> -<style id="style" type="text/css">.orange{color:orange}</style> -<span id="comment"><!-- note --></span> - -<script> - var $ = goog.dom.getElement; - - var TEXT = 'This little piggy cried "Wee! Wee! Wee!" all the way home.'; - - function doAnnotation(termIndex, termHtml) { - return '<span class="c' + termIndex + '">' + termHtml + '</span>'; - } - - // goog.dom.annotate.annotateText tests - - function testAnnotateText() { - var terms = [['pig', true]]; - var html = goog.dom.annotate.annotateText(TEXT, terms, doAnnotation); - assertEquals(null, html); - - terms = [['pig', false]]; - html = goog.dom.annotate.annotateText(TEXT, terms, doAnnotation); - assertEquals('This little <span class="c0">pig</span>gy cried ' + - '"Wee! Wee! Wee!" all the way home.', html); - - terms = [[' piggy ', true]]; - html = goog.dom.annotate.annotateText(TEXT, terms, doAnnotation); - assertEquals(null, html); - - terms = [[' piggy ', false]]; - html = goog.dom.annotate.annotateText(TEXT, terms, doAnnotation); - assertEquals('This little<span class="c0"> piggy </span>cried ' + - '"Wee! Wee! Wee!" all the way home.', html); - - terms = [['goose', true], ['piggy', true]]; - html = goog.dom.annotate.annotateText(TEXT, terms, doAnnotation); - assertEquals('This little <span class="c1">piggy</span> cried ' + - '"Wee! Wee! Wee!" all the way home.', html); - } - - function testAnnotateTextHtmlEscaping() { - var terms = [['a', false]]; - var html = goog.dom.annotate.annotateText('&a', terms, doAnnotation) - assertEquals('&<span class="c0">a</span>', html); - - terms = [['a', false]]; - html = goog.dom.annotate.annotateText('a&', terms, doAnnotation) - assertEquals('<span class="c0">a</span>&', html); - - terms = [['&', false]]; - html = goog.dom.annotate.annotateText('&', terms, doAnnotation) - assertEquals('<span class="c0">&</span>', html); - } - - function testAnnotateTextIgnoreCase() { - var terms = [['wEe', true]]; - var html = goog.dom.annotate.annotateText(TEXT, terms, doAnnotation, true); - assertEquals('This little piggy cried "<span class="c0">Wee</span>! ' + - '<span class="c0">Wee</span>! <span class="c0">Wee</span>!' + - '" all the way home.', html); - - terms = [['WEE!', true], ['HE', false]]; - html = goog.dom.annotate.annotateText(TEXT, terms, doAnnotation, true); - assertEquals('This little piggy cried "<span class="c0">Wee!</span> ' + - '<span class="c0">Wee!</span> <span class="c0">Wee!</span>' + - '" all t<span class="c1">he</span> way home.', html); - } - - function testAnnotateTextOverlappingTerms() { - var terms = [['tt', false], ['little', false]]; - var html = goog.dom.annotate.annotateText(TEXT, terms, doAnnotation); - assertEquals('This <span class="c1">little</span> piggy cried "Wee! ' + - 'Wee! Wee!" all the way home.', html); - } - - // goog.dom.annotate.annotateTerms tests - - function testAnnotateTerms() { - var terms = [['pig', true]]; - assertFalse(goog.dom.annotate.annotateTerms($('p'), terms, doAnnotation)); - assertEquals('Tom & Jerry', $('p').innerHTML); - - terms = [['Tom', true]]; - assertTrue(goog.dom.annotate.annotateTerms($('p'), terms, doAnnotation)); - var spans = goog.dom.getElementsByTagNameAndClass('SPAN', 'c0', $('p')); - assertEquals(1, spans.length); - assertEquals('Tom', spans[0].innerHTML); - assertEquals(' & Jerry', spans[0].nextSibling.nodeValue); - } - - function testAnnotateTermsInTable() { - var terms = [['pig', false]]; - assertTrue(goog.dom.annotate.annotateTerms($('q'), terms, doAnnotation)); - var spans = goog.dom.getElementsByTagNameAndClass('SPAN', 'c0', $('q')); - assertEquals(2, spans.length); - assertEquals('pig', spans[0].innerHTML); - assertEquals('gy', spans[0].nextSibling.nodeValue); - assertEquals('pig', spans[1].innerHTML); - assertEquals('I', spans[1].parentNode.tagName); - } - - function testAnnotateTermsWithClassExclusions() { - var terms = [['pig', false]]; - var classesToIgnore = ['s']; - assertTrue(goog.dom.annotate.annotateTerms($('r'), terms, doAnnotation, - false, classesToIgnore)); - var spans = goog.dom.getElementsByTagNameAndClass('SPAN', 'c0', $('r')); - assertEquals(1, spans.length); - assertEquals('pig', spans[0].innerHTML); - assertEquals('gy', spans[0].nextSibling.nodeValue); - } - - function testAnnotateTermsInObject() { - var terms = [['object', true]]; - assertTrue(goog.dom.annotate.annotateTerms($('o'), terms, doAnnotation)); - var spans = goog.dom.getElementsByTagNameAndClass('SPAN', 'c0', $('o')); - assertEquals(1, spans.length); - assertEquals('object', spans[0].innerHTML); - } - - function testAnnotateTermsInScript() { - var terms = [['variable', true]]; - assertFalse(goog.dom.annotate.annotateTerms($('script'), terms, - doAnnotation)); - } - - function testAnnotateTermsInStyle() { - var terms = [['color', true]]; - assertFalse(goog.dom.annotate.annotateTerms($('style'), terms, - doAnnotation)); - } - - function testAnnotateTermsInHtmlComment() { - var terms = [['note', true]]; - assertFalse(goog.dom.annotate.annotateTerms($('comment'), terms, - doAnnotation)); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/browserfeature.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/browserfeature.js.svn-base deleted file mode 100644 index ea921a1..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/browserfeature.js.svn-base +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2010 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Browser capability checks for the dom package. - * - */ - - -goog.provide('goog.dom.BrowserFeature'); - -goog.require('goog.userAgent'); - - -/** - * Enum of browser capabilities. - * @enum {boolean} - */ -goog.dom.BrowserFeature = { - /** - * Whether attributes 'name' and 'type' can be added to an element after it's - * created. False in Internet Explorer prior to version 9. - */ - CAN_ADD_NAME_OR_TYPE_ATTRIBUTES: !goog.userAgent.IE || - goog.userAgent.isDocumentMode(9), - - /** - * Whether we can use element.children to access an element's Element - * children. Available since Gecko 1.9.1, IE 9. (IE<9 also includes comment - * nodes in the collection.) - */ - CAN_USE_CHILDREN_ATTRIBUTE: !goog.userAgent.GECKO && !goog.userAgent.IE || - goog.userAgent.IE && goog.userAgent.isDocumentMode(9) || - goog.userAgent.GECKO && goog.userAgent.isVersion('1.9.1'), - - /** - * Opera, Safari 3, and Internet Explorer 9 all support innerText but they - * include text nodes in script and style tags. Not document-mode-dependent. - */ - CAN_USE_INNER_TEXT: goog.userAgent.IE && !goog.userAgent.isVersion('9'), - - /** - * MSIE, Opera, and Safari>=4 support element.parentElement to access an - * element's parent if it is an Element. - */ - CAN_USE_PARENT_ELEMENT_PROPERTY: goog.userAgent.IE || goog.userAgent.OPERA || - goog.userAgent.WEBKIT, - - /** - * Whether NoScope elements need a scoped element written before them in - * innerHTML. - * MSDN: http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx#1 - */ - INNER_HTML_NEEDS_SCOPED_ELEMENT: goog.userAgent.IE -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/classes.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/classes.js.svn-base deleted file mode 100644 index d1e7b14..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/classes.js.svn-base +++ /dev/null @@ -1,233 +0,0 @@ -// Copyright 2006 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for adding, removing and setting classes. - * - */ - - -goog.provide('goog.dom.classes'); - -goog.require('goog.array'); - - -/** - * Sets the entire class name of an element. - * @param {Node} element DOM node to set class of. - * @param {string} className Class name(s) to apply to element. - */ -goog.dom.classes.set = function(element, className) { - element.className = className; -}; - - -/** - * Gets an array of class names on an element - * @param {Node} element DOM node to get class of. - * @return {Array} Class names on {@code element}. - */ -goog.dom.classes.get = function(element) { - var className = element.className; - // Some types of elements don't have a className in IE (e.g. iframes). - // Furthermore, in Firefox, className is not a string when the element is - // an SVG element. - return className && typeof className.split == 'function' ? - className.split(/\s+/) : []; -}; - - -/** - * Adds a class or classes to an element. Does not add multiples of class names. - * @param {Node} element DOM node to add class to. - * @param {...string} var_args Class names to add. - * @return {boolean} Whether class was added (or all classes were added). - */ -goog.dom.classes.add = function(element, var_args) { - var classes = goog.dom.classes.get(element); - var args = goog.array.slice(arguments, 1); - - var b = goog.dom.classes.add_(classes, args); - element.className = classes.join(' '); - - return b; -}; - - -/** - * Removes a class or classes from an element. - * @param {Node} element DOM node to remove class from. - * @param {...string} var_args Class name(s) to remove. - * @return {boolean} Whether all classes in {@code var_args} were found and - * removed. - */ -goog.dom.classes.remove = function(element, var_args) { - var classes = goog.dom.classes.get(element); - var args = goog.array.slice(arguments, 1); - - var b = goog.dom.classes.remove_(classes, args); - element.className = classes.join(' '); - - return b; -}; - - -/** - * Helper method for {@link goog.dom.classes.add} and - * {@link goog.dom.classes.addRemove}. Adds one or more classes to the supplied - * classes array. - * @param {Array.<string>} classes All class names for the element, will be - * updated to have the classes supplied in {@code args} added. - * @param {Array.<string>} args Class names to add. - * @return {boolean} Whether all classes in were added. - * @private - */ -goog.dom.classes.add_ = function(classes, args) { - var rv = 0; - for (var i = 0; i < args.length; i++) { - if (!goog.array.contains(classes, args[i])) { - classes.push(args[i]); - rv++; - } - } - return rv == args.length; -}; - - -/** - * Helper method for {@link goog.dom.classes.remove} and - * {@link goog.dom.classes.addRemove}. Removes one or more classes from the - * supplied classes array. - * @param {Array.<string>} classes All class names for the element, will be - * updated to have the classes supplied in {@code args} removed. - * @param {Array.<string>} args Class names to remove. - * @return {boolean} Whether all classes in were found and removed. - * @private - */ -goog.dom.classes.remove_ = function(classes, args) { - var rv = 0; - for (var i = 0; i < classes.length; i++) { - if (goog.array.contains(args, classes[i])) { - goog.array.splice(classes, i--, 1); - rv++; - } - } - return rv == args.length; -}; - - -/** - * Switches a class on an element from one to another without disturbing other - * classes. If the fromClass isn't removed, the toClass won't be added. - * @param {Node} element DOM node to swap classes on. - * @param {string} fromClass Class to remove. - * @param {string} toClass Class to add. - * @return {boolean} Whether classes were switched. - */ -goog.dom.classes.swap = function(element, fromClass, toClass) { - var classes = goog.dom.classes.get(element); - - var removed = false; - for (var i = 0; i < classes.length; i++) { - if (classes[i] == fromClass) { - goog.array.splice(classes, i--, 1); - removed = true; - } - } - - if (removed) { - classes.push(toClass); - element.className = classes.join(' '); - } - - return removed; -}; - - -/** - * Adds zero or more classes to an element and removes zero or more as a single - * operation. Unlike calling {@link goog.dom.classes.add} and - * {@link goog.dom.classes.remove} separately, this is more efficient as it only - * parses the class property once. - * - * If a class is in both the remove and add lists, it will be added. Thus, - * you can use this instead of {@link goog.dom.classes.swap} when you have - * more than two class names that you want to swap. - * - * @param {Node} element DOM node to swap classes on. - * @param {string|Array.<string>|null} classesToRemove Class or classes to - * remove, if null no classes are removed. - * @param {string|Array.<string>|null} classesToAdd Class or classes to add, if - * null no classes are added. - */ -goog.dom.classes.addRemove = function(element, classesToRemove, classesToAdd) { - var classes = goog.dom.classes.get(element); - if (goog.isString(classesToRemove)) { - goog.array.remove(classes, classesToRemove); - } else if (goog.isArray(classesToRemove)) { - goog.dom.classes.remove_(classes, classesToRemove); - } - - if (goog.isString(classesToAdd) && - !goog.array.contains(classes, classesToAdd)) { - classes.push(classesToAdd); - } else if (goog.isArray(classesToAdd)) { - goog.dom.classes.add_(classes, classesToAdd); - } - - element.className = classes.join(' '); -}; - - -/** - * Returns true if an element has a class. - * @param {Node} element DOM node to test. - * @param {string} className Class name to test for. - * @return {boolean} Whether element has the class. - */ -goog.dom.classes.has = function(element, className) { - return goog.array.contains(goog.dom.classes.get(element), className); -}; - - -/** - * Adds or removes a class depending on the enabled argument. - * @param {Node} element DOM node to add or remove the class on. - * @param {string} className Class name to add or remove. - * @param {boolean} enabled Whether to add or remove the class (true adds, - * false removes). - */ -goog.dom.classes.enable = function(element, className, enabled) { - if (enabled) { - goog.dom.classes.add(element, className); - } else { - goog.dom.classes.remove(element, className); - } -}; - - -/** - * Removes a class if an element has it, and adds it the element doesn't have - * it. Won't affect other classes on the node. - * @param {Node} element DOM node to toggle class on. - * @param {string} className Class to toggle. - * @return {boolean} True if class was added, false if it was removed - * (in other words, whether element has the class after this function has - * been called). - */ -goog.dom.classes.toggle = function(element, className) { - var add = !goog.dom.classes.has(element, className); - goog.dom.classes.enable(element, className, add); - return add; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/classes_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/classes_test.html.svn-base deleted file mode 100644 index 9368795..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/classes_test.html.svn-base +++ /dev/null @@ -1,228 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2006 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.classes</title>= -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.classes'); - goog.require('goog.testing.jsunit'); -</script> -<style type="text/css"> -#styleTest1 { - width:120px;font-weight:bold; -} -</style> -</head> -<body> - <div id="testEl"> - <span>Test Element</span> - </div> - - <div><div><div id="testEl2"></div></div></div> - - <span id="span1" class="test1"></span> - <span id="span2" class="test1"></span> - <span id="span3" class="test2"></span> - <span id="span4" class="test3"></span> - <span id="span5" class="test1"></span> - <span id="span6"></span> - - <p id="p1"></p> - - <div id="styleTest1"></div> - <div id="styleTest2" style="width:100px;font-weight:bold"></div> - <div id="styleTest3"></div> - - <!-- Paragraph to test element child and sibling --> - <p id="p2"> - <!-- Comment --> - a - <b id="b1">c</b> - d - <!-- Comment --> - e - <b id="b2">f</b> - g - <!-- Comment --> - </p> - <p id="p3" class="someclass - otherclass"> - h - </p> - <iframe name="frame" src="../math/math_test.html"></iframe> - -<script> - - var $ = goog.dom.getElement; - var classes = goog.dom.classes; - - function testSetAddHasRemove() { - var el = $('p1'); - classes.set(el, 'someclass'); - assertTrue('Should have someclass', classes.has(el, 'someclass')); - - classes.set(el, 'otherclass'); - assertTrue('Should have otherclass', classes.has(el, 'otherclass')); - assertFalse('Should not have someclass', classes.has(el, 'someclass')); - - classes.add(el, 'wooclass'); - assertTrue('Should have otherclass', classes.has(el, 'otherclass')); - assertTrue('Should have wooclass', classes.has(el, 'wooclass')); - - classes.add(el, 'aclass', 'bclass', 'cclass'); - assertTrue('Should have otherclass', classes.has(el, 'otherclass')); - assertTrue('Should have wooclass', classes.has(el, 'wooclass')); - assertTrue('Should have aclass', classes.has(el, 'aclass')); - assertTrue('Should have bclass', classes.has(el, 'bclass')); - assertTrue('Should have cclass', classes.has(el, 'cclass')); - - classes.remove(el, 'cclass'); - assertTrue('Should have otherclass', classes.has(el, 'otherclass')); - assertTrue('Should have wooclass', classes.has(el, 'wooclass')); - assertTrue('Should have aclass', classes.has(el, 'aclass')); - assertTrue('Should have bclass', classes.has(el, 'bclass')); - assertFalse('Should not have cclass', classes.has(el, 'cclass')); - - classes.remove(el, 'aclass', 'bclass'); - assertTrue('Should have otherclass', classes.has(el, 'otherclass')); - assertTrue('Should have wooclass', classes.has(el, 'wooclass')); - assertFalse('Should not have aclass', classes.has(el, 'aclass')); - assertFalse('Should not have bclass', classes.has(el, 'bclass')); - } - - function testSwap() { - var el = $('p1'); - classes.set(el, 'someclass first'); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have first class', classes.has(el, 'someclass')); - assertFalse('Should not have second class', classes.has(el, 'second')); - - classes.swap(el, 'first', 'second'); - - assertFalse('Should not have first class', classes.has(el, 'first')); - assertTrue('Should have first class', classes.has(el, 'someclass')); - assertTrue('Should have second class', classes.has(el, 'second')); - - classes.swap(el, 'second', 'first'); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have first class', classes.has(el, 'someclass')); - assertFalse('Should not have second class', classes.has(el, 'second')); - } - - function testEnable() { - var el = $('p1'); - classes.set(el, 'someclass first'); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - - classes.enable(el, 'first', false); - - assertFalse('Should not have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - - classes.enable(el, 'first', true); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - } - - function testToggle() { - var el = $('p1'); - classes.set(el, 'someclass first'); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - - classes.toggle(el, 'first'); - - assertFalse('Should not have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - - classes.toggle(el, 'first'); - - assertTrue('Should have first class', classes.has(el, 'first')); - assertTrue('Should have someclass class', classes.has(el, 'someclass')); - } - - function testAddNotAddingMultiples() { - var el = $('span6'); - classes.add(el, 'a'); - assertEquals('a', el.className); - classes.add(el, 'a'); - assertEquals('a', el.className); - classes.add(el, 'b', 'b'); - assertEquals('a b', el.className); - } - - function testAddRemoveString() { - var el = $('span6'); - el.className = 'a'; - - goog.dom.classes.addRemove(el, 'a', 'b'); - assertEquals('b', el.className); - - goog.dom.classes.addRemove(el, null, 'c'); - assertEquals('b c', el.className); - - goog.dom.classes.addRemove(el, 'c', 'd'); - assertEquals('b d', el.className); - - goog.dom.classes.addRemove(el, 'd', null); - assertEquals('b', el.className); - } - - function testAddRemoveArray() { - var el = $('span6'); - el.className = 'a'; - - goog.dom.classes.addRemove(el, ['a'], ['b']); - assertEquals('b', el.className); - - goog.dom.classes.addRemove(el, [], ['c']); - assertEquals('b c', el.className); - - goog.dom.classes.addRemove(el, ['c'], ['d']); - assertEquals('b d', el.className); - - goog.dom.classes.addRemove(el, ['d'], []); - assertEquals('b', el.className); - } - - function testAddRemoveMultiple() { - var el = $('span6'); - el.className = 'a'; - - goog.dom.classes.addRemove(el, ['a'], ['b', 'c', 'd']); - assertEquals('b c d', el.className); - - goog.dom.classes.addRemove(el, [], ['e', 'f']); - assertEquals('b c d e f', el.className); - - goog.dom.classes.addRemove(el, ['c', 'e'], []); - assertEquals('b d f', el.className); - - goog.dom.classes.addRemove(el, ['b'], ['g']); - assertEquals('d f g', el.className); - } - - function testHasWithNewlines() { - var el = $('p3'); - assertTrue('Should have someclass', classes.has(el, 'someclass')); - assertTrue('Should also have otherclass', classes.has(el, 'otherclass')); - assertFalse('Should not have weirdclass', classes.has(el, 'weirdclass')); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/controlrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/controlrange.js.svn-base deleted file mode 100644 index 1bced30..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/controlrange.js.svn-base +++ /dev/null @@ -1,511 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for working with IE control ranges. - * - * @author robbyw@google.com (Robby Walker) - * @author jparent@google.com (Julie Parent) - */ - - -goog.provide('goog.dom.ControlRange'); -goog.provide('goog.dom.ControlRangeIterator'); - -goog.require('goog.array'); -goog.require('goog.dom'); -goog.require('goog.dom.AbstractMultiRange'); -goog.require('goog.dom.AbstractRange'); -goog.require('goog.dom.RangeIterator'); -goog.require('goog.dom.RangeType'); -goog.require('goog.dom.SavedRange'); -goog.require('goog.dom.TagWalkType'); -goog.require('goog.dom.TextRange'); -goog.require('goog.iter.StopIteration'); -goog.require('goog.userAgent'); - - - -/** - * Create a new control selection with no properties. Do not use this - * constructor: use one of the goog.dom.Range.createFrom* methods instead. - * @constructor - * @extends {goog.dom.AbstractMultiRange} - */ -goog.dom.ControlRange = function() { -}; -goog.inherits(goog.dom.ControlRange, goog.dom.AbstractMultiRange); - - -/** - * Create a new range wrapper from the given browser range object. Do not use - * this method directly - please use goog.dom.Range.createFrom* instead. - * @param {Object} controlRange The browser range object. - * @return {goog.dom.ControlRange} A range wrapper object. - */ -goog.dom.ControlRange.createFromBrowserRange = function(controlRange) { - var range = new goog.dom.ControlRange(); - range.range_ = controlRange; - return range; -}; - - -/** - * Create a new range wrapper that selects the given element. Do not use - * this method directly - please use goog.dom.Range.createFrom* instead. - * @param {...Element} var_args The element(s) to select. - * @return {goog.dom.ControlRange} A range wrapper object. - */ -goog.dom.ControlRange.createFromElements = function(var_args) { - var range = goog.dom.getOwnerDocument(arguments[0]).body.createControlRange(); - for (var i = 0, len = arguments.length; i < len; i++) { - range.addElement(arguments[i]); - } - return goog.dom.ControlRange.createFromBrowserRange(range); -}; - - -/** - * The IE control range obejct. - * @type {Object} - * @private - */ -goog.dom.ControlRange.prototype.range_ = null; - - -/** - * Cached list of elements. - * @type {Array.<Element>?} - * @private - */ -goog.dom.ControlRange.prototype.elements_ = null; - - -/** - * Cached sorted list of elements. - * @type {Array.<Element>?} - * @private - */ -goog.dom.ControlRange.prototype.sortedElements_ = null; - - -// Method implementations - - -/** - * Clear cached values. - * @private - */ -goog.dom.ControlRange.prototype.clearCachedValues_ = function() { - this.elements_ = null; - this.sortedElements_ = null; -}; - - -/** - * @return {goog.dom.ControlRange} A clone of this range. - */ -goog.dom.ControlRange.prototype.clone = function() { - return goog.dom.ControlRange.createFromElements.apply(this, - this.getElements()); -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getType = function() { - return goog.dom.RangeType.CONTROL; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getBrowserRangeObject = function() { - return this.range_ || document.body.createControlRange(); -}; - - -/** @override */ -goog.dom.ControlRange.prototype.setBrowserRangeObject = function(nativeRange) { - if (!goog.dom.AbstractRange.isNativeControlRange(nativeRange)) { - return false; - } - this.range_ = nativeRange; - return true; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getTextRangeCount = function() { - return this.range_ ? this.range_.length : 0; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getTextRange = function(i) { - return goog.dom.TextRange.createFromNodeContents(this.range_.item(i)); -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getContainer = function() { - return goog.dom.findCommonAncestor.apply(null, this.getElements()); -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getStartNode = function() { - return this.getSortedElements()[0]; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getStartOffset = function() { - return 0; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getEndNode = function() { - var sorted = this.getSortedElements(); - var startsLast = /** @type {Node} */ (goog.array.peek(sorted)); - return /** @type {Node} */ (goog.array.find(sorted, function(el) { - return goog.dom.contains(el, startsLast); - })); -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getEndOffset = function() { - return this.getEndNode().childNodes.length; -}; - - -// TODO(robbyw): Figure out how to unify getElements with TextRange API. -/** - * @return {Array.<Element>} Array of elements in the control range. - */ -goog.dom.ControlRange.prototype.getElements = function() { - if (!this.elements_) { - this.elements_ = []; - if (this.range_) { - for (var i = 0; i < this.range_.length; i++) { - this.elements_.push(this.range_.item(i)); - } - } - } - - return this.elements_; -}; - - -/** - * @return {Array.<Element>} Array of elements comprising the control range, - * sorted by document order. - */ -goog.dom.ControlRange.prototype.getSortedElements = function() { - if (!this.sortedElements_) { - this.sortedElements_ = this.getElements().concat(); - this.sortedElements_.sort(function(a, b) { - return a.sourceIndex - b.sourceIndex; - }); - } - - return this.sortedElements_; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.isRangeInDocument = function() { - var returnValue = false; - - try { - returnValue = goog.array.every(this.getElements(), function(element) { - // On IE, this throws an exception when the range is detached. - return goog.userAgent.IE ? - element.parentNode : - goog.dom.contains(element.ownerDocument.body, element); - }); - } catch (e) { - // IE sometimes throws Invalid Argument errors for detached elements. - // Note: trying to return a value from the above try block can cause IE - // to crash. It is necessary to use the local returnValue. - } - - return returnValue; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.isCollapsed = function() { - return !this.range_ || !this.range_.length; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getText = function() { - // TODO(robbyw): What about for table selections? Should those have text? - return ''; -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getHtmlFragment = function() { - return goog.array.map(this.getSortedElements(), goog.dom.getOuterHtml). - join(''); -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getValidHtml = function() { - return this.getHtmlFragment(); -}; - - -/** @override */ -goog.dom.ControlRange.prototype.getPastableHtml = - goog.dom.ControlRange.prototype.getValidHtml; - - -/** @override */ -goog.dom.ControlRange.prototype.__iterator__ = function(opt_keys) { - return new goog.dom.ControlRangeIterator(this); -}; - - -// RANGE ACTIONS - - -/** @override */ -goog.dom.ControlRange.prototype.select = function() { - if (this.range_) { - this.range_.select(); - } -}; - - -/** @override */ -goog.dom.ControlRange.prototype.removeContents = function() { - // TODO(robbyw): Test implementing with execCommand('Delete') - if (this.range_) { - var nodes = []; - for (var i = 0, len = this.range_.length; i < len; i++) { - nodes.push(this.range_.item(i)); - } - goog.array.forEach(nodes, goog.dom.removeNode); - - this.collapse(false); - } -}; - - -/** @override */ -goog.dom.ControlRange.prototype.replaceContentsWithNode = function(node) { - // Control selections have to have the node inserted before removing the - // selection contents because a collapsed control range doesn't have start or - // end nodes. - var result = this.insertNode(node, true); - - if (!this.isCollapsed()) { - this.removeContents(); - } - - return result; -}; - - -// SAVE/RESTORE - - -/** @override */ -goog.dom.ControlRange.prototype.saveUsingDom = function() { - return new goog.dom.DomSavedControlRange_(this); -}; - - -// RANGE MODIFICATION - - -/** @override */ -goog.dom.ControlRange.prototype.collapse = function(toAnchor) { - // TODO(robbyw): Should this return a text range? If so, API needs to change. - this.range_ = null; - this.clearCachedValues_(); -}; - - -// SAVED RANGE OBJECTS - - - -/** - * A SavedRange implementation using DOM endpoints. - * @param {goog.dom.ControlRange} range The range to save. - * @constructor - * @extends {goog.dom.SavedRange} - * @private - */ -goog.dom.DomSavedControlRange_ = function(range) { - /** - * The element list. - * @type {Array.<Element>} - * @private - */ - this.elements_ = range.getElements(); -}; -goog.inherits(goog.dom.DomSavedControlRange_, goog.dom.SavedRange); - - -/** - * @return {goog.dom.ControlRange} The restored range. - */ -goog.dom.DomSavedControlRange_.prototype.restoreInternal = function() { - var doc = this.elements_.length ? - goog.dom.getOwnerDocument(this.elements_[0]) : document; - var controlRange = doc.body.createControlRange(); - for (var i = 0, len = this.elements_.length; i < len; i++) { - controlRange.addElement(this.elements_[i]); - } - return goog.dom.ControlRange.createFromBrowserRange(controlRange); -}; - - -/** @override */ -goog.dom.DomSavedControlRange_.prototype.disposeInternal = function() { - goog.dom.DomSavedControlRange_.superClass_.disposeInternal.call(this); - delete this.elements_; -}; - - -// RANGE ITERATION - - - -/** - * Subclass of goog.dom.TagIterator that iterates over a DOM range. It - * adds functions to determine the portion of each text node that is selected. - * - * @param {goog.dom.ControlRange?} range The range to traverse. - * @constructor - * @extends {goog.dom.RangeIterator} - */ -goog.dom.ControlRangeIterator = function(range) { - if (range) { - this.elements_ = range.getSortedElements(); - this.startNode_ = this.elements_.shift(); - this.endNode_ = /** @type {Node} */ (goog.array.peek(this.elements_)) || - this.startNode_; - } - - goog.dom.RangeIterator.call(this, this.startNode_, false); -}; -goog.inherits(goog.dom.ControlRangeIterator, goog.dom.RangeIterator); - - -/** - * The first node in the selection. - * @type {Node} - * @private - */ -goog.dom.ControlRangeIterator.prototype.startNode_ = null; - - -/** - * The last node in the selection. - * @type {Node} - * @private - */ -goog.dom.ControlRangeIterator.prototype.endNode_ = null; - - -/** - * The list of elements left to traverse. - * @type {Array.<Element>?} - * @private - */ -goog.dom.ControlRangeIterator.prototype.elements_ = null; - - -/** @override */ -goog.dom.ControlRangeIterator.prototype.getStartTextOffset = function() { - return 0; -}; - - -/** @override */ -goog.dom.ControlRangeIterator.prototype.getEndTextOffset = function() { - return 0; -}; - - -/** @override */ -goog.dom.ControlRangeIterator.prototype.getStartNode = function() { - return this.startNode_; -}; - - -/** @override */ -goog.dom.ControlRangeIterator.prototype.getEndNode = function() { - return this.endNode_; -}; - - -/** @override */ -goog.dom.ControlRangeIterator.prototype.isLast = function() { - return !this.depth && !this.elements_.length; -}; - - -/** - * Move to the next position in the selection. - * Throws {@code goog.iter.StopIteration} when it passes the end of the range. - * @return {Node} The node at the next position. - */ -goog.dom.ControlRangeIterator.prototype.next = function() { - // Iterate over each element in the range, and all of its children. - if (this.isLast()) { - throw goog.iter.StopIteration; - } else if (!this.depth) { - var el = this.elements_.shift(); - this.setPosition(el, - goog.dom.TagWalkType.START_TAG, - goog.dom.TagWalkType.START_TAG); - return el; - } - - // Call the super function. - return goog.dom.ControlRangeIterator.superClass_.next.call(this); -}; - - -/** - * Replace this iterator's values with values from another. - * @param {goog.dom.ControlRangeIterator} other The iterator to copy. - * @protected - */ -goog.dom.ControlRangeIterator.prototype.copyFrom = function(other) { - this.elements_ = other.elements_; - this.startNode_ = other.startNode_; - this.endNode_ = other.endNode_; - - goog.dom.ControlRangeIterator.superClass_.copyFrom.call(this, other); -}; - - -/** - * @return {goog.dom.ControlRangeIterator} An identical iterator. - */ -goog.dom.ControlRangeIterator.prototype.clone = function() { - var copy = new goog.dom.ControlRangeIterator(null); - copy.copyFrom(this); - return copy; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/controlrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/controlrange_test.html.svn-base deleted file mode 100644 index 99ecd11..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/controlrange_test.html.svn-base +++ /dev/null @@ -1,246 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.ControlRange</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.ControlRange'); - goog.require('goog.dom.TextRange'); - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -</head> -<body> - <div id="test1"></div> - <div id="test2"> - <img id="logo" src="http://www.google.com/intl/en_ALL/images/logo.gif"> - </div> - <!-- Omit whitespace here to ensure no extra text nodes are included. --> - <table id="table"><tbody id="tbody"><tr id="tr1"><td id="td11">a</td - ><td id="td12">b</td></tr><tr id="tr2"><td id="td21">c</td><td id="td22" - >d</td></tr></tbody></table> - <table id="table2"> - <tr> - <td>moof</td> - </tr> - <tr> - <td id="table2td"> - foo - <img id="logo2" src="http://www.google.com/intl/en_ALL/images/logo.gif"> - bar - </td> - </tr> - </table> - - -<script> - var logo = goog.dom.getElement('logo'); - var table = goog.dom.getElement('table'); - - function testCreateFromElement() { - if (!goog.userAgent.IE) { - return; - } - assertNotNull('Control range object can be created for element', - goog.dom.ControlRange.createFromElements(logo)); - } - - function testCreateFromRange() { - if (!goog.userAgent.IE) { - return; - } - var range = document.body.createControlRange(); - range.addElement(table); - assertNotNull('Control range object can be created for element', - goog.dom.ControlRange.createFromBrowserRange(range)); - } - - function testSelect() { - if (!goog.userAgent.IE) { - return; - } - - var range = goog.dom.ControlRange.createFromElements(table); - range.select(); - - assertEquals('Control range should be selected', 'Control', - document.selection.type); - assertEquals('Control range should have length 1', 1, - document.selection.createRange().length); - assertEquals('Control range should select table', table, - document.selection.createRange().item(0)); - } - - function testControlRangeIterator() { - if (!goog.userAgent.IE) { - return; - } - var range = goog.dom.ControlRange.createFromElements(logo, table); - // Each node is included twice - once as a start tag, once as an end. - goog.testing.dom.assertNodesMatch(range, ['#logo', '#logo', '#table', - '#tbody', '#tr1', '#td11', 'a', '#td11', '#td12', 'b', '#td12', '#tr1', - '#tr2', '#td21', 'c', '#td21', '#td22', 'd', '#td22', '#tr2', '#tbody', - '#table']); - } - - function testBounds() { - if (!goog.userAgent.IE) { - return; - } - - // Initialize in both orders. - helpTestBounds(goog.dom.ControlRange.createFromElements(logo, table)); - helpTestBounds(goog.dom.ControlRange.createFromElements(table, logo)); - } - - function helpTestBounds(range) { - assertEquals('Start node is logo', logo, range.getStartNode()); - assertEquals('Start offset is 0', 0, range.getStartOffset()); - assertEquals('End node is table', table, range.getEndNode()); - assertEquals('End offset is 1', 1, range.getEndOffset()); - } - - function testCollapse() { - if (!goog.userAgent.IE) { - return; - } - - var range = goog.dom.ControlRange.createFromElements(logo, table); - assertFalse('Not initially collapsed', range.isCollapsed()); - range.collapse(); - assertTrue('Successfully collapsed', range.isCollapsed()); - } - - function testGetContainer() { - if (!goog.userAgent.IE) { - return; - } - - var range = goog.dom.ControlRange.createFromElements(logo); - assertEquals('Single element range is contained by itself', logo, - range.getContainer()); - - range = goog.dom.ControlRange.createFromElements(logo, table); - assertEquals('Two element range is contained by body', document.body, - range.getContainer()); - } - - function testSave() { - if (!goog.userAgent.IE) { - return; - } - - var range = goog.dom.ControlRange.createFromElements(logo, table); - var savedRange = range.saveUsingDom(); - - range.collapse(); - assertTrue('Successfully collapsed', range.isCollapsed()); - - range = savedRange.restore(); - assertEquals('Restored a control range', goog.dom.RangeType.CONTROL, - range.getType()); - assertFalse('Not collapsed after restore', range.isCollapsed()); - helpTestBounds(range); - } - - function testRemoveContents() { - if (!goog.userAgent.IE) { - return; - } - - var img = goog.dom.createDom('IMG'); - img.src = logo.src; - - var div = goog.dom.getElement('test1'); - div.innerHTML = ''; - div.appendChild(img); - assertEquals('Div has 1 child', 1, div.childNodes.length); - - var range = goog.dom.ControlRange.createFromElements(img); - range.removeContents(); - assertEquals('Div has 0 children', 0, div.childNodes.length); - assertTrue('Range is collapsed', range.isCollapsed()); - } - - function testReplaceContents() { - // Test a control range. - if (!goog.userAgent.IE) { - return; - } - - var outer = goog.dom.getElement('test1'); - outer.innerHTML = - '<div contentEditable="true">' + - 'Hello <input type="text" value="World">' + - '</div>'; - range = goog.dom.ControlRange.createFromElements( - outer.getElementsByTagName(goog.dom.TagName.INPUT)[0]); - goog.dom.ControlRange.createFromElements(table) - range.replaceContentsWithNode(goog.dom.createTextNode('World')); - assertEquals('Hello World', outer.firstChild.innerHTML); - } - - function testContainsRange() { - if (!goog.userAgent.IE) { - return; - } - - var table2 = goog.dom.getElement('table2'); - var table2td = goog.dom.getElement('table2td'); - var logo2 = goog.dom.getElement('logo2'); - - var range = goog.dom.ControlRange.createFromElements(logo, table); - var range2 = goog.dom.ControlRange.createFromElements(logo); - assertTrue('Control range contains the other control range', - range.containsRange(range2)); - assertTrue('Control range partially contains the other control range', - range2.containsRange(range, true)); - - range2 = goog.dom.ControlRange.createFromElements(table2); - assertFalse('Control range does not contain the other control range', - range.containsRange(range2)); - - range = goog.dom.ControlRange.createFromElements(table2); - range2 = goog.dom.TextRange.createFromNodeContents(table2td); - assertTrue('Control range contains text range', - range.containsRange(range2)); - - range2 = goog.dom.TextRange.createFromNodeContents(table); - assertFalse('Control range does not contain text range', - range.containsRange(range2)); - - range = goog.dom.ControlRange.createFromElements(logo2); - range2 = goog.dom.TextRange.createFromNodeContents(table2); - assertFalse('Control range does not fully contain text range', - range.containsRange(range2, false)); - - range2 = goog.dom.ControlRange.createFromElements(table2); - assertTrue('Control range contains the other control range (2)', - range2.containsRange(range)); - } - - function testCloneRange() { - if (!goog.userAgent.IE) { - return; - } - var range = goog.dom.ControlRange.createFromElements(logo); - assertNotNull('Control range object created for element', range); - - var cloneRange = range.clone(); - assertNotNull('Cloned control range object', cloneRange); - assertArrayEquals('Control range and clone have same elements', - range.getElements(), cloneRange.getElements()); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dataset.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dataset.js.svn-base deleted file mode 100644 index 5f9b821..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dataset.js.svn-base +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2009 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for adding, removing and setting values in - * an Element's dataset. - * See {@link http://www.w3.org/TR/html5/Overview.html#dom-dataset}. - * - */ - -goog.provide('goog.dom.dataset'); - -goog.require('goog.string'); - - -/** - * Sets a custom data attribute on an element. The key should be - * in camelCase format (e.g "keyName" for the "data-key-name" attribute). - * @param {Element} element DOM node to set the custom data attribute on. - * @param {string} key Key for the custom data attribute. - * @param {string} value Value for the custom data attribute. - */ -goog.dom.dataset.set = function(element, key, value) { - if (element.dataset) { - element.dataset[key] = value; - } else { - element.setAttribute('data-' + goog.string.toSelectorCase(key), value); - } -}; - - -/** - * Gets a custom data attribute from an element. The key should be - * in camelCase format (e.g "keyName" for the "data-key-name" attribute). - * @param {Element} element DOM node to get the custom data attribute from. - * @param {string} key Key for the custom data attribute. - * @return {?string} The attribute value, if it exists. - */ -goog.dom.dataset.get = function(element, key) { - if (element.dataset) { - return element.dataset[key]; - } else { - return element.getAttribute('data-' + goog.string.toSelectorCase(key)); - } -}; - - -/** - * Removes a custom data attribute from an element. The key should be - * in camelCase format (e.g "keyName" for the "data-key-name" attribute). - * @param {Element} element DOM node to get the custom data attribute from. - * @param {string} key Key for the custom data attribute. - */ -goog.dom.dataset.remove = function(element, key) { - if (element.dataset) { - delete element.dataset[key]; - } else { - element.removeAttribute('data-' + goog.string.toSelectorCase(key)); - } -}; - - -/** - * Checks whether custom data attribute exists on an element. The key should be - * in camelCase format (e.g "keyName" for the "data-key-name" attribute). - * - * @param {Element} element DOM node to get the custom data attribute from. - * @param {string} key Key for the custom data attribute. - * @return {boolean} Whether the attibute exists. - */ -goog.dom.dataset.has = function(element, key) { - if (element.dataset) { - return key in element.dataset; - } else if (element.hasAttribute) { - return element.hasAttribute('data-' + goog.string.toSelectorCase(key)); - } else { - return !!(element.getAttribute('data-' + goog.string.toSelectorCase(key))); - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dataset_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dataset_test.html.svn-base deleted file mode 100644 index 0030aa6..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dataset_test.html.svn-base +++ /dev/null @@ -1,104 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2011 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.dataset</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.dataset'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - <span id="el1" data-basic-key="basic" - data--unusual-key1="unusual1" - data-unusual--key2="unusual2" - data---bizarre---key="bizarre"></span> - <span id="el2"></span> -<script> - - -var $ = goog.dom.getElement; -var dataset = goog.dom.dataset; - - -function setUp() { - var el = $('el2'); - el.setAttribute('data-dynamic-key', 'dynamic'); -} - - -function testHas() { - var el = $('el1'); - - assertTrue('Dataset should have an existing key', - dataset.has(el, 'basicKey')); - assertTrue('Dataset should have an existing (unusual) key', - dataset.has(el, 'UnusualKey1')); - assertTrue('Dataset should have an existing (unusual) key', - dataset.has(el, 'unusual-Key2')); - assertTrue('Dataset should have an existing (bizarre) key', - dataset.has(el, '-Bizarre--Key')); - assertFalse('Dataset should not have a non-existent key', - dataset.has(el, 'bogusKey')); -} - - -function testGet() { - var el = $('el1'); - - assertEquals('Dataset should return the proper value for an existing key', - dataset.get(el, 'basicKey'), 'basic'); - assertEquals('Dataset should have an existing (unusual) key', - dataset.get(el, 'UnusualKey1'), 'unusual1'); - assertEquals('Dataset should have an existing (unusual) key', - dataset.get(el, 'unusual-Key2'), 'unusual2'); - assertEquals('Dataset should have an existing (bizarre) key', - dataset.get(el, '-Bizarre--Key'), 'bizarre'); - assertFalse('Dataset should return null or an empty string for a non-existent key', - !!dataset.get(el, 'bogusKey')); - - el = $('el2'); - assertEquals('Dataset should return the proper value for an existing key', - dataset.get(el, 'dynamicKey'), 'dynamic'); -} - - -function testSet() { - var el = $('el2'); - - dataset.set(el, 'newKey', 'newValue'); - assertTrue('Dataset should have a newly created key', - dataset.has(el, 'newKey')); - assertEquals('Dataset should return the proper value for a newly created key', - dataset.get(el, 'newKey'), 'newValue'); - - dataset.set(el, 'dynamicKey', 'customValue'); - assertTrue('Dataset should have a modified, existing key', - dataset.has(el, 'dynamicKey')); - assertEquals('Dataset should return the proper value for a modified key', - dataset.get(el, 'dynamicKey'), 'customValue'); -} - - -function testRemove() { - var el = $('el2'); - - dataset.remove(el, 'dynamicKey'); - assertFalse('Dataset should not have a removed key', - dataset.has(el, 'dynamicKey')); - assertFalse('Dataset should return null or an empty string for removed key', - !!dataset.get(el, 'dynamicKey')); -} - - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom.js.svn-base deleted file mode 100644 index dc78f3f..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom.js.svn-base +++ /dev/null @@ -1,2534 +0,0 @@ -// Copyright 2006 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for manipulating the browser's Document Object Model - * Inspiration taken *heavily* from mochikit (http://mochikit.com/). - * - * You can use {@link goog.dom.DomHelper} to create new dom helpers that refer - * to a different document object. This is useful if you are working with - * frames or multiple windows. - * - */ - - -// TODO(arv): Rename/refactor getTextContent and getRawTextContent. The problem -// is that getTextContent should mimic the DOM3 textContent. We should add a -// getInnerText (or getText) which tries to return the visible text, innerText. - - -goog.provide('goog.dom'); -goog.provide('goog.dom.DomHelper'); -goog.provide('goog.dom.NodeType'); - -goog.require('goog.array'); -goog.require('goog.dom.BrowserFeature'); -goog.require('goog.dom.TagName'); -goog.require('goog.dom.classes'); -goog.require('goog.math.Coordinate'); -goog.require('goog.math.Size'); -goog.require('goog.object'); -goog.require('goog.string'); -goog.require('goog.userAgent'); - - -/** - * @define {boolean} Whether we know at compile time that the browser is in - * quirks mode. - */ -goog.dom.ASSUME_QUIRKS_MODE = false; - - -/** - * @define {boolean} Whether we know at compile time that the browser is in - * standards compliance mode. - */ -goog.dom.ASSUME_STANDARDS_MODE = false; - - -/** - * Whether we know the compatibility mode at compile time. - * @type {boolean} - * @private - */ -goog.dom.COMPAT_MODE_KNOWN_ = - goog.dom.ASSUME_QUIRKS_MODE || goog.dom.ASSUME_STANDARDS_MODE; - - -/** - * Enumeration for DOM node types (for reference) - * @enum {number} - */ -goog.dom.NodeType = { - ELEMENT: 1, - ATTRIBUTE: 2, - TEXT: 3, - CDATA_SECTION: 4, - ENTITY_REFERENCE: 5, - ENTITY: 6, - PROCESSING_INSTRUCTION: 7, - COMMENT: 8, - DOCUMENT: 9, - DOCUMENT_TYPE: 10, - DOCUMENT_FRAGMENT: 11, - NOTATION: 12 -}; - - -/** - * Gets the DomHelper object for the document where the element resides. - * @param {Node|Window=} opt_element If present, gets the DomHelper for this - * element. - * @return {!goog.dom.DomHelper} The DomHelper. - */ -goog.dom.getDomHelper = function(opt_element) { - return opt_element ? - new goog.dom.DomHelper(goog.dom.getOwnerDocument(opt_element)) : - (goog.dom.defaultDomHelper_ || - (goog.dom.defaultDomHelper_ = new goog.dom.DomHelper())); -}; - - -/** - * Cached default DOM helper. - * @type {goog.dom.DomHelper} - * @private - */ -goog.dom.defaultDomHelper_; - - -/** - * Gets the document object being used by the dom library. - * @return {!Document} Document object. - */ -goog.dom.getDocument = function() { - return document; -}; - - -/** - * Alias for getElementById. If a DOM node is passed in then we just return - * that. - * @param {string|Element} element Element ID or a DOM node. - * @return {Element} The element with the given ID, or the node passed in. - */ -goog.dom.getElement = function(element) { - return goog.isString(element) ? - document.getElementById(element) : element; -}; - - -/** - * Alias for getElement. - * @param {string|Element} element Element ID or a DOM node. - * @return {Element} The element with the given ID, or the node passed in. - * @deprecated Use {@link goog.dom.getElement} instead. - */ -goog.dom.$ = goog.dom.getElement; - - -/** - * Looks up elements by both tag and class name, using browser native functions - * ({@code querySelectorAll}, {@code getElementsByTagName} or - * {@code getElementsByClassName}) where possible. This function - * is a useful, if limited, way of collecting a list of DOM elements - * with certain characteristics. {@code goog.dom.query} offers a - * more powerful and general solution which allows matching on CSS3 - * selector expressions, but at increased cost in code size. If all you - * need is particular tags belonging to a single class, this function - * is fast and sleek. - * - * @see {goog.dom.query} - * - * @param {?string=} opt_tag Element tag name. - * @param {?string=} opt_class Optional class name. - * @param {Document|Element=} opt_el Optional element to look in. - * @return { {length: number} } Array-like list of elements (only a length - * property and numerical indices are guaranteed to exist). - */ -goog.dom.getElementsByTagNameAndClass = function(opt_tag, opt_class, opt_el) { - return goog.dom.getElementsByTagNameAndClass_(document, opt_tag, opt_class, - opt_el); -}; - - -/** - * Returns an array of all the elements with the provided className. - * @see {goog.dom.query} - * @param {string} className the name of the class to look for. - * @param {Document|Element=} opt_el Optional element to look in. - * @return { {length: number} } The items found with the class name provided. - */ -goog.dom.getElementsByClass = function(className, opt_el) { - var parent = opt_el || document; - if (goog.dom.canUseQuerySelector_(parent)) { - return parent.querySelectorAll('.' + className); - } else if (parent.getElementsByClassName) { - return parent.getElementsByClassName(className); - } - return goog.dom.getElementsByTagNameAndClass_( - document, '*', className, opt_el); -}; - - -/** - * Returns the first element with the provided className. - * @see {goog.dom.query} - * @param {string} className the name of the class to look for. - * @param {Element|Document=} opt_el Optional element to look in. - * @return {Element} The first item with the class name provided. - */ -goog.dom.getElementByClass = function(className, opt_el) { - var parent = opt_el || document; - var retVal = null; - if (goog.dom.canUseQuerySelector_(parent)) { - retVal = parent.querySelector('.' + className); - } else { - retVal = goog.dom.getElementsByClass(className, opt_el)[0]; - } - return retVal || null; -}; - - -/** - * Prefer the standardized (http://www.w3.org/TR/selectors-api/), native and - * fast W3C Selectors API. However, the version of WebKit that shipped with - * Safari 3.1 and Chrome has a bug where it will not correctly match mixed- - * case class name selectors in quirks mode. - * @param {!Element|Document} parent The parent document object. - * @return {boolean} whether or not we can use parent.querySelector* APIs. - * @private - */ -goog.dom.canUseQuerySelector_ = function(parent) { - return parent.querySelectorAll && - parent.querySelector && - (!goog.userAgent.WEBKIT || goog.dom.isCss1CompatMode_(document) || - goog.userAgent.isVersion('528')); -}; - - -/** - * Helper for {@code getElementsByTagNameAndClass}. - * @param {!Document} doc The document to get the elements in. - * @param {?string=} opt_tag Element tag name. - * @param {?string=} opt_class Optional class name. - * @param {Document|Element=} opt_el Optional element to look in. - * @return { {length: number} } Array-like list of elements (only a length - * property and numerical indices are guaranteed to exist). - * @private - */ -goog.dom.getElementsByTagNameAndClass_ = function(doc, opt_tag, opt_class, - opt_el) { - var parent = opt_el || doc; - var tagName = (opt_tag && opt_tag != '*') ? opt_tag.toUpperCase() : ''; - - if (goog.dom.canUseQuerySelector_(parent) && - (tagName || opt_class)) { - var query = tagName + (opt_class ? '.' + opt_class : ''); - return parent.querySelectorAll(query); - } - - // Use the native getElementsByClassName if available, under the assumption - // that even when the tag name is specified, there will be fewer elements to - // filter through when going by class than by tag name - if (opt_class && parent.getElementsByClassName) { - var els = parent.getElementsByClassName(opt_class); - - if (tagName) { - var arrayLike = {}; - var len = 0; - - // Filter for specific tags if requested. - for (var i = 0, el; el = els[i]; i++) { - if (tagName == el.nodeName) { - arrayLike[len++] = el; - } - } - arrayLike.length = len; - - return arrayLike; - } else { - return els; - } - } - - var els = parent.getElementsByTagName(tagName || '*'); - - if (opt_class) { - var arrayLike = {}; - var len = 0; - for (var i = 0, el; el = els[i]; i++) { - var className = el.className; - // Check if className has a split function since SVG className does not. - if (typeof className.split == 'function' && - goog.array.contains(className.split(/\s+/), opt_class)) { - arrayLike[len++] = el; - } - } - arrayLike.length = len; - return arrayLike; - } else { - return els; - } -}; - - -/** - * Alias for {@code getElementsByTagNameAndClass}. - * @param {?string=} opt_tag Element tag name. - * @param {?string=} opt_class Optional class name. - * @param {Element=} opt_el Optional element to look in. - * @return { {length: number} } Array-like list of elements (only a length - * property and numerical indices are guaranteed to exist). - * @deprecated Use {@link goog.dom.getElementsByTagNameAndClass} instead. - */ -goog.dom.$$ = goog.dom.getElementsByTagNameAndClass; - - -/** - * Sets multiple properties on a node. - * @param {Element} element DOM node to set properties on. - * @param {Object} properties Hash of property:value pairs. - */ -goog.dom.setProperties = function(element, properties) { - goog.object.forEach(properties, function(val, key) { - if (key == 'style') { - element.style.cssText = val; - } else if (key == 'class') { - element.className = val; - } else if (key == 'for') { - element.htmlFor = val; - } else if (key in goog.dom.DIRECT_ATTRIBUTE_MAP_) { - element.setAttribute(goog.dom.DIRECT_ATTRIBUTE_MAP_[key], val); - } else if (goog.string.startsWith(key, 'aria-')) { - element.setAttribute(key, val); - } else { - element[key] = val; - } - }); -}; - - -/** - * Map of attributes that should be set using - * element.setAttribute(key, val) instead of element[key] = val. Used - * by goog.dom.setProperties. - * - * @type {Object} - * @private - */ -goog.dom.DIRECT_ATTRIBUTE_MAP_ = { - 'cellpadding': 'cellPadding', - 'cellspacing': 'cellSpacing', - 'colspan': 'colSpan', - 'rowspan': 'rowSpan', - 'valign': 'vAlign', - 'height': 'height', - 'width': 'width', - 'usemap': 'useMap', - 'frameborder': 'frameBorder', - 'maxlength': 'maxLength', - 'type': 'type' -}; - - -/** - * Gets the dimensions of the viewport. - * - * Gecko Standards mode: - * docEl.clientWidth Width of viewport excluding scrollbar. - * win.innerWidth Width of viewport including scrollbar. - * body.clientWidth Width of body element. - * - * docEl.clientHeight Height of viewport excluding scrollbar. - * win.innerHeight Height of viewport including scrollbar. - * body.clientHeight Height of document. - * - * Gecko Backwards compatible mode: - * docEl.clientWidth Width of viewport excluding scrollbar. - * win.innerWidth Width of viewport including scrollbar. - * body.clientWidth Width of viewport excluding scrollbar. - * - * docEl.clientHeight Height of document. - * win.innerHeight Height of viewport including scrollbar. - * body.clientHeight Height of viewport excluding scrollbar. - * - * IE6/7 Standards mode: - * docEl.clientWidth Width of viewport excluding scrollbar. - * win.innerWidth Undefined. - * body.clientWidth Width of body element. - * - * docEl.clientHeight Height of viewport excluding scrollbar. - * win.innerHeight Undefined. - * body.clientHeight Height of document element. - * - * IE5 + IE6/7 Backwards compatible mode: - * docEl.clientWidth 0. - * win.innerWidth Undefined. - * body.clientWidth Width of viewport excluding scrollbar. - * - * docEl.clientHeight 0. - * win.innerHeight Undefined. - * body.clientHeight Height of viewport excluding scrollbar. - * - * Opera 9 Standards and backwards compatible mode: - * docEl.clientWidth Width of viewport excluding scrollbar. - * win.innerWidth Width of viewport including scrollbar. - * body.clientWidth Width of viewport excluding scrollbar. - * - * docEl.clientHeight Height of document. - * win.innerHeight Height of viewport including scrollbar. - * body.clientHeight Height of viewport excluding scrollbar. - * - * WebKit: - * Safari 2 - * docEl.clientHeight Same as scrollHeight. - * docEl.clientWidth Same as innerWidth. - * win.innerWidth Width of viewport excluding scrollbar. - * win.innerHeight Height of the viewport including scrollbar. - * frame.innerHeight Height of the viewport exluding scrollbar. - * - * Safari 3 (tested in 522) - * - * docEl.clientWidth Width of viewport excluding scrollbar. - * docEl.clientHeight Height of viewport excluding scrollbar in strict mode. - * body.clientHeight Height of viewport excluding scrollbar in quirks mode. - * - * @param {Window=} opt_window Optional window element to test. - * @return {!goog.math.Size} Object with values 'width' and 'height'. - */ -goog.dom.getViewportSize = function(opt_window) { - // TODO(arv): This should not take an argument - return goog.dom.getViewportSize_(opt_window || window); -}; - - -/** - * Helper for {@code getViewportSize}. - * @param {Window} win The window to get the view port size for. - * @return {!goog.math.Size} Object with values 'width' and 'height'. - * @private - */ -goog.dom.getViewportSize_ = function(win) { - var doc = win.document; - - if (goog.userAgent.WEBKIT && !goog.userAgent.isVersion('500') && - !goog.userAgent.MOBILE) { - // TODO(user): Sometimes we get something that isn't a valid window - // object. In this case we just revert to the current window. We need to - // figure out when this happens and find a real fix for it. - // See the comments on goog.dom.getWindow. - if (typeof win.innerHeight == 'undefined') { - win = window; - } - var innerHeight = win.innerHeight; - var scrollHeight = win.document.documentElement.scrollHeight; - - if (win == win.top) { - if (scrollHeight < innerHeight) { - innerHeight -= 15; // Scrollbars are 15px wide on Mac - } - } - return new goog.math.Size(win.innerWidth, innerHeight); - } - - var el = goog.dom.isCss1CompatMode_(doc) ? doc.documentElement : doc.body; - - return new goog.math.Size(el.clientWidth, el.clientHeight); -}; - - -/** - * Calculates the height of the document. - * - * @return {number} The height of the current document. - */ -goog.dom.getDocumentHeight = function() { - return goog.dom.getDocumentHeight_(window); -}; - - -/** - * Calculates the height of the document of the given window. - * - * Function code copied from the opensocial gadget api: - * gadgets.window.adjustHeight(opt_height) - * - * @private - * @param {Window} win The window whose document height to retrieve. - * @return {number} The height of the document of the given window. - */ -goog.dom.getDocumentHeight_ = function(win) { - // NOTE(eae): This method will return the window size rather than the document - // size in webkit quirks mode. - var doc = win.document; - var height = 0; - - if (doc) { - // Calculating inner content height is hard and different between - // browsers rendering in Strict vs. Quirks mode. We use a combination of - // three properties within document.body and document.documentElement: - // - scrollHeight - // - offsetHeight - // - clientHeight - // These values differ significantly between browsers and rendering modes. - // But there are patterns. It just takes a lot of time and persistence - // to figure out. - - // Get the height of the viewport - var vh = goog.dom.getViewportSize_(win).height; - var body = doc.body; - var docEl = doc.documentElement; - if (goog.dom.isCss1CompatMode_(doc) && docEl.scrollHeight) { - // In Strict mode: - // The inner content height is contained in either: - // document.documentElement.scrollHeight - // document.documentElement.offsetHeight - // Based on studying the values output by different browsers, - // use the value that's NOT equal to the viewport height found above. - height = docEl.scrollHeight != vh ? - docEl.scrollHeight : docEl.offsetHeight; - } else { - // In Quirks mode: - // documentElement.clientHeight is equal to documentElement.offsetHeight - // except in IE. In most browsers, document.documentElement can be used - // to calculate the inner content height. - // However, in other browsers (e.g. IE), document.body must be used - // instead. How do we know which one to use? - // If document.documentElement.clientHeight does NOT equal - // document.documentElement.offsetHeight, then use document.body. - var sh = docEl.scrollHeight; - var oh = docEl.offsetHeight; - if (docEl.clientHeight != oh) { - sh = body.scrollHeight; - oh = body.offsetHeight; - } - - // Detect whether the inner content height is bigger or smaller - // than the bounding box (viewport). If bigger, take the larger - // value. If smaller, take the smaller value. - if (sh > vh) { - // Content is larger - height = sh > oh ? sh : oh; - } else { - // Content is smaller - height = sh < oh ? sh : oh; - } - } - } - - return height; -}; - - -/** - * Gets the page scroll distance as a coordinate object. - * - * @param {Window=} opt_window Optional window element to test. - * @return {!goog.math.Coordinate} Object with values 'x' and 'y'. - * @deprecated Use {@link goog.dom.getDocumentScroll} instead. - */ -goog.dom.getPageScroll = function(opt_window) { - var win = opt_window || goog.global || window; - return goog.dom.getDomHelper(win.document).getDocumentScroll(); -}; - - -/** - * Gets the document scroll distance as a coordinate object. - * - * @return {!goog.math.Coordinate} Object with values 'x' and 'y'. - */ -goog.dom.getDocumentScroll = function() { - return goog.dom.getDocumentScroll_(document); -}; - - -/** - * Helper for {@code getDocumentScroll}. - * - * @param {!Document} doc The document to get the scroll for. - * @return {!goog.math.Coordinate} Object with values 'x' and 'y'. - * @private - */ -goog.dom.getDocumentScroll_ = function(doc) { - var el = goog.dom.getDocumentScrollElement_(doc); - var win = goog.dom.getWindow_(doc); - return new goog.math.Coordinate(win.pageXOffset || el.scrollLeft, - win.pageYOffset || el.scrollTop); -}; - - -/** - * Gets the document scroll element. - * @return {Element} Scrolling element. - */ -goog.dom.getDocumentScrollElement = function() { - return goog.dom.getDocumentScrollElement_(document); -}; - - -/** - * Helper for {@code getDocumentScrollElement}. - * @param {!Document} doc The document to get the scroll element for. - * @return {Element} Scrolling element. - * @private - */ -goog.dom.getDocumentScrollElement_ = function(doc) { - // Safari (2 and 3) needs body.scrollLeft in both quirks mode and strict mode. - return !goog.userAgent.WEBKIT && goog.dom.isCss1CompatMode_(doc) ? - doc.documentElement : doc.body; -}; - - -/** - * Gets the window object associated with the given document. - * - * @param {Document=} opt_doc Document object to get window for. - * @return {!Window} The window associated with the given document. - */ -goog.dom.getWindow = function(opt_doc) { - // TODO(arv): This should not take an argument. - return opt_doc ? goog.dom.getWindow_(opt_doc) : window; -}; - - -/** - * Helper for {@code getWindow}. - * - * @param {!Document} doc Document object to get window for. - * @return {!Window} The window associated with the given document. - * @private - */ -goog.dom.getWindow_ = function(doc) { - return doc.parentWindow || doc.defaultView; -}; - - -/** - * Returns a dom node with a set of attributes. This function accepts varargs - * for subsequent nodes to be added. Subsequent nodes will be added to the - * first node as childNodes. - * - * So: - * <code>createDom('div', null, createDom('p'), createDom('p'));</code> - * would return a div with two child paragraphs - * - * @param {string} tagName Tag to create. - * @param {Object|Array.<string>|string=} opt_attributes If object, then a map - * of name-value pairs for attributes. If a string, then this is the - * className of the new element. If an array, the elements will be joined - * together as the className of the new element. - * @param {...Object|string|Array|NodeList} var_args Further DOM nodes or - * strings for text nodes. If one of the var_args is an array or NodeList,i - * its elements will be added as childNodes instead. - * @return {!Element} Reference to a DOM node. - */ -goog.dom.createDom = function(tagName, opt_attributes, var_args) { - return goog.dom.createDom_(document, arguments); -}; - - -/** - * Helper for {@code createDom}. - * @param {!Document} doc The document to create the DOM in. - * @param {!Arguments} args Argument object passed from the callers. See - * {@code goog.dom.createDom} for details. - * @return {!Element} Reference to a DOM node. - * @private - */ -goog.dom.createDom_ = function(doc, args) { - var tagName = args[0]; - var attributes = args[1]; - - // Internet Explorer is dumb: http://msdn.microsoft.com/workshop/author/ - // dhtml/reference/properties/name_2.asp - // Also does not allow setting of 'type' attribute on 'input' or 'button'. - if (!goog.dom.BrowserFeature.CAN_ADD_NAME_OR_TYPE_ATTRIBUTES && attributes && - (attributes.name || attributes.type)) { - var tagNameArr = ['<', tagName]; - if (attributes.name) { - tagNameArr.push(' name="', goog.string.htmlEscape(attributes.name), - '"'); - } - if (attributes.type) { - tagNameArr.push(' type="', goog.string.htmlEscape(attributes.type), - '"'); - - // Clone attributes map to remove 'type' without mutating the input. - var clone = {}; - goog.object.extend(clone, attributes); - attributes = clone; - delete attributes.type; - } - tagNameArr.push('>'); - tagName = tagNameArr.join(''); - } - - var element = doc.createElement(tagName); - - if (attributes) { - if (goog.isString(attributes)) { - element.className = attributes; - } else if (goog.isArray(attributes)) { - goog.dom.classes.add.apply(null, [element].concat(attributes)); - } else { - goog.dom.setProperties(element, attributes); - } - } - - if (args.length > 2) { - goog.dom.append_(doc, element, args, 2); - } - - return element; -}; - - -/** - * Appends a node with text or other nodes. - * @param {!Document} doc The document to create new nodes in. - * @param {!Node} parent The node to append nodes to. - * @param {!Arguments} args The values to add. See {@code goog.dom.append}. - * @param {number} startIndex The index of the array to start from. - * @private - */ -goog.dom.append_ = function(doc, parent, args, startIndex) { - function childHandler(child) { - // TODO(user): More coercion, ala MochiKit? - if (child) { - parent.appendChild(goog.isString(child) ? - doc.createTextNode(child) : child); - } - } - - for (var i = startIndex; i < args.length; i++) { - var arg = args[i]; - // TODO(attila): Fix isArrayLike to return false for a text node. - if (goog.isArrayLike(arg) && !goog.dom.isNodeLike(arg)) { - // If the argument is a node list, not a real array, use a clone, - // because forEach can't be used to mutate a NodeList. - goog.array.forEach(goog.dom.isNodeList(arg) ? - goog.array.clone(arg) : arg, - childHandler); - } else { - childHandler(arg); - } - } -}; - - -/** - * Alias for {@code createDom}. - * @param {string} tagName Tag to create. - * @param {string|Object=} opt_attributes If object, then a map of name-value - * pairs for attributes. If a string, then this is the className of the new - * element. - * @param {...Object|string|Array|NodeList} var_args Further DOM nodes or - * strings for text nodes. If one of the var_args is an array, its - * children will be added as childNodes instead. - * @return {!Element} Reference to a DOM node. - * @deprecated Use {@link goog.dom.createDom} instead. - */ -goog.dom.$dom = goog.dom.createDom; - - -/** - * Creates a new element. - * @param {string} name Tag name. - * @return {!Element} The new element. - */ -goog.dom.createElement = function(name) { - return document.createElement(name); -}; - - -/** - * Creates a new text node. - * @param {string} content Content. - * @return {!Text} The new text node. - */ -goog.dom.createTextNode = function(content) { - return document.createTextNode(content); -}; - - -/** - * Create a table. - * @param {number} rows The number of rows in the table. Must be >= 1. - * @param {number} columns The number of columns in the table. Must be >= 1. - * @param {boolean=} opt_fillWithNbsp If true, fills table entries with nsbps. - * @return {!Element} The created table. - */ -goog.dom.createTable = function(rows, columns, opt_fillWithNbsp) { - return goog.dom.createTable_(document, rows, columns, !!opt_fillWithNbsp); -}; - - -/** - * Create a table. - * @param {!Document} doc Document object to use to create the table. - * @param {number} rows The number of rows in the table. Must be >= 1. - * @param {number} columns The number of columns in the table. Must be >= 1. - * @param {boolean} fillWithNbsp If true, fills table entries with nsbps. - * @return {!Element} The created table. - * @private - */ -goog.dom.createTable_ = function(doc, rows, columns, fillWithNbsp) { - var rowHtml = ['<tr>']; - for (var i = 0; i < columns; i++) { - rowHtml.push(fillWithNbsp ? '<td> </td>' : '<td></td>'); - } - rowHtml.push('</tr>'); - rowHtml = rowHtml.join(''); - var totalHtml = ['<table>']; - for (i = 0; i < rows; i++) { - totalHtml.push(rowHtml); - } - totalHtml.push('</table>'); - - var elem = doc.createElement(goog.dom.TagName.DIV); - elem.innerHTML = totalHtml.join(''); - return /** @type {!Element} */ (elem.removeChild(elem.firstChild)); -}; - - -/** - * Converts an HTML string into a document fragment. - * - * @param {string} htmlString The HTML string to convert. - * @return {!Node} The resulting document fragment. - */ -goog.dom.htmlToDocumentFragment = function(htmlString) { - return goog.dom.htmlToDocumentFragment_(document, htmlString); -}; - - -/** - * Helper for {@code htmlToDocumentFragment}. - * - * @param {!Document} doc The document. - * @param {string} htmlString The HTML string to convert. - * @return {!Node} The resulting document fragment. - * @private - */ -goog.dom.htmlToDocumentFragment_ = function(doc, htmlString) { - var tempDiv = doc.createElement('div'); - if (goog.dom.BrowserFeature.INNER_HTML_NEEDS_SCOPED_ELEMENT) { - tempDiv.innerHTML = '<br>' + htmlString; - tempDiv.removeChild(tempDiv.firstChild); - } else { - tempDiv.innerHTML = htmlString; - } - if (tempDiv.childNodes.length == 1) { - return /** @type {!Node} */ (tempDiv.removeChild(tempDiv.firstChild)); - } else { - var fragment = doc.createDocumentFragment(); - while (tempDiv.firstChild) { - fragment.appendChild(tempDiv.firstChild); - } - return fragment; - } -}; - - -/** - * Returns the compatMode of the document. - * @return {string} The result is either CSS1Compat or BackCompat. - * @deprecated use goog.dom.isCss1CompatMode instead. - */ -goog.dom.getCompatMode = function() { - return goog.dom.isCss1CompatMode() ? 'CSS1Compat' : 'BackCompat'; -}; - - -/** - * Returns true if the browser is in "CSS1-compatible" (standards-compliant) - * mode, false otherwise. - * @return {boolean} True if in CSS1-compatible mode. - */ -goog.dom.isCss1CompatMode = function() { - return goog.dom.isCss1CompatMode_(document); -}; - - -/** - * Returns true if the browser is in "CSS1-compatible" (standards-compliant) - * mode, false otherwise. - * @param {Document} doc The document to check. - * @return {boolean} True if in CSS1-compatible mode. - * @private - */ -goog.dom.isCss1CompatMode_ = function(doc) { - if (goog.dom.COMPAT_MODE_KNOWN_) { - return goog.dom.ASSUME_STANDARDS_MODE; - } - - return doc.compatMode == 'CSS1Compat'; -}; - - -/** - * Determines if the given node can contain children, intended to be used for - * HTML generation. - * - * IE natively supports node.canHaveChildren but has inconsistent behavior. - * Prior to IE8 the base tag allows children and in IE9 all nodes return true - * for canHaveChildren. - * - * In practice all non-IE browsers allow you to add children to any node, but - * the behavior is inconsistent: - * - * <pre> - * var a = document.createElement('br'); - * a.appendChild(document.createTextNode('foo')); - * a.appendChild(document.createTextNode('bar')); - * console.log(a.childNodes.length); // 2 - * console.log(a.innerHTML); // Chrome: "", IE9: "foobar", FF3.5: "foobar" - * </pre> - * - * TODO(user): Rename shouldAllowChildren() ? - * - * @param {Node} node The node to check. - * @return {boolean} Whether the node can contain children. - */ -goog.dom.canHaveChildren = function(node) { - if (node.nodeType != goog.dom.NodeType.ELEMENT) { - return false; - } - switch (node.tagName) { - case goog.dom.TagName.APPLET: - case goog.dom.TagName.AREA: - case goog.dom.TagName.BASE: - case goog.dom.TagName.BR: - case goog.dom.TagName.COL: - case goog.dom.TagName.FRAME: - case goog.dom.TagName.HR: - case goog.dom.TagName.IMG: - case goog.dom.TagName.INPUT: - case goog.dom.TagName.IFRAME: - case goog.dom.TagName.ISINDEX: - case goog.dom.TagName.LINK: - case goog.dom.TagName.NOFRAMES: - case goog.dom.TagName.NOSCRIPT: - case goog.dom.TagName.META: - case goog.dom.TagName.OBJECT: - case goog.dom.TagName.PARAM: - case goog.dom.TagName.SCRIPT: - case goog.dom.TagName.STYLE: - return false; - } - return true; -}; - - -/** - * Appends a child to a node. - * @param {Node} parent Parent. - * @param {Node} child Child. - */ -goog.dom.appendChild = function(parent, child) { - parent.appendChild(child); -}; - - -/** - * Appends a node with text or other nodes. - * @param {!Node} parent The node to append nodes to. - * @param {...goog.dom.Appendable} var_args The things to append to the node. - * If this is a Node it is appended as is. - * If this is a string then a text node is appended. - * If this is an array like object then fields 0 to length - 1 are appended. - */ -goog.dom.append = function(parent, var_args) { - goog.dom.append_(goog.dom.getOwnerDocument(parent), parent, arguments, 1); -}; - - -/** - * Removes all the child nodes on a DOM node. - * @param {Node} node Node to remove children from. - */ -goog.dom.removeChildren = function(node) { - // Note: Iterations over live collections can be slow, this is the fastest - // we could find. The double parenthesis are used to prevent JsCompiler and - // strict warnings. - var child; - while ((child = node.firstChild)) { - node.removeChild(child); - } -}; - - -/** - * Inserts a new node before an existing reference node (i.e. as the previous - * sibling). If the reference node has no parent, then does nothing. - * @param {Node} newNode Node to insert. - * @param {Node} refNode Reference node to insert before. - */ -goog.dom.insertSiblingBefore = function(newNode, refNode) { - if (refNode.parentNode) { - refNode.parentNode.insertBefore(newNode, refNode); - } -}; - - -/** - * Inserts a new node after an existing reference node (i.e. as the next - * sibling). If the reference node has no parent, then does nothing. - * @param {Node} newNode Node to insert. - * @param {Node} refNode Reference node to insert after. - */ -goog.dom.insertSiblingAfter = function(newNode, refNode) { - if (refNode.parentNode) { - refNode.parentNode.insertBefore(newNode, refNode.nextSibling); - } -}; - - -/** - * Insert a child at a given index. If index is larger than the number of child - * nodes that the parent currently has, the node is inserted as the last child - * node. - * @param {Element} parent The element into which to insert the child. - * @param {Node} child The element to insert. - * @param {number} index The index at which to insert the new child node. Must - * not be negative. - */ -goog.dom.insertChildAt = function(parent, child, index) { - // Note that if the second argument is null, insertBefore - // will append the child at the end of the list of children. - parent.insertBefore(child, parent.childNodes[index] || null); -}; - - -/** - * Removes a node from its parent. - * @param {Node} node The node to remove. - * @return {Node} The node removed if removed; else, null. - */ -goog.dom.removeNode = function(node) { - return node && node.parentNode ? node.parentNode.removeChild(node) : null; -}; - - -/** - * Replaces a node in the DOM tree. Will do nothing if {@code oldNode} has no - * parent. - * @param {Node} newNode Node to insert. - * @param {Node} oldNode Node to replace. - */ -goog.dom.replaceNode = function(newNode, oldNode) { - var parent = oldNode.parentNode; - if (parent) { - parent.replaceChild(newNode, oldNode); - } -}; - - -/** - * Flattens an element. That is, removes it and replace it with its children. - * Does nothing if the element is not in the document. - * @param {Element} element The element to flatten. - * @return {Element|undefined} The original element, detached from the document - * tree, sans children; or undefined, if the element was not in the - * document to begin with. - */ -goog.dom.flattenElement = function(element) { - var child, parent = element.parentNode; - if (parent && parent.nodeType != goog.dom.NodeType.DOCUMENT_FRAGMENT) { - // Use IE DOM method (supported by Opera too) if available - if (element.removeNode) { - return /** @type {Element} */ (element.removeNode(false)); - } else { - // Move all children of the original node up one level. - while ((child = element.firstChild)) { - parent.insertBefore(child, element); - } - - // Detach the original element. - return /** @type {Element} */ (goog.dom.removeNode(element)); - } - } -}; - - -/** - * Returns an array containing just the element children of the given element. - * @param {Element} element The element whose element children we want. - * @return {Array|NodeList} An array or array-like list of just the element - * children of the given element. - */ -goog.dom.getChildren = function(element) { - // We check if the children attribute is supported for child elements - // since IE8 misuses the attribute by also including comments. - if (goog.dom.BrowserFeature.CAN_USE_CHILDREN_ATTRIBUTE && - element.children != undefined) { - return element.children; - } - // Fall back to manually filtering the element's child nodes. - return goog.array.filter(element.childNodes, function(node) { - return node.nodeType == goog.dom.NodeType.ELEMENT; - }); -}; - - -/** - * Returns the first child node that is an element. - * @param {Node} node The node to get the first child element of. - * @return {Element} The first child node of {@code node} that is an element. - */ -goog.dom.getFirstElementChild = function(node) { - if (node.firstElementChild != undefined) { - return /** @type {Element} */(node).firstElementChild; - } - return goog.dom.getNextElementNode_(node.firstChild, true); -}; - - -/** - * Returns the last child node that is an element. - * @param {Node} node The node to get the last child element of. - * @return {Element} The last child node of {@code node} that is an element. - */ -goog.dom.getLastElementChild = function(node) { - if (node.lastElementChild != undefined) { - return /** @type {Element} */(node).lastElementChild; - } - return goog.dom.getNextElementNode_(node.lastChild, false); -}; - - -/** - * Returns the first next sibling that is an element. - * @param {Node} node The node to get the next sibling element of. - * @return {Element} The next sibling of {@code node} that is an element. - */ -goog.dom.getNextElementSibling = function(node) { - if (node.nextElementSibling != undefined) { - return /** @type {Element} */(node).nextElementSibling; - } - return goog.dom.getNextElementNode_(node.nextSibling, true); -}; - - -/** - * Returns the first previous sibling that is an element. - * @param {Node} node The node to get the previous sibling element of. - * @return {Element} The first previous sibling of {@code node} that is - * an element. - */ -goog.dom.getPreviousElementSibling = function(node) { - if (node.previousElementSibling != undefined) { - return /** @type {Element} */(node).previousElementSibling; - } - return goog.dom.getNextElementNode_(node.previousSibling, false); -}; - - -/** - * Returns the first node that is an element in the specified direction, - * starting with {@code node}. - * @param {Node} node The node to get the next element from. - * @param {boolean} forward Whether to look forwards or backwards. - * @return {Element} The first element. - * @private - */ -goog.dom.getNextElementNode_ = function(node, forward) { - while (node && node.nodeType != goog.dom.NodeType.ELEMENT) { - node = forward ? node.nextSibling : node.previousSibling; - } - - return /** @type {Element} */ (node); -}; - - -/** - * Returns the next node in source order from the given node. - * @param {Node} node The node. - * @return {Node} The next node in the DOM tree, or null if this was the last - * node. - */ -goog.dom.getNextNode = function(node) { - if (!node) { - return null; - } - - if (node.firstChild) { - return node.firstChild; - } - - while (node && !node.nextSibling) { - node = node.parentNode; - } - - return node ? node.nextSibling : null; -}; - - -/** - * Returns the previous node in source order from the given node. - * @param {Node} node The node. - * @return {Node} The previous node in the DOM tree, or null if this was the - * first node. - */ -goog.dom.getPreviousNode = function(node) { - if (!node) { - return null; - } - - if (!node.previousSibling) { - return node.parentNode; - } - - node = node.previousSibling; - while (node && node.lastChild) { - node = node.lastChild; - } - - return node; -}; - - -/** - * Whether the object looks like a DOM node. - * @param {*} obj The object being tested for node likeness. - * @return {boolean} Whether the object looks like a DOM node. - */ -goog.dom.isNodeLike = function(obj) { - return goog.isObject(obj) && obj.nodeType > 0; -}; - - -/** - * Whether the object looks like an Element. - * @param {*} obj The object being tested for Element likeness. - * @return {boolean} Whether the object looks like an Element. - */ -goog.dom.isElement = function(obj) { - return goog.isObject(obj) && obj.nodeType == goog.dom.NodeType.ELEMENT; -}; - - -/** - * Returns true if the specified value is a Window object. This includes the - * global window for HTML pages, and iframe windows. - * @param {*} obj Variable to test. - * @return {boolean} Whether the variable is a window. - */ -goog.dom.isWindow = function(obj) { - return goog.isObject(obj) && obj['window'] == obj; -}; - - -/** - * Returns an element's parent, if it's an Element. - * @param {Element} element The DOM element. - * @return {Element} The parent, or null if not an Element. - */ -goog.dom.getParentElement = function(element) { - if (goog.dom.BrowserFeature.CAN_USE_PARENT_ELEMENT_PROPERTY) { - return element.parentElement; - } - var parent = element.parentNode; - return goog.dom.isElement(parent) ? (/** @type {!Element} */ parent) : null; -}; - - -/** - * Whether a node contains another node. - * @param {Node} parent The node that should contain the other node. - * @param {Node} descendant The node to test presence of. - * @return {boolean} Whether the parent node contains the descendent node. - */ -goog.dom.contains = function(parent, descendant) { - // We use browser specific methods for this if available since it is faster - // that way. - - // IE DOM - if (parent.contains && descendant.nodeType == goog.dom.NodeType.ELEMENT) { - return parent == descendant || parent.contains(descendant); - } - - // W3C DOM Level 3 - if (typeof parent.compareDocumentPosition != 'undefined') { - return parent == descendant || - Boolean(parent.compareDocumentPosition(descendant) & 16); - } - - // W3C DOM Level 1 - while (descendant && parent != descendant) { - descendant = descendant.parentNode; - } - return descendant == parent; -}; - - -/** - * Compares the document order of two nodes, returning 0 if they are the same - * node, a negative number if node1 is before node2, and a positive number if - * node2 is before node1. Note that we compare the order the tags appear in the - * document so in the tree <b><i>text</i></b> the B node is considered to be - * before the I node. - * - * @param {Node} node1 The first node to compare. - * @param {Node} node2 The second node to compare. - * @return {number} 0 if the nodes are the same node, a negative number if node1 - * is before node2, and a positive number if node2 is before node1. - */ -goog.dom.compareNodeOrder = function(node1, node2) { - // Fall out quickly for equality. - if (node1 == node2) { - return 0; - } - - // Use compareDocumentPosition where available - if (node1.compareDocumentPosition) { - // 4 is the bitmask for FOLLOWS. - return node1.compareDocumentPosition(node2) & 2 ? 1 : -1; - } - - // Process in IE using sourceIndex - we check to see if the first node has - // a source index or if its parent has one. - if ('sourceIndex' in node1 || - (node1.parentNode && 'sourceIndex' in node1.parentNode)) { - var isElement1 = node1.nodeType == goog.dom.NodeType.ELEMENT; - var isElement2 = node2.nodeType == goog.dom.NodeType.ELEMENT; - - if (isElement1 && isElement2) { - return node1.sourceIndex - node2.sourceIndex; - } else { - var parent1 = node1.parentNode; - var parent2 = node2.parentNode; - - if (parent1 == parent2) { - return goog.dom.compareSiblingOrder_(node1, node2); - } - - if (!isElement1 && goog.dom.contains(parent1, node2)) { - return -1 * goog.dom.compareParentsDescendantNodeIe_(node1, node2); - } - - - if (!isElement2 && goog.dom.contains(parent2, node1)) { - return goog.dom.compareParentsDescendantNodeIe_(node2, node1); - } - - return (isElement1 ? node1.sourceIndex : parent1.sourceIndex) - - (isElement2 ? node2.sourceIndex : parent2.sourceIndex); - } - } - - // For Safari, we compare ranges. - var doc = goog.dom.getOwnerDocument(node1); - - var range1, range2; - range1 = doc.createRange(); - range1.selectNode(node1); - range1.collapse(true); - - range2 = doc.createRange(); - range2.selectNode(node2); - range2.collapse(true); - - return range1.compareBoundaryPoints(goog.global['Range'].START_TO_END, - range2); -}; - - -/** - * Utility function to compare the position of two nodes, when - * {@code textNode}'s parent is an ancestor of {@code node}. If this entry - * condition is not met, this function will attempt to reference a null object. - * @param {Node} textNode The textNode to compare. - * @param {Node} node The node to compare. - * @return {number} -1 if node is before textNode, +1 otherwise. - * @private - */ -goog.dom.compareParentsDescendantNodeIe_ = function(textNode, node) { - var parent = textNode.parentNode; - if (parent == node) { - // If textNode is a child of node, then node comes first. - return -1; - } - var sibling = node; - while (sibling.parentNode != parent) { - sibling = sibling.parentNode; - } - return goog.dom.compareSiblingOrder_(sibling, textNode); -}; - - -/** - * Utility function to compare the position of two nodes known to be non-equal - * siblings. - * @param {Node} node1 The first node to compare. - * @param {Node} node2 The second node to compare. - * @return {number} -1 if node1 is before node2, +1 otherwise. - * @private - */ -goog.dom.compareSiblingOrder_ = function(node1, node2) { - var s = node2; - while ((s = s.previousSibling)) { - if (s == node1) { - // We just found node1 before node2. - return -1; - } - } - - // Since we didn't find it, node1 must be after node2. - return 1; -}; - - -/** - * Find the deepest common ancestor of the given nodes. - * @param {...Node} var_args The nodes to find a common ancestor of. - * @return {Node} The common ancestor of the nodes, or null if there is none. - * null will only be returned if two or more of the nodes are from different - * documents. - */ -goog.dom.findCommonAncestor = function(var_args) { - var i, count = arguments.length; - if (!count) { - return null; - } else if (count == 1) { - return arguments[0]; - } - - var paths = []; - var minLength = Infinity; - for (i = 0; i < count; i++) { - // Compute the list of ancestors. - var ancestors = []; - var node = arguments[i]; - while (node) { - ancestors.unshift(node); - node = node.parentNode; - } - - // Save the list for comparison. - paths.push(ancestors); - minLength = Math.min(minLength, ancestors.length); - } - var output = null; - for (i = 0; i < minLength; i++) { - var first = paths[0][i]; - for (var j = 1; j < count; j++) { - if (first != paths[j][i]) { - return output; - } - } - output = first; - } - return output; -}; - - -/** - * Returns the owner document for a node. - * @param {Node|Window} node The node to get the document for. - * @return {!Document} The document owning the node. - */ -goog.dom.getOwnerDocument = function(node) { - // TODO(arv): Remove IE5 code. - // IE5 uses document instead of ownerDocument - return /** @type {!Document} */ ( - node.nodeType == goog.dom.NodeType.DOCUMENT ? node : - node.ownerDocument || node.document); -}; - - -/** - * Cross-browser function for getting the document element of a frame or iframe. - * @param {Element} frame Frame element. - * @return {!Document} The frame content document. - */ -goog.dom.getFrameContentDocument = function(frame) { - var doc = frame.contentDocument || frame.contentWindow.document; - return doc; -}; - - -/** - * Cross-browser function for getting the window of a frame or iframe. - * @param {HTMLIFrameElement|HTMLFrameElement} frame Frame element. - * @return {Window} The window associated with the given frame. - */ -goog.dom.getFrameContentWindow = function(frame) { - return frame.contentWindow || - goog.dom.getWindow_(goog.dom.getFrameContentDocument(frame)); -}; - - -/** - * Cross-browser function for setting the text content of an element. - * @param {Element} element The element to change the text content of. - * @param {string} text The string that should replace the current element - * content. - */ -goog.dom.setTextContent = function(element, text) { - if ('textContent' in element) { - element.textContent = text; - } else if (element.firstChild && - element.firstChild.nodeType == goog.dom.NodeType.TEXT) { - // If the first child is a text node we just change its data and remove the - // rest of the children. - while (element.lastChild != element.firstChild) { - element.removeChild(element.lastChild); - } - element.firstChild.data = text; - } else { - goog.dom.removeChildren(element); - var doc = goog.dom.getOwnerDocument(element); - element.appendChild(doc.createTextNode(text)); - } -}; - - -/** - * Gets the outerHTML of a node, which islike innerHTML, except that it - * actually contains the HTML of the node itself. - * @param {Element} element The element to get the HTML of. - * @return {string} The outerHTML of the given element. - */ -goog.dom.getOuterHtml = function(element) { - // IE, Opera and WebKit all have outerHTML. - if ('outerHTML' in element) { - return element.outerHTML; - } else { - var doc = goog.dom.getOwnerDocument(element); - var div = doc.createElement('div'); - div.appendChild(element.cloneNode(true)); - return div.innerHTML; - } -}; - - -/** - * Finds the first descendant node that matches the filter function, using - * a depth first search. This function offers the most general purpose way - * of finding a matching element. You may also wish to consider - * {@code goog.dom.query} which can express many matching criteria using - * CSS selector expressions. These expressions often result in a more - * compact representation of the desired result. - * @see goog.dom.query - * - * @param {Node} root The root of the tree to search. - * @param {function(Node) : boolean} p The filter function. - * @return {Node|undefined} The found node or undefined if none is found. - */ -goog.dom.findNode = function(root, p) { - var rv = []; - var found = goog.dom.findNodes_(root, p, rv, true); - return found ? rv[0] : undefined; -}; - - -/** - * Finds all the descendant nodes that match the filter function, using a - * a depth first search. This function offers the most general-purpose way - * of finding a set of matching elements. You may also wish to consider - * {@code goog.dom.query} which can express many matching criteria using - * CSS selector expressions. These expressions often result in a more - * compact representation of the desired result. - - * @param {Node} root The root of the tree to search. - * @param {function(Node) : boolean} p The filter function. - * @return {Array.<Node>} The found nodes or an empty array if none are found. - */ -goog.dom.findNodes = function(root, p) { - var rv = []; - goog.dom.findNodes_(root, p, rv, false); - return rv; -}; - - -/** - * Finds the first or all the descendant nodes that match the filter function, - * using a depth first search. - * @param {Node} root The root of the tree to search. - * @param {function(Node) : boolean} p The filter function. - * @param {Array.<Node>} rv The found nodes are added to this array. - * @param {boolean} findOne If true we exit after the first found node. - * @return {boolean} Whether the search is complete or not. True in case findOne - * is true and the node is found. False otherwise. - * @private - */ -goog.dom.findNodes_ = function(root, p, rv, findOne) { - if (root != null) { - var child = root.firstChild; - while (child) { - if (p(child)) { - rv.push(child); - if (findOne) { - return true; - } - } - if (goog.dom.findNodes_(child, p, rv, findOne)) { - return true; - } - child = child.nextSibling; - } - } - return false; -}; - - -/** - * Map of tags whose content to ignore when calculating text length. - * @type {Object} - * @private - */ -goog.dom.TAGS_TO_IGNORE_ = { - 'SCRIPT': 1, - 'STYLE': 1, - 'HEAD': 1, - 'IFRAME': 1, - 'OBJECT': 1 -}; - - -/** - * Map of tags which have predefined values with regard to whitespace. - * @type {Object} - * @private - */ -goog.dom.PREDEFINED_TAG_VALUES_ = {'IMG': ' ', 'BR': '\n'}; - - -/** - * Returns true if the element has a tab index that allows it to receive - * keyboard focus (tabIndex >= 0), false otherwise. Note that form elements - * natively support keyboard focus, even if they have no tab index. - * @param {Element} element Element to check. - * @return {boolean} Whether the element has a tab index that allows keyboard - * focus. - * @see http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ - */ -goog.dom.isFocusableTabIndex = function(element) { - // IE returns 0 for an unset tabIndex, so we must use getAttributeNode(), - // which returns an object with a 'specified' property if tabIndex is - // specified. This works on other browsers, too. - var attrNode = element.getAttributeNode('tabindex'); // Must be lowercase! - if (attrNode && attrNode.specified) { - var index = element.tabIndex; - // NOTE: IE9 puts tabIndex in 16-bit int, e.g. -2 is 65534. - return goog.isNumber(index) && index >= 0 && index < 32768; - } - return false; -}; - - -/** - * Enables or disables keyboard focus support on the element via its tab index. - * Only elements for which {@link goog.dom.isFocusableTabIndex} returns true - * (or elements that natively support keyboard focus, like form elements) can - * receive keyboard focus. See http://go/tabindex for more info. - * @param {Element} element Element whose tab index is to be changed. - * @param {boolean} enable Whether to set or remove a tab index on the element - * that supports keyboard focus. - */ -goog.dom.setFocusableTabIndex = function(element, enable) { - if (enable) { - element.tabIndex = 0; - } else { - // Set tabIndex to -1 first, then remove it. This is a workaround for - // Safari (confirmed in version 4 on Windows). When removing the attribute - // without setting it to -1 first, the element remains keyboard focusable - // despite not having a tabIndex attribute anymore. - element.tabIndex = -1; - element.removeAttribute('tabIndex'); // Must be camelCase! - } -}; - - -/** - * Returns the text content of the current node, without markup and invisible - * symbols. New lines are stripped and whitespace is collapsed, - * such that each character would be visible. - * - * In browsers that support it, innerText is used. Other browsers attempt to - * simulate it via node traversal. Line breaks are canonicalized in IE. - * - * @param {Node} node The node from which we are getting content. - * @return {string} The text content. - */ -goog.dom.getTextContent = function(node) { - var textContent; - // Note(arv): IE9, Opera, and Safari 3 support innerText but they include - // text nodes in script tags. So we revert to use a user agent test here. - if (goog.dom.BrowserFeature.CAN_USE_INNER_TEXT && ('innerText' in node)) { - textContent = goog.string.canonicalizeNewlines(node.innerText); - // Unfortunately .innerText() returns text with ­ symbols - // We need to filter it out and then remove duplicate whitespaces - } else { - var buf = []; - goog.dom.getTextContent_(node, buf, true); - textContent = buf.join(''); - } - - // Strip ­ entities. goog.format.insertWordBreaks inserts them in Opera. - textContent = textContent.replace(/ \xAD /g, ' ').replace(/\xAD/g, ''); - // Strip ​ entities. goog.format.insertWordBreaks inserts them in IE8. - textContent = textContent.replace(/\u200B/g, ''); - - // Skip this replacement on old browsers with working innerText, which - // automatically turns into ' ' and / +/ into ' ' when reading - // innerText. - if (!goog.dom.BrowserFeature.CAN_USE_INNER_TEXT) { - textContent = textContent.replace(/ +/g, ' '); - } - if (textContent != ' ') { - textContent = textContent.replace(/^\s*/, ''); - } - - return textContent; -}; - - -/** - * Returns the text content of the current node, without markup. - * - * Unlike {@code getTextContent} this method does not collapse whitespaces - * or normalize lines breaks. - * - * @param {Node} node The node from which we are getting content. - * @return {string} The raw text content. - */ -goog.dom.getRawTextContent = function(node) { - var buf = []; - goog.dom.getTextContent_(node, buf, false); - - return buf.join(''); -}; - - -/** - * Recursive support function for text content retrieval. - * - * @param {Node} node The node from which we are getting content. - * @param {Array} buf string buffer. - * @param {boolean} normalizeWhitespace Whether to normalize whitespace. - * @private - */ -goog.dom.getTextContent_ = function(node, buf, normalizeWhitespace) { - if (node.nodeName in goog.dom.TAGS_TO_IGNORE_) { - // ignore certain tags - } else if (node.nodeType == goog.dom.NodeType.TEXT) { - if (normalizeWhitespace) { - buf.push(String(node.nodeValue).replace(/(\r\n|\r|\n)/g, '')); - } else { - buf.push(node.nodeValue); - } - } else if (node.nodeName in goog.dom.PREDEFINED_TAG_VALUES_) { - buf.push(goog.dom.PREDEFINED_TAG_VALUES_[node.nodeName]); - } else { - var child = node.firstChild; - while (child) { - goog.dom.getTextContent_(child, buf, normalizeWhitespace); - child = child.nextSibling; - } - } -}; - - -/** - * Returns the text length of the text contained in a node, without markup. This - * is equivalent to the selection length if the node was selected, or the number - * of cursor movements to traverse the node. Images & BRs take one space. New - * lines are ignored. - * - * @param {Node} node The node whose text content length is being calculated. - * @return {number} The length of {@code node}'s text content. - */ -goog.dom.getNodeTextLength = function(node) { - return goog.dom.getTextContent(node).length; -}; - - -/** - * Returns the text offset of a node relative to one of its ancestors. The text - * length is the same as the length calculated by goog.dom.getNodeTextLength. - * - * @param {Node} node The node whose offset is being calculated. - * @param {Node=} opt_offsetParent The node relative to which the offset will - * be calculated. Defaults to the node's owner document's body. - * @return {number} The text offset. - */ -goog.dom.getNodeTextOffset = function(node, opt_offsetParent) { - var root = opt_offsetParent || goog.dom.getOwnerDocument(node).body; - var buf = []; - while (node && node != root) { - var cur = node; - while ((cur = cur.previousSibling)) { - buf.unshift(goog.dom.getTextContent(cur)); - } - node = node.parentNode; - } - // Trim left to deal with FF cases when there might be line breaks and empty - // nodes at the front of the text - return goog.string.trimLeft(buf.join('')).replace(/ +/g, ' ').length; -}; - - -/** - * Returns the node at a given offset in a parent node. If an object is - * provided for the optional third parameter, the node and the remainder of the - * offset will stored as properties of this object. - * @param {Node} parent The parent node. - * @param {number} offset The offset into the parent node. - * @param {Object=} opt_result Object to be used to store the return value. The - * return value will be stored in the form {node: Node, remainder: number} - * if this object is provided. - * @return {Node} The node at the given offset. - */ -goog.dom.getNodeAtOffset = function(parent, offset, opt_result) { - var stack = [parent], pos = 0, cur; - while (stack.length > 0 && pos < offset) { - cur = stack.pop(); - if (cur.nodeName in goog.dom.TAGS_TO_IGNORE_) { - // ignore certain tags - } else if (cur.nodeType == goog.dom.NodeType.TEXT) { - var text = cur.nodeValue.replace(/(\r\n|\r|\n)/g, '').replace(/ +/g, ' '); - pos += text.length; - } else if (cur.nodeName in goog.dom.PREDEFINED_TAG_VALUES_) { - pos += goog.dom.PREDEFINED_TAG_VALUES_[cur.nodeName].length; - } else { - for (var i = cur.childNodes.length - 1; i >= 0; i--) { - stack.push(cur.childNodes[i]); - } - } - } - if (goog.isObject(opt_result)) { - opt_result.remainder = cur ? cur.nodeValue.length + offset - pos - 1 : 0; - opt_result.node = cur; - } - - return cur; -}; - - -/** - * Returns true if the object is a {@code NodeList}. To qualify as a NodeList, - * the object must have a numeric length property and an item function (which - * has type 'string' on IE for some reason). - * @param {Object} val Object to test. - * @return {boolean} Whether the object is a NodeList. - */ -goog.dom.isNodeList = function(val) { - // TODO(attila): Now the isNodeList is part of goog.dom we can use - // goog.userAgent to make this simpler. - // A NodeList must have a length property of type 'number' on all platforms. - if (val && typeof val.length == 'number') { - // A NodeList is an object everywhere except Safari, where it's a function. - if (goog.isObject(val)) { - // A NodeList must have an item function (on non-IE platforms) or an item - // property of type 'string' (on IE). - return typeof val.item == 'function' || typeof val.item == 'string'; - } else if (goog.isFunction(val)) { - // On Safari, a NodeList is a function with an item property that is also - // a function. - return typeof val.item == 'function'; - } - } - - // Not a NodeList. - return false; -}; - - -/** - * Walks up the DOM hierarchy returning the first ancestor that has the passed - * tag name and/or class name. If the passed element matches the specified - * criteria, the element itself is returned. - * @param {Node} element The DOM node to start with. - * @param {?string=} opt_tag The tag name to match (or null/undefined to match - * any node regardless of tag name). Must be uppercase (goog.dom.TagName). - * @param {?string=} opt_class The class name to match (or null/undefined to - * match any node regardless of class name). - * @return {Node} The first ancestor that matches the passed criteria, or - * null if none match. - */ -goog.dom.getAncestorByTagNameAndClass = function(element, opt_tag, opt_class) { - var tagName = opt_tag ? opt_tag.toUpperCase() : null; - return goog.dom.getAncestor(element, - function(node) { - return (!tagName || node.nodeName == tagName) && - (!opt_class || goog.dom.classes.has(node, opt_class)); - }, true); -}; - - -/** - * Walks up the DOM hierarchy returning the first ancestor that has the passed - * class name. If the passed element matches the specified criteria, the - * element itself is returned. - * @param {Node} element The DOM node to start with. - * @param {?string=} opt_class The class name to match (or null/undefined to - * match any node regardless of class name). - * @return {Node} The first ancestor that matches the passed criteria, or - * null if none match. - */ -goog.dom.getAncestorByClass = function(element, opt_class) { - return goog.dom.getAncestorByTagNameAndClass(element, null, opt_class); -}; - - -/** - * Walks up the DOM hierarchy returning the first ancestor that passes the - * matcher function. - * @param {Node} element The DOM node to start with. - * @param {function(Node) : boolean} matcher A function that returns true if the - * passed node matches the desired criteria. - * @param {boolean=} opt_includeNode If true, the node itself is included in - * the search (the first call to the matcher will pass startElement as - * the node to test). - * @param {number=} opt_maxSearchSteps Maximum number of levels to search up the - * dom. - * @return {Node} DOM node that matched the matcher, or null if there was - * no match. - */ -goog.dom.getAncestor = function( - element, matcher, opt_includeNode, opt_maxSearchSteps) { - if (!opt_includeNode) { - element = element.parentNode; - } - var ignoreSearchSteps = opt_maxSearchSteps == null; - var steps = 0; - while (element && (ignoreSearchSteps || steps <= opt_maxSearchSteps)) { - if (matcher(element)) { - return element; - } - element = element.parentNode; - steps++; - } - // Reached the root of the DOM without a match - return null; -}; - - -/** - * Determines the active element in the given document. - * @param {Document} doc The document to look in. - * @return {Element} The active element. - */ -goog.dom.getActiveElement = function(doc) { - try { - return doc && doc.activeElement; - } catch (e) { - // NOTE(nicksantos): Sometimes, evaluating document.activeElement in IE - // throws an exception. I'm not 100% sure why, but I suspect it chokes - // on document.activeElement if the activeElement has been recently - // removed from the DOM by a JS operation. - // - // We assume that an exception here simply means - // "there is no active element." - } - - return null; -}; - - - -/** - * Create an instance of a DOM helper with a new document object. - * @param {Document=} opt_document Document object to associate with this - * DOM helper. - * @constructor - */ -goog.dom.DomHelper = function(opt_document) { - /** - * Reference to the document object to use - * @type {!Document} - * @private - */ - this.document_ = opt_document || goog.global.document || document; -}; - - -/** - * Gets the dom helper object for the document where the element resides. - * @param {Node=} opt_node If present, gets the DomHelper for this node. - * @return {!goog.dom.DomHelper} The DomHelper. - */ -goog.dom.DomHelper.prototype.getDomHelper = goog.dom.getDomHelper; - - -/** - * Sets the document object. - * @param {!Document} document Document object. - */ -goog.dom.DomHelper.prototype.setDocument = function(document) { - this.document_ = document; -}; - - -/** - * Gets the document object being used by the dom library. - * @return {!Document} Document object. - */ -goog.dom.DomHelper.prototype.getDocument = function() { - return this.document_; -}; - - -/** - * Alias for {@code getElementById}. If a DOM node is passed in then we just - * return that. - * @param {string|Element} element Element ID or a DOM node. - * @return {Element} The element with the given ID, or the node passed in. - */ -goog.dom.DomHelper.prototype.getElement = function(element) { - if (goog.isString(element)) { - return this.document_.getElementById(element); - } else { - return element; - } -}; - - -/** - * Alias for {@code getElement}. - * @param {string|Element} element Element ID or a DOM node. - * @return {Element} The element with the given ID, or the node passed in. - * @deprecated Use {@link goog.dom.DomHelper.prototype.getElement} instead. - */ -goog.dom.DomHelper.prototype.$ = goog.dom.DomHelper.prototype.getElement; - - -/** - * Looks up elements by both tag and class name, using browser native functions - * ({@code querySelectorAll}, {@code getElementsByTagName} or - * {@code getElementsByClassName}) where possible. The returned array is a live - * NodeList or a static list depending on the code path taken. - * - * @see goog.dom.query - * - * @param {?string=} opt_tag Element tag name or * for all tags. - * @param {?string=} opt_class Optional class name. - * @param {Document|Element=} opt_el Optional element to look in. - * @return { {length: number} } Array-like list of elements (only a length - * property and numerical indices are guaranteed to exist). - */ -goog.dom.DomHelper.prototype.getElementsByTagNameAndClass = function(opt_tag, - opt_class, - opt_el) { - return goog.dom.getElementsByTagNameAndClass_(this.document_, opt_tag, - opt_class, opt_el); -}; - - -/** - * Returns an array of all the elements with the provided className. - * @see {goog.dom.query} - * @param {string} className the name of the class to look for. - * @param {Element|Document=} opt_el Optional element to look in. - * @return { {length: number} } The items found with the class name provided. - */ -goog.dom.DomHelper.prototype.getElementsByClass = function(className, opt_el) { - var doc = opt_el || this.document_; - return goog.dom.getElementsByClass(className, doc); -}; - - -/** - * Returns the first element we find matching the provided class name. - * @see {goog.dom.query} - * @param {string} className the name of the class to look for. - * @param {Element|Document=} opt_el Optional element to look in. - * @return {Element} The first item found with the class name provided. - */ -goog.dom.DomHelper.prototype.getElementByClass = function(className, opt_el) { - var doc = opt_el || this.document_; - return goog.dom.getElementByClass(className, doc); -}; - - -/** - * Alias for {@code getElementsByTagNameAndClass}. - * @deprecated Use DomHelper getElementsByTagNameAndClass. - * @see goog.dom.query - * - * @param {?string=} opt_tag Element tag name. - * @param {?string=} opt_class Optional class name. - * @param {Element=} opt_el Optional element to look in. - * @return { {length: number} } Array-like list of elements (only a length - * property and numerical indices are guaranteed to exist). - */ -goog.dom.DomHelper.prototype.$$ = - goog.dom.DomHelper.prototype.getElementsByTagNameAndClass; - - -/** - * Sets a number of properties on a node. - * @param {Element} element DOM node to set properties on. - * @param {Object} properties Hash of property:value pairs. - */ -goog.dom.DomHelper.prototype.setProperties = goog.dom.setProperties; - - -/** - * Gets the dimensions of the viewport. - * @param {Window=} opt_window Optional window element to test. Defaults to - * the window of the Dom Helper. - * @return {!goog.math.Size} Object with values 'width' and 'height'. - */ -goog.dom.DomHelper.prototype.getViewportSize = function(opt_window) { - // TODO(arv): This should not take an argument. That breaks the rule of a - // a DomHelper representing a single frame/window/document. - return goog.dom.getViewportSize(opt_window || this.getWindow()); -}; - - -/** - * Calculates the height of the document. - * - * @return {number} The height of the document. - */ -goog.dom.DomHelper.prototype.getDocumentHeight = function() { - return goog.dom.getDocumentHeight_(this.getWindow()); -}; - - -/** - * Typedef for use with goog.dom.createDom and goog.dom.append. - * @typedef {Object|string|Array|NodeList} - */ -goog.dom.Appendable; - - -/** - * Returns a dom node with a set of attributes. This function accepts varargs - * for subsequent nodes to be added. Subsequent nodes will be added to the - * first node as childNodes. - * - * So: - * <code>createDom('div', null, createDom('p'), createDom('p'));</code> - * would return a div with two child paragraphs - * - * An easy way to move all child nodes of an existing element to a new parent - * element is: - * <code>createDom('div', null, oldElement.childNodes);</code> - * which will remove all child nodes from the old element and add them as - * child nodes of the new DIV. - * - * @param {string} tagName Tag to create. - * @param {Object|string=} opt_attributes If object, then a map of name-value - * pairs for attributes. If a string, then this is the className of the new - * element. - * @param {...goog.dom.Appendable} var_args Further DOM nodes or - * strings for text nodes. If one of the var_args is an array or - * NodeList, its elements will be added as childNodes instead. - * @return {!Element} Reference to a DOM node. - */ -goog.dom.DomHelper.prototype.createDom = function(tagName, - opt_attributes, - var_args) { - return goog.dom.createDom_(this.document_, arguments); -}; - - -/** - * Alias for {@code createDom}. - * @param {string} tagName Tag to create. - * @param {Object|string=} opt_attributes If object, then a map of name-value - * pairs for attributes. If a string, then this is the className of the new - * element. - * @param {...goog.dom.Appendable} var_args Further DOM nodes or strings for - * text nodes. If one of the var_args is an array, its children will be - * added as childNodes instead. - * @return {!Element} Reference to a DOM node. - * @deprecated Use {@link goog.dom.DomHelper.prototype.createDom} instead. - */ -goog.dom.DomHelper.prototype.$dom = goog.dom.DomHelper.prototype.createDom; - - -/** - * Creates a new element. - * @param {string} name Tag name. - * @return {!Element} The new element. - */ -goog.dom.DomHelper.prototype.createElement = function(name) { - return this.document_.createElement(name); -}; - - -/** - * Creates a new text node. - * @param {string} content Content. - * @return {!Text} The new text node. - */ -goog.dom.DomHelper.prototype.createTextNode = function(content) { - return this.document_.createTextNode(content); -}; - - -/** - * Create a table. - * @param {number} rows The number of rows in the table. Must be >= 1. - * @param {number} columns The number of columns in the table. Must be >= 1. - * @param {boolean=} opt_fillWithNbsp If true, fills table entries with nsbps. - * @return {!Element} The created table. - */ -goog.dom.DomHelper.prototype.createTable = function(rows, columns, - opt_fillWithNbsp) { - return goog.dom.createTable_(this.document_, rows, columns, - !!opt_fillWithNbsp); -}; - - -/** - * Converts an HTML string into a node or a document fragment. A single Node - * is used if the {@code htmlString} only generates a single node. If the - * {@code htmlString} generates multiple nodes then these are put inside a - * {@code DocumentFragment}. - * - * @param {string} htmlString The HTML string to convert. - * @return {!Node} The resulting node. - */ -goog.dom.DomHelper.prototype.htmlToDocumentFragment = function(htmlString) { - return goog.dom.htmlToDocumentFragment_(this.document_, htmlString); -}; - - -/** - * Returns the compatMode of the document. - * @return {string} The result is either CSS1Compat or BackCompat. - * @deprecated use goog.dom.DomHelper.prototype.isCss1CompatMode instead. - */ -goog.dom.DomHelper.prototype.getCompatMode = function() { - return this.isCss1CompatMode() ? 'CSS1Compat' : 'BackCompat'; -}; - - -/** - * Returns true if the browser is in "CSS1-compatible" (standards-compliant) - * mode, false otherwise. - * @return {boolean} True if in CSS1-compatible mode. - */ -goog.dom.DomHelper.prototype.isCss1CompatMode = function() { - return goog.dom.isCss1CompatMode_(this.document_); -}; - - -/** - * Gets the window object associated with the document. - * @return {!Window} The window associated with the given document. - */ -goog.dom.DomHelper.prototype.getWindow = function() { - return goog.dom.getWindow_(this.document_); -}; - - -/** - * Gets the document scroll element. - * @return {Element} Scrolling element. - */ -goog.dom.DomHelper.prototype.getDocumentScrollElement = function() { - return goog.dom.getDocumentScrollElement_(this.document_); -}; - - -/** - * Gets the document scroll distance as a coordinate object. - * @return {!goog.math.Coordinate} Object with properties 'x' and 'y'. - */ -goog.dom.DomHelper.prototype.getDocumentScroll = function() { - return goog.dom.getDocumentScroll_(this.document_); -}; - - -/** - * Appends a child to a node. - * @param {Node} parent Parent. - * @param {Node} child Child. - */ -goog.dom.DomHelper.prototype.appendChild = goog.dom.appendChild; - - -/** - * Appends a node with text or other nodes. - * @param {!Node} parent The node to append nodes to. - * @param {...goog.dom.Appendable} var_args The things to append to the node. - * If this is a Node it is appended as is. - * If this is a string then a text node is appended. - * If this is an array like object then fields 0 to length - 1 are appended. - */ -goog.dom.DomHelper.prototype.append = goog.dom.append; - - -/** - * Removes all the child nodes on a DOM node. - * @param {Node} node Node to remove children from. - */ -goog.dom.DomHelper.prototype.removeChildren = goog.dom.removeChildren; - - -/** - * Inserts a new node before an existing reference node (i.e., as the previous - * sibling). If the reference node has no parent, then does nothing. - * @param {Node} newNode Node to insert. - * @param {Node} refNode Reference node to insert before. - */ -goog.dom.DomHelper.prototype.insertSiblingBefore = goog.dom.insertSiblingBefore; - - -/** - * Inserts a new node after an existing reference node (i.e., as the next - * sibling). If the reference node has no parent, then does nothing. - * @param {Node} newNode Node to insert. - * @param {Node} refNode Reference node to insert after. - */ -goog.dom.DomHelper.prototype.insertSiblingAfter = goog.dom.insertSiblingAfter; - - -/** - * Removes a node from its parent. - * @param {Node} node The node to remove. - * @return {Node} The node removed if removed; else, null. - */ -goog.dom.DomHelper.prototype.removeNode = goog.dom.removeNode; - - -/** - * Replaces a node in the DOM tree. Will do nothing if {@code oldNode} has no - * parent. - * @param {Node} newNode Node to insert. - * @param {Node} oldNode Node to replace. - */ -goog.dom.DomHelper.prototype.replaceNode = goog.dom.replaceNode; - - -/** - * Flattens an element. That is, removes it and replace it with its children. - * @param {Element} element The element to flatten. - * @return {Element|undefined} The original element, detached from the document - * tree, sans children, or undefined if the element was already not in the - * document. - */ -goog.dom.DomHelper.prototype.flattenElement = goog.dom.flattenElement; - - -/** - * Returns the first child node that is an element. - * @param {Node} node The node to get the first child element of. - * @return {Element} The first child node of {@code node} that is an element. - */ -goog.dom.DomHelper.prototype.getFirstElementChild = - goog.dom.getFirstElementChild; - - -/** - * Returns the last child node that is an element. - * @param {Node} node The node to get the last child element of. - * @return {Element} The last child node of {@code node} that is an element. - */ -goog.dom.DomHelper.prototype.getLastElementChild = goog.dom.getLastElementChild; - - -/** - * Returns the first next sibling that is an element. - * @param {Node} node The node to get the next sibling element of. - * @return {Element} The next sibling of {@code node} that is an element. - */ -goog.dom.DomHelper.prototype.getNextElementSibling = - goog.dom.getNextElementSibling; - - -/** - * Returns the first previous sibling that is an element. - * @param {Node} node The node to get the previous sibling element of. - * @return {Element} The first previous sibling of {@code node} that is - * an element. - */ -goog.dom.DomHelper.prototype.getPreviousElementSibling = - goog.dom.getPreviousElementSibling; - - -/** - * Returns the next node in source order from the given node. - * @param {Node} node The node. - * @return {Node} The next node in the DOM tree, or null if this was the last - * node. - */ -goog.dom.DomHelper.prototype.getNextNode = - goog.dom.getNextNode; - - -/** - * Returns the previous node in source order from the given node. - * @param {Node} node The node. - * @return {Node} The previous node in the DOM tree, or null if this was the - * first node. - */ -goog.dom.DomHelper.prototype.getPreviousNode = - goog.dom.getPreviousNode; - - -/** - * Whether the object looks like a DOM node. - * @param {*} obj The object being tested for node likeness. - * @return {boolean} Whether the object looks like a DOM node. - */ -goog.dom.DomHelper.prototype.isNodeLike = goog.dom.isNodeLike; - - -/** - * Whether a node contains another node. - * @param {Node} parent The node that should contain the other node. - * @param {Node} descendant The node to test presence of. - * @return {boolean} Whether the parent node contains the descendent node. - */ -goog.dom.DomHelper.prototype.contains = goog.dom.contains; - - -/** - * Returns the owner document for a node. - * @param {Node} node The node to get the document for. - * @return {!Document} The document owning the node. - */ -goog.dom.DomHelper.prototype.getOwnerDocument = goog.dom.getOwnerDocument; - - -/** - * Cross browser function for getting the document element of an iframe. - * @param {HTMLIFrameElement|HTMLFrameElement} iframe Iframe element. - * @return {!HTMLDocument} The frame content document. - */ -goog.dom.DomHelper.prototype.getFrameContentDocument = - goog.dom.getFrameContentDocument; - - -/** - * Cross browser function for getting the window of a frame or iframe. - * @param {HTMLIFrameElement|HTMLFrameElement} frame Frame element. - * @return {Window} The window associated with the given frame. - */ -goog.dom.DomHelper.prototype.getFrameContentWindow = - goog.dom.getFrameContentWindow; - - -/** - * Cross browser function for setting the text content of an element. - * @param {Element} element The element to change the text content of. - * @param {string} text The string that should replace the current element - * content with. - */ -goog.dom.DomHelper.prototype.setTextContent = goog.dom.setTextContent; - - -/** - * Finds the first descendant node that matches the filter function. This does - * a depth first search. - * @param {Node} root The root of the tree to search. - * @param {function(Node) : boolean} p The filter function. - * @return {(Node, undefined)} The found node or undefined if none is found. - */ -goog.dom.DomHelper.prototype.findNode = goog.dom.findNode; - - -/** - * Finds all the descendant nodes that matches the filter function. This does a - * depth first search. - * @param {Node} root The root of the tree to search. - * @param {function(Node) : boolean} p The filter function. - * @return {Array.<Node>} The found nodes or an empty array if none are found. - */ -goog.dom.DomHelper.prototype.findNodes = goog.dom.findNodes; - - -/** - * Returns the text contents of the current node, without markup. New lines are - * stripped and whitespace is collapsed, such that each character would be - * visible. - * - * In browsers that support it, innerText is used. Other browsers attempt to - * simulate it via node traversal. Line breaks are canonicalized in IE. - * - * @param {Node} node The node from which we are getting content. - * @return {string} The text content. - */ -goog.dom.DomHelper.prototype.getTextContent = goog.dom.getTextContent; - - -/** - * Returns the text length of the text contained in a node, without markup. This - * is equivalent to the selection length if the node was selected, or the number - * of cursor movements to traverse the node. Images & BRs take one space. New - * lines are ignored. - * - * @param {Node} node The node whose text content length is being calculated. - * @return {number} The length of {@code node}'s text content. - */ -goog.dom.DomHelper.prototype.getNodeTextLength = goog.dom.getNodeTextLength; - - -/** - * Returns the text offset of a node relative to one of its ancestors. The text - * length is the same as the length calculated by - * {@code goog.dom.getNodeTextLength}. - * - * @param {Node} node The node whose offset is being calculated. - * @param {Node=} opt_offsetParent Defaults to the node's owner document's body. - * @return {number} The text offset. - */ -goog.dom.DomHelper.prototype.getNodeTextOffset = goog.dom.getNodeTextOffset; - - -/** - * Walks up the DOM hierarchy returning the first ancestor that has the passed - * tag name and/or class name. If the passed element matches the specified - * criteria, the element itself is returned. - * @param {Node} element The DOM node to start with. - * @param {?string=} opt_tag The tag name to match (or null/undefined to match - * any node regardless of tag name). Must be uppercase (goog.dom.TagName). - * @param {?string=} opt_class The class name to match (or null/undefined to - * match any node regardless of class name). - * @return {Node} The first ancestor that matches the passed criteria, or - * null if none match. - */ -goog.dom.DomHelper.prototype.getAncestorByTagNameAndClass = - goog.dom.getAncestorByTagNameAndClass; - - -/** - * Walks up the DOM hierarchy returning the first ancestor that has the passed - * class name. If the passed element matches the specified criteria, the - * element itself is returned. - * @param {Node} element The DOM node to start with. - * @param {?string=} opt_class The class name to match (or null/undefined to - * match any node regardless of class name). - * @return {Node} The first ancestor that matches the passed criteria, or - * null if none match. - */ -goog.dom.DomHelper.prototype.getAncestorByClass = - goog.dom.getAncestorByClass; - - -/** - * Walks up the DOM hierarchy returning the first ancestor that passes the - * matcher function. - * @param {Node} element The DOM node to start with. - * @param {function(Node) : boolean} matcher A function that returns true if the - * passed node matches the desired criteria. - * @param {boolean=} opt_includeNode If true, the node itself is included in - * the search (the first call to the matcher will pass startElement as - * the node to test). - * @param {number=} opt_maxSearchSteps Maximum number of levels to search up the - * dom. - * @return {Node} DOM node that matched the matcher, or null if there was - * no match. - */ -goog.dom.DomHelper.prototype.getAncestor = goog.dom.getAncestor; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_quirks_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_quirks_test.html.svn-base deleted file mode 100644 index 523179b..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_quirks_test.html.svn-base +++ /dev/null @@ -1,108 +0,0 @@ -<html> -<!-- -Copyright 2006 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- - - This is a copy of dom_test.html but without a doctype. Make sure these two - are in sync. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom</title> -<script src="../base.js"></script> -<script> - goog.require('goog.array'); - goog.require('goog.dom'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -<style type="text/css"> -#styleTest1 { - width:120px;font-weight:bold; -} -</style> -</head> -<body> - <div> - abc <i>def</i> <s id="offsetParent1">g <b>h <i id="offsetTest1">ij</i> kl</b> mn</s> opq - </div> - - - <div id="testEl"> - <span>Test Element</span> - </div> - - <div><div><div id="testEl2"></div></div></div> - - <!-- classbefore and classafter are for making sure that getElementsByClass - works when multiple classes are specified. --> - <div id="span-container"> - <span id="span1" class="classbefore test1"></span> - <span id="span2" class="test1"></span> - <span id="span3" class="test2"></span> - <span id="span4" class="test3"></span> - <span id="span5" class="test1 classafter"></span> - </div> - - <div class="mixedCaseClass"></div> - - <p id="p1"></p> - - <div id="styleTest1"></div> - <div id="styleTest2" style="width:100px;font-weight:bold"></div> - <div id="styleTest3"></div> - - <!-- Paragraph to test element child and sibling --> - <p id="p2"> - <!-- Comment --> - a - <b id="b1">c</b> - d - <!-- Comment --> - e - <b id="b2">f</b> - g - <!-- Comment --> - </p> - - <table id="testTable1"> - <tr> - <td> - </tr> - </table> - - <iframe name="frame" src="tagname_test.html"></iframe> - - <p id="order-test"></p> - - <div id="testAncestorDiv" class="ancestorClassA testAncestor"> - <p id="testAncestorP" class="ancestorClassB testAncestor"> - <b id="nestedElement">ancestorTest</b> - </p> - </div> - - <div id="noTabIndex">Test</div> - <div id="tabIndexNegative2" tabindex="-2">Test</div> - <div id="tabIndexNegative1" tabindex="-1">Test</div> - <div id="tabIndex0" tabindex="0">Test</div> - <div id="tabIndex1" tabindex="1">Test</div> - <div id="tabIndex2" tabindex="2">Test</div> - - <div id="toReplace">Replace Test</div> - - <iframe id="iframe"></iframe> - - <div id="myIframeDiv1" style="height:42px;font-size:1px;line-height:0;">hello world</div> - <div id="myIframeDiv2" style="height:23px;font-size:1px;line-height:0;">hello world</div> - - <iframe id="myIframe" style="width:400px;height:200px;"></iframe> - - <a id='link' href='foo.html'>Foo</a> - -<script src="dom_test.js"></script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_test.html.svn-base deleted file mode 100644 index d55c850..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_test.html.svn-base +++ /dev/null @@ -1,107 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2006 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- - - When changing this, make sure that dom_quirks_test.html is kept in sync. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom</title> -<script src="../base.js"></script> -<script> - goog.require('goog.array'); - goog.require('goog.dom'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -<style type="text/css"> -#styleTest1 { - width:120px;font-weight:bold; -} -</style> -</head> -<body> - <div> - abc <i>def</i> <s id="offsetParent1">g <b>h <i id="offsetTest1">ij</i> kl</b> mn</s> opq - </div> - - - <div id="testEl"> - <span>Test Element</span> - </div> - - <div><div><div id="testEl2"></div></div></div> - - <!-- classbefore and classafter are for making sure that getElementsByClass - works when multiple classes are specified. --> - <div id="span-container"> - <span id="span1" class="classbefore test1"></span> - <span id="span2" class="test1"></span> - <span id="span3" class="test2"></span> - <span id="span4" class="test3"></span> - <span id="span5" class="test1 classafter"></span> - </div> - - <div class="mixedCaseClass"></div> - - <p id="p1"></p> - - <div id="styleTest1"></div> - <div id="styleTest2" style="width:100px;font-weight:bold"></div> - <div id="styleTest3"></div> - - <!-- Paragraph to test element child and sibling --> - <p id="p2"> - <!-- Comment --> - a - <b id="b1">c</b> - d - <!-- Comment --> - e - <b id="b2">f</b> - g - <!-- Comment --> - </p> - - <table id="testTable1"> - <tr> - <td> - </tr> - </table> - - <iframe name="frame" src="tagname_test.html"></iframe> - - <p id="order-test"></p> - - <div id="testAncestorDiv" class="ancestorClassA testAncestor"> - <p id="testAncestorP" class="ancestorClassB testAncestor"> - <b id="nestedElement">ancestorTest</b> - </p> - </div> - - <div id="noTabIndex">Test</div> - <div id="tabIndexNegative2" tabindex="-2">Test</div> - <div id="tabIndexNegative1" tabindex="-1">Test</div> - <div id="tabIndex0" tabindex="0">Test</div> - <div id="tabIndex1" tabindex="1">Test</div> - <div id="tabIndex2" tabindex="2">Test</div> - - <div id="toReplace">Replace Test</div> - - <iframe id="iframe"></iframe> - - <div id="myIframeDiv1" style="height:42px;font-size:1px;line-height:0;">hello world</div> - <div id="myIframeDiv2" style="height:23px;font-size:1px;line-height:0;">hello world</div> - - <iframe id="myIframe" style="width:400px;height:200px;"></iframe> - - <a id='link' href='foo.html'>Foo</a> - -<script src="dom_test.js"></script></body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_test.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_test.js.svn-base deleted file mode 100644 index 614ff12..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/dom_test.js.svn-base +++ /dev/null @@ -1,1349 +0,0 @@ -// Copyright 2009 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Shared code for dom_test.html and dom_quirks_test.html. - */ - -goog.provide('goog.dom.dom_test'); - -goog.require('goog.dom'); -goog.require('goog.dom.DomHelper'); -goog.require('goog.dom.NodeType'); -goog.require('goog.dom.TagName'); -goog.require('goog.testing.asserts'); -goog.require('goog.userAgent'); -goog.require('goog.userAgent.product'); -goog.require('goog.userAgent.product.isVersion'); - -goog.setTestOnly('dom_test'); - -var $ = goog.dom.getElement; - -var divForTestingScrolling; -var myIframe; -var myIframeDoc; - -function setUpPage() { - divForTestingScrolling = document.createElement('div'); - divForTestingScrolling.style.width = '5000px'; - divForTestingScrolling.style.height = '5000px'; - document.body.appendChild(divForTestingScrolling); - - // Setup for the iframe - myIframe = $('myIframe'); - myIframeDoc = goog.dom.getFrameContentDocument( - /** @type {HTMLIFrameElement} */ (myIframe)); - - // Set up document for iframe: total height of elements in document is 65 - // If the elements are not create like below, IE will get a wrong height for - // the document. - myIframeDoc.open(); - // Make sure we progate the compat mode - myIframeDoc.write((goog.dom.isCss1CompatMode() ? '<!DOCTYPE html>' : '') + - '<style>body{margin:0;padding:0}</style>' + - '<div style="height:42px;font-size:1px;line-height:0;">' + - 'hello world</div>' + - '<div style="height:23px;font-size:1px;line-height:0;">' + - 'hello world</div>'); - myIframeDoc.close(); -} - -function tearDownPage() { - document.body.removeChild(divForTestingScrolling); -} - -function tearDown() { - window.scrollTo(0, 0); -} - -function testDom() { - assert('Dom library exists', typeof goog.dom != 'undefined'); -} - -function testGetElement() { - var el = $('testEl'); - assertEquals('Should be able to get id', el.id, 'testEl'); - - assertEquals($, goog.dom.getElement); - assertEquals(goog.dom.$, goog.dom.getElement); -} - -function testGetElementsByTagNameAndClass() { - assertEquals('Should get 6 spans', - goog.dom.getElementsByTagNameAndClass('span').length, 6); - assertEquals('Should get 6 spans', - goog.dom.getElementsByTagNameAndClass('SPAN').length, 6); - assertEquals('Should get 3 spans', - goog.dom.getElementsByTagNameAndClass('span', 'test1').length, 3); - assertEquals('Should get 1 span', - goog.dom.getElementsByTagNameAndClass('span', 'test2').length, 1); - assertEquals('Should get 1 span', - goog.dom.getElementsByTagNameAndClass('SPAN', 'test2').length, 1); - assertEquals('Should get lots of elements', - goog.dom.getElementsByTagNameAndClass().length, - document.getElementsByTagName('*').length); - - assertEquals('Should get 1 span', - goog.dom.getElementsByTagNameAndClass('span', null, $('testEl')).length, - 1); - - // '*' as the tag name should be equivalent to all tags - var container = goog.dom.getElement('span-container'); - assertEquals(5, - goog.dom.getElementsByTagNameAndClass('*', undefined, container).length); - assertEquals(3, - goog.dom.getElementsByTagNameAndClass('*', 'test1', container).length); - assertEquals(1, - goog.dom.getElementsByTagNameAndClass('*', 'test2', container).length); - - // Some version of WebKit have problems with mixed-case class names - assertEquals(1, - goog.dom.getElementsByTagNameAndClass( - undefined, 'mixedCaseClass').length); - - // Make sure that out of bounds indices are OK - assertUndefined( - goog.dom.getElementsByTagNameAndClass(undefined, 'noSuchClass')[0]); - - assertEquals(goog.dom.getElementsByTagNameAndClass, - goog.dom.getElementsByTagNameAndClass); -} - -function testGetElementsByClass() { - assertEquals(3, goog.dom.getElementsByClass('test1').length); - assertEquals(1, goog.dom.getElementsByClass('test2').length); - assertEquals(0, goog.dom.getElementsByClass('nonexistant').length); - - var container = goog.dom.getElement('span-container'); - assertEquals(3, goog.dom.getElementsByClass('test1', container).length); -} - -function testGetElementByClass() { - assertNotNull(goog.dom.getElementByClass('test1')); - assertNotNull(goog.dom.getElementByClass('test2')); - // assertNull(goog.dom.getElementByClass('nonexistant')); - - var container = goog.dom.getElement('span-container'); - assertNotNull(goog.dom.getElementByClass('test1', container)); -} - -function testSetProperties() { - var attrs = { 'name': 'test3', 'title': 'A title', 'random': 'woop' }; - var el = $('testEl'); - - var res = goog.dom.setProperties(el, attrs); - assertEquals('Should be equal', el.name, 'test3'); - assertEquals('Should be equal', el.title, 'A title'); - assertEquals('Should be equal', el.random, 'woop'); -} - -function testSetPropertiesDirectAttributeMap() { - var attrs = {'usemap': '#myMap'}; - var el = goog.dom.createDom('img'); - - var res = goog.dom.setProperties(el, attrs); - assertEquals('Should be equal', '#myMap', el.getAttribute('usemap')); -} - -function testSetPropertiesAria() { - var attrs = { - 'aria-hidden': 'true', - 'aria-label': 'This is a label' - }; - var el = goog.dom.createDom('div'); - - goog.dom.setProperties(el, attrs); - assertEquals('Should be equal', 'true', el.getAttribute('aria-hidden')); - assertEquals('Should be equal', - 'This is a label', el.getAttribute('aria-label')); -} - -function testSetTableProperties() { - var attrs = { - 'style': 'padding-left: 10px;', - 'class': 'mytestclass', - 'height': '101', - 'cellpadding': '15' - }; - var el = $('testTable1'); - - var res = goog.dom.setProperties(el, attrs); - assertEquals('Should be equal', el.style.paddingLeft, '10px'); - assertEquals('Should be equal', el.className, 'mytestclass'); - assertEquals('Should be equal', el.getAttribute('height'), '101'); - assertEquals('Should be equal', el.cellPadding, '15'); -} - -function testGetViewportSize() { - // TODO: This is failing in the test runner now, fix later. - //var dims = getViewportSize(); - //assertNotUndefined('Should be defined at least', dims.width); - //assertNotUndefined('Should be defined at least', dims.height); -} - -function testGetViewportSizeInIframe() { - var iframe = /** @type {HTMLIFrameElement} */ (goog.dom.getElement('iframe')); - var contentDoc = goog.dom.getFrameContentDocument(iframe); - contentDoc.write('<body></body>'); - - var outerSize = goog.dom.getViewportSize(); - var innerSize = (new goog.dom.DomHelper(contentDoc)).getViewportSize(); - assert('Viewport sizes must not match', - innerSize.width != outerSize.width); -} - -function testGetDocumentHeightInIframe() { - var doc = goog.dom.getDomHelper(myIframeDoc).getDocument(); - var height = goog.dom.getDomHelper(myIframeDoc).getDocumentHeight(); - - // Broken in webkit quirks mode and in IE8+ - if ((goog.dom.isCss1CompatMode_(doc) || !goog.userAgent.WEBKIT) && - !isIE8OrHigher()) { - assertEquals('height should be 65', 42 + 23, height); - } -} - -function testCreateDom() { - var el = goog.dom.$dom('div', - { - style: 'border: 1px solid black; width: 50%; background-color: #EEE;', - onclick: "alert('woo')" - }, - goog.dom.$dom('p', {style: 'font: normal 12px arial; color: red; '}, - 'Para 1'), - goog.dom.$dom('p', {style: 'font: bold 18px garamond; color: blue; '}, - 'Para 2'), - goog.dom.$dom('p', {style: 'font: normal 24px monospace; color: green'}, - 'Para 3 ', - goog.dom.$dom('a', { - name: 'link', href: 'http://bbc.co.uk' - }, - 'has a link'), - ', how cool is this?')); - - assertEquals('Tagname should be a DIV', 'DIV', el.tagName); - assertEquals('Style width should be 50%', '50%', el.style.width); - assertEquals('first child is a P tag', 'P', el.childNodes[0].tagName); - assertEquals('second child .innerHTML', 'Para 2', - el.childNodes[1].innerHTML); - - assertEquals(goog.dom.$dom, goog.dom.createDom); -} - -function testCreateDomNoChildren() { - var el; - - // Test unspecified children. - el = goog.dom.$dom('div'); - assertNull('firstChild should be null', el.firstChild); - - // Test null children. - el = goog.dom.$dom('div', null, null); - assertNull('firstChild should be null', el.firstChild); - - // Test empty array of children. - el = goog.dom.$dom('div', null, []); - assertNull('firstChild should be null', el.firstChild); -} - -function testCreateDomAcceptsArray() { - var items = [ - goog.dom.$dom('li', {}, 'Item 1'), - goog.dom.$dom('li', {}, 'Item 2') - ]; - var ul = goog.dom.$dom('ul', {}, items); - assertEquals('List should have two children', 2, ul.childNodes.length); - assertEquals('First child should be an LI tag', - 'LI', ul.firstChild.tagName); - assertEquals('Item 1', ul.childNodes[0].innerHTML); - assertEquals('Item 2', ul.childNodes[1].innerHTML); -} - -function testCreateDomStringArg() { - var el; - - // Test string arg. - el = goog.dom.$dom('div', null, 'Hello'); - assertEquals('firstChild should be a text node', goog.dom.NodeType.TEXT, - el.firstChild.nodeType); - assertEquals('firstChild should have node value "Hello"', 'Hello', - el.firstChild.nodeValue); - - // Test text node arg. - el = goog.dom.$dom('div', null, goog.dom.createTextNode('World')); - assertEquals('firstChild should be a text node', goog.dom.NodeType.TEXT, - el.firstChild.nodeType); - assertEquals('firstChild should have node value "World"', 'World', - el.firstChild.nodeValue); -} - -function testCreateDomNodeListArg() { - var el; - var emptyElem = goog.dom.$dom('div'); - var simpleElem = goog.dom.$dom('div', null, 'Hello, world!'); - var complexElem = goog.dom.$dom('div', null, 'Hello, ', - goog.dom.$dom('b', null, 'world'), - goog.dom.createTextNode('!')); - - // Test empty node list. - el = goog.dom.$dom('div', null, emptyElem.childNodes); - assertNull('emptyElem.firstChild should be null', emptyElem.firstChild); - assertNull('firstChild should be null', el.firstChild); - - // Test simple node list. - el = goog.dom.$dom('div', null, simpleElem.childNodes); - assertNull('simpleElem.firstChild should be null', simpleElem.firstChild); - assertEquals('firstChild should be a text node with value "Hello, world!"', - 'Hello, world!', el.firstChild.nodeValue); - - // Test complex node list. - el = goog.dom.$dom('div', null, complexElem.childNodes); - assertNull('complexElem.firstChild should be null', complexElem.firstChild); - assertEquals('Element should have 3 child nodes', 3, el.childNodes.length); - assertEquals('childNodes[0] should be a text node with value "Hello, "', - 'Hello, ', el.childNodes[0].nodeValue); - assertEquals('childNodes[1] should be an element node with tagName "B"', - 'B', el.childNodes[1].tagName); - assertEquals('childNodes[2] should be a text node with value "!"', '!', - el.childNodes[2].nodeValue); -} - -function testCreateDomWithTypeAttribute() { - var el = goog.dom.createDom('button', {'type': 'reset', 'id': 'cool-button'}, - 'Cool button'); - assertNotNull('Button with type attribute was created successfully', el); - assertEquals('Button has correct type attribute', 'reset', el.type); - assertEquals('Button has correct id', 'cool-button', el.id); -} - -function testCreateDomWithClassList() { - var el = goog.dom.createDom('div', ['foo', 'bar']); - assertEquals('foo bar', el.className); - - el = goog.dom.createDom('div', ['foo', 'foo']); - assertEquals('foo', el.className); -} - -function testContains() { - assertTrue('HTML should contain BODY', goog.dom.contains( - document.documentElement, document.body)); - assertTrue('Document should contain BODY', goog.dom.contains( - document, document.body)); - - var d = goog.dom.$dom('p', null, 'A paragraph'); - var t = d.firstChild; - assertTrue('Same element', goog.dom.contains(d, d)); - assertTrue('Same text', goog.dom.contains(t, t)); - assertTrue('Nested text', goog.dom.contains(d, t)); - assertFalse('Nested text, reversed', goog.dom.contains(t, d)); - assertFalse('Disconnected element', goog.dom.contains( - document, d)); - goog.dom.appendChild(document.body, d); - assertTrue('Connected element', goog.dom.contains( - document, d)); - goog.dom.removeNode(d); -} - -function testCreateDomWithClassName() { - var el = goog.dom.$dom('div', 'cls'); - assertNull('firstChild should be null', el.firstChild); - assertEquals('Tagname should be a DIV', 'DIV', el.tagName); - assertEquals('ClassName should be cls', 'cls', el.className); - - el = goog.dom.$dom('div', ''); - assertEquals('ClassName should be empty', '', el.className); -} - -function testCompareNodeOrder() { - var b1 = $('b1'); - var b2 = $('b2'); - var p2 = $('p2'); - - assertEquals('equal nodes should compare to 0', 0, - goog.dom.compareNodeOrder(b1, b1)); - - assertTrue('parent should come before child', - goog.dom.compareNodeOrder(p2, b1) < 0); - assertTrue('child should come after parent', - goog.dom.compareNodeOrder(b1, p2) > 0); - - assertTrue('parent should come before text child', - goog.dom.compareNodeOrder(b1, b1.firstChild) < 0); - assertTrue('text child should come after parent', goog.dom.compareNodeOrder( - b1.firstChild, b1) > 0); - - assertTrue('first sibling should come before second', - goog.dom.compareNodeOrder(b1, b2) < 0); - assertTrue('second sibling should come after first', - goog.dom.compareNodeOrder(b2, b1) > 0); - - assertTrue('text node after cousin element returns correct value', - goog.dom.compareNodeOrder(b1.nextSibling, b1) > 0); - assertTrue('text node before cousin element returns correct value', - goog.dom.compareNodeOrder(b1, b1.nextSibling) < 0); - - assertTrue('text node is before once removed cousin element', - goog.dom.compareNodeOrder(b1.firstChild, b2) < 0); - assertTrue('once removed cousin element is before text node', - goog.dom.compareNodeOrder(b2, b1.firstChild) > 0); - - assertTrue('text node is after once removed cousin text node', - goog.dom.compareNodeOrder(b1.nextSibling, b1.firstChild) > 0); - assertTrue('once removed cousin text node is before text node', - goog.dom.compareNodeOrder(b1.firstChild, b1.nextSibling) < 0); - - assertTrue('first text node is before second text node', - goog.dom.compareNodeOrder(b1.previousSibling, b1.nextSibling) < 0); - assertTrue('second text node is after first text node', - goog.dom.compareNodeOrder(b1.nextSibling, b1.previousSibling) > 0); - - assertTrue('grandchild is after grandparent', - goog.dom.compareNodeOrder(b1.firstChild, b1.parentNode) > 0); - assertTrue('grandparent is after grandchild', - goog.dom.compareNodeOrder(b1.parentNode, b1.firstChild) < 0); - - assertTrue('grandchild is after grandparent', - goog.dom.compareNodeOrder(b1.firstChild, b1.parentNode) > 0); - assertTrue('grandparent is after grandchild', - goog.dom.compareNodeOrder(b1.parentNode, b1.firstChild) < 0); - - assertTrue('second cousins compare correctly', - goog.dom.compareNodeOrder(b1.firstChild, b2.firstChild) < 0); - assertTrue('second cousins compare correctly in reverse', - goog.dom.compareNodeOrder(b2.firstChild, b1.firstChild) > 0); - - assertTrue('testEl2 is after testEl', - goog.dom.compareNodeOrder($('testEl2'), $('testEl')) > 0); - assertTrue('testEl is before testEl2', - goog.dom.compareNodeOrder($('testEl'), $('testEl2')) < 0); - - var p = $('order-test'); - var text1 = document.createTextNode('1'); - p.appendChild(text1); - var text2 = document.createTextNode('1'); - p.appendChild(text2); - - assertEquals('Equal text nodes should compare to 0', 0, - goog.dom.compareNodeOrder(text1, text1)); - assertTrue('First text node is before second', - goog.dom.compareNodeOrder(text1, text2) < 0); - assertTrue('Second text node is after first', - goog.dom.compareNodeOrder(text2, text1) > 0); - assertTrue('Late text node is after b1', - goog.dom.compareNodeOrder(text1, $('b1')) > 0); -} - -function testFindCommonAncestor() { - var b1 = $('b1'); - var b2 = $('b2'); - var p1 = $('p1'); - var p2 = $('p2'); - var testEl2 = $('testEl2'); - - assertNull('findCommonAncestor() = null', goog.dom.findCommonAncestor()); - assertEquals('findCommonAncestor(b1) = b1', b1, - goog.dom.findCommonAncestor(b1)); - assertEquals('findCommonAncestor(b1, b1) = b1', b1, - goog.dom.findCommonAncestor(b1, b1)); - assertEquals('findCommonAncestor(b1, b2) = p2', p2, - goog.dom.findCommonAncestor(b1, b2)); - assertEquals('findCommonAncestor(p1, b2) = body', document.body, - goog.dom.findCommonAncestor(p1, b2)); - assertEquals('findCommonAncestor(testEl2, b1, b2, p1, p2) = body', - document.body, goog.dom.findCommonAncestor(testEl2, b1, b2, p1, p2)); - - var outOfDoc = document.createElement('div'); - assertNull('findCommonAncestor(outOfDoc, b1) = null', - goog.dom.findCommonAncestor(outOfDoc, b1)); -} - -function testRemoveNode() { - var b = document.createElement('b'); - var el = $('p1'); - el.appendChild(b); - goog.dom.removeNode(b); - assertTrue('b should have been removed', el.lastChild != b); -} - -function testReplaceNode() { - var n = $('toReplace'); - var previousSibling = n.previousSibling; - var goodNode = goog.dom.createDom('div', {'id': 'goodReplaceNode'}); - goog.dom.replaceNode(goodNode, n); - - assertEquals('n should have been replaced', previousSibling.nextSibling, - goodNode); - assertNull('n should no longer be in the DOM tree', $('toReplace')); - - var badNode = goog.dom.createDom('div', {'id': 'badReplaceNode'}); - goog.dom.replaceNode(badNode, n); - assertNull('badNode should not be in the DOM tree', $('badReplaceNode')); -} - -function testAppendChildAt() { - var parent = $('p2'); - var origNumChildren = parent.childNodes.length; - - var child1 = document.createElement('div'); - goog.dom.insertChildAt(parent, child1, origNumChildren); - assertEquals(origNumChildren + 1, parent.childNodes.length); - - var child2 = document.createElement('div'); - goog.dom.insertChildAt(parent, child2, origNumChildren + 42); - assertEquals(origNumChildren + 2, parent.childNodes.length); - - var child3 = document.createElement('div'); - goog.dom.insertChildAt(parent, child3, 0); - assertEquals(origNumChildren + 3, parent.childNodes.length); - - var child4 = document.createElement('div'); - goog.dom.insertChildAt(parent, child3, 2); - assertEquals(origNumChildren + 3, parent.childNodes.length); - - parent.removeChild(child1); - parent.removeChild(child2); - parent.removeChild(child3); - - var emptyParentNotInDocument = document.createElement('div'); - goog.dom.insertChildAt(emptyParentNotInDocument, child1, 0); - assertEquals(1, emptyParentNotInDocument.childNodes.length); -} - -function testFlattenElement() { - var text = document.createTextNode('Text'); - var br = document.createElement('br'); - var span = goog.dom.createDom('span', null, text, br); - assertEquals('span should have 2 children', 2, span.childNodes.length); - - var el = $('p1'); - el.appendChild(span); - - var ret = goog.dom.flattenElement(span); - - assertTrue('span should have been removed', el.lastChild != span); - assertFalse('span should have no parent', !!span.parentNode && - span.parentNode.nodeType != goog.dom.NodeType.DOCUMENT_FRAGMENT); - assertEquals('span should have no children', 0, span.childNodes.length); - assertEquals('Last child of p should be br', br, el.lastChild); - assertEquals('Previous sibling of br should be text', text, - br.previousSibling); - - var outOfDoc = goog.dom.createDom('span', null, '1 child'); - // Should do nothing. - goog.dom.flattenElement(outOfDoc); - assertEquals('outOfDoc should still have 1 child', 1, - outOfDoc.childNodes.length); -} - -function testIsNodeLike() { - assertTrue('document should be node like', goog.dom.isNodeLike(document)); - assertTrue('document.body should be node like', - goog.dom.isNodeLike(document.body)); - assertTrue('a text node should be node like', goog.dom.isNodeLike( - document.createTextNode(''))); - - assertFalse('null should not be node like', goog.dom.isNodeLike(null)); - assertFalse('a string should not be node like', goog.dom.isNodeLike('abcd')); - - assertTrue('custom object should be node like', - goog.dom.isNodeLike({nodeType: 1})); -} - -function testIsElement() { - assertFalse('document is not an element', goog.dom.isElement(document)); - assertTrue('document.body is an element', - goog.dom.isElement(document.body)); - assertFalse('a text node is not an element', goog.dom.isElement( - document.createTextNode(''))); - assertTrue('an element created with createElement() is an element', - goog.dom.isElement(document.createElement('a'))); - - assertFalse('null is not an element', goog.dom.isElement(null)); - assertFalse('a string is not an element', goog.dom.isElement('abcd')); - - assertTrue('custom object is an element', - goog.dom.isElement({nodeType: 1})); - assertFalse('custom non-element object is a not an element', - goog.dom.isElement({someProperty: 'somevalue'})); -} - -function testIsWindow() { - var global = goog.global; - var frame = window.frames['frame']; - var otherWindow = window.open('', 'blank'); - var object = {window: goog.global}; - var nullVar = null; - var notDefined; - - try { - // Use try/finally to ensure that we clean up the window we open, even if an - // assertion fails or something else goes wrong. - assertTrue('global object in HTML context should be a window', - goog.dom.isWindow(goog.global)); - assertTrue('iframe window should be a window', goog.dom.isWindow(frame)); - if (otherWindow) { - assertTrue('other window should be a window', - goog.dom.isWindow(otherWindow)); - } - assertFalse('object should not be a window', goog.dom.isWindow(object)); - assertFalse('null should not be a window', goog.dom.isWindow(nullVar)); - assertFalse('undefined should not be a window', - goog.dom.isWindow(notDefined)); - } finally { - if (otherWindow) { - otherWindow.close(); - } - } -} - -function testGetOwnerDocument() { - assertEquals(goog.dom.getOwnerDocument($('p1')), document); - assertEquals(goog.dom.getOwnerDocument(document.body), document); - assertEquals(goog.dom.getOwnerDocument(document.documentElement), document); -} - -function testDomHelper() { - var x = new goog.dom.DomHelper(window.frames['frame'].document); - assertTrue('Should have some HTML', - x.getDocument().body.innerHTML.length > 0); -} - -function testGetFirstElementChild() { - var p2 = $('p2'); - var b1 = goog.dom.getFirstElementChild(p2); - assertNotNull('First element child of p2 should not be null', b1); - assertEquals('First element child is b1', 'b1', b1.id); - - var c = goog.dom.getFirstElementChild(b1); - assertNull('First element child of b1 should be null', c); - - // Test with an undefined firstElementChild attribute. - var b2 = $('b2'); - var mockP2 = { - childNodes: [b1, b2], - firstChild: b1, - firstElementChild: undefined - }; - - b1 = goog.dom.getFirstElementChild(mockP2); - assertNotNull('First element child of mockP2 should not be null', b1); - assertEquals('First element child is b1', 'b1', b1.id); -} - -function testGetLastElementChild() { - var p2 = $('p2'); - var b2 = goog.dom.getLastElementChild(p2); - assertNotNull('Last element child of p2 should not be null', b2); - assertEquals('Last element child is b2', 'b2', b2.id); - - var c = goog.dom.getLastElementChild(b2); - assertNull('Last element child of b2 should be null', c); - - // Test with an undefined lastElementChild attribute. - var b1 = $('b1'); - var mockP2 = { - childNodes: [b1, b2], - lastChild: b2, - lastElementChild: undefined - }; - - b2 = goog.dom.getLastElementChild(mockP2); - assertNotNull('Last element child of mockP2 should not be null', b2); - assertEquals('Last element child is b2', 'b2', b2.id); -} - -function testGetNextElementSibling() { - var b1 = $('b1'); - var b2 = goog.dom.getNextElementSibling(b1); - assertNotNull('Next element sibling of b1 should not be null', b1); - assertEquals('Next element sibling is b2', 'b2', b2.id); - - var c = goog.dom.getNextElementSibling(b2); - assertNull('Next element sibling of b2 should be null', c); - - // Test with an undefined nextElementSibling attribute. - var mockB1 = { - nextSibling: b2, - nextElementSibling: undefined - }; - - b2 = goog.dom.getNextElementSibling(mockB1); - assertNotNull('Next element sibling of mockB1 should not be null', b1); - assertEquals('Next element sibling is b2', 'b2', b2.id); -} - -function testGetPreviousElementSibling() { - var b2 = $('b2'); - var b1 = goog.dom.getPreviousElementSibling(b2); - assertNotNull('Previous element sibling of b2 should not be null', b1); - assertEquals('Previous element sibling is b1', 'b1', b1.id); - - var c = goog.dom.getPreviousElementSibling(b1); - assertNull('Previous element sibling of b1 should be null', c); - - // Test with an undefined previousElementSibling attribute. - var mockB2 = { - previousSibling: b1, - previousElementSibling: undefined - }; - - b1 = goog.dom.getPreviousElementSibling(mockB2); - assertNotNull('Previous element sibling of mockB2 should not be null', b1); - assertEquals('Previous element sibling is b1', 'b1', b1.id); -} - -function testGetChildren() { - var p2 = $('p2'); - var children = goog.dom.getChildren(p2); - assertNotNull('Elements array should not be null', children); - assertEquals('List of element children should be length two.', 2, - children.length); - - var b1 = $('b1'); - var b2 = $('b2'); - assertObjectEquals('First element child should be b1.', b1, children[0]); - assertObjectEquals('Second element child should be b2.', b2, children[1]); - - var noChildren = goog.dom.getChildren(b1); - assertNotNull('Element children array should not be null', noChildren); - assertEquals('List of element children should be length zero.', 0, - noChildren.length); - - // Test with an undefined children attribute. - var mockP2 = { - childNodes: [b1, b2], - children: undefined - }; - - children = goog.dom.getChildren(mockP2); - assertNotNull('Elements array should not be null', children); - assertEquals('List of element children should be length two.', 2, - children.length); - - assertObjectEquals('First element child should be b1.', b1, children[0]); - assertObjectEquals('Second element child should be b2.', b2, children[1]); -} - -function testGetNextNode() { - var tree = goog.dom.htmlToDocumentFragment( - '<div>' + - '<p>Some text</p>' + - '<blockquote>Some <i>special</i> <b>text</b></blockquote>' + - '<address><!-- comment -->Foo</address>' + - '</div>'); - - assertNull(goog.dom.getNextNode(null)); - - var node = tree; - var next = function() { - return node = goog.dom.getNextNode(node); - }; - - assertEquals('P', next().tagName); - assertEquals('Some text', next().nodeValue); - assertEquals('BLOCKQUOTE', next().tagName); - assertEquals('Some ', next().nodeValue); - assertEquals('I', next().tagName); - assertEquals('special', next().nodeValue); - assertEquals(' ', next().nodeValue); - assertEquals('B', next().tagName); - assertEquals('text', next().nodeValue); - assertEquals('ADDRESS', next().tagName); - assertEquals(goog.dom.NodeType.COMMENT, next().nodeType); - assertEquals('Foo', next().nodeValue); - - assertNull(next()); -} - -function testGetPreviousNode() { - var tree = goog.dom.htmlToDocumentFragment( - '<div>' + - '<p>Some text</p>' + - '<blockquote>Some <i>special</i> <b>text</b></blockquote>' + - '<address><!-- comment -->Foo</address>' + - '</div>'); - - assertNull(goog.dom.getPreviousNode(null)); - - var node = tree.lastChild.lastChild; - var previous = function() { - return node = goog.dom.getPreviousNode(node); - }; - - assertEquals(goog.dom.NodeType.COMMENT, previous().nodeType); - assertEquals('ADDRESS', previous().tagName); - assertEquals('text', previous().nodeValue); - assertEquals('B', previous().tagName); - assertEquals(' ', previous().nodeValue); - assertEquals('special', previous().nodeValue); - assertEquals('I', previous().tagName); - assertEquals('Some ', previous().nodeValue); - assertEquals('BLOCKQUOTE', previous().tagName); - assertEquals('Some text', previous().nodeValue); - assertEquals('P', previous().tagName); - assertEquals('DIV', previous().tagName); - - if (!goog.userAgent.IE) { - // Internet Explorer maintains a parentNode for Elements after they are - // removed from the hierarchy. Everyone else agrees on a null parentNode. - assertNull(previous()); - } -} - -function testSetTextContent() { - var p1 = $('p1'); - var s = 'hello world'; - goog.dom.setTextContent(p1, s); - assertEquals('We should have one childNode after setTextContent', 1, - p1.childNodes.length); - assertEquals(s, p1.firstChild.data); - assertEquals(s, p1.innerHTML); - - s = 'four elefants < five ants'; - var sHtml = 'four elefants < five ants'; - goog.dom.setTextContent(p1, s); - assertEquals('We should have one childNode after setTextContent', 1, - p1.childNodes.length); - assertEquals(s, p1.firstChild.data); - assertEquals(sHtml, p1.innerHTML); - - // ensure that we remove existing children - p1.innerHTML = 'a<b>b</b>c'; - s = 'hello world'; - goog.dom.setTextContent(p1, s); - assertEquals('We should have one childNode after setTextContent', 1, - p1.childNodes.length); - assertEquals(s, p1.firstChild.data); - - // same but start with an element - p1.innerHTML = '<b>a</b>b<i>c</i>'; - s = 'hello world'; - goog.dom.setTextContent(p1, s); - assertEquals('We should have one childNode after setTextContent', 1, - p1.childNodes.length); - assertEquals(s, p1.firstChild.data); - - // clean up - p1.innerHTML = ''; -} - -function testFindNode() { - var expected = document.body; - var result = goog.dom.findNode(document, function(n) { - return n.nodeType == goog.dom.NodeType.ELEMENT && n.tagName == 'BODY'; - }); - assertEquals(expected, result); - - expected = document.getElementsByTagName('P')[0]; - result = goog.dom.findNode(document, function(n) { - return n.nodeType == goog.dom.NodeType.ELEMENT && n.tagName == 'P'; - }); - assertEquals(expected, result); - - result = goog.dom.findNode(document, function(n) { - return false; - }); - assertUndefined(result); -} - -function testFindNodes() { - var expected = document.getElementsByTagName('P'); - var result = goog.dom.findNodes(document, function(n) { - return n.nodeType == goog.dom.NodeType.ELEMENT && n.tagName == 'P'; - }); - assertEquals(expected.length, result.length); - assertEquals(expected[0], result[0]); - assertEquals(expected[1], result[1]); - - result = goog.dom.findNodes(document, function(n) { - return false; - }).length; - assertEquals(0, result); -} - -function createTestDom(txt) { - var dom = goog.dom.createDom('div'); - dom.innerHTML = txt; - return dom; -} - -function testIsFocusableTabIndex() { - assertFalse('isFocusableTabIndex() must be false for no tab index', - goog.dom.isFocusableTabIndex(goog.dom.getElement('noTabIndex'))); - assertFalse('isFocusableTabIndex() must be false for tab index -2', - goog.dom.isFocusableTabIndex(goog.dom.getElement('tabIndexNegative2'))); - assertFalse('isFocusableTabIndex() must be false for tab index -1', - goog.dom.isFocusableTabIndex(goog.dom.getElement('tabIndexNegative1'))); - - // WebKit on Mac doesn't support focusable DIVs until version 526 and later. - if (!goog.userAgent.WEBKIT || !goog.userAgent.MAC || - goog.userAgent.isVersion('526')) { - assertTrue('isFocusableTabIndex() must be true for tab index 0', - goog.dom.isFocusableTabIndex(goog.dom.getElement('tabIndex0'))); - assertTrue('isFocusableTabIndex() must be true for tab index 1', - goog.dom.isFocusableTabIndex(goog.dom.getElement('tabIndex1'))); - assertTrue('isFocusableTabIndex() must be true for tab index 2', - goog.dom.isFocusableTabIndex(goog.dom.getElement('tabIndex2'))); - } -} - -function testSetFocusableTabIndex() { - // WebKit on Mac doesn't support focusable DIVs until version 526 and later. - if (!goog.userAgent.WEBKIT || !goog.userAgent.MAC || - goog.userAgent.isVersion('526')) { - // Test enabling focusable tab index. - goog.dom.setFocusableTabIndex(goog.dom.getElement('noTabIndex'), true); - assertTrue('isFocusableTabIndex() must be true after enabling tab index', - goog.dom.isFocusableTabIndex(goog.dom.getElement('noTabIndex'))); - - // Test disabling focusable tab index that was added programmatically. - goog.dom.setFocusableTabIndex(goog.dom.getElement('noTabIndex'), false); - assertFalse('isFocusableTabIndex() must be false after disabling tab ' + - 'index that was programmatically added', - goog.dom.isFocusableTabIndex(goog.dom.getElement('noTabIndex'))); - - // Test disabling focusable tab index that was specified in markup. - goog.dom.setFocusableTabIndex(goog.dom.getElement('tabIndex0'), false); - assertFalse('isFocusableTabIndex() must be false after disabling tab ' + - 'index that was specified in markup', - goog.dom.isFocusableTabIndex(goog.dom.getElement('tabIndex0'))); - - // Test re-enabling focusable tab index. - goog.dom.setFocusableTabIndex(goog.dom.getElement('tabIndex0'), true); - assertTrue('isFocusableTabIndex() must be true after reenabling tabindex', - goog.dom.isFocusableTabIndex(goog.dom.getElement('tabIndex0'))); - } -} - -function testGetTextContent() { - function t(inp, out) { - assertEquals(out.replace(/ /g, '_'), - goog.dom.getTextContent( - createTestDom(inp)).replace(/ /g, '_')); - } - - t('abcde', 'abcde'); - t('a<b>bcd</b>efgh', 'abcdefgh'); - t('a<script type="text/javascript' + '">var a=1;<' + '/script>h', 'ah'); - t('<html><head><style type="text/css">' + - 'p{margin:100%;padding:5px}\n.class{background-color:red;}</style>' + - '</head><body><h1>Hello</h1>\n<p>One two three</p>\n<table><tr><td>a' + - '<td>b</table><' + 'script>var a = \'foo\';' + - '</scrip' + 't></body></html>', 'HelloOne two threeab'); - t('abc<br>def', 'abc\ndef'); - t('abc<br>\ndef', 'abc\ndef'); - t('abc<br>\n\ndef', 'abc\ndef'); - t('abc<br><br>\ndef', 'abc\n\ndef'); - t(' <b>abcde </b> ', 'abcde '); - t(' <b>abcde </b> hi ', 'abcde hi '); - t(' \n<b>abcde </b> ', 'abcde '); - t(' \n<b>abcde </b> \n\n\n', 'abcde '); - t('<p>abcde</p>\nfg', 'abcdefg'); - t('\n <div> <b>abcde </b> ', 'abcde '); - t(' \n­<b>abcde ­ </b> \n\n\n­', 'abcde '); - t(' \n­\n\n­\na ', 'a '); - t(' \n<wbr></wbr><b>abcde <wbr></wbr> </b> \n\n\n<wbr></wbr>', 'abcde '); - t('a b', - goog.dom.BrowserFeature.CAN_USE_INNER_TEXT ? - 'a b' : 'a\xA0\xA0\xA0\xA0\xA0b'); -} - -function testGetNodeTextLength() { - - assertEquals(6, goog.dom.getNodeTextLength(createTestDom('abcdef'))); - assertEquals(8, goog.dom.getNodeTextLength( - createTestDom('a<b>bcd</b>efgh'))); - assertEquals(2, goog.dom.getNodeTextLength(createTestDom( - 'a<script type="text/javascript' + '">var a = 1234;<' + '/script>h'))); - assertEquals(4, goog.dom.getNodeTextLength(createTestDom( - 'a<br>\n<!-- some comments -->\nfo'))); - assertEquals(20, goog.dom.getNodeTextLength(createTestDom( - '<html><head><style type="text/css">' + - 'p{margin:100%;padding:5px}\n.class{background-color:red;}</style>' + - '</head><body><h1>Hello</h1><p>One two three</p><table><tr><td>a<td>b' + - '</table><' + 'script>var a = \'foo\';</scrip' + - 't></body></html>'))); - assertEquals(10, goog.dom.getNodeTextLength(createTestDom( - 'a<b>bcd</b><br />efghi'))); -} - -function testGetNodeTextOffset() { - assertEquals(4, goog.dom.getNodeTextOffset($('offsetTest1'), - $('offsetParent1'))); - assertEquals(12, goog.dom.getNodeTextOffset($('offsetTest1'))); -} - -function testGetNodeAtOffset() { - var html = '<div id=a>123<b id=b>45</b><span id=c>67<b id=d>89<i id=e>01' + - '</i>23<i id=f>45</i>67</b>890<i id=g>123</i><b id=h>456</b>' + - '</span></div><div id=i>7890<i id=j>123</i></div>'; - var node = document.createElement('div'); - node.innerHTML = html; - var rv = {}; - - goog.dom.getNodeAtOffset(node, 2, rv); - assertEquals('123', rv.node.nodeValue); - assertEquals('a', rv.node.parentNode.id); - assertEquals(1, rv.remainder); - - goog.dom.getNodeAtOffset(node, 3, rv); - assertEquals('123', rv.node.nodeValue); - assertEquals('a', rv.node.parentNode.id); - assertEquals(2, rv.remainder); - - goog.dom.getNodeAtOffset(node, 5, rv); - assertEquals('45', rv.node.nodeValue); - assertEquals('b', rv.node.parentNode.id); - assertEquals(1, rv.remainder); - - goog.dom.getNodeAtOffset(node, 6, rv); - assertEquals('67', rv.node.nodeValue); - assertEquals('c', rv.node.parentNode.id); - assertEquals(0, rv.remainder); - - goog.dom.getNodeAtOffset(node, 23, rv); - assertEquals('123', rv.node.nodeValue); - assertEquals('g', rv.node.parentNode.id); - assertEquals(2, rv.remainder); - - goog.dom.getNodeAtOffset(node, 30, rv); - assertEquals('7890', rv.node.nodeValue); - assertEquals('i', rv.node.parentNode.id); - assertEquals(3, rv.remainder); - -} - -// IE inserts line breaks and capitalizes nodenames. -function assertEqualsCaseAndLeadingWhitespaceInsensitive(value1, value2) { - value1 = value1.replace(/^\s+|\s+$/g, '').toLowerCase(); - value2 = value2.replace(/^\s+|\s+$/g, '').toLowerCase(); - assertEquals(value1, value2); -} - -function testGetOuterHtml() { - var contents = '<b>foo</b>'; - var node = document.createElement('div'); - node.setAttribute('foo', 'bar'); - node.innerHTML = contents; - assertEqualsCaseAndLeadingWhitespaceInsensitive( - goog.dom.getOuterHtml(node), '<div foo="bar">' + contents + '</div>'); - - var imgNode = document.createElement('img'); - imgNode.setAttribute('foo', 'bar'); - assertEqualsCaseAndLeadingWhitespaceInsensitive( - goog.dom.getOuterHtml(imgNode), '<img foo="bar">'); -} - - -function testGetWindowFrame() { - var frameWindow = window.frames['frame']; - var frameDocument = frameWindow.document; - var frameDomHelper = new goog.dom.DomHelper(frameDocument); - - // Cannot use assertEquals since IE fails on === - assertTrue(frameWindow == frameDomHelper.getWindow()); -} - -function testGetWindow() { - var domHelper = new goog.dom.DomHelper(); - // Cannot use assertEquals since IE fails on === - assertTrue(window == domHelper.getWindow()); -} - -function testGetWindowStatic() { - // Cannot use assertEquals since IE fails on === - assertTrue(window == goog.dom.getWindow()); -} - -function testIsNodeList() { - var elem = document.getElementById('p2'); - var text = document.getElementById('b2').firstChild; - - assertTrue('NodeList should be a node list', - goog.dom.isNodeList(elem.childNodes)); - assertFalse('TextNode should not be a node list', - goog.dom.isNodeList(text)); - assertFalse('Array of nodes should not be a node list', - goog.dom.isNodeList([elem.firstChild, elem.lastChild])); -} - -function testGetFrameContentDocument() { - var iframe = document.getElementsByTagName('iframe')[0]; - var name = iframe.name; - var iframeDoc = goog.dom.getFrameContentDocument(iframe); - assertEquals(window.frames[name].document, iframeDoc); -} - -function testGetFrameContentWindow() { - var iframe = document.getElementsByTagName('iframe')[0]; - var name = iframe.name; - var iframeWin = goog.dom.getFrameContentWindow(iframe); - assertEquals(window.frames[name], iframeWin); -} - -function testCanHaveChildren() { - for (var tag in goog.dom.TagName) { - var expected = true; - switch (tag) { - case goog.dom.TagName.BASE: - case goog.dom.TagName.APPLET: - case goog.dom.TagName.AREA: - case goog.dom.TagName.BR: - case goog.dom.TagName.COL: - case goog.dom.TagName.FRAME: - case goog.dom.TagName.HR: - case goog.dom.TagName.IMG: - case goog.dom.TagName.INPUT: - case goog.dom.TagName.IFRAME: - case goog.dom.TagName.ISINDEX: - case goog.dom.TagName.LINK: - case goog.dom.TagName.NOFRAMES: - case goog.dom.TagName.NOSCRIPT: - case goog.dom.TagName.META: - case goog.dom.TagName.OBJECT: - case goog.dom.TagName.PARAM: - case goog.dom.TagName.SCRIPT: - case goog.dom.TagName.STYLE: - expected = false; - break; - } - var node = goog.dom.createDom(tag); - assertEquals(tag + ' should ' + (expected ? '' : 'not ') + - 'have children', expected, goog.dom.canHaveChildren(node)); - - // Make sure we can _actually_ add a child if we identify the node as - // allowing children. - if (goog.dom.canHaveChildren(node)) { - node.appendChild(goog.dom.createDom('div', null, 'foo')); - } - } -} - -function testGetAncestorNoMatch() { - var elem = goog.dom.getElement('nestedElement'); - assertNull(goog.dom.getAncestor(elem, function() {return false;})); -} - -function testGetAncestorMatchSelf() { - var elem = goog.dom.getElement('nestedElement'); - var matched = goog.dom.getAncestor(elem, function() {return true;}, true); - assertEquals(elem, matched); -} - -function testGetAncestorNoMatchSelf() { - var elem = goog.dom.getElement('nestedElement'); - var matched = goog.dom.getAncestor(elem, function() {return true;}); - assertEquals(elem.parentNode, matched); -} - -function testGetAncestorWithMaxSearchStepsMatchSelf() { - var elem = goog.dom.getElement('nestedElement'); - var matched = goog.dom.getAncestor( - elem, function() {return true;}, true, 2); - assertEquals(elem, matched); -} - -function testGetAncestorWithMaxSearchStepsMatch() { - var elem = goog.dom.getElement('nestedElement'); - var searchEl = elem.parentNode.parentNode; - var matched = goog.dom.getAncestor( - elem, function(el) {return el == searchEl;}, false, 1); - assertEquals(searchEl, matched); -} - -function testGetAncestorWithMaxSearchStepsNoMatch() { - var elem = goog.dom.getElement('nestedElement'); - var searchEl = elem.parentNode.parentNode; - var matched = goog.dom.getAncestor( - elem, function(el) {return el == searchEl;}, false, 0); - assertNull(matched); -} - -function testGetAncestorByTagNameNoMatch() { - var elem = goog.dom.getElement('nestedElement'); - assertNull( - goog.dom.getAncestorByTagNameAndClass(elem, goog.dom.TagName.IMG)); -} - -function testGetAncestorByTagNameOnly() { - var elem = goog.dom.getElement('nestedElement'); - var expected = goog.dom.getElement('testAncestorDiv'); - assertEquals(expected, - goog.dom.getAncestorByTagNameAndClass(elem, goog.dom.TagName.DIV)); - assertEquals(expected, - goog.dom.getAncestorByTagNameAndClass(elem, 'div')); -} - -function testGetAncestorByClassNameNoMatch() { - var elem = goog.dom.getElement('nestedElement'); - assertNull( - goog.dom.getAncestorByClass(elem, 'bogusClassName')); -} - -function testGetAncestorByClassName() { - var elem = goog.dom.getElement('nestedElement'); - var expected = goog.dom.getElement('testAncestorP'); - assertEquals(expected, - goog.dom.getAncestorByClass(elem, 'testAncestor')); -} - -function testGetAncestorByTagNameAndClass() { - var elem = goog.dom.getElement('nestedElement'); - var expected = goog.dom.getElement('testAncestorDiv'); - assertEquals(expected, - goog.dom.getAncestorByTagNameAndClass(elem, goog.dom.TagName.DIV, - 'testAncestor')); -} - -function testCreateTable() { - var table = goog.dom.createTable(2, 3, true); - assertEquals(2, table.getElementsByTagName(goog.dom.TagName.TR).length); - assertEquals(3, - table.getElementsByTagName(goog.dom.TagName.TR)[0].childNodes.length); - assertEquals(6, table.getElementsByTagName(goog.dom.TagName.TD).length); - assertEquals(goog.string.Unicode.NBSP, - table.getElementsByTagName(goog.dom.TagName.TD)[0].firstChild.nodeValue); - - table = goog.dom.createTable(2, 3, false); - assertEquals(2, table.getElementsByTagName(goog.dom.TagName.TR).length); - assertEquals(3, - table.getElementsByTagName(goog.dom.TagName.TR)[0].childNodes.length); - assertEquals(6, table.getElementsByTagName(goog.dom.TagName.TD).length); - assertEquals(0, - table.getElementsByTagName(goog.dom.TagName.TD)[0].childNodes.length); -} - -function testHtmlToDocumentFragment() { - var docFragment = goog.dom.htmlToDocumentFragment('<a>1</a><b>2</b>'); - assertNull(docFragment.parentNode); - assertEquals(2, docFragment.childNodes.length); - - var div = goog.dom.htmlToDocumentFragment('<div>3</div>'); - assertEquals('DIV', div.tagName); - - var script = goog.dom.htmlToDocumentFragment('<script></script>'); - assertEquals('SCRIPT', script.tagName); - - if (goog.userAgent.IE && !goog.userAgent.isDocumentMode(9)) { - // Removing an Element from a DOM tree in IE sets its parentNode to a new - // DocumentFragment. Bizarre! - assertEquals(goog.dom.NodeType.DOCUMENT_FRAGMENT, - goog.dom.removeNode(div).parentNode.nodeType); - } else { - assertNull(div.parentNode); - } -} - -function testAppend() { - var div = document.createElement('div'); - var b = document.createElement('b'); - var c = document.createTextNode('c'); - goog.dom.append(div, 'a', b, c); - assertEqualsCaseAndLeadingWhitespaceInsensitive('a<b></b>c', div.innerHTML); -} - -function testAppend2() { - var div = myIframeDoc.createElement('div'); - var b = myIframeDoc.createElement('b'); - var c = myIframeDoc.createTextNode('c'); - goog.dom.append(div, 'a', b, c); - assertEqualsCaseAndLeadingWhitespaceInsensitive('a<b></b>c', div.innerHTML); -} - -function testAppend3() { - var div = document.createElement('div'); - var b = document.createElement('b'); - var c = document.createTextNode('c'); - goog.dom.append(div, ['a', b, c]); - assertEqualsCaseAndLeadingWhitespaceInsensitive('a<b></b>c', div.innerHTML); -} - -function testAppend4() { - var div = document.createElement('div'); - var div2 = document.createElement('div'); - div2.innerHTML = 'a<b></b>c'; - goog.dom.append(div, div2.childNodes); - assertEqualsCaseAndLeadingWhitespaceInsensitive('a<b></b>c', div.innerHTML); - assertFalse(div2.hasChildNodes()); -} - -function testGetDocumentScroll() { - // setUpPage added divForTestingScrolling to the DOM. It's not init'd here so - // it can be shared amonst other tests. - window.scrollTo(100, 100); - - assertEquals(100, goog.dom.getDocumentScroll().x); - assertEquals(100, goog.dom.getDocumentScroll().y); -} - -function testGetDocumentScrollOfFixedViewport() { - // iOS and perhaps other environments don't actually support scrolling. - // Instead, you view the document's fixed layout through a screen viewport. - // We need getDocumentScroll to handle this case though. - var fakeDocumentScrollElement = {scrollLeft: 0, scrollTop: 0}; - var fakeDocument = { - defaultView: {pageXOffset: 100, pageYOffset: 100}, - documentElement: fakeDocumentScrollElement, - body: fakeDocumentScrollElement - }; - var dh = goog.dom.getDomHelper(document); - dh.setDocument(fakeDocument); - assertEquals(100, dh.getDocumentScroll().x); - assertEquals(100, dh.getDocumentScroll().y); -} - -function testActiveElementIE() { - if (!goog.userAgent.IE) { - return; - } - - var link = goog.dom.getElement('link'); - link.focus(); - - assertEquals(link.tagName, goog.dom.getActiveElement(document).tagName); - assertEquals(link, goog.dom.getActiveElement(document)); -} - -function testParentElement() { - var testEl = $('testEl'); - var bodyEl = goog.dom.getParentElement(testEl); - assertNotNull(bodyEl); - var htmlEl = goog.dom.getParentElement(bodyEl); - assertNotNull(htmlEl); - var documentNotAnElement = goog.dom.getParentElement(htmlEl); - assertNull(documentNotAnElement); - - var tree = goog.dom.htmlToDocumentFragment( - '<div>' + - '<p>Some text</p>' + - '<blockquote>Some <i>special</i> <b>text</b></blockquote>' + - '<address><!-- comment -->Foo</address>' + - '</div>'); - assertNull(goog.dom.getParentElement(tree)); - pEl = goog.dom.getNextNode(tree); - var fragmentRootEl = goog.dom.getParentElement(pEl); - assertEquals(tree, fragmentRootEl); - - var detachedEl = goog.dom.createDom('div'); - var detachedHasNoParent = goog.dom.getParentElement(detachedEl); - assertNull(detachedHasNoParent); -} - -/** - * @return {boolean} Returns true if the userAgent is IE8 or higher. - */ -function isIE8OrHigher() { - return goog.userAgent.IE && goog.userAgent.product.isVersion('8'); -} diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/fontsizemonitor.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/fontsizemonitor.js.svn-base deleted file mode 100644 index e505257..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/fontsizemonitor.js.svn-base +++ /dev/null @@ -1,158 +0,0 @@ -// Copyright 2005 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview A class that can be used to listen to font size changes. - */ - -goog.provide('goog.dom.FontSizeMonitor'); -goog.provide('goog.dom.FontSizeMonitor.EventType'); - -goog.require('goog.dom'); -goog.require('goog.events'); -goog.require('goog.events.EventTarget'); -goog.require('goog.events.EventType'); -goog.require('goog.userAgent'); - - -// TODO(arv): Move this to goog.events instead. - - - -/** - * This class can be used to monitor changes in font size. Instances will - * dispatch a {@code goog.dom.FontSizeMonitor.EventType.CHANGE} event. - * Example usage: - * <pre> - * var fms = new goog.dom.FontSizeMonitor(); - * goog.events.listen(fms, goog.dom.FontSizeMonitor.EventType.CHANGE, - * function(e) { - * alert('Font size was changed'); - * }); - * </pre> - * @param {goog.dom.DomHelper=} opt_domHelper DOM helper object that is used to - * determine where to insert the DOM nodes used to determine when the font - * size changes. - * @constructor - * @extends {goog.events.EventTarget} - */ -goog.dom.FontSizeMonitor = function(opt_domHelper) { - goog.events.EventTarget.call(this); - - var dom = opt_domHelper || goog.dom.getDomHelper(); - - /** - * Offscreen iframe which we use to detect resize events. - * @type {Element} - * @private - */ - this.sizeElement_ = dom.createDom( - // The size of the iframe is expressed in em, which are font size relative - // which will cause the iframe to be resized when the font size changes. - // The actual values are not relevant as long as we can ensure that the - // iframe has a non zero size and is completely off screen. - goog.userAgent.IE ? 'div' : 'iframe', { - 'style': 'position:absolute;width:9em;height:9em;top:-99em', - 'tabIndex': -1, - 'aria-hidden': 'true' - }); - var p = dom.getDocument().body; - p.insertBefore(this.sizeElement_, p.firstChild); - - /** - * The object that we listen to resize events on. - * @type {Element|Window} - * @private - */ - var resizeTarget = this.resizeTarget_ = - goog.userAgent.IE ? this.sizeElement_ : - goog.dom.getFrameContentWindow( - /** @type {HTMLIFrameElement} */ (this.sizeElement_)); - - // We need to open and close the document to get Firefox 2 to work. We must - // not do this for IE in case we are using HTTPS since accessing the document - // on an about:blank iframe in IE using HTTPS raises a Permission Denied - // error. - if (goog.userAgent.GECKO) { - var doc = resizeTarget.document; - doc.open(); - doc.close(); - } - - // Listen to resize event on the window inside the iframe. - goog.events.listen(resizeTarget, goog.events.EventType.RESIZE, - this.handleResize_, false, this); - - /** - * Last measured width of the iframe element. - * @type {number} - * @private - */ - this.lastWidth_ = this.sizeElement_.offsetWidth; -}; -goog.inherits(goog.dom.FontSizeMonitor, goog.events.EventTarget); - - -/** - * The event types that the FontSizeMonitor fires. - * @enum {string} - */ -goog.dom.FontSizeMonitor.EventType = { - // TODO(arv): Change value to 'change' after updating the callers. - CHANGE: 'fontsizechange' -}; - - -/** - * Constant for the change event. - * @type {string} - * @deprecated Use {@code goog.dom.FontSizeMonitor.EventType.CHANGE} instead. - */ -goog.dom.FontSizeMonitor.CHANGE_EVENT = - goog.dom.FontSizeMonitor.EventType.CHANGE; - - -/** @override */ -goog.dom.FontSizeMonitor.prototype.disposeInternal = function() { - goog.dom.FontSizeMonitor.superClass_.disposeInternal.call(this); - - goog.events.unlisten(this.resizeTarget_, goog.events.EventType.RESIZE, - this.handleResize_, false, this); - this.resizeTarget_ = null; - - // Firefox 2 crashes if the iframe is removed during the unload phase. - if (!goog.userAgent.GECKO || goog.userAgent.isVersion('1.9')) { - goog.dom.removeNode(this.sizeElement_); - } - delete this.sizeElement_; -}; - - -/** - * Handles the onresize event of the iframe and dispatches a change event in - * case its size really changed. - * @param {goog.events.BrowserEvent} e The event object. - * @private - */ -goog.dom.FontSizeMonitor.prototype.handleResize_ = function(e) { - // Only dispatch the event if the size really changed. Some newer browsers do - // not really change the font-size, instead they zoom the whole page. This - // does trigger window resize events on the iframe but the logical pixel size - // remains the same (the device pixel size changes but that is irrelevant). - var currentWidth = this.sizeElement_.offsetWidth; - if (this.lastWidth_ != currentWidth) { - this.lastWidth_ = currentWidth; - this.dispatchEvent(goog.dom.FontSizeMonitor.EventType.CHANGE); - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/fontsizemonitor_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/fontsizemonitor_test.html.svn-base deleted file mode 100644 index 3852042..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/fontsizemonitor_test.html.svn-base +++ /dev/null @@ -1,284 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- -Author: arv@google.com (Erik Arvidsson) ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.FontSizeMonitor</title> -<script src="../base.js"></script> -<script> - -goog.require('goog.dom'); -goog.require('goog.dom.FontSizeMonitor'); -goog.require('goog.events'); -goog.require('goog.testing.PropertyReplacer'); -goog.require('goog.testing.events'); -goog.require('goog.testing.jsunit'); -goog.require('goog.userAgent'); - -</script> -</head> -<body> - -<!-- iframe to be used to test DomHelper support --> -<iframe></iframe> - -<script> - -function isBuggyGecko() { - return goog.userAgent.GECKO && !goog.userAgent.isVersion('1.9'); -} - -var monitor; - -function setUp() { - monitor = new goog.dom.FontSizeMonitor(); -} - -function tearDown() { - monitor.dispose(); -} - -function getResizeTarget() { - return goog.userAgent.IE ? monitor.sizeElement_ : - goog.dom.getFrameContentWindow(monitor.sizeElement_); -} - -function testFontSizeNoChange() { - // This tests that firing the resize event without changing the font-size - // does not trigger the event. - - var fired = false; - goog.events.listen(monitor, goog.dom.FontSizeMonitor.EventType.CHANGE, - function(e) { - fired = true; - }); - - var resizeEvent = new goog.events.Event('resize', getResizeTarget()); - goog.testing.events.fireBrowserEvent(resizeEvent); - - assertFalse('The font size should not have changed', fired); -} - -function testFontSizeChanged() { - // One can trigger the iframe resize by changing the - // document.body.style.fontSize but the event is fired asynchronously in - // Firefox. Instead, we just override the lastWidth_ to simulate that the - // size changed. - - var fired = false; - goog.events.listen(monitor, goog.dom.FontSizeMonitor.EventType.CHANGE, - function(e) { - fired = true; - }); - - monitor.lastWidth_--; - - var resizeEvent = new goog.events.Event('resize', getResizeTarget()); - goog.testing.events.fireBrowserEvent(resizeEvent); - - assertTrue('The font size should have changed', fired); -} - -function testCreateAndDispose() { - var frameCount = window.frames.length; - var iframeElementCount = document.getElementsByTagName('iframe').length; - var divElementCount = document.getElementsByTagName('div').length; - - var monitor = new goog.dom.FontSizeMonitor(); - monitor.dispose(); - - var newFrameCount = window.frames.length; - var newIframeElementCount = document.getElementsByTagName('iframe').length; - var newDivElementCount = document.getElementsByTagName('div').length; - - assertEquals('There should be no trailing frames', - frameCount + isBuggyGecko(), newFrameCount); - assertEquals('There should be no trailing iframe elements', - iframeElementCount + isBuggyGecko(), - newIframeElementCount); - assertEquals('There should be no trailing div elements', - divElementCount, newDivElementCount); -} - -function testWithDomHelper() { - var frameCount = window.frames.length; - var iframeElementCount = document.getElementsByTagName('iframe').length; - var divElementCount = document.getElementsByTagName('div').length; - - var monitor = new goog.dom.FontSizeMonitor(goog.dom.getDomHelper()); - - var newFrameCount = window.frames.length; - var newIframeElementCount = document.getElementsByTagName('iframe').length; - var newDivElementCount = document.getElementsByTagName('div').length; - - if (goog.userAgent.IE) { - assertEquals('There should be one new div element', - divElementCount + 1, newDivElementCount); - } else { - assertEquals('There should be one new frame', - frameCount + 1, newFrameCount); - assertEquals('There should be one new iframe element', - iframeElementCount + 1, newIframeElementCount); - } - - // Use the first iframe in the doc. This is added in the HTML markup. - var win = window.frames[0]; - var doc = win.document; - doc.open(); - doc.write('<html><body></body></html>'); - doc.close(); - var domHelper = goog.dom.getDomHelper(doc); - - var frameCount2 = win.frames.length; - var iframeElementCount2 = doc.getElementsByTagName('iframe').length; - var divElementCount2 = doc.getElementsByTagName('div').length; - - var monitor2 = new goog.dom.FontSizeMonitor(domHelper); - - var newFrameCount2 = win.frames.length; - var newIframeElementCount2 = doc.getElementsByTagName('iframe').length; - var newDivElementCount2 = doc.getElementsByTagName('div').length; - - if (goog.userAgent.IE) { - assertEquals('There should be one new div element', - divElementCount2 + 1, newDivElementCount2); - } else { - assertEquals('There should be one new frame', frameCount2 + 1, - newFrameCount2); - assertEquals('There should be one new iframe element', - iframeElementCount2 + 1, newIframeElementCount2); - } - - monitor.dispose(); - monitor2.dispose(); -} - -function testEnsureThatDocIsOpenedForGecko() { - - var pr = new goog.testing.PropertyReplacer(); - pr.set(goog.userAgent, 'GECKO', true); - pr.set(goog.userAgent, 'IE', false); - - var openCalled = false; - var closeCalled = false; - var instance = { - document: { - open: function() { - openCalled = true; - }, - close: function() { - closeCalled = true; - } - }, - attachEvent: function() {} - }; - - pr.set(goog.dom, 'getFrameContentWindow', function() { - return instance; - }); - - try { - var monitor = new goog.dom.FontSizeMonitor(); - - assertTrue('doc.open should have been called', openCalled); - assertTrue('doc.close should have been called', closeCalled); - - monitor.dispose(); - } finally { - pr.reset(); - } -} - -function testFirefox2WorkAroundFirefox3() { - var pr = new goog.testing.PropertyReplacer(); - pr.set(goog.userAgent, 'GECKO', true); - pr.set(goog.userAgent, 'IE', false); - - try { - // 1.9 should clear iframes - pr.set(goog.userAgent, 'VERSION', '1.9'); - goog.userAgent.isVersionCache_ = {}; - - var frameCount = window.frames.length; - var iframeElementCount = document.getElementsByTagName('iframe').length; - var divElementCount = document.getElementsByTagName('div').length; - - var monitor = new goog.dom.FontSizeMonitor(); - monitor.dispose(); - - var newFrameCount = window.frames.length; - var newIframeElementCount = document.getElementsByTagName('iframe').length; - var newDivElementCount = document.getElementsByTagName('div').length; - - assertEquals('There should be no trailing frames', - frameCount, newFrameCount); - assertEquals('There should be no trailing iframe elements', - iframeElementCount, - newIframeElementCount); - assertEquals('There should be no trailing div elements', - divElementCount, newDivElementCount); - } finally { - pr.reset(); - } -} - - -function testFirefox2WorkAroundFirefox2() { - var pr = new goog.testing.PropertyReplacer(); - pr.set(goog.userAgent, 'GECKO', true); - pr.set(goog.userAgent, 'IE', false); - - try { - // 1.8 should NOT clear iframes - pr.set(goog.userAgent, 'VERSION', '1.8'); - goog.userAgent.isVersionCache_ = {}; - - var frameCount = window.frames.length; - var iframeElementCount = document.getElementsByTagName('iframe').length; - var divElementCount = document.getElementsByTagName('div').length; - - var monitor = new goog.dom.FontSizeMonitor(); - monitor.dispose(); - - var newFrameCount = window.frames.length; - var newIframeElementCount = document.getElementsByTagName('iframe').length; - var newDivElementCount = document.getElementsByTagName('div').length; - - assertEquals('There should be no trailing frames', - frameCount + 1, newFrameCount); - assertEquals('There should be no trailing iframe elements', - iframeElementCount + 1, - newIframeElementCount); - assertEquals('There should be no trailing div elements', - divElementCount, newDivElementCount); - } finally { - pr.reset(); - } -} - -</script> - -<!-- -This div has a script in it that creates a FontSizeMonitor. This ensures that -we do not get an "Operation abort" error in IE. ---> -<div> - <script> - var operationAbortTester = new goog.dom.FontSizeMonitor(); - // Close script tag before disposing. - </script> - <script> - operationAbortTester.dispose(); - </script> -</div> - -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/forms.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/forms.js.svn-base deleted file mode 100644 index af403f9..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/forms.js.svn-base +++ /dev/null @@ -1,406 +0,0 @@ -// Copyright 2006 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for manipulating a form and elements. - * - * @author arv@google.com (Erik Arvidsson) - * @author jonp@google.com (Jon Perlow) - * @author elsigh@google.com (Lindsey Simon) - */ - -goog.provide('goog.dom.forms'); - -goog.require('goog.structs.Map'); - - -/** - * Returns form data as a map of name to value arrays. This doesn't - * support file inputs. - * @param {HTMLFormElement} form The form. - * @return {!goog.structs.Map} A map of the form data as form name to arrays of - * values. - */ -goog.dom.forms.getFormDataMap = function(form) { - var map = new goog.structs.Map(); - goog.dom.forms.getFormDataHelper_(form, map, - goog.dom.forms.addFormDataToMap_); - return map; -}; - - -/** - * Returns the form data as an application/x-www-url-encoded string. This - * doesn't support file inputs. - * @param {HTMLFormElement} form The form. - * @return {string} An application/x-www-url-encoded string. - */ -goog.dom.forms.getFormDataString = function(form) { - var sb = []; - goog.dom.forms.getFormDataHelper_(form, sb, - goog.dom.forms.addFormDataToStringBuffer_); - return sb.join('&'); -}; - - -/** - * Returns the form data as a map or an application/x-www-url-encoded - * string. This doesn't support file inputs. - * @param {HTMLFormElement} form The form. - * @param {Object} result The object form data is being put in. - * @param {Function} fnAppend Function that takes {@code result}, an element - * name, and an element value, and adds the name/value pair to the result - * object. - * @private - */ -goog.dom.forms.getFormDataHelper_ = function(form, result, fnAppend) { - var els = form.elements; - for (var el, i = 0; el = els[i]; i++) { - if (el.disabled || el.tagName.toLowerCase() == 'fieldset') { - continue; - } - var name = el.name; - var type = el.type.toLowerCase(); - switch (type) { - case 'file': - // file inputs are not supported - case 'submit': - case 'reset': - case 'button': - // don't submit these - break; - case 'select-multiple': - var values = goog.dom.forms.getValue(el); - if (values != null) { - for (var value, j = 0; value = values[j]; j++) { - fnAppend(result, name, value); - } - } - break; - default: - var value = goog.dom.forms.getValue(el); - if (value != null) { - fnAppend(result, name, value); - } - } - } - - // input[type=image] are not included in the elements collection - var inputs = form.getElementsByTagName('input'); - for (var input, i = 0; input = inputs[i]; i++) { - if (input.form == form && input.type.toLowerCase() == 'image') { - name = input.name; - fnAppend(result, name, input.value); - fnAppend(result, name + '.x', '0'); - fnAppend(result, name + '.y', '0'); - } - } -}; - - -/** - * Adds the name/value pair to the map. - * @param {goog.structs.Map} map The map to add to. - * @param {string} name The name. - * @param {string} value The value. - * @private - */ -goog.dom.forms.addFormDataToMap_ = function(map, name, value) { - var array = map.get(name); - if (!array) { - array = []; - map.set(name, array); - } - array.push(value); -}; - - -/** - * Adds a name/value pair to an string buffer array in the form 'name=value'. - * @param {Array} sb The string buffer array for storing data. - * @param {string} name The name. - * @param {string} value The value. - * @private - */ -goog.dom.forms.addFormDataToStringBuffer_ = function(sb, name, value) { - sb.push(encodeURIComponent(name) + '=' + encodeURIComponent(value)); -}; - - -/** - * Whether the form has a file input. - * @param {HTMLFormElement} form The form. - * @return {boolean} Whether the form has a file input. - */ -goog.dom.forms.hasFileInput = function(form) { - var els = form.elements; - for (var el, i = 0; el = els[i]; i++) { - if (!el.disabled && el.type && el.type.toLowerCase() == 'file') { - return true; - } - } - return false; -}; - - -/** - * Enables or disables either all elements in a form or a single form element. - * @param {Element} el The element, either a form or an element within a form. - * @param {boolean} disabled Whether the element should be disabled. - */ -goog.dom.forms.setDisabled = function(el, disabled) { - // disable all elements in a form - if (el.tagName == 'FORM') { - var els = el.elements; - for (var i = 0; el = els[i]; i++) { - goog.dom.forms.setDisabled(el, disabled); - } - } else { - // makes sure to blur buttons, multi-selects, and any elements which - // maintain keyboard/accessibility focus when disabled - if (disabled == true) { - el.blur(); - } - el.disabled = disabled; - } -}; - - -/** - * Focuses, and optionally selects the content of, a form element. - * @param {Element} el The form element. - */ -goog.dom.forms.focusAndSelect = function(el) { - el.focus(); - if (el.select) { - el.select(); - } -}; - - -/** - * Whether a form element has a value. - * @param {Element} el The element. - * @return {boolean} Whether the form has a value. - */ -goog.dom.forms.hasValue = function(el) { - var value = goog.dom.forms.getValue(el); - return !!value; -}; - - -/** - * Whether a named form field has a value. - * @param {HTMLFormElement} form The form element. - * @param {string} name Name of an input to the form. - * @return {boolean} Whether the form has a value. - */ -goog.dom.forms.hasValueByName = function(form, name) { - var value = goog.dom.forms.getValueByName(form, name); - return !!value; -}; - - -/** - * Gets the current value of any element with a type. - * @param {Element} el The element. - * @return {string|Array.<string>|null} The current value of the element - * (or null). - */ -goog.dom.forms.getValue = function(el) { - var type = el.type; - if (!goog.isDef(type)) { - return null; - } - switch (type.toLowerCase()) { - case 'checkbox': - case 'radio': - return goog.dom.forms.getInputChecked_(el); - case 'select-one': - return goog.dom.forms.getSelectSingle_(el); - case 'select-multiple': - return goog.dom.forms.getSelectMultiple_(el); - default: - return goog.isDef(el.value) ? el.value : null; - } -}; - - -/** - * Alias for goog.dom.form.element.getValue - * @type {Function} - * @deprecated Use {@link goog.dom.forms.getValue} instead. - */ -goog.dom.$F = goog.dom.forms.getValue; - - -/** - * Returns the value of the named form field. In the case of radio buttons, - * returns the value of the checked button with the given name. - * - * @param {HTMLFormElement} form The form element. - * @param {string} name Name of an input to the form. - * - * @return {Array.<string>|string|null} The value of the form element, or - * null if the form element does not exist or has no value. - */ -goog.dom.forms.getValueByName = function(form, name) { - var els = form.elements[name]; - - if (els.type) { - return goog.dom.forms.getValue(els); - } else { - for (var i = 0; i < els.length; i++) { - var val = goog.dom.forms.getValue(els[i]); - if (val) { - return val; - } - } - - return null; - } -}; - - -/** - * Gets the current value of a checkable input element. - * @param {Element} el The element. - * @return {?string} The value of the form element (or null). - * @private - */ -goog.dom.forms.getInputChecked_ = function(el) { - return el.checked ? el.value : null; -}; - - -/** - * Gets the current value of a select-one element. - * @param {Element} el The element. - * @return {?string} The value of the form element (or null). - * @private - */ -goog.dom.forms.getSelectSingle_ = function(el) { - var selectedIndex = el.selectedIndex; - return selectedIndex >= 0 ? el.options[selectedIndex].value : null; -}; - - -/** - * Gets the current value of a select-multiple element. - * @param {Element} el The element. - * @return {Array.<string>?} The value of the form element (or null). - * @private - */ -goog.dom.forms.getSelectMultiple_ = function(el) { - var values = []; - for (var option, i = 0; option = el.options[i]; i++) { - if (option.selected) { - values.push(option.value); - } - } - return values.length ? values : null; -}; - - -/** - * Sets the current value of any element with a type. - * @param {Element} el The element. - * @param {*=} opt_value The value to give to the element, which will be coerced - * by the browser in the default case using toString. This value should be - * an array for setting the value of select multiple elements. - */ -goog.dom.forms.setValue = function(el, opt_value) { - var type = el.type; - if (goog.isDef(type)) { - switch (type.toLowerCase()) { - case 'checkbox': - case 'radio': - goog.dom.forms.setInputChecked_(el, - /** @type {string} */ (opt_value)); - break; - case 'select-one': - goog.dom.forms.setSelectSingle_(el, - /** @type {string} */ (opt_value)); - break; - case 'select-multiple': - goog.dom.forms.setSelectMultiple_(el, - /** @type {Array} */ (opt_value)); - break; - default: - el.value = goog.isDefAndNotNull(opt_value) ? opt_value : ''; - } - } -}; - - -/** - * Sets a checkable input element's checked property. - * #TODO(user): This seems potentially unintuitive since it doesn't set - * the value property but my hunch is that the primary use case is to check a - * checkbox, not to reset its value property. - * @param {Element} el The element. - * @param {string|boolean=} opt_value The value, sets the element checked if - * val is set. - * @private - */ -goog.dom.forms.setInputChecked_ = function(el, opt_value) { - el.checked = opt_value ? 'checked' : null; -}; - - -/** - * Sets the value of a select-one element. - * @param {Element} el The element. - * @param {string=} opt_value The value of the selected option element. - * @private - */ -goog.dom.forms.setSelectSingle_ = function(el, opt_value) { - // unset any prior selections - el.selectedIndex = -1; - if (goog.isString(opt_value)) { - for (var option, i = 0; option = el.options[i]; i++) { - if (option.value == opt_value) { - option.selected = true; - break; - } - } - } -}; - - -/** - * Sets the value of a select-multiple element. - * @param {Element} el The element. - * @param {Array.<string>|string=} opt_value The value of the selected option - * element(s). - * @private - */ -goog.dom.forms.setSelectMultiple_ = function(el, opt_value) { - // reset string opt_values as an array - if (goog.isString(opt_value)) { - opt_value = [opt_value]; - } - for (var option, i = 0; option = el.options[i]; i++) { - // we have to reset the other options to false for select-multiple - option.selected = false; - if (opt_value) { - for (var value, j = 0; value = opt_value[j]; j++) { - if (option.value == value) { - option.selected = true; - } - } - } - } -}; - diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/forms_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/forms_test.html.svn-base deleted file mode 100644 index 67570fd..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/forms_test.html.svn-base +++ /dev/null @@ -1,483 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2006 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.forms</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.forms'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - <!-- empty div to test against --> - <div id="testdiv1"></div> - - <form id="testform1" onsubmit="return false"> - - <!-- text input with one value --> - <input id="in1" name="in1" value="foo"> - - <!-- text inputs with two values --> - <input id="in2" name="in2" value="bar"> - <input id="in2" name="in2" value="baaz"> - - <!-- empty text input --> - <input id="in3" name="in3" value=""> - - <!-- password --> - <input id="pass" name="pass" type="password" value="bar"> - - <!-- textarea --> - <textarea id="textarea1" name="textarea">foo bar baz</textarea> - - <!-- select single --> - <select id="select1" name="select1"> - <option value="1" selected>one</option> - <option value="2">two</option> - </select> - - <!-- select multiple --> - <select id="select2" name="select2" multiple=true> - <option value="a" selected>A</option> - <option value="b">B</option> - <option value="c" selected>C</option> - </select> - - <!-- select no value --> - <select id="select3" name="select3"> - <option></option> - <option value="1">one</option> - <option value="2">two</option> - </select> - - <!-- checkboxes --> - <fieldset id="testfieldset1"> - <legend id="testlegend1">Checkboxes</legend> - <input id="checkbox1" type="checkbox" name="checkbox1" checked> - <input id="checkbox2" type="checkbox" name="checkbox2"> - </fieldset> - - <!-- radio buttons --> - <fieldset> - <legend>Radio Buttons</legend> - <input id="radio1" type="radio" name="radio" value="X" checked> - <input id="radio2" type="radio" name="radio" value="Y"> - </fieldset> - - <fieldset> - <legend>Radio Buttons</legend> - <input id="radio3" type="radio" name="radio2" value="X"> - <input id="radio4" type="radio" name="radio2" value="Y" checked> - </fieldset> - - <!-- button --> - <button id="button" name="button" type="button" value="button" onclick="testSetValueSelectMultiple()">button</button> - - <!-- submit --> - <input id="submit" type="submit" name="submit" value="submit"> - - <!-- reset --> - <input id="reset" type="reset" name="reset" value="reset"> - - </form> - - <form id="testform2"> - <input type="file" name="file"> - </form> - - <form id="testform3"> - <!-- text input --> - <input id="in4" name="in4"> - - <!-- textarea --> - <textarea id="textarea2" name="textarea"></textarea> - - <!-- select single --> - <select id="select4" name="select1"> - <option value="1">one</option> - <option value="2">two</option> - </select> - - <!-- select multiple --> - <select id="select5" name="select5" multiple=true> - <option value="a">A</option> - <option value="b">B</option> - <option value="c">C</option> - </select> - - <!-- radio --> - <input id="radio3" type="radio" name="radio3" value="Z"> - - <!-- checkbox --> - <input id="checkbox2" type="checkbox" name="checkbox2"> - - - <!-- select multiple no value --> - <select id="select6" name="select6" multiple=true> - <option value="a">A</option> - <option value="b">B</option> - </select> - - <!-- select with empty value --> - <select id="select7" name="select7"> - <option value="">Empty</option> - <option value="a">A</option> - <option value="b">B</option> - </select> - </form> - -<script> - - function testGetFormDataString() { - var el = goog.dom.getElement('testform1'); - var result = goog.dom.forms.getFormDataString(el); - assertEquals('in1=foo&in2=bar&in2=baaz&in3=&pass=bar&textarea=foo%20bar%20baz&select1=1&select2=a&select2=c&select3=&checkbox1=on&radio=X&radio2=Y', result); - } - - function testGetFormDataMap() { - var el = goog.dom.getElement('testform1'); - var result = goog.dom.forms.getFormDataMap(el); - - assertArrayEquals(['foo'], result.get('in1')); - assertArrayEquals(['bar', 'baaz'], result.get('in2')); - assertArrayEquals(['1'], result.get('select1')); - assertArrayEquals(['a', 'c'], result.get('select2')); - assertArrayEquals(['on'], result.get('checkbox1')); - assertUndefined(result.get('select6')); - assertUndefined(result.get('checkbox2')); - assertArrayEquals(['X'], result.get('radio')); - assertArrayEquals(['Y'], result.get('radio2')); - } - - function testHasFileInput() { - var el = goog.dom.getElement('testform1'); - assertFalse(goog.dom.forms.hasFileInput(el)); - el = goog.dom.getElement('testform2'); - assertTrue(goog.dom.forms.hasFileInput(el)); - } - - - function testGetValueOnAtypicalValueElements() { - var el = goog.dom.getElement('testdiv1'); - var result = goog.dom.forms.getValue(el); - assertNull(result); - var el = goog.dom.getElement('testfieldset1'); - var result = goog.dom.forms.getValue(el); - assertNull(result); - var el = goog.dom.getElement('testlegend1'); - var result = goog.dom.forms.getValue(el); - assertNull(result); - } - - function testHasValueInput() { - var el = goog.dom.getElement('in1'); - var result = goog.dom.forms.hasValue(el); - assertTrue(result); - } - - function testHasValueByNameInput() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.hasValueByName(form, 'in1'); - assertTrue(result); - } - - function testHasValueInputEmpty() { - var el = goog.dom.getElement('in3'); - var result = goog.dom.forms.hasValue(el); - assertFalse(result); - } - - function testHasValueByNameEmpty() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.hasValueByName(form, 'in3'); - assertFalse(result); - } - - function testHasValueRadio() { - var el = goog.dom.getElement('radio1'); - var result = goog.dom.forms.hasValue(el); - assertTrue(result); - } - - function testHasValueByNameRadio() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.hasValueByName(form, 'radio'); - assertTrue(result); - } - - function testHasValueRadioNotChecked() { - var el = goog.dom.getElement('radio2'); - var result = goog.dom.forms.hasValue(el); - assertFalse(result); - } - - function testHasValueByNameRadioNotChecked() { - var form = goog.dom.getElement('testform3'); - var result = goog.dom.forms.hasValueByName(form, 'radio3'); - assertFalse(result); - } - - function testHasValueSelectSingle() { - var el = goog.dom.getElement('select1'); - var result = goog.dom.forms.hasValue(el); - assertTrue(result); - } - - function testHasValueByNameSelectSingle() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.hasValueByName(form, 'select1'); - assertTrue(result); - } - - function testHasValueSelectMultiple() { - var el = goog.dom.getElement('select2'); - var result = goog.dom.forms.hasValue(el); - assertTrue(result); - } - - function testHasValueByNameSelectMultiple() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.hasValueByName(form, 'select2'); - assertTrue(result); - } - - function testHasValueSelectNotSelected() { - // select without value - var el = goog.dom.getElement('select3'); - var result = goog.dom.forms.hasValue(el); - assertFalse(result); - } - - function testHasValueByNameSelectNotSelected() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.hasValueByName(form, 'select3'); - assertFalse(result); - } - - function testHasValueSelectMultipleNotSelected() { - var el = goog.dom.getElement('select6'); - var result = goog.dom.forms.hasValue(el); - assertFalse(result); - } - - function testHasValueByNameSelectMultipleNotSelected() { - var form = goog.dom.getElement('testform3'); - var result = goog.dom.forms.hasValueByName(form, 'select6'); - assertFalse(result); - } - - // TODO(user): make this a meaningful selenium test - function testSetDisabledFalse() { - } - function testSetDisabledTrue() { - } - - // TODO(user): make this a meaningful selenium test - function testFocusAndSelect() { - var el = goog.dom.getElement('in1'); - goog.dom.forms.focusAndSelect(el); - } - - function testGetValueInput() { - var el = goog.dom.getElement('in1'); - var result = goog.dom.forms.getValue(el); - assertEquals('foo', result); - } - - function testSetValueInput() { - var el = goog.dom.getElement('in3'); - goog.dom.forms.setValue(el, 'foo'); - assertEquals('foo', goog.dom.forms.getValue(el)); - - goog.dom.forms.setValue(el, 3500); - assertEquals('3500', goog.dom.forms.getValue(el)); - - goog.dom.forms.setValue(el, 0); - assertEquals('0', goog.dom.forms.getValue(el)); - - goog.dom.forms.setValue(el, null); - assertEquals('', goog.dom.forms.getValue(el)); - - goog.dom.forms.setValue(el, undefined); - assertEquals('', goog.dom.forms.getValue(el)); - - goog.dom.forms.setValue(el, false); - assertEquals('false', goog.dom.forms.getValue(el)); - - goog.dom.forms.setValue(el, {}); - assertEquals({}.toString(), goog.dom.forms.getValue(el)); - - goog.dom.forms.setValue(el, { - toString: function() { - return 'test'; - } - }); - assertEquals('test', goog.dom.forms.getValue(el)); - - // unset - goog.dom.forms.setValue(el); - assertEquals('', goog.dom.forms.getValue(el)); - } - - function testGetValuePassword() { - var el = goog.dom.getElement('pass'); - var result = goog.dom.forms.getValue(el); - assertEquals('bar', result); - } - - function testGetValueByNamePassword() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.getValueByName(form, 'pass'); - assertEquals('bar', result); - } - - function testGetValueTextarea() { - var el = goog.dom.getElement('textarea1'); - var result = goog.dom.forms.getValue(el); - assertEquals('foo bar baz', result); - } - - function testGetValueByNameTextarea() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.getValueByName(form, 'textarea1'); - assertEquals('foo bar baz', result); - } - - function testSetValueTextarea() { - var el = goog.dom.getElement('textarea2'); - goog.dom.forms.setValue(el, 'foo bar baz'); - var result = goog.dom.forms.getValue(el); - assertEquals('foo bar baz', result); - } - - function testGetValueSelectSingle() { - var el = goog.dom.getElement('select1'); - var result = goog.dom.forms.getValue(el); - assertEquals('1', result); - } - - function testGetValueByNameSelectSingle() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.getValueByName(form, 'select1'); - assertEquals('1', result); - } - - function testSetValueSelectSingle() { - var el = goog.dom.getElement('select4'); - goog.dom.forms.setValue(el, '2'); - var result = goog.dom.forms.getValue(el); - assertEquals('2', result); - // unset - goog.dom.forms.setValue(el); - var result = goog.dom.forms.getValue(el); - assertNull(result); - } - - function testSetValueSelectSingleEmptyString() { - var el = goog.dom.getElement('select7'); - // unset - goog.dom.forms.setValue(el); - var result = goog.dom.forms.getValue(el); - assertNull(result); - goog.dom.forms.setValue(el, ''); - result = goog.dom.forms.getValue(el); - assertEquals('', result); - } - - function testGetValueSelectMultiple() { - var el = goog.dom.getElement('select2'); - var result = goog.dom.forms.getValue(el); - assertArrayEquals(['a', 'c'], result); - } - - function testGetValueSelectMultipleNotSelected() { - var el = goog.dom.getElement('select6'); - var result = goog.dom.forms.getValue(el); - assertNull(result); - } - - function testGetValueByNameSelectMultiple() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.getValueByName(form, 'select2'); - assertArrayEquals(['a', 'c'], result); - } - - function testSetValueSelectMultiple() { - var el = goog.dom.getElement('select5'); - goog.dom.forms.setValue(el, ['a', 'c']); - var result = goog.dom.forms.getValue(el); - assertArrayEquals(['a', 'c'], result); - - goog.dom.forms.setValue(el, 'a'); - var result = goog.dom.forms.getValue(el); - assertArrayEquals(['a'], result); - - // unset - goog.dom.forms.setValue(el); - var result = goog.dom.forms.getValue(el); - assertNull(result); - } - - function testGetValueCheckbox() { - var el = goog.dom.getElement('checkbox1'); - var result = goog.dom.forms.getValue(el); - assertEquals('on', result); - var el = goog.dom.getElement('checkbox2'); - var result = goog.dom.forms.getValue(el); - assertNull(result); - } - - function testGetValueByNameCheckbox() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.getValueByName(form, 'checkbox1'); - assertEquals('on', result); - result = goog.dom.forms.getValueByName(form, 'checkbox2'); - assertNull(result); - } - - function testGetValueRadio() { - var el = goog.dom.getElement('radio1'); - var result = goog.dom.forms.getValue(el); - assertEquals('X', result); - var el = goog.dom.getElement('radio2'); - var result = goog.dom.forms.getValue(el); - assertNull(result); - } - - function testGetValueByNameRadio() { - var form = goog.dom.getElement('testform1'); - var result = goog.dom.forms.getValueByName(form, 'radio'); - assertEquals('X', result); - - result = goog.dom.forms.getValueByName(form, 'radio2'); - assertEquals('Y', result); - } - - function testGetValueButton() { - var el = goog.dom.getElement('button'); - var result = goog.dom.forms.getValue(el); - assertEquals('button', result); - } - - function testGetValueSubmit() { - var el = goog.dom.getElement('submit'); - var result = goog.dom.forms.getValue(el); - assertEquals('submit', result); - } - - function testGetValueReset() { - var el = goog.dom.getElement('reset'); - var result = goog.dom.forms.getValue(el); - assertEquals('reset', result); - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iframe.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iframe.js.svn-base deleted file mode 100644 index 71b3df4..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iframe.js.svn-base +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for creating and working with iframes - * cross-browser. - * @author gboyer@google.com (Garry Boyer) - */ - - -goog.provide('goog.dom.iframe'); - -goog.require('goog.dom'); - - -/** - * Safe source for a blank iframe. - * - * Intentionally not about:blank, which gives mixed content warnings in IE6 - * over HTTPS. - * - * @type {string} - */ -goog.dom.iframe.BLANK_SOURCE = 'javascript:""'; - - -/** - * Styles to help ensure an undecorated iframe. - * @type {string} - * @private - */ -goog.dom.iframe.STYLES_ = 'border:0;vertical-align:bottom;'; - - -/** - * Creates a completely blank iframe element. - * - * The iframe will not caused mixed-content warnings for IE6 under HTTPS. - * The iframe will also have no borders or padding, so that the styled width - * and height will be the actual width and height of the iframe. - * - * This function currently only attempts to create a blank iframe. There - * are no guarantees to the contents of the iframe or whether it is rendered - * in quirks mode. - * - * @param {goog.dom.DomHelper} domHelper The dom helper to use. - * @param {string=} opt_styles CSS styles for the iframe. - * @return {!HTMLIFrameElement} A completely blank iframe. - */ -goog.dom.iframe.createBlank = function(domHelper, opt_styles) { - return /** @type {!HTMLIFrameElement} */ (domHelper.createDom('iframe', { - 'frameborder': 0, - // Since iframes are inline elements, we must align to bottom to - // compensate for the line descent. - 'style': goog.dom.iframe.STYLES_ + (opt_styles || ''), - 'src': goog.dom.iframe.BLANK_SOURCE - })); -}; - - -/** - * Writes the contents of a blank iframe that has already been inserted - * into the document. - * @param {!HTMLIFrameElement} iframe An iframe with no contents, such as - * one created by goog.dom.iframe.createBlank, but already appended to - * a parent document. - * @param {string} content Content to write to the iframe, from doctype to - * the HTML close tag. - */ -goog.dom.iframe.writeContent = function(iframe, content) { - var doc = goog.dom.getFrameContentDocument(iframe); - doc.open(); - doc.write(content); - doc.close(); -}; - - -// TODO(gboyer): Provide a higher-level API for the most common use case, so -// that you can just provide a list of stylesheets and some content HTML. -/** - * Creates a same-domain iframe containing preloaded content. - * - * This is primarily useful for DOM sandboxing. One use case is to embed - * a trusted Javascript app with potentially conflicting CSS styles. The - * second case is to reduce the cost of layout passes by the browser -- for - * example, you can perform sandbox sizing of characters in an iframe while - * manipulating a heavy DOM in the main window. The iframe and parent frame - * can access each others' properties and functions without restriction. - * - * @param {!Element} parentElement The parent element in which to append the - * iframe. - * @param {string=} opt_headContents Contents to go into the iframe's head. - * @param {string=} opt_bodyContents Contents to go into the iframe's body. - * @param {string=} opt_styles CSS styles for the iframe itself, before adding - * to the parent element. - * @param {boolean=} opt_quirks Whether to use quirks mode (false by default). - * @return {HTMLIFrameElement} An iframe that has the specified contents. - */ -goog.dom.iframe.createWithContent = function( - parentElement, opt_headContents, opt_bodyContents, opt_styles, opt_quirks) { - var domHelper = goog.dom.getDomHelper(parentElement); - // Generate the HTML content. - var contentBuf = []; - - if (!opt_quirks) { - contentBuf.push('<!DOCTYPE html>'); - } - contentBuf.push('<html><head>', opt_headContents, '</head><body>', - opt_bodyContents, '</body></html>'); - - var iframe = goog.dom.iframe.createBlank(domHelper, opt_styles); - - // Cannot manipulate iframe content until it is in a document. - parentElement.appendChild(iframe); - goog.dom.iframe.writeContent(iframe, contentBuf.join('')); - - return iframe; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iframe_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iframe_test.html.svn-base deleted file mode 100644 index 5a1fcc6..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iframe_test.html.svn-base +++ /dev/null @@ -1,88 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- - All Rights Reserved. - -Author: gboyer@google.com (Garrett Boyer) ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.iframe</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.iframe'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> - -</head> -<body> - <div style="border: 1px solid black; padding: 4px"> - <div> - Blank Iframe - The below area should be completely white. - </div> - <!-- - - Simple table to measure the exterior size of the iframe. A table is - - used because it is sensitive to problems with iframe margins and - - vertical alignment. - --> - <table cellpadding="0" cellspacing="0"> - <tr><td> - <div id="blank"> - </div> - </td></tr> - </table> - </div> - - <div id="sandbox"></div> - -<script> - - var domHelper = goog.dom.getDomHelper(); - var sandbox = domHelper.getElement('sandbox'); - - function setUp() { - goog.dom.removeChildren(sandbox); - } - - function testCreateWithContent() { - var iframe = goog.dom.iframe.createWithContent(sandbox, - '<title>Foo Title</title>', '<div id="blah">Test</div>', - 'position: absolute', - false /* opt_quirks */); - - var doc = goog.dom.getFrameContentDocument(iframe); - assertNotNull(doc.getElementById('blah')); - assertEquals('Foo Title', doc.title); - assertEquals('absolute', iframe.style.position); - }; - - function testCreateBlankYieldsIframeWithNoBorderOrPadding() { - var iframe = goog.dom.iframe.createBlank(domHelper); - iframe.style.width = '350px'; - iframe.style.height = '250px'; - var blankElement = domHelper.getElement('blank'); - blankElement.appendChild(iframe); - assertEquals( - 'Width should be as styled: no extra borders, padding, etc.', - 350, blankElement.offsetWidth); - assertEquals( - 'Height should be as styled: no extra borders, padding, etc.', - 250, blankElement.offsetHeight); - }; - - function testCreateBlankWithStyles() { - var iframe = goog.dom.iframe.createBlank(domHelper, 'position:absolute'); - assertEquals('absolute', iframe.style.position); - assertEquals('bottom', iframe.style.verticalAlign); - }; -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iter.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iter.js.svn-base deleted file mode 100644 index 0224af3..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iter.js.svn-base +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Iterators over DOM nodes. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.iter.AncestorIterator'); -goog.provide('goog.dom.iter.ChildIterator'); -goog.provide('goog.dom.iter.SiblingIterator'); - -goog.require('goog.iter.Iterator'); -goog.require('goog.iter.StopIteration'); - - - -/** - * Iterator over a Node's siblings. - * @param {Node} node The node to start with. - * @param {boolean=} opt_includeNode Whether to return the given node as the - * first return value from next. - * @param {boolean=} opt_reverse Whether to traverse siblings in reverse - * document order. - * @constructor - * @extends {goog.iter.Iterator} - */ -goog.dom.iter.SiblingIterator = function(node, opt_includeNode, opt_reverse) { - /** - * The current node, or null if iteration is finished. - * @type {Node} - * @private - */ - this.node_ = node; - - /** - * Whether to iterate in reverse. - * @type {boolean} - * @private - */ - this.reverse_ = !!opt_reverse; - - if (node && !opt_includeNode) { - this.next(); - } -}; -goog.inherits(goog.dom.iter.SiblingIterator, goog.iter.Iterator); - - -/** @override */ -goog.dom.iter.SiblingIterator.prototype.next = function() { - var node = this.node_; - if (!node) { - throw goog.iter.StopIteration; - } - this.node_ = this.reverse_ ? node.previousSibling : node.nextSibling; - return node; -}; - - - -/** - * Iterator over an Element's children. - * @param {Element} element The element to iterate over. - * @param {boolean=} opt_reverse Optionally traverse children from last to - * first. - * @param {number=} opt_startIndex Optional starting index. - * @constructor - * @extends {goog.dom.iter.SiblingIterator} - */ -goog.dom.iter.ChildIterator = function(element, opt_reverse, opt_startIndex) { - if (!goog.isDef(opt_startIndex)) { - opt_startIndex = opt_reverse && element.childNodes.length ? - element.childNodes.length - 1 : 0; - } - goog.dom.iter.SiblingIterator.call(this, element.childNodes[opt_startIndex], - true, opt_reverse); -}; -goog.inherits(goog.dom.iter.ChildIterator, goog.dom.iter.SiblingIterator); - - - -/** - * Iterator over a Node's ancestors, stopping after the document body. - * @param {Node} node The node to start with. - * @param {boolean=} opt_includeNode Whether to return the given node as the - * first return value from next. - * @constructor - * @extends {goog.iter.Iterator} - */ -goog.dom.iter.AncestorIterator = function(node, opt_includeNode) { - /** - * The current node, or null if iteration is finished. - * @type {Node} - * @private - */ - this.node_ = node; - - if (node && !opt_includeNode) { - this.next(); - } -}; -goog.inherits(goog.dom.iter.AncestorIterator, goog.iter.Iterator); - - -/** @override */ -goog.dom.iter.AncestorIterator.prototype.next = function() { - var node = this.node_; - if (!node) { - throw goog.iter.StopIteration; - } - this.node_ = node.parentNode; - return node; -}; - diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iter_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iter_test.html.svn-base deleted file mode 100644 index 00485bd..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/iter_test.html.svn-base +++ /dev/null @@ -1,97 +0,0 @@ -<!DOCTYPE html> -<html id="html"> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.iter</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom.iter.AncestorIterator'); - goog.require('goog.dom.iter.ChildIterator'); - goog.require('goog.dom.iter.SiblingIterator'); - goog.require('goog.dom.NodeType'); - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body id="body"> - <div id="test">abc<br id="br">def</div> - - -<script> -var test = goog.dom.getElement('test'); -var br = goog.dom.getElement('br'); - -function testNextSibling() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.SiblingIterator(test.firstChild), - ['#br', 'def']); -} - -function testNextSiblingInclusive() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.SiblingIterator(test.firstChild, true), - ['abc', '#br', 'def']); -} - -function testPreviousSibling() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.SiblingIterator(test.lastChild, false, true), - ['#br', 'abc']); -} - -function testPreviousSiblingInclusive() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.SiblingIterator(test.lastChild, true, true), - ['def', '#br', 'abc']); -} - -function testChildIterator() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.ChildIterator(test), - ['abc', '#br', 'def']); -} - -function testChildIteratorIndex() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.ChildIterator(test, false, 1), - ['#br', 'def']); -} - -function testChildIteratorReverse() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.ChildIterator(test, true), - ['def', '#br', 'abc']); -} - -function testEmptyChildIteratorReverse() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.ChildIterator(br, true), []); -} - -function testChildIteratorIndexReverse() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.ChildIterator(test, true, 1), - ['#br', 'abc']); -} - -function testAncestorIterator() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.AncestorIterator(br), - ['#test', '#body', '#html', goog.dom.NodeType.DOCUMENT]); -} - -function testAncestorIteratorInclusive() { - goog.testing.dom.assertNodesMatch( - new goog.dom.iter.AncestorIterator(br, true), - ['#br', '#test', '#body', '#html', goog.dom.NodeType.DOCUMENT]); -}; - -</script> -</body> -</html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/multirange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/multirange.js.svn-base deleted file mode 100644 index 5eaa392..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/multirange.js.svn-base +++ /dev/null @@ -1,519 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for working with W3C multi-part ranges. - * - * @author robbyw@google.com (Robby Walker) - */ - - -goog.provide('goog.dom.MultiRange'); -goog.provide('goog.dom.MultiRangeIterator'); - -goog.require('goog.array'); -goog.require('goog.debug.Logger'); -goog.require('goog.dom.AbstractMultiRange'); -goog.require('goog.dom.AbstractRange'); -goog.require('goog.dom.RangeIterator'); -goog.require('goog.dom.RangeType'); -goog.require('goog.dom.SavedRange'); -goog.require('goog.dom.TextRange'); -goog.require('goog.iter.StopIteration'); - - - -/** - * Creates a new multi part range with no properties. Do not use this - * constructor: use one of the goog.dom.Range.createFrom* methods instead. - * @constructor - * @extends {goog.dom.AbstractMultiRange} - */ -goog.dom.MultiRange = function() { - /** - * Array of browser sub-ranges comprising this multi-range. - * @type {Array.<Range>} - * @private - */ - this.browserRanges_ = []; - - /** - * Lazily initialized array of range objects comprising this multi-range. - * @type {Array.<goog.dom.TextRange>} - * @private - */ - this.ranges_ = []; - - /** - * Lazily computed sorted version of ranges_, sorted by start point. - * @type {Array.<goog.dom.TextRange>?} - * @private - */ - this.sortedRanges_ = null; - - /** - * Lazily computed container node. - * @type {Node} - * @private - */ - this.container_ = null; -}; -goog.inherits(goog.dom.MultiRange, goog.dom.AbstractMultiRange); - - -/** - * Creates a new range wrapper from the given browser selection object. Do not - * use this method directly - please use goog.dom.Range.createFrom* instead. - * @param {Selection} selection The browser selection object. - * @return {goog.dom.MultiRange} A range wrapper object. - */ -goog.dom.MultiRange.createFromBrowserSelection = function(selection) { - var range = new goog.dom.MultiRange(); - for (var i = 0, len = selection.rangeCount; i < len; i++) { - range.browserRanges_.push(selection.getRangeAt(i)); - } - return range; -}; - - -/** - * Creates a new range wrapper from the given browser ranges. Do not - * use this method directly - please use goog.dom.Range.createFrom* instead. - * @param {Array.<Range>} browserRanges The browser ranges. - * @return {goog.dom.MultiRange} A range wrapper object. - */ -goog.dom.MultiRange.createFromBrowserRanges = function(browserRanges) { - var range = new goog.dom.MultiRange(); - range.browserRanges_ = goog.array.clone(browserRanges); - return range; -}; - - -/** - * Creates a new range wrapper from the given goog.dom.TextRange objects. Do - * not use this method directly - please use goog.dom.Range.createFrom* instead. - * @param {Array.<goog.dom.TextRange>} textRanges The text range objects. - * @return {goog.dom.MultiRange} A range wrapper object. - */ -goog.dom.MultiRange.createFromTextRanges = function(textRanges) { - var range = new goog.dom.MultiRange(); - range.ranges_ = textRanges; - range.browserRanges_ = goog.array.map(textRanges, function(range) { - return range.getBrowserRangeObject(); - }); - return range; -}; - - -/** - * Logging object. - * @type {goog.debug.Logger} - * @private - */ -goog.dom.MultiRange.prototype.logger_ = - goog.debug.Logger.getLogger('goog.dom.MultiRange'); - - -// Method implementations - - -/** - * Clears cached values. Should be called whenever this.browserRanges_ is - * modified. - * @private - */ -goog.dom.MultiRange.prototype.clearCachedValues_ = function() { - this.ranges_ = []; - this.sortedRanges_ = null; - this.container_ = null; -}; - - -/** - * @return {goog.dom.MultiRange} A clone of this range. - */ -goog.dom.MultiRange.prototype.clone = function() { - return goog.dom.MultiRange.createFromBrowserRanges(this.browserRanges_); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getType = function() { - return goog.dom.RangeType.MULTI; -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getBrowserRangeObject = function() { - // NOTE(robbyw): This method does not make sense for multi-ranges. - if (this.browserRanges_.length > 1) { - this.logger_.warning( - 'getBrowserRangeObject called on MultiRange with more than 1 range'); - } - return this.browserRanges_[0]; -}; - - -/** @override */ -goog.dom.MultiRange.prototype.setBrowserRangeObject = function(nativeRange) { - // TODO(robbyw): Look in to adding setBrowserSelectionObject. - return false; -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getTextRangeCount = function() { - return this.browserRanges_.length; -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getTextRange = function(i) { - if (!this.ranges_[i]) { - this.ranges_[i] = goog.dom.TextRange.createFromBrowserRange( - this.browserRanges_[i]); - } - return this.ranges_[i]; -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getContainer = function() { - if (!this.container_) { - var nodes = []; - for (var i = 0, len = this.getTextRangeCount(); i < len; i++) { - nodes.push(this.getTextRange(i).getContainer()); - } - this.container_ = goog.dom.findCommonAncestor.apply(null, nodes); - } - return this.container_; -}; - - -/** - * @return {Array.<goog.dom.TextRange>} An array of sub-ranges, sorted by start - * point. - */ -goog.dom.MultiRange.prototype.getSortedRanges = function() { - if (!this.sortedRanges_) { - this.sortedRanges_ = this.getTextRanges(); - this.sortedRanges_.sort(function(a, b) { - var aStartNode = a.getStartNode(); - var aStartOffset = a.getStartOffset(); - var bStartNode = b.getStartNode(); - var bStartOffset = b.getStartOffset(); - - if (aStartNode == bStartNode && aStartOffset == bStartOffset) { - return 0; - } - - return goog.dom.Range.isReversed(aStartNode, aStartOffset, bStartNode, - bStartOffset) ? 1 : -1; - }); - } - return this.sortedRanges_; -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getStartNode = function() { - return this.getSortedRanges()[0].getStartNode(); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getStartOffset = function() { - return this.getSortedRanges()[0].getStartOffset(); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getEndNode = function() { - // NOTE(robbyw): This may return the wrong node if any subranges overlap. - return goog.array.peek(this.getSortedRanges()).getEndNode(); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getEndOffset = function() { - // NOTE(robbyw): This may return the wrong value if any subranges overlap. - return goog.array.peek(this.getSortedRanges()).getEndOffset(); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.isRangeInDocument = function() { - return goog.array.every(this.getTextRanges(), function(range) { - return range.isRangeInDocument(); - }); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.isCollapsed = function() { - return this.browserRanges_.length == 0 || - this.browserRanges_.length == 1 && this.getTextRange(0).isCollapsed(); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getText = function() { - return goog.array.map(this.getTextRanges(), function(range) { - return range.getText(); - }).join(''); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getHtmlFragment = function() { - return this.getValidHtml(); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getValidHtml = function() { - // NOTE(robbyw): This does not behave well if the sub-ranges overlap. - return goog.array.map(this.getTextRanges(), function(range) { - return range.getValidHtml(); - }).join(''); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.getPastableHtml = function() { - // TODO(robbyw): This should probably do something smart like group TR and TD - // selections in to the same table. - return this.getValidHtml(); -}; - - -/** @override */ -goog.dom.MultiRange.prototype.__iterator__ = function(opt_keys) { - return new goog.dom.MultiRangeIterator(this); -}; - - -// RANGE ACTIONS - - -/** @override */ -goog.dom.MultiRange.prototype.select = function() { - var selection = goog.dom.AbstractRange.getBrowserSelectionForWindow( - this.getWindow()); - selection.removeAllRanges(); - for (var i = 0, len = this.getTextRangeCount(); i < len; i++) { - selection.addRange(this.getTextRange(i).getBrowserRangeObject()); - } -}; - - -/** @override */ -goog.dom.MultiRange.prototype.removeContents = function() { - goog.array.forEach(this.getTextRanges(), function(range) { - range.removeContents(); - }); -}; - - -// SAVE/RESTORE - - -/** @override */ -goog.dom.MultiRange.prototype.saveUsingDom = function() { - return new goog.dom.DomSavedMultiRange_(this); -}; - - -// RANGE MODIFICATION - - -/** - * Collapses this range to a single point, either the first or last point - * depending on the parameter. This will result in the number of ranges in this - * multi range becoming 1. - * @param {boolean} toAnchor Whether to collapse to the anchor. - */ -goog.dom.MultiRange.prototype.collapse = function(toAnchor) { - if (!this.isCollapsed()) { - var range = toAnchor ? this.getTextRange(0) : this.getTextRange( - this.getTextRangeCount() - 1); - - this.clearCachedValues_(); - range.collapse(toAnchor); - this.ranges_ = [range]; - this.sortedRanges_ = [range]; - this.browserRanges_ = [range.getBrowserRangeObject()]; - } -}; - - -// SAVED RANGE OBJECTS - - - -/** - * A SavedRange implementation using DOM endpoints. - * @param {goog.dom.MultiRange} range The range to save. - * @constructor - * @extends {goog.dom.SavedRange} - * @private - */ -goog.dom.DomSavedMultiRange_ = function(range) { - /** - * Array of saved ranges. - * @type {Array.<goog.dom.SavedRange>} - * @private - */ - this.savedRanges_ = goog.array.map(range.getTextRanges(), function(range) { - return range.saveUsingDom(); - }); -}; -goog.inherits(goog.dom.DomSavedMultiRange_, goog.dom.SavedRange); - - -/** - * @return {goog.dom.MultiRange} The restored range. - */ -goog.dom.DomSavedMultiRange_.prototype.restoreInternal = function() { - var ranges = goog.array.map(this.savedRanges_, function(savedRange) { - return savedRange.restore(); - }); - return goog.dom.MultiRange.createFromTextRanges(ranges); -}; - - -/** @override */ -goog.dom.DomSavedMultiRange_.prototype.disposeInternal = function() { - goog.dom.DomSavedMultiRange_.superClass_.disposeInternal.call(this); - - goog.array.forEach(this.savedRanges_, function(savedRange) { - savedRange.dispose(); - }); - delete this.savedRanges_; -}; - - -// RANGE ITERATION - - - -/** - * Subclass of goog.dom.TagIterator that iterates over a DOM range. It - * adds functions to determine the portion of each text node that is selected. - * - * @param {goog.dom.MultiRange} range The range to traverse. - * @constructor - * @extends {goog.dom.RangeIterator} - */ -goog.dom.MultiRangeIterator = function(range) { - if (range) { - this.iterators_ = goog.array.map( - range.getSortedRanges(), - function(r) { - return goog.iter.toIterator(r); - }); - } - - goog.dom.RangeIterator.call( - this, range ? this.getStartNode() : null, false); -}; -goog.inherits(goog.dom.MultiRangeIterator, goog.dom.RangeIterator); - - -/** - * The list of range iterators left to traverse. - * @type {Array.<goog.dom.RangeIterator>?} - * @private - */ -goog.dom.MultiRangeIterator.prototype.iterators_ = null; - - -/** - * The index of the current sub-iterator being traversed. - * @type {number} - * @private - */ -goog.dom.MultiRangeIterator.prototype.currentIdx_ = 0; - - -/** @override */ -goog.dom.MultiRangeIterator.prototype.getStartTextOffset = function() { - return this.iterators_[this.currentIdx_].getStartTextOffset(); -}; - - -/** @override */ -goog.dom.MultiRangeIterator.prototype.getEndTextOffset = function() { - return this.iterators_[this.currentIdx_].getEndTextOffset(); -}; - - -/** @override */ -goog.dom.MultiRangeIterator.prototype.getStartNode = function() { - return this.iterators_[0].getStartNode(); -}; - - -/** @override */ -goog.dom.MultiRangeIterator.prototype.getEndNode = function() { - return goog.array.peek(this.iterators_).getEndNode(); -}; - - -/** @override */ -goog.dom.MultiRangeIterator.prototype.isLast = function() { - return this.iterators_[this.currentIdx_].isLast(); -}; - - -/** @override */ -goog.dom.MultiRangeIterator.prototype.next = function() { - /** @preserveTry */ - try { - var it = this.iterators_[this.currentIdx_]; - var next = it.next(); - this.setPosition(it.node, it.tagType, it.depth); - return next; - } catch (ex) { - if (ex !== goog.iter.StopIteration || - this.iterators_.length - 1 == this.currentIdx_) { - throw ex; - } else { - // In case we got a StopIteration, increment counter and try again. - this.currentIdx_++; - return this.next(); - } - } -}; - - -/** - * Replaces this iterator's values with values from another. - * @param {goog.dom.MultiRangeIterator} other The iterator to copy. - * @protected - */ -goog.dom.MultiRangeIterator.prototype.copyFrom = function(other) { - this.iterators_ = goog.array.clone(other.iterators_); - goog.dom.MultiRangeIterator.superClass_.copyFrom.call(this, other); -}; - - -/** - * @return {goog.dom.MultiRangeIterator} An identical iterator. - */ -goog.dom.MultiRangeIterator.prototype.clone = function() { - var copy = new goog.dom.MultiRangeIterator(null); - copy.copyFrom(this); - return copy; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/multirange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/multirange_test.html.svn-base deleted file mode 100644 index f82fc50..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/multirange_test.html.svn-base +++ /dev/null @@ -1,67 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- - -Author: robbyw@google.com (Robby Walker) ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.MultiRange</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.MultiRange'); - goog.require('goog.dom.Range'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - <div id="test"> - <div id="test1">abc</div> - <div id="test2">defghi</div> - </div> - -<script> - var range; - function setUp() { - range = new goog.dom.MultiRange.createFromTextRanges([ - goog.dom.Range.createFromNodeContents(goog.dom.getElement('test2')), - goog.dom.Range.createFromNodeContents(goog.dom.getElement('test1')) - ]); - } - - function testStartAndEnd() { - assertEquals(goog.dom.getElement('test1').firstChild, range.getStartNode()); - assertEquals(0, range.getStartOffset()); - assertEquals(goog.dom.getElement('test2').firstChild, range.getEndNode()); - assertEquals(6, range.getEndOffset()); - } - - function testStartAndEndIterator() { - var it = goog.iter.toIterator(range); - assertEquals(goog.dom.getElement('test1').firstChild, it.getStartNode()); - assertEquals(0, it.getStartTextOffset()); - assertEquals(goog.dom.getElement('test2').firstChild, it.getEndNode()); - assertEquals(3, it.getEndTextOffset()); - - it.next(); - it.next(); - assertEquals(6, it.getEndTextOffset()); - } - - function testIteration() { - var tags = goog.iter.toArray(range); - assertEquals(2, tags.length); - - assertEquals(goog.dom.getElement('test1').firstChild, tags[0]); - assertEquals(goog.dom.getElement('test2').firstChild, tags[1]); - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeiterator.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeiterator.js.svn-base deleted file mode 100644 index 7716b41..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeiterator.js.svn-base +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Iterator subclass for DOM tree traversal. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.NodeIterator'); - -goog.require('goog.dom.TagIterator'); - - - -/** - * A DOM tree traversal iterator. - * - * Starting with the given node, the iterator walks the DOM in order, reporting - * events for each node. The iterator acts as a prefix iterator: - * - * <pre> - * <div>1<span>2</span>3</div> - * </pre> - * - * Will return the following nodes: - * - * <code>[div, 1, span, 2, 3]</code> - * - * With the following depths - * - * <code>[1, 1, 2, 2, 1]</code> - * - * Imagining <code>|</code> represents iterator position, the traversal stops at - * each of the following locations: - * - * <pre><div>|1|<span>|2|</span>3|</div></pre> - * - * The iterator can also be used in reverse mode, which will return the nodes - * and states in the opposite order. The depths will be slightly different - * since, like in normal mode, the depth is computed *after* the last move. - * - * Lastly, it is possible to create an iterator that is unconstrained, meaning - * that it will continue iterating until the end of the document instead of - * until exiting the start node. - * - * @param {Node=} opt_node The start node. Defaults to an empty iterator. - * @param {boolean=} opt_reversed Whether to traverse the tree in reverse. - * @param {boolean=} opt_unconstrained Whether the iterator is not constrained - * to the starting node and its children. - * @param {number=} opt_depth The starting tree depth. - * @constructor - * @extends {goog.dom.TagIterator} - */ -goog.dom.NodeIterator = function(opt_node, opt_reversed, - opt_unconstrained, opt_depth) { - goog.dom.TagIterator.call(this, opt_node, opt_reversed, opt_unconstrained, - null, opt_depth); -}; -goog.inherits(goog.dom.NodeIterator, goog.dom.TagIterator); - - -/** - * Moves to the next position in the DOM tree. - * @return {Node} Returns the next node, or throws a goog.iter.StopIteration - * exception if the end of the iterator's range has been reached. - */ -goog.dom.NodeIterator.prototype.next = function() { - do { - goog.dom.NodeIterator.superClass_.next.call(this); - } while (this.isEndTag()); - - return this.node; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeiterator_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeiterator_test.html.svn-base deleted file mode 100644 index cea874e..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeiterator_test.html.svn-base +++ /dev/null @@ -1,49 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>goog.dom.NodeIterator Tests</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom.NodeIterator'); - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - -<!-- - The next line goes past 80 characters to avoid ambiguity with - newlines as text nodes ---> -<div id="test"><a href="#" id="a1">T<b id="b1">e</b>xt</a><span id="span1"></span><p id="p1">Text</p></div> -<ul id="test2"><li id="li1">Not<li id="li2">Closed</ul> - -<script> - function testBasic() { - goog.testing.dom.assertNodesMatch( - new goog.dom.NodeIterator(goog.dom.getElement('test')), - ['#test', '#a1', 'T', '#b1', 'e', 'xt', '#span1', '#p1', 'Text']); - } - - function testUnclosed() { - goog.testing.dom.assertNodesMatch( - new goog.dom.NodeIterator(goog.dom.getElement('test2')), - ['#test2', '#li1', 'Not', '#li2', 'Closed']); - } - - function testReverse() { - goog.testing.dom.assertNodesMatch( - new goog.dom.NodeIterator(goog.dom.getElement('test'), true), - ['Text', '#p1', '#span1', 'xt', 'e', '#b1', 'T', '#a1', '#test']); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeoffset.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeoffset.js.svn-base deleted file mode 100644 index 9180796..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeoffset.js.svn-base +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2005 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Object to store the offset from one node to another in a way - * that works on any similar DOM structure regardless of whether it is the same - * actual nodes. - * - */ - -goog.provide('goog.dom.NodeOffset'); - -goog.require('goog.Disposable'); -goog.require('goog.dom.TagName'); - - - -/** - * Object to store the offset from one node to another in a way that works on - * any similar DOM structure regardless of whether it is the same actual nodes. - * @param {Node} node The node to get the offset for. - * @param {Node} baseNode The node to calculate the offset from. - * @extends {goog.Disposable} - * @constructor - */ -goog.dom.NodeOffset = function(node, baseNode) { - goog.Disposable.call(this); - - /** - * A stack of childNode offsets. - * @type {Array.<number>} - * @private - */ - this.offsetStack_ = []; - - /** - * A stack of childNode names. - * @type {Array.<string>} - * @private - */ - this.nameStack_ = []; - - while (node && node.nodeName != goog.dom.TagName.BODY && node != baseNode) { - // Compute the sibling offset. - var siblingOffset = 0; - var sib = node.previousSibling; - while (sib) { - sib = sib.previousSibling; - ++siblingOffset; - } - this.offsetStack_.unshift(siblingOffset); - this.nameStack_.unshift(node.nodeName); - - node = node.parentNode; - } -}; -goog.inherits(goog.dom.NodeOffset, goog.Disposable); - - -/** - * @return {string} A string representation of this object. - */ -goog.dom.NodeOffset.prototype.toString = function() { - var strs = []; - var name; - for (var i = 0; name = this.nameStack_[i]; i++) { - strs.push(this.offsetStack_[i] + ',' + name); - } - return strs.join('\n'); -}; - - -/** - * Walk the dom and find the node relative to baseNode. Returns null on - * failure. - * @param {Node} baseNode The node to start walking from. Should be equivalent - * to the node passed in to the constructor, in that it should have the - * same contents. - * @return {Node} The node relative to baseNode, or null on failure. - */ -goog.dom.NodeOffset.prototype.findTargetNode = function(baseNode) { - var name; - var curNode = baseNode; - for (var i = 0; name = this.nameStack_[i]; ++i) { - curNode = curNode.childNodes[this.offsetStack_[i]]; - - // Sanity check and make sure the element names match. - if (!curNode || curNode.nodeName != name) { - return null; - } - } - return curNode; -}; - - -/** @override */ -goog.dom.NodeOffset.prototype.disposeInternal = function() { - delete this.offsetStack_; - delete this.nameStack_; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeoffset_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeoffset_test.html.svn-base deleted file mode 100644 index b92b8f7..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/nodeoffset_test.html.svn-base +++ /dev/null @@ -1,88 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>goog.dom.NodeOffset Tests</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.NodeOffset'); - goog.require('goog.dom.NodeType'); - goog.require('goog.dom.TagName'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - -<div id="test1">Text<br> and <b>more <i id="i">text.</i></b></div> -<div id="test2"></div> -<div id="empty"></div> - -<script> - var test1 = goog.dom.getElement('test1'); - var i = goog.dom.getElement('i'); - - var test2 = goog.dom.getElement('test2'); - test2.innerHTML = test1.innerHTML; - - var empty = goog.dom.getElement('empty'); - - function testElementOffset() { - var nodeOffset = new goog.dom.NodeOffset(i, test1); - - var recovered = nodeOffset.findTargetNode(test2); - assertNotNull('Should recover a node.', recovered); - assertEquals('Should recover an I node.', goog.dom.TagName.I, - recovered.tagName); - assertTrue('Should recover a child of test2', - goog.dom.contains(test2, recovered)); - assertFalse('Should not recover a child of test1', - goog.dom.contains(test1, recovered)); - - nodeOffset.dispose(); - } - - function testNodeOffset() { - var nodeOffset = new goog.dom.NodeOffset(i.firstChild, test1); - - var recovered = nodeOffset.findTargetNode(test2); - assertNotNull('Should recover a node.', recovered); - assertEquals('Should recover a text node.', goog.dom.NodeType.TEXT, - recovered.nodeType); - assertEquals('Should have correct contents.', 'text.', - recovered.nodeValue); - assertTrue('Should recover a child of test2', - goog.dom.contains(test2, recovered)); - assertFalse('Should not recover a child of test1', - goog.dom.contains(test1, recovered)); - - nodeOffset.dispose(); - } - - function testToString() { - var nodeOffset = new goog.dom.NodeOffset(i.firstChild, test1); - - assertEquals('Should have correct string representation', - '3,B\n1,I\n0,#text', nodeOffset.toString()); - - nodeOffset.dispose(); - } - - function testBadRecovery() { - var nodeOffset = new goog.dom.NodeOffset(i.firstChild, test1); - - var recovered = nodeOffset.findTargetNode(empty); - assertNull('Should recover nothing.', recovered); - - nodeOffset.dispose(); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/range.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/range.js.svn-base deleted file mode 100644 index 4df2a20..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/range.js.svn-base +++ /dev/null @@ -1,226 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for working with ranges in HTML documents. - * - * @author robbyw@google.com (Robby Walker) - * @author ojan@google.com (Ojan Vafai) - * @author jparent@google.com (Julie Parent) - */ - -goog.provide('goog.dom.Range'); - -goog.require('goog.dom'); -goog.require('goog.dom.AbstractRange'); -goog.require('goog.dom.ControlRange'); -goog.require('goog.dom.MultiRange'); -goog.require('goog.dom.NodeType'); -goog.require('goog.dom.TextRange'); -goog.require('goog.userAgent'); - - -/** - * Create a new selection from the given browser window's current selection. - * Note that this object does not auto-update if the user changes their - * selection and should be used as a snapshot. - * @param {Window=} opt_win The window to get the selection of. Defaults to the - * window this class was defined in. - * @return {goog.dom.AbstractRange?} A range wrapper object, or null if there - * was an error. - */ -goog.dom.Range.createFromWindow = function(opt_win) { - var sel = goog.dom.AbstractRange.getBrowserSelectionForWindow( - opt_win || window); - return sel && goog.dom.Range.createFromBrowserSelection(sel); -}; - - -/** - * Create a new range wrapper from the given browser selection object. Note - * that this object does not auto-update if the user changes their selection and - * should be used as a snapshot. - * @param {!Object} selection The browser selection object. - * @return {goog.dom.AbstractRange?} A range wrapper object or null if there - * was an error. - */ -goog.dom.Range.createFromBrowserSelection = function(selection) { - var range; - var isReversed = false; - if (selection.createRange) { - /** @preserveTry */ - try { - range = selection.createRange(); - } catch (e) { - // Access denied errors can be thrown here in IE if the selection was - // a flash obj or if there are cross domain issues - return null; - } - } else if (selection.rangeCount) { - if (selection.rangeCount > 1) { - return goog.dom.MultiRange.createFromBrowserSelection( - /** @type {Selection} */ (selection)); - } else { - range = selection.getRangeAt(0); - isReversed = goog.dom.Range.isReversed(selection.anchorNode, - selection.anchorOffset, selection.focusNode, selection.focusOffset); - } - } else { - return null; - } - - return goog.dom.Range.createFromBrowserRange(range, isReversed); -}; - - -/** - * Create a new range wrapper from the given browser range object. - * @param {Range|TextRange} range The browser range object. - * @param {boolean=} opt_isReversed Whether the focus node is before the anchor - * node. - * @return {goog.dom.AbstractRange} A range wrapper object. - */ -goog.dom.Range.createFromBrowserRange = function(range, opt_isReversed) { - // Create an IE control range when appropriate. - return goog.dom.AbstractRange.isNativeControlRange(range) ? - goog.dom.ControlRange.createFromBrowserRange(range) : - goog.dom.TextRange.createFromBrowserRange(range, opt_isReversed); -}; - - -/** - * Create a new range wrapper that selects the given node's text. - * @param {Node} node The node to select. - * @param {boolean=} opt_isReversed Whether the focus node is before the anchor - * node. - * @return {goog.dom.AbstractRange} A range wrapper object. - */ -goog.dom.Range.createFromNodeContents = function(node, opt_isReversed) { - return goog.dom.TextRange.createFromNodeContents(node, opt_isReversed); -}; - - -/** - * Create a new range wrapper that represents a caret at the given node, - * accounting for the given offset. This always creates a TextRange, regardless - * of whether node is an image node or other control range type node. - * @param {Node} node The node to place a caret at. - * @param {number} offset The offset within the node to place the caret at. - * @return {goog.dom.AbstractRange} A range wrapper object. - */ -goog.dom.Range.createCaret = function(node, offset) { - return goog.dom.TextRange.createFromNodes(node, offset, node, offset); -}; - - -/** - * Create a new range wrapper that selects the area between the given nodes, - * accounting for the given offsets. - * @param {Node} startNode The node to start with. - * @param {number} startOffset The offset within the node to start. - * @param {Node} endNode The node to end with. - * @param {number} endOffset The offset within the node to end. - * @return {goog.dom.AbstractRange} A range wrapper object. - */ -goog.dom.Range.createFromNodes = function(startNode, startOffset, endNode, - endOffset) { - return goog.dom.TextRange.createFromNodes(startNode, startOffset, endNode, - endOffset); -}; - - -/** - * Clears the window's selection. - * @param {Window=} opt_win The window to get the selection of. Defaults to the - * window this class was defined in. - */ -goog.dom.Range.clearSelection = function(opt_win) { - var sel = goog.dom.AbstractRange.getBrowserSelectionForWindow( - opt_win || window); - if (!sel) { - return; - } - if (sel.empty) { - // We can't just check that the selection is empty, becuase IE - // sometimes gets confused. - try { - sel.empty(); - } catch (e) { - // Emptying an already empty selection throws an exception in IE - } - } else { - try { - sel.removeAllRanges(); - } catch (e) { - // This throws in IE9 if the range has been invalidated; for example, if - // the user clicked on an element which disappeared during the event - // handler. - } - } -}; - - -/** - * Tests if the window has a selection. - * @param {Window=} opt_win The window to check the selection of. Defaults to - * the window this class was defined in. - * @return {boolean} Whether the window has a selection. - */ -goog.dom.Range.hasSelection = function(opt_win) { - var sel = goog.dom.AbstractRange.getBrowserSelectionForWindow( - opt_win || window); - return !!sel && (goog.userAgent.IE ? sel.type != 'None' : !!sel.rangeCount); -}; - - -/** - * Returns whether the focus position occurs before the anchor position. - * @param {Node} anchorNode The node to start with. - * @param {number} anchorOffset The offset within the node to start. - * @param {Node} focusNode The node to end with. - * @param {number} focusOffset The offset within the node to end. - * @return {boolean} Whether the focus position occurs before the anchor - * position. - */ -goog.dom.Range.isReversed = function(anchorNode, anchorOffset, focusNode, - focusOffset) { - if (anchorNode == focusNode) { - return focusOffset < anchorOffset; - } - var child; - if (anchorNode.nodeType == goog.dom.NodeType.ELEMENT && anchorOffset) { - child = anchorNode.childNodes[anchorOffset]; - if (child) { - anchorNode = child; - anchorOffset = 0; - } else if (goog.dom.contains(anchorNode, focusNode)) { - // If focus node is contained in anchorNode, it must be before the - // end of the node. Hence we are reversed. - return true; - } - } - if (focusNode.nodeType == goog.dom.NodeType.ELEMENT && focusOffset) { - child = focusNode.childNodes[focusOffset]; - if (child) { - focusNode = child; - focusOffset = 0; - } else if (goog.dom.contains(focusNode, anchorNode)) { - // If anchor node is contained in focusNode, it must be before the - // end of the node. Hence we are not reversed. - return false; - } - } - return (goog.dom.compareNodeOrder(anchorNode, focusNode) || - anchorOffset - focusOffset) > 0; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/range_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/range_test.html.svn-base deleted file mode 100644 index 14070be..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/range_test.html.svn-base +++ /dev/null @@ -1,702 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2007 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.Range</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.Range'); - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -</head> -<body> - <div id="test1">Text</div> - <div id="test2">abc<br id="br">def</div> - <div id="empty"></div> - <div id="test3"><div></div></div> - <div id="removeTest"><div>Text that<br/>will be deleted</div></div> - <div id="surroundTest"></div> - <div id="insertTest"></div> - <div id="surroundWithNodesTest"></div> - <div id="removePartialTest">012345</div> - <table id="tableTest"><tr><td id="cell">1</td><td>2</td></tr></table> - <div id="ulTest"><ul><li>1</li><li>2</li></ul></div> - <div id="olTest"><ol><li>1</li><li>2</li></ol></div> - <img id="logo" src="http://www.google.com/intl/en_ALL/images/logo.gif"> - <div id="removeNodeTest"><div>Will be removed</div></div> - - <div id='bug1480638'></div> - <div id='textWithSpaces'>hello world !</div> - <div contentEditable=true> - <div id='rangeAroundBreaks'>abcd<br />e</div> - <div id='breaksAroundNode'><br />abcde<br /></div> - </div> - -<script> - var assertRangeEquals = goog.testing.dom.assertRangeEquals; - - function normalizeHtml(str) { - return str.toLowerCase().replace(/[\n\r\f"]/g, '') - .replace(/<\/li>/g, ''); // " for emacs - } - - function testCreate() { - assertNotNull('Browser range object can be created for node', - goog.dom.Range.createFromNodeContents(goog.dom.getElement('test1'))); - } - - function testTableRange() { - var tr = goog.dom.getElement('cell').parentNode; - var range = goog.dom.Range.createFromNodeContents(tr); - assertEquals('Selection should have correct text', '12', - range.getText()); - assertEquals('Selection should have correct html fragment', - '1</td><td>2', normalizeHtml(range.getHtmlFragment())); - - // TODO(robbyw): On IE the TR is included, on FF it is not. - //assertEquals('Selection should have correct valid html', - // '<tr id=row><td>1</td><td>2</td></tr>', - // normalizeHtml(range.getValidHtml())); - - assertEquals('Selection should have correct pastable html', - '<table><tbody><tr><td id=cell>1</td><td>2</td></tr></tbody></table>', - normalizeHtml(range.getPastableHtml())); - } - - function testUnorderedListRange() { - var ul = goog.dom.getElement('ulTest').firstChild; - var range = goog.dom.Range.createFromNodeContents(ul); - assertEquals('Selection should have correct html fragment', - '1<li>2', normalizeHtml(range.getHtmlFragment())); - - // TODO(robbyw): On IE the UL is included, on FF it is not. - //assertEquals('Selection should have correct valid html', - // '<li>1</li><li>2</li>', normalizeHtml(range.getValidHtml())); - - assertEquals('Selection should have correct pastable html', - '<ul><li>1<li>2</ul>', - normalizeHtml(range.getPastableHtml())); - } - - function testOrderedListRange() { - var ol = goog.dom.getElement('olTest').firstChild; - var range = goog.dom.Range.createFromNodeContents(ol); - assertEquals('Selection should have correct html fragment', - '1<li>2', normalizeHtml(range.getHtmlFragment())); - - // TODO(robbyw): On IE the OL is included, on FF it is not. - //assertEquals('Selection should have correct valid html', - // '<li>1</li><li>2</li>', normalizeHtml(range.getValidHtml())); - - assertEquals('Selection should have correct pastable html', - '<ol><li>1<li>2</ol>', - normalizeHtml(range.getPastableHtml())); - } - - function testCreateFromNodes() { - var start = goog.dom.getElement('test1').firstChild; - var end = goog.dom.getElement('br'); - var range = goog.dom.Range.createFromNodes(start, 2, end, 0); - assertNotNull('Browser range object can be created for W3C node range', - range); - - assertEquals('Start node should be selected at start endpoint', start, - range.getStartNode()); - assertEquals('Selection should start at offset 2', 2, - range.getStartOffset()); - assertEquals('Start node should be selected at anchor endpoint', start, - range.getAnchorNode()); - assertEquals('Selection should be anchored at offset 2', 2, - range.getAnchorOffset()); - - var div = goog.dom.getElement('test2'); - assertEquals('DIV node should be selected at end endpoint', div, - range.getEndNode()); - assertEquals('Selection should end at offset 1', 1, range.getEndOffset()); - assertEquals('DIV node should be selected at focus endpoint', div, - range.getFocusNode()); - assertEquals('Selection should be focused at offset 1', 1, - range.getFocusOffset()); - - - assertTrue('Text content should be "xt\\s*abc"', - /xt\s*abc/.test(range.getText())); - assertFalse('Nodes range is not collapsed', range.isCollapsed()); - } - - - function testCreateControlRange() { - if (!goog.userAgent.IE) { - return; - } - var cr = document.body.createControlRange(); - cr.addElement(goog.dom.getElement('logo')); - - var range = goog.dom.Range.createFromBrowserRange(cr); - assertNotNull('Control range object can be created from browser range', - range); - assertEquals('Created range is a control range', goog.dom.RangeType.CONTROL, - range.getType()); - } - - - function testTextNode() { - var range = goog.dom.Range.createFromNodeContents( - goog.dom.getElement('test1').firstChild); - - assertEquals('Created range is a text range', goog.dom.RangeType.TEXT, - range.getType()); - assertEquals('Text node should be selected at start endpoint', 'Text', - range.getStartNode().nodeValue); - assertEquals('Selection should start at offset 0', 0, - range.getStartOffset()); - - assertEquals('Text node should be selected at end endpoint', 'Text', - range.getEndNode().nodeValue); - assertEquals('Selection should end at offset 4', 'Text'.length, - range.getEndOffset()); - - assertEquals('Container should be text node', goog.dom.NodeType.TEXT, - range.getContainer().nodeType); - - assertEquals('Text content should be "Text"', 'Text', range.getText()); - assertFalse('Text range is not collapsed', range.isCollapsed()); - } - - - function testDiv() { - var range = goog.dom.Range.createFromNodeContents( - goog.dom.getElement('test2')); - - assertEquals('Text node "abc" should be selected at start endpoint', 'abc', - range.getStartNode().nodeValue); - assertEquals('Selection should start at offset 0', 0, - range.getStartOffset()); - - assertEquals('Text node "def" should be selected at end endpoint', 'def', - range.getEndNode().nodeValue); - assertEquals('Selection should end at offset 3', 'def'.length, - range.getEndOffset()); - - assertEquals('Container should be DIV', goog.dom.getElement('test2'), - range.getContainer()); - - assertTrue('Div text content should be "abc\\s*def"', - /abc\s*def/.test(range.getText())); - assertFalse('Div range is not collapsed', range.isCollapsed()); - } - - - function testEmptyNode() { - var range = goog.dom.Range.createFromNodeContents( - goog.dom.getElement('empty')); - - assertEquals('DIV be selected at start endpoint', - goog.dom.getElement('empty'), range.getStartNode()); - assertEquals('Selection should start at offset 0', 0, - range.getStartOffset()); - - assertEquals('DIV should be selected at end endpoint', - goog.dom.getElement('empty'), range.getEndNode()); - assertEquals('Selection should end at offset 0', 0, - range.getEndOffset()); - - assertEquals('Container should be DIV', goog.dom.getElement('empty'), - range.getContainer()); - - assertEquals('Empty text content should be ""', '', range.getText()); - assertTrue('Empty range is collapsed', range.isCollapsed()); - } - - - function testCollapse() { - var range = goog.dom.Range.createFromNodeContents( - goog.dom.getElement('test2')); - assertFalse('Div range is not collapsed', range.isCollapsed()); - range.collapse(); - assertTrue('Div range is collapsed after call to empty()', - range.isCollapsed()); - - range = goog.dom.Range.createFromNodeContents(goog.dom.getElement('empty')); - assertTrue('Empty range is collapsed', range.isCollapsed()); - range.collapse(); - assertTrue('Empty range is still collapsed', range.isCollapsed()); - } - - // TODO(robbyw): Test iteration over a strange document fragment. - - function testIterator() { - goog.testing.dom.assertNodesMatch(goog.dom.Range.createFromNodeContents( - goog.dom.getElement('test2')), ['abc', '#br', '#br', 'def']); - } - - function testReversedNodes() { - var node = goog.dom.getElement('test1').firstChild; - var range = goog.dom.Range.createFromNodes(node, 4, node, 0); - assertTrue('Range is reversed', range.isReversed()); - node = goog.dom.getElement('test3'); - range = goog.dom.Range.createFromNodes(node, 0, node, 1); - assertFalse('Range is not reversed', range.isReversed()); - } - - function testReversedContents() { - var range = goog.dom.Range.createFromNodeContents( - goog.dom.getElement('test1'), true); - assertTrue('Range is reversed', range.isReversed()); - assertEquals('Range should select "Text"', 'Text', - range.getText()); - assertEquals('Range start offset should be 0', 0, range.getStartOffset()); - assertEquals('Range end offset should be 4', 4, range.getEndOffset()); - assertEquals('Range anchor offset should be 4', 4, range.getAnchorOffset()); - assertEquals('Range focus offset should be 0', 0, range.getFocusOffset()); - - var range2 = range.clone(); - - range.collapse(true); - assertTrue('Range is collapsed', range.isCollapsed()); - assertFalse('Collapsed range is not reversed', range.isReversed()); - assertEquals('Post collapse start offset should be 4', 4, - range.getStartOffset()); - - range2.collapse(false); - assertTrue('Range 2 is collapsed', range2.isCollapsed()); - assertFalse('Collapsed range 2 is not reversed', range2.isReversed()); - assertEquals('Post collapse start offset 2 should be 0', 0, - range2.getStartOffset()); - } - - function testRemoveContents() { - var outer = goog.dom.getElement('removeTest'); - var range = goog.dom.Range.createFromNodeContents(outer.firstChild); - - range.removeContents(); - - assertEquals('Removed range content should be ""', '', range.getText()); - assertTrue('Removed range should be collapsed', range.isCollapsed()); - assertEquals('Outer div should have 1 child now', 1, - outer.childNodes.length); - assertEquals('Inner div should be empty', 0, - outer.firstChild.childNodes.length); - } - - function testRemovePartialContents() { - var outer = goog.dom.getElement('removePartialTest'); - - var range = goog.dom.Range.createFromNodes(outer.firstChild, 2, - outer.firstChild, 4); - removeHelper(1, range, outer, 1, '0145'); - - range = goog.dom.Range.createFromNodes(outer.firstChild, 0, - outer.firstChild, 1); - removeHelper(2, range, outer, 1, '145'); - - range = goog.dom.Range.createFromNodes(outer.firstChild, 2, - outer.firstChild, 3); - removeHelper(3, range, outer, 1, '14'); - - var br = goog.dom.createDom('BR'); - outer.appendChild(br); - range = goog.dom.Range.createFromNodes(outer.firstChild, 1, - outer, 1); - removeHelper(4, range, outer, 2, '1<br>'); - - outer.innerHTML = '<br>123'; - range = goog.dom.Range.createFromNodes(outer, 0, outer.lastChild, 2); - removeHelper(5, range, outer, 1, '3'); - - outer.innerHTML = '123<br>456'; - range = goog.dom.Range.createFromNodes(outer.firstChild, 1, outer.lastChild, - 2); - removeHelper(6, range, outer, 2, '16'); - - outer.innerHTML = '123<br>456'; - range = goog.dom.Range.createFromNodes(outer.firstChild, 0, outer.lastChild, - 2); - removeHelper(7, range, outer, 1, '6'); - - outer.innerHTML = '<div></div>'; - range = goog.dom.Range.createFromNodeContents(outer.firstChild); - removeHelper(8, range, outer, 1, '<div></div>'); - - // TODO(robbyw): Fix the following edge cases: - // * Selecting contents of a node containing multiply empty divs - // * Selecting via createFromNodes(x, 0, x, x.childNodes.length) - // * Consistent handling of nodeContents(<div><div></div></div>).remove - } - - function removeHelper(testNumber, range, outer, expectedChildCount, - expectedContent) { - range.removeContents(); - assertTrue(testNumber + ': Removed range should now be collapsed', - range.isCollapsed()); - assertEquals(testNumber + ': Removed range content should be ""', '', - range.getText()); - assertEquals(testNumber + ': Outer div should contain correct text', - expectedContent, outer.innerHTML.toLowerCase()); - assertEquals(testNumber + ': Outer div should have ' + expectedChildCount + - ' children now', expectedChildCount, outer.childNodes.length); - assertNotNull(testNumber + ': Empty node should still exist', - goog.dom.getElement('empty')); - } - - function testSurroundContents() { - var outer = goog.dom.getElement('surroundTest'); - outer.innerHTML = '---Text that<br/>will be surrounded---'; - var range = goog.dom.Range.createFromNodes(outer.firstChild, 3, - outer.lastChild, outer.lastChild.nodeValue.length - 3); - - var div = goog.dom.createDom(goog.dom.TagName.DIV, {'style': 'color: red'}); - var output = range.surroundContents(div); - - assertEquals('Outer element should contain new element', outer, - output.parentNode); - assertFalse('New element should have no id', !!output.id); - assertEquals('New element should be red', 'red', output.style.color); - assertEquals('Outer element should have three children', 3, - outer.childNodes.length); - assertEquals('New element should have three children', 3, - output.childNodes.length); - - // TODO(robbyw): Ensure the range stays in a reasonable state. - } - - /** - * Given two offsets into the 'foobar' node, make sure that inserting - * nodes at those offsets doesn't change a selection of 'oba'. - * @bug 1480638 - */ - function assertSurroundDoesntChangeSelectionWithOffsets( - offset1, offset2, expectedHtml) { - var div = goog.dom.getElement('bug1480638'); - div.innerHTML = 'foobar'; - var rangeToSelect = goog.dom.Range.createFromNodes( - div.firstChild, 2, div.firstChild, 5); - rangeToSelect.select(); - - var rangeToSurround = goog.dom.Range.createFromNodes( - div.firstChild, offset1, div.firstChild, offset2); - rangeToSurround.surroundWithNodes(goog.dom.createDom('span'), - goog.dom.createDom('span')); - - // Make sure that the selection didn't change. - assertHTMLEquals('Selection must not change when contents are surrounded.', - expectedHtml, goog.dom.Range.createFromWindow().getHtmlFragment()); - } - - function testSurroundWithNodesDoesntChangeSelection1() { - assertSurroundDoesntChangeSelectionWithOffsets(3, 4, - 'o<span></span>b<span></span>a'); - } - - function testSurroundWithNodesDoesntChangeSelection2() { - assertSurroundDoesntChangeSelectionWithOffsets(3, 6, - 'o<span></span>ba'); - } - - function testSurroundWithNodesDoesntChangeSelection3() { - assertSurroundDoesntChangeSelectionWithOffsets(1, 3, - 'o<span></span>ba'); - } - - function testSurroundWithNodesDoesntChangeSelection4() { - assertSurroundDoesntChangeSelectionWithOffsets(1, 6, - 'oba'); - } - - function testInsertNode() { - var outer = goog.dom.getElement('insertTest'); - outer.innerHTML = 'ACD'; - - var range = goog.dom.Range.createFromNodes(outer.firstChild, 1, - outer.firstChild, 2); - range.insertNode(goog.dom.createTextNode('B'), true); - assertEquals('Element should have correct innerHTML', 'ABCD', - outer.innerHTML); - - outer.innerHTML = '12'; - range = goog.dom.Range.createFromNodes(outer.firstChild, 0, - outer.firstChild, 1); - var br = range.insertNode(goog.dom.createDom(goog.dom.TagName.BR), false); - assertEquals('New element should have correct innerHTML', '1<br>2', - outer.innerHTML.toLowerCase()); - assertEquals('BR should be in outer', outer, br.parentNode); - } - - function testReplaceContentsWithNode() { - var outer = goog.dom.getElement('insertTest'); - outer.innerHTML = 'AXC'; - - var range = goog.dom.Range.createFromNodes(outer.firstChild, 1, - outer.firstChild, 2); - range.replaceContentsWithNode(goog.dom.createTextNode('B')); - assertEquals('Element should have correct innerHTML', 'ABC', - outer.innerHTML); - - outer.innerHTML = 'ABC'; - range = goog.dom.Range.createFromNodes(outer.firstChild, 3, - outer.firstChild, 3); - range.replaceContentsWithNode(goog.dom.createTextNode('D')); - assertEquals( - 'Element should have correct innerHTML after collapsed replace', - 'ABCD', outer.innerHTML); - - outer.innerHTML = 'AX<b>X</b>XC'; - range = goog.dom.Range.createFromNodes(outer.firstChild, 1, - outer.lastChild, 1); - range.replaceContentsWithNode(goog.dom.createTextNode('B')); - goog.testing.dom.assertHtmlContentsMatch('ABC', outer); - } - - function testSurroundWithNodes() { - var outer = goog.dom.getElement('insertTest'); - outer.innerHTML = 'ACE'; - var range = goog.dom.Range.createFromNodes(outer.firstChild, 1, - outer.firstChild, 2); - - range.surroundWithNodes(goog.dom.createTextNode('B'), - goog.dom.createTextNode('D')); - - assertEquals('New element should have correct innerHTML', 'ABCDE', - outer.innerHTML); - } - - function testIsRangeInDocument() { - var outer = goog.dom.getElement('insertTest'); - outer.innerHTML = '<br>ABC'; - var range = goog.dom.Range.createCaret(outer.lastChild, 1); - - assertEquals('Should get correct start element', 'ABC', - range.getStartNode().nodeValue); - assertTrue('Should be considered in document', range.isRangeInDocument()); - - outer.innerHTML = 'DEF'; - - assertFalse('Should be marked as out of document', - range.isRangeInDocument()); - } - - function testRemovedNode() { - var node = goog.dom.getElement('removeNodeTest'); - var range = goog.dom.browserrange.createRangeFromNodeContents(node); - range.select(); - goog.dom.removeNode(node); - - var newRange = goog.dom.Range.createFromWindow(window); - if (goog.userAgent.WEBKIT) { - assertNull('Webkit supports rangeCount == 0', newRange); - } else { - assertTrue('The other browsers will just have an empty range.', - newRange.isCollapsed()); - } - } - - function testReversedRange() { - goog.dom.Range.createFromNodes(goog.dom.getElement('test2'), 0, - goog.dom.getElement('test1'), 0).select(); - - var range = goog.dom.Range.createFromWindow(window); - assertTrue('Range should be reversed', - goog.userAgent.IE || range.isReversed()); - } - - function testUnreversedRange() { - goog.dom.Range.createFromNodes(goog.dom.getElement('test1'), 0, - goog.dom.getElement('test2'), 0).select(); - - var range = goog.dom.Range.createFromWindow(window); - assertFalse('Range should not be reversed', range.isReversed()); - } - - function testReversedThenUnreversedRange() { - // This tests a workaround for a webkit bug where webkit caches selections - // incorrectly. - goog.dom.Range.createFromNodes(goog.dom.getElement('test2'), 0, - goog.dom.getElement('test1'), 0).select(); - goog.dom.Range.createFromNodes(goog.dom.getElement('test1'), 0, - goog.dom.getElement('test2'), 0).select(); - - var range = goog.dom.Range.createFromWindow(window); - assertFalse('Range should not be reversed', range.isReversed()); - } - - function testHasAndClearSelection() { - goog.dom.Range.createFromNodeContents( - goog.dom.getElement('test1')).select(); - - assertTrue('Selection should exist', goog.dom.Range.hasSelection()); - - goog.dom.Range.clearSelection(); - - assertFalse('Selection should not exist', goog.dom.Range.hasSelection()); - } - - function assertForward(string, startNode, startOffset, endNode, endOffset) { - var root = goog.dom.getElement('test2'); - var originalInnerHtml = root.innerHTML; - - assertFalse(string, goog.dom.Range.isReversed(startNode, startOffset, - endNode, endOffset)); - assertTrue(string, goog.dom.Range.isReversed(endNode, endOffset, - startNode, startOffset)); - assertEquals('Contents should be unaffected after: ' + string, - root.innerHTML, originalInnerHtml); - } - - function testIsReversed() { - var root = goog.dom.getElement('test2'); - var text1 = root.firstChild; // Text content: 'abc'. - var br = root.childNodes[1]; - var text2 = root.lastChild; // Text content: 'def'. - - assertFalse('Same element position gives false', goog.dom.Range.isReversed( - root, 0, root, 0)); - assertFalse('Same text position gives false', goog.dom.Range.isReversed( - text1, 0, text2, 0)); - assertForward('Element offsets should compare against each other', - root, 0, root, 2); - assertForward('Text node offsets should compare against each other', - text1, 0, text2, 2); - assertForward('Text nodes should compare correctly', - text1, 0, text2, 0); - assertForward('Text nodes should compare to later elements', - text1, 0, br, 0); - assertForward('Text nodes should compare to earlier elements', - br, 0, text2, 0); - assertForward('Parent is before element child', root, 0, br, 0); - assertForward('Parent is before text child', root, 0, text1, 0); - assertFalse('Equivalent position gives false', goog.dom.Range.isReversed( - root, 0, text1, 0)); - assertFalse('Equivalent position gives false', goog.dom.Range.isReversed( - root, 1, br, 0)); - assertForward('End of element is after children', text1, 0, root, 3); - assertForward('End of element is after children', br, 0, root, 3); - assertForward('End of element is after children', text2, 0, root, 3); - assertForward('End of element is after end of last child', - text2, 3, root, 3); - } - - function testSelectAroundSpaces() { - // set the selection - var textNode = goog.dom.getElement('textWithSpaces').firstChild; - goog.dom.TextRange.createFromNodes( - textNode, 5, textNode, 12).select(); - - // get the selection and check that it matches what we set it to - var range = goog.dom.Range.createFromWindow(); - assertEquals(' world ', range.getText()); - assertEquals(5, range.getStartOffset()); - assertEquals(12, range.getEndOffset()); - assertEquals(textNode, range.getContainer()); - - // Check the contents again, because there used to be a bug where - // it changed after calling getContainer(). - assertEquals(' world ', range.getText()); - } - - function testSelectInsideSpaces() { - // set the selection - var textNode = goog.dom.getElement('textWithSpaces').firstChild; - goog.dom.TextRange.createFromNodes( - textNode, 6, textNode, 11).select(); - - // get the selection and check that it matches what we set it to - var range = goog.dom.Range.createFromWindow(); - assertEquals('world', range.getText()); - assertEquals(6, range.getStartOffset()); - assertEquals(11, range.getEndOffset()); - assertEquals(textNode, range.getContainer()); - - // Check the contents again, because there used to be a bug where - // it changed after calling getContainer(). - assertEquals('world', range.getText()); - } - - function testRangeBeforeBreak() { - var container = goog.dom.getElement('rangeAroundBreaks'); - var text = container.firstChild; - var offset = text.length; - assertEquals(4, offset); - - var br = container.childNodes[1]; - var caret = goog.dom.Range.createCaret(text, offset); - caret.select(); - assertEquals(offset, caret.getStartOffset()); - - var range = goog.dom.Range.createFromWindow(); - assertFalse('Should not contain whole <br>', - range.containsNode(br, false)); - if (goog.userAgent.IE) { - assertTrue('Range over <br> is adjacent to the immediate range before it', - range.containsNode(br, true)); - } else { - assertFalse('Should not contain partial <br>', - range.containsNode(br, true)); - } - - assertEquals(offset, range.getStartOffset()); - assertEquals(text, range.getStartNode()); - } - - function testRangeAfterBreak() { - var container = goog.dom.getElement('rangeAroundBreaks'); - var br = container.childNodes[1]; - var caret = goog.dom.Range.createCaret(container.lastChild, 0); - caret.select(); - assertEquals(0, caret.getStartOffset()); - - var range = goog.dom.Range.createFromWindow(); - assertFalse('Should not contain whole <br>', - range.containsNode(br, false)); - var isSafari3 = goog.userAgent.WEBKIT && !goog.userAgent.isVersion('528'); - - if (goog.userAgent.IE || isSafari3) { - assertTrue('Range over <br> is adjacent to the immediate range after it', - range.containsNode(br, true)); - } else { - assertFalse('Should not contain partial <br>', - range.containsNode(br, true)); - } - - if (isSafari3) { - assertEquals(2, range.getStartOffset()); - assertEquals(container, range.getStartNode()); - } else { - assertEquals(0, range.getStartOffset()); - assertEquals(container.lastChild, range.getStartNode()); - } - } - - function testRangeAtBreakAtStart() { - var container = goog.dom.getElement('breaksAroundNode'); - var br = container.firstChild; - var caret = goog.dom.Range.createCaret(container.firstChild, 0); - caret.select(); - assertEquals(0, caret.getStartOffset()); - - var range = goog.dom.Range.createFromWindow(); - assertTrue('Range over <br> is adjacent to the immediate range before it', - range.containsNode(br, true)); - assertFalse('Should not contain whole <br>', - range.containsNode(br, false)); - - assertRangeEquals(container, 0, container, 0, range); - } - - function assertNodeEquals(expected, actual) { - assertEquals( - 'Expected: ' + goog.testing.dom.exposeNode(expected) + - '\nActual: ' + goog.testing.dom.exposeNode(actual), - expected, actual); - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/rangeendpoint.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/rangeendpoint.js.svn-base deleted file mode 100644 index f8d0fe4..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/rangeendpoint.js.svn-base +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Simple struct for endpoints of a range. - * - * @author robbyw@google.com (Robby Walker) - */ - - -goog.provide('goog.dom.RangeEndpoint'); - - -/** - * Constants for selection endpoints. - * @enum {number} - */ -goog.dom.RangeEndpoint = { - START: 1, - END: 0 -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedcaretrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedcaretrange.js.svn-base deleted file mode 100644 index 31d3134..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedcaretrange.js.svn-base +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview An API for saving and restoring ranges as HTML carets. - * - * @author nicksantos@google.com (Nick Santos) - */ - - -goog.provide('goog.dom.SavedCaretRange'); - -goog.require('goog.array'); -goog.require('goog.dom'); -goog.require('goog.dom.SavedRange'); -goog.require('goog.dom.TagName'); -goog.require('goog.string'); - - - -/** - * A struct for holding context about saved selections. - * This can be used to preserve the selection and restore while the DOM is - * manipulated, or through an asynchronous call. Use goog.dom.Range factory - * methods to obtain an {@see goog.dom.AbstractRange} instance, and use - * {@see goog.dom.AbstractRange#saveUsingCarets} to obtain a SavedCaretRange. - * For editor ranges under content-editable elements or design-mode iframes, - * prefer using {@see goog.editor.range.saveUsingNormalizedCarets}. - * @param {goog.dom.AbstractRange} range The range being saved. - * @constructor - * @extends {goog.dom.SavedRange} - */ -goog.dom.SavedCaretRange = function(range) { - goog.dom.SavedRange.call(this); - - /** - * The DOM id of the caret at the start of the range. - * @type {string} - * @private - */ - this.startCaretId_ = goog.string.createUniqueString(); - - /** - * The DOM id of the caret at the end of the range. - * @type {string} - * @private - */ - this.endCaretId_ = goog.string.createUniqueString(); - - /** - * A DOM helper for storing the current document context. - * @type {goog.dom.DomHelper} - * @private - */ - this.dom_ = goog.dom.getDomHelper(range.getDocument()); - - range.surroundWithNodes(this.createCaret_(true), this.createCaret_(false)); -}; -goog.inherits(goog.dom.SavedCaretRange, goog.dom.SavedRange); - - -/** - * Gets the range that this SavedCaretRage represents, without selecting it - * or removing the carets from the DOM. - * @return {goog.dom.AbstractRange?} An abstract range. - */ -goog.dom.SavedCaretRange.prototype.toAbstractRange = function() { - var range = null; - var startCaret = this.getCaret(true); - var endCaret = this.getCaret(false); - if (startCaret && endCaret) { - range = goog.dom.Range.createFromNodes(startCaret, 0, endCaret, 0); - } - return range; -}; - - -/** - * Gets carets. - * @param {boolean} start If true, returns the start caret. Otherwise, get the - * end caret. - * @return {Element} The start or end caret in the given document. - */ -goog.dom.SavedCaretRange.prototype.getCaret = function(start) { - return this.dom_.getElement(start ? this.startCaretId_ : this.endCaretId_); -}; - - -/** - * Removes the carets from the current restoration document. - * @param {goog.dom.AbstractRange=} opt_range A range whose offsets have already - * been adjusted for caret removal; it will be adjusted if it is also - * affected by post-removal operations, such as text node normalization. - * @return {goog.dom.AbstractRange|undefined} The adjusted range, if opt_range - * was provided. - */ -goog.dom.SavedCaretRange.prototype.removeCarets = function(opt_range) { - goog.dom.removeNode(this.getCaret(true)); - goog.dom.removeNode(this.getCaret(false)); - return opt_range; -}; - - -/** - * Sets the document where the range will be restored. - * @param {!Document} doc An HTML document. - */ -goog.dom.SavedCaretRange.prototype.setRestorationDocument = function(doc) { - this.dom_.setDocument(doc); -}; - - -/** - * Reconstruct the selection from the given saved range. Removes carets after - * restoring the selection. If restore does not dispose this saved range, it may - * only be restored a second time if innerHTML or some other mechanism is used - * to restore the carets to the dom. - * @return {goog.dom.AbstractRange?} Restored selection. - * @override - * @protected - */ -goog.dom.SavedCaretRange.prototype.restoreInternal = function() { - var range = null; - var startCaret = this.getCaret(true); - var endCaret = this.getCaret(false); - if (startCaret && endCaret) { - var startNode = startCaret.parentNode; - var startOffset = goog.array.indexOf(startNode.childNodes, startCaret); - var endNode = endCaret.parentNode; - var endOffset = goog.array.indexOf(endNode.childNodes, endCaret); - if (endNode == startNode) { - // Compensate for the start caret being removed. - endOffset -= 1; - } - range = goog.dom.Range.createFromNodes(startNode, startOffset, - endNode, endOffset); - range = this.removeCarets(range); - range.select(); - } else { - // If only one caret was found, remove it. - this.removeCarets(); - } - return range; -}; - - -/** - * Dispose the saved range and remove the carets from the DOM. - * @override - * @protected - */ -goog.dom.SavedCaretRange.prototype.disposeInternal = function() { - this.removeCarets(); - this.dom_ = null; -}; - - -/** - * Creates a caret element. - * @param {boolean} start If true, creates the start caret. Otherwise, - * creates the end caret. - * @return {Element} The new caret element. - * @private - */ -goog.dom.SavedCaretRange.prototype.createCaret_ = function(start) { - return this.dom_.createDom(goog.dom.TagName.SPAN, - {'id': start ? this.startCaretId_ : this.endCaretId_}); -}; - - -/** - * A regex that will match all saved range carets in a string. - * @type {RegExp} - */ -goog.dom.SavedCaretRange.CARET_REGEX = /<span\s+id="?goog_\d+"?><\/span>/ig; - - -/** - * Returns whether two strings of html are equal, ignoring any saved carets. - * Thus two strings of html whose only difference is the id of their saved - * carets will be considered equal, since they represent html with the - * same selection. - * @param {string} str1 The first string. - * @param {string} str2 The second string. - * @return {boolean} Whether two strings of html are equal, ignoring any - * saved carets. - */ -goog.dom.SavedCaretRange.htmlEqual = function(str1, str2) { - return str1 == str2 || - str1.replace(goog.dom.SavedCaretRange.CARET_REGEX, '') == - str2.replace(goog.dom.SavedCaretRange.CARET_REGEX, ''); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedcaretrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedcaretrange_test.html.svn-base deleted file mode 100644 index 22a1b4a..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedcaretrange_test.html.svn-base +++ /dev/null @@ -1,235 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.SavedCaretRange</title> -<script src="../base.js"></script> -<script> - goog.require('goog.userAgent'); - goog.require('goog.dom'); - goog.require('goog.dom.Range'); - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - <div id='caretRangeTest'> - abc - <div id='def'>def</div> - ghi - <div id='jkl'>jkl</div> - mno - <div id='pqr'>pqr</div> - stu - </div> - - <div id='caretRangeTest-2'> - abc - <div id='def-2'>def</div> - ghi - <div id='jkl-2'>jkl</div> - mno - <div id='pqr-2'>pqr</div> - stu - </div> - - <div id='caretRangeTest-3'> - abc - <div id='def-3'>def</div> - ghi - <div id='jkl-3'>jkl</div> - mno - <div id='pqr-3'>pqr</div> - stu - </div> - - <div id='removeContentsTest'> - abc - <div id='def-4'>def</div> - ghi - <div id='jkl-4'>jkl</div> - mno - <div id='pqr-4'>pqr</div> - stu - </div> - - <div id='bug1480638'>foo<table><tr><td>bar</td></tr></table>baz</div> - -<script> - /** @bug 1480638 */ - function testSavedCaretRangeDoesntChangeSelection() { - // NOTE(nicksantos): We cannot detect this bug programatically. The only - // way to detect it is to run this test manually and look at the selection - // when it ends. - var div = goog.dom.getElement('bug1480638'); - var range = goog.dom.Range.createFromNodes( - div.firstChild, 0, div.lastChild, 1); - range.select(); - - // Observe visible selection. Then move to next line and see it change. - // If the bug exists, it starts with "foo" selected and ends with - // it not selected. - //debugger; - var saved = range.saveUsingCarets(); - } - - function testSavedCaretRange() { - var parent = goog.dom.getElement('caretRangeTest'); - var def = goog.dom.getElement('def'); - var jkl = goog.dom.getElement('jkl'); - - var range = goog.dom.Range.createFromNodes( - def.firstChild, 1, jkl.firstChild, 2); - range.select(); - - var saved = range.saveUsingCarets(); - assertHTMLEquals( - "d<span id='" + saved.startCaretId_ + "'></span>ef", def.innerHTML); - assertHTMLEquals( - "jk<span id='" + saved.endCaretId_ + "'></span>l", jkl.innerHTML); - - goog.testing.dom.assertRangeEquals( - def.childNodes[1], 0, jkl.childNodes[1], 0, - saved.toAbstractRange()); - - def = goog.dom.getElement('def'); - jkl = goog.dom.getElement('jkl'); - - var restoredRange = clearSelectionAndRestoreSaved(parent, saved); - goog.testing.dom.assertRangeEquals( - def, 1, jkl, 1, restoredRange); - - var selection = goog.dom.Range.createFromWindow(window); - assertHTMLEquals('def', def.innerHTML); - assertHTMLEquals('jkl', jkl.innerHTML); - - // def and jkl now contain fragmented text nodes. - if (goog.userAgent.WEBKIT || goog.userAgent.IE) { - goog.testing.dom.assertRangeEquals( - def.childNodes[1], 0, jkl.childNodes[0], 2, selection); - } else if (goog.userAgent.OPERA) { - goog.testing.dom.assertRangeEquals( - def.childNodes[1], 0, jkl.childNodes[1], 0, selection); - } else { - goog.testing.dom.assertRangeEquals( - def, 1, jkl, 1, selection); - } - } - - - /* - TODO(user): Look into why removeCarets test doesn't pass. - function testRemoveCarets() { - var def = goog.dom.getElement('def'); - var jkl = goog.dom.getElement('jkl'); - - var range = goog.dom.Range.createFromNodes( - def.firstChild, 1, jkl.firstChild, 2); - range.select(); - - var saved = range.saveUsingCarets(); - assertHTMLEquals( - "d<span id='" + saved.startCaretId_ + "'></span>ef", def.innerHTML); - assertHTMLEquals( - "jk<span id='" + saved.endCaretId_ + "'></span>l", jkl.innerHTML); - - saved.removeCarets(); - assertHTMLEquals("def", def.innerHTML); - assertHTMLEquals("jkl", jkl.innerHTML); - - var selection = goog.dom.Range.createFromWindow(window); - - assertEquals('Wrong start node', def.firstChild, selection.getStartNode()); - assertEquals('Wrong end node', jkl.firstChild, selection.getEndNode()); - assertEquals('Wrong start offset', 1, selection.getStartOffset()); - assertEquals('Wrong end offset', 2, selection.getEndOffset()); - } -*/ - - function testRemoveContents() { - var def = goog.dom.getElement('def-4'); - var jkl = goog.dom.getElement('jkl-4'); - - // Sanity check. - var container = goog.dom.getElement('removeContentsTest'); - assertEquals(7, container.childNodes.length); - assertEquals('def', def.innerHTML); - assertEquals('jkl', jkl.innerHTML); - - var range = goog.dom.Range.createFromNodes( - def.firstChild, 1, jkl.firstChild, 2); - range.select(); - - var saved = range.saveUsingCarets(); - var restored = saved.restore(); - restored.removeContents(); - - assertEquals(6, container.childNodes.length); - assertEquals('d', def.innerHTML); - assertEquals('l', jkl.innerHTML); - } - - function testHtmlEqual() { - var parent = goog.dom.getElement('caretRangeTest-2'); - var def = goog.dom.getElement('def-2'); - var jkl = goog.dom.getElement('jkl-2'); - - var range = goog.dom.Range.createFromNodes( - def.firstChild, 1, jkl.firstChild, 2); - range.select(); - var saved = range.saveUsingCarets(); - var html1 = parent.innerHTML; - saved.removeCarets(); - - var saved2 = range.saveUsingCarets(); - var html2 = parent.innerHTML; - saved2.removeCarets(); - - assertNotEquals('Same selection with different saved caret range carets ' + - 'must have different html.', html1, html2); - - assertTrue('Same selection with different saved caret range carets must ' + - 'be considered equal by htmlEqual', - goog.dom.SavedCaretRange.htmlEqual(html1, html2)); - - saved.dispose(); - saved2.dispose(); - } - - function testStartCaretIsAtEndOfParent() { - var parent = goog.dom.getElement('caretRangeTest-3'); - var def = goog.dom.getElement('def-3'); - var jkl = goog.dom.getElement('jkl-3'); - - var range = goog.dom.Range.createFromNodes( - def, 1, jkl, 1); - range.select(); - var saved = range.saveUsingCarets(); - clearSelectionAndRestoreSaved(parent, saved); - range = goog.dom.Range.createFromWindow(); - assertEquals('ghijkl', range.getText().replace(/\s/g, '')); - } - - /** - * Clear the selection by re-parsing the DOM. Then restore the saved - * selection. - * @param {Node} parent The node containing the current selection. - * @param {goog.dom.SavedRange} saved The saved range. - * @return {goog.dom.AbstractRange} Restored range. - */ - function clearSelectionAndRestoreSaved(parent, saved) { - goog.dom.Range.clearSelection(); - assertFalse(goog.dom.Range.hasSelection(window)); - var range = saved.restore(); - assertTrue(goog.dom.Range.hasSelection(window)); - return range; - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedrange.js.svn-base deleted file mode 100644 index 4f356d3..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedrange.js.svn-base +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview A generic interface for saving and restoring ranges. - * - * @author robbyw@google.com (Robby Walker) - */ - - -goog.provide('goog.dom.SavedRange'); - -goog.require('goog.Disposable'); -goog.require('goog.debug.Logger'); - - - -/** - * Abstract interface for a saved range. - * @constructor - * @extends {goog.Disposable} - */ -goog.dom.SavedRange = function() { - goog.Disposable.call(this); -}; -goog.inherits(goog.dom.SavedRange, goog.Disposable); - - -/** - * Logging object. - * @type {goog.debug.Logger} - * @private - */ -goog.dom.SavedRange.logger_ = - goog.debug.Logger.getLogger('goog.dom.SavedRange'); - - -/** - * Restores the range and by default disposes of the saved copy. Take note: - * this means the by default SavedRange objects are single use objects. - * @param {boolean=} opt_stayAlive Whether this SavedRange should stay alive - * (not be disposed) after restoring the range. Defaults to false (dispose). - * @return {goog.dom.AbstractRange} The restored range. - */ -goog.dom.SavedRange.prototype.restore = function(opt_stayAlive) { - if (this.isDisposed()) { - goog.dom.SavedRange.logger_.severe( - 'Disposed SavedRange objects cannot be restored.'); - } - - var range = this.restoreInternal(); - if (!opt_stayAlive) { - this.dispose(); - } - return range; -}; - - -/** - * Internal method to restore the saved range. - * @return {goog.dom.AbstractRange} The restored range. - */ -goog.dom.SavedRange.prototype.restoreInternal = goog.abstractMethod; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedrange_test.html.svn-base deleted file mode 100644 index 9e4b018..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/savedrange_test.html.svn-base +++ /dev/null @@ -1,61 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2007 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.SavedRange</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.Range'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -</head> -<body> - <div id="test1">Text</div> - -<script> - function testSaved() { - var node = goog.dom.getElement('test1'); - var range = goog.dom.Range.createFromNodeContents(node); - var savedRange = range.saveUsingDom(); - - range = savedRange.restore(true); - assertEquals('Restored range should select "Text"', 'Text', - range.getText()); - assertFalse('Restored range should not be reversed.', range.isReversed()); - assertFalse('Range should not have disposed itself.', - savedRange.isDisposed()); - - goog.dom.Range.clearSelection(); - assertFalse(goog.dom.Range.hasSelection(window)); - - range = savedRange.restore(); - assertTrue('Range should have auto-disposed.', savedRange.isDisposed()); - assertEquals('Restored range should select "Text"', 'Text', - range.getText()); - assertFalse('Restored range should not be reversed.', range.isReversed()); - } - - function testReversedSave() { - var node = goog.dom.getElement('test1').firstChild; - var range = goog.dom.Range.createFromNodes(node, 4, node, 0); - var savedRange = range.saveUsingDom(); - - range = savedRange.restore(); - assertEquals('Restored range should select "Text"', 'Text', - range.getText()); - if (!goog.userAgent.IE) { - assertTrue('Restored range should be reversed.', range.isReversed()); - } - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/selection.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/selection.js.svn-base deleted file mode 100644 index 6d6f69e..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/selection.js.svn-base +++ /dev/null @@ -1,470 +0,0 @@ -// Copyright 2006 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for working with selections in input boxes and text - * areas. - * - * @see ../demos/dom_selection.html - */ - - -goog.provide('goog.dom.selection'); - -goog.require('goog.string'); -goog.require('goog.userAgent'); - - -/** - * Sets the place where the selection should start inside a textarea or a text - * input - * @param {Element} textfield A textarea or text input. - * @param {number} pos The position to set the start of the selection at. - */ -goog.dom.selection.setStart = function(textfield, pos) { - if (goog.dom.selection.useSelectionProperties_(textfield)) { - textfield.selectionStart = pos; - } else if (goog.userAgent.IE) { - // destructuring assignment would have been sweet - var tmp = goog.dom.selection.getRangeIe_(textfield); - var range = tmp[0]; - var selectionRange = tmp[1]; - - if (range.inRange(selectionRange)) { - pos = goog.dom.selection.canonicalizePositionIe_(textfield, pos); - - range.collapse(true); - range.move('character', pos); - range.select(); - } - } -}; - - -/** - * Return the place where the selection starts inside a textarea or a text - * input - * @param {Element} textfield A textarea or text input. - * @return {number} The position where the selection starts or 0 if it was - * unable to find the position or no selection exists. Note that we can't - * reliably tell the difference between an element that has no selection and - * one where it starts at 0. - */ -goog.dom.selection.getStart = function(textfield) { - return goog.dom.selection.getEndPoints_(textfield, true)[0]; -}; - - -/** - * Returns the start and end points of the selection within a textarea in IE. - * IE treats newline characters as \r\n characters, and we need to check for - * these characters at the edge of our selection, to ensure that we return the - * right cursor position. - * @param {TextRange} range Complete range object, e.g., "Hello\r\n". - * @param {TextRange} selRange Selected range object. - * @param {boolean} getOnlyStart Value indicating if only start - * cursor position is to be returned. In IE, obtaining the end position - * involves extra work, hence we have this parameter for calls which need - * only start position. - * @return {Array.<number>} An array with the start and end positions where the - * selection starts and ends or [0,0] if it was unable to find the - * positions or no selection exists. Note that we can't reliably tell the - * difference between an element that has no selection and one where - * it starts and ends at 0. If getOnlyStart was true, we return - * -1 as end offset. - * @private - */ -goog.dom.selection.getEndPointsTextareaIe_ = function( - range, selRange, getOnlyStart) { - // Create a duplicate of the selected range object to perform our actions - // against. Example of selectionRange = "" (assuming that the cursor is - // just after the \r\n combination) - var selectionRange = selRange.duplicate(); - - // Text before the selection start, e.g.,"Hello" (notice how range.text - // excludes the \r\n sequence) - var beforeSelectionText = range.text; - // Text before the selection start, e.g., "Hello" (this will later include - // the \r\n sequences also) - var untrimmedBeforeSelectionText = beforeSelectionText; - // Text within the selection , e.g. "" assuming that the cursor is just after - // the \r\n combination. - var selectionText = selectionRange.text; - // Text within the selection, e.g., "" (this will later include the \r\n - // sequences also) - var untrimmedSelectionText = selectionText; - - // Boolean indicating whether we are done dealing with the text before the - // selection's beginning. - var isRangeEndTrimmed = false; - // Go over the range until it becomes a 0-lengthed range or until the range - // text starts changing when we move the end back by one character. - // If after moving the end back by one character, the text remains the same, - // then we need to add a "\r\n" at the end to get the actual text. - while (!isRangeEndTrimmed) { - if (range.compareEndPoints('StartToEnd', range) == 0) { - isRangeEndTrimmed = true; - } else { - range.moveEnd('character', -1); - if (range.text == beforeSelectionText) { - // If the start position of the cursor was after a \r\n string, - // we would skip over it in one go with the moveEnd call, but - // range.text will still show "Hello" (because of the IE range.text - // bug) - this implies that we should add a \r\n to our - // untrimmedBeforeSelectionText string. - untrimmedBeforeSelectionText += '\r\n'; - } else { - isRangeEndTrimmed = true; - } - } - } - - if (getOnlyStart) { - // We return -1 as end, since the caller is only interested in the start - // value. - return [untrimmedBeforeSelectionText.length, -1]; - } - // Boolean indicating whether we are done dealing with the text inside the - // selection. - var isSelectionRangeEndTrimmed = false; - // Go over the selected range until it becomes a 0-lengthed range or until - // the range text starts changing when we move the end back by one character. - // If after moving the end back by one character, the text remains the same, - // then we need to add a "\r\n" at the end to get the actual text. - while (!isSelectionRangeEndTrimmed) { - if (selectionRange.compareEndPoints('StartToEnd', selectionRange) == 0) { - isSelectionRangeEndTrimmed = true; - } else { - selectionRange.moveEnd('character', -1); - if (selectionRange.text == selectionText) { - // If the selection was not empty, and the end point of the selection - // was just after a \r\n, we would have skipped it in one go with the - // moveEnd call, and this implies that we should add a \r\n to the - // untrimmedSelectionText string. - untrimmedSelectionText += '\r\n'; - } else { - isSelectionRangeEndTrimmed = true; - } - } - } - return [ - untrimmedBeforeSelectionText.length, - untrimmedBeforeSelectionText.length + untrimmedSelectionText.length]; -}; - - -/** - * Returns the start and end points of the selection inside a textarea or a - * text input. - * @param {Element} textfield A textarea or text input. - * @return {Array.<number>} An array with the start and end positions where the - * selection starts and ends or [0,0] if it was unable to find the - * positions or no selection exists. Note that we can't reliably tell the - * difference between an element that has no selection and one where - * it starts and ends at 0. - */ -goog.dom.selection.getEndPoints = function(textfield) { - return goog.dom.selection.getEndPoints_(textfield, false); -}; - - -/** - * Returns the start and end points of the selection inside a textarea or a - * text input. - * @param {Element} textfield A textarea or text input. - * @param {boolean} getOnlyStart Value indicating if only start - * cursor position is to be returned. In IE, obtaining the end position - * involves extra work, hence we have this parameter. In FF, there is not - * much extra effort involved. - * @return {Array.<number>} An array with the start and end positions where the - * selection starts and ends or [0,0] if it was unable to find the - * positions or no selection exists. Note that we can't reliably tell the - * difference between an element that has no selection and one where - * it starts and ends at 0. If getOnlyStart was true, we return - * -1 as end offset. - * @private - */ -goog.dom.selection.getEndPoints_ = function(textfield, getOnlyStart) { - var startPos = 0; - var endPos = 0; - if (goog.dom.selection.useSelectionProperties_(textfield)) { - startPos = textfield.selectionStart; - endPos = getOnlyStart ? -1 : textfield.selectionEnd; - } else if (goog.userAgent.IE) { - var tmp = goog.dom.selection.getRangeIe_(textfield); - var range = tmp[0]; - var selectionRange = tmp[1]; - - if (range.inRange(selectionRange)) { - range.setEndPoint('EndToStart', selectionRange); - if (textfield.type == 'textarea') { - return goog.dom.selection.getEndPointsTextareaIe_( - range, selectionRange, getOnlyStart); - } - startPos = range.text.length; - if (!getOnlyStart) { - endPos = range.text.length + selectionRange.text.length; - } else { - endPos = -1; // caller did not ask for end position - } - } - } - return [startPos, endPos]; -}; - - -/** - * Sets the place where the selection should end inside a text area or a text - * input - * @param {Element} textfield A textarea or text input. - * @param {number} pos The position to end the selection at. - */ -goog.dom.selection.setEnd = function(textfield, pos) { - if (goog.dom.selection.useSelectionProperties_(textfield)) { - textfield.selectionEnd = pos; - } else if (goog.userAgent.IE) { - var tmp = goog.dom.selection.getRangeIe_(textfield); - var range = tmp[0]; - var selectionRange = tmp[1]; - - if (range.inRange(selectionRange)) { - // Both the current position and the start cursor position need - // to be canonicalized to take care of possible \r\n miscounts. - pos = goog.dom.selection.canonicalizePositionIe_(textfield, pos); - var startCursorPos = goog.dom.selection.canonicalizePositionIe_( - textfield, goog.dom.selection.getStart(textfield)); - - selectionRange.collapse(true); - selectionRange.moveEnd('character', pos - startCursorPos); - selectionRange.select(); - } - } -}; - - -/** - * Returns the place where the selection ends inside a textarea or a text input - * @param {Element} textfield A textarea or text input. - * @return {number} The position where the selection ends or 0 if it was - * unable to find the position or no selection exists. - */ -goog.dom.selection.getEnd = function(textfield) { - return goog.dom.selection.getEndPoints_(textfield, false)[1]; -}; - - -/** - * Sets the cursor position within a textfield. - * @param {Element} textfield A textarea or text input. - * @param {number} pos The position within the text field. - */ -goog.dom.selection.setCursorPosition = function(textfield, pos) { - if (goog.dom.selection.useSelectionProperties_(textfield)) { - // Mozilla directly supports this - textfield.selectionStart = pos; - textfield.selectionEnd = pos; - - } else if (goog.userAgent.IE) { - pos = goog.dom.selection.canonicalizePositionIe_(textfield, pos); - - // IE has textranges. A textfield's textrange encompasses the - // entire textfield's text by default - var sel = textfield.createTextRange(); - - sel.collapse(true); - sel.move('character', pos); - sel.select(); - } -}; - - -/** - * Sets the selected text inside a textarea or a text input - * @param {Element} textfield A textarea or text input. - * @param {string} text The text to change the selection to. - */ -goog.dom.selection.setText = function(textfield, text) { - if (goog.dom.selection.useSelectionProperties_(textfield)) { - var value = textfield.value; - var oldSelectionStart = textfield.selectionStart; - var before = value.substr(0, oldSelectionStart); - var after = value.substr(textfield.selectionEnd); - textfield.value = before + text + after; - textfield.selectionStart = oldSelectionStart; - textfield.selectionEnd = oldSelectionStart + text.length; - } else if (goog.userAgent.IE) { - var tmp = goog.dom.selection.getRangeIe_(textfield); - var range = tmp[0]; - var selectionRange = tmp[1]; - - if (!range.inRange(selectionRange)) { - return; - } - // When we set the selection text the selection range is collapsed to the - // end. We therefore duplicate the current selection so we know where it - // started. Once we've set the selection text we move the start of the - // selection range to the old start - var range2 = selectionRange.duplicate(); - selectionRange.text = text; - selectionRange.setEndPoint('StartToStart', range2); - selectionRange.select(); - } else { - throw Error('Cannot set the selection end'); - } -}; - - -/** - * Returns the selected text inside a textarea or a text input - * @param {Element} textfield A textarea or text input. - * @return {string} The selected text. - */ -goog.dom.selection.getText = function(textfield) { - if (goog.dom.selection.useSelectionProperties_(textfield)) { - var s = textfield.value; - return s.substring(textfield.selectionStart, textfield.selectionEnd); - } - - if (goog.userAgent.IE) { - var tmp = goog.dom.selection.getRangeIe_(textfield); - var range = tmp[0]; - var selectionRange = tmp[1]; - - if (!range.inRange(selectionRange)) { - return ''; - } else if (textfield.type == 'textarea') { - return goog.dom.selection.getSelectionRangeText_(selectionRange); - } - return selectionRange.text; - } - - throw Error('Cannot get the selection text'); -}; - - -/** - * Returns the selected text within a textarea in IE. - * IE treats newline characters as \r\n characters, and we need to check for - * these characters at the edge of our selection, to ensure that we return the - * right string. - * @param {TextRange} selRange Selected range object. - * @return {string} Selected text in the textarea. - * @private - */ -goog.dom.selection.getSelectionRangeText_ = function(selRange) { - // Create a duplicate of the selected range object to perform our actions - // against. Suppose the text in the textarea is "Hello\r\nWorld" and the - // selection encompasses the "o\r\n" bit, initial selectionRange will be "o" - // (assuming that the cursor is just after the \r\n combination) - var selectionRange = selRange.duplicate(); - - // Text within the selection , e.g. "o" assuming that the cursor is just after - // the \r\n combination. - var selectionText = selectionRange.text; - // Text within the selection, e.g., "o" (this will later include the \r\n - // sequences also) - var untrimmedSelectionText = selectionText; - - // Boolean indicating whether we are done dealing with the text inside the - // selection. - var isSelectionRangeEndTrimmed = false; - // Go over the selected range until it becomes a 0-lengthed range or until - // the range text starts changing when we move the end back by one character. - // If after moving the end back by one character, the text remains the same, - // then we need to add a "\r\n" at the end to get the actual text. - while (!isSelectionRangeEndTrimmed) { - if (selectionRange.compareEndPoints('StartToEnd', selectionRange) == 0) { - isSelectionRangeEndTrimmed = true; - } else { - selectionRange.moveEnd('character', -1); - if (selectionRange.text == selectionText) { - // If the selection was not empty, and the end point of the selection - // was just after a \r\n, we would have skipped it in one go with the - // moveEnd call, and this implies that we should add a \r\n to the - // untrimmedSelectionText string. - untrimmedSelectionText += '\r\n'; - } else { - isSelectionRangeEndTrimmed = true; - } - } - } - return untrimmedSelectionText; -}; - - -/** - * Helper function for returning the range for an object as well as the - * selection range - * @private - * @param {Element} el The element to get the range for. - * @return {Array.<TextRange>} Range of object and selection range in two - * element array. - */ -goog.dom.selection.getRangeIe_ = function(el) { - var doc = el.ownerDocument || el.document; - - var selectionRange = doc.selection.createRange(); - // el.createTextRange() doesn't work on textareas - var range; - - if (el.type == 'textarea') { - range = doc.body.createTextRange(); - range.moveToElementText(el); - } else { - range = el.createTextRange(); - } - - return [range, selectionRange]; -}; - - -/** - * Helper function for canonicalizing a position inside a textfield in IE. - * Deals with the issue that \r\n counts as 2 characters, but - * move('character', n) passes over both characters in one move. - * @private - * @param {Element} textfield The text element. - * @param {number} pos The position desired in that element. - * @return {number} The canonicalized position that will work properly with - * move('character', pos). - */ -goog.dom.selection.canonicalizePositionIe_ = function(textfield, pos) { - if (textfield.type == 'textarea') { - // We do this only for textarea because it is the only one which can - // have a \r\n (input cannot have this). - var value = textfield.value.substring(0, pos); - pos = goog.string.canonicalizeNewlines(value).length; - } - return pos; -}; - - -/** - * Helper function to determine whether it's okay to use - * selectionStart/selectionEnd. - * - * @param {Element} el The element to check for. - * @return {boolean} Whether it's okay to use the selectionStart and - * selectionEnd properties on {@code el}. - * @private - */ -goog.dom.selection.useSelectionProperties_ = function(el) { - try { - return typeof el.selectionStart == 'number'; - } catch (e) { - // Firefox throws an exception if you try to access selectionStart - // on an element with display: none. - return false; - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/selection_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/selection_test.html.svn-base deleted file mode 100644 index 8cfc624..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/selection_test.html.svn-base +++ /dev/null @@ -1,329 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2007 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.selection</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.selection'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -</head> -<body> - -<script> - - var input; - var hiddenInput; - var textarea; - var hiddenTextarea; - - function setUp() { - input = goog.dom.createDom('input', {type: 'text'}); - textarea = goog.dom.createDom('textarea'); - hiddenInput = goog.dom.createDom( - 'input', {type: 'text', style: 'display: none'}); - hiddenTextarea = goog.dom.createDom( - 'textarea', {style: 'display: none'}); - - document.body.appendChild(input); - document.body.appendChild(textarea); - document.body.appendChild(hiddenInput); - document.body.appendChild(hiddenTextarea); - } - - function tearDown() { - goog.dom.removeNode(input); - goog.dom.removeNode(textarea); - goog.dom.removeNode(hiddenInput); - goog.dom.removeNode(hiddenTextarea); - } - - /** - * Tests getStart routine in both input and textarea. - */ - function testGetStartInput() { - getStartHelper(input, hiddenInput); - } - - function testGetStartTextarea() { - getStartHelper(textarea, hiddenTextarea); - } - - function getStartHelper(field, hiddenField) { - assertEquals(0, goog.dom.selection.getStart(field)); - assertEquals(0, goog.dom.selection.getStart(hiddenField)); - - field.focus(); - assertEquals(0, goog.dom.selection.getStart(field)); - } - - /** - * Tests the setText routine for both input and textarea - * with a single line of text. - */ - function testSetTextInput() { - setTextHelper(input); - } - - function testSetTextTextarea() { - setTextHelper(textarea); - } - - function setTextHelper(field) { - // Test one line string only - select(field); - assertEquals('', goog.dom.selection.getText(field)); - - goog.dom.selection.setText(field, 'Get Behind Me Satan'); - assertEquals('Get Behind Me Satan', goog.dom.selection.getText(field)); - } - - /** - * Tests the setText routine for textarea with multiple lines of text. - */ - function testSetTextMultipleLines() { - select(textarea); - assertEquals('', goog.dom.selection.getText(textarea)); - var message = goog.userAgent.IE ? - 'Get Behind Me\r\nSatan' : - 'Get Behind Me\nSatan'; - goog.dom.selection.setText(textarea, message); - assertEquals(message, goog.dom.selection.getText(textarea)); - - // Select the text upto the point just after the \r\n combination - // or \n in GECKO. - var endOfNewline = goog.userAgent.IE ? 15 : 14; - var selectedMessage = message.substring(0, endOfNewline); - goog.dom.selection.setStart(textarea, 0); - goog.dom.selection.setEnd(textarea, endOfNewline); - assertEquals(selectedMessage, goog.dom.selection.getText(textarea)); - - selectedMessage = goog.userAgent.IE ? '\r\n' : '\n'; - goog.dom.selection.setStart(textarea, 13); - goog.dom.selection.setEnd(textarea, endOfNewline); - assertEquals(selectedMessage, goog.dom.selection.getText(textarea)); - } - - /** - * Tests the setCursor routine for both input and textarea. - */ - function testSetCursorInput() { - setCursorHelper(input); - } - - function testSetCursorTextarea() { - setCursorHelper(textarea); - } - - function setCursorHelper(field) { - select(field); - // try to set the cursor beyond the length of the content - goog.dom.selection.setStart(field, 5); - goog.dom.selection.setEnd(field, 15); - assertEquals(0, goog.dom.selection.getStart(field)); - assertEquals(0, goog.dom.selection.getEnd(field)); - - select(field); - var message = 'Get Behind Me Satan'; - goog.dom.selection.setText(field, message); - goog.dom.selection.setStart(field, 5); - goog.dom.selection.setEnd(field, message.length); - assertEquals(5, goog.dom.selection.getStart(field)); - assertEquals(message.length, goog.dom.selection.getEnd(field)); - - // Set the end before the start, and see if getEnd returns the start - // position itself. - goog.dom.selection.setStart(field, 5); - goog.dom.selection.setEnd(field, 3); - assertEquals(3, goog.dom.selection.getEnd(field)); - } - - /** - * Tests the getText and setText routines acting on selected text in - * both input and textarea. - */ - function testGetAndSetSelectedTextInput() { - getAndSetSelectedTextHelper(input); - } - - function testGetAndSetSelectedTextTextarea() { - getAndSetSelectedTextHelper(textarea); - } - - function getAndSetSelectedTextHelper(field) { - select(field); - goog.dom.selection.setText(field, 'Get Behind Me Satan'); - - // select 'Behind' - goog.dom.selection.setStart(field, 4); - goog.dom.selection.setEnd(field, 10); - assertEquals('Behind', goog.dom.selection.getText(field)); - - goog.dom.selection.setText(field, 'In Front Of'); - goog.dom.selection.setStart(field, 0); - goog.dom.selection.setEnd(field, 100); - assertEquals('Get In Front Of Me Satan', goog.dom.selection.getText(field)); - } - - /** - * Test setStart on hidden input and hidden textarea. - */ - function testSetCursorOnHiddenInput() { - setCursorOnHiddenInputHelper(hiddenInput); - } - - function testSetCursorOnHiddenTextarea() { - setCursorOnHiddenInputHelper(hiddenTextarea); - } - - function setCursorOnHiddenInputHelper(hiddenField) { - goog.dom.selection.setStart(hiddenField, 0); - assertEquals(0, goog.dom.selection.getStart(hiddenField)); - } - - /** - * Test setStart, setEnd, getStart and getEnd in textarea with text - * containing line breaks. - */ - function testSetAndGetCursorWithLineBreaks() { - select(textarea); - var newline = goog.userAgent.IE ? '\r\n' : '\n'; - var message = 'Hello' + newline + 'World'; - goog.dom.selection.setText(textarea, message); - - // Test setEnd and getEnd, by setting the cursor somewhere after the - // \r\n combination. - goog.dom.selection.setEnd(textarea, 9); - assertEquals(9, goog.dom.selection.getEnd(textarea)); - - // Test basic setStart and getStart - goog.dom.selection.setStart(textarea, 10); - assertEquals(10, goog.dom.selection.getStart(textarea)); - - // Test setEnd and getEnd, by setting the cursor exactly after the - // \r\n combination in IE or after \n in GECKO. - var endOfNewline = goog.userAgent.IE ? 7 : 6; - checkSetAndGetTextarea(endOfNewline, endOfNewline); - - // Select a \r\n combination in IE or \n in GECKO and see if - // getStart and getEnd work correctly. - clearField(textarea); - message = 'Hello' + newline + newline + 'World'; - goog.dom.selection.setText(textarea, message); - var startOfNewline = goog.userAgent.IE ? 7 : 6; - endOfNewline = goog.userAgent.IE ? 9 : 7; - checkSetAndGetTextarea(startOfNewline, endOfNewline); - - // Select 2 \r\n combinations in IE or 2 \ns in GECKO and see if getStart - // and getEnd work correctly. - checkSetAndGetTextarea(5, endOfNewline); - - // Position cursor b/w 2 \r\n combinations in IE or 2 \ns in GECKO and see - // if getStart and getEnd work correctly. - clearField(textarea); - message = 'Hello' + newline + newline + newline + newline + 'World'; - goog.dom.selection.setText(textarea, message); - var middleOfNewlines = goog.userAgent.IE ? 9 : 7; - checkSetAndGetTextarea(middleOfNewlines, middleOfNewlines); - - // Position cursor at end of a textarea which ends with \r\n in IE or \n in - // GECKO. - clearField(textarea); - message = 'Hello' + newline + newline; - goog.dom.selection.setText(textarea, message); - var endOfTextarea = message.length; - checkSetAndGetTextarea(endOfTextarea, endOfTextarea); - - // Position cursor at the end of the 2 starting \r\ns in IE or \ns in GECKO - // within a textarea. - clearField(textarea); - message = newline + newline + 'World'; - goog.dom.selection.setText(textarea, message); - var endOfTwoNewlines = goog.userAgent.IE ? 4 : 2; - checkSetAndGetTextarea(endOfTwoNewlines, endOfTwoNewlines); - - // Position cursor at the end of the first \r\n in IE or \n in - // GECKO within a textarea. - endOfOneNewline = goog.userAgent.IE ? 2 : 1; - checkSetAndGetTextarea(endOfOneNewline, endOfOneNewline); - } - - /** - * Test to make sure there's no error when getting the range of an unselected - * textarea. See bug 1274027. - */ - function testGetStartOnUnfocusedTextarea() { - input.value = 'White Blood Cells'; - input.focus(); - goog.dom.selection.setCursorPosition(input, 5); - - assertEquals('getStart on input should return where we put the cursor', - 5, goog.dom.selection.getStart(input)); - - assertEquals('getStart on unfocused textarea should succeed without error', - 0, goog.dom.selection.getStart(textarea)); - } - - /** - * Test to make sure there's no error setting cursor position within a - * textarea after a newline. This is problematic on IE because of the - * '\r\n' vs '\n' issue. - */ - function testSetCursorPositionTextareaWithNewlines() { - textarea.value = 'Hello\nWorld'; - textarea.focus(); - - // Set the selection point between 'W' and 'o'. Position is computed this - // way instead of being hard-coded because it's different in IE due to \r\n - // vs \n. - goog.dom.selection.setCursorPosition(textarea, textarea.value.length - 4); - - var linebreak = goog.userAgent.IE ? '\r\n' : '\n'; - var expectedLeftString = 'Hello' + linebreak + 'W'; - - assertEquals('getStart on input should return after the newline', - expectedLeftString.length, goog.dom.selection.getStart(textarea)); - assertEquals('getEnd on input should return after the newline', - expectedLeftString.length, goog.dom.selection.getEnd(textarea)); - - goog.dom.selection.setEnd(textarea, textarea.value.length); - assertEquals('orld', goog.dom.selection.getText(textarea)); - } - - /** - * Helper function to clear the textfield contents. - */ - function clearField(field) { - field.value = ''; - } - - /** - * Helper function to set the start and end and assert the getter values. - */ - function checkSetAndGetTextarea(start, end) { - goog.dom.selection.setStart(textarea, start); - goog.dom.selection.setEnd(textarea, end); - assertEquals(start, goog.dom.selection.getStart(textarea)); - assertEquals(end, goog.dom.selection.getEnd(textarea)); - } - - /** - * Helper function to focus and select a field. In IE8, selected - * fields need focus. - */ - function select(field) { - field.focus(); - field.select(); - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagiterator.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagiterator.js.svn-base deleted file mode 100644 index b4c22e6..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagiterator.js.svn-base +++ /dev/null @@ -1,365 +0,0 @@ -// Copyright 2008 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Iterator subclass for DOM tree traversal. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.TagIterator'); -goog.provide('goog.dom.TagWalkType'); - -goog.require('goog.dom.NodeType'); -goog.require('goog.iter.Iterator'); -goog.require('goog.iter.StopIteration'); - - -/** - * There are three types of token: - * <ol> - * <li>{@code START_TAG} - The beginning of a tag. - * <li>{@code OTHER} - Any non-element node position. - * <li>{@code END_TAG} - The end of a tag. - * </ol> - * Users of this enumeration can rely on {@code START_TAG + END_TAG = 0} and - * that {@code OTHER = 0}. - * - * @enum {number} - */ -goog.dom.TagWalkType = { - START_TAG: 1, - OTHER: 0, - END_TAG: -1 -}; - - - -/** - * A DOM tree traversal iterator. - * - * Starting with the given node, the iterator walks the DOM in order, reporting - * events for the start and end of Elements, and the presence of text nodes. For - * example: - * - * <pre> - * <div>1<span>2</span>3</div> - * </pre> - * - * Will return the following nodes: - * - * <code>[div, 1, span, 2, span, 3, div]</code> - * - * With the following states: - * - * <code>[START, OTHER, START, OTHER, END, OTHER, END]</code> - * - * And the following depths - * - * <code>[1, 1, 2, 2, 1, 1, 0]</code> - * - * Imagining <code>|</code> represents iterator position, the traversal stops at - * each of the following locations: - * - * <pre> - * <div>|1|<span>|2|</span>|3|</div>| - * </pre> - * - * The iterator can also be used in reverse mode, which will return the nodes - * and states in the opposite order. The depths will be slightly different - * since, like in normal mode, the depth is computed *after* the given node. - * - * Lastly, it is possible to create an iterator that is unconstrained, meaning - * that it will continue iterating until the end of the document instead of - * until exiting the start node. - * - * @param {Node=} opt_node The start node. If unspecified or null, defaults to - * an empty iterator. - * @param {boolean=} opt_reversed Whether to traverse the tree in reverse. - * @param {boolean=} opt_unconstrained Whether the iterator is not constrained - * to the starting node and its children. - * @param {goog.dom.TagWalkType?=} opt_tagType The type of the position. - * Defaults to the start of the given node for forward iterators, and - * the end of the node for reverse iterators. - * @param {number=} opt_depth The starting tree depth. - * @constructor - * @extends {goog.iter.Iterator} - */ -goog.dom.TagIterator = function(opt_node, opt_reversed, - opt_unconstrained, opt_tagType, opt_depth) { - this.reversed = !!opt_reversed; - if (opt_node) { - this.setPosition(opt_node, opt_tagType); - } - this.depth = opt_depth != undefined ? opt_depth : this.tagType || 0; - if (this.reversed) { - this.depth *= -1; - } - this.constrained = !opt_unconstrained; -}; -goog.inherits(goog.dom.TagIterator, goog.iter.Iterator); - - -/** - * The node this position is located on. - * @type {Node} - */ -goog.dom.TagIterator.prototype.node = null; - - -/** - * The type of this position. - * @type {goog.dom.TagWalkType} - */ -goog.dom.TagIterator.prototype.tagType = goog.dom.TagWalkType.OTHER; - - -/** - * The tree depth of this position relative to where the iterator started. The - * depth is considered to be the tree depth just past the current node, so if an - * iterator is at position <pre> - * <div>|</div> - * </pre> - * (i.e. the node is the div and the type is START_TAG) its depth will be 1. - * @type {number} - */ -goog.dom.TagIterator.prototype.depth; - - -/** - * Whether the node iterator is moving in reverse. - * @type {boolean} - */ -goog.dom.TagIterator.prototype.reversed; - - -/** - * Whether the iterator is constrained to the starting node and its children. - * @type {boolean} - */ -goog.dom.TagIterator.prototype.constrained; - - -/** - * Whether iteration has started. - * @type {boolean} - * @private - */ -goog.dom.TagIterator.prototype.started_ = false; - - -/** - * Set the position of the iterator. Overwrite the tree node and the position - * type which can be one of the {@link goog.dom.TagWalkType} token types. - * Only overwrites the tree depth when the parameter is specified. - * @param {Node} node The node to set the position to. - * @param {goog.dom.TagWalkType?=} opt_tagType The type of the position - * Defaults to the start of the given node. - * @param {number=} opt_depth The tree depth. - */ -goog.dom.TagIterator.prototype.setPosition = function(node, - opt_tagType, opt_depth) { - this.node = node; - - if (node) { - if (goog.isNumber(opt_tagType)) { - this.tagType = opt_tagType; - } else { - // Auto-determine the proper type - this.tagType = this.node.nodeType != goog.dom.NodeType.ELEMENT ? - goog.dom.TagWalkType.OTHER : - this.reversed ? goog.dom.TagWalkType.END_TAG : - goog.dom.TagWalkType.START_TAG; - } - } - - if (goog.isNumber(opt_depth)) { - this.depth = opt_depth; - } -}; - - -/** - * Replace this iterator's values with values from another. - * @param {goog.dom.TagIterator} other The iterator to copy. - * @protected - */ -goog.dom.TagIterator.prototype.copyFrom = function(other) { - this.node = other.node; - this.tagType = other.tagType; - this.depth = other.depth; - this.reversed = other.reversed; - this.constrained = other.constrained; -}; - - -/** - * @return {goog.dom.TagIterator} A copy of this iterator. - */ -goog.dom.TagIterator.prototype.clone = function() { - return new goog.dom.TagIterator(this.node, this.reversed, - !this.constrained, this.tagType, this.depth); -}; - - -/** - * Skip the current tag. - */ -goog.dom.TagIterator.prototype.skipTag = function() { - var check = this.reversed ? goog.dom.TagWalkType.END_TAG : - goog.dom.TagWalkType.START_TAG; - if (this.tagType == check) { - this.tagType = /** @type {goog.dom.TagWalkType} */ (check * -1); - this.depth += this.tagType * (this.reversed ? -1 : 1); - } -}; - - -/** - * Restart the current tag. - */ -goog.dom.TagIterator.prototype.restartTag = function() { - var check = this.reversed ? goog.dom.TagWalkType.START_TAG : - goog.dom.TagWalkType.END_TAG; - if (this.tagType == check) { - this.tagType = /** @type {goog.dom.TagWalkType} */ (check * -1); - this.depth += this.tagType * (this.reversed ? -1 : 1); - } -}; - - -/** - * Move to the next position in the DOM tree. - * @return {Node} Returns the next node, or throws a goog.iter.StopIteration - * exception if the end of the iterator's range has been reached. - */ -goog.dom.TagIterator.prototype.next = function() { - var node; - - if (this.started_) { - if (!this.node || this.constrained && this.depth == 0) { - throw goog.iter.StopIteration; - } - node = this.node; - - var startType = this.reversed ? goog.dom.TagWalkType.END_TAG : - goog.dom.TagWalkType.START_TAG; - - if (this.tagType == startType) { - // If we have entered the tag, test if there are any children to move to. - var child = this.reversed ? node.lastChild : node.firstChild; - if (child) { - this.setPosition(child); - } else { - // If not, move on to exiting this tag. - this.setPosition(node, - /** @type {goog.dom.TagWalkType} */ (startType * -1)); - } - } else { - var sibling = this.reversed ? node.previousSibling : node.nextSibling; - if (sibling) { - // Try to move to the next node. - this.setPosition(sibling); - } else { - // If no such node exists, exit our parent. - this.setPosition(node.parentNode, - /** @type {goog.dom.TagWalkType} */ (startType * -1)); - } - } - - this.depth += this.tagType * (this.reversed ? -1 : 1); - } else { - this.started_ = true; - } - - // Check the new position for being last, and return it if it's not. - node = this.node; - if (!this.node) { - throw goog.iter.StopIteration; - } - return node; -}; - - -/** - * @return {boolean} Whether next has ever been called on this iterator. - * @protected - */ -goog.dom.TagIterator.prototype.isStarted = function() { - return this.started_; -}; - - -/** - * @return {boolean} Whether this iterator's position is a start tag position. - */ -goog.dom.TagIterator.prototype.isStartTag = function() { - return this.tagType == goog.dom.TagWalkType.START_TAG; -}; - - -/** - * @return {boolean} Whether this iterator's position is an end tag position. - */ -goog.dom.TagIterator.prototype.isEndTag = function() { - return this.tagType == goog.dom.TagWalkType.END_TAG; -}; - - -/** - * @return {boolean} Whether this iterator's position is not at an element node. - */ -goog.dom.TagIterator.prototype.isNonElement = function() { - return this.tagType == goog.dom.TagWalkType.OTHER; -}; - - -/** - * Test if two iterators are at the same position - i.e. if the node and tagType - * is the same. This will still return true if the two iterators are moving in - * opposite directions or have different constraints. - * @param {goog.dom.TagIterator} other The iterator to compare to. - * @return {boolean} Whether the two iterators are at the same position. - */ -goog.dom.TagIterator.prototype.equals = function(other) { - // Nodes must be equal, and we must either have reached the end of our tree - // or be at the same position. - return other.node == this.node && (!this.node || - other.tagType == this.tagType); -}; - - -/** - * Replace the current node with the list of nodes. Reset the iterator so that - * it visits the first of the nodes next. - * @param {...Object} var_args A list of nodes to replace the current node with. - * If the first argument is array-like, it will be used, otherwise all the - * arguments are assumed to be nodes. - */ -goog.dom.TagIterator.prototype.splice = function(var_args) { - // Reset the iterator so that it iterates over the first replacement node in - // the arguments on the next iteration. - var node = this.node; - this.restartTag(); - this.reversed = !this.reversed; - goog.dom.TagIterator.prototype.next.call(this); - this.reversed = !this.reversed; - - // Replace the node with the arguments. - var arr = goog.isArrayLike(arguments[0]) ? arguments[0] : arguments; - for (var i = arr.length - 1; i >= 0; i--) { - goog.dom.insertSiblingAfter(arr[i], node); - } - goog.dom.removeNode(node); -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagiterator_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagiterator_test.html.svn-base deleted file mode 100644 index 6d61d03..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagiterator_test.html.svn-base +++ /dev/null @@ -1,589 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>goog.dom.TagIterator Tests</title> -<script src="../base.js"></script> -<script> - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); - goog.require('goog.dom.TagIterator'); -</script> -</head> -<body> - -<div id="test"><a href="#">T<b>e</b>xt</a><span></span><p>Text</p></div> -<ul id="test2"><li>Not<li>Closed</ul> -<div id="test3">text</div> -<div id="testSplice"></div> - -<script> - var it; - var pos; - - function assertStartTag(type) { - assertEquals('Position ' + pos + ' should be start tag', - goog.dom.TagWalkType.START_TAG, it.tagType); - assertTrue('isStartTag should return true', it.isStartTag()); - assertFalse('isEndTag should return false', it.isEndTag()); - assertFalse('isNonElement should return false', it.isNonElement()); - assertEquals('Position ' + pos + ' should be ' + type, type, - it.node.tagName); - } - - function assertEndTag(type) { - assertEquals('Position ' + pos + ' should be end tag', - goog.dom.TagWalkType.END_TAG, it.tagType); - assertFalse('isStartTag should return false', it.isStartTag()); - assertTrue('isEndTag should return true', it.isEndTag()); - assertFalse('isNonElement should return false', it.isNonElement()); - assertEquals('Position ' + pos + ' should be ' + type, type, - it.node.tagName); - } - - function assertTextNode(value) { - assertEquals('Position ' + pos + ' should be text node', - goog.dom.TagWalkType.OTHER, it.tagType); - assertFalse('isStartTag should return false', it.isStartTag()); - assertFalse('isEndTag should return false', it.isEndTag()); - assertTrue('isNonElement should return true', it.isNonElement()); - assertEquals('Position ' + pos + ' should be "' + value + '"', value, - it.node.nodeValue); - } - - function testBasicHTML() { - it = new goog.dom.TagIterator(goog.dom.getElement('test')); - pos = 0; - - goog.iter.forEach(it, function() { - pos++; - switch (pos) { - case 1: - assertStartTag('DIV'); - break; - case 2: - assertStartTag('A'); - break; - case 3: - assertTextNode('T'); - break; - case 4: - assertStartTag('B'); - assertEquals('Depth at <B> should be 3', 3, it.depth); - break; - case 5: - assertTextNode('e'); - break; - case 6: - assertEndTag('B'); - break; - case 7: - assertTextNode('xt'); - break; - case 8: - assertEndTag('A'); - break; - case 9: - assertStartTag('SPAN'); - break; - case 10: - assertEndTag('SPAN'); - break; - case 11: - assertStartTag('P'); - break; - case 12: - assertTextNode('Text'); - break; - case 13: - assertEndTag('P'); - break; - case 14: - assertEndTag('DIV'); - assertEquals('Depth at end should be 0', 0, it.depth); - break; - default: - throw goog.iter.StopIteration; - } - }); - } - - function testSkipTag() { - it = new goog.dom.TagIterator(goog.dom.getElement('test')); - pos = 0; - - goog.iter.forEach(it, function() { - pos++; - switch (pos) { - case 1: - assertStartTag('DIV'); - break; - case 2: - assertStartTag('A'); - it.skipTag(); - break; - case 3: - assertStartTag('SPAN'); - break; - case 4: - assertEndTag('SPAN'); - break; - case 5: - assertStartTag('P'); - break; - case 6: - assertTextNode('Text'); - break; - case 7: - assertEndTag('P'); - break; - case 8: - assertEndTag('DIV'); - assertEquals('Depth at end should be 0', 0, it.depth); - break; - default: - throw goog.iter.StopIteration; - } - }); - } - - function testRestartTag() { - it = new goog.dom.TagIterator(goog.dom.getElement('test')); - pos = 0; - var done = false; - - goog.iter.forEach(it, function() { - pos++; - switch (pos) { - case 1: - assertStartTag('DIV'); - break; - case 2: - assertStartTag('A'); - it.skipTag(); - break; - case 3: - assertStartTag('SPAN'); - break; - case 4: - assertEndTag('SPAN'); - break; - case 5: - assertStartTag('P'); - break; - case 6: - assertTextNode('Text'); - break; - case 7: - assertEndTag('P'); - break; - case 8: - assertEndTag('DIV'); - assertEquals('Depth at end should be 0', 0, it.depth); - - // Do them all again, starting after this element. - if (!done) { - pos = 1; - it.restartTag(); - done = true; - } - break; - default: - throw goog.iter.StopIteration; - } - }); - } - - - function testSkipTagReverse() { - it = new goog.dom.TagIterator(goog.dom.getElement('test'), true); - pos = 9; - - goog.iter.forEach(it, function() { - pos--; - switch (pos) { - case 1: - assertStartTag('DIV'); - assertEquals('Depth at end should be 0', 0, it.depth); - break; - case 2: - assertEndTag('A'); - it.skipTag(); - break; - case 3: - assertStartTag('SPAN'); - break; - case 4: - assertEndTag('SPAN'); - break; - case 5: - assertStartTag('P'); - break; - case 6: - assertTextNode('Text'); - break; - case 7: - assertEndTag('P'); - break; - case 8: - assertEndTag('DIV'); - break; - default: - throw goog.iter.StopIteration; - } - }); - } - - - function testUnclosedLI() { - it = new goog.dom.TagIterator(goog.dom.getElement('test2')); - pos = 0; - - goog.iter.forEach(it, function() { - pos++; - switch (pos) { - case 1: - assertStartTag('UL'); - break; - case 2: - assertStartTag('LI'); - assertEquals('Depth at <LI> should be 2', 2, it.depth); - break; - case 3: - assertTextNode('Not'); - break; - case 4: - assertEndTag('LI'); - break; - case 5: - assertStartTag('LI'); - assertEquals('Depth at second <LI> should be 2', 2, it.depth); - break; - case 6: - assertTextNode('Closed'); - break; - case 7: - assertEndTag('LI'); - break; - case 8: - assertEndTag('UL'); - assertEquals('Depth at end should be 0', 0, it.depth); - break; - default: - throw goog.iter.StopIteration; - } - }); - } - - function testReversedUnclosedLI() { - it = new goog.dom.TagIterator(goog.dom.getElement('test2'), true); - pos = 9; - - goog.iter.forEach(it, function() { - pos--; - switch (pos) { - case 1: - assertStartTag('UL'); - assertEquals('Depth at start should be 0', 0, it.depth); - break; - case 2: - assertStartTag('LI'); - break; - case 3: - assertTextNode('Not'); - break; - case 4: - assertEndTag('LI'); - assertEquals('Depth at <LI> should be 2', 2, it.depth); - break; - case 5: - assertStartTag('LI'); - break; - case 6: - assertTextNode('Closed'); - break; - case 7: - assertEndTag('LI'); - assertEquals('Depth at second <LI> should be 2', 2, it.depth); - break; - case 8: - assertEndTag('UL'); - break; - default: - throw goog.iter.StopIteration; - } - }); - } - - function testConstrained() { - it = new goog.dom.TagIterator(goog.dom.getElement('test3'), false, false); - pos = 0; - - goog.iter.forEach(it, function() { - pos++; - switch (pos) { - case 1: - assertStartTag('DIV'); - break; - case 2: - assertTextNode('text'); - break; - case 3: - assertEndTag('DIV'); - break; - } - }); - - assertEquals('Constrained iterator should stop at position 3.', 3, pos); - } - - function testUnconstrained() { - it = new goog.dom.TagIterator(goog.dom.getElement('test3'), false, true); - pos = 0; - - goog.iter.forEach(it, function() { - pos++; - switch (pos) { - case 1: - assertStartTag('DIV'); - break; - case 2: - assertTextNode('text'); - break; - case 3: - assertEndTag('DIV'); - break; - } - }); - - assertNotEquals('Unonstrained iterator should not stop at position 3.', 3, - pos); - } - - function testConstrainedText() { - it = new goog.dom.TagIterator(goog.dom.getElement('test3').firstChild, - false, false); - pos = 0; - - goog.iter.forEach(it, function() { - pos++; - switch (pos) { - case 1: - assertTextNode('text'); - break; - } - }); - - assertEquals('Constrained text iterator should stop at position 1.', 1, - pos); - } - - function testReverseConstrained() { - it = new goog.dom.TagIterator(goog.dom.getElement('test3'), true, false); - pos = 4; - - goog.iter.forEach(it, function() { - pos--; - switch (pos) { - case 1: - assertStartTag('DIV'); - break; - case 2: - assertTextNode('text'); - break; - case 3: - assertEndTag('DIV'); - break; - } - }); - - assertEquals('Constrained reversed iterator should stop at position 1.', 1, - pos); - } - - function testSpliceRemoveSingleNode() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = '<br/>'; - it = new goog.dom.TagIterator(testDiv.firstChild); - - goog.iter.forEach(it, function(node, dummy, i) { - i.splice(); - }); - - assertEquals('Node not removed', 0, testDiv.childNodes.length); - } - - function testSpliceRemoveFirstTextNode() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = 'hello<b>world</b><em>goodbye</em>'; - it = new goog.dom.TagIterator(testDiv.firstChild, false, true); - - goog.iter.forEach(it, function(node, dummy, i) { - if (node.nodeType == 3 && node.data == 'hello') { - i.splice(); - } - if (node.nodeName == 'EM') { - i.splice(goog.dom.createDom('I', null, node.childNodes)); - } - }); - - goog.testing.dom.assertHtmlMatches('<b>world</b><i>goodbye</i>', - testDiv.innerHTML); - } - - function testSpliceReplaceFirstTextNode() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = 'hello<b>world</b>'; - it = new goog.dom.TagIterator(testDiv.firstChild, false, true); - - goog.iter.forEach(it, function(node, dummy, i) { - if (node.nodeType == 3 && node.data == 'hello') { - i.splice(goog.dom.createDom('EM', null, 'HELLO')); - } else if (node.nodeName == 'EM') { - i.splice(goog.dom.createDom('I', null, node.childNodes)); - } - }); - - goog.testing.dom.assertHtmlMatches('<i>HELLO</i><b>world</b>', - testDiv.innerHTML); - } - - function testSpliceReplaceSingleNode() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = '<br/>'; - it = new goog.dom.TagIterator(testDiv.firstChild); - - goog.iter.forEach(it, function(node, dummy, i) { - i.splice(goog.dom.createDom('link'), goog.dom.createDom('img')); - }); - - goog.testing.dom.assertHtmlMatches('<link><img>', testDiv.innerHTML); - } - - function testSpliceFlattenSingleNode() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = '<div><b>one</b>two<i>three</i></div>'; - it = new goog.dom.TagIterator(testDiv.firstChild); - - goog.iter.forEach(it, function(node, dummy, i) { - i.splice(node.childNodes); - }); - - goog.testing.dom.assertHtmlMatches('<b>one</b>two<i>three</i>', - testDiv.innerHTML); - } - - function testSpliceMiddleNode() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = 'a<b>hello<span>world</span></b>c'; - it = new goog.dom.TagIterator(testDiv); - - goog.iter.forEach(it, function(node, dummy, i) { - if (node.nodeName == 'B') { - i.splice(goog.dom.createDom('IMG')); - } - }); - - goog.testing.dom.assertHtmlMatches('a<img>c', testDiv.innerHTML); - } - - function testSpliceMiddleNodeReversed() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = 'a<b>hello<span>world</span></b>c'; - it = new goog.dom.TagIterator(testDiv, true); - - goog.iter.forEach(it, function(node, dummy, i) { - if (node.nodeName == 'B') { - i.splice(goog.dom.createDom('IMG')); - } - }); - - goog.testing.dom.assertHtmlMatches('a<img>c', testDiv.innerHTML); - } - - function testSpliceMiddleNodeAtEndTag() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = 'a<b>hello<span>world</span></b>c'; - it = new goog.dom.TagIterator(testDiv); - - goog.iter.forEach(it, function(node, dummy, i) { - if (node.tagName == 'B' && i.isEndTag()) { - i.splice(goog.dom.createDom('IMG')); - } - }); - - goog.testing.dom.assertHtmlMatches('a<img>c', testDiv.innerHTML); - } - - function testSpliceMultipleNodes() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = '<STRONG>this</STRONG> is <EM>from IE</EM>'; - it = new goog.dom.TagIterator(testDiv); - - goog.iter.forEach(it, function(node, dummy, i) { - var replace = null; - if (node.nodeName == 'STRONG') { - replace = goog.dom.createDom('B', null, node.childNodes); - } else if (node.nodeName == 'EM') { - replace = goog.dom.createDom('I', null, node.childNodes); - } - if (replace) { - i.splice(replace); - } - }); - - goog.testing.dom.assertHtmlMatches('<b>this</b> is <i>from IE</i>', - testDiv.innerHTML); - } - - function testSpliceMultipleNodesAtEnd() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = '<STRONG>this</STRONG> is <EM>from IE</EM>'; - it = new goog.dom.TagIterator(testDiv); - - goog.iter.forEach(it, function(node, dummy, i) { - var replace = null; - if (node.nodeName == 'STRONG' && i.isEndTag()) { - replace = goog.dom.createDom('B', null, node.childNodes); - } else if (node.nodeName == 'EM' && i.isEndTag()) { - replace = goog.dom.createDom('I', null, node.childNodes); - } - if (replace) { - i.splice(replace); - } - }); - - goog.testing.dom.assertHtmlMatches('<b>this</b> is <i>from IE</i>', - testDiv.innerHTML); - } - - function testSpliceMultipleNodesReversed() { - var testDiv = goog.dom.getElement('testSplice'); - testDiv.innerHTML = '<STRONG>this</STRONG> is <EM>from IE</EM>'; - it = new goog.dom.TagIterator(testDiv, true); - - goog.iter.forEach(it, function(node, dummy, i) { - var replace = null; - if (node.nodeName == 'STRONG') { - replace = goog.dom.createDom('B', null, node.childNodes); - } else if (node.nodeName == 'EM') { - replace = goog.dom.createDom('I', null, node.childNodes); - } - if (replace) { - i.splice(replace); - } - }); - - goog.testing.dom.assertHtmlMatches('<b>this</b> is <i>from IE</i>', - testDiv.innerHTML); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagname.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagname.js.svn-base deleted file mode 100644 index 23bdd42..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagname.js.svn-base +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Defines the goog.dom.TagName enum. This enumerates - * all html tag names specified by the W3C HTML 4.01 Specification. - * Reference http://www.w3.org/TR/html401/index/elements.html. - */ -goog.provide('goog.dom.TagName'); - - -/** - * Enum of all html tag names specified by the W3C HTML 4.01 Specification. - * Reference http://www.w3.org/TR/html401/index/elements.html - * @enum {string} - */ -goog.dom.TagName = { - A: 'A', - ABBR: 'ABBR', - ACRONYM: 'ACRONYM', - ADDRESS: 'ADDRESS', - APPLET: 'APPLET', - AREA: 'AREA', - B: 'B', - BASE: 'BASE', - BASEFONT: 'BASEFONT', - BDO: 'BDO', - BIG: 'BIG', - BLOCKQUOTE: 'BLOCKQUOTE', - BODY: 'BODY', - BR: 'BR', - BUTTON: 'BUTTON', - CANVAS: 'CANVAS', - CAPTION: 'CAPTION', - CENTER: 'CENTER', - CITE: 'CITE', - CODE: 'CODE', - COL: 'COL', - COLGROUP: 'COLGROUP', - DD: 'DD', - DEL: 'DEL', - DFN: 'DFN', - DIR: 'DIR', - DIV: 'DIV', - DL: 'DL', - DT: 'DT', - EM: 'EM', - FIELDSET: 'FIELDSET', - FONT: 'FONT', - FORM: 'FORM', - FRAME: 'FRAME', - FRAMESET: 'FRAMESET', - H1: 'H1', - H2: 'H2', - H3: 'H3', - H4: 'H4', - H5: 'H5', - H6: 'H6', - HEAD: 'HEAD', - HR: 'HR', - HTML: 'HTML', - I: 'I', - IFRAME: 'IFRAME', - IMG: 'IMG', - INPUT: 'INPUT', - INS: 'INS', - ISINDEX: 'ISINDEX', - KBD: 'KBD', - LABEL: 'LABEL', - LEGEND: 'LEGEND', - LI: 'LI', - LINK: 'LINK', - MAP: 'MAP', - MENU: 'MENU', - META: 'META', - NOFRAMES: 'NOFRAMES', - NOSCRIPT: 'NOSCRIPT', - OBJECT: 'OBJECT', - OL: 'OL', - OPTGROUP: 'OPTGROUP', - OPTION: 'OPTION', - P: 'P', - PARAM: 'PARAM', - PRE: 'PRE', - Q: 'Q', - S: 'S', - SAMP: 'SAMP', - SCRIPT: 'SCRIPT', - SELECT: 'SELECT', - SMALL: 'SMALL', - SPAN: 'SPAN', - STRIKE: 'STRIKE', - STRONG: 'STRONG', - STYLE: 'STYLE', - SUB: 'SUB', - SUP: 'SUP', - TABLE: 'TABLE', - TBODY: 'TBODY', - TD: 'TD', - TEXTAREA: 'TEXTAREA', - TFOOT: 'TFOOT', - TH: 'TH', - THEAD: 'THEAD', - TITLE: 'TITLE', - TR: 'TR', - TT: 'TT', - U: 'U', - UL: 'UL', - VAR: 'VAR' -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagname_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagname_test.html.svn-base deleted file mode 100644 index 464a193..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/tagname_test.html.svn-base +++ /dev/null @@ -1,37 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2007 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<!-- ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.TagName</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom.TagName'); - goog.require('goog.object'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - -<script> - - function testCorrectNumberOfTagNames() { - assertEquals(92, goog.object.getCount(goog.dom.TagName)); - } - - function testPropertyNamesEqualValues() { - for (var propertyName in goog.dom.TagName) { - assertEquals(propertyName, goog.dom.TagName[propertyName]); - } - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrange.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrange.js.svn-base deleted file mode 100644 index 5f96bd3..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrange.js.svn-base +++ /dev/null @@ -1,611 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utilities for working with text ranges in HTML documents. - * - * @author robbyw@google.com (Robby Walker) - * @author ojan@google.com (Ojan Vafai) - * @author jparent@google.com (Julie Parent) - */ - - -goog.provide('goog.dom.TextRange'); - -goog.require('goog.array'); -goog.require('goog.dom'); -goog.require('goog.dom.AbstractRange'); -goog.require('goog.dom.RangeType'); -goog.require('goog.dom.SavedRange'); -goog.require('goog.dom.TagName'); -goog.require('goog.dom.TextRangeIterator'); -goog.require('goog.dom.browserrange'); -goog.require('goog.string'); -goog.require('goog.userAgent'); - - - -/** - * Create a new text selection with no properties. Do not use this constructor: - * use one of the goog.dom.Range.createFrom* methods instead. - * @constructor - * @extends {goog.dom.AbstractRange} - */ -goog.dom.TextRange = function() { -}; -goog.inherits(goog.dom.TextRange, goog.dom.AbstractRange); - - -/** - * Create a new range wrapper from the given browser range object. Do not use - * this method directly - please use goog.dom.Range.createFrom* instead. - * @param {Range|TextRange} range The browser range object. - * @param {boolean=} opt_isReversed Whether the focus node is before the anchor - * node. - * @return {goog.dom.TextRange} A range wrapper object. - */ -goog.dom.TextRange.createFromBrowserRange = function(range, opt_isReversed) { - return goog.dom.TextRange.createFromBrowserRangeWrapper_( - goog.dom.browserrange.createRange(range), opt_isReversed); -}; - - -/** - * Create a new range wrapper from the given browser range wrapper. - * @param {goog.dom.browserrange.AbstractRange} browserRange The browser range - * wrapper. - * @param {boolean=} opt_isReversed Whether the focus node is before the anchor - * node. - * @return {goog.dom.TextRange} A range wrapper object. - * @private - */ -goog.dom.TextRange.createFromBrowserRangeWrapper_ = function(browserRange, - opt_isReversed) { - var range = new goog.dom.TextRange(); - - // Initialize the range as a browser range wrapper type range. - range.browserRangeWrapper_ = browserRange; - range.isReversed_ = !!opt_isReversed; - - return range; -}; - - -/** - * Create a new range wrapper that selects the given node's text. Do not use - * this method directly - please use goog.dom.Range.createFrom* instead. - * @param {Node} node The node to select. - * @param {boolean=} opt_isReversed Whether the focus node is before the anchor - * node. - * @return {goog.dom.TextRange} A range wrapper object. - */ -goog.dom.TextRange.createFromNodeContents = function(node, opt_isReversed) { - return goog.dom.TextRange.createFromBrowserRangeWrapper_( - goog.dom.browserrange.createRangeFromNodeContents(node), - opt_isReversed); -}; - - -/** - * Create a new range wrapper that selects the area between the given nodes, - * accounting for the given offsets. Do not use this method directly - please - * use goog.dom.Range.createFrom* instead. - * @param {Node} anchorNode The node to start with. - * @param {number} anchorOffset The offset within the node to start. - * @param {Node} focusNode The node to end with. - * @param {number} focusOffset The offset within the node to end. - * @return {goog.dom.TextRange} A range wrapper object. - */ -goog.dom.TextRange.createFromNodes = function(anchorNode, anchorOffset, - focusNode, focusOffset) { - var range = new goog.dom.TextRange(); - range.isReversed_ = goog.dom.Range.isReversed(anchorNode, anchorOffset, - focusNode, focusOffset); - - // Avoid selecting BRs directly - if (anchorNode.tagName == 'BR') { - var parent = anchorNode.parentNode; - anchorOffset = goog.array.indexOf(parent.childNodes, anchorNode); - anchorNode = parent; - } - - if (focusNode.tagName == 'BR') { - var parent = focusNode.parentNode; - focusOffset = goog.array.indexOf(parent.childNodes, focusNode); - focusNode = parent; - } - - // Initialize the range as a W3C style range. - if (range.isReversed_) { - range.startNode_ = focusNode; - range.startOffset_ = focusOffset; - range.endNode_ = anchorNode; - range.endOffset_ = anchorOffset; - } else { - range.startNode_ = anchorNode; - range.startOffset_ = anchorOffset; - range.endNode_ = focusNode; - range.endOffset_ = focusOffset; - } - - return range; -}; - - -// Representation 1: a browser range wrapper. - - -/** - * The browser specific range wrapper. This can be null if one of the other - * representations of the range is specified. - * @type {goog.dom.browserrange.AbstractRange?} - * @private - */ -goog.dom.TextRange.prototype.browserRangeWrapper_ = null; - - -// Representation 2: two endpoints specified as nodes + offsets - - -/** - * The start node of the range. This can be null if one of the other - * representations of the range is specified. - * @type {Node} - * @private - */ -goog.dom.TextRange.prototype.startNode_ = null; - - -/** - * The start offset of the range. This can be null if one of the other - * representations of the range is specified. - * @type {?number} - * @private - */ -goog.dom.TextRange.prototype.startOffset_ = null; - - -/** - * The end node of the range. This can be null if one of the other - * representations of the range is specified. - * @type {Node} - * @private - */ -goog.dom.TextRange.prototype.endNode_ = null; - - -/** - * The end offset of the range. This can be null if one of the other - * representations of the range is specified. - * @type {?number} - * @private - */ -goog.dom.TextRange.prototype.endOffset_ = null; - - -/** - * Whether the focus node is before the anchor node. - * @type {boolean} - * @private - */ -goog.dom.TextRange.prototype.isReversed_ = false; - - -// Method implementations - - -/** - * @return {goog.dom.TextRange} A clone of this range. - */ -goog.dom.TextRange.prototype.clone = function() { - var range = new goog.dom.TextRange(); - range.browserRangeWrapper_ = this.browserRangeWrapper_; - range.startNode_ = this.startNode_; - range.startOffset_ = this.startOffset_; - range.endNode_ = this.endNode_; - range.endOffset_ = this.endOffset_; - range.isReversed_ = this.isReversed_; - - return range; -}; - - -/** @override */ -goog.dom.TextRange.prototype.getType = function() { - return goog.dom.RangeType.TEXT; -}; - - -/** @override */ -goog.dom.TextRange.prototype.getBrowserRangeObject = function() { - return this.getBrowserRangeWrapper_().getBrowserRange(); -}; - - -/** @override */ -goog.dom.TextRange.prototype.setBrowserRangeObject = function(nativeRange) { - // Test if it's a control range by seeing if a control range only method - // exists. - if (goog.dom.AbstractRange.isNativeControlRange(nativeRange)) { - return false; - } - this.browserRangeWrapper_ = goog.dom.browserrange.createRange( - nativeRange); - this.clearCachedValues_(); - return true; -}; - - -/** - * Clear all cached values. - * @private - */ -goog.dom.TextRange.prototype.clearCachedValues_ = function() { - this.startNode_ = this.startOffset_ = this.endNode_ = this.endOffset_ = null; -}; - - -/** @override */ -goog.dom.TextRange.prototype.getTextRangeCount = function() { - return 1; -}; - - -/** @override */ -goog.dom.TextRange.prototype.getTextRange = function(i) { - return this; -}; - - -/** - * @return {goog.dom.browserrange.AbstractRange} The range wrapper object. - * @private - */ -goog.dom.TextRange.prototype.getBrowserRangeWrapper_ = function() { - return this.browserRangeWrapper_ || - (this.browserRangeWrapper_ = goog.dom.browserrange.createRangeFromNodes( - this.getStartNode(), this.getStartOffset(), - this.getEndNode(), this.getEndOffset())); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getContainer = function() { - return this.getBrowserRangeWrapper_().getContainer(); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getStartNode = function() { - return this.startNode_ || - (this.startNode_ = this.getBrowserRangeWrapper_().getStartNode()); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getStartOffset = function() { - return this.startOffset_ != null ? this.startOffset_ : - (this.startOffset_ = this.getBrowserRangeWrapper_().getStartOffset()); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getEndNode = function() { - return this.endNode_ || - (this.endNode_ = this.getBrowserRangeWrapper_().getEndNode()); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getEndOffset = function() { - return this.endOffset_ != null ? this.endOffset_ : - (this.endOffset_ = this.getBrowserRangeWrapper_().getEndOffset()); -}; - - -/** - * Moves a TextRange to the provided nodes and offsets. - * @param {Node} startNode The node to start with. - * @param {number} startOffset The offset within the node to start. - * @param {Node} endNode The node to end with. - * @param {number} endOffset The offset within the node to end. - * @param {boolean} isReversed Whether the range is reversed. - */ -goog.dom.TextRange.prototype.moveToNodes = function(startNode, startOffset, - endNode, endOffset, - isReversed) { - this.startNode_ = startNode; - this.startOffset_ = startOffset; - this.endNode_ = endNode; - this.endOffset_ = endOffset; - this.isReversed_ = isReversed; - this.browserRangeWrapper_ = null; -}; - - -/** @override */ -goog.dom.TextRange.prototype.isReversed = function() { - return this.isReversed_; -}; - - -/** @override */ -goog.dom.TextRange.prototype.containsRange = function(otherRange, - opt_allowPartial) { - var otherRangeType = otherRange.getType(); - if (otherRangeType == goog.dom.RangeType.TEXT) { - return this.getBrowserRangeWrapper_().containsRange( - otherRange.getBrowserRangeWrapper_(), opt_allowPartial); - } else if (otherRangeType == goog.dom.RangeType.CONTROL) { - var elements = otherRange.getElements(); - var fn = opt_allowPartial ? goog.array.some : goog.array.every; - return fn(elements, function(el) { - return this.containsNode(el, opt_allowPartial); - }, this); - } - return false; -}; - - -/** - * Tests if the given node is in a document. - * @param {Node} node The node to check. - * @return {boolean} Whether the given node is in the given document. - */ -goog.dom.TextRange.isAttachedNode = function(node) { - if (goog.userAgent.IE && !goog.userAgent.isDocumentMode(9)) { - var returnValue = false; - /** @preserveTry */ - try { - returnValue = node.parentNode; - } catch (e) { - // IE sometimes throws Invalid Argument errors when a node is detached. - // Note: trying to return a value from the above try block can cause IE - // to crash. It is necessary to use the local returnValue - } - return !!returnValue; - } else { - return goog.dom.contains(node.ownerDocument.body, node); - } -}; - - -/** @override */ -goog.dom.TextRange.prototype.isRangeInDocument = function() { - // Ensure any cached nodes are in the document. IE also allows ranges to - // become detached, so we check if the range is still in the document as - // well for IE. - return (!this.startNode_ || - goog.dom.TextRange.isAttachedNode(this.startNode_)) && - (!this.endNode_ || - goog.dom.TextRange.isAttachedNode(this.endNode_)) && - (!(goog.userAgent.IE && !goog.userAgent.isDocumentMode(9)) || - this.getBrowserRangeWrapper_().isRangeInDocument()); -}; - - -/** @override */ -goog.dom.TextRange.prototype.isCollapsed = function() { - return this.getBrowserRangeWrapper_().isCollapsed(); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getText = function() { - return this.getBrowserRangeWrapper_().getText(); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getHtmlFragment = function() { - // TODO(robbyw): Generalize the code in browserrange so it is static and - // just takes an iterator. This would mean we don't always have to create a - // browser range. - return this.getBrowserRangeWrapper_().getHtmlFragment(); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getValidHtml = function() { - return this.getBrowserRangeWrapper_().getValidHtml(); -}; - - -/** @override */ -goog.dom.TextRange.prototype.getPastableHtml = function() { - // TODO(robbyw): Get any attributes the table or tr has. - - var html = this.getValidHtml(); - - if (html.match(/^\s*<td\b/i)) { - // Match html starting with a TD. - html = '<table><tbody><tr>' + html + '</tr></tbody></table>'; - } else if (html.match(/^\s*<tr\b/i)) { - // Match html starting with a TR. - html = '<table><tbody>' + html + '</tbody></table>'; - } else if (html.match(/^\s*<tbody\b/i)) { - // Match html starting with a TBODY. - html = '<table>' + html + '</table>'; - } else if (html.match(/^\s*<li\b/i)) { - // Match html starting with an LI. - var container = this.getContainer(); - var tagType = goog.dom.TagName.UL; - while (container) { - if (container.tagName == goog.dom.TagName.OL) { - tagType = goog.dom.TagName.OL; - break; - } else if (container.tagName == goog.dom.TagName.UL) { - break; - } - container = container.parentNode; - } - html = goog.string.buildString('<', tagType, '>', html, '</', tagType, '>'); - } - - return html; -}; - - -/** - * Returns a TextRangeIterator over the contents of the range. Regardless of - * the direction of the range, the iterator will move in document order. - * @param {boolean=} opt_keys Unused for this iterator. - * @return {goog.dom.TextRangeIterator} An iterator over tags in the range. - */ -goog.dom.TextRange.prototype.__iterator__ = function(opt_keys) { - return new goog.dom.TextRangeIterator(this.getStartNode(), - this.getStartOffset(), this.getEndNode(), this.getEndOffset()); -}; - - -// RANGE ACTIONS - - -/** @override */ -goog.dom.TextRange.prototype.select = function() { - this.getBrowserRangeWrapper_().select(this.isReversed_); -}; - - -/** @override */ -goog.dom.TextRange.prototype.removeContents = function() { - this.getBrowserRangeWrapper_().removeContents(); - this.clearCachedValues_(); -}; - - -/** - * Surrounds the text range with the specified element (on Mozilla) or with a - * clone of the specified element (on IE). Returns a reference to the - * surrounding element if the operation was successful; returns null if the - * operation failed. - * @param {Element} element The element with which the selection is to be - * surrounded. - * @return {Element} The surrounding element (same as the argument on Mozilla, - * but not on IE), or null if unsuccessful. - */ -goog.dom.TextRange.prototype.surroundContents = function(element) { - var output = this.getBrowserRangeWrapper_().surroundContents(element); - this.clearCachedValues_(); - return output; -}; - - -/** @override */ -goog.dom.TextRange.prototype.insertNode = function(node, before) { - var output = this.getBrowserRangeWrapper_().insertNode(node, before); - this.clearCachedValues_(); - return output; -}; - - -/** @override */ -goog.dom.TextRange.prototype.surroundWithNodes = function(startNode, endNode) { - this.getBrowserRangeWrapper_().surroundWithNodes(startNode, endNode); - this.clearCachedValues_(); -}; - - -// SAVE/RESTORE - - -/** @override */ -goog.dom.TextRange.prototype.saveUsingDom = function() { - return new goog.dom.DomSavedTextRange_(this); -}; - - -// RANGE MODIFICATION - - -/** @override */ -goog.dom.TextRange.prototype.collapse = function(toAnchor) { - var toStart = this.isReversed() ? !toAnchor : toAnchor; - - if (this.browserRangeWrapper_) { - this.browserRangeWrapper_.collapse(toStart); - } - - if (toStart) { - this.endNode_ = this.startNode_; - this.endOffset_ = this.startOffset_; - } else { - this.startNode_ = this.endNode_; - this.startOffset_ = this.endOffset_; - } - - // Collapsed ranges can't be reversed - this.isReversed_ = false; -}; - - -// SAVED RANGE OBJECTS - - - -/** - * A SavedRange implementation using DOM endpoints. - * @param {goog.dom.AbstractRange} range The range to save. - * @constructor - * @extends {goog.dom.SavedRange} - * @private - */ -goog.dom.DomSavedTextRange_ = function(range) { - /** - * The anchor node. - * @type {Node} - * @private - */ - this.anchorNode_ = range.getAnchorNode(); - - /** - * The anchor node offset. - * @type {number} - * @private - */ - this.anchorOffset_ = range.getAnchorOffset(); - - /** - * The focus node. - * @type {Node} - * @private - */ - this.focusNode_ = range.getFocusNode(); - - /** - * The focus node offset. - * @type {number} - * @private - */ - this.focusOffset_ = range.getFocusOffset(); -}; -goog.inherits(goog.dom.DomSavedTextRange_, goog.dom.SavedRange); - - -/** - * @return {goog.dom.AbstractRange} The restored range. - */ -goog.dom.DomSavedTextRange_.prototype.restoreInternal = function() { - return goog.dom.Range.createFromNodes(this.anchorNode_, this.anchorOffset_, - this.focusNode_, this.focusOffset_); -}; - - -/** @override */ -goog.dom.DomSavedTextRange_.prototype.disposeInternal = function() { - goog.dom.DomSavedTextRange_.superClass_.disposeInternal.call(this); - - this.anchorNode_ = null; - this.focusNode_ = null; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrange_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrange_test.html.svn-base deleted file mode 100644 index 12af489..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrange_test.html.svn-base +++ /dev/null @@ -1,127 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.TextRange</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.Range'); - goog.require('goog.dom.ControlRange'); - goog.require('goog.dom.TextRange'); - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -</head> -<body> - <div id="test1"></div> - <div id="test2"> - <img id="logo" src="http://www.google.com/intl/en_ALL/images/logo.gif"> - </div> - <!-- Omit whitespace here to ensure no extra text nodes are included. --> - <table id="table"><tbody id="tbody"><tr id="tr1"><td id="td11">a</td - ><td id="td12">b</td></tr><tr id="tr2"><td id="td21">c</td><td id="td22" - >d</td></tr></tbody></table> - <table id="table2"> - <tr> - <td>moof</td> - </tr> - <tr> - <td id="table2td"> - <div id="table2div">foo<img id="logo2" - src="http://www.google.com/intl/en_ALL/images/logo.gif">bar</div> - </td> - </tr> - </table> - - -<script> - var logo = goog.dom.getElement('logo'); - var logo2 = goog.dom.getElement('logo2'); - var table = goog.dom.getElement('table'); - var table2 = goog.dom.getElement('table2'); - var table2div = goog.dom.getElement('table2div'); - - function testCreateFromNodeContents() { - assertNotNull('Text range object can be created for element node', - goog.dom.TextRange.createFromNodeContents(logo)); - assertNotNull('Text range object can be created for text node', - goog.dom.TextRange.createFromNodeContents(logo2.previousSibling)); - } - - function testMoveToNodes() { - var range = goog.dom.TextRange.createFromNodeContents(table2); - range.moveToNodes(table2div, 0, table2div, 1, false); - assertEquals('Range should start in table2div', - table2div, - range.getStartNode()); - assertEquals('Range should end in table2div', - table2div, - range.getEndNode()); - assertEquals('Range start offset should be 0', - 0, - range.getStartOffset()); - assertEquals('Range end offset should be 0', - 1, - range.getEndOffset()); - assertFalse('Range should not be reversed', - range.isReversed()); - range.moveToNodes(table2div, 0, table2div, 1, true); - assertTrue('Range should be reversed', - range.isReversed()); - assertEquals('Range text should be "foo"', - 'foo', - range.getText()); - } - - function testContainsTextRange() { - var range = goog.dom.TextRange.createFromNodeContents(table2); - var range2 = goog.dom.TextRange.createFromNodeContents(table2div); - assertTrue('TextRange contains other TextRange', - range.containsRange(range2)); - assertFalse('TextRange does not contain other TextRange', - range2.containsRange(range)); - - range = goog.dom.Range.createFromNodes( - table2div.firstChild, 1, table2div.lastChild, 1); - range2 = goog.dom.TextRange.createFromNodes( - table2div.firstChild, 0, table2div.lastChild, 0); - if (!goog.userAgent.WEBKIT) { - // TODO(user): Figure out why this fails, fix it, and get the WebKit - // folks to fix it :-) - assertTrue('TextRange partially contains other TextRange', - range2.containsRange(range, true)); - } - assertFalse('TextRange does not fully contain other TextRange', - range2.containsRange(range, false)); - - } - - function testContainsControlRange() { - if (goog.userAgent.IE) { - var range = goog.dom.ControlRange.createFromElements(table2); - var range2 = goog.dom.TextRange.createFromNodeContents(table2div); - assertFalse('TextRange does not contain ControlRange', - range2.containsRange(range)); - range = goog.dom.ControlRange.createFromElements(logo2); - assertTrue('TextRange contains ControlRange', - range2.containsRange(range)); - range = goog.dom.TextRange.createFromNodeContents(table2); - range2 = goog.dom.ControlRange.createFromElements(logo, logo2); - assertTrue('TextRange partially contains ControlRange', - range2.containsRange(range, true)); - assertFalse('TextRange does not fully contain ControlRange', - range2.containsRange(range, false)); - } - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrangeiterator.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrangeiterator.js.svn-base deleted file mode 100644 index aef7f77..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrangeiterator.js.svn-base +++ /dev/null @@ -1,246 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Iterator between two DOM text range positions. - * - * @author robbyw@google.com (Robby Walker) - */ - -goog.provide('goog.dom.TextRangeIterator'); - -goog.require('goog.array'); -goog.require('goog.dom.NodeType'); -goog.require('goog.dom.RangeIterator'); -goog.require('goog.dom.TagName'); -goog.require('goog.iter.StopIteration'); - - - -/** - * Subclass of goog.dom.TagIterator that iterates over a DOM range. It - * adds functions to determine the portion of each text node that is selected. - * - * @param {Node} startNode The starting node position. - * @param {number} startOffset The offset in to startNode. If startNode is - * an element, indicates an offset in to childNodes. If startNode is a - * text node, indicates an offset in to nodeValue. - * @param {Node} endNode The ending node position. - * @param {number} endOffset The offset in to endNode. If endNode is - * an element, indicates an offset in to childNodes. If endNode is a - * text node, indicates an offset in to nodeValue. - * @param {boolean=} opt_reverse Whether to traverse nodes in reverse. - * @constructor - * @extends {goog.dom.RangeIterator} - */ -goog.dom.TextRangeIterator = function(startNode, startOffset, endNode, - endOffset, opt_reverse) { - var goNext; - - if (startNode) { - this.startNode_ = startNode; - this.startOffset_ = startOffset; - this.endNode_ = endNode; - this.endOffset_ = endOffset; - - // Skip to the offset nodes - being careful to special case BRs since these - // have no children but still can appear as the startContainer of a range. - if (startNode.nodeType == goog.dom.NodeType.ELEMENT && - startNode.tagName != goog.dom.TagName.BR) { - var startChildren = startNode.childNodes; - var candidate = startChildren[startOffset]; - if (candidate) { - this.startNode_ = candidate; - this.startOffset_ = 0; - } else { - if (startChildren.length) { - this.startNode_ = - /** @type {Node} */ (goog.array.peek(startChildren)); - } - goNext = true; - } - } - - if (endNode.nodeType == goog.dom.NodeType.ELEMENT) { - this.endNode_ = endNode.childNodes[endOffset]; - if (this.endNode_) { - this.endOffset_ = 0; - } else { - // The offset was past the last element. - this.endNode_ = endNode; - } - } - } - - goog.dom.RangeIterator.call(this, opt_reverse ? this.endNode_ : - this.startNode_, opt_reverse); - - if (goNext) { - try { - this.next(); - } catch (e) { - if (e != goog.iter.StopIteration) { - throw e; - } - } - } -}; -goog.inherits(goog.dom.TextRangeIterator, goog.dom.RangeIterator); - - -/** - * The first node in the selection. - * @type {Node} - * @private - */ -goog.dom.TextRangeIterator.prototype.startNode_ = null; - - -/** - * The last node in the selection. - * @type {Node} - * @private - */ -goog.dom.TextRangeIterator.prototype.endNode_ = null; - - -/** - * The offset within the first node in the selection. - * @type {number} - * @private - */ -goog.dom.TextRangeIterator.prototype.startOffset_ = 0; - - -/** - * The offset within the last node in the selection. - * @type {number} - * @private - */ -goog.dom.TextRangeIterator.prototype.endOffset_ = 0; - - -/** @override */ -goog.dom.TextRangeIterator.prototype.getStartTextOffset = function() { - // Offsets only apply to text nodes. If our current node is the start node, - // return the saved offset. Otherwise, return 0. - return this.node.nodeType != goog.dom.NodeType.TEXT ? -1 : - this.node == this.startNode_ ? this.startOffset_ : 0; -}; - - -/** @override */ -goog.dom.TextRangeIterator.prototype.getEndTextOffset = function() { - // Offsets only apply to text nodes. If our current node is the end node, - // return the saved offset. Otherwise, return the length of the node. - return this.node.nodeType != goog.dom.NodeType.TEXT ? -1 : - this.node == this.endNode_ ? this.endOffset_ : this.node.nodeValue.length; -}; - - -/** @override */ -goog.dom.TextRangeIterator.prototype.getStartNode = function() { - return this.startNode_; -}; - - -/** - * Change the start node of the iterator. - * @param {Node} node The new start node. - */ -goog.dom.TextRangeIterator.prototype.setStartNode = function(node) { - if (!this.isStarted()) { - this.setPosition(node); - } - - this.startNode_ = node; - this.startOffset_ = 0; -}; - - -/** @override */ -goog.dom.TextRangeIterator.prototype.getEndNode = function() { - return this.endNode_; -}; - - -/** - * Change the end node of the iterator. - * @param {Node} node The new end node. - */ -goog.dom.TextRangeIterator.prototype.setEndNode = function(node) { - this.endNode_ = node; - this.endOffset_ = 0; -}; - - -/** @override */ -goog.dom.TextRangeIterator.prototype.isLast = function() { - return this.isStarted() && this.node == this.endNode_ && - (!this.endOffset_ || !this.isStartTag()); -}; - - -/** - * Move to the next position in the selection. - * Throws {@code goog.iter.StopIteration} when it passes the end of the range. - * @return {Node} The node at the next position. - */ -goog.dom.TextRangeIterator.prototype.next = function() { - if (this.isLast()) { - throw goog.iter.StopIteration; - } - - // Call the super function. - return goog.dom.TextRangeIterator.superClass_.next.call(this); -}; - - -/** @override */ -goog.dom.TextRangeIterator.prototype.skipTag = function() { - goog.dom.TextRangeIterator.superClass_.skipTag.apply(this); - - // If the node we are skipping contains the end node, we just skipped past - // the end, so we stop the iteration. - if (goog.dom.contains(this.node, this.endNode_)) { - throw goog.iter.StopIteration; - } -}; - - -/** - * Replace this iterator's values with values from another. - * @param {goog.dom.TextRangeIterator} other The iterator to copy. - * @protected - */ -goog.dom.TextRangeIterator.prototype.copyFrom = function(other) { - this.startNode_ = other.startNode_; - this.endNode_ = other.endNode_; - this.startOffset_ = other.startOffset_; - this.endOffset_ = other.endOffset_; - this.isReversed_ = other.isReversed_; - - goog.dom.TextRangeIterator.superClass_.copyFrom.call(this, other); -}; - - -/** - * @return {goog.dom.TextRangeIterator} An identical iterator. - */ -goog.dom.TextRangeIterator.prototype.clone = function() { - var copy = new goog.dom.TextRangeIterator(this.startNode_, - this.startOffset_, this.endNode_, this.endOffset_, this.isReversed_); - copy.copyFrom(this); - return copy; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrangeiterator_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrangeiterator_test.html.svn-base deleted file mode 100644 index 028b771..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/textrangeiterator_test.html.svn-base +++ /dev/null @@ -1,142 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>goog.dom.TextRangeIterator Tests</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom'); - goog.require('goog.dom.TagName'); - goog.require('goog.dom.TextRangeIterator'); - goog.require('goog.testing.dom'); - goog.require('goog.testing.jsunit'); -</script> -</head> -<body> - -<!-- - The next line goes past 80 characters to avoid ambiguity with - newlines as text nodes ---> -<div id="test"><a href="#" id="a1">T<b id="b1">e</b>xt</a><span id="span1"></span><p id="p1">Text</p></div> -<ul id="test2">foo<br>bar</ul> - -<script> - var test = goog.dom.getElement('test'); - var test2 = goog.dom.getElement('test2'); - - function testBasic() { - goog.testing.dom.assertNodesMatch( - new goog.dom.TextRangeIterator(test, 0, test, 2), - ['#a1', 'T', '#b1', 'e', '#b1', 'xt', '#a1', '#span1', - '#span1', '#p1']); - } - - function testAdjustStart() { - var iterator = new goog.dom.TextRangeIterator(test, 0, test, 2); - iterator.setStartNode(goog.dom.getElement('span1')); - - goog.testing.dom.assertNodesMatch(iterator, - ['#span1', '#span1', '#p1']); - } - - function testAdjustEnd() { - var iterator = new goog.dom.TextRangeIterator(test, 0, test, 2); - iterator.setEndNode(goog.dom.getElement('span1')); - - goog.testing.dom.assertNodesMatch(iterator, - ['#a1', 'T', '#b1', 'e', '#b1', 'xt', '#a1', '#span1']); - } - - function testOffsets() { - var iterator = new goog.dom.TextRangeIterator(test2.firstChild, 1, - test2.lastChild, 2); - - // foo - var node = iterator.next(); - assertEquals('Should have start offset at iteration step 1', 1, - iterator.getStartTextOffset()); - assertEquals('Should not have end offset at iteration step 1', - node.nodeValue.length, iterator.getEndTextOffset()); - - // <br> - node = iterator.next(); - assertEquals('Should not have start offset at iteration step 2', -1, - iterator.getStartTextOffset()); - assertEquals('Should not have end offset at iteration step 2', -1, - iterator.getEndTextOffset()); - - // </br> - node = iterator.next(); - assertEquals('Should not have start offset at iteration step 3', -1, - iterator.getStartTextOffset()); - assertEquals('Should not have end offset at iteration step 3', -1, - iterator.getEndTextOffset()); - - // bar - node = iterator.next(); - assertEquals('Should not have start offset at iteration step 4', 0, - iterator.getStartTextOffset()); - assertEquals('Should have end offset at iteration step 4', 2, - iterator.getEndTextOffset()); - } - - function testSingleNodeOffsets() { - var iterator = new goog.dom.TextRangeIterator(test2.firstChild, 1, - test2.firstChild, 2); - - iterator.next(); - assertEquals('Should have start offset', 1, iterator.getStartTextOffset()); - assertEquals('Should have end offset', 2, iterator.getEndTextOffset()); - } - - function testEndNodeOffsetAtEnd() { - var iterator = new goog.dom.TextRangeIterator( - goog.dom.getElement('b1').firstChild, 0, goog.dom.getElement('b1'), 1); - goog.testing.dom.assertNodesMatch(iterator, ['e', '#b1']); - } - - function testSkipTagDoesNotSkipEnd() { - // Iterate over 'Tex'. - var iterator = new goog.dom.TextRangeIterator( - test.firstChild.firstChild, 0, - test.firstChild.lastChild, 1); - - var node = iterator.next(); - assertEquals('T', node.nodeValue); - - node = iterator.next(); - assertEquals(goog.dom.TagName.B, node.tagName); - - iterator.skipTag(); - - node = iterator.next(); - assertEquals('xt', node.nodeValue); - } - - function testSkipTagSkipsEnd() { - // Iterate over 'Te'. - var iterator = new goog.dom.TextRangeIterator( - test.firstChild.firstChild, 0, - test.getElementsByTagName(goog.dom.TagName.B)[0].firstChild, 1); - - var node = iterator.next(); - assertEquals('T', node.nodeValue); - - node = iterator.next(); - assertEquals(goog.dom.TagName.B, node.tagName); - - var ex = assertThrows('Should stop iteration when skipping B', function() { - iterator.skipTag(); - }); - assertEquals(goog.iter.StopIteration, ex); - } -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/viewportsizemonitor.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/viewportsizemonitor.js.svn-base deleted file mode 100644 index db24177..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/viewportsizemonitor.js.svn-base +++ /dev/null @@ -1,219 +0,0 @@ -// Copyright 2007 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview Utility class that monitors viewport size changes. - * - * @author attila@google.com (Attila Bodis) - * @see ../demos/viewportsizemonitor.html - */ - -goog.provide('goog.dom.ViewportSizeMonitor'); - -goog.require('goog.dom'); -goog.require('goog.events'); -goog.require('goog.events.EventTarget'); -goog.require('goog.events.EventType'); -goog.require('goog.math.Size'); -goog.require('goog.userAgent'); - - - -/** - * This class can be used to monitor changes in the viewport size. Instances - * dispatch a {@link goog.events.EventType.RESIZE} event when the viewport size - * changes. Handlers can call {@link goog.dom.ViewportSizeMonitor#getSize} to - * get the new viewport size. - * - * Use this class if you want to execute resize/reflow logic each time the - * user resizes the browser window. This class is guaranteed to only dispatch - * {@code RESIZE} events when the pixel dimensions of the viewport change. - * (Internet Explorer fires resize events if any element on the page is resized, - * even if the viewport dimensions are unchanged, which can lead to infinite - * resize loops.) - * - * Example usage: - * <pre> - * var vsm = new goog.dom.ViewportSizeMonitor(); - * goog.events.listen(vsm, goog.events.EventType.RESIZE, function(e) { - * alert('Viewport size changed to ' + vsm.getSize()); - * }); - * </pre> - * - * Manually verified on IE6, IE7, FF2, Opera 9, and WebKit. {@code getSize} - * doesn't always return the correct viewport height on Safari 2.0.4. - * - * @param {Window=} opt_window The window to monitor; defaults to the window in - * which this code is executing. - * @constructor - * @extends {goog.events.EventTarget} - */ -goog.dom.ViewportSizeMonitor = function(opt_window) { - goog.events.EventTarget.call(this); - - // Default the window to the current window if unspecified. - this.window_ = opt_window || window; - - // Listen for window resize events. - this.listenerKey_ = goog.events.listen(this.window_, - goog.events.EventType.RESIZE, this.handleResize_, false, this); - - // Set the initial size. - this.size_ = goog.dom.getViewportSize(this.window_); - - if (this.isPollingRequired_()) { - this.windowSizePollInterval_ = window.setInterval( - goog.bind(this.checkForSizeChange_, this), - goog.dom.ViewportSizeMonitor.WINDOW_SIZE_POLL_RATE); - } -}; -goog.inherits(goog.dom.ViewportSizeMonitor, goog.events.EventTarget); - - -/** - * Returns a viewport size monitor for the given window. A new one is created - * if it doesn't exist already. This prevents the unnecessary creation of - * multiple spooling monitors for a window. - * @param {Window=} opt_window The window to monitor; defaults to the window in - * which this code is executing. - * @return {goog.dom.ViewportSizeMonitor} Monitor for the given window. - */ -goog.dom.ViewportSizeMonitor.getInstanceForWindow = function(opt_window) { - var currentWindow = opt_window || window; - var uid = goog.getUid(currentWindow); - - return goog.dom.ViewportSizeMonitor.windowInstanceMap_[uid] = - goog.dom.ViewportSizeMonitor.windowInstanceMap_[uid] || - new goog.dom.ViewportSizeMonitor(currentWindow); -}; - - -/** - * Map of window hash code to viewport size monitor for that window, if - * created. - * @type {Object.<number,goog.dom.ViewportSizeMonitor>} - * @private - */ -goog.dom.ViewportSizeMonitor.windowInstanceMap_ = {}; - - -/** - * Rate in milliseconds at which to poll the window size on browsers that - * need polling. - * @type {number} - */ -goog.dom.ViewportSizeMonitor.WINDOW_SIZE_POLL_RATE = 500; - - -/** - * Event listener key for window the window resize handler, as returned by - * {@link goog.events.listen}. - * @type {?number} - * @private - */ -goog.dom.ViewportSizeMonitor.prototype.listenerKey_ = null; - - -/** - * The window to monitor. Defaults to the window in which the code is running. - * @type {Window} - * @private - */ -goog.dom.ViewportSizeMonitor.prototype.window_ = null; - - -/** - * The most recently recorded size of the viewport, in pixels. - * @type {goog.math.Size?} - * @private - */ -goog.dom.ViewportSizeMonitor.prototype.size_ = null; - - -/** - * Identifier for the interval used for polling the window size on Windows - * Safari. - * @type {?number} - * @private - */ -goog.dom.ViewportSizeMonitor.prototype.windowSizePollInterval_ = null; - - -/** - * Checks if polling is required for this user agent. Opera only requires - * polling when the page is loaded within an IFRAME. - * @return {boolean} Whether polling is required. - * @private - */ -goog.dom.ViewportSizeMonitor.prototype.isPollingRequired_ = function() { - return goog.userAgent.WEBKIT && goog.userAgent.WINDOWS || - goog.userAgent.OPERA && this.window_.self != this.window_.top; -}; - - -/** - * Returns the most recently recorded size of the viewport, in pixels. May - * return null if no window resize event has been handled yet. - * @return {goog.math.Size} The viewport dimensions, in pixels. - */ -goog.dom.ViewportSizeMonitor.prototype.getSize = function() { - // Return a clone instead of the original to preserve encapsulation. - return this.size_ ? this.size_.clone() : null; -}; - - -/** @override */ -goog.dom.ViewportSizeMonitor.prototype.disposeInternal = function() { - goog.dom.ViewportSizeMonitor.superClass_.disposeInternal.call(this); - - if (this.listenerKey_) { - goog.events.unlistenByKey(this.listenerKey_); - this.listenerKey_ = null; - } - - if (this.windowSizePollInterval_) { - window.clearInterval(this.windowSizePollInterval_); - this.windowSizePollInterval_ = null; - } - - this.window_ = null; - this.size_ = null; -}; - - -/** - * Handles window resize events by measuring the dimensions of the - * viewport and dispatching a {@link goog.events.EventType.RESIZE} event if the - * current dimensions are different from the previous ones. - * @param {goog.events.Event} event The window resize event to handle. - * @private - */ -goog.dom.ViewportSizeMonitor.prototype.handleResize_ = function(event) { - this.checkForSizeChange_(); -}; - - -/** - * Measures the dimensions of the viewport and dispatches a - * {@link goog.events.EventType.RESIZE} event if the current dimensions are - * different from the previous ones. - * @private - */ -goog.dom.ViewportSizeMonitor.prototype.checkForSizeChange_ = function() { - var size = goog.dom.getViewportSize(this.window_); - if (!goog.math.Size.equals(size, this.size_)) { - this.size_ = size; - this.dispatchEvent(goog.events.EventType.RESIZE); - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/viewportsizemonitor_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/viewportsizemonitor_test.html.svn-base deleted file mode 100644 index d9b3c5f..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/viewportsizemonitor_test.html.svn-base +++ /dev/null @@ -1,166 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.dom.ViewportSizeMonitor</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom.ViewportSizeMonitor'); - goog.require('goog.events.Event'); - goog.require('goog.events.EventTarget'); - goog.require('goog.events.EventType'); - goog.require('goog.testing.jsunit'); - goog.require('goog.testing.MockClock'); - goog.require('goog.testing.PropertyReplacer'); -</script> -</head> -<body> -<script> - var propertyReplacer, fakeWindow, viewportSizeMonitor, mockClock; - - - function FakeWindow() { - }; - goog.inherits(FakeWindow, goog.events.EventTarget); - - - FakeWindow.prototype.fireResize = function() { - return this.dispatchEvent(new FakeResizeEvent()); - }; - - - function FakeResizeEvent(obj) { - this.type = goog.events.EventType.RESIZE; - } - goog.inherits(FakeResizeEvent, goog.events.Event); - - - function getViewportSize() { - return viewportSize; - }; - - - function setViewportSize(w, h, fireEvent) { - this.viewportSize = new goog.math.Size(w, h); - if (fireEvent) { - fakeWindow.fireResize(); - } - }; - - - var eventWasFired = {}; - function getListenerFn(id) { - return function() { - propertyReplacer.set(eventWasFired, id, true); - }; - }; - - - function listenerWasCalled(id) { - return !!eventWasFired[id]; - }; - - - function setUp() { - propertyReplacer = new goog.testing.PropertyReplacer(); - propertyReplacer.set(goog.dom, 'getViewportSize', getViewportSize); - mockClock = new goog.testing.MockClock(); - mockClock.install(); - fakeWindow = new FakeWindow(); - setViewportSize(300, 300); - viewportSizeMonitor = new goog.dom.ViewportSizeMonitor(fakeWindow); - }; - - - function tearDown() { - propertyReplacer.reset(); - mockClock.uninstall(); - }; - - - function testResizeEvent() { - goog.events.listen(viewportSizeMonitor, goog.events.EventType.RESIZE, - getListenerFn(1)); - assertFalse('Listener should not be called if window was not resized', - listenerWasCalled(1)); - setViewportSize(300, 300, true); - assertFalse('Listener should not be called for bogus resize event', - listenerWasCalled(1)); - setViewportSize(301, 301, true); - assertTrue('Listener should be called for valid resize event', - listenerWasCalled(1)); - }; - - - function testPollingEvent() { - propertyReplacer.set(goog.dom.ViewportSizeMonitor.prototype, - 'isPollingRequired_', function() { return true; }); - viewportSizeMonitor = new goog.dom.ViewportSizeMonitor(fakeWindow); - goog.events.listen(viewportSizeMonitor, goog.events.EventType.RESIZE, - getListenerFn(1)); - assertFalse('Listener should not be called if window was not resized', - listenerWasCalled(1)); - mockClock.tick(goog.dom.ViewportSizeMonitor.WINDOW_SIZE_POLL_RATE); - assertFalse('Listener should not be called if window was not resized ' + - 'during polling', listenerWasCalled(1)); - setViewportSize(301, 301, false); - mockClock.tick(goog.dom.ViewportSizeMonitor.WINDOW_SIZE_POLL_RATE); - assertTrue('Listener should be called for valid resize during polling', - listenerWasCalled(1)); - }; - - - function testIsPollingRequired() { - propertyReplacer.set(goog.userAgent, 'WEBKIT', false); - propertyReplacer.set(goog.userAgent, 'OPERA', false); - assertFalse('Polling should not be required except for WebKit and Opera', - viewportSizeMonitor.isPollingRequired_()); - propertyReplacer.set(goog.userAgent, 'WEBKIT', true); - propertyReplacer.set(goog.userAgent, 'WINDOWS', true); - assertTrue('WebKit on Windows should require polling', - viewportSizeMonitor.isPollingRequired_()); - propertyReplacer.set(goog.userAgent, 'WEBKIT', false); - propertyReplacer.set(goog.userAgent, 'OPERA', true); - - // window.top and window.self are read-only in Opera - fakeWindow.self = fakeWindow; - fakeWindow.top = {}; - assertEquals('Opera should require polling if window.top != window.self', - viewportSizeMonitor.isPollingRequired_(), true); - fakeWindow.self = fakeWindow; - fakeWindow.top = fakeWindow; - assertEquals( - 'Opera should not require polling if window.top == window.self', - viewportSizeMonitor.isPollingRequired_(), false); - }; - - - function testInstanceGetter() { - var fakeWindow1 = new FakeWindow(); - var monitor1 = goog.dom.ViewportSizeMonitor.getInstanceForWindow( - fakeWindow1); - var monitor2 = goog.dom.ViewportSizeMonitor.getInstanceForWindow( - fakeWindow1); - assertEquals('The same window should give us the same instance monitor', - monitor1, monitor2); - - var fakeWindow2 = new FakeWindow(); - var monitor3 = goog.dom.ViewportSizeMonitor.getInstanceForWindow( - fakeWindow2); - assertNotEquals('Different windows should give different instances', - monitor1, monitor3); - - assertEquals('Monitors should match if opt_window is not provided', - goog.dom.ViewportSizeMonitor.getInstanceForWindow(), - goog.dom.ViewportSizeMonitor.getInstanceForWindow()); - } - -</script> -</body> -</html> diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/xml.js.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/xml.js.svn-base deleted file mode 100644 index a5ab4f8..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/xml.js.svn-base +++ /dev/null @@ -1,204 +0,0 @@ -// Copyright 2006 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview - * XML utilities. - * - */ - -goog.provide('goog.dom.xml'); - -goog.require('goog.dom'); -goog.require('goog.dom.NodeType'); - - -/** - * Max XML size for MSXML2. Used to prevent potential DoS attacks. - * @type {number} - */ -goog.dom.xml.MAX_XML_SIZE_KB = 2 * 1024; // In kB - - -/** - * Max XML size for MSXML2. Used to prevent potential DoS attacks. - * @type {number} - */ -goog.dom.xml.MAX_ELEMENT_DEPTH = 256; // Same default as MSXML6. - - -/** - * Creates an XML document appropriate for the current JS runtime - * @param {string=} opt_rootTagName The root tag name. - * @param {string=} opt_namespaceUri Namespace URI of the document element. - * @return {Document} The new document. - */ -goog.dom.xml.createDocument = function(opt_rootTagName, opt_namespaceUri) { - if (opt_namespaceUri && !opt_rootTagName) { - throw Error("Can't create document with namespace and no root tag"); - } - if (document.implementation && document.implementation.createDocument) { - return document.implementation.createDocument(opt_namespaceUri || '', - opt_rootTagName || '', - null); - } else if (typeof ActiveXObject != 'undefined') { - var doc = goog.dom.xml.createMsXmlDocument_(); - if (doc) { - if (opt_rootTagName) { - doc.appendChild(doc.createNode(goog.dom.NodeType.ELEMENT, - opt_rootTagName, - opt_namespaceUri || '')); - } - return doc; - } - } - throw Error('Your browser does not support creating new documents'); -}; - - -/** - * Creates an XML document from a string - * @param {string} xml The text. - * @return {Document} XML document from the text. - */ -goog.dom.xml.loadXml = function(xml) { - if (typeof DOMParser != 'undefined') { - return new DOMParser().parseFromString(xml, 'application/xml'); - } else if (typeof ActiveXObject != 'undefined') { - var doc = goog.dom.xml.createMsXmlDocument_(); - doc.loadXML(xml); - return doc; - } - throw Error('Your browser does not support loading xml documents'); -}; - - -/** - * Serializes an XML document or subtree to string. - * @param {Document|Element} xml The document or the root node of the subtree. - * @return {string} The serialized XML. - */ -goog.dom.xml.serialize = function(xml) { - // Compatible with Firefox, Opera and WebKit. - if (typeof XMLSerializer != 'undefined') { - return new XMLSerializer().serializeToString(xml); - } - // Compatible with Internet Explorer. - var text = xml.xml; - if (text) { - return text; - } - throw Error('Your browser does not support serializing XML documents'); -}; - - -/** - * Selects a single node using an Xpath expression and a root node - * @param {Node} node The root node. - * @param {string} path Xpath selector. - * @return {Node} The selected node, or null if no matching node. - */ -goog.dom.xml.selectSingleNode = function(node, path) { - if (typeof node.selectSingleNode != 'undefined') { - var doc = goog.dom.getOwnerDocument(node); - if (typeof doc.setProperty != 'undefined') { - doc.setProperty('SelectionLanguage', 'XPath'); - } - return node.selectSingleNode(path); - } else if (document.implementation.hasFeature('XPath', '3.0')) { - var doc = goog.dom.getOwnerDocument(node); - var resolver = doc.createNSResolver(doc.documentElement); - var result = doc.evaluate(path, node, resolver, - XPathResult.FIRST_ORDERED_NODE_TYPE, null); - return result.singleNodeValue; - } - return null; -}; - - -/** - * Selects multiple nodes using an Xpath expression and a root node - * @param {Node} node The root node. - * @param {string} path Xpath selector. - * @return {(NodeList,Array.<Node>)} The selected nodes, or empty array if no - * matching nodes. - */ -goog.dom.xml.selectNodes = function(node, path) { - if (typeof node.selectNodes != 'undefined') { - var doc = goog.dom.getOwnerDocument(node); - if (typeof doc.setProperty != 'undefined') { - doc.setProperty('SelectionLanguage', 'XPath'); - } - return node.selectNodes(path); - } else if (document.implementation.hasFeature('XPath', '3.0')) { - var doc = goog.dom.getOwnerDocument(node); - var resolver = doc.createNSResolver(doc.documentElement); - var nodes = doc.evaluate(path, node, resolver, - XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); - var results = []; - var count = nodes.snapshotLength; - for (var i = 0; i < count; i++) { - results.push(nodes.snapshotItem(i)); - } - return results; - } else { - return []; - } -}; - - -/** - * Sets multiple attributes on an element. Differs from goog.dom.setProperties - * in that it exclusively uses the element's setAttributes method. Use this - * when you need to ensure that the exact property is available as an attribute - * and can be read later by the native getAttribute method. - * @param {!Element} element XML or DOM element to set attributes on. - * @param {!Object.<string, string>} attributes Map of property:value pairs. - */ -goog.dom.xml.setAttributes = function(element, attributes) { - for (var key in attributes) { - if (attributes.hasOwnProperty(key)) { - element.setAttribute(key, attributes[key]); - } - } -}; - - -/** - * Creates an instance of the MSXML2.DOMDocument. - * @return {Document} The new document. - * @private - */ -goog.dom.xml.createMsXmlDocument_ = function() { - var doc = new ActiveXObject('MSXML2.DOMDocument'); - if (doc) { - // Prevent potential vulnerabilities exposed by MSXML2, see - // http://b/1707300 and http://wiki/Main/ISETeamXMLAttacks for details. - doc.resolveExternals = false; - doc.validateOnParse = false; - // Add a try catch block because accessing these properties will throw an - // error on unsupported MSXML versions. This affects Windows machines - // running IE6 or IE7 that are on XP SP2 or earlier without MSXML updates. - // See http://msdn.microsoft.com/en-us/library/ms766391(VS.85).aspx for - // specific details on which MSXML versions support these properties. - try { - doc.setProperty('ProhibitDTD', true); - doc.setProperty('MaxXMLSize', goog.dom.xml.MAX_XML_SIZE_KB); - doc.setProperty('MaxElementDepth', goog.dom.xml.MAX_ELEMENT_DEPTH); - } catch (e) { - // No-op. - } - } - return doc; -}; diff --git a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/xml_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/xml_test.html.svn-base deleted file mode 100644 index 0c66d9f..0000000 --- a/contexts/data/lib/closure-library/closure/goog/dom/.svn/text-base/xml_test.html.svn-base +++ /dev/null @@ -1,103 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2008 The Closure Library Authors. All Rights Reserved. - -Use of this source code is governed by the Apache License, Version 2.0. -See the COPYING file for details. ---> -<head> -<meta http-equiv="X-UA-Compatible" content="IE=edge"> -<title>Closure Unit Tests - goog.net.MockXhrLite</title> -<script src="../base.js"></script> -<script> - goog.require('goog.dom.xml'); - goog.require('goog.string'); - goog.require('goog.testing.jsunit'); - goog.require('goog.userAgent'); -</script> -</head> -<body> -<script> - -function testSerialize() { - var doc = goog.dom.xml.createDocument(); - var node = doc.createElement('root'); - doc.appendChild(node); - - var serializedNode = goog.dom.xml.serialize(node); - assertTrue(/<root ?\/>/.test(serializedNode)); - - var serializedDoc = goog.dom.xml.serialize(doc); - assertTrue(/(<\?xml version="1.0"\?>)?<root ?\/>/.test(serializedDoc)); -} - -function testBelowMaxDepthInIE() { - if (goog.userAgent.IE) { - goog.dom.xml.MAX_ELEMENT_DEPTH = 5; - var junk = '<a><b><c><d><e>Hello</e></d></c></b></a>'; - var doc = goog.dom.xml.loadXml(junk); - assertEquals('Should not have caused a parse error', 0, - Number(doc.parseError)); - } -} - -function testAboveMaxDepthInIE() { - if (goog.userAgent.IE) { - goog.dom.xml.MAX_ELEMENT_DEPTH = 4; - var junk = '<a><b><c><d><e>Hello</e></d></c></b></a>'; - var doc = goog.dom.xml.loadXml(junk); - assertNotEquals('Should have caused a parse error', 0, - Number(doc.parseError)); - } -} - -function testBelowMaxSizeInIE() { - if (goog.userAgent.IE) { - goog.dom.xml.MAX_XML_SIZE_KB = 1; - var junk = '<a>' + new Array(50).join('<b>junk</b>') + '</a>'; - var doc = goog.dom.xml.loadXml(junk); - assertEquals('Should not have caused a parse error', - 0, Number(doc.parseError)); - } -} - -function testMaxSizeInIE() { - if (goog.userAgent.IE) { - goog.dom.xml.MAX_XML_SIZE_KB = 1; - var junk = '<a>' + new Array(1000).join('<b>junk</b>') + '</a>'; - var doc = goog.dom.xml.loadXml(junk); - assertNotEquals('Should have caused a parse error', 0, - Number(doc.parseError)); - } -} - -function testSetAttributes() { - var xmlElement = goog.dom.xml.createDocument().createElement('root'); - var domElement = document.createElement('div'); - var attrs = { - name: 'test3', - title: 'A title', - random: 'woop', - cellpadding: '123' - }; - - goog.dom.xml.setAttributes(xmlElement, attrs); - goog.dom.xml.setAttributes(domElement, attrs); - - assertEquals('test3', xmlElement.getAttribute('name')); - assertEquals('test3', domElement.getAttribute('name')); - - assertEquals('A title', xmlElement.getAttribute('title')); - assertEquals('A title', domElement.getAttribute('title')); - - assertEquals('woop', xmlElement.getAttribute('random')); - assertEquals('woop', domElement.getAttribute('random')); - - assertEquals('123', xmlElement.getAttribute('cellpadding')); - assertEquals('123', domElement.getAttribute('cellpadding')); -} - -</script> -</body> -</html> |