API Docs for: 0.9.1
Show:

File: lib/panelObject.js

// Copyright 2014, Yahoo! Inc.
// Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms.

var ViewObject = require('./viewObject');

/**
 * @class PanelObject
 * @extends ViewObject
 */
var PanelObject = ViewObject.extend(

	/**
	 * Panel-object constructor
	 *
	 * @constructor
	 * @param {Element} [root]
	 * @param {int} [timeOut]
	 * @param {int} [waitInMs]
	 */
	function (root, timeOut, waitInMs) {
		this.__super(this._getPanelRootElement(root, timeOut, waitInMs), timeOut, waitInMs);
	},

	{
		/**
		 * Gets the root element of the panel-object
		 *
		 * @param {Element} context
		 * @param {int} [timeOut]
		 * @param {int} [waitInMs]
		 * @returns {Element}
		 * @private
		 */
		_getPanelRootElement: function (context, timeOut, waitInMs) {
			var selector = this.constructor.SELECTOR,
				elements;

			context = context || this.getAdapter().getPageContext();

			if (selector) {

				this.waitUntil(function () {
					elements = context.getElements(selector);
					return elements.length > 0;
				}, timeOut, waitInMs);

				if (elements && elements.length === 1) {
					return elements[0];

				} else if (elements && elements.length > 1) {
					throw new Error("Panel-object selector is not specific enough. '" + selector + "'");

				} else {
					throw new Error("Root element for panel-object could not be found. '" + selector + "'");
				}

			} else {
				return context;
			}
		}
	},

	{
		/**
		 * @var {string}
		 */
		TYPE: 'PanelObject',

		/**
		 * Selector for panel
		 *
		 * @var {string}
		 */
		SELECTOR: undefined
	});

module.exports = PanelObject;