Adding mapbox-gl branch

This commit is contained in:
Andreas Hocevar
2015-03-16 18:50:27 +01:00
parent 7985f030fa
commit 57ee7f52fd
3109 changed files with 943365 additions and 0 deletions
@@ -0,0 +1,55 @@
// 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 The event object dispatched when the history changes.
*
*/
goog.provide('goog.history.Event');
goog.require('goog.events.Event');
goog.require('goog.history.EventType');
/**
* Event object dispatched after the history state has changed.
* @param {string} token The string identifying the new history state.
* @param {boolean} isNavigation True if the event was triggered by a browser
* action, such as forward or back, clicking on a link, editing the URL, or
* calling {@code window.history.(go|back|forward)}.
* False if the token has been changed by a {@code setToken} or
* {@code replaceToken} call.
* @constructor
* @extends {goog.events.Event}
* @final
*/
goog.history.Event = function(token, isNavigation) {
goog.events.Event.call(this, goog.history.EventType.NAVIGATE);
/**
* The current history state.
* @type {string}
*/
this.token = token;
/**
* Whether the event was triggered by browser navigation.
* @type {boolean}
*/
this.isNavigation = isNavigation;
};
goog.inherits(goog.history.Event, goog.events.Event);
@@ -0,0 +1,30 @@
// 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 Event types for goog.history.
*
*/
goog.provide('goog.history.EventType');
/**
* Event types for goog.history.
* @enum {string}
*/
goog.history.EventType = {
NAVIGATE: 'navigate'
};
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<!--
Copyright 2013 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.history</title>
<script src="../base.js"></script>
<script>
goog.require('goog.HistoryTest');
</script>
</head>
<body>
<input id="hidden-input" type="hidden">
<iframe id="hidden-iframe" style="display:none">
</body>
</html>
@@ -0,0 +1,55 @@
// Copyright 2013 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 Unit tests for goog.history.History.
*/
/** @suppress {extraProvide} */
goog.provide('goog.HistoryTest');
goog.require('goog.History');
goog.require('goog.dispose');
goog.require('goog.dom');
goog.require('goog.testing.jsunit');
goog.require('goog.userAgent');
goog.setTestOnly('goog.HistoryTest');
// Mimimal function to exercise construction.
function testCreation() {
var input = goog.dom.getElement('hidden-input');
var iframe = goog.dom.getElement('hidden-iframe');
try {
var history = new goog.History(undefined, undefined, input, iframe);
} finally {
goog.dispose(history);
}
}
function testIsHashChangeSupported() {
// This is the policy currently implemented.
var supportsOnHashChange = (goog.userAgent.IE ?
document.documentMode >= 8 :
'onhashchange' in window);
assertEquals(
supportsOnHashChange,
goog.History.isOnHashChangeSupported());
}
// TODO(nnaze): Test additional behavior.
@@ -0,0 +1,303 @@
// 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 HTML5 based history implementation, compatible with
* goog.History.
*
* TODO(user): There should really be a history interface and multiple
* implementations.
*
*/
goog.provide('goog.history.Html5History');
goog.provide('goog.history.Html5History.TokenTransformer');
goog.require('goog.asserts');
goog.require('goog.events');
goog.require('goog.events.EventTarget');
goog.require('goog.events.EventType');
goog.require('goog.history.Event');
/**
* An implementation compatible with goog.History that uses the HTML5
* history APIs.
*
* @param {Window=} opt_win The window to listen/dispatch history events on.
* @param {goog.history.Html5History.TokenTransformer=} opt_transformer
* The token transformer that is used to create URL from the token
* when storing token without using hash fragment.
* @constructor
* @extends {goog.events.EventTarget}
* @final
*/
goog.history.Html5History = function(opt_win, opt_transformer) {
goog.events.EventTarget.call(this);
goog.asserts.assert(goog.history.Html5History.isSupported(opt_win),
'HTML5 history is not supported.');
/**
* The window object to use for history tokens. Typically the top window.
* @type {Window}
* @private
*/
this.window_ = opt_win || window;
/**
* The token transformer that is used to create URL from the token
* when storing token without using hash fragment.
* @type {goog.history.Html5History.TokenTransformer}
* @private
*/
this.transformer_ = opt_transformer || null;
goog.events.listen(this.window_, goog.events.EventType.POPSTATE,
this.onHistoryEvent_, false, this);
goog.events.listen(this.window_, goog.events.EventType.HASHCHANGE,
this.onHistoryEvent_, false, this);
};
goog.inherits(goog.history.Html5History, goog.events.EventTarget);
/**
* Returns whether Html5History is supported.
* @param {Window=} opt_win Optional window to check.
* @return {boolean} Whether html5 history is supported.
*/
goog.history.Html5History.isSupported = function(opt_win) {
var win = opt_win || window;
return !!(win.history && win.history.pushState);
};
/**
* Status of when the object is active and dispatching events.
* @type {boolean}
* @private
*/
goog.history.Html5History.prototype.enabled_ = false;
/**
* Whether to use the fragment to store the token, defaults to true.
* @type {boolean}
* @private
*/
goog.history.Html5History.prototype.useFragment_ = true;
/**
* If useFragment is false the path will be used, the path prefix will be
* prepended to all tokens. Defaults to '/'.
* @type {string}
* @private
*/
goog.history.Html5History.prototype.pathPrefix_ = '/';
/**
* Starts or stops the History. When enabled, the History object
* will immediately fire an event for the current location. The caller can set
* up event listeners between the call to the constructor and the call to
* setEnabled.
*
* @param {boolean} enable Whether to enable history.
*/
goog.history.Html5History.prototype.setEnabled = function(enable) {
if (enable == this.enabled_) {
return;
}
this.enabled_ = enable;
if (enable) {
this.dispatchEvent(new goog.history.Event(this.getToken(), false));
}
};
/**
* Returns the current token.
* @return {string} The current token.
*/
goog.history.Html5History.prototype.getToken = function() {
if (this.useFragment_) {
var loc = this.window_.location.href;
var index = loc.indexOf('#');
return index < 0 ? '' : loc.substring(index + 1);
} else {
return this.transformer_ ?
this.transformer_.retrieveToken(
this.pathPrefix_, this.window_.location) :
this.window_.location.pathname.substr(this.pathPrefix_.length);
}
};
/**
* Sets the history state.
* @param {string} token The history state identifier.
* @param {string=} opt_title Optional title to associate with history entry.
*/
goog.history.Html5History.prototype.setToken = function(token, opt_title) {
if (token == this.getToken()) {
return;
}
// Per externs/gecko_dom.js document.title can be null.
this.window_.history.pushState(null,
opt_title || this.window_.document.title || '', this.getUrl_(token));
this.dispatchEvent(new goog.history.Event(token, false));
};
/**
* Replaces the current history state without affecting the rest of the history
* stack.
* @param {string} token The history state identifier.
* @param {string=} opt_title Optional title to associate with history entry.
*/
goog.history.Html5History.prototype.replaceToken = function(token, opt_title) {
// Per externs/gecko_dom.js document.title can be null.
this.window_.history.replaceState(null,
opt_title || this.window_.document.title || '', this.getUrl_(token));
this.dispatchEvent(new goog.history.Event(token, false));
};
/** @override */
goog.history.Html5History.prototype.disposeInternal = function() {
goog.events.unlisten(this.window_, goog.events.EventType.POPSTATE,
this.onHistoryEvent_, false, this);
if (this.useFragment_) {
goog.events.unlisten(this.window_, goog.events.EventType.HASHCHANGE,
this.onHistoryEvent_, false, this);
}
};
/**
* Sets whether to use the fragment to store tokens.
* @param {boolean} useFragment Whether to use the fragment.
*/
goog.history.Html5History.prototype.setUseFragment = function(useFragment) {
if (this.useFragment_ != useFragment) {
if (useFragment) {
goog.events.listen(this.window_, goog.events.EventType.HASHCHANGE,
this.onHistoryEvent_, false, this);
} else {
goog.events.unlisten(this.window_, goog.events.EventType.HASHCHANGE,
this.onHistoryEvent_, false, this);
}
this.useFragment_ = useFragment;
}
};
/**
* Sets the path prefix to use if storing tokens in the path. The path
* prefix should start and end with slash.
* @param {string} pathPrefix Sets the path prefix.
*/
goog.history.Html5History.prototype.setPathPrefix = function(pathPrefix) {
this.pathPrefix_ = pathPrefix;
};
/**
* Gets the path prefix.
* @return {string} The path prefix.
*/
goog.history.Html5History.prototype.getPathPrefix = function() {
return this.pathPrefix_;
};
/**
* Gets the URL to set when calling history.pushState
* @param {string} token The history token.
* @return {string} The URL.
* @private
*/
goog.history.Html5History.prototype.getUrl_ = function(token) {
if (this.useFragment_) {
return '#' + token;
} else {
return this.transformer_ ?
this.transformer_.createUrl(
token, this.pathPrefix_, this.window_.location) :
this.pathPrefix_ + token + this.window_.location.search;
}
};
/**
* Handles history events dispatched by the browser.
* @param {goog.events.BrowserEvent} e The browser event object.
* @private
*/
goog.history.Html5History.prototype.onHistoryEvent_ = function(e) {
if (this.enabled_) {
this.dispatchEvent(new goog.history.Event(this.getToken(), true));
}
};
/**
* A token transformer that can create a URL from a history
* token. This is used by {@code goog.history.Html5History} to create
* URL when storing token without the hash fragment.
*
* Given a {@code window.location} object containing the location
* created by {@code createUrl}, the token transformer allows
* retrieval of the token back via {@code retrieveToken}.
*
* @interface
*/
goog.history.Html5History.TokenTransformer = function() {};
/**
* Retrieves a history token given the path prefix and
* {@code window.location} object.
*
* @param {string} pathPrefix The path prefix to use when storing token
* in a path; always begin with a slash.
* @param {Location} location The {@code window.location} object.
* Treat this object as read-only.
* @return {string} token The history token.
*/
goog.history.Html5History.TokenTransformer.prototype.retrieveToken = function(
pathPrefix, location) {};
/**
* Creates a URL to be pushed into HTML5 history stack when storing
* token without using hash fragment.
*
* @param {string} token The history token.
* @param {string} pathPrefix The path prefix to use when storing token
* in a path; always begin with a slash.
* @param {Location} location The {@code window.location} object.
* Treat this object as read-only.
* @return {string} url The complete URL string from path onwards
* (without {@code protocol://host:port} part); must begin with a
* slash.
*/
goog.history.Html5History.TokenTransformer.prototype.createUrl = function(
token, pathPrefix, location) {};
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<!--
Copyright 2010 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.history.Html5History
</title>
<script src="../base.js">
</script>
<script>
goog.require('goog.history.Html5HistoryTest');
</script>
</head>
<body>
</body>
</html>
@@ -0,0 +1,159 @@
// 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.
goog.provide('goog.history.Html5HistoryTest');
goog.setTestOnly('goog.history.Html5HistoryTest');
goog.require('goog.history.Html5History');
goog.require('goog.testing.MockControl');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.mockmatchers');
var mockControl;
var mockWindow;
var html5History;
function setUp() {
mockControl = new goog.testing.MockControl();
mockWindow = {
location: {}
};
mockWindow.attachEvent = mockControl.createFunctionMock();
mockWindow.attachEvent(
goog.testing.mockmatchers.ignoreArgument,
goog.testing.mockmatchers.ignoreArgument).$anyTimes();
var mockHistoryIsSupportedMethod = mockControl.createMethodMock(
goog.history.Html5History, 'isSupported');
mockHistoryIsSupportedMethod(mockWindow).$returns(true).$anyTimes();
}
function tearDown() {
if (html5History) {
html5History.dispose();
html5History = null;
}
mockControl.$tearDown();
}
function testGetTokenWithoutUsingFragment() {
mockWindow.location.pathname = '/test/something';
mockControl.$replayAll();
html5History = new goog.history.Html5History(mockWindow);
html5History.setUseFragment(false);
assertEquals('test/something', html5History.getToken());
mockControl.$verifyAll();
}
function testGetTokenWithoutUsingFragmentWithCustomPathPrefix() {
mockWindow.location.pathname = '/test/something';
mockControl.$replayAll();
html5History = new goog.history.Html5History(mockWindow);
html5History.setUseFragment(false);
html5History.setPathPrefix('/test/');
assertEquals('something', html5History.getToken());
mockControl.$verifyAll();
}
function testGetTokenWithoutUsingFragmentWithCustomTransformer() {
mockWindow.location.pathname = '/test/something';
var mockTransformer = mockControl.createLooseMock(
goog.history.Html5History.TokenTransformer);
mockTransformer.retrieveToken('/', mockWindow.location).$returns('abc/1');
mockControl.$replayAll();
html5History = new goog.history.Html5History(mockWindow, mockTransformer);
html5History.setUseFragment(false);
assertEquals('abc/1', html5History.getToken());
mockControl.$verifyAll();
}
function testGetTokenWithoutUsingFragmentWithCustomTransformerAndPrefix() {
mockWindow.location.pathname = '/test/something';
var mockTransformer = mockControl.createLooseMock(
goog.history.Html5History.TokenTransformer);
mockTransformer.retrieveToken('/test/', mockWindow.location).
$returns('abc/1');
mockControl.$replayAll();
html5History = new goog.history.Html5History(mockWindow, mockTransformer);
html5History.setUseFragment(false);
html5History.setPathPrefix('/test/');
assertEquals('abc/1', html5History.getToken());
mockControl.$verifyAll();
}
function testGetUrlWithoutUsingFragment() {
mockWindow.location.search = '?q=something';
mockControl.$replayAll();
html5History = new goog.history.Html5History(mockWindow);
html5History.setUseFragment(false);
assertEquals('/some/token?q=something', html5History.getUrl_('some/token'));
mockControl.$verifyAll();
}
function testGetUrlWithoutUsingFragmentWithCustomPathPrefix() {
mockWindow.location.search = '?q=something';
mockControl.$replayAll();
html5History = new goog.history.Html5History(mockWindow);
html5History.setUseFragment(false);
html5History.setPathPrefix('/test/');
assertEquals('/test/some/token?q=something',
html5History.getUrl_('some/token'));
mockControl.$verifyAll();
}
function testGetUrlWithoutUsingFragmentWithCustomTransformer() {
mockWindow.location.search = '?q=something';
var mockTransformer = mockControl.createLooseMock(
goog.history.Html5History.TokenTransformer);
mockTransformer.createUrl('some/token', '/', mockWindow.location).
$returns('/something/else/?different');
mockControl.$replayAll();
html5History = new goog.history.Html5History(mockWindow, mockTransformer);
html5History.setUseFragment(false);
assertEquals('/something/else/?different',
html5History.getUrl_('some/token'));
mockControl.$verifyAll();
}
function testGetUrlWithoutUsingFragmentWithCustomTransformerAndPrefix() {
mockWindow.location.search = '?q=something';
var mockTransformer = mockControl.createLooseMock(
goog.history.Html5History.TokenTransformer);
mockTransformer.createUrl('some/token', '/test/', mockWindow.location).
$returns('/something/else/?different');
mockControl.$replayAll();
html5History = new goog.history.Html5History(mockWindow, mockTransformer);
html5History.setUseFragment(false);
html5History.setPathPrefix('/test/');
assertEquals('/something/else/?different',
html5History.getUrl_('some/token'));
mockControl.$verifyAll();
}