Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2330)

Unified Diff: server/static/bower_components/html5-history-anchor/src/html5-history-anchor.js

Issue 1695893004: RPC Explorer (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@rpcepxlorer-deps
Patch Set: 80 chars Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: server/static/bower_components/html5-history-anchor/src/html5-history-anchor.js
diff --git a/server/static/bower_components/html5-history-anchor/src/html5-history-anchor.js b/server/static/bower_components/html5-history-anchor/src/html5-history-anchor.js
new file mode 100644
index 0000000000000000000000000000000000000000..d8194263cba59eef02634cc6978a7c09b6bf0b8b
--- /dev/null
+++ b/server/static/bower_components/html5-history-anchor/src/html5-history-anchor.js
@@ -0,0 +1,96 @@
+(function() {
+ // Extend the <a> tag with the window.history API
+ // http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#the-history-interface
+ //
+ // <a is="html5-history-anchor"
+ // [href="/path"]
+ // [pushstate]
+ // [replacestate]
+ // [back]
+ // [forward]
+ // [go[="0"]]
+ // [title="New Page Title"]
+ // [state="{'message':'New State!'}"]
+ // [popstate]>
+ // title</a>
+
+ var HTML5HistoryAnchorElement = Object.create(HTMLAnchorElement.prototype);
+
+ function historyAnchorEventListener(event) {
+ // open in new tab
+ if (event.ctrlKey || event.metaKey || event.which === 2) {
+ return;
+ }
+
+ // pushstate
+ if (this.hasAttribute('pushstate')) {
+ window.history.pushState(JSON.parse(this.getAttribute('state')), this.getAttribute('title'), this.getAttribute('href'));
+ event.preventDefault();
+ }
+
+ // replacestate
+ if (this.hasAttribute('replacestate')) {
+ window.history.replaceState(JSON.parse(this.getAttribute('state')), this.getAttribute('title'), this.getAttribute('href'));
+ event.preventDefault();
+ }
+
+ // popstate
+ if (this.hasAttribute('popstate')) {
+ try {
+ var popstateEvent = new PopStateEvent('popstate', {
+ bubbles: false,
+ cancelable: false,
+ state: window.history.state
+ });
+
+ if ('dispatchEvent_' in window) {
+ // FireFox with polyfill
+ window.dispatchEvent_(popstateEvent);
+ } else {
+ // normal
+ window.dispatchEvent(popstateEvent);
+ }
+ } catch(error) {
+ // Internet Explorer
+ var fallbackEvent = document.createEvent('CustomEvent');
+ fallbackEvent.initCustomEvent('popstate', false, false, { state: window.history.state });
+ window.dispatchEvent(fallbackEvent);
+ }
+
+ event.preventDefault();
+ }
+
+ // go
+ if (this.hasAttribute('go')) {
+ var num = this.getAttribute('go');
+ if (num) {
+ num = parseInt(num);
+ } else {
+ num = 0;
+ }
+ window.history.go(num);
+ event.preventDefault();
+ }
+
+ // back
+ if (this.hasAttribute('back')) {
+ window.history.back();
+ event.preventDefault();
+ }
+
+ // forward
+ if (this.hasAttribute('forward')) {
+ window.history.forward();
+ event.preventDefault();
+ }
+ }
+
+ HTML5HistoryAnchorElement.createdCallback = function() {
+ this.addEventListener('click', historyAnchorEventListener, false);
+ };
+
+ document.registerElement('html5-history-anchor', {
+ prototype: HTML5HistoryAnchorElement,
+ extends: 'a'
+ });
+})();
« no previous file with comments | « server/static/bower_components/html5-history-anchor/src/html5-history-anchor.html ('k') | server/static/rpc/rpc-call.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698