You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by st...@apache.org on 2012/05/12 11:29:12 UTC
svn commit: r1337487 - in /myfaces/extensions/cdi/trunk:
examples/jsf-playground/clientside_windowhandler_jsf20/src/main/resources/META-INF/resources/
jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/
jee-modules/jsf-module/impl/src/ma...
Author: struberg
Date: Sat May 12 09:29:12 2012
New Revision: 1337487
URL: http://svn.apache.org/viewvc?rev=1337487&view=rev
Log:
EXTCDI-284 move windowhandler.js to the internal project.
That way it is automtically available for use in
custom projects.
just include the follwing head lines in your template:
<h:outputScript library="javax.faces" name="jsf.js"/>
<h:outputScript library="js" name="windowhandler.js"/>
Added:
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/
myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js (with props)
Removed:
myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/resources/META-INF/resources/
Added: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js?rev=1337487&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js (added)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js Sat May 12 09:29:12 2012
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+(function() {
+//wrapping so that all internal functions are privately scoped
+ function isHtml5() {
+ try {
+ return !!localStorage.getItem;
+ } catch(e) {
+ return false;
+ }
+ }
+
+// some browsers don't understand JSON - guess which one ... :(
+ function stringify(someArray) {
+ if (JSON) {
+ return JSON.stringify(someArray);
+ }
+ return someArray.join("|||");
+ }
+
+// store the current body in the html5 localstorage
+ function storeWindowTree() {
+ // first we store all CSS we also need on the intermediate page
+ var headNodes = document.getElementsByTagName("head")[0].childNodes;
+ var oldSS = new Array();
+ var j = 0;
+ for (var i = 0; i < headNodes.length; i++) {
+ var tagName = headNodes[i].tagName;
+ if (tagName && equalsIgnoreCase(tagName, "link") &&
+ equalsIgnoreCase(headNodes[i].getAttribute("type"), "text/css")) {
+
+ // sort out media="print" and stuff
+ var media = headNodes[i].getAttribute("media");
+ if (!media || equalsIgnoreCase(media, "all") || equalsIgnoreCase(media, 'screen')) {
+ oldSS[j++] = headNodes[i].getAttribute("href");
+ }
+ }
+ }
+ localStorage.setItem(window.name + '_css', stringify(oldSS));
+ var body = document.getElementsByTagName("body")[0];
+ localStorage.setItem(window.name + '_body', body.innerHTML);
+ //X TODO: store ALL attributes of the body tag
+ localStorage.setItem(window.name + '_bodyAttrs', body.getAttribute("class"));
+ return true;
+ }
+
+ function equalsIgnoreCase(source, destination) {
+ //either both are not set or null
+ if (!source && !destination) {
+ return true;
+ }
+ //source or dest is set while the other is not
+ if (!source || !destination) return false;
+
+ //in any other case we do a strong string comparison
+ return source.toLowerCase() === destination.toLowerCase();
+ }
+
+ function applyOnClick() {
+ var links = document.getElementsByTagName("a");
+ for (var i = 0; i < links.length; i++) {
+ if (!links[i].onclick) {
+ links[i].onclick = function() {storeWindowTree(); return true;};
+ } else {
+ //the function wrapper is important
+ //otherwise the last onclick handler would be assigned
+ //to oldonclick
+ (function storeEvent() {
+ var oldonclick = links[i].onclick;
+ links[i].onclick = function(evt) {
+ //ie handling added
+ evt = evt || window.event;
+
+ return storeWindowTree() && oldonclick(evt);
+ };
+ })();
+ }
+ }
+ }
+
+ function assertWindowId() {
+ var freshWindow = window.name.length < 1;
+ if (freshWindow) {
+ var url = urlWithoutWindowId(window.location.href);
+ window.name = "window";
+ window.location = url;
+ }
+ }
+
+ var oldWindowOnLoad = window.onload;
+
+ window.onload = function(evt) {
+ try {
+ (oldWindowOnLoad)? oldWindowOnLoad(evt): null;
+ } finally {
+ if (isHtml5()) {
+ applyOnClick();
+ }
+ // this ensures that even without the ClientSideWindowHandler
+ assertWindowId();
+ }
+ }
+})();
Propchange: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/META-INF/resources/js/windowhandler.js
------------------------------------------------------------------------------
svn:eol-style = native