You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by jm...@apache.org on 2006/07/08 00:09:00 UTC

svn commit: r420019 - in /incubator/xap/trunk: WebContent/examples/dojo/dojoExample_0.html WebContent/examples/dojo/dojoExample_0.js src/xap/Xap.js src/xap/session/ClientSession.js src/xap/util/MessageFormat.js

Author: jmargaris
Date: Fri Jul  7 17:08:59 2006
New Revision: 420019

URL: http://svn.apache.org/viewvc?rev=420019&view=rev
Log:
allow for xap imbedded in html, etc

Modified:
    incubator/xap/trunk/WebContent/examples/dojo/dojoExample_0.html
    incubator/xap/trunk/WebContent/examples/dojo/dojoExample_0.js
    incubator/xap/trunk/src/xap/Xap.js
    incubator/xap/trunk/src/xap/session/ClientSession.js
    incubator/xap/trunk/src/xap/util/MessageFormat.js

Modified: incubator/xap/trunk/WebContent/examples/dojo/dojoExample_0.html
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/dojo/dojoExample_0.html?rev=420019&r1=420018&r2=420019&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/dojo/dojoExample_0.html (original)
+++ incubator/xap/trunk/WebContent/examples/dojo/dojoExample_0.html Fri Jul  7 17:08:59 2006
@@ -9,64 +9,51 @@
       -->
     </style>
     
-    <!-- Keep dojo from trying to scan this whole page for dojoType'd tags: -->
+	<!-- Keep dojo from trying to scan this whole page for dojoType'd tags: -->
 	<script type="text/javascript">
 		djConfig = {
 			parseWidgets: false
 		};
 	</script>    
 	
-	
-
-	
-    
-    
     <script language="JavaScript" type="text/javascript" src="../../src/dojo/dojo.js"></script>
     <script language="JavaScript" type="text/javascript" src="../../src/xap/util/Utils.js"></script>
     <script language="JavaScript" type="text/javascript" src="../../src/xap/Xap.js"></script>
     <script language="JavaScript" type="text/javascript">
     	Xap.bootstrap( "../../", true);
   	</script>
- </head>
- 
-   	
-     
-    <!-- SECTION 2 -->
+  	
+  	  <!-- SECTION 2 -->
 	<script type="text/javascript">
-            // Load Dojo's code concerned with a Button or Button2 widget,
-            // including the object dojo.widget needed to create one
-           dojo.require("dojo.widget.*");   
-	       dojo.require("dojo.event.*");            
-           dojo.require("dojo.widget.Button");  
-           dojo.require("dojo.widget.FloatingPane"); 
-           //dojo.require("dojo.widget.LayoutPane");                         
-           
-                             
+		// Load Dojo's code concerned with a Button or Button2 widget,
+		// including the object dojo.widget needed to create one
+		dojo.require("dojo.widget.*");   
+		dojo.require("dojo.event.*");            
+		dojo.require("dojo.widget.Button");  
+		dojo.require("dojo.widget.FloatingPane"); 
+		//dojo.require("dojo.widget.LayoutPane");  	                                          
  	</script>
 
-
    <script language="JavaScript" 
    			type="text/javascript" 
    			src="dojoExample_0.js"></script>	
+ </head>
+ 
 
+<body onLoad="Xap.scanPage()">
+	<script type="text/javascript">
+		DBG = new AjxDebug( AjxDebug.NONE, null, false ); 
+	</script>
+	
+	SOME TEXT
+	<h1>SOME BIG TEXT</h1>
+	<div context="../../" appName="MyApp" src="dojoExample_0.xal" toolkit="dojo" >
+	</div>
 
-<body onLoad="launch()" >
-		
-  <script language="JavaScript" 
-   			type="text/javascript" 
-   			src="../../../xap/src/xap/taghandling/AbstractTagImpl.js"></script>			
-   <script language="JavaScript" 
-   			type="text/javascript" 
-   			src="../../../xap/src/xap/taghandling/PluginDocumentHandler.js"></script>   			
-   <script language="JavaScript" 
-   			type="text/javascript" 
-   			src="../../../xap/src/xap/bridges/dojo/DojoWidgetBridge.js"></script>
-   <script language="JavaScript" 
-   			type="text/javascript" 
-   			src="../../../xap/src/xap/bridges/dojo/DojoLayoutPaneBridge.js"></script>
-   <script language="JavaScript" 
-   			type="text/javascript" 
-   			src="../../../xap/src/xap/bridges/dojo/DojoFloatingPaneBridge.js"></script>   			
+	<!-- MyApp as the app name is a top-level alias for session
+	as this event handler illustrates -->	
+	<button onclick="alert(MyApp.getDocumentContainer().getUiDocument().toXml());">hello</button>
+	FOOTER TEXT
 </body>
 
 

