Author: xlawrence
Date: Tue Nov 6 10:10:14 2007
New Revision: 19050
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D19050&repname=
=3Djahia
Log:
update action menu javascript code and add a js file for templates, contain=
ing Zimbra and ESI functions
Added:
branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/jsp/jahia/javascript/=
templates.js
Modified:
branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/jsp/jahia/javascript/=
actions.js
Modified: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/jsp/jahia/javas=
cript/actions.js
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-INCLUD=
E-TAG-BRANCH/core/src/webapp/jsp/jahia/javascript/actions.js&rev=3D19050&re=
pname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/jsp/jahia/javascript/=
actions.js (original)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/jsp/jahia/javascript/=
actions.js Tue Nov 6 10:10:14 2007
@@ -1,25 +1,10 @@
-/*
- * Copyright 2002-2006 Jahia Ltd
- *
- * Licensed under the JAHIA COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (J=
CDDL), =
- * Version 1.0 (the "License"), or (at your option) any later version; you=
may =
- * not use this file except in compliance with the License. You should hav=
e =
- * received a copy of the License along with this program; if not, you may=
obtain =
- * a copy of the License at =
- *
- * http://www.jahia.org/license/
- *
- * 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.
- */
//************************************************************************=
*****
// Do not remove this notice.
//
// Copyright 2000 by Mike Hall.
// See http://www.brainjar.com for terms of use.
+
+// Modified by Xavier Lawrence, 2005 Copyright Jahia Solutions
//************************************************************************=
*****
=
//------------------------------------------------------------------------=
----
@@ -68,6 +53,9 @@
=
var activeButton =3D null;
=
+// AJAX variables
+var req;
+
// Capture mouse clicks on the page so any active button can be
// deactivated.
=
@@ -106,66 +94,56 @@
}
}
=
-function buttonClick(event, menuId) {
-
- var button;
-
- // Get the target button element.
-
- if (browser.isIE)
- button =3D window.event.srcElement;
- else
- button =3D event.currentTarget;
+// Opens up the menu of the given id
+function buttonClick (menuId) {
+ var button =3D getObjectById ("button_" + menuId);
=
// Blur focus from the link to remove that annoying outline.
-
button.blur();
=
// Associate the named menu to this button if not already done.
// Additionally, initialize menu display.
-
if (button.menu =3D=3D null) {
- button.menu =3D document.getElementById(menuId);
- if (button.menu.isInitialized =3D=3D null)
+ button.menu =3D getObjectById (menuId);
+ if (button.menu.isInitialized =3D=3D null) {
menuInit(button.menu);
+ }
}
=
// Reset the currently active button, if any.
=
- if (activeButton !=3D null)
+ if (activeButton !=3D null) {
resetButton(activeButton);
+ }
=
// Activate this button, unless it was the currently active one.
=
if (button !=3D activeButton) {
depressButton(button);
activeButton =3D button;
- }
- else
+ } else {
activeButton =3D null;
-
- return false;
+ }
}
=
+// Switches menu if the user's mouse goes on another menu
function buttonMouseover(event, menuId) {
+ var button;
=
- var button;
-
- // Find the target button element.
-
- if (browser.isIE)
- button =3D window.event.srcElement;
- else
- button =3D event.currentTarget;
-
- // If any other button menu is active, make this one active instead.
-
- if (activeButton !=3D null && activeButton !=3D button)
- buttonClick(event, menuId);
+ // Find the target button element.
+ if (browser.isIE) {
+ button =3D window.event.srcElement;
+ } else {
+ button =3D event.currentTarget;
+ }
+
+ // If any other button menu is active, make this one active instead.
+ if (activeButton !=3D null && activeButton !=3D button) {
+ buttonClick (menuId);
+ }
}
=
function depressButton(button) {
-
var x, y;
=
// Update the button's style class to make it look like it's
@@ -177,7 +155,7 @@
// show it.
=
x =3D getPageOffsetLeft(button);
- y =3D getPageOffsetTop(button) + button.offsetHeight;
+ y =3D getPageOffsetTop(button) + button.offsetHeight - 5;
=
// For IE, adjust position.
=
@@ -460,3 +438,332 @@
=
return y;
}
+
+// Check the browser for DOM manipulation
+function checkBrowser(){
+ this.ver=3Dnavigator.appVersion;
+ this.dom=3Ddocument.getElementById?1:0;
+ this.ie6=3D(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
+ this.ie55=3D((this.ver.indexOf("MSIE 5.5")>-1 || this.ie6) &&
this.dom)?1=
:0;
+ this.ie5=3D((this.ver.indexOf("MSIE 5")>-1 || this.ie5 || this.ie6) &&
th=
is.dom)?1:0;
+ this.ie4=3D(document.all && !this.dom)?1:0;
+ this.ns5=3D(this.dom && parseInt(this.ver) >=3D 5) ?1:0;
+ this.ns4=3D(document.layers && !this.dom)?1:0;
+ this.ie4plus=3D(this.ie6 || this.ie5 || this.ie4);
+ this.ie5plus=3D(this.ie6 || this.ie5)
+ this.bw=3D(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns5);
+ return this;
+}
+
+bw =3D new checkBrowser();
+
+// Get an Object contained in a DOM document by its ID attribute
+function getObjectById (ID) {
+ var obj;
+ if (bw.dom)
+ return document.getElementById (ID);
+ else if (bw.ie4)
+ return document.all (ID);
+ else
+ alert ("Error: Your browser version is not supported. Please
upgrade..."=
);
+ return null;
+}
+
+// Returns an array of values. The delimiter is the ',' character
+function getNodeValues (content, nodeName) {
+ var tag =3D "<" + nodeName + ">";
+ var start =3D content.indexOf (tag);
+ var end =3D content.indexOf ("</" + nodeName + ">");
+
+ if (start < end) {
+ var values =3D content.substring (start + tag.length, end);
+ return values.split (";;");
+ } else {
+ return new Array (0);
+ }
+}
+
+// Returns the value of an XML tag
+function getNodeValue (content, nodeName) {
+ var tag =3D "<" + nodeName + ">";
+ var start =3D content.indexOf (tag);
+ var end =3D content.indexOf ("</" + nodeName + ">");
+
+ if (start < end) {
+ return content.substring (start + tag.length, end);
+ } else {
+ return null;
+ }
+}
+
+// AJAX based function to get all Actions to fill up the Action menu
+function getActionMenu(context, objectType, objectKey, definitionID, paren=
tID, pageID, domID, lang) {
+ document.body.style.cursor =3D "wait";
+ try {
+ // correct values are "POST" or "GET" (HTTP methods).
+ var method =3D "POST" ;
+ var data =3D "key=3D" + objectKey + "&type=3D" + objectType +
+ "&def=3D" + definitionID + "&parent=3D" + parentID + "&=
domid=3D" + domID +
+ "¶ms=3D/op/edit/lang/" + lang + "/pid/" + pageID;
+
+ var url =3D context + "/ajaxaction/GetMenuItems";
+
+ if (method =3D=3D "GET") {
+ url +=3D "?" + data;
+ data =3D null;
+ }
+
+ // Create new XMLHttpRequest request
+ if (window.XMLHttpRequest) {
+ req =3D new XMLHttpRequest ();
+
+ } else if (window.ActiveXObject) {
+ req =3D new ActiveXObject ("Microsoft.XMLHTTP");
+
+ } else {
+ alert ("Error: Your Browser does not support
XMLHTTPRequests, please up=
grade...");
+ return;
+ }
+
+ req.open (method, url, true);
+
+ req.onreadystatechange =3D function () {
+ buildActionMenu();
+ }
+
+ if (method =3D=3D "POST") {
+ req.setRequestHeader ("Content-type",
"application/x-www-form-urlencode=
d");
+ }
+ req.send (data);
+
+ } catch (e) {
+ alert ("Exception sending the Request: " + e);
+ }
+}
+
+// Build the Action Menu
+function buildActionMenu () {
+ var readyState =3D req.readyState;
+ if (req.readyState =3D=3D 4) {
+ // alert ("resp: " + req.responseText);
+ if (req.status =3D=3D 200) {
+ try {
+ var response =3D req.responseText;
+ var uniqueID =3D getNodeValue(response, "domid");
+
+ var methods =3D getNodeValues (response,
"method");
+ var launchers =3D getNodeValues (response,
"launcher");
+ var images =3D getNodeValues (response,
"image");
+
+ var fieldset =3D getNodeValue (response,
"fieldset");
+ updateFieldSet (uniqueID, fieldset);
+
+ addActions (uniqueID, methods, launchers,
images);
+
+ // changeURL(uniqueID);
+
+ buttonClick (uniqueID);
+
+ } catch (e) {
+ alert ("Exception building Action Menu: " + e);
+ }
+
+ } else {
+ alert ("There was a problem processing the request.
Status: " +
+ req.status + ", msg: " +
req.statusText);
+ }
+ document.body.style.cursor =3D "default";
+ }
+}
+
+// Changes the default grey border. Use in case the object is locked for e=
xample
+function updateFieldSet (id, param) {
+ // alert ("Updating fieldSet for " + id + ", param =3D " + param);
+ if (param =3D=3D null) {
+ return;
+ }
+
+ var setID =3D "fieldset_" + id;
+ var setElem =3D getObjectById (setID);
+
+ var content;
+ if (param =3D=3D "complete") {
+ content =3D "completeLocked";
+
+ } else if (param =3D=3D "partial") {
+ content =3D "partialLocked";
+
+ } else {
+ content =3D "unlocked";
+ }
+
+ setElem.className =3D content;
+}
+
+// Changes the href value of the given element
+function changeURL (id) {
+ var button =3D getObjectById ("button_" + id);
+ button.href =3D "javascript:buttonClick('" + id + "');";
+}
+
+// Adds the Actions to the action menu
+function addActions(id, methods, launchers, images) {
+ var menuDiv =3D getObjectById(id);
+ var content =3D "\n";
+
+ var i;
+ for (i =3D 0; i < methods.length-1; i++) {
+ //alert("i=3D"+i+methods[i])
+ =
+ if(methods[i]=3D=3D"copies"){
+
+ //specific code to display the list of pickers
+ var parts=3Dlaunchers[i].split(",")
+ p=3Dfalse
+ if(parts.length>1) p=3Dparts[1]
+
+ content +=3D"<a class=3D\"menuItem\" href=3D\""+parts[3]+"=
\" title=3D\"id:"+parts[0]+"\"><i>  =
;"+parts[2]+"</i></a>"
+ } else {
+ content +=3D printLauncher(launchers[i]) + printImage(imag=
es[i]) + printMethod(methods[i]);
+ }
+
+ }
+ menuDiv.innerHTML =3D content;
+}
+
+// Returns a String for the Action Launcher URI
+function printLauncher (launcher) {
+ return " <a class=3D\"menuItem\" href=3D\"javascript:" + launcher +
"\"=
>\n";
+}
+
+// Returns a String for the Action Image
+function printImage (imageName) {
+ return " <img src=3D\"" + imageName + "\" alt=3D\"\"
border=3D\"0\" =
/> ";
+}
+
+// Returns a String for the Action method name
+function printMethod (methodName) {
+ return methodName + "\n </a>\n";
+}
+
+function clipboard (context, objectKey, op, pageID) {
+ document.body.style.cursor =3D "wait";
+ try {
+ // correct values are "POST" or "GET" (HTTP methods).
+ var method =3D "POST" ;
+ var data =3D "key=3D" + objectKey + "&cop=3D" + op;
+ var url =3D jahiaMainServletPath + "/op/edit/engineName/clipboard/=
pid/" + pageID ;
+
+ if (method =3D=3D "GET") {
+ url +=3D "?" + data;
+ data =3D null;
+ }
+
+ // Create new XMLHttpRequest request
+ if (window.XMLHttpRequest) {
+ req =3D new XMLHttpRequest ();
+
+ } else if (window.ActiveXObject) {
+ req =3D new ActiveXObject ("Microsoft.XMLHTTP");
+
+ } else {
+ alert ("Error: Your Browser does not support
XMLHTTPRequests, please up=
grade...");
+ return;
+ }
+
+ req.open (method, url, true);
+
+ if (op =3D=3D "paste") {
+ req.onreadystatechange =3D function () {
+ if (req.readyState =3D=3D 4) {
+ document.body.style.cursor =3D "default";
+ window.location.reload();
+ }
+ }
+ } else {
+ req.onreadystatechange =3D function () {
+ if (req.readyState =3D=3D 4) {
+ //copy
+ myurl =3D "http://" + document.location.host + context=
+ "/jsp/jahia/engines/images/clipboard_next.png";
+ myclip =3D document.getElementById('clipboard');
+ myclip.src =3D myurl;
+ myclip.alt =3D "clipboard:" + objectKey;
+ //window.location.reload();
+ document.body.style.cursor =3D "default";
+ }
+ }
+ }
+
+ if (method =3D=3D "POST") {
+ req.setRequestHeader ("Content-type",
"application/x-www-form-urlencode=
d");
+ }
+ req.send (data);
+ } catch (e) {
+ alert ("Exception sending the Request: " + e);
+ }
+}
+
+function getWorkflowState(context, key, pid) {
+ try {
+ // correct values are "POST" or "GET" (HTTP methods).
+ var method =3D "POST" ;
+ var data =3D "key=3D" + key + "¶ms=3D/op/edit/pid/" + pid;
+
+ var url =3D context + "/ajaxaction/GetWorkflowState";
+
+ if (method =3D=3D "GET") {
+ url +=3D "?" + data;
+ data =3D null;
+ }
+
+ // Create new XMLHttpRequest request
+ if (window.XMLHttpRequest) {
+ req =3D new XMLHttpRequest ();
+
+ } else if (window.ActiveXObject) {
+ req =3D new ActiveXObject ("Microsoft.XMLHTTP");
+
+ } else {
+ alert("Error: Your Browser does not support XMLHTTPRequests, p=
lease upgrade...");
+ return;
+ }
+
+ req.open(method, url, true);
+
+ req.onreadystatechange =3D function () {
+ changeIcone();
+ }
+
+ if (method =3D=3D "POST") {
+ req.setRequestHeader("Content-type", "application/x-www-form-u=
rlencoded");
+ }
+ req.send(data);
+
+ } catch (e) {
+ alert("Exception sending the Request: " + e);
+ }
+}
+
+function changeIcone() {
+ var readyState =3D req.readyState;
+ if (req.readyState =3D=3D 4) {
+ // alert ("resp: " + req.responseText);
+ if (req.status =3D=3D 200) {
+ try {
+ var response =3D req.responseText;
+ var objectKey =3D getNodeValue(response, "key");
+ var icone =3D getNodeValue(response, "stateIcone");
+
+ var elem =3D getObjectById("img_" + objectKey);
+ elem.src =3D icone;
+
+ } catch (e) {
+ alert("Exception changing Icone: " + e);
+ }
+
+ } else {
+ alert("There was a problem processing the request. Status: " +
+ req.status + ", msg: " + req.statusText);
+ }
+ }
+}
Added: branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/jsp/jahia/javascri=
pt/templates.js
URL: https://svndev.jahia.net/websvn/filedetails.php?path=3D/branches/JAHIA=
-INCLUDE-TAG-BRANCH/core/src/webapp/jsp/jahia/javascript/templates.js&rev=
=3D19050&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/jsp/jahia/javascript/=
templates.js (added)
+++ branches/JAHIA-INCLUDE-TAG-BRANCH/core/src/webapp/jsp/jahia/javascript/=
templates.js Tue Nov 6 10:10:14 2007
@@ -0,0 +1,56 @@
+
+// Zimbra specific functions
+function hideUserShell(){
+ try {
+ Dwt.setVisibility(document.getElementById("userShell"),false);
+ } catch (ex){
+ return;
+ }
+}
+ =
+function showUserShell(){
+ try {
+ Dwt.setVisibility(document.getElementById("userShell"),true);
+ } catch (ex){
+ return;
+ }
+}
+
+// ESI specific functions
+function esiGeneratePageInvalidationUrl(){
+ var theUrl =3D window.location.href;
+
+ var invEsiMarker =3D "esi=3DinvalidateNow";
+
+ var posInv =3D theUrl.indexOf(invEsiMarker);
+ //add invalidation marker
+ if (posInv =3D=3D -1) {
+ var posParam =3D theUrl.indexOf("?");
+ if (posParam =3D=3D -1) {
+ theUrl +=3D "?"+invEsiMarker;
+ } else {
+ theUrl +=3D "&"+invEsiMarker;
+ }
+ document.write("Invalidating cache for this page...");
+ document.close();
+ } else {
+ document.write("The current URL["+theUrl+"] already contains ["+invEsiM=
arker+"] when it shouldn't");
+ document.close();
+ }
+ window.location.href =3D theUrl;
+}
+
+function esiForwardToOrginalUrl(){
+ var theUrl =3D window.location.href;
+ var invEsiMarker =3D new String("esi=3DinvalidateNow");
+ var posInv =3D theUrl.indexOf(invEsiMarker);
+
+ //remove invalidation marker
+ if (posInv !=3D -1) {
+ document.write(theUrl);
+ theUrl =3D theUrl.replace(/\?esi=3DinvalidateNow/gi,"");
+ theUrl =3D theUrl.replace(/&esi=3DinvalidateNow/gi,"");
+ theUrl =3D theUrl.replace(/esi=3DinvalidateNow/gi,"");
+ window.location.href =3D theUrl;
+ }
+}
\ No newline at end of file
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list