From a6cb23b02a1c184176313c2f662bc30078e8b9c3 Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Fri, 1 Mar 2013 10:30:56 +0000 Subject: [PATCH] Handle History back step in browser #PL-1897 --- .../toolkit/gwt/client/utils/VScriptHost.java | 57 ++++++++++++++++++- .../gwt/client/ApplicationConfiguration.java | 16 +++++- .../src/com/haulmont/cuba/web/AppWindow.java | 10 +++- .../src/com/haulmont/cuba/web/WebConfig.java | 7 +++ .../cuba/web/sys/CubaApplicationServlet.java | 40 ++++++++++--- .../cuba/web/toolkit/ui/JavaScriptHost.java | 28 ++++++++- .../web/VAADIN/resources/js/jquery.history.js | 1 + modules/web/web/VAADIN/resources/js/json2.js | 1 + 8 files changed, 143 insertions(+), 17 deletions(-) create mode 100644 modules/web/web/VAADIN/resources/js/jquery.history.js create mode 100644 modules/web/web/VAADIN/resources/js/json2.js diff --git a/modules/web-toolkit/src/com/haulmont/cuba/toolkit/gwt/client/utils/VScriptHost.java b/modules/web-toolkit/src/com/haulmont/cuba/toolkit/gwt/client/utils/VScriptHost.java index d8fcfba55b..a717b984a2 100644 --- a/modules/web-toolkit/src/com/haulmont/cuba/toolkit/gwt/client/utils/VScriptHost.java +++ b/modules/web-toolkit/src/com/haulmont/cuba/toolkit/gwt/client/utils/VScriptHost.java @@ -15,9 +15,9 @@ import com.vaadin.terminal.gwt.client.ValueMap; /** * Component for evaluate custom JavaScript from server - *

$Id$

