[Xmpp4js-commit] SF.net SVN: xmpp4js:[749] trunk
Status: Beta
Brought to you by:
h-iverson
|
From: <h-i...@us...> - 2008-07-25 16:36:10
|
Revision: 749
http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=749&view=rev
Author: h-iverson
Date: 2008-07-25 16:36:16 +0000 (Fri, 25 Jul 2008)
Log Message:
-----------
removed dependency on prototype
Modified Paths:
--------------
trunk/pom.xml
trunk/src/main/javascript/Events.js
trunk/src/main/javascript/adapter/Default.js
trunk/src/main/javascript/roster/PresenceManager.js
trunk/src/main/javascript/roster/RosterEntry.js
trunk/src/main/javascript/roster/RosterGroup.js
trunk/src/main/javascript/roster/RosterItemManager.js
trunk/src/main/javascript/roster/UnfiledEntriesRosterGroup.js
trunk/src/test/javascript/EventListenerManagerTest.html
trunk/src/test/javascript/RosterItemManagerTest.html
trunk/src/test/javascript/broken/RosterTest.html
trunk/src/test/javascript/common-test-library.js
Added Paths:
-----------
trunk/src/test/javascript/LangTest.html
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2008-07-25 04:26:41 UTC (rev 748)
+++ trunk/pom.xml 2008-07-25 16:36:16 UTC (rev 749)
@@ -16,12 +16,6 @@
<url>http://xmpp4js.sourceforge.net</url>
<dependencies>
<dependency>
- <groupId>com.prototype</groupId>
- <artifactId>prototype</artifactId>
- <type>javascript</type>
- <version>1.5.1-SNAPSHOT</version>
- </dependency>
- <dependency>
<groupId>uk.org.pajhome</groupId>
<artifactId>crypto</artifactId>
<type>javascript</type>
@@ -51,7 +45,7 @@
<configuration>
<descriptor>${basedir}/src/assembler/xmpp4js.xml</descriptor>
<includes>
- <include>*Test.html</include>
+ <include>LangTest.html</include>
</includes>
<excludes>
<!-- hasn't been ported to new connection stuff yet -->
Modified: trunk/src/main/javascript/Events.js
===================================================================
--- trunk/src/main/javascript/Events.js 2008-07-25 04:26:41 UTC (rev 748)
+++ trunk/src/main/javascript/Events.js 2008-07-25 16:36:16 UTC (rev 749)
@@ -42,15 +42,15 @@
* Fire each delegate method with arguments that were passed to fire
*/
fire: function() {
- var fireArgs = arguments;
- $H(this.map).each(function(pair) {
+ var fireArgs = Array.prototype.slice.call(arguments);
+ for( var k in this.map) {
try {
// scope doesn't matter, should have been set with bind()
- pair.value.apply(null,fireArgs);
+ this.map[k].apply(null,fireArgs);
} catch(e) {
// TODO do something
}
- });
+ }
},
// TODO test... even though it hardly needs it.
getMap: function() {
@@ -102,7 +102,7 @@
}
EventListenerManager.prototype.fireArgs = function( event, args ) {
- var callArgs = $A(args);
+ var callArgs = args.slice(0);
// put event onto the beginning of the arg stack
callArgs.unshift( event );
@@ -115,7 +115,7 @@
// get passed arguments and shift the first (event) off the front
- var args = $A(arguments);
+ var args = Array.prototype.slice.call(arguments);
args.shift();
dm.fire.apply( dm, args );
@@ -196,7 +196,7 @@
},
fireEvent: function(event, args) {
- var callArgs = $A(arguments);
+ var callArgs = Array.prototype.slice.call(arguments);
callArgs.shift(); // pull off the event
this.eventListenerManager.fireArgs( event, callArgs );
Modified: trunk/src/main/javascript/adapter/Default.js
===================================================================
--- trunk/src/main/javascript/adapter/Default.js 2008-07-25 04:26:41 UTC (rev 748)
+++ trunk/src/main/javascript/adapter/Default.js 2008-07-25 16:36:16 UTC (rev 749)
@@ -395,12 +395,27 @@
return output;
},
- noOp: function(){}
+ noOp: function(){},
-
+ bind: function( fn, scope ) {
+ var args = Array.prototype.slice.call(arguments);
+ args.shift(); args.shift(); // remove fn and scope
+
+ return function() {
+ var fnArgs = Array.prototype.slice.call(arguments)
+ return fn.apply(scope, args.concat(fnArgs));
+ }
+ }
}
+Function.prototype.bind = function(scope) {
+;;; console.warn( "Using Function.prototype.bind" );
+ var args = Array.prototype.slice.call(arguments);
+ args.unshift( this ); // add fn argument to the beginning
+ return Xmpp4Js.Lang.bind.apply( this, args );
+}
+
Xmpp4Js.Lang.TaskRunner = function(interval) {
this.interval = interval;
this.tasks = [];
Modified: trunk/src/main/javascript/roster/PresenceManager.js
===================================================================
--- trunk/src/main/javascript/roster/PresenceManager.js 2008-07-25 04:26:41 UTC (rev 748)
+++ trunk/src/main/javascript/roster/PresenceManager.js 2008-07-25 16:36:16 UTC (rev 749)
@@ -87,11 +87,12 @@
remove: function(jid, resource) {
if( this.map[jid] == undefined ) { return; }
+ // remove all resources if none is specified
if( !resource ) {
- $H(this.map[jid]).each(function(pair) {
- var resource = pair.value;
- this.remove( jid, resource);
- }.bind(this));
+ for( var k in this.map[jid]) {
+ var mapResource = this.map[jid][k];
+ this.remove( jid, mapResource);
+ }
delete this.map[jid];
} else {
if( this.map[jid][resource] == undefined ) { return; }
@@ -152,8 +153,8 @@
var bestPresence = undefined;
var bestWeight = 0;
- $H(presenceList).each(function(pair) {
- var presence = pair.value;
+ for(var k in presenceList) {
+ var presence = presenceList[k];
// these return default values if empty.
var show = presence.getShow();
@@ -171,7 +172,7 @@
bestPresence = presence;
bestWeight = weight;
}
- }.bind(this));
+ };
return bestPresence;
}
Modified: trunk/src/main/javascript/roster/RosterEntry.js
===================================================================
--- trunk/src/main/javascript/roster/RosterEntry.js 2008-07-25 04:26:41 UTC (rev 748)
+++ trunk/src/main/javascript/roster/RosterEntry.js 2008-07-25 16:36:16 UTC (rev 749)
@@ -25,24 +25,25 @@
},
/** references to all groups this entry belongs to. 0 or more. */
getGroups: function() {
- var retGroups = [];
- // TODO possibly refactor this to roster.getGroups and make use of that... for each group, if contains this jid, add to list
- // gets groups off of con.roster
- if( this.groups.length == 0 ) {
- retGroups.push( this.roster.getUnfiledContacts() );
- } else {
- $A(this.groups).each(function(groupName) {
- var group = this.roster.getGroup(groupName);
- // if group is undefined, that means that this entry is not associated with
- // an existing group--perhaps it was just removed.
- // TODO make a test for this case.
- if( group == undefined ) {
- group = new Xmpp4Js.Roster.VirtualRosterGroup( groupName, [this], this.roster );
- }
- retGroups.push( group );
- }.bind(this));
- }
+ var retGroups = [];
+ // TODO possibly refactor this to roster.getGroups and make use of that... for each group, if contains this jid, add to list
+ // gets groups off of con.roster
+ if( this.groups.length == 0 ) {
+ retGroups.push( this.roster.getUnfiledContacts() );
+ } else {
+ for(var i = 0; i < this.groups.length; i++) {
+ var groupName = this.groups[i];
+ var group = this.roster.getGroup(groupName);
+ // if group is undefined, that means that this entry is not associated with
+ // an existing group--perhaps it was just removed.
+ // TODO make a test for this case.
+ if( group == undefined ) {
+ group = new Xmpp4Js.Roster.VirtualRosterGroup( groupName, [this], this.roster );
+ }
+ retGroups.push( group );
+ };
+ }
return retGroups;
- }
+ }
}
Modified: trunk/src/main/javascript/roster/RosterGroup.js
===================================================================
--- trunk/src/main/javascript/roster/RosterGroup.js 2008-07-25 04:26:41 UTC (rev 748)
+++ trunk/src/main/javascript/roster/RosterGroup.js 2008-07-25 16:36:16 UTC (rev 749)
@@ -13,8 +13,8 @@
getEntries: function() {
var retEntries = [];
- $H(this.roster.map).each(function(pair) {
- var entry = pair.value;
+ for(var k in this.roster.map) {
+ var entry = this.roster.map[k];
var groups = entry.groups;
for( var j = 0; j < groups.length; j++ ) {
@@ -23,20 +23,21 @@
retEntries.push( entry );
}
}
- }.bind(this));
+ };
return retEntries;
},
- getEntry: function(jid) {
- var entries = this.getEntries();
- var retEntry = undefined;
- $A(entries).each(function(entry) {
- if( entry.jid == jid ) {
- retEntry = entry;
- }
- }.bind(this));
-
- return retEntry;
+ getEntry: function(jid) {
+ var entries = this.getEntries();
+ var retEntry = undefined;
+ for(var i = 0; i < entries.length; i++) {
+ var entry = entries[i];
+ if( entry.jid == jid ) {
+ retEntry = entry;
+ }
+ };
- }
+ return retEntry;
+
+ }
}
Modified: trunk/src/main/javascript/roster/RosterItemManager.js
===================================================================
--- trunk/src/main/javascript/roster/RosterItemManager.js 2008-07-25 04:26:41 UTC (rev 748)
+++ trunk/src/main/javascript/roster/RosterItemManager.js 2008-07-25 16:36:16 UTC (rev 749)
@@ -71,16 +71,17 @@
retGroups.push( this.getUnfiledContacts() );
- $H(this.map).each(function(pair) {
- var entry = pair.value;
- $A(entry.groups).each(function(groupName) {
+ for( var k in this.map) {
+ var entry = this.map[k];
+ for(var i = 0; i < entry.groups.length; i++) {
+ var groupName = entry.groups[i];
if( groupNames[groupName] == undefined ) {
groupNames[ groupName ] = 1;
retGroups.push( new Xmpp4Js.Roster.RosterGroup( groupName, this ) );
}
- }.bind(this));
+ };
- }.bind(this));
+ };
return retGroups;
},
Modified: trunk/src/main/javascript/roster/UnfiledEntriesRosterGroup.js
===================================================================
--- trunk/src/main/javascript/roster/UnfiledEntriesRosterGroup.js 2008-07-25 04:26:41 UTC (rev 748)
+++ trunk/src/main/javascript/roster/UnfiledEntriesRosterGroup.js 2008-07-25 16:36:16 UTC (rev 749)
@@ -12,14 +12,14 @@
getEntries: function() {
var retEntries = [];
- $H(this.roster.map).each(function(pair) {
- var entry = pair.value;
+ for(var k in this.roster.map) {
+ var entry = this.roster.map[k];
var groups = entry.groups;
if( !groups || groups.length == 0 ) {
retEntries.push( entry );
}
- }.bind(this));
+ }
return retEntries;
}
Modified: trunk/src/test/javascript/EventListenerManagerTest.html
===================================================================
--- trunk/src/test/javascript/EventListenerManagerTest.html 2008-07-25 04:26:41 UTC (rev 748)
+++ trunk/src/test/javascript/EventListenerManagerTest.html 2008-07-25 16:36:16 UTC (rev 749)
@@ -35,7 +35,7 @@
var listeners = el.getMap( EVENT_NAME );
- assertEquals( 1, $H(listeners).keys().length );
+ assertEquals( 1, mapLength(listeners) );
assertEquals( listener, listeners[id] );
}
@@ -52,7 +52,7 @@
var listeners = el.getMap( EVENT_NAME );
- assertEquals( 2, $H(listeners).keys().length );
+ assertEquals( 2, mapLength(listeners) );
assertEquals( listener1, listeners[ l1id ] );
assertEquals( listener2, listeners[ l2id ] );
@@ -67,7 +67,7 @@
var listeners = el.getMap( EVENT_NAME );
- assertEquals( 0, $H(listeners).keys().length );
+ assertEquals( 0, mapLength(listeners) );
assertUndefined( listeners[id] );
}
@@ -80,7 +80,7 @@
var listeners = el.getMap( EVENT_NAME );
- assertEquals( 0, $H(listeners).keys().length );
+ assertEquals( 0, mapLength(listeners) );
assertUndefined( listeners[id] );
}
Added: trunk/src/test/javascript/LangTest.html
===================================================================
--- trunk/src/test/javascript/LangTest.html (rev 0)
+++ trunk/src/test/javascript/LangTest.html 2008-07-25 16:36:16 UTC (rev 749)
@@ -0,0 +1,91 @@
+<html>
+ <head>
+ <title>JSUnit - RosterWindowTest</title>
+ <script language="javascript" src="app/jsUnitCore.js"></script>
+
+ <script type="text/javascript" src="includes.js"></script>
+ <script type="text/javascript" src="common-test-library.js"></script>
+
+ </head>
+ <body>
+ <script type="text/javascript">
+
+
+
+
+
+function setUp() {
+
+}
+function tearDown() {
+
+}
+
+function testBind() {
+ var expectedThis = {testProperty: "abc123"};
+ var actualThis = null;
+ var fn = function() {
+ actualThis = this;
+ }
+
+ var boundFn = Xmpp4Js.Lang.bind( fn, expectedThis );
+ boundFn();
+
+ assertEquals( "Scope was no correct.", expectedThis, actualThis );
+ assertEquals( "Scope was no correct.", expectedThis.testProperty, actualThis.testProperty );
+}
+
+function testBindArguments() {
+ var expectedThis = {testProperty: "abc123"};
+ var actualThis = null;
+ var fn = function(arg1, arg2) {
+ actualThis = this;
+ assertEquals( "123", arg1 );
+ assertEquals( "456", arg2 );
+ }
+
+ var boundFn = Xmpp4Js.Lang.bind( fn, expectedThis, "123" );
+ boundFn("456");
+
+ assertEquals( "Scope was no correct.", expectedThis, actualThis );
+ assertEquals( "Scope was no correct.", expectedThis.testProperty, actualThis.testProperty );
+}
+
+// temporary, will go away when all instances of .bind() are removed
+function testFunctionPrototypeBind() {
+ var expectedThis = {testProperty: "abc123"};
+ var actualThis = null;
+ var fn = function() {
+ actualThis = this;
+ }
+
+ var boundFn = fn.bind( expectedThis );
+ boundFn();
+
+ assertEquals( "Scope was no correct.", expectedThis, actualThis );
+ assertEquals( "Scope was no correct.", expectedThis.testProperty, actualThis.testProperty );
+}
+
+// temporary, will go away when all instances of .bind() are removed
+function FunctionPrototypeBindArguments() {
+ var expectedThis = {testProperty: "abc123"};
+ var actualThis = null;
+ var fn = function(arg1, arg2) {
+ actualThis = this;
+ assertEquals( "123", arg1 );
+ assertEquals( "456", arg2 );
+ }
+
+ var boundFn = fn.bind( expectedThis, "123" );
+ boundFn("456");
+
+ assertEquals( "Scope was no correct.", expectedThis, actualThis );
+ assertEquals( "Scope was no correct.", expectedThis.testProperty, actualThis.testProperty );
+}
+
+
+ </script>
+ </body>
+</html>
+
+
Modified: trunk/src/test/javascript/RosterItemManagerTest.html
===================================================================
--- trunk/src/test/javascript/RosterItemManagerTest.html 2008-07-25 04:26:41 UTC (rev 748)
+++ trunk/src/test/javascript/RosterItemManagerTest.html 2008-07-25 16:36:16 UTC (rev 749)
@@ -73,9 +73,10 @@
function testGetGroup() {
rim.update( JID1, ALIAS1, null, null, GROUPS1 );
- $A(GROUPS1).each(function(groupName) {
+ for(var i = 0; i < GROUPS1.length; i++) {
+ var groupName = GROUPS1[i];
assertNotUndefined( rim.getGroup( groupName ) );
- }.bind(this));
+ };
}
function testGetGroupsFromEntry() {
@@ -88,21 +89,20 @@
assertEquals( GROUPS1.length, groups.length );
/* TODO compare group names
- $A(groups).each(function(group) {
-
- }.bind(this));
+
*/
}
function testGetEntryFromGroup() {
rim.update( JID1, ALIAS1, null, null, GROUPS1 );
- $A(GROUPS1).each(function(groupName) {
+ for(var i = 0; i < GROUPS1.length; i++) {
+ var groupName = GROUPS1[i];
var group = rim.getGroup( groupName );
var entry = group.getEntry( JID1 );
assertNotUndefined( entry );
assertEquals( JID1, entry.jid );
- }.bind(this));
+ };
}
function testAddEntryNoGroup() {
@@ -165,9 +165,10 @@
var entry = rim.get( JID1 );
assertUndefined(entry);
- $A(GROUPS1).each(function(groupName) {
+ for(var i = 0; i < GROUPS1.length; i++) {
+ var groupName = GROUPS1[i];
assertUndefined( rim.getGroup( groupName) );
- }.bind(this));
+ };
}
Modified: trunk/src/test/javascript/broken/RosterTest.html
===================================================================
--- trunk/src/test/javascript/broken/RosterTest.html 2008-07-25 04:26:41 UTC (rev 748)
+++ trunk/src/test/javascript/broken/RosterTest.html 2008-07-25 16:36:16 UTC (rev 749)
@@ -73,12 +73,13 @@
var entry = rim.update( JID1, ALIAS1, null, null, GROUPS1 );
- $A( GROUPS1 ).each( function(groupName ) {
+ for( var i = 0; i < GROUPS1.length; i++ ) {
+ var groupName = GROUPSi[i];
var group = rim.getGroup( groupName );
var entryNode = ri._getEntryNode( entry, group );
assertNotUndefined( entryNode );
- });
+ };
}
Modified: trunk/src/test/javascript/common-test-library.js
===================================================================
--- trunk/src/test/javascript/common-test-library.js 2008-07-25 04:26:41 UTC (rev 748)
+++ trunk/src/test/javascript/common-test-library.js 2008-07-25 16:36:16 UTC (rev 749)
@@ -322,4 +322,12 @@
}
}
+function mapLength(map) {
+ var length = 0;
+ for(var k in map) {
+ length++;
+ }
+ return length;
+}
+
Xmpp4Js.Lang.extend( MockConnection, Xmpp4Js.Event.EventProvider, MockConnection.prototype );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|