Adding float-no-zero branch hosted build
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
// 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.
|
||||
|
||||
/** @nocompile */
|
||||
|
||||
['Big Table', 'Googlebot', 'Instant Indexing', 'Mustang', 'Page Rank',
|
||||
'Proto Buffer']
|
||||
@@ -0,0 +1,33 @@
|
||||
// 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.
|
||||
|
||||
/** @nocompile */
|
||||
|
||||
[
|
||||
['apple',
|
||||
{name: 'Fuji', url: 'http://www.google.com/images?q=fuji+apple'},
|
||||
{name: 'Gala', url: 'http://www.google.com/images?q=gala+apple'},
|
||||
{name: 'Golden Delicious',
|
||||
url: 'http://www.google.com/images?q=golden delicious+apple'}
|
||||
],
|
||||
['citrus',
|
||||
{name: 'Lemon', url: 'http://www.google.com/images?q=lemon+fruit'},
|
||||
{name: 'Orange', url: 'http://www.google.com/images?q=orange+fruit'}
|
||||
],
|
||||
['berry',
|
||||
{name: 'Strawberry', url: 'http://www.google.com/images?q=strawberry+fruit'},
|
||||
{name: 'Blueberry', url: 'http://www.google.com/images?q=blueberry+fruit'},
|
||||
{name: 'Blackberry', url: 'http://www.google.com/images?q=blackberry+fruit'}
|
||||
]
|
||||
]
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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.
|
||||
//
|
||||
// This file has been auto-generated by GenJsDeps, please do not edit.
|
||||
|
||||
goog.addDependency('demos/editor/equationeditor.js', ['goog.demos.editor.EquationEditor'], ['goog.ui.equation.EquationEditorDialog']);
|
||||
goog.addDependency('demos/editor/helloworld.js', ['goog.demos.editor.HelloWorld'], ['goog.dom', 'goog.dom.TagName', 'goog.editor.Plugin']);
|
||||
goog.addDependency('demos/editor/helloworlddialog.js', ['goog.demos.editor.HelloWorldDialog', 'goog.demos.editor.HelloWorldDialog.OkEvent'], ['goog.dom.TagName', 'goog.events.Event', 'goog.string', 'goog.ui.editor.AbstractDialog', 'goog.ui.editor.AbstractDialog.Builder', 'goog.ui.editor.AbstractDialog.EventType']);
|
||||
goog.addDependency('demos/editor/helloworlddialogplugin.js', ['goog.demos.editor.HelloWorldDialogPlugin', 'goog.demos.editor.HelloWorldDialogPlugin.Command'], ['goog.demos.editor.HelloWorldDialog', 'goog.dom.TagName', 'goog.editor.plugins.AbstractDialogPlugin', 'goog.editor.range', 'goog.functions', 'goog.ui.editor.AbstractDialog.EventType']);
|
||||
@@ -0,0 +1,40 @@
|
||||
// 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.
|
||||
|
||||
/**
|
||||
* @see equationeditor.html
|
||||
*/
|
||||
|
||||
goog.provide('goog.demos.editor.EquationEditor');
|
||||
|
||||
goog.require('goog.ui.equation.EquationEditorDialog');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
goog.demos.editor.EquationEditor = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new editor and opens the dialog.
|
||||
* @param {string} initialEquation The initial equation value to use.
|
||||
*/
|
||||
goog.demos.editor.EquationEditor.prototype.openEditor = function(
|
||||
initialEquation) {
|
||||
var editorDialog = new goog.ui.equation.EquationEditorDialog(initialEquation);
|
||||
editorDialog.setVisible(true);
|
||||
};
|
||||
@@ -0,0 +1,81 @@
|
||||
// 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 A simple plugin that inserts 'Hello World!' on command. This
|
||||
* plugin is intended to be an example of a very simple plugin for plugin
|
||||
* developers.
|
||||
*
|
||||
* @author gak@google.com (Gregory Kick)
|
||||
* @see helloworld.html
|
||||
*/
|
||||
|
||||
goog.provide('goog.demos.editor.HelloWorld');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.dom.TagName');
|
||||
goog.require('goog.editor.Plugin');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Plugin to insert 'Hello World!' into an editable field.
|
||||
* @constructor
|
||||
* @extends {goog.editor.Plugin}
|
||||
*/
|
||||
goog.demos.editor.HelloWorld = function() {
|
||||
goog.editor.Plugin.call(this);
|
||||
};
|
||||
goog.inherits(goog.demos.editor.HelloWorld, goog.editor.Plugin);
|
||||
|
||||
|
||||
/** @override */
|
||||
goog.demos.editor.HelloWorld.prototype.getTrogClassId = function() {
|
||||
return 'HelloWorld';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Commands implemented by this plugin.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.demos.editor.HelloWorld.COMMAND = {
|
||||
HELLO_WORLD: '+helloWorld'
|
||||
};
|
||||
|
||||
|
||||
/** @override */
|
||||
goog.demos.editor.HelloWorld.prototype.isSupportedCommand = function(
|
||||
command) {
|
||||
return command == goog.demos.editor.HelloWorld.COMMAND.HELLO_WORLD;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Executes a command. Does not fire any BEFORECHANGE, CHANGE, or
|
||||
* SELECTIONCHANGE events (these are handled by the super class implementation
|
||||
* of {@code execCommand}.
|
||||
* @param {string} command Command to execute.
|
||||
* @override
|
||||
* @protected
|
||||
*/
|
||||
goog.demos.editor.HelloWorld.prototype.execCommandInternal = function(
|
||||
command) {
|
||||
var domHelper = this.getFieldObject().getEditableDomHelper();
|
||||
var range = this.getFieldObject().getRange();
|
||||
range.removeContents();
|
||||
var newNode =
|
||||
domHelper.createDom(goog.dom.TagName.SPAN, null, 'Hello World!');
|
||||
range.insertNode(newNode, false);
|
||||
};
|
||||
@@ -0,0 +1,171 @@
|
||||
// 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 example of how to write a dialog to be opened by a plugin.
|
||||
*
|
||||
*/
|
||||
|
||||
goog.provide('goog.demos.editor.HelloWorldDialog');
|
||||
goog.provide('goog.demos.editor.HelloWorldDialog.OkEvent');
|
||||
|
||||
goog.require('goog.dom.TagName');
|
||||
goog.require('goog.events.Event');
|
||||
goog.require('goog.string');
|
||||
goog.require('goog.ui.editor.AbstractDialog');
|
||||
|
||||
|
||||
// *** Public interface ***************************************************** //
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a dialog to let the user enter a customized hello world message.
|
||||
* @param {goog.dom.DomHelper} domHelper DomHelper to be used to create the
|
||||
* dialog's dom structure.
|
||||
* @constructor
|
||||
* @extends {goog.ui.editor.AbstractDialog}
|
||||
*/
|
||||
goog.demos.editor.HelloWorldDialog = function(domHelper) {
|
||||
goog.ui.editor.AbstractDialog.call(this, domHelper);
|
||||
};
|
||||
goog.inherits(goog.demos.editor.HelloWorldDialog,
|
||||
goog.ui.editor.AbstractDialog);
|
||||
|
||||
|
||||
// *** Event **************************************************************** //
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* OK event object for the hello world dialog.
|
||||
* @param {string} message Customized hello world message chosen by the user.
|
||||
* @constructor
|
||||
* @extends {goog.events.Event}
|
||||
*/
|
||||
goog.demos.editor.HelloWorldDialog.OkEvent = function(message) {
|
||||
this.message = message;
|
||||
};
|
||||
goog.inherits(goog.demos.editor.HelloWorldDialog.OkEvent, goog.events.Event);
|
||||
|
||||
|
||||
/**
|
||||
* Event type.
|
||||
* @type {goog.ui.editor.AbstractDialog.EventType}
|
||||
* @override
|
||||
*/
|
||||
goog.demos.editor.HelloWorldDialog.OkEvent.prototype.type =
|
||||
goog.ui.editor.AbstractDialog.EventType.OK;
|
||||
|
||||
|
||||
/**
|
||||
* Customized hello world message chosen by the user.
|
||||
* @type {string}
|
||||
*/
|
||||
goog.demos.editor.HelloWorldDialog.OkEvent.prototype.message;
|
||||
|
||||
|
||||
// *** Protected interface ************************************************** //
|
||||
|
||||
|
||||
/** @override */
|
||||
goog.demos.editor.HelloWorldDialog.prototype.createDialogControl = function() {
|
||||
var builder = new goog.ui.editor.AbstractDialog.Builder(this);
|
||||
/** @desc Title of the hello world dialog. */
|
||||
var MSG_HELLO_WORLD_DIALOG_TITLE = goog.getMsg('Add a Hello World message');
|
||||
builder.setTitle(MSG_HELLO_WORLD_DIALOG_TITLE).
|
||||
setContent(this.createContent_());
|
||||
return builder.build();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Creates and returns the event object to be used when dispatching the OK
|
||||
* event to listeners, or returns null to prevent the dialog from closing.
|
||||
* @param {goog.events.Event} e The event object dispatched by the wrapped
|
||||
* dialog.
|
||||
* @return {goog.demos.editor.HelloWorldDialog.OkEvent} The event object to be
|
||||
* used when dispatching the OK event to listeners.
|
||||
* @protected
|
||||
* @override
|
||||
*/
|
||||
goog.demos.editor.HelloWorldDialog.prototype.createOkEvent = function(e) {
|
||||
var message = this.getMessage_();
|
||||
if (message &&
|
||||
goog.demos.editor.HelloWorldDialog.isValidHelloWorld_(message)) {
|
||||
return new goog.demos.editor.HelloWorldDialog.OkEvent(message);
|
||||
} else {
|
||||
/** @desc Error message telling the user why their message was rejected. */
|
||||
var MSG_HELLO_WORLD_DIALOG_ERROR =
|
||||
goog.getMsg('Your message must contain the words "hello" and "world".');
|
||||
this.dom.getWindow().alert(MSG_HELLO_WORLD_DIALOG_ERROR);
|
||||
return null; // Prevents the dialog from closing.
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// *** Private implementation *********************************************** //
|
||||
|
||||
|
||||
/**
|
||||
* Input element where the user will type their hello world message.
|
||||
* @type {Element}
|
||||
* @private
|
||||
*/
|
||||
goog.demos.editor.HelloWorldDialog.prototype.input_;
|
||||
|
||||
|
||||
/**
|
||||
* Creates the DOM structure that makes up the dialog's content area.
|
||||
* @return {Element} The DOM structure that makes up the dialog's content area.
|
||||
* @private
|
||||
*/
|
||||
goog.demos.editor.HelloWorldDialog.prototype.createContent_ = function() {
|
||||
/** @desc Sample hello world message to prepopulate the dialog with. */
|
||||
var MSG_HELLO_WORLD_DIALOG_SAMPLE = goog.getMsg('Hello, world!');
|
||||
this.input_ = this.dom.createDom(goog.dom.TagName.INPUT,
|
||||
{size: 25, value: MSG_HELLO_WORLD_DIALOG_SAMPLE});
|
||||
/** @desc Prompt telling the user to enter a hello world message. */
|
||||
var MSG_HELLO_WORLD_DIALOG_PROMPT =
|
||||
goog.getMsg('Enter your Hello World message');
|
||||
return this.dom.createDom(goog.dom.TagName.DIV,
|
||||
null,
|
||||
[MSG_HELLO_WORLD_DIALOG_PROMPT, this.input_]);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns the hello world message currently typed into the dialog's input.
|
||||
* @return {?string} The hello world message currently typed into the dialog's
|
||||
* input, or null if called before the input is created.
|
||||
* @private
|
||||
*/
|
||||
goog.demos.editor.HelloWorldDialog.prototype.getMessage_ = function() {
|
||||
return this.input_ && this.input_.value;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether or not the given message contains the strings "hello" and
|
||||
* "world". Case-insensitive and order doesn't matter.
|
||||
* @param {string} message The message to be checked.
|
||||
* @return {boolean} Whether or not the given message contains the strings
|
||||
* "hello" and "world".
|
||||
* @private
|
||||
*/
|
||||
goog.demos.editor.HelloWorldDialog.isValidHelloWorld_ = function(message) {
|
||||
message = message.toLowerCase();
|
||||
return goog.string.contains(message, 'hello') &&
|
||||
goog.string.contains(message, 'world');
|
||||
};
|
||||
@@ -0,0 +1,116 @@
|
||||
// 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 example of how to write a dialog plugin.
|
||||
*
|
||||
*/
|
||||
|
||||
goog.provide('goog.demos.editor.HelloWorldDialogPlugin');
|
||||
goog.provide('goog.demos.editor.HelloWorldDialogPlugin.Command');
|
||||
|
||||
goog.require('goog.demos.editor.HelloWorldDialog');
|
||||
goog.require('goog.dom.TagName');
|
||||
goog.require('goog.editor.plugins.AbstractDialogPlugin');
|
||||
goog.require('goog.editor.range');
|
||||
goog.require('goog.functions');
|
||||
goog.require('goog.ui.editor.AbstractDialog');
|
||||
|
||||
|
||||
// *** Public interface ***************************************************** //
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A plugin that opens the hello world dialog.
|
||||
* @constructor
|
||||
* @extends {goog.editor.plugins.AbstractDialogPlugin}
|
||||
*/
|
||||
goog.demos.editor.HelloWorldDialogPlugin = function() {
|
||||
goog.editor.plugins.AbstractDialogPlugin.call(this,
|
||||
goog.demos.editor.HelloWorldDialogPlugin.Command.HELLO_WORLD_DIALOG);
|
||||
};
|
||||
goog.inherits(goog.demos.editor.HelloWorldDialogPlugin,
|
||||
goog.editor.plugins.AbstractDialogPlugin);
|
||||
|
||||
|
||||
/**
|
||||
* Commands implemented by this plugin.
|
||||
* @enum {string}
|
||||
*/
|
||||
goog.demos.editor.HelloWorldDialogPlugin.Command = {
|
||||
HELLO_WORLD_DIALOG: 'helloWorldDialog'
|
||||
};
|
||||
|
||||
|
||||
/** @override */
|
||||
goog.demos.editor.HelloWorldDialogPlugin.prototype.getTrogClassId =
|
||||
goog.functions.constant('HelloWorldDialog');
|
||||
|
||||
|
||||
// *** Protected interface ************************************************** //
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of the dialog and registers for the relevant events.
|
||||
* @param {goog.dom.DomHelper} dialogDomHelper The dom helper to be used to
|
||||
* create the dialog.
|
||||
* @return {goog.demos.editor.HelloWorldDialog} The dialog.
|
||||
* @override
|
||||
* @protected
|
||||
*/
|
||||
goog.demos.editor.HelloWorldDialogPlugin.prototype.createDialog = function(
|
||||
dialogDomHelper) {
|
||||
var dialog = new goog.demos.editor.HelloWorldDialog(dialogDomHelper);
|
||||
dialog.addEventListener(goog.ui.editor.AbstractDialog.EventType.OK,
|
||||
this.handleOk_,
|
||||
false,
|
||||
this);
|
||||
return dialog;
|
||||
};
|
||||
|
||||
|
||||
// *** Private implementation *********************************************** //
|
||||
|
||||
|
||||
/**
|
||||
* Handles the OK event from the dialog by inserting the hello world message
|
||||
* into the field.
|
||||
* @param {goog.demos.editor.HelloWorldDialog.OkEvent} e OK event object.
|
||||
* @private
|
||||
*/
|
||||
goog.demos.editor.HelloWorldDialogPlugin.prototype.handleOk_ = function(e) {
|
||||
// First restore the selection so we can manipulate the field's content
|
||||
// according to what was selected.
|
||||
this.restoreOriginalSelection();
|
||||
|
||||
// Notify listeners that the field's contents are about to change.
|
||||
this.getFieldObject().dispatchBeforeChange();
|
||||
|
||||
// Now we can clear out what was previously selected (if anything).
|
||||
var range = this.getFieldObject().getRange();
|
||||
range.removeContents();
|
||||
// And replace it with a span containing our hello world message.
|
||||
var createdNode = this.getFieldDomHelper().createDom(goog.dom.TagName.SPAN,
|
||||
null,
|
||||
e.message);
|
||||
createdNode = range.insertNode(createdNode, false);
|
||||
// Place the cursor at the end of the new text node (false == to the right).
|
||||
goog.editor.range.placeCursorNextTo(createdNode, false);
|
||||
|
||||
// Notify listeners that the field's selection has changed.
|
||||
this.getFieldObject().dispatchSelectionChangeEvent();
|
||||
// Notify listeners that the field's contents have changed.
|
||||
this.getFieldObject().dispatchChange();
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,197 @@
|
||||
// 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 simple, sample component.
|
||||
*
|
||||
*/
|
||||
goog.provide('goog.demos.SampleComponent');
|
||||
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.dom.classes');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.events.KeyCodes');
|
||||
goog.require('goog.events.KeyHandler');
|
||||
goog.require('goog.ui.Component');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A simple box that changes colour when clicked. This class demonstrates the
|
||||
* goog.ui.Component API, and is keyboard accessible, as per
|
||||
* http://wiki/Main/ClosureKeyboardAccessible
|
||||
*
|
||||
* @param {string=} opt_label A label to display. Defaults to "Click Me" if none
|
||||
* provided.
|
||||
* @param {goog.dom.DomHelper=} opt_domHelper DOM helper to use.
|
||||
*
|
||||
* @extends {goog.ui.Component}
|
||||
* @constructor
|
||||
*/
|
||||
goog.demos.SampleComponent = function(opt_label, opt_domHelper) {
|
||||
goog.base(this, opt_domHelper);
|
||||
|
||||
/**
|
||||
* The label to display.
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
this.initialLabel_ = opt_label || 'Click Me';
|
||||
|
||||
/**
|
||||
* The current color.
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
this.color_ = 'red';
|
||||
|
||||
/**
|
||||
* Keyboard handler for this object. This object is created once the
|
||||
* component's DOM element is known.
|
||||
*
|
||||
* @type {goog.events.KeyHandler?}
|
||||
* @private
|
||||
*/
|
||||
this.kh_ = null;
|
||||
};
|
||||
goog.inherits(goog.demos.SampleComponent, goog.ui.Component);
|
||||
|
||||
|
||||
/**
|
||||
* Changes the color of the element.
|
||||
* @private
|
||||
*/
|
||||
goog.demos.SampleComponent.prototype.changeColor_ = function() {
|
||||
if (this.color_ == 'red') {
|
||||
this.color_ = 'green';
|
||||
} else if (this.color_ == 'green') {
|
||||
this.color_ = 'blue';
|
||||
} else {
|
||||
this.color_ = 'red';
|
||||
}
|
||||
this.getElement().style.backgroundColor = this.color_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Creates an initial DOM representation for the component.
|
||||
* @override
|
||||
*/
|
||||
goog.demos.SampleComponent.prototype.createDom = function() {
|
||||
this.decorateInternal(this.dom_.createElement('div'));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decorates an existing HTML DIV element as a SampleComponent.
|
||||
*
|
||||
* @param {Element} element The DIV element to decorate. The element's
|
||||
* text, if any will be used as the component's label.
|
||||
* @override
|
||||
*/
|
||||
goog.demos.SampleComponent.prototype.decorateInternal = function(element) {
|
||||
goog.base(this, 'decorateInternal', element);
|
||||
if (!this.getLabelText()) {
|
||||
this.setLabelText(this.initialLabel_);
|
||||
}
|
||||
|
||||
var elem = this.getElement();
|
||||
goog.dom.classes.add(elem, goog.getCssName('goog-sample-component'));
|
||||
elem.style.backgroundColor = this.color_;
|
||||
elem.tabIndex = 0;
|
||||
|
||||
this.kh_ = new goog.events.KeyHandler(elem);
|
||||
this.getHandler().listen(this.kh_, goog.events.KeyHandler.EventType.KEY,
|
||||
this.onKey_);
|
||||
};
|
||||
|
||||
|
||||
/** @override */
|
||||
goog.demos.SampleComponent.prototype.disposeInternal = function() {
|
||||
goog.base(this, 'disposeInternal');
|
||||
if (this.kh_) {
|
||||
this.kh_.dispose();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Called when component's element is known to be in the document.
|
||||
* @override
|
||||
*/
|
||||
goog.demos.SampleComponent.prototype.enterDocument = function() {
|
||||
goog.base(this, 'enterDocument');
|
||||
this.getHandler().listen(this.getElement(), goog.events.EventType.CLICK,
|
||||
this.onDivClicked_);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Called when component's element is known to have been removed from the
|
||||
* document.
|
||||
* @override
|
||||
*/
|
||||
goog.demos.SampleComponent.prototype.exitDocument = function() {
|
||||
goog.base(this, 'exitDocument');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Gets the current label text.
|
||||
*
|
||||
* @return {string} The current text set into the label, or empty string if
|
||||
* none set.
|
||||
*/
|
||||
goog.demos.SampleComponent.prototype.getLabelText = function() {
|
||||
if (!this.getElement()) {
|
||||
return '';
|
||||
}
|
||||
return goog.dom.getTextContent(this.getElement());
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Handles DIV element clicks, causing the DIV's colour to change.
|
||||
* @param {goog.events.Event} event The click event.
|
||||
* @private
|
||||
*/
|
||||
goog.demos.SampleComponent.prototype.onDivClicked_ = function(event) {
|
||||
this.changeColor_();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Fired when user presses a key while the DIV has focus. If the user presses
|
||||
* space or enter, the color will be changed.
|
||||
* @param {goog.events.Event} event The key event.
|
||||
* @private
|
||||
*/
|
||||
goog.demos.SampleComponent.prototype.onKey_ = function(event) {
|
||||
var keyCodes = goog.events.KeyCodes;
|
||||
if (event.keyCode == keyCodes.SPACE || event.keyCode == keyCodes.ENTER) {
|
||||
this.changeColor_();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Sets the current label text. Has no effect if component is not rendered.
|
||||
*
|
||||
* @param {string} text The text to set as the label.
|
||||
*/
|
||||
goog.demos.SampleComponent.prototype.setLabelText = function(text) {
|
||||
if (this.getElement()) {
|
||||
goog.dom.setTextContent(this.getElement(), text);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,260 @@
|
||||
// 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.
|
||||
var testData =
|
||||
['Countries', [['A', [['Afghanistan'],
|
||||
['Albania'],
|
||||
['Algeria'],
|
||||
['American Samoa'],
|
||||
['Andorra'],
|
||||
['Angola'],
|
||||
['Anguilla'],
|
||||
['Antarctica'],
|
||||
['Antigua and Barbuda'],
|
||||
['Argentina'],
|
||||
['Armenia'],
|
||||
['Aruba'],
|
||||
['Australia'],
|
||||
['Austria'],
|
||||
['Azerbaijan']]],
|
||||
['B', [['Bahamas'],
|
||||
['Bahrain'],
|
||||
['Bangladesh'],
|
||||
['Barbados'],
|
||||
['Belarus'],
|
||||
['Belgium'],
|
||||
['Belize'],
|
||||
['Benin'],
|
||||
['Bermuda'],
|
||||
['Bhutan'],
|
||||
['Bolivia'],
|
||||
['Bosnia and Herzegovina'],
|
||||
['Botswana'],
|
||||
['Bouvet Island'],
|
||||
['Brazil'],
|
||||
['British Indian Ocean Territory'],
|
||||
['Brunei Darussalam'],
|
||||
['Bulgaria'],
|
||||
['Burkina Faso'],
|
||||
['Burundi']]],
|
||||
['C', [['Cambodia'],
|
||||
['Cameroon'],
|
||||
['Canada'],
|
||||
['Cape Verde'],
|
||||
['Cayman Islands'],
|
||||
['Central African Republic'],
|
||||
['Chad'],
|
||||
['Chile'],
|
||||
['China'],
|
||||
['Christmas Island'],
|
||||
['Cocos (Keeling) Islands'],
|
||||
['Colombia'],
|
||||
['Comoros'],
|
||||
['Congo'],
|
||||
['Congo, the Democratic Republic of the'],
|
||||
['Cook Islands'],
|
||||
['Costa Rica'],
|
||||
['Croatia'],
|
||||
['Cuba'],
|
||||
['Cyprus'],
|
||||
['Czech Republic'],
|
||||
['C\u00f4te d\u2019Ivoire']]],
|
||||
['D', [['Denmark'],
|
||||
['Djibouti'],
|
||||
['Dominica'],
|
||||
['Dominican Republic']]],
|
||||
['E', [['Ecuador'],
|
||||
['Egypt'],
|
||||
['El Salvador'],
|
||||
['Equatorial Guinea'],
|
||||
['Eritrea'],
|
||||
['Estonia'],
|
||||
['Ethiopia']]],
|
||||
['F', [['Falkland Islands (Malvinas)'],
|
||||
['Faroe Islands'],
|
||||
['Fiji'],
|
||||
['Finland'],
|
||||
['France'],
|
||||
['French Guiana'],
|
||||
['French Polynesia'],
|
||||
['French Southern Territories']]],
|
||||
['G', [['Gabon'],
|
||||
['Gambia'],
|
||||
['Georgia'],
|
||||
['Germany'],
|
||||
['Ghana'],
|
||||
['Gibraltar'],
|
||||
['Greece'],
|
||||
['Greenland'],
|
||||
['Grenada'],
|
||||
['Guadeloupe'],
|
||||
['Guam'],
|
||||
['Guatemala'],
|
||||
['Guernsey'],
|
||||
['Guinea'],
|
||||
['Guinea-Bissau'],
|
||||
['Guyana']]],
|
||||
['H', [['Haiti'],
|
||||
['Heard Island and McDonald Islands'],
|
||||
['Holy See (Vatican City State)'],
|
||||
['Honduras'],
|
||||
['Hong Kong'],
|
||||
['Hungary']]],
|
||||
['I', [['Iceland'],
|
||||
['India'],
|
||||
['Indonesia'],
|
||||
['Iran, Islamic Republic of'],
|
||||
['Iraq'],
|
||||
['Ireland'],
|
||||
['Isle of Man'],
|
||||
['Israel'],
|
||||
['Italy']]],
|
||||
['J', [['Jamaica'],
|
||||
['Japan'],
|
||||
['Jersey'],
|
||||
['Jordan']]],
|
||||
['K', [['Kazakhstan'],
|
||||
['Kenya'],
|
||||
['Kiribati'],
|
||||
['Korea, Democratic People\u2019s Republic of'],
|
||||
['Korea, Republic of'],
|
||||
['Kuwait'],
|
||||
['Kyrgyzstan']]],
|
||||
['L', [['Lao People\u2019s Democratic Republic'],
|
||||
['Latvia'],
|
||||
['Lebanon'],
|
||||
['Lesotho'],
|
||||
['Liberia'],
|
||||
['Libyan Arab Jamahiriya'],
|
||||
['Liechtenstein'],
|
||||
['Lithuania'],
|
||||
['Luxembourg']]],
|
||||
['M', [['Macao'],
|
||||
['Macedonia, the former Yugoslav Republic of'],
|
||||
['Madagascar'],
|
||||
['Malawi'],
|
||||
['Malaysia'],
|
||||
['Maldives'],
|
||||
['Mali'],
|
||||
['Malta'],
|
||||
['Marshall Islands'],
|
||||
['Martinique'],
|
||||
['Mauritania'],
|
||||
['Mauritius'],
|
||||
['Mayotte'],
|
||||
['Mexico'],
|
||||
['Micronesia, Federated States of'],
|
||||
['Moldova, Republic of'],
|
||||
['Monaco'],
|
||||
['Mongolia'],
|
||||
['Montenegro'],
|
||||
['Montserrat'],
|
||||
['Morocco'],
|
||||
['Mozambique'],
|
||||
['Myanmar']]],
|
||||
['N', [['Namibia'],
|
||||
['Nauru'],
|
||||
['Nepal'],
|
||||
['Netherlands'],
|
||||
['Netherlands Antilles'],
|
||||
['New Caledonia'],
|
||||
['New Zealand'],
|
||||
['Nicaragua'],
|
||||
['Niger'],
|
||||
['Nigeria'],
|
||||
['Niue'],
|
||||
['Norfolk Island'],
|
||||
['Northern Mariana Islands'],
|
||||
['Norway']]],
|
||||
['O', [['Oman']]],
|
||||
['P', [['Pakistan'],
|
||||
['Palau'],
|
||||
['Palestinian Territory, Occupied'],
|
||||
['Panama'],
|
||||
['Papua New Guinea'],
|
||||
['Paraguay'],
|
||||
['Peru'],
|
||||
['Philippines'],
|
||||
['Pitcairn'],
|
||||
['Poland'],
|
||||
['Portugal'],
|
||||
['Puerto Rico']]],
|
||||
['Q', [['Qatar']]],
|
||||
['R', [['Romania'],
|
||||
['Russian Federation'],
|
||||
['Rwanda'],
|
||||
['R\u00e9union']]],
|
||||
['S', [['Saint Barth\u00e9lemy'],
|
||||
['Saint Helena'],
|
||||
['Saint Kitts and Nevis'],
|
||||
['Saint Lucia'],
|
||||
['Saint Martin (French part)'],
|
||||
['Saint Pierre and Miquelon'],
|
||||
['Saint Vincent and the Grenadines'],
|
||||
['Samoa'],
|
||||
['San Marino'],
|
||||
['Sao Tome and Principe'],
|
||||
['Saudi Arabia'],
|
||||
['Senegal'],
|
||||
['Serbia'],
|
||||
['Seychelles'],
|
||||
['Sierra Leone'],
|
||||
['Singapore'],
|
||||
['Slovakia'],
|
||||
['Slovenia'],
|
||||
['Solomon Islands'],
|
||||
['Somalia'],
|
||||
['South Africa'],
|
||||
['South Georgia and the South Sandwich Islands'],
|
||||
['Spain'],
|
||||
['Sri Lanka'],
|
||||
['Sudan'],
|
||||
['Suriname'],
|
||||
['Svalbard and Jan Mayen'],
|
||||
['Swaziland'],
|
||||
['Sweden'],
|
||||
['Switzerland'],
|
||||
['Syrian Arab Republic']]],
|
||||
['T', [['Taiwan, Province of China'],
|
||||
['Tajikistan'],
|
||||
['Tanzania, United Republic of'],
|
||||
['Thailand'],
|
||||
['Timor-Leste'],
|
||||
['Togo'],
|
||||
['Tokelau'],
|
||||
['Tonga'],
|
||||
['Trinidad and Tobago'],
|
||||
['Tunisia'],
|
||||
['Turkey'],
|
||||
['Turkmenistan'],
|
||||
['Turks and Caicos Islands'],
|
||||
['Tuvalu']]],
|
||||
['U', [['Uganda'],
|
||||
['Ukraine'],
|
||||
['United Arab Emirates'],
|
||||
['United Kingdom'],
|
||||
['United States'],
|
||||
['United States Minor Outlying Islands'],
|
||||
['Uruguay'],
|
||||
['Uzbekistan']]],
|
||||
['V', [['Vanuatu'],
|
||||
['Venezuela'],
|
||||
['Viet Nam'],
|
||||
['Virgin Islands, British'],
|
||||
['Virgin Islands, U.S.']]],
|
||||
['W', [['Wallis and Futuna'],
|
||||
['Western Sahara']]],
|
||||
['Y', [['Yemen']]],
|
||||
['Z', [['Zambia'],
|
||||
['Zimbabwe']]],
|
||||
['\u00c5', [['\u00c5land Islands']]]]]
|
||||
@@ -0,0 +1,307 @@
|
||||
// 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 Contains application code for the XPC demo.
|
||||
* This script is used in both the container page and the iframe.
|
||||
*
|
||||
*/
|
||||
|
||||
goog.require('goog.Uri');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.json');
|
||||
goog.require('goog.log');
|
||||
goog.require('goog.net.xpc.CfgFields');
|
||||
goog.require('goog.net.xpc.CrossPageChannel');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Namespace for the demo. We don't use goog.provide here because it's not a
|
||||
* real module (cannot be required).
|
||||
*/
|
||||
var xpcdemo = {};
|
||||
|
||||
|
||||
/**
|
||||
* Global function to kick off initialization in the containing document.
|
||||
*/
|
||||
goog.global.initOuter = function() {
|
||||
goog.events.listen(window, 'load', function() { xpcdemo.initOuter(); });
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Global function to kick off initialization in the iframe.
|
||||
*/
|
||||
goog.global.initInner = function() {
|
||||
goog.events.listen(window, 'load', function() { xpcdemo.initInner(); });
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Initializes XPC in the containing page.
|
||||
*/
|
||||
xpcdemo.initOuter = function() {
|
||||
// Build the configuration object.
|
||||
var cfg = {};
|
||||
|
||||
var ownUri = new goog.Uri(window.location.href);
|
||||
var relayUri = ownUri.resolve(new goog.Uri('relay.html'));
|
||||
var pollUri = ownUri.resolve(new goog.Uri('blank.html'));
|
||||
|
||||
// Determine the peer domain. Uses the value of the URI-parameter
|
||||
// 'peerdomain'. If that parameter is not present, it falls back to
|
||||
// the own domain so that the demo will work out of the box (but
|
||||
// communication will of course not cross domain-boundaries). For
|
||||
// real cross-domain communication, the easiest way is to point two
|
||||
// different host-names to the same webserver and then hit the
|
||||
// following URI:
|
||||
// http://host1.com/path/to/closure/demos/xpc/index.html?peerdomain=host2.com
|
||||
var peerDomain = ownUri.getParameterValue('peerdomain') || ownUri.getDomain();
|
||||
|
||||
cfg[goog.net.xpc.CfgFields.LOCAL_RELAY_URI] = relayUri.toString();
|
||||
cfg[goog.net.xpc.CfgFields.PEER_RELAY_URI] =
|
||||
relayUri.setDomain(peerDomain).toString();
|
||||
|
||||
cfg[goog.net.xpc.CfgFields.LOCAL_POLL_URI] = pollUri.toString();
|
||||
cfg[goog.net.xpc.CfgFields.PEER_POLL_URI] =
|
||||
pollUri.setDomain(peerDomain).toString();
|
||||
|
||||
|
||||
// Force transport to be used if tp-parameter is set.
|
||||
var tp = ownUri.getParameterValue('tp');
|
||||
if (tp) {
|
||||
cfg[goog.net.xpc.CfgFields.TRANSPORT] = parseInt(tp, 10);
|
||||
}
|
||||
|
||||
|
||||
// Construct the URI of the peer page.
|
||||
|
||||
var peerUri = ownUri.resolve(
|
||||
new goog.Uri('inner.html')).setDomain(peerDomain);
|
||||
// Passthrough of verbose and compiled flags.
|
||||
if (goog.isDef(ownUri.getParameterValue('verbose'))) {
|
||||
peerUri.setParameterValue('verbose', '');
|
||||
}
|
||||
if (goog.isDef(ownUri.getParameterValue('compiled'))) {
|
||||
peerUri.setParameterValue('compiled', '');
|
||||
}
|
||||
|
||||
cfg[goog.net.xpc.CfgFields.PEER_URI] = peerUri;
|
||||
|
||||
// Instantiate the channel.
|
||||
xpcdemo.channel = new goog.net.xpc.CrossPageChannel(cfg);
|
||||
|
||||
// Create the peer iframe.
|
||||
xpcdemo.peerIframe = xpcdemo.channel.createPeerIframe(
|
||||
goog.dom.getElement('iframeContainer'));
|
||||
|
||||
xpcdemo.initCommon_();
|
||||
|
||||
goog.dom.getElement('inactive').style.display = 'none';
|
||||
goog.dom.getElement('active').style.display = '';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Initialization in the iframe.
|
||||
*/
|
||||
xpcdemo.initInner = function() {
|
||||
// Get the channel configuration passed by the containing document.
|
||||
var cfg = goog.json.parse(
|
||||
(new goog.Uri(window.location.href)).getParameterValue('xpc'));
|
||||
|
||||
xpcdemo.channel = new goog.net.xpc.CrossPageChannel(cfg);
|
||||
|
||||
xpcdemo.initCommon_();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the demo.
|
||||
* Registers service-handlers and connects the channel.
|
||||
* @private
|
||||
*/
|
||||
xpcdemo.initCommon_ = function() {
|
||||
var xpcLogger = goog.log.getLogger('goog.net.xpc');
|
||||
goog.log.addHandler(xpcLogger, function(logRecord) {
|
||||
xpcdemo.log('[XPC] ' + logRecord.getMessage());
|
||||
});
|
||||
xpcLogger.setLevel(window.location.href.match(/verbose/) ?
|
||||
goog.log.Level.ALL : goog.log.Level.INFO);
|
||||
|
||||
// Register services.
|
||||
xpcdemo.channel.registerService('log', xpcdemo.log);
|
||||
xpcdemo.channel.registerService('ping', xpcdemo.pingHandler_);
|
||||
xpcdemo.channel.registerService('events', xpcdemo.eventsMsgHandler_);
|
||||
|
||||
// Connect the channel.
|
||||
xpcdemo.channel.connect(function() {
|
||||
xpcdemo.channel.send('log', 'Hi from ' + window.location.host);
|
||||
goog.events.listen(goog.dom.getElement('clickfwd'),
|
||||
'click', xpcdemo.mouseEventHandler_);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Kills the peer iframe and the disposes the channel.
|
||||
*/
|
||||
xpcdemo.teardown = function() {
|
||||
goog.events.unlisten(goog.dom.getElement('clickfwd'),
|
||||
goog.events.EventType.CLICK, xpcdemo.mouseEventHandler_);
|
||||
|
||||
xpcdemo.channel.dispose();
|
||||
delete xpcdemo.channel;
|
||||
|
||||
goog.dom.removeNode(xpcdemo.peerIframe);
|
||||
xpcdemo.peerIframe = null;
|
||||
|
||||
goog.dom.getElement('inactive').style.display = '';
|
||||
goog.dom.getElement('active').style.display = 'none';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Logging function. Inserts log-message into element with it id 'console'.
|
||||
* @param {string} msgString The log-message.
|
||||
*/
|
||||
xpcdemo.log = function(msgString) {
|
||||
xpcdemo.consoleElm || (xpcdemo.consoleElm = goog.dom.getElement('console'));
|
||||
var msgElm = goog.dom.createDom('div');
|
||||
msgElm.innerHTML = msgString;
|
||||
xpcdemo.consoleElm.insertBefore(msgElm, xpcdemo.consoleElm.firstChild);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Sends a ping request to the peer.
|
||||
*/
|
||||
xpcdemo.ping = function() {
|
||||
// send current time
|
||||
xpcdemo.channel.send('ping', goog.now() + '');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The handler function for incoming pings (messages sent to the service
|
||||
* called 'ping');
|
||||
* @param {string} payload The message payload.
|
||||
* @private
|
||||
*/
|
||||
xpcdemo.pingHandler_ = function(payload) {
|
||||
// is the incoming message a response to a ping we sent?
|
||||
if (payload.charAt(0) == '#') {
|
||||
// calculate roundtrip time and log
|
||||
var dt = goog.now() - parseInt(payload.substring(1), 10);
|
||||
xpcdemo.log('roundtrip: ' + dt + 'ms');
|
||||
} else {
|
||||
// incoming message is a ping initiated from peer
|
||||
// -> prepend with '#' and send back
|
||||
xpcdemo.channel.send('ping', '#' + payload);
|
||||
xpcdemo.log('ping reply sent');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Counter for mousemove events.
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
xpcdemo.mmCount_ = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Holds timestamp when the last mousemove rate has been logged.
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
xpcdemo.mmLastRateOutput_ = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Start mousemove event forwarding. Registers a listener on the document which
|
||||
* sends them over the channel.
|
||||
*/
|
||||
xpcdemo.startMousemoveForwarding = function() {
|
||||
goog.events.listen(document, goog.events.EventType.MOUSEMOVE,
|
||||
xpcdemo.mouseEventHandler_);
|
||||
xpcdemo.mmLastRateOutput_ = goog.now();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Stop mousemove event forwarding.
|
||||
*/
|
||||
xpcdemo.stopMousemoveForwarding = function() {
|
||||
goog.events.unlisten(document, goog.events.EventType.MOUSEMOVE,
|
||||
xpcdemo.mouseEventHandler_);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Function to be used as handler for mouse-events.
|
||||
* @param {goog.events.BrowserEvent} e The mouse event.
|
||||
* @private
|
||||
*/
|
||||
xpcdemo.mouseEventHandler_ = function(e) {
|
||||
xpcdemo.channel.send('events',
|
||||
[e.type, e.clientX, e.clientY, goog.now()].join(','));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Handler for the 'events' service.
|
||||
* @param {string} payload The string returned from the xpcdemo.
|
||||
* @private
|
||||
*/
|
||||
xpcdemo.eventsMsgHandler_ = function(payload) {
|
||||
var now = goog.now();
|
||||
var args = payload.split(',');
|
||||
var type = args[0];
|
||||
var pageX = args[1];
|
||||
var pageY = args[2];
|
||||
var time = parseInt(args[3], 10);
|
||||
|
||||
var msg = type + ': (' + pageX + ',' + pageY + '), latency: ' + (now - time);
|
||||
xpcdemo.log(msg);
|
||||
|
||||
if (type == goog.events.EventType.MOUSEMOVE) {
|
||||
xpcdemo.mmCount_++;
|
||||
var dt = now - xpcdemo.mmLastRateOutput_;
|
||||
if (dt > 1000) {
|
||||
msg = 'RATE (mousemove/s): ' + (1000 * xpcdemo.mmCount_ / dt);
|
||||
xpcdemo.log(msg);
|
||||
xpcdemo.mmLastRateOutput_ = now;
|
||||
xpcdemo.mmCount_ = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Send multiple messages.
|
||||
* @param {number} n The number of messages to send.
|
||||
*/
|
||||
xpcdemo.sendN = function(n) {
|
||||
xpcdemo.count_ || (xpcdemo.count_ = 1);
|
||||
|
||||
for (var i = 0; i < n; i++) {
|
||||
xpcdemo.channel.send('log', '' + xpcdemo.count_++);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user