* * @author artamonov + * @version $Id$ */ public class VScriptHost extends SimplePanel implements Paintable { public static final String COMMAND_PARAM_KEY = "command"; @@ -34,13 +34,28 @@ public class VScriptHost extends SimplePanel implements Paintable { public static final String URL_PARAM_KEY = "url"; public static final String LOCALE_PARAM_KEY = "messages"; + public static final String HISTORY_BACK_ACTION = "historyBackAction"; + + private boolean historyHandlerInitialized = false; + + private ApplicationConnection client; + private String paintableId; + public VScriptHost() { getElement().getStyle().setDisplay(Style.Display.NONE); getElement().getStyle().setVisibility(Style.Visibility.HIDDEN); } + @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - String paintableId = uidl.getId(); + this.client = client; + this.paintableId = uidl.getId(); + + if (client.getConfiguration().isHandleHistoryBack() && !historyHandlerInitialized) { + initHistoryHandler(); + + historyHandlerInitialized = true; + } this.getElement().setId("scriptHost_" + paintableId); @@ -66,6 +81,12 @@ public class VScriptHost extends SimplePanel implements Paintable { } } + public void handleHistoryBackAction() { + if (historyHandlerInitialized) { + client.updateVariable(paintableId, HISTORY_BACK_ACTION, "performed", true); + } + } + private native void evaluateScript(String script)/*-{ eval(script); }-*/; @@ -80,4 +101,34 @@ public class VScriptHost extends SimplePanel implements Paintable { }; setTimeout(timedAction, 50); }-*/; -} + + private native void initHistoryHandler() + /*-{ + var vScriptHost = this; + (function(window){ + var History = window.History; + + var location = window.location.href; + + var defaultState = 0; + + if (location.indexOf('?wv') >= 0) { + History.pushState({state: 1, rand: 1}, window.document.title, '?vw'); + defaultState = 1; + } else { + History.pushState({state: 2, rand: 2}, window.document.title, '?wv'); + defaultState = 2; + } + + History.Adapter.bind(window, 'statechange', function () { + var State = History.getState(); + + if (!State.data || State.data.state != defaultState) { + History.go(1); + + vScriptHost.@com.haulmont.cuba.toolkit.gwt.client.utils.VScriptHost::handleHistoryBackAction()(); + } + }); + })($wnd); + }-*/; +} \ No newline at end of file diff --git a/modules/web-toolkit/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java b/modules/web-toolkit/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java index 90224a1f18..4a2944b70d 100644 --- a/modules/web-toolkit/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java +++ b/modules/web-toolkit/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java @@ -63,6 +63,8 @@ public class ApplicationConfiguration implements EntryPoint { private String blockUiMessage = "Please wait"; private boolean useUiBlocking = false; + private boolean handleHistoryBack = false; + private String requiredWidgetset; private boolean useDebugIdInDom = true; private boolean usePortletURLs = false; @@ -123,7 +125,7 @@ public class ApplicationConfiguration implements EntryPoint { */ public void updateSystemMessages(ValueMap localeMessages) { if (!localeMessages.getKeySet().isEmpty()) { - // Update all system messages + // Update all system messages handleHistoryBack communicationErrorCaption = localeMessages.getString("communicationErrorCaption"); communicationErrorMessage = localeMessages.getString("communicationErrorMessage"); @@ -190,6 +192,14 @@ public class ApplicationConfiguration implements EntryPoint { return useUiBlocking; } + public boolean isHandleHistoryBack() { + return handleHistoryBack; + } + + public void setHandleHistoryBack(boolean handleHistoryBack) { + this.handleHistoryBack = handleHistoryBack; + } + private native void loadFromDOM() /*-{ @@ -203,6 +213,7 @@ public class ApplicationConfiguration implements EntryPoint { this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::appUri = uri; this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::themeUri = jsobj.themeUri; this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::sessionId = jsobj.sessionId; + if(jsobj.windowName) { this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::windowName = jsobj.windowName; } @@ -226,6 +237,9 @@ public class ApplicationConfiguration implements EntryPoint { this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::useUiBlocking = jsobj.uiBlocking.useUiBlocking; this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::blockUiMessage = jsobj.uiBlocking.blockUiMessage; } + if (jsobj.handleHistoryBack) { + this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::handleHistoryBack = jsobj.handleHistoryBack; + } if (jsobj.usePortletURLs) { this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::usePortletURLs = jsobj.usePortletURLs; } diff --git a/modules/web/src/com/haulmont/cuba/web/AppWindow.java b/modules/web/src/com/haulmont/cuba/web/AppWindow.java index 8620e87847..6a65090121 100644 --- a/modules/web/src/com/haulmont/cuba/web/AppWindow.java +++ b/modules/web/src/com/haulmont/cuba/web/AppWindow.java @@ -51,7 +51,7 @@ import java.util.*; * @version $Id$ */ @SuppressWarnings("unused") -public class AppWindow extends Window implements UserSubstitutionListener { +public class AppWindow extends Window implements UserSubstitutionListener, JavaScriptHost.HistoryBackHandler { private static final long serialVersionUID = 7269808125566032433L; @@ -165,9 +165,17 @@ public class AppWindow extends Window implements UserSubstitutionListener { private void initStaticComponents() { scriptHost = new JavaScriptHost(); + if (webConfig.getAllowHandleBrowserHistoryBack()) { + scriptHost.setHistoryBackHandler(this); + } addComponent(scriptHost); } + @Override + public void onHistoryBackPerformed() { + showNotification("Go back to the Future!", Notification.TYPE_HUMANIZED_MESSAGE); + } + /** * @return Current mode */ diff --git a/modules/web/src/com/haulmont/cuba/web/WebConfig.java b/modules/web/src/com/haulmont/cuba/web/WebConfig.java index 7d56b0b223..061c1e1a41 100644 --- a/modules/web/src/com/haulmont/cuba/web/WebConfig.java +++ b/modules/web/src/com/haulmont/cuba/web/WebConfig.java @@ -217,6 +217,13 @@ public interface WebConfig extends Config { @DefaultBoolean(true) boolean getUseUiBlocking(); + /** + * @return Whether to handle back button click in browser on server-side. + */ + @Property("cuba.web.getAllowHandleBrowserHistoryBack") + @DefaultBoolean(true) + boolean getAllowHandleBrowserHistoryBack(); + /** * @return Theme */ diff --git a/modules/web/src/com/haulmont/cuba/web/sys/CubaApplicationServlet.java b/modules/web/src/com/haulmont/cuba/web/sys/CubaApplicationServlet.java index a6660526ca..d7132ea4f9 100644 --- a/modules/web/src/com/haulmont/cuba/web/sys/CubaApplicationServlet.java +++ b/modules/web/src/com/haulmont/cuba/web/sys/CubaApplicationServlet.java @@ -2,16 +2,12 @@ * Copyright (c) 2008 Haulmont Technology Ltd. All Rights Reserved. * Haulmont Technology proprietary and confidential. * Use is subject to license terms. - - * Author: Nikolay Gorodnov - * Created: 27.08.2009 18:39:09 - * - * $Id$ */ package com.haulmont.cuba.web.sys; import com.haulmont.cuba.core.app.ServerInfoService; -import com.haulmont.cuba.core.global.ConfigProvider; +import com.haulmont.cuba.core.global.AppBeans; +import com.haulmont.cuba.core.global.Configuration; import com.haulmont.cuba.core.global.GlobalConfig; import com.haulmont.cuba.gui.ServiceLocator; import com.haulmont.cuba.web.App; @@ -25,6 +21,7 @@ import org.apache.commons.lang.BooleanUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; @@ -38,6 +35,10 @@ import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; +/** + * @author gorodnov + * @version $Id$ + */ public class CubaApplicationServlet extends ApplicationServlet { private static final long serialVersionUID = -8701539520754293569L; @@ -45,9 +46,13 @@ public class CubaApplicationServlet extends ApplicationServlet { private Log log = LogFactory.getLog(CubaApplicationServlet.class); + private WebConfig webConfig; + + private GlobalConfig globalConfig; + @Override protected boolean isTestingMode() { - return ConfigProvider.getConfig(GlobalConfig.class).getTestMode(); + return globalConfig.getTestMode(); } @Override @@ -55,6 +60,15 @@ public class CubaApplicationServlet extends ApplicationServlet { return CubaApplicationContext.getApplicationContext(session); } + @Override + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + + Configuration configuration = AppBeans.get(Configuration.class); + webConfig = configuration.getConfig(WebConfig.class); + globalConfig = configuration.getConfig(GlobalConfig.class); + } + @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String requestURI = request.getRequestURI(); @@ -249,7 +263,9 @@ public class CubaApplicationServlet extends ApplicationServlet { page.write("useDebugIdInDom: true,\n"); } - WebConfig webConfig = ConfigProvider.getConfig(WebConfig.class); + if (webConfig.getAllowHandleBrowserHistoryBack()) + page.write("handleHistoryBack: true,\n"); + page.write("\n\"uiBlocking\" : {"); page.write(" \"blockUiMessage\" : \"" + systemMessages.getUiBlockingMessage() + "\" ,"); page.write(" \"useUiBlocking\" : " + @@ -296,7 +312,7 @@ public class CubaApplicationServlet extends ApplicationServlet { protected void writeAjaxPageHtmlHeader(HttpServletRequest request, BufferedWriter page, String title, String themeUri) throws IOException { page.write("\n"); - if (ConfigProvider.getConfig(WebConfig.class).getUseChromeFramePlugin() + if (webConfig.getUseChromeFramePlugin() && Browser.getBrowserInfo(request).isChromeFrame()) { page.write("\n"); /* @@ -319,6 +335,12 @@ public class CubaApplicationServlet extends ApplicationServlet { writeScriptResource(request, page, "jquery-1.4.2.min.js", false); writeScriptResource(request, page, "jquery.blockUI.js", false); writeScriptResource(request, page, "scripts.js", true); + + // history control + if (webConfig.getAllowHandleBrowserHistoryBack()) { + writeScriptResource(request, page, "jquery.history.js", false); + writeScriptResource(request, page, "json2.js", false); + } } private void writeScriptResource(HttpServletRequest request, BufferedWriter page, String fileName, boolean nocache) throws IOException { diff --git a/modules/web/src/com/haulmont/cuba/web/toolkit/ui/JavaScriptHost.java b/modules/web/src/com/haulmont/cuba/web/toolkit/ui/JavaScriptHost.java index 638ccf947f..7c17c25e14 100644 --- a/modules/web/src/com/haulmont/cuba/web/toolkit/ui/JavaScriptHost.java +++ b/modules/web/src/com/haulmont/cuba/web/toolkit/ui/JavaScriptHost.java @@ -19,9 +19,9 @@ import java.util.Set; /** * Component for evaluate custom JavaScript from server - *

$Id$

* * @author artamonov + * @version $Id$ */ @ClientWidget(VScriptHost.class) public class JavaScriptHost extends AbstractComponent { @@ -29,12 +29,14 @@ public class JavaScriptHost extends AbstractComponent { private static class ScriptValueProvider implements ValueProvider { - Map params = new HashMap(); + Map params = new HashMap<>(); + @Override public Map getValues() { return params; } + @Override public Map getParameters() { return params; } @@ -54,7 +56,15 @@ public class JavaScriptHost extends AbstractComponent { private ScriptValueProvider valueProvider = new ScriptValueProvider(); - public JavaScriptHost() { + private HistoryBackHandler historyBackHandler = null; + + @Override + public void changeVariables(Object source, Map variables) { + super.changeVariables(source, variables); + + if (variables.containsKey(VScriptHost.HISTORY_BACK_ACTION) && historyBackHandler != null) { + historyBackHandler.onHistoryBackPerformed(); + } } @Override @@ -114,4 +124,16 @@ public class JavaScriptHost extends AbstractComponent { valueProvider.removeParam(VScriptHost.SCRIPT_PARAM_KEY); valueProvider.removeParam(VScriptHost.COMMAND_PARAM_KEY); } + + public HistoryBackHandler getHistoryBackHandler() { + return historyBackHandler; + } + + public void setHistoryBackHandler(HistoryBackHandler historyBackHandler) { + this.historyBackHandler = historyBackHandler; + } + + public interface HistoryBackHandler { + void onHistoryBackPerformed(); + } } \ No newline at end of file diff --git a/modules/web/web/VAADIN/resources/js/jquery.history.js b/modules/web/web/VAADIN/resources/js/jquery.history.js new file mode 100644 index 0000000000..8d4edcd210 --- /dev/null +++ b/modules/web/web/VAADIN/resources/js/jquery.history.js @@ -0,0 +1 @@ +window.JSON||(window.JSON={}),function(){function f(a){return a<10?"0"+a:a}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return typeof b=="string"?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g=gap,h,i=b[a];i&&typeof i=="object"&&typeof i.toJSON=="function"&&(i=i.toJSON(a)),typeof rep=="function"&&(i=rep.call(b,a,i));switch(typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";gap+=indent,h=[];if(Object.prototype.toString.apply(i)==="[object Array]"){f=i.length;for(c=0;c")&&c[0]);return a>4?a:!1}();return a},m.isInternetExplorer=function(){var a=m.isInternetExplorer.cached=typeof m.isInternetExplorer.cached!="undefined"?m.isInternetExplorer.cached:Boolean(m.getInternetExplorerMajorVersion());return a},m.emulated={pushState:!Boolean(a.history&&a.history.pushState&&a.history.replaceState&&!/ Mobile\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))/i.test(e.userAgent)&&!/AppleWebKit\/5([0-2]|3[0-2])/i.test(e.userAgent)),hashChange:Boolean(!("onhashchange"in a||"onhashchange"in d)||m.isInternetExplorer()&&m.getInternetExplorerMajorVersion()<8)},m.enabled=!m.emulated.pushState,m.bugs={setHash:Boolean(!m.emulated.pushState&&e.vendor==="Apple Computer, Inc."&&/AppleWebKit\/5([0-2]|3[0-3])/.test(e.userAgent)),safariPoll:Boolean(!m.emulated.pushState&&e.vendor==="Apple Computer, Inc."&&/AppleWebKit\/5([0-2]|3[0-3])/.test(e.userAgent)),ieDoubleCheck:Boolean(m.isInternetExplorer()&&m.getInternetExplorerMajorVersion()<8),hashEscape:Boolean(m.isInternetExplorer()&&m.getInternetExplorerMajorVersion()<7)},m.isEmptyObject=function(a){for(var b in a)return!1;return!0},m.cloneObject=function(a){var b,c;return a?(b=k.stringify(a),c=k.parse(b)):c={},c},m.getRootUrl=function(){var a=d.location.protocol+"//"+(d.location.hostname||d.location.host);if(d.location.port||!1)a+=":"+d.location.port;return a+="/",a},m.getBaseHref=function(){var a=d.getElementsByTagName("base"),b=null,c="";return a.length===1&&(b=a[0],c=b.href.replace(/[^\/]+$/,"")),c=c.replace(/\/+$/,""),c&&(c+="/"),c},m.getBaseUrl=function(){var a=m.getBaseHref()||m.getBasePageUrl()||m.getRootUrl();return a},m.getPageUrl=function(){var a=m.getState(!1,!1),b=(a||{}).url||d.location.href,c;return c=b.replace(/\/+$/,"").replace(/[^\/]+$/,function(a,b,c){return/\./.test(a)?a:a+"/"}),c},m.getBasePageUrl=function(){var a=d.location.href.replace(/[#\?].*/,"").replace(/[^\/]+$/,function(a,b,c){return/[^\/]$/.test(a)?"":a}).replace(/\/+$/,"")+"/";return a},m.getFullUrl=function(a,b){var c=a,d=a.substring(0,1);return b=typeof b=="undefined"?!0:b,/[a-z]+\:\/\//.test(a)||(d==="/"?c=m.getRootUrl()+a.replace(/^\/+/,""):d==="#"?c=m.getPageUrl().replace(/#.*/,"")+a:d==="?"?c=m.getPageUrl().replace(/[\?#].*/,"")+a:b?c=m.getBaseUrl()+a.replace(/^(\.\/)+/,""):c=m.getBasePageUrl()+a.replace(/^(\.\/)+/,"")),c.replace(/\#$/,"")},m.getShortUrl=function(a){var b=a,c=m.getBaseUrl(),d=m.getRootUrl();return m.emulated.pushState&&(b=b.replace(c,"")),b=b.replace(d,"/"),m.isTraditionalAnchor(b)&&(b="./"+b),b=b.replace(/^(\.\/)+/g,"./").replace(/\#$/,""),b},m.store={},m.idToState=m.idToState||{},m.stateToId=m.stateToId||{},m.urlToId=m.urlToId||{},m.storedStates=m.storedStates||[],m.savedStates=m.savedStates||[],m.normalizeStore=function(){m.store.idToState=m.store.idToState||{},m.store.urlToId=m.store.urlToId||{},m.store.stateToId=m.store.stateToId||{}},m.getState=function(a,b){typeof a=="undefined"&&(a=!0),typeof b=="undefined"&&(b=!0);var c=m.getLastSavedState();return!c&&b&&(c=m.createStateObject()),a&&(c=m.cloneObject(c),c.url=c.cleanUrl||c.url),c},m.getIdByState=function(a){var b=m.extractId(a.url),c;if(!b){c=m.getStateString(a);if(typeof m.stateToId[c]!="undefined")b=m.stateToId[c];else if(typeof m.store.stateToId[c]!="undefined")b=m.store.stateToId[c];else{for(;;){b=(new Date).getTime()+String(Math.random()).replace(/\D/g,"");if(typeof m.idToState[b]=="undefined"&&typeof m.store.idToState[b]=="undefined")break}m.stateToId[c]=b,m.idToState[b]=a}}return b},m.normalizeState=function(a){var b,c;if(!a||typeof a!="object")a={};if(typeof a.normalized!="undefined")return a;if(!a.data||typeof a.data!="object")a.data={};b={},b.normalized=!0,b.title=a.title||"",b.url=m.getFullUrl(m.unescapeString(a.url||d.location.href)),b.hash=m.getShortUrl(b.url),b.data=m.cloneObject(a.data),b.id=m.getIdByState(b),b.cleanUrl=b.url.replace(/\??\&_suid.*/,""),b.url=b.cleanUrl,c=!m.isEmptyObject(b.data);if(b.title||c)b.hash=m.getShortUrl(b.url).replace(/\??\&_suid.*/,""),/\?/.test(b.hash)||(b.hash+="?"),b.hash+="&_suid="+b.id;return b.hashedUrl=m.getFullUrl(b.hash),(m.emulated.pushState||m.bugs.safariPoll)&&m.hasUrlDuplicate(b)&&(b.url=b.hashedUrl),b},m.createStateObject=function(a,b,c){var d={data:a,title:b,url:c};return d=m.normalizeState(d),d},m.getStateById=function(a){a=String(a);var c=m.idToState[a]||m.store.idToState[a]||b;return c},m.getStateString=function(a){var b,c,d;return b=m.normalizeState(a),c={data:b.data,title:a.title,url:a.url},d=k.stringify(c),d},m.getStateId=function(a){var b,c;return b=m.normalizeState(a),c=b.id,c},m.getHashByState=function(a){var b,c;return b=m.normalizeState(a),c=b.hash,c},m.extractId=function(a){var b,c,d;return c=/(.*)\&_suid=([0-9]+)$/.exec(a),d=c?c[1]||a:a,b=c?String(c[2]||""):"",b||!1},m.isTraditionalAnchor=function(a){var b=!/[\/\?\.]/.test(a);return b},m.extractState=function(a,b){var c=null,d,e;return b=b||!1,d=m.extractId(a),d&&(c=m.getStateById(d)),c||(e=m.getFullUrl(a),d=m.getIdByUrl(e)||!1,d&&(c=m.getStateById(d)),!c&&b&&!m.isTraditionalAnchor(a)&&(c=m.createStateObject(null,null,e))),c},m.getIdByUrl=function(a){var c=m.urlToId[a]||m.store.urlToId[a]||b;return c},m.getLastSavedState=function(){return m.savedStates[m.savedStates.length-1]||b},m.getLastStoredState=function(){return m.storedStates[m.storedStates.length-1]||b},m.hasUrlDuplicate=function(a){var b=!1,c;return c=m.extractState(a.url),b=c&&c.id!==a.id,b},m.storeState=function(a){return m.urlToId[a.url]=a.id,m.storedStates.push(m.cloneObject(a)),a},m.isLastSavedState=function(a){var b=!1,c,d,e;return m.savedStates.length&&(c=a.id,d=m.getLastSavedState(),e=d.id,b=c===e),b},m.saveState=function(a){return m.isLastSavedState(a)?!1:(m.savedStates.push(m.cloneObject(a)),!0)},m.getStateByIndex=function(a){var b=null;return typeof a=="undefined"?b=m.savedStates[m.savedStates.length-1]:a<0?b=m.savedStates[m.savedStates.length+a]:b=m.savedStates[a],b},m.getHash=function(){var a=m.unescapeHash(d.location.hash);return a},m.unescapeString=function(b){var c=b,d;for(;;){d=a.unescape(c);if(d===c)break;c=d}return c},m.unescapeHash=function(a){var b=m.normalizeHash(a);return b=m.unescapeString(b),b},m.normalizeHash=function(a){var b=a.replace(/[^#]*#/,"").replace(/#.*/,"");return b},m.setHash=function(a,b){var c,e,f;return b!==!1&&m.busy()?(m.pushQueue({scope:m,callback:m.setHash,args:arguments,queue:b}),!1):(c=m.escapeHash(a),m.busy(!0),e=m.extractState(a,!0),e&&!m.emulated.pushState?m.pushState(e.data,e.title,e.url,!1):d.location.hash!==c&&(m.bugs.setHash?(f=m.getPageUrl(),m.pushState(null,null,f+"#"+c,!1)):d.location.hash=c),m)},m.escapeHash=function(b){var c=m.normalizeHash(b);return c=a.escape(c),m.bugs.hashEscape||(c=c.replace(/\%21/g,"!").replace(/\%26/g,"&").replace(/\%3D/g,"=").replace(/\%3F/g,"?")),c},m.getHashByUrl=function(a){var b=String(a).replace(/([^#]*)#?([^#]*)#?(.*)/,"$2");return b=m.unescapeHash(b),b},m.setTitle=function(a){var b=a.title,c;b||(c=m.getStateByIndex(0),c&&c.url===a.url&&(b=c.title||m.options.initialTitle));try{d.getElementsByTagName("title")[0].innerHTML=b.replace("<","<").replace(">",">").replace(" & "," & ")}catch(e){}return d.title=b,m},m.queues=[],m.busy=function(a){typeof a!="undefined"?m.busy.flag=a:typeof m.busy.flag=="undefined"&&(m.busy.flag=!1);if(!m.busy.flag){h(m.busy.timeout);var b=function(){var a,c,d;if(m.busy.flag)return;for(a=m.queues.length-1;a>=0;--a){c=m.queues[a];if(c.length===0)continue;d=c.shift(),m.fireQueueItem(d),m.busy.timeout=g(b,m.options.busyDelay)}};m.busy.timeout=g(b,m.options.busyDelay)}return m.busy.flag},m.busy.flag=!1,m.fireQueueItem=function(a){return a.callback.apply(a.scope||m,a.args||[])},m.pushQueue=function(a){return m.queues[a.queue||0]=m.queues[a.queue||0]||[],m.queues[a.queue||0].push(a),m},m.queue=function(a,b){return typeof a=="function"&&(a={callback:a}),typeof b!="undefined"&&(a.queue=b),m.busy()?m.pushQueue(a):m.fireQueueItem(a),m},m.clearQueue=function(){return m.busy.flag=!1,m.queues=[],m},m.stateChanged=!1,m.doubleChecker=!1,m.doubleCheckComplete=function(){return m.stateChanged=!0,m.doubleCheckClear(),m},m.doubleCheckClear=function(){return m.doubleChecker&&(h(m.doubleChecker),m.doubleChecker=!1),m},m.doubleCheck=function(a){return m.stateChanged=!1,m.doubleCheckClear(),m.bugs.ieDoubleCheck&&(m.doubleChecker=g(function(){return m.doubleCheckClear(),m.stateChanged||a(),!0},m.options.doubleCheckInterval)),m},m.safariStatePoll=function(){var b=m.extractState(d.location.href),c;if(!m.isLastSavedState(b))c=b;else return;return c||(c=m.createStateObject()),m.Adapter.trigger(a,"popstate"),m},m.back=function(a){return a!==!1&&m.busy()?(m.pushQueue({scope:m,callback:m.back,args:arguments,queue:a}),!1):(m.busy(!0),m.doubleCheck(function(){m.back(!1)}),n.go(-1),!0)},m.forward=function(a){return a!==!1&&m.busy()?(m.pushQueue({scope:m,callback:m.forward,args:arguments,queue:a}),!1):(m.busy(!0),m.doubleCheck(function(){m.forward(!1)}),n.go(1),!0)},m.go=function(a,b){var c;if(a>0)for(c=1;c<=a;++c)m.forward(b);else{if(!(a<0))throw new Error("History.go: History.go requires a positive or negative integer passed.");for(c=-1;c>=a;--c)m.back(b)}return m};if(m.emulated.pushState){var o=function(){};m.pushState=m.pushState||o,m.replaceState=m.replaceState||o}else m.onPopState=function(b,c){var e=!1,f=!1,g,h;return m.doubleCheckComplete(),g=m.getHash(),g?(h=m.extractState(g||d.location.href,!0),h?m.replaceState(h.data,h.title,h.url,!1):(m.Adapter.trigger(a,"anchorchange"),m.busy(!1)),m.expectedStateId=!1,!1):(e=m.Adapter.extractEventData("state",b,c)||!1,e?f=m.getStateById(e):m.expectedStateId?f=m.getStateById(m.expectedStateId):f=m.extractState(d.location.href),f||(f=m.createStateObject(null,null,d.location.href)),m.expectedStateId=!1,m.isLastSavedState(f)?(m.busy(!1),!1):(m.storeState(f),m.saveState(f),m.setTitle(f),m.Adapter.trigger(a,"statechange"),m.busy(!1),!0))},m.Adapter.bind(a,"popstate",m.onPopState),m.pushState=function(b,c,d,e){if(m.getHashByUrl(d)&&m.emulated.pushState)throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(e!==!1&&m.busy())return m.pushQueue({scope:m,callback:m.pushState,args:arguments,queue:e}),!1;m.busy(!0);var f=m.createStateObject(b,c,d);return m.isLastSavedState(f)?m.busy(!1):(m.storeState(f),m.expectedStateId=f.id,n.pushState(f.id,f.title,f.url),m.Adapter.trigger(a,"popstate")),!0},m.replaceState=function(b,c,d,e){if(m.getHashByUrl(d)&&m.emulated.pushState)throw new Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(e!==!1&&m.busy())return m.pushQueue({scope:m,callback:m.replaceState,args:arguments,queue:e}),!1;m.busy(!0);var f=m.createStateObject(b,c,d);return m.isLastSavedState(f)?m.busy(!1):(m.storeState(f),m.expectedStateId=f.id,n.replaceState(f.id,f.title,f.url),m.Adapter.trigger(a,"popstate")),!0};if(f){try{m.store=k.parse(f.getItem("History.store"))||{}}catch(p){m.store={}}m.normalizeStore()}else m.store={},m.normalizeStore();m.Adapter.bind(a,"beforeunload",m.clearAllIntervals),m.Adapter.bind(a,"unload",m.clearAllIntervals),m.saveState(m.storeState(m.extractState(d.location.href,!0))),f&&(m.onUnload=function(){var a,b;try{a=k.parse(f.getItem("History.store"))||{}}catch(c){a={}}a.idToState=a.idToState||{},a.urlToId=a.urlToId||{},a.stateToId=a.stateToId||{};for(b in m.idToState){if(!m.idToState.hasOwnProperty(b))continue;a.idToState[b]=m.idToState[b]}for(b in m.urlToId){if(!m.urlToId.hasOwnProperty(b))continue;a.urlToId[b]=m.urlToId[b]}for(b in m.stateToId){if(!m.stateToId.hasOwnProperty(b))continue;a.stateToId[b]=m.stateToId[b]}m.store=a,m.normalizeStore(),f.setItem("History.store",k.stringify(a))},m.intervalList.push(i(m.onUnload,m.options.storeInterval)),m.Adapter.bind(a,"beforeunload",m.onUnload),m.Adapter.bind(a,"unload",m.onUnload));if(!m.emulated.pushState){m.bugs.safariPoll&&m.intervalList.push(i(m.safariStatePoll,m.options.safariPollInterval));if(e.vendor==="Apple Computer, Inc."||(e.appCodeName||"")==="Mozilla")m.Adapter.bind(a,"hashchange",function(){m.Adapter.trigger(a,"popstate")}),m.getHash()&&m.Adapter.onDomLoad(function(){m.Adapter.trigger(a,"hashchange")})}},m.init()}(window) \ No newline at end of file diff --git a/modules/web/web/VAADIN/resources/js/json2.js b/modules/web/web/VAADIN/resources/js/json2.js new file mode 100644 index 0000000000..8ae5a75703 --- /dev/null +++ b/modules/web/web/VAADIN/resources/js/json2.js @@ -0,0 +1 @@ +window.JSON||(window.JSON={}),function(){function f(a){return a<10?"0"+a:a}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return typeof b=="string"?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g=gap,h,i=b[a];i&&typeof i=="object"&&typeof i.toJSON=="function"&&(i=i.toJSON(a)),typeof rep=="function"&&(i=rep.call(b,a,i));switch(typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";gap+=indent,h=[];if(Object.prototype.toString.apply(i)==="[object Array]"){f=i.length;for(c=0;c