Modified: incubator/xap/trunk/WebContent/examples/dojo/dojoExample_0.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/dojo/dojoExample_0.js?rev=420019&r1=420018&r2=420019&view=diff
==============================================================================
--- incubator/xap/trunk/WebContent/examples/dojo/dojoExample_0.js (original)
+++ incubator/xap/trunk/WebContent/examples/dojo/dojoExample_0.js Fri Jul  7 17:08:59 2006
@@ -1,22 +1,9 @@
-
-	function launch(){
- 		// required for Zimbra, so this should be gone, soon:
-		DBG = new AjxDebug( AjxDebug.NONE, null, false );    	
-        // Dojo uses djConfig to let you specify config options for it.
-        // baseRelativePath is telling Dojo where to find itself
-        // isDebug will give us error messages if something goes wrong
-        var djConfig = new Object() ;
-        djConfig.baseRelativePath = "../../src/dojo" ; 
-        djConfig.isDebug = true ; 
- 		Xap.createSession( "../../", "dojoExample_0.xal", "dojo" );
-	}
-
-	function huh_0(){
-		alert("Clicked button 0.") ;
-	}
-	function huh_1(){
-		alert("Clicked button 1.") ;
-	}
-	function huh_2(){
-		alert("Clicked button 2.") ;
-	}
\ No newline at end of file
+function huh_0(){
+	alert("Clicked button 0.") ;
+}
+function huh_1(){
+	alert("Clicked button 1.") ;
+}
+function huh_2(){
+	alert("Clicked button 2.") ;
+}
\ No newline at end of file

Modified: incubator/xap/trunk/src/xap/Xap.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/Xap.js?rev=420019&r1=420018&r2=420019&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/Xap.js (original)
+++ incubator/xap/trunk/src/xap/Xap.js Fri Jul  7 17:08:59 2006
@@ -38,6 +38,29 @@
 	dojo.require.apply(dojo,arguments) ;
 }
 
+Xap.scanPage = function(){
+	var xapElements = document.body.getElementsByTagName("DIV");
+	for (var i =0; i<xapElements.length; i++){
+		var element = xapElements.item(i);
+		var appName = element.getAttribute("appName");
+		if(!appName){
+			continue;
+		}
+		var src = element.getAttribute("src");	
+		alert("Found xap tag with appName:" + appName + " and source " + src);
+		var context = element.getAttribute("context");
+		var toolkit = element.getAttribute("toolkit");
+		
+		var session = Xap.createSession(context, src, toolkit , element);
+		if (window[appName]==null){
+			window[appName]= session;
+		}
+		else{
+			//TODO throw some error?
+		}
+	}
+}
+
 
 
 
@@ -63,8 +86,8 @@
 	Xap.loadZimbra( sourceRootDir );
 }
 
-Xap.createSession = function( context, startPage,toolkitType ) {
-	var session = new ClientSession( context,toolkitType );
+Xap.createSession = function( context, startPage,toolkitType , element) {
+	var session = new ClientSession( context,toolkitType ,element );
 	session._start( startPage );
 	return session;
 }

Modified: incubator/xap/trunk/src/xap/session/ClientSession.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/session/ClientSession.js?rev=420019&r1=420018&r2=420019&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/session/ClientSession.js (original)
+++ incubator/xap/trunk/src/xap/session/ClientSession.js Fri Jul  7 17:08:59 2006
@@ -27,7 +27,7 @@
 //-----------------------------------------------------------------------
 // Constructors.
 //-----------------------------------------------------------------------
-ClientSession = function( webappContext,toolkitType ) {
+ClientSession = function( webappContext,toolkitType, parentElement ) {
 	
 	this._namesToContainers = new Hashtable();
 	this._webappContext = webappContext;
@@ -60,7 +60,7 @@
 	
 	
 	//TODO handle this in a better way
-	this._createInitialDocument(toolkitType);
+	this._createInitialDocument(toolkitType, parentElement);
 }
 
 ClientSession.s_log = LogFactory.getLog( "ClientSession" );
@@ -240,10 +240,10 @@
 	return this._uiDocumentHandler;
 }
 
-ClientSession.prototype._createInitialDocument = function(toolkitType) {
+ClientSession.prototype._createInitialDocument = function(toolkitType, parentElement) {
 	var shell = null ;
 	if( toolkitType && toolkitType=="dojo"){
-		shell = document.body ;
+		shell = parentElement!=null? parentElement : document.body ;
 	} else {
 		shell = new DwtShell( "MainShell", false, null, null, true );
 	}

Modified: incubator/xap/trunk/src/xap/util/MessageFormat.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/util/MessageFormat.js?rev=420019&r1=420018&r2=420019&view=diff
==============================================================================
--- incubator/xap/trunk/src/xap/util/MessageFormat.js (original)
+++ incubator/xap/trunk/src/xap/util/MessageFormat.js Fri Jul  7 17:08:59 2006
@@ -44,7 +44,8 @@
 		return null;
 	}
 	
-	//TODO escaping syntax??
+	//TODO escaping syntax?? And if we replace something
+	//and it has a {1} we are in trouble...
 	for (var i =0; args && i<args.length; i++){	
 		var replacementString = "\\{" + i + "\\}";
 		var regEx = new RegExp(replacementString, "gm");
@@ -54,4 +55,24 @@
 	return formatString;
 }
 
+//TODO if nothing else put this in a general
+//xap.string.... method
+//along with trim() and others.
+
+
+//DOJO code that is similar
+//no escape syntax here either?
+//this lets you do something like:
+//asd {hello} asd {goodbye}
+//then pass in an object[hello]=x and object[goodby]=y and do the sub that way
+
+// dojo.string.substituteParams = function(template /*string */, hash /* object - optional or ... */) {
+//	var map = (typeof hash == 'object') ? hash : dojo.lang.toArray(arguments, 1);
+//
+//	return template.replace(/\%\{(\w+)\}/g, function(match, key){
+//		return map[key] || dojo.raise("Substitution not found: " + key);
+//	});
+//};
+// 
